summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-04-04 19:25:54 -0400
committerTavian Barnes <tavianator@gmail.com>2011-04-06 15:01:06 -0400
commit629cad2c7578aea62761ba2e1810356138b57480 (patch)
tree56e89b6efc240c4c90b38997e0ceea844df005b3
parent5a535f9fac3f4b82f0b154b4c81fd1e2a8d62802 (diff)
downloaddimension-629cad2c7578aea62761ba2e1810356138b57480.tar.xz
Don't make empty child arrays when parsing.
-rw-r--r--dimension/common.prologue16
-rw-r--r--dimension/common.rules53
-rw-r--r--dimension/directives.rules9
-rw-r--r--dimension/grammar.rules6
4 files changed, 48 insertions, 36 deletions
diff --git a/dimension/common.prologue b/dimension/common.prologue
index 2830094..649f184 100644
--- a/dimension/common.prologue
+++ b/dimension/common.prologue
@@ -47,6 +47,22 @@
/* Create a new astnode, populating filename, line, and col */
static dmnsn_astnode
+dmnsn_new_astleaf(dmnsn_astnode_type type, YYLTYPE lloc)
+{
+ dmnsn_astnode astnode = {
+ .type = type,
+ .children = NULL,
+ .ptr = NULL,
+ .free_fn = NULL,
+ .refcount = dmnsn_malloc(sizeof(unsigned int)),
+ .location = lloc
+ };
+
+ *astnode.refcount = 1;
+ return astnode;
+}
+
+static dmnsn_astnode
dmnsn_new_astnode(dmnsn_astnode_type type, YYLTYPE lloc)
{
dmnsn_astnode astnode = {
diff --git a/dimension/common.rules b/dimension/common.rules
index 43fef8d..9383d4b 100644
--- a/dimension/common.rules
+++ b/dimension/common.rules
@@ -28,14 +28,14 @@ IDENTIFIER: "identifier" {
id = symbol->ptr;
symbol = dmnsn_find_symbol(symtable, id);
}
- $$ = dmnsn_new_astnode(DMNSN_AST_IDENTIFIER, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_IDENTIFIER, @$);
$$.ptr = dmnsn_strdup(id);
dmnsn_free($1);
}
;
STRING: "string" {
- $$ = dmnsn_new_astnode(DMNSN_AST_STRING, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_STRING, @$);
$$.ptr = $1;
}
;
@@ -152,7 +152,7 @@ TRANSFORMATION_ITEM: IDENTIFIER {
dmnsn_delete_astnode($1);
}
| "inverse" {
- $$ = dmnsn_new_astnode(DMNSN_AST_INVERSE, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_INVERSE, @$);
}
;
@@ -181,7 +181,7 @@ CAMERA_ITEM: CAMERA_TYPE
;
CAMERA_TYPE: "perspective" {
- $$ = dmnsn_new_astnode(DMNSN_AST_PERSPECTIVE, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_PERSPECTIVE, @$);
}
;
@@ -481,8 +481,7 @@ OBJECT_MODIFIER: TRANSFORMATION
/* Patterns */
BLOCK_PATTERN_TYPE: "checker" {
- dmnsn_astnode p
- = dmnsn_new_astnode(DMNSN_AST_CHECKER, @$);
+ dmnsn_astnode p = dmnsn_new_astleaf(DMNSN_AST_CHECKER, @$);
$$ = dmnsn_new_astnode1(DMNSN_AST_PATTERN, @$, p);
}
;
@@ -537,14 +536,14 @@ PIGMENT_BODY: PIGMENT_TYPE PIGMENT_MODIFIERS {
$$ = dmnsn_new_astnode2(DMNSN_AST_PIGMENT, @$, $1, $2);
}
| "checker" COLOR_LIST2 PIGMENT_MODIFIERS {
- dmnsn_astnode checker = dmnsn_new_astnode(DMNSN_AST_CHECKER, @1);
+ dmnsn_astnode checker = dmnsn_new_astleaf(DMNSN_AST_CHECKER, @1);
dmnsn_astnode pattern = dmnsn_new_astnode1(DMNSN_AST_PATTERN, @1,
checker);
dmnsn_array_push($3.children, &$2);
$$ = dmnsn_new_astnode2(DMNSN_AST_PIGMENT, @$, pattern, $3);
}
| "checker" PIGMENT_LIST2 PIGMENT_MODIFIERS {
- dmnsn_astnode checker = dmnsn_new_astnode(DMNSN_AST_CHECKER, @1);
+ dmnsn_astnode checker = dmnsn_new_astleaf(DMNSN_AST_CHECKER, @1);
dmnsn_astnode pattern = dmnsn_new_astnode1(DMNSN_AST_PATTERN, @1,
checker);
dmnsn_array_push($3.children, &$2);
@@ -564,13 +563,13 @@ PIGMENT_TYPE: COLOR
STRING
"}"
{
- dmnsn_astnode type = dmnsn_new_astnode(DMNSN_AST_PNG, @$);
+ dmnsn_astnode type = dmnsn_new_astleaf(DMNSN_AST_PNG, @$);
$$ = dmnsn_new_astnode2(DMNSN_AST_IMAGE_MAP, @$, type, $3);
}
;
BITMAP_TYPE: "png" {
- $$ = dmnsn_new_astnode(DMNSN_AST_PNG, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_PNG, @$);
}
;
@@ -771,12 +770,12 @@ INT: FLOAT {
;
FLOAT_LITERAL: "integer" {
- dmnsn_astnode string = dmnsn_new_astnode(DMNSN_AST_STRING, @$);
+ dmnsn_astnode string = dmnsn_new_astleaf(DMNSN_AST_STRING, @$);
string.ptr = $1;
$$ = dmnsn_new_astnode1(DMNSN_AST_VAL, @$, string);
}
| "float" {
- dmnsn_astnode string = dmnsn_new_astnode(DMNSN_AST_STRING, @$);
+ dmnsn_astnode string = dmnsn_new_astleaf(DMNSN_AST_STRING, @$);
string.ptr = $1;
$$ = dmnsn_new_astnode1(DMNSN_AST_VAL, @$, string);
}
@@ -987,26 +986,26 @@ ARITH_EXPR: FLOAT_LITERAL
$$ = dmnsn_new_astnode2(DMNSN_AST_VROTATE, @$, $3, $5);
}
| "image_height" {
- $$ = dmnsn_new_astnode(DMNSN_AST_IDENTIFIER, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_IDENTIFIER, @$);
$$.ptr = dmnsn_strdup("image_height");
}
| "image_width" {
- $$ = dmnsn_new_astnode(DMNSN_AST_IDENTIFIER, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_IDENTIFIER, @$);
$$.ptr = dmnsn_strdup("image_width");
}
- | "pi" { $$ = dmnsn_new_astnode(DMNSN_AST_PI, @$); }
- | "true" { $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); }
- | "on" { $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); }
- | "yes" { $$ = dmnsn_new_astnode(DMNSN_AST_TRUE, @$); }
- | "false" { $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); }
- | "off" { $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); }
- | "no" { $$ = dmnsn_new_astnode(DMNSN_AST_FALSE, @$); }
- | "x" { $$ = dmnsn_new_astnode(DMNSN_AST_X, @$); }
- | "u" { $$ = dmnsn_new_astnode(DMNSN_AST_X, @$); }
- | "y" { $$ = dmnsn_new_astnode(DMNSN_AST_Y, @$); }
- | "v" { $$ = dmnsn_new_astnode(DMNSN_AST_Y, @$); }
- | "z" { $$ = dmnsn_new_astnode(DMNSN_AST_Z, @$); }
- | "t" { $$ = dmnsn_new_astnode(DMNSN_AST_T, @$); }
+ | "pi" { $$ = dmnsn_new_astleaf(DMNSN_AST_PI, @$); }
+ | "true" { $$ = dmnsn_new_astleaf(DMNSN_AST_TRUE, @$); }
+ | "on" { $$ = dmnsn_new_astleaf(DMNSN_AST_TRUE, @$); }
+ | "yes" { $$ = dmnsn_new_astleaf(DMNSN_AST_TRUE, @$); }
+ | "false" { $$ = dmnsn_new_astleaf(DMNSN_AST_FALSE, @$); }
+ | "off" { $$ = dmnsn_new_astleaf(DMNSN_AST_FALSE, @$); }
+ | "no" { $$ = dmnsn_new_astleaf(DMNSN_AST_FALSE, @$); }
+ | "x" { $$ = dmnsn_new_astleaf(DMNSN_AST_X, @$); }
+ | "u" { $$ = dmnsn_new_astleaf(DMNSN_AST_X, @$); }
+ | "y" { $$ = dmnsn_new_astleaf(DMNSN_AST_Y, @$); }
+ | "v" { $$ = dmnsn_new_astleaf(DMNSN_AST_Y, @$); }
+ | "z" { $$ = dmnsn_new_astleaf(DMNSN_AST_Z, @$); }
+ | "t" { $$ = dmnsn_new_astleaf(DMNSN_AST_T, @$); }
| IDENTIFIER
;
diff --git a/dimension/directives.rules b/dimension/directives.rules
index a3c53d2..b9c6cc6 100644
--- a/dimension/directives.rules
+++ b/dimension/directives.rules
@@ -130,8 +130,7 @@ DECL_PARAMS: /* empty */ {
;
DECL_PARAM_LIST: IDENTIFIER {
- $$ = dmnsn_new_astnode(DMNSN_AST_MACRO, @$);
- dmnsn_array_push($$.children, &$1);
+ $$ = dmnsn_new_astnode1(DMNSN_AST_MACRO, @$, $1);
}
| DECL_PARAM_LIST "," IDENTIFIER {
$$ = $1;
@@ -146,12 +145,10 @@ PARAMS: /* empty */ {
;
PARAM_LIST: IDENTIFIER %dprec 2 {
- $$ = dmnsn_new_astnode(DMNSN_AST_MACRO, @$);
- dmnsn_array_push($$.children, &$1);
+ $$ = dmnsn_new_astnode1(DMNSN_AST_MACRO, @$, $1);
}
| PARAM %dprec 1 {
- $$ = dmnsn_new_astnode(DMNSN_AST_MACRO, @$);
- dmnsn_array_push($$.children, &$1);
+ $$ = dmnsn_new_astnode1(DMNSN_AST_MACRO, @$, $1);
}
| PARAM_LIST "," IDENTIFIER %dprec 2 {
$$ = $1;
diff --git a/dimension/grammar.rules b/dimension/grammar.rules
index cf002cb..5f08e20 100644
--- a/dimension/grammar.rules
+++ b/dimension/grammar.rules
@@ -82,13 +82,13 @@ GLOBAL_SETTINGS_ITEM: "ambient_light" COLOR {
;
GLOBAL_CHARSET: "ascii" {
- $$ = dmnsn_new_astnode(DMNSN_AST_ASCII, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_ASCII, @$);
}
| "utf8" {
- $$ = dmnsn_new_astnode(DMNSN_AST_UTF8, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_UTF8, @$);
}
| "sys" {
- $$ = dmnsn_new_astnode(DMNSN_AST_SYS, @$);
+ $$ = dmnsn_new_astleaf(DMNSN_AST_SYS, @$);
}
/* Atmospheric effects */