diff --git a/src/Parser.c b/src/Parser.c index a110dc4..0da0e85 100644 --- a/src/Parser.c +++ b/src/Parser.c @@ -438,8 +438,7 @@ struct ASTNode* ParseStatement(void) { VerifyToken(LI_RBRAC, "}"); return Node; case TY_IDENTIFIER: - DumpAllLists(); - if (FindAlias(CurrentIdentifier) != NULL) { + if (FindAlias(CurrentIdentifier) == NULL) { Node = ParsePrecedenceASTNode(0); VerifyToken(LI_SEMIC, ";"); return Node; @@ -451,7 +450,7 @@ struct ASTNode* ParseStatement(void) { case KW_UNION: case KW_ENUM: case KW_ALIAS: - printf("\t\tNew Variable: %s\n", CurrentIdentifier); + printf("\t\tTrying new Variable: %s\n", CurrentIdentifier); ParseDeclarationList(&Composite, SC_LOCAL, LI_SEMIC, LI_EOF, &Node); VerifyToken(LI_SEMIC, ";"); Safe(); diff --git a/src/Statements.c b/src/Statements.c index bfe33a4..f286a4e 100644 --- a/src/Statements.c +++ b/src/Statements.c @@ -88,6 +88,26 @@ int ParseLiteral(int Type) { return CurrentFile->CurrentSymbol.value; } +/* + * Get the type that a typedef declaration aliases. + * @param name the name of the typedef + * @param CompositeType out: the type if composite + * @return the type if scalar + */ +static int GetTypedef(char* name, struct SymbolTableEntry** CompositeType) { + struct SymbolTableEntry* type; + type = FindAlias(name); + + if (type == NULL) + ErrorReport("Unknown alias type: %s\n", name); + Tokenise(); + Safe(); + + *CompositeType = type->CompositeType; + return type->Type; +} + + /* * Resolve a typename to a type struct. * Short circuit on the case where a definition is present, as definitions are typeless. @@ -123,7 +143,6 @@ static int ParseType(struct SymbolTableEntry** CompositeType, int* Scope) { Type = RET_LONG; Tokenise(); break; - case TY_IDENTIFIER: case KW_ALIAS: Type = ParseAliasDeclaration(CompositeType); if (CurrentFile->CurrentSymbol.type == LI_SEMIC) @@ -147,6 +166,9 @@ static int ParseType(struct SymbolTableEntry** CompositeType, int* Scope) { if (CurrentFile->CurrentSymbol.type == LI_SEMIC) Type = -1; break; + case TY_IDENTIFIER: + Type = GetTypedef(CurrentIdentifier, CompositeType); + break; default: ErrorReport("Illegal type on token %s\n", TokenNames[CurrentFile->CurrentSymbol.type]); } @@ -297,7 +319,7 @@ static struct SymbolTableEntry* ParseScalarDeclaration(char* name, int Type, str } /* - * Handles reading in a comma-separated list of declarations. + * Handles reading in a comma-or-semicolon separated list of declarations. * Erythro treats structs, enums and function parameters the same in this regard - * comma separated. * @@ -525,25 +547,6 @@ static int ParseAliasDeclaration(struct SymbolTableEntry** CompositeType) { return Type; } -/* - * Get the type that a typedef declaration aliases. - * @param name the name of the typedef - * @param CompositeType out: the type if composite - * @return the type if scalar - */ -static int GetTypedef(char* name, struct SymbolTableEntry** CompositeType) { - struct SymbolTableEntry* type; - type = FindAlias(name); - - if (type == NULL) - ErrorReport("Unknown alias type"); - Tokenise(); - Safe(); - - *CompositeType = type->CompositeType; - return type->Type; -} - /* * Parse an array initialization. * Everything after the =, for example.