aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-02 01:55:44 +1000
committerDavid Walter Seikel2012-02-02 01:55:44 +1000
commit809530889811445b7fca3a57ce38efee196d1c22 (patch)
tree179cc1515705f051268b4c37215a440de4b85089 /LuaSL/src
parentFix up single statement "blocks". (diff)
downloadSledjHamr-809530889811445b7fca3a57ce38efee196d1c22.zip
SledjHamr-809530889811445b7fca3a57ce38efee196d1c22.tar.gz
SledjHamr-809530889811445b7fca3a57ce38efee196d1c22.tar.bz2
SledjHamr-809530889811445b7fca3a57ce38efee196d1c22.tar.xz
Parse dot subbies.
Diffstat (limited to 'LuaSL/src')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h3
-rw-r--r--LuaSL/src/LuaSL_compile.c36
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y4
3 files changed, 38 insertions, 5 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 5e36c73..7791b10 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -211,6 +211,7 @@ struct _LSL_Parenthesis
211struct _LSL_Identifier // For variables and function parameters. 211struct _LSL_Identifier // For variables and function parameters.
212{ 212{
213 LSL_Text name; 213 LSL_Text name;
214 const char *sub;
214 LSL_Leaf value; 215 LSL_Leaf value;
215}; 216};
216 217
@@ -411,7 +412,7 @@ LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *
411LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr); 412LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *assignment, LSL_Leaf *expr);
412 413
413LSL_Leaf *beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block); 414LSL_Leaf *beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block);
414LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier); 415LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *dot, LSL_Leaf *sub);
415LSL_Leaf *collectArguments(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *arg); 416LSL_Leaf *collectArguments(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *arg);
416LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam); 417LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam);
417LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *newStatement); 418LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *newStatement);
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 0b56845..5fb3946 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -300,13 +300,19 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name)
300 return var; 300 return var;
301} 301}
302 302
303LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier) 303LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *dot, LSL_Leaf *sub)
304{ 304{
305 gameGlobals *game = compiler->game; 305 gameGlobals *game = compiler->game;
306 const char *search;
307
308 if (dot)
309 search = identifier->value.identifierValue->name.text;
310 else
311 search = identifier->value.stringValue;
306 312
307 if (identifier) 313 if (identifier)
308 { 314 {
309 LSL_Leaf *var = findVariable(compiler, identifier->value.stringValue); 315 LSL_Leaf *var = findVariable(compiler, search);
310 316
311 if (var) 317 if (var)
312 { 318 {
@@ -314,6 +320,26 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier)
314 PI("Found %s!", identifier->value.stringValue); 320 PI("Found %s!", identifier->value.stringValue);
315 identifier->value.identifierValue = var->value.identifierValue; 321 identifier->value.identifierValue = var->value.identifierValue;
316 identifier->basicType = var->basicType; 322 identifier->basicType = var->basicType;
323 if ((dot) && (sub))
324 {
325 LSL_Identifier *id = calloc(1, sizeof(LSL_Identifier));
326
327 if (id)
328 {
329 memcpy(id, var->value.identifierValue, sizeof(LSL_Identifier));
330 identifier->value.identifierValue = id;
331 if (LSL_ROTATION == var->toKen->type)
332 {
333 // TODO - check if it's one of x, y, z, or s.
334 }
335 if (LSL_VECTOR == var->toKen->type)
336 {
337 // TODO - check if it's one of x, y, or z.
338 }
339 identifier->value.identifierValue->sub = sub->value.stringValue;
340 identifier->basicType = OT_float;
341 }
342 }
317 } 343 }
318 else 344 else
319 PE("NOT found %s @ line %d, column %d!", identifier->value.stringValue, identifier->line, identifier->column); 345 PE("NOT found %s @ line %d, column %d!", identifier->value.stringValue, identifier->line, identifier->column);
@@ -1520,6 +1546,8 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state
1520 fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file); 1546 fwrite(eina_strbuf_string_get(statement->ignorable[1]), 1, eina_strbuf_length_get(statement->ignorable[1]), file);
1521#endif 1547#endif
1522 fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen); 1548 fprintf(file, "%s", tokens[statement->type - lowestToken]->toKen);
1549 if (statement->identifier)
1550 outputText(file, &(statement->identifier->name), FALSE);
1523 break; 1551 break;
1524 } 1552 }
1525 case LSL_STATEMENT : 1553 case LSL_STATEMENT :
@@ -1708,7 +1736,11 @@ static void outputIdentifierToken(FILE *file, outputMode mode, LSL_Leaf *content
1708 if (content) 1736 if (content)
1709 { 1737 {
1710 if (LSL_IDENTIFIER == content->toKen->type) 1738 if (LSL_IDENTIFIER == content->toKen->type)
1739 {
1711 outputText(file, &(content->value.identifierValue->name), FALSE); 1740 outputText(file, &(content->value.identifierValue->name), FALSE);
1741 if (content->value.identifierValue->sub)
1742 fprintf(file, ".%s", content->value.identifierValue->sub);
1743 }
1712 else 1744 else
1713 outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags)); 1745 outputText(file, &(content->value.identifierValue->name), !(LSL_NOIGNORE & content->toKen->flags));
1714 } 1746 }
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y
index ad85337..565a431 100644
--- a/LuaSL/src/LuaSL_lemon_yaccer.y
+++ b/LuaSL/src/LuaSL_lemon_yaccer.y
@@ -182,8 +182,8 @@ statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_S
182statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, NULL, NULL), NULL, NULL, I); } 182statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, NULL, NULL), NULL, NULL, I); }
183 183
184%right LSL_DOT LSL_IDENTIFIER LSL_FUNCTION_CALL LSL_VARIABLE. 184%right LSL_DOT LSL_IDENTIFIER LSL_FUNCTION_CALL LSL_VARIABLE.
185identifier(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. 185identifier(A) ::= identifier(I) LSL_DOT(D) LSL_IDENTIFIER(B). { A = checkVariable(compiler, I, D, B); }
186identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B); } 186identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B, NULL, NULL); }
187 187
188%right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST. 188%right LSL_DECREMENT_PRE LSL_INCREMENT_PRE LSL_DECREMENT_POST LSL_INCREMENT_POST.
189expr(A) ::= identifier(B) LSL_DECREMENT_PRE(C). { A = addCrement(compiler, B, C, LSL_DECREMENT_POST); } 189expr(A) ::= identifier(B) LSL_DECREMENT_PRE(C). { A = addCrement(compiler, B, C, LSL_DECREMENT_POST); }