mojoshader_compiler.c
changeset 920 d943a995ee1b
parent 918 b7644336f032
child 921 97b879e372c6
--- a/mojoshader_compiler.c	Thu Oct 14 01:48:27 2010 -0400
+++ b/mojoshader_compiler.c	Tue Oct 19 16:12:44 2010 -0400
@@ -1456,6 +1456,7 @@
 #include "mojoshader_parser_hlsl.h"
 
 
+// !!! FIXME: this screws up on order of operations.
 static void print_ast(const int substmt, void *ast)
 {
     const char *nl = substmt ? "" : "\n";
@@ -1723,8 +1724,15 @@
             break;
 
         case AST_OP_FLOAT_LITERAL:
-            printf("%f", ((ExpressionFloatLiteral *) ast)->value);
+        {
+            const float f = ((ExpressionFloatLiteral *) ast)->value;
+            const long long flr = (long long) f;
+            if (((float) flr) == f)
+                printf("%lld.0", flr);
+            else
+                printf("%.16g", f);
             break;
+        } // case
 
         case AST_OP_STRING_LITERAL:
             printf("\"%s\"", ((ExpressionStringLiteral *) ast)->string);
@@ -1850,7 +1858,11 @@
 
             printf("for (");
             print_ast(1, ((ForStatement *) ast)->var_decl);
-            print_ast(1, ((ForStatement *) ast)->initializer);
+            if (((ForStatement *) ast)->initializer != NULL)
+            {
+                printf(" = ");
+                print_ast(1, ((ForStatement *) ast)->initializer);
+            } // if
             printf("; ");
             print_ast(1, ((ForStatement *) ast)->looptest);
             printf("; ");
@@ -2028,7 +2040,10 @@
             } // switch
 
             if (((FunctionArguments *) ast)->initializer)
+            {
+                printf(" = ");
                 print_ast(0, ((FunctionArguments *) ast)->initializer);
+            } // if
 
             if (((FunctionArguments *) ast)->next)
             {
@@ -2117,7 +2132,11 @@
                 printf(" ");
                 print_ast(0, ((VariableDeclaration *) ast)->annotations);
             } // if
-            print_ast(0, ((VariableDeclaration *) ast)->initializer);
+            if (((VariableDeclaration *) ast)->initializer != NULL)
+            {
+                printf(" = ");
+                print_ast(0, ((VariableDeclaration *) ast)->initializer);
+            } // if
             print_ast(0, ((VariableDeclaration *) ast)->lowlevel);
 
             if (((VariableDeclaration *) ast)->next == NULL)
@@ -2152,7 +2171,11 @@
             while (a)
             {
                 printf(" %s ", a->datatype);
-                print_ast(0, a->initializer);
+                if (a->initializer != NULL)
+                {
+                    printf(" = ");
+                    print_ast(0, a->initializer);
+                } // if
                 if (a->next)
                     printf(",");
                 a = a->next;