From 0d4da92f1e19d786d8ac9a1ff10270d2eca46765 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 21 Jan 2012 12:31:56 +1000 Subject: More stuff for parsing blocks and their statement lists. --- LuaSL/src/LuaSL_compile.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'LuaSL/src/LuaSL_compile.c') diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 29c45f3..b1efddd 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -7,6 +7,7 @@ static LSL_Leaf *evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *ri static LSL_Leaf *evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); static LSL_Leaf *eveluateParenthesisToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); +static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content); static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content); @@ -129,7 +130,7 @@ LSL_Token LSL_Tokens[] = {LSL_STATEMENT, ST_NONE, ";", LSL_NOIGNORE, outputStatementToken, evaluateStatementToken}, {LSL_BLOCK_CLOSE, ST_NONE, "}", LSL_NONE, NULL, NULL}, - {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, NULL, NULL}, + {LSL_BLOCK_OPEN, ST_NONE, "{", LSL_NONE, outputBlockToken, NULL}, {LSL_PARAMETER, ST_NONE, "parameter", LSL_NONE, outputIdentifierToken, NULL}, {LSL_PARAMETER_LIST, ST_NONE, "plist", LSL_NONE, outputParameterListToken, NULL}, {LSL_FUNCTION, ST_NONE, "function", LSL_NONE, outputFunctionToken, NULL}, @@ -547,6 +548,7 @@ LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) { stat->type = type; stat->expressions = expr; + eina_clist_element_init(&(stat->statement)); if (lval) lval->value.statementValue = stat; } @@ -554,6 +556,31 @@ LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) return lval; } +LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *statement) +{ + if (NULL == list) + { + list = newLeaf(LSL_BLOCK_OPEN, NULL, NULL); + if (list) + { + list->value.blockValue = compiler->currentBlock; // Maybe NULL. + } + } + + if (list) + { + if (statement) + { + if (list->value.blockValue) + { + eina_clist_add_tail(&(list->value.blockValue->statements), &(statement->value.statementValue->statement)); + } + } + } + + return list; +} + LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr) { addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval); @@ -604,6 +631,7 @@ void beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block) if (blok) { + eina_clist_init(&(blok->statements)); blok->variables = eina_hash_stringshared_new(burnLeaf); block->value.blockValue = blok; blok->outerBlock = compiler->currentBlock; @@ -933,6 +961,25 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) } } +static void outputBlockToken(FILE *file, outputMode mode, LSL_Leaf *content) +{ + if (content) + { + fprintf(file, "\n{\n"); + if (content->value.blockValue) + { + LSL_Statement *statement = NULL; + + EINA_CLIST_FOR_EACH_ENTRY(statement, &(content->value.blockValue->statements), LSL_Statement, statement) + { + outputLeaf(file, mode, statement->expressions); + fprintf(file, ";\n"); + } + } + fprintf(file, "}\n"); + } +} + static void outputFloatToken(FILE *file, outputMode mode, LSL_Leaf *content) { if (content) -- cgit v1.1