aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-30 18:31:40 +1000
committerDavid Walter Seikel2012-01-30 18:31:40 +1000
commitfb7e642c4600f30b30e147eb5b91f0adc1f08f57 (patch)
tree3a025b675a972c3e7663b0fb6273e6c82ec0114a
parentRemove the else if stuff, and empty function lists. Add the else precedence ... (diff)
downloadSledjHamr-fb7e642c4600f30b30e147eb5b91f0adc1f08f57.zip
SledjHamr-fb7e642c4600f30b30e147eb5b91f0adc1f08f57.tar.gz
SledjHamr-fb7e642c4600f30b30e147eb5b91f0adc1f08f57.tar.bz2
SledjHamr-fb7e642c4600f30b30e147eb5b91f0adc1f08f57.tar.xz
Add a new struct for tracking bits of text and the attached ignorable, then use it for names.
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h22
-rw-r--r--LuaSL/src/LuaSL_compile.c71
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y4
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 @@
38 38
39typedef struct _allowedTypes allowedTypes; 39typedef struct _allowedTypes allowedTypes;
40typedef struct _LSL_Token LSL_Token; 40typedef struct _LSL_Token LSL_Token;
41typedef struct _LSL_Text LSL_Text;
41typedef struct _LSL_Leaf LSL_Leaf; 42typedef struct _LSL_Leaf LSL_Leaf;
42typedef struct _LSL_Parenthesis LSL_Parenthesis; 43typedef struct _LSL_Parenthesis LSL_Parenthesis;
43typedef struct _LSL_Identifier LSL_Identifier; 44typedef struct _LSL_Identifier LSL_Identifier;
@@ -160,6 +161,14 @@ struct _LSL_Token
160 evaluateToken evaluate; 161 evaluateToken evaluate;
161}; 162};
162 163
164struct _LSL_Text
165{
166 const char *text;
167#if LUASL_DIFF_CHECK
168 Eina_Strbuf *ignorableText;
169#endif
170};
171
163struct _LSL_Leaf 172struct _LSL_Leaf
164{ 173{
165 LSL_Leaf *left; 174 LSL_Leaf *left;
@@ -201,8 +210,8 @@ struct _LSL_Parenthesis
201 210
202struct _LSL_Identifier // For variables and function parameters. 211struct _LSL_Identifier // For variables and function parameters.
203{ 212{
204 const char *name; 213 LSL_Text name;
205 LSL_Leaf value; 214 LSL_Leaf value;
206}; 215};
207 216
208struct _LSL_Statement 217struct _LSL_Statement
@@ -246,10 +255,10 @@ struct _LSL_Block
246 255
247struct _LSL_Function 256struct _LSL_Function
248{ 257{
249 const char *name; 258 LSL_Text name;
250 LSL_Leaf *type; 259 LSL_Leaf *type;
251#if LUASL_DIFF_CHECK 260#if LUASL_DIFF_CHECK
252 LSL_Leaf *params; // So we store the parenthesis, and their ignorables. 261// LSL_Leaf *params; // So we store the parenthesis, and their ignorables.
253 // This points to the params leaf, which is a function, pointing to this structure. The actual params are in vars. 262 // This points to the params leaf, which is a function, pointing to this structure. The actual params are in vars.
254#endif 263#endif
255 Eina_Inarray vars; // Eina Inarray has not been released yet (Eina 1.2). 264 Eina_Inarray vars; // Eina Inarray has not been released yet (Eina 1.2).
@@ -266,7 +275,8 @@ struct _LSL_FunctionCall
266 275
267struct _LSL_State 276struct _LSL_State
268{ 277{
269 const char *name; 278 LSL_Text name;
279 LSL_Text state;
270 LSL_Leaf *block; 280 LSL_Leaf *block;
271 Eina_Hash *handlers; 281 Eina_Hash *handlers;
272}; 282};
@@ -382,7 +392,7 @@ LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Le
382LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); 392LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right);
383LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam); 393LSL_Leaf *addParameter(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *newParam);
384LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); 394LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval);
385LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *block); 395LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifier, LSL_Leaf *block);
386LSL_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); 396LSL_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);
387LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr); 397LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr);
388LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr); 398LSL_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)
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
628LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *block) 631LSL_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
1188static 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
1178static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) 1200static 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)
1247static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content) 1273static 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
1258static void outputParameterListToken(FILE *file, outputMode mode, LSL_Leaf *content) 1279static 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 }
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 ::= .
32 32
33%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE. 33%nonassoc LSL_BLOCK_OPEN LSL_BLOCK_CLOSE LSL_STATE.
34stateBlock(A) ::= beginBlock(L) functionList(B) LSL_BLOCK_CLOSE(R). { A = addBlock(compiler, L, B, R); } 34stateBlock(A) ::= beginBlock(L) functionList(B) LSL_BLOCK_CLOSE(R). { A = addBlock(compiler, L, B, R); }
35state(S) ::= LSL_DEFAULT(I) stateBlock(B). { S = addState(compiler, I, B); } 35state(A) ::= LSL_DEFAULT(I) stateBlock(B). { A = addState(compiler, NULL, I, B); }
36state(S) ::= LSL_STATE_CHANGE LSL_IDENTIFIER(I) stateBlock(B). { S = addState(compiler, I, B); } 36state(A) ::= LSL_STATE_CHANGE(S) LSL_IDENTIFIER(I) stateBlock(B). { A = addState(compiler, S, I, B); }
37 37
38// Function definitions. 38// Function definitions.
39 39