From 8b9b6332cc31a76385eeb4bdd47e1ae5ce675f3d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 11 Feb 2009 04:27:44 +0000 Subject: [PATCH] changed getPtr() to isNull() in util/refptr, filled in parser logic a lot more git-svn-id: svn://anubis/fart/trunk@99 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- parser/parser.yy | 100 +++++++++++++++++++++++++++++------------------ util/refptr.h | 2 +- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/parser/parser.yy b/parser/parser.yy index 0e96ab3..2ccc5b2 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -31,12 +31,20 @@ class Node { public: Node(); - ~Node(); int type; - double * the_double; - Material * the_Material; - Shape * the_Shape; - Vector * the_Vector; + refptr the_double; + refptr the_Material; + refptr the_Node; + refptr the_tail; + refptr the_Shape; + refptr the_Vector; +}; + +enum Node_Type +{ + Node_Shape = 0x42001, /* don't clash with bison token namespace */ + Node_Camera, + Node_Options }; static Scene * g_scene; @@ -96,9 +104,9 @@ static Scene * g_scene; %% -scene: /* empty */ - | scene_spec { printf("Saw a scene\n"); } - ; +scene: SCENE LCURLY scene_items RCURLY { + } + ; boolean_items: shape shape boolean_items_more ; @@ -110,10 +118,14 @@ boolean_items_more: /* empty */ box: BOX LPAREN vector RPAREN LCURLY box_items RCURLY ; -box_items: shape_items +box_items: shape_items { $$ = $1; } ; -camera: CAMERA LCURLY camera_items RCURLY +camera: CAMERA LCURLY camera_items RCURLY { + Vector default_position(0, -1, 0); + Vector default_look_at(0, 0, 0); + Vector default_up(0, 0, 1); + } ; camera_items: /* empty */ @@ -183,6 +195,34 @@ number: DEC_NUMBER { } ; +options: OPTIONS LCURLY options_items RCURLY { $$ = $3; } + ; + +options_items: /* empty */ + | options_item options_items { + $$ = new Node(); + $$->the_Node = $1; + $$->the_tail = $2; + } + ; + +options_item: WIDTH number { + $$ = new Node(); + $$->type = WIDTH; + $$->the_double = $2->the_double; + } + | HEIGHT number { + $$ = new Node(); + $$->type = HEIGHT; + $$->the_double = $2->the_double; + } + | MULTISAMPLE number { + $$ = new Node(); + $$->type = MULTISAMPLE; + $$->the_double = $2->the_double; + } + ; + plane: PLANE LPAREN vector COMMA number RPAREN LCURLY plane_items RCURLY { Plane * plane = new Plane((*($3->the_Vector))[0], (*($3->the_Vector))[1], @@ -193,18 +233,20 @@ plane: PLANE LPAREN vector COMMA number RPAREN LCURLY plane_items RCURLY { } ; -plane_items: shape_items +plane_items: shape_items { $$ = $1; } ; -scene_spec: SCENE LCURLY scene_items RCURLY - ; - scene_items: /* empty */ - | scene_item scene_items + | scene_item scene_items { + $$ = new Node(); + $$->the_Node = $1; + $$->the_tail = $2; + } ; -scene_item: camera { $$ = $1; } - | shape { $$ = $1; } +scene_item: camera { $$ = $1; $$->type = Node_Camera; } + | shape { $$ = $1; $$->type = Node_Shape; } + | options { $$ = $1; $$->type = Node_Options; } ; shape: plane { $$ = $1; } @@ -226,7 +268,7 @@ sphere: SPHERE LPAREN number RPAREN LCURLY sphere_items RCURLY { } ; -sphere_items: shape_items +sphere_items: shape_items { $$ = $1; } ; subtract: SUBTRACT LCURLY boolean_items RCURLY @@ -237,9 +279,9 @@ union: UNION LCURLY boolean_items RCURLY vector: LESS number COMMA number COMMA number GREATER { Vector * ptr = new Vector(); - (*ptr)[0] = * (double *) $2->the_double; - (*ptr)[1] = * (double *) $4->the_double; - (*ptr)[2] = * (double *) $6->the_double; + (*ptr)[0] = * $2->the_double; + (*ptr)[1] = * $4->the_double; + (*ptr)[2] = * $6->the_double; $$ = new Node(); $$->the_Vector = ptr; } @@ -262,20 +304,4 @@ int parse(Scene * scene, const char * fileName) Node::Node() { type = -1; - the_double = NULL; - the_Material = NULL; - the_Shape = NULL; - the_Vector = NULL; -} - -Node::~Node() -{ - if (the_double != NULL) - delete the_double; - if (the_Material != NULL) - delete the_Material; - if (the_Shape != NULL) - delete the_Shape; - if (the_Vector != NULL) - delete the_Vector; } diff --git a/util/refptr.h b/util/refptr.h index 1571f48..1f33df1 100644 --- a/util/refptr.h +++ b/util/refptr.h @@ -16,7 +16,7 @@ class refptr ~refptr(); T & operator*() const; T * operator->() const; - T * getPtr() const { return m_ptr; } + bool isNull() const { return m_ptr == NULL; } private: void cloneFrom(const refptr & orig);