From fb7e642c4600f30b30e147eb5b91f0adc1f08f57 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 30 Jan 2012 18:31:40 +1000 Subject: Add a new struct for tracking bits of text and the attached ignorable, then use it for names. --- LuaSL/src/LuaSL_LSL_tree.h | 22 +++++++++---- LuaSL/src/LuaSL_compile.c | 71 ++++++++++++++++++++++++++---------------- LuaSL/src/LuaSL_lemon_yaccer.y | 4 +-- 3 files changed, 63 insertions(+), 34 deletions(-) diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 147ca5e..26e7ee8 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -38,6 +38,7 @@ typedef struct _allowedTypes allowedTypes; typedef struct _LSL_Token LSL_Token; +typedef struct _LSL_Text LSL_Text; typedef struct _LSL_Leaf LSL_Leaf; typedef struct _LSL_Parenthesis LSL_Parenthesis; typedef struct _LSL_Identifier LSL_Identifier; @@ -160,6 +161,14 @@ struct _LSL_Token evaluateToken evaluate; }; +struct _LSL_Text +{ + const char *text; +#if LUASL_DIFF_CHECK + Eina_Strbuf *ignorableText; +#endif +}; + struct _LSL_Leaf { LSL_Leaf *left; @@ -201,8 +210,8 @@ struct _LSL_Parenthesis struct _LSL_Identifier // For variables and function parameters. { - const char *name; - LSL_Leaf value; + LSL_Text name; + LSL_Leaf value; }; struct _LSL_Statement @@ -246,10 +255,10 @@ struct _LSL_Block struct _LSL_Function { - const char *name; + LSL_Text name; LSL_Leaf *type; #if LUASL_DIFF_CHECK - LSL_Leaf *params; // So we store the parenthesis, and their ignorables. +// LSL_Leaf *params; // So we store the parenthesis, and their ignorables. // This points to the params leaf, which is a function, pointing to this structure. The actual params are in vars. #endif Eina_Inarray vars; // Eina Inarray has not been released yet (Eina 1.2). @@ -266,7 +275,8 @@ struct _LSL_FunctionCall struct _LSL_State { - const char *name; + LSL_Text name; + LSL_Text state; LSL_Leaf *block; Eina_Hash *handlers; }; @@ -382,7 +392,7 @@ LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Le LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); 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 *identifier, LSL_Leaf *block); +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 *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 6beadf4..21f876c 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -275,8 +275,8 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) { if ((param) && (LSL_PARAMETER == param->toKen->type)) { -// if (name == param->value.identifierValue->name) // Assuming they are stringshares. - if (0 == strcmp(name, param->value.identifierValue->name)) // Not assuming they are stringeshares. +// if (name == param->value.identifierValue->name.text) // Assuming they are stringshares. + if (0 == strcmp(name, param->value.identifierValue->name.text)) // Not assuming they are stringeshares. They should be. var = param; } } @@ -339,7 +339,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, { if ((left->toKen) && (LSL_IDENTIFIER == left->toKen->type) && (left->value.identifierValue)) { - LSL_Leaf *var = findVariable(compiler, left->value.identifierValue->name); + LSL_Leaf *var = findVariable(compiler, left->value.identifierValue->name.text); if (var) lType = var->basicType; @@ -361,7 +361,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, { if ((right->toKen) && (LSL_IDENTIFIER == right->toKen->type) && (right->value.identifierValue)) { - LSL_Leaf *var = findVariable(compiler, right->value.identifierValue->name); + LSL_Leaf *var = findVariable(compiler, right->value.identifierValue->name.text); if (var) rType = var->basicType; @@ -468,7 +468,8 @@ LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *ident if ( (identifier) && (result)) { - result->name = identifier->value.stringValue; + result->name.text = identifier->value.stringValue; + result->name.ignorableText = identifier->ignorableText; result->value.toKen = tokens[LSL_UNKNOWN - lowestToken]; identifier->value.identifierValue = result; identifier->toKen = tokens[LSL_PARAMETER - lowestToken]; @@ -534,7 +535,8 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi { if (identifier) { - func->name = identifier->value.stringValue; + func->name.text = identifier->value.stringValue; + func->name.ignorableText = identifier->ignorableText; identifier->toKen = tokens[LSL_FUNCTION - lowestToken]; identifier->value.functionValue = func; func->type = type; @@ -542,9 +544,9 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi identifier->basicType = type->basicType; else identifier->basicType = OT_nothing; - eina_hash_add(compiler->script.functions, func->name, identifier); + eina_hash_add(compiler->script.functions, func->name.text, identifier); #if LUASL_DIFF_CHECK - func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); +// func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); #endif } compiler->currentFunction = func; @@ -584,6 +586,7 @@ LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Le } identifier->value.functionCallValue = call; // TODO - Put the params in call. +// eina_inarray_setup(&(cal->vars), sizeof(LSL_Text), 3); identifier->toKen = tokens[LSL_FUNCTION_CALL - lowestToken]; identifier->basicType = func->basicType; } @@ -625,17 +628,23 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf return lval; } -LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *block) +LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifier, LSL_Leaf *block) { LSL_State *result = calloc(1, sizeof(LSL_State)); if ((identifier) && (result)) { - result->name = identifier->value.stringValue; + result->name.text = identifier->value.stringValue; + result->name.ignorableText = identifier->ignorableText; result->block = block; + if (state) + { + result->state.text = state->toKen->toKen; + result->state.ignorableText = state->ignorableText; + } identifier->value.stateValue = result; identifier->toKen = tokens[LSL_STATE - lowestToken]; - eina_hash_add(compiler->script.states, result->name, identifier); + eina_hash_add(compiler->script.states, result->name.text, identifier); } return identifier; @@ -778,7 +787,8 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi if ( (identifier) && (result)) { - result->name = identifier->value.stringValue; + result->name.text = identifier->value.stringValue; + result->name.ignorableText = identifier->ignorableText; result->value.toKen = tokens[LSL_UNKNOWN - lowestToken]; identifier->value.identifierValue = result; identifier->left = type; @@ -792,9 +802,9 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi result->value.toKen = type->toKen; // This is the LSL_TYPE_* toKen instead of the LSL_* toKen. Not sure if that's a problem. } if (compiler->currentBlock) - eina_hash_add(compiler->currentBlock->variables, result->name, identifier); + eina_hash_add(compiler->currentBlock->variables, result->name.text, identifier); else - eina_hash_add(compiler->script.variables, result->name, identifier); + eina_hash_add(compiler->script.variables, result->name.text, identifier); } return identifier; @@ -1175,6 +1185,18 @@ static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_L return result; } +static void outputText(FILE *file, LSL_Text *text, boolean ignore) +{ + if (text->text) + { +#if LUASL_DIFF_CHECK + if (ignore && (text->ignorableText)) + fwrite(eina_strbuf_string_get(text->ignorableText), 1, eina_strbuf_length_get(text->ignorableText), file); +#endif + fprintf(file, "%s", text->text); + } +} + static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) { if (leaf) @@ -1207,8 +1229,10 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) int first = TRUE; outputLeaf(file, mode, func->type); + outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); +// fprintf(file, "%s(", func->name); // TODO - should print comma and parenthesis ignorables. - fprintf(file, "%s(", func->name); + fprintf(file, "("); EINA_INARRAY_FOREACH((&(func->vars)), param) { if (!LUASL_DIFF_CHECK) @@ -1232,7 +1256,9 @@ static void outputFunctionCallToken(FILE *file, outputMode mode, LSL_Leaf *conte { LSL_FunctionCall *call = content->value.functionCallValue; LSL_Function *func = call->function; - fprintf(file, "%s(", func->name); + outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); +// fprintf(file, "%s(", func->name); + fprintf(file, "("); // TODO - print params here. fprintf(file, ")"); } @@ -1247,12 +1273,7 @@ static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content) static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content) { if (content) - { - if (LUASL_DIFF_CHECK) - fprintf(file, "%s", content->value.identifierValue->name); - else - fprintf(file, " %s", content->value.identifierValue->name); - } + outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); } static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) @@ -1292,10 +1313,8 @@ static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content) if (state) { - if (0 == strcmp(state->name, "default")) - fprintf(file, "%s", state->name); - else - fprintf(file, "state %s", state->name); + outputText(file, &(state->state), !(LSL_NOIGNORE & content->toKen->flags)); + outputText(file, &(state->name), !(LSL_NOIGNORE & content->toKen->flags)); outputLeaf(file, mode, state->block); fprintf(file, "\n"); } diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 78aa349..b6eac2e 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -32,8 +32,8 @@ script ::= . %nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE. stateBlock(A) ::= beginBlock(L) functionList(B) LSL_BLOCK_CLOSE(R). { A = addBlock(compiler, L, B, R); } -state(S) ::= LSL_DEFAULT(I) stateBlock(B). { S = addState(compiler, I, B); } -state(S) ::= LSL_STATE_CHANGE LSL_IDENTIFIER(I) stateBlock(B). { S = addState(compiler, I, B); } +state(A) ::= LSL_DEFAULT(I) stateBlock(B). { A = addState(compiler, NULL, I, B); } +state(A) ::= LSL_STATE_CHANGE(S) LSL_IDENTIFIER(I) stateBlock(B). { A = addState(compiler, S, I, B); } // Function definitions. -- cgit v1.1