summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2012-11-11 20:39:08 +0000
committerVincent Sanders <vince@kyllikki.org>2012-11-11 20:39:08 +0000
commit0c49659f6d956d2d09d5df0b7019dc8f44aa86ed (patch)
treea9760687e987892530bfd2556511f2d5594cf8dd /src
parent21be3e136e5dc995bd53e9484e7693c4efc481b5 (diff)
downloadnsgenbind-0c49659f6d956d2d09d5df0b7019dc8f44aa86ed.tar.gz
nsgenbind-0c49659f6d956d2d09d5df0b7019dc8f44aa86ed.tar.bz2
add AST construction of constants in interfaces
Diffstat (limited to 'src')
-rw-r--r--src/webidl-ast.c4
-rw-r--r--src/webidl-ast.h7
-rw-r--r--src/webidl-parser.y59
3 files changed, 66 insertions, 4 deletions
diff --git a/src/webidl-ast.c b/src/webidl-ast.c
index a1f2276..bc4ab01 100644
--- a/src/webidl-ast.c
+++ b/src/webidl-ast.c
@@ -232,6 +232,7 @@ webidl_node_getint(struct webidl_node *node)
switch(node->type) {
case WEBIDL_NODE_TYPE_MODIFIER:
case WEBIDL_NODE_TYPE_TYPE_BASE:
+ case WEBIDL_NODE_TYPE_LITERAL_INT:
return node->r.number;
default:
@@ -318,6 +319,9 @@ static const char *webidl_node_type_to_str(enum webidl_node_type type)
case WEBIDL_NODE_TYPE_CONST:
return "Const";
+ case WEBIDL_NODE_TYPE_LITERAL_INT:
+ return "Literal (int)";
+
default:
return "Unknown";
}
diff --git a/src/webidl-ast.h b/src/webidl-ast.h
index d891dec..5d7c615 100644
--- a/src/webidl-ast.h
+++ b/src/webidl-ast.h
@@ -22,14 +22,21 @@ enum webidl_node_type {
WEBIDL_NODE_TYPE_INTERFACE,
WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE,
WEBIDL_NODE_TYPE_INTERFACE_IMPLEMENTS,
+
WEBIDL_NODE_TYPE_ATTRIBUTE,
WEBIDL_NODE_TYPE_OPERATION,
WEBIDL_NODE_TYPE_CONST,
+
WEBIDL_NODE_TYPE_OPTIONAL_ARGUMENT,
WEBIDL_NODE_TYPE_ARGUMENT,
WEBIDL_NODE_TYPE_ELLIPSIS,
WEBIDL_NODE_TYPE_TYPE,
WEBIDL_NODE_TYPE_TYPE_BASE,
+ WEBIDL_NODE_TYPE_LITERAL_NULL,
+ WEBIDL_NODE_TYPE_LITERAL_INT,
+ WEBIDL_NODE_TYPE_LITERAL_BOOL,
+ WEBIDL_NODE_TYPE_LITERAL_FLOAT,
+
};
enum webidl_type {
diff --git a/src/webidl-parser.y b/src/webidl-parser.y
index f71c19c..683a1a2 100644
--- a/src/webidl-parser.y
+++ b/src/webidl-parser.y
@@ -15,6 +15,7 @@
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
+#include <math.h>
#include "webidl-ast.h"
@@ -155,12 +156,17 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str)
%type <node> SingleType
%type <node> UnionType
%type <node> NonAnyType
+%type <node> ConstType
%type <node> PrimitiveType
%type <node> UnrestrictedFloatType
%type <node> FloatType
%type <node> UnsignedIntegerType
%type <node> IntegerType
+%type <node> FloatLiteral
+%type <node> BooleanLiteral
+%type <node> ConstValue
+
%type <isit> ReadOnly
%type <isit> OptionalLong
%type <isit> Inherit
@@ -513,13 +519,12 @@ Const:
constant = webidl_node_new(WEBIDL_NODE_TYPE_IDENT, NULL, $3);
/* add constant type */
- //constant = webidl_node_prepend(constant, $2);
+ constant = webidl_node_prepend(constant, $2);
/* add constant value */
- //constant = webidl_node_prepend(constant, $5);
+ constant = webidl_node_prepend(constant, $5);
$$ = webidl_node_new(WEBIDL_NODE_TYPE_CONST, NULL, constant);
-
}
;
@@ -530,26 +535,62 @@ ConstValue:
FloatLiteral
|
TOK_INT_LITERAL
+ {
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_LITERAL_INT, NULL, (void *)$1);
+ }
|
- TOK_NULL_LITERAL
+ TOK_NULL_LITERAL
+ {
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_LITERAL_NULL, NULL, NULL);
+ }
;
/* [28] */
BooleanLiteral:
TOK_TRUE
+ {
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_LITERAL_BOOL, NULL, (void *)true);
+ }
|
TOK_FALSE
+ {
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_LITERAL_BOOL, NULL, (void *)false);
+ }
;
/* [29] */
FloatLiteral:
TOK_FLOAT_LITERAL
+ {
+ float *value;
+ value = malloc(sizeof(float));
+ *value = strtof($1, NULL);
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_LITERAL_FLOAT, NULL, value);
+ }
|
'-' TOK_INFINITY
+ {
+ float *value;
+ value = malloc(sizeof(float));
+ *value = -INFINITY;
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_LITERAL_FLOAT, NULL, value);
+ }
|
TOK_INFINITY
+ {
+ float *value;
+ value = malloc(sizeof(float));
+ *value = INFINITY;
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_LITERAL_FLOAT, NULL, value);
+ }
|
TOK_NAN
+ {
+ float *value;
+ value = malloc(sizeof(float));
+ *value = NAN;
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_LITERAL_FLOAT, NULL, value);
+ }
;
/* [30] */
@@ -1090,8 +1131,18 @@ NonAnyType:
/* [63] */
ConstType:
PrimitiveType Null
+ {
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_TYPE, NULL, $1);
+ }
|
TOK_IDENTIFIER Null
+ {
+ struct webidl_node *type;
+ type = webidl_node_new(WEBIDL_NODE_TYPE_TYPE_BASE, NULL, (void *)WEBIDL_TYPE_USER);
+ type = webidl_node_new(WEBIDL_NODE_TYPE_IDENT, type, $1);
+ $$ = webidl_node_new(WEBIDL_NODE_TYPE_TYPE, NULL, type);
+ }
+
;
/* [64] */