Uncommented some grammar bits that got masked out in the calculator experiment.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 20 Feb 2010 00:27:28 -0500
changeset 837 5f6528602658
parent 836 d975fa785f1e
child 838 37e901d1b7bf
Uncommented some grammar bits that got masked out in the calculator experiment.
mojoshader_compiler.c
mojoshader_parser_hlsl.lemon
--- a/mojoshader_compiler.c	Fri Feb 19 02:28:44 2010 -0500
+++ b/mojoshader_compiler.c	Sat Feb 20 00:27:28 2010 -0500
@@ -88,6 +88,9 @@
     OP_FLOAT_LITERAL,
     OP_STRING_LITERAL,
     OP_END_RANGE_DATA,
+
+    OP_CONSTRUCTOR,
+    OP_CAST
 } Operator;
 
 typedef enum VariableAttributes
@@ -189,6 +192,20 @@
     const char *string;
 } ExpressionStringLiteral;
 
+typedef struct ExpressionConstructor
+{
+    Operator op;  // Always OP_CONSTRUCTOR
+    const char *datatype;
+    Expression *args;
+} ExpressionConstructor;
+
+typedef struct ExpressionCast
+{
+    Operator op;  // Always OP_CAST
+    const char *datatype;
+    Expression *operand;
+} ExpressionCast;
+
 typedef enum CompilationUnitType
 {
     COMPUNITTYPE_FUNCTION,  // function declaration or definition
@@ -517,6 +534,26 @@
 static void delete_compilation_unit(Context *ctx, CompilationUnit *unit);
 static void delete_statement(Context *ctx, Statement *stmt);
 
+static Expression *new_constructor_expr(Context *ctx, const char *datatype,
+                                        Expression *args)
+{
+    NEW_AST_NODE(ExpressionConstructor);
+    retval->op = OP_CONSTRUCTOR;
+    retval->datatype = datatype;
+    retval->args = args;
+    return (Expression *) retval;
+} // new_constructor_expr
+
+static Expression *new_cast_expr(Context *ctx, const char *datatype,
+                                 Expression *operand)
+{
+    NEW_AST_NODE(ExpressionCast);
+    retval->op = OP_CAST;
+    retval->datatype = datatype;
+    retval->operand = operand;
+    return (Expression *) retval;
+} // new_cast_expr
+
 static Expression *new_unary_expr(Context *ctx, const Operator op,
                                   Expression *operand)
 {
@@ -604,9 +641,14 @@
         delete_expr(ctx, ternary->center);
         delete_expr(ctx, ternary->right);
     } // else if
-
-    // don't need to free extra fields in other types at the moment.
-
+    else if (expr->op == OP_CAST)
+    {
+        delete_expr(ctx, ((ExpressionCast *) expr)->operand);
+    } // else if
+    else if (expr->op == OP_CONSTRUCTOR)
+    {
+        delete_expr(ctx, ((ExpressionConstructor *) expr)->args);
+    } // else if
     Free(ctx, expr);
 } // delete_expr
 
--- a/mojoshader_parser_hlsl.lemon	Fri Feb 19 02:28:44 2010 -0500
+++ b/mojoshader_parser_hlsl.lemon	Sat Feb 20 00:27:28 2010 -0500
@@ -591,7 +591,7 @@
 postfix_expr(A) ::= postfix_expr(B) LBRACKET expression(C) RBRACKET. { A = new_binary_expr(ctx, OP_DEREF_ARRAY, B, C); }
 postfix_expr(A) ::= postfix_expr(B) LPAREN RPAREN. { A = new_binary_expr(ctx, OP_CALLFUNC, B, NULL); }
 postfix_expr(A) ::= postfix_expr(B) LPAREN argument_expr_list(C) RPAREN. { A = new_binary_expr(ctx, OP_CALLFUNC, B, C); }
-//postfix_expr(A) ::= datatype(B) LPAREN argument_expr_list(C) RPAREN. { A = new_constructor_expr(ctx, B, C); } // HLSL constructor
+postfix_expr(A) ::= datatype(B) LPAREN argument_expr_list(C) RPAREN. { A = NULL; new_constructor_expr(ctx, B, C); } // HLSL constructor
 postfix_expr(A) ::= postfix_expr(B) DOT IDENTIFIER(C). { A = new_binary_expr(ctx, OP_DEREF_STRUCT, B, new_identifier_expr(ctx, C.string)); }
 postfix_expr(A) ::= postfix_expr(B) PLUSPLUS. { A = new_unary_expr(ctx, OP_POSTINCREMENT, B); }
 postfix_expr(A) ::= postfix_expr(B) MINUSMINUS. { A = new_unary_expr(ctx, OP_POSTDECREMENT, B); }
@@ -614,7 +614,7 @@
 %type cast_expr { Expression * }
 %destructor cast_expr { delete_expr(ctx, $$); }
 cast_expr(A) ::= unary_expr(B). { A = B; }
-//cast_expr(A) ::= LPAREN datatype(B) RPAREN cast_expr(C). { A = new_cast_expr(ctx, B, C); }
+cast_expr(A) ::= LPAREN datatype(B) RPAREN cast_expr(C). { A = new_cast_expr(ctx, B, C); }
 
 %type multiplicative_expr { Expression * }
 %destructor multiplicative_expr { delete_expr(ctx, $$); }