[svn:parrot] r42080 - trunk/compilers/pirc/src
kjs at svn.parrot.org
kjs at svn.parrot.org
Sat Oct 24 15:19:31 UTC 2009
Author: kjs
Date: Sat Oct 24 15:19:30 2009
New Revision: 42080
URL: https://trac.parrot.org/parrot/changeset/42080
Log:
[pirc] clean up code a bit, remove need for another auto var in set_lex_flag(); only set the .lex flag on a target if it wasn't done so already
Modified:
trunk/compilers/pirc/src/pircompunit.c
Modified: trunk/compilers/pirc/src/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/src/pircompunit.c Sat Oct 24 15:04:16 2009 (r42079)
+++ trunk/compilers/pirc/src/pircompunit.c Sat Oct 24 15:19:30 2009 (r42080)
@@ -1972,26 +1972,28 @@
*/
void
set_lex_flag(lexer_state * const lexer, target * const t, char const * const name) {
- lexical *lex = (lexical *)pir_mem_allocate(lexer, sizeof (lexical));
- lexical *iter;
+ lexical *lex = CURRENT_SUB(lexer)->info.lexicals;
- lex->name = name;
-
- /* get a pointer to the "color" field, so that the lexical struct knows
- * the assigned PASM register.
- */
- lex->color = &t->info->color;
-
/* check whether there is already a target marked as .lex with the specified name */
- iter = CURRENT_SUB(lexer)->info.lexicals;
- while (iter != NULL) {
- if (STREQ(iter->name, name)) {
+ while (lex != NULL) {
+ if (STREQ(lex->name, name)) {
yypirerror(lexer->yyscanner, lexer, "lexical '%s' was already declared", name);
+ /* abort immediately */
+ return;
}
- iter = iter->next;
+ lex = lex->next;
}
+
+ lex = (lexical *)pir_mem_allocate(lexer, sizeof (lexical));
+ lex->name = name;
+
+ /* get a pointer to the "color" field, so that the lexical struct knows
+ * the assigned PASM register.
+ */
+ lex->color = &t->info->color;
+
/* link this lex node in the list of lexicals at the front; order doesn't matter. */
- lex->next = CURRENT_SUB(lexer)->info.lexicals;
+ lex->next = CURRENT_SUB(lexer)->info.lexicals;
CURRENT_SUB(lexer)->info.lexicals = lex;
}
More information about the parrot-commits
mailing list