Skip to content

Commit

Permalink
More output fixes for print_ast().
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 19, 2010
1 parent b3de19c commit 6451750
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions mojoshader_compiler.c
Expand Up @@ -1456,6 +1456,7 @@ static int is_usertype(const Context *ctx, const char *token)
#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";
Expand Down Expand Up @@ -1723,8 +1724,15 @@ static void print_ast(const int substmt, void *ast)
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);
Expand Down Expand Up @@ -1850,7 +1858,11 @@ static void print_ast(const int substmt, void *ast)

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("; ");
Expand Down Expand Up @@ -2028,7 +2040,10 @@ static void print_ast(const int substmt, void *ast)
} // switch

if (((FunctionArguments *) ast)->initializer)
{
printf(" = ");
print_ast(0, ((FunctionArguments *) ast)->initializer);
} // if

if (((FunctionArguments *) ast)->next)
{
Expand Down Expand Up @@ -2117,7 +2132,11 @@ static void print_ast(const int substmt, void *ast)
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)
Expand Down Expand Up @@ -2152,7 +2171,11 @@ static void print_ast(const int substmt, void *ast)
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;
Expand Down

0 comments on commit 6451750

Please sign in to comment.