mojoshader_compiler.c
changeset 928 c9b0235e9d23
parent 927 0e8b7f053a45
child 929 5d2d66bd35e7
--- a/mojoshader_compiler.c	Mon Oct 25 16:47:26 2010 -0400
+++ b/mojoshader_compiler.c	Tue Oct 26 02:05:21 2010 -0400
@@ -59,7 +59,6 @@
 
     AST_OP_START_RANGE_BINARY,
     AST_OP_DEREF_ARRAY,
-    AST_OP_DEREF_STRUCT,
     AST_OP_COMMA,
     AST_OP_MULTIPLY,
     AST_OP_DIVIDE,
@@ -105,6 +104,7 @@
     AST_OP_END_RANGE_DATA,
 
     AST_OP_START_RANGE_MISC,
+    AST_OP_DEREF_STRUCT,
     AST_OP_CALLFUNC,
     AST_OP_CONSTRUCTOR,
     AST_OP_CAST,
@@ -281,6 +281,13 @@
     Arguments *args;
 } ExpressionConstructor;
 
+typedef struct ExpressionDerefStruct
+{
+    ASTNode ast;  // Always AST_OP_DEREF_STRUCT
+    Expression *identifier;
+    const char *member;
+} ExpressionDerefStruct;
+
 typedef struct ExpressionCallFunction
 {
     ASTNode ast;  // Always AST_OP_CALLFUNC
@@ -809,6 +816,15 @@
     return (Expression *) retval;
 } // new_ternary_expr
 
+static Expression *new_deref_struct_expr(Context *ctx, Expression *identifier,
+                                         const char *member)
+{
+    NEW_AST_NODE(retval, ExpressionDerefStruct, AST_OP_DEREF_STRUCT);
+    retval->identifier = identifier;
+    retval->member = member;  // cached; don't copy string.
+    return (Expression *) retval;
+} // new_deref_struct_expr
+
 static Expression *new_identifier_expr(Context *ctx, const char *string)
 {
     NEW_AST_NODE(retval, ExpressionIdentifier, AST_OP_IDENTIFIER);
@@ -875,6 +891,10 @@
     {
         delete_arguments(ctx, ((ExpressionConstructor *) expr)->args);
     } // else if
+    else if (expr->ast.type == AST_OP_DEREF_STRUCT)
+    {
+        delete_expr(ctx, ((ExpressionDerefStruct *) expr)->identifier);
+    } // else if
     else if (expr->ast.type == AST_OP_CALLFUNC)
     {
         delete_expr(ctx, ((ExpressionCallFunction *) expr)->identifier);
@@ -1601,9 +1621,9 @@
             break;
 
         case AST_OP_DEREF_STRUCT:
-            print_ast(0, ((ExpressionBinary *) ast)->left);
+            print_ast(0, ((ExpressionDerefStruct *) ast)->identifier);
             printf(".");
-            print_ast(0, ((ExpressionBinary *) ast)->right);
+            printf("%s", ((ExpressionDerefStruct *) ast)->member);
             break;
 
         case AST_OP_COMMA: