From 32de568d1c03eedb42db3fb4b7339576e57f4faa Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 31 Jan 2012 13:41:26 +1000 Subject: Fix a bunch of statement ignorables. --- LuaSL/src/LuaSL_LSL_tree.h | 2 +- LuaSL/src/LuaSL_compile.c | 88 ++++++++++++++++++++++++++++++++++-------- LuaSL/src/LuaSL_lemon_yaccer.y | 34 ++++++++-------- 3 files changed, 90 insertions(+), 34 deletions(-) (limited to 'LuaSL') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 931537c..dd46167 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -396,7 +396,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam); LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifier, LSL_Leaf *block); -LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Type type, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block, LSL_Leaf *identifier); +LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block, LSL_Leaf *identifier); LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr); LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index dc2dd5c..00f41da 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -584,7 +584,7 @@ LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf if (function) { function->value.functionValue->block = block->value.blockValue; - statement = addStatement(compiler, NULL, LSL_FUNCTION, NULL, function, NULL, NULL, NULL); + statement = addStatement(compiler, NULL, function, NULL, function, NULL, NULL, NULL); } return statement; @@ -676,17 +676,18 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi return identifier; } -LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Type type, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block, LSL_Leaf *identifier) +LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block, LSL_Leaf *identifier) { gameGlobals *game = compiler->game; LSL_Statement *stat = calloc(1, sizeof(LSL_Statement)); + boolean justOne = FALSE; if (NULL == lval) lval = newLeaf(LSL_STATEMENT, NULL, NULL); if (stat) { - stat->type = type; + stat->type = flow->toKen->type; stat->expressions = expr; if (block) stat->block = block->value.blockValue; @@ -701,17 +702,7 @@ LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Type type, stat->parenthesis = parens->value.parenthesis; } - if (lval) - { -#if LUASL_DIFF_CHECK - stat->ignorable = calloc(1, sizeof(Eina_Strbuf *)); - stat->ignorable[0] = lval->ignorable; - lval->ignorable = NULL; -#endif - lval->value.statementValue = stat; - } - - switch (type) + switch (stat->type) { case LSL_EXPRESSION : { @@ -731,28 +722,37 @@ LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Type type, } case LSL_IF : { + justOne = TRUE; break; } case LSL_ELSE : { + justOne = TRUE; break; } case LSL_JUMP : { + justOne = TRUE; break; } case LSL_RETURN : { + justOne = TRUE; break; } case LSL_STATE_CHANGE : { + justOne = TRUE; + break; + } + case LSL_STATEMENT : + { break; } case LSL_WHILE : { stat->identifier = NULL; - // TODO - need to stash the while's white space somewhere. + justOne = TRUE; break; } case LSL_IDENTIFIER : @@ -765,11 +765,34 @@ LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Type type, } default : { - PE("Should not be here %d.", type); + PE("Should not be here %d.", stat->type); break; } } + if (justOne && (flow)) + { + stat->ignorable = calloc(2, sizeof(Eina_Strbuf *)); + if (stat->ignorable) + { + stat->ignorable[1] = flow->ignorable; + flow->ignorable = NULL; + } + } + + if (lval) + { +#if LUASL_DIFF_CHECK + if (NULL == stat->ignorable) + stat->ignorable = calloc(1, sizeof(Eina_Strbuf *)); + if (stat->ignorable) + { + stat->ignorable[0] = lval->ignorable; + lval->ignorable = NULL; + } +#endif + lval->value.statementValue = stat; + } } return lval; @@ -1195,6 +1218,11 @@ static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_L { break; } + case LSL_STATEMENT : + { + result = evaluateLeaf(content->value.statementValue->expressions, left, right); + break; + } case LSL_WHILE : { break; @@ -1326,32 +1354,60 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state case LSL_IF : { isBlock = TRUE; +#if LUASL_DIFF_CHECK + if ((statement->ignorable) && (statement->ignorable[1])) + fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); +#endif fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); break; } case LSL_ELSE : { +#if LUASL_DIFF_CHECK + if ((statement->ignorable) && (statement->ignorable[1])) + fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); +#endif fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); break; } case LSL_JUMP : { +#if LUASL_DIFF_CHECK + if ((statement->ignorable) && (statement->ignorable[1])) + fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); +#endif fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); break; } case LSL_RETURN : { +#if LUASL_DIFF_CHECK + if ((statement->ignorable) && (statement->ignorable[1])) + fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); +#endif fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); break; } case LSL_STATE_CHANGE : { +#if LUASL_DIFF_CHECK + if ((statement->ignorable) && (statement->ignorable[1])) + fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); +#endif fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); break; } + case LSL_STATEMENT : + { + break; + } case LSL_WHILE : { isBlock = TRUE; +#if LUASL_DIFF_CHECK + if ((statement->ignorable) && (statement->ignorable[1])) + fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); +#endif fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); break; } diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 6a489f3..bbc4939 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -43,7 +43,7 @@ functionList(A) ::= functionBody(C). { A = collectStatements(compiler, NULL // No such thing as a function list with no functions. //functionList(A) ::= . { A = collectStatements(compiler, NULL, NULL); } -functionBody(A) ::= function(F) block(B). { A = addFunctionBody(compiler, F, B); } // addFunctionBody has an implied addStatement(compiler, NULL, LSL_FUNCTION, NULL, B, NULL, NULL); +functionBody(A) ::= function(F) block(B). { A = addFunctionBody(compiler, F, B); } // addFunctionBody has an implied addStatement(compiler, NULL, F, NULL, B, NULL, NULL); parameterList(A) ::= parameterList(B) LSL_COMMA(C) parameter(D). { A = collectParameters(compiler, B, C, D); } parameterList(A) ::= parameter(D). { A = collectParameters(compiler, NULL, NULL, D); } @@ -67,31 +67,31 @@ statementList(A) ::= . { A = collectStatements(compiler, NULL, NULL); } %nonassoc LSL_DO LSL_FOR LSL_IF LSL_JUMP LSL_RETURN LSL_STATE_CHANGE LSL_WHILE. %nonassoc LSL_ELSE. -statement(A) ::= LSL_DO(F) block(B) LSL_WHILE(W) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, L, E, R, B, W); } -statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) block(B). { A = addStatement(compiler, NULL, F->toKen->type, L, E1, R, B, NULL); } // three expressions, two semi colons -statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) statement(S). { A = addStatement(compiler, S, F->toKen->type, L, E1, R, NULL, NULL); } // three expressions, two semi colons +statement(A) ::= LSL_DO(F) block(B) LSL_WHILE(W) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, L, E, R, B, W); } +statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) block(B). { A = addStatement(compiler, NULL, F, L, E1, R, B, NULL); } // three expressions, two semi colons +statement(A) ::= LSL_FOR(F) LSL_PARENTHESIS_OPEN(L) expr(E0) LSL_STATEMENT(S0) expr(E1) LSL_STATEMENT(S1) expr(E2) LSL_PARENTHESIS_CLOSE(R) statement(S). { A = addStatement(compiler, S, F, L, E1, R, NULL, NULL); } // three expressions, two semi colons statement(A) ::= ifBlock(B). { A = B; } ifBlock ::= ifBlock LSL_ELSE block. ifBlock ::= ifBlock LSL_ELSE statement. -ifBlock(A) ::= LSL_IF(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) block(B). [LSL_ELSE] { A = addStatement(compiler, NULL, F->toKen->type, L, E, R, B, NULL); } -ifBlock(A) ::= LSL_IF(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) statement(S). [LSL_ELSE] { A = addStatement(compiler, S, F->toKen->type, L, E, R, NULL, NULL); } +ifBlock(A) ::= LSL_IF(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) block(B). [LSL_ELSE] { A = addStatement(compiler, NULL, F, L, E, R, B, NULL); } +ifBlock(A) ::= LSL_IF(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) statement(S). [LSL_ELSE] { A = addStatement(compiler, S, F, L, E, R, NULL, NULL); } -statement(A) ::= LSL_JUMP(F) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, NULL, NULL, NULL, NULL, I); } -statement(A) ::= LSL_RETURN(F) expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, NULL, E, NULL, NULL, NULL); } -statement(A) ::= LSL_RETURN(F) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, NULL, NULL, NULL, NULL, NULL); } -statement(A) ::= LSL_STATE_CHANGE(F) LSL_DEFAULT(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, NULL, NULL, NULL, NULL, I); } -statement(A) ::= LSL_STATE_CHANGE(F) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, NULL, NULL, NULL, NULL, I); } -statement(A) ::= LSL_WHILE(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) block(B). { A = addStatement(compiler, NULL, F->toKen->type, L, E, R, B, NULL); } -statement(A) ::= LSL_WHILE(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) statement(S). { A = addStatement(compiler, S, F->toKen->type, L, E, R, NULL, NULL); } +statement(A) ::= LSL_JUMP(F) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, NULL, NULL, NULL, NULL, I); } +statement(A) ::= LSL_RETURN(F) expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, NULL, E, NULL, NULL, NULL); } +statement(A) ::= LSL_RETURN(F) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, NULL, NULL, NULL, NULL, NULL); } +statement(A) ::= LSL_STATE_CHANGE(F) LSL_DEFAULT(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, NULL, NULL, NULL, NULL, I); } +statement(A) ::= LSL_STATE_CHANGE(F) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, NULL, NULL, NULL, NULL, I); } +statement(A) ::= LSL_WHILE(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) block(B). { A = addStatement(compiler, NULL, F, L, E, R, B, NULL); } +statement(A) ::= LSL_WHILE(F) LSL_PARENTHESIS_OPEN(L) expr(E) LSL_PARENTHESIS_CLOSE(R) statement(S). { A = addStatement(compiler, S, F, L, E, R, NULL, NULL); } %nonassoc LSL_LABEL. -statement(A) ::= LSL_LABEL(F) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F->toKen->type, NULL, NULL, NULL, NULL, I); } +statement(A) ::= LSL_LABEL(F) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, F, NULL, NULL, NULL, NULL, I); } beginBlock(A) ::= LSL_BLOCK_OPEN(B). { A = beginBlock(compiler, B); } // This might be bogus, or might be valid LSL, but it lets us test the expression parser by evaluating them. -statement(A) ::= expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, LSL_EXPRESSION, NULL, E, NULL, NULL, NULL); } +statement(A) ::= expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, S, NULL, E, NULL, NULL, NULL); } // Various forms of expression. @@ -177,8 +177,8 @@ expr(A) ::= identifier(B) LSL_ASSIGNMENT_PLAIN(C) expr(D). { A = addOperation(c // Hmm think this can have commas seperating the assignment parts, or is that only in C?. If so, best to separate them when converting to Lua, as it uses that syntax for something else. // Well, not in OpenSim at least, nor in SL. So we are safe. B-) // On the other hand, it might be legal to have comma separated bits in a for loop - for ((i = 1), (j=1); ... -statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, LSL_IDENTIFIER, NULL, addVariable(compiler, T, I, D, E), NULL, NULL, I); } -statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, LSL_IDENTIFIER, NULL, addVariable(compiler, T, I, NULL, NULL), NULL, NULL, I); } +statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, D, E), NULL, NULL, I); } +statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, NULL, NULL), NULL, NULL, I); } %right LSL_DOT LSL_IDENTIFIER LSL_FUNCTION_CALL LSL_VARIABLE. identifier(A) ::= identifier LSL_DOT LSL_IDENTIFIER(B). { A = checkVariable(compiler, B); A->basicType = OT_float; } // Just a stub to get it to work for now. -- cgit v1.1