diff options
Diffstat (limited to 'LuaSL/src/LuaSL_compile.c')
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 71 |
1 files changed, 45 insertions, 26 deletions
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) | |||
275 | { | 275 | { |
276 | if ((param) && (LSL_PARAMETER == param->toKen->type)) | 276 | if ((param) && (LSL_PARAMETER == param->toKen->type)) |
277 | { | 277 | { |
278 | // if (name == param->value.identifierValue->name) // Assuming they are stringshares. | 278 | // if (name == param->value.identifierValue->name.text) // Assuming they are stringshares. |
279 | if (0 == strcmp(name, param->value.identifierValue->name)) // Not assuming they are stringeshares. | 279 | if (0 == strcmp(name, param->value.identifierValue->name.text)) // Not assuming they are stringeshares. They should be. |
280 | var = param; | 280 | var = param; |
281 | } | 281 | } |
282 | } | 282 | } |
@@ -339,7 +339,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, | |||
339 | { | 339 | { |
340 | if ((left->toKen) && (LSL_IDENTIFIER == left->toKen->type) && (left->value.identifierValue)) | 340 | if ((left->toKen) && (LSL_IDENTIFIER == left->toKen->type) && (left->value.identifierValue)) |
341 | { | 341 | { |
342 | LSL_Leaf *var = findVariable(compiler, left->value.identifierValue->name); | 342 | LSL_Leaf *var = findVariable(compiler, left->value.identifierValue->name.text); |
343 | 343 | ||
344 | if (var) | 344 | if (var) |
345 | lType = var->basicType; | 345 | lType = var->basicType; |
@@ -361,7 +361,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, | |||
361 | { | 361 | { |
362 | if ((right->toKen) && (LSL_IDENTIFIER == right->toKen->type) && (right->value.identifierValue)) | 362 | if ((right->toKen) && (LSL_IDENTIFIER == right->toKen->type) && (right->value.identifierValue)) |
363 | { | 363 | { |
364 | LSL_Leaf *var = findVariable(compiler, right->value.identifierValue->name); | 364 | LSL_Leaf *var = findVariable(compiler, right->value.identifierValue->name.text); |
365 | 365 | ||
366 | if (var) | 366 | if (var) |
367 | rType = var->basicType; | 367 | rType = var->basicType; |
@@ -468,7 +468,8 @@ LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *ident | |||
468 | 468 | ||
469 | if ( (identifier) && (result)) | 469 | if ( (identifier) && (result)) |
470 | { | 470 | { |
471 | result->name = identifier->value.stringValue; | 471 | result->name.text = identifier->value.stringValue; |
472 | result->name.ignorableText = identifier->ignorableText; | ||
472 | result->value.toKen = tokens[LSL_UNKNOWN - lowestToken]; | 473 | result->value.toKen = tokens[LSL_UNKNOWN - lowestToken]; |
473 | identifier->value.identifierValue = result; | 474 | identifier->value.identifierValue = result; |
474 | identifier->toKen = tokens[LSL_PARAMETER - lowestToken]; | 475 | identifier->toKen = tokens[LSL_PARAMETER - lowestToken]; |
@@ -534,7 +535,8 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi | |||
534 | { | 535 | { |
535 | if (identifier) | 536 | if (identifier) |
536 | { | 537 | { |
537 | func->name = identifier->value.stringValue; | 538 | func->name.text = identifier->value.stringValue; |
539 | func->name.ignorableText = identifier->ignorableText; | ||
538 | identifier->toKen = tokens[LSL_FUNCTION - lowestToken]; | 540 | identifier->toKen = tokens[LSL_FUNCTION - lowestToken]; |
539 | identifier->value.functionValue = func; | 541 | identifier->value.functionValue = func; |
540 | func->type = type; | 542 | func->type = type; |
@@ -542,9 +544,9 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi | |||
542 | identifier->basicType = type->basicType; | 544 | identifier->basicType = type->basicType; |
543 | else | 545 | else |
544 | identifier->basicType = OT_nothing; | 546 | identifier->basicType = OT_nothing; |
545 | eina_hash_add(compiler->script.functions, func->name, identifier); | 547 | eina_hash_add(compiler->script.functions, func->name.text, identifier); |
546 | #if LUASL_DIFF_CHECK | 548 | #if LUASL_DIFF_CHECK |
547 | func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); | 549 | // func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); |
548 | #endif | 550 | #endif |
549 | } | 551 | } |
550 | compiler->currentFunction = func; | 552 | compiler->currentFunction = func; |
@@ -584,6 +586,7 @@ LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Le | |||
584 | } | 586 | } |
585 | identifier->value.functionCallValue = call; | 587 | identifier->value.functionCallValue = call; |
586 | // TODO - Put the params in call. | 588 | // TODO - Put the params in call. |
589 | // eina_inarray_setup(&(cal->vars), sizeof(LSL_Text), 3); | ||
587 | identifier->toKen = tokens[LSL_FUNCTION_CALL - lowestToken]; | 590 | identifier->toKen = tokens[LSL_FUNCTION_CALL - lowestToken]; |
588 | identifier->basicType = func->basicType; | 591 | identifier->basicType = func->basicType; |
589 | } | 592 | } |
@@ -625,17 +628,23 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf | |||
625 | return lval; | 628 | return lval; |
626 | } | 629 | } |
627 | 630 | ||
628 | LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *block) | 631 | LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifier, LSL_Leaf *block) |
629 | { | 632 | { |
630 | LSL_State *result = calloc(1, sizeof(LSL_State)); | 633 | LSL_State *result = calloc(1, sizeof(LSL_State)); |
631 | 634 | ||
632 | if ((identifier) && (result)) | 635 | if ((identifier) && (result)) |
633 | { | 636 | { |
634 | result->name = identifier->value.stringValue; | 637 | result->name.text = identifier->value.stringValue; |
638 | result->name.ignorableText = identifier->ignorableText; | ||
635 | result->block = block; | 639 | result->block = block; |
640 | if (state) | ||
641 | { | ||
642 | result->state.text = state->toKen->toKen; | ||
643 | result->state.ignorableText = state->ignorableText; | ||
644 | } | ||
636 | identifier->value.stateValue = result; | 645 | identifier->value.stateValue = result; |
637 | identifier->toKen = tokens[LSL_STATE - lowestToken]; | 646 | identifier->toKen = tokens[LSL_STATE - lowestToken]; |
638 | eina_hash_add(compiler->script.states, result->name, identifier); | 647 | eina_hash_add(compiler->script.states, result->name.text, identifier); |
639 | } | 648 | } |
640 | 649 | ||
641 | return identifier; | 650 | return identifier; |
@@ -778,7 +787,8 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi | |||
778 | 787 | ||
779 | if ( (identifier) && (result)) | 788 | if ( (identifier) && (result)) |
780 | { | 789 | { |
781 | result->name = identifier->value.stringValue; | 790 | result->name.text = identifier->value.stringValue; |
791 | result->name.ignorableText = identifier->ignorableText; | ||
782 | result->value.toKen = tokens[LSL_UNKNOWN - lowestToken]; | 792 | result->value.toKen = tokens[LSL_UNKNOWN - lowestToken]; |
783 | identifier->value.identifierValue = result; | 793 | identifier->value.identifierValue = result; |
784 | identifier->left = type; | 794 | identifier->left = type; |
@@ -792,9 +802,9 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi | |||
792 | result->value.toKen = type->toKen; // This is the LSL_TYPE_* toKen instead of the LSL_* toKen. Not sure if that's a problem. | 802 | result->value.toKen = type->toKen; // This is the LSL_TYPE_* toKen instead of the LSL_* toKen. Not sure if that's a problem. |
793 | } | 803 | } |
794 | if (compiler->currentBlock) | 804 | if (compiler->currentBlock) |
795 | eina_hash_add(compiler->currentBlock->variables, result->name, identifier); | 805 | eina_hash_add(compiler->currentBlock->variables, result->name.text, identifier); |
796 | else | 806 | else |
797 | eina_hash_add(compiler->script.variables, result->name, identifier); | 807 | eina_hash_add(compiler->script.variables, result->name.text, identifier); |
798 | } | 808 | } |
799 | 809 | ||
800 | return identifier; | 810 | return identifier; |
@@ -1175,6 +1185,18 @@ static LSL_Leaf *evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_L | |||
1175 | return result; | 1185 | return result; |
1176 | } | 1186 | } |
1177 | 1187 | ||
1188 | static void outputText(FILE *file, LSL_Text *text, boolean ignore) | ||
1189 | { | ||
1190 | if (text->text) | ||
1191 | { | ||
1192 | #if LUASL_DIFF_CHECK | ||
1193 | if (ignore && (text->ignorableText)) | ||
1194 | fwrite(eina_strbuf_string_get(text->ignorableText), 1, eina_strbuf_length_get(text->ignorableText), file); | ||
1195 | #endif | ||
1196 | fprintf(file, "%s", text->text); | ||
1197 | } | ||
1198 | } | ||
1199 | |||
1178 | static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) | 1200 | static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) |
1179 | { | 1201 | { |
1180 | if (leaf) | 1202 | if (leaf) |
@@ -1207,8 +1229,10 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
1207 | int first = TRUE; | 1229 | int first = TRUE; |
1208 | 1230 | ||
1209 | outputLeaf(file, mode, func->type); | 1231 | outputLeaf(file, mode, func->type); |
1232 | outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); | ||
1233 | // fprintf(file, "%s(", func->name); | ||
1210 | // TODO - should print comma and parenthesis ignorables. | 1234 | // TODO - should print comma and parenthesis ignorables. |
1211 | fprintf(file, "%s(", func->name); | 1235 | fprintf(file, "("); |
1212 | EINA_INARRAY_FOREACH((&(func->vars)), param) | 1236 | EINA_INARRAY_FOREACH((&(func->vars)), param) |
1213 | { | 1237 | { |
1214 | if (!LUASL_DIFF_CHECK) | 1238 | if (!LUASL_DIFF_CHECK) |
@@ -1232,7 +1256,9 @@ static void outputFunctionCallToken(FILE *file, outputMode mode, LSL_Leaf *conte | |||
1232 | { | 1256 | { |
1233 | LSL_FunctionCall *call = content->value.functionCallValue; | 1257 | LSL_FunctionCall *call = content->value.functionCallValue; |
1234 | LSL_Function *func = call->function; | 1258 | LSL_Function *func = call->function; |
1235 | fprintf(file, "%s(", func->name); | 1259 | outputText(file, &(func->name), !(LSL_NOIGNORE & content->toKen->flags)); |
1260 | // fprintf(file, "%s(", func->name); | ||
1261 | fprintf(file, "("); | ||
1236 | // TODO - print params here. | 1262 | // TODO - print params here. |
1237 | fprintf(file, ")"); | 1263 | fprintf(file, ")"); |
1238 | } | 1264 | } |
@@ -1247,12 +1273,7 @@ static void outputIntegerToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
1247 | static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content) | 1273 | static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content) |
1248 | { | 1274 | { |
1249 | if (content) | 1275 | if (content) |
1250 | { | 1276 | outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); |
1251 | if (LUASL_DIFF_CHECK) | ||
1252 | fprintf(file, "%s", content->value.identifierValue->name); | ||
1253 | else | ||
1254 | fprintf(file, " %s", content->value.identifierValue->name); | ||
1255 | } | ||
1256 | } | 1277 | } |
1257 | 1278 | ||
1258 | static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) | 1279 | static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) |
@@ -1292,10 +1313,8 @@ static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
1292 | 1313 | ||
1293 | if (state) | 1314 | if (state) |
1294 | { | 1315 | { |
1295 | if (0 == strcmp(state->name, "default")) | 1316 | outputText(file, &(state->state), !(LSL_NOIGNORE & content->toKen->flags)); |
1296 | fprintf(file, "%s", state->name); | 1317 | outputText(file, &(state->name), !(LSL_NOIGNORE & content->toKen->flags)); |
1297 | else | ||
1298 | fprintf(file, "state %s", state->name); | ||
1299 | outputLeaf(file, mode, state->block); | 1318 | outputLeaf(file, mode, state->block); |
1300 | fprintf(file, "\n"); | 1319 | fprintf(file, "\n"); |
1301 | } | 1320 | } |