From 33985ad1615bb2d238f1af246be03961067facf2 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Fri, 18 Feb 2011 02:31:56 +0000 Subject: [PATCH] Working on enum issue git-svn-id: http://picoc.googlecode.com/svn/trunk@552 21eae674-98b7-11dd-bd71-f92a316d2d60 --- cstdlib/stdio.c | 2 +- expression.c | 2 +- type.c | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cstdlib/stdio.c b/cstdlib/stdio.c index 0bbafaf..7abc45d 100644 --- a/cstdlib/stdio.c +++ b/cstdlib/stdio.c @@ -670,7 +670,7 @@ void StdioSetupFunc(void) StructFileType = TypeCreateOpaqueStruct(NULL, TableStrRegister("__FILEStruct"), sizeof(FILE)); /* get a FILE * type */ - FilePtrType = TypeGetMatching(NULL, StructFileType, TypePointer, 0, StrEmpty); + FilePtrType = TypeGetMatching(NULL, StructFileType, TypePointer, 0, StrEmpty, TRUE); /* make a "struct __va_listStruct" which is the same size as our struct StdVararg */ TypeCreateOpaqueStruct(NULL, TableStrRegister("__va_listStruct"), sizeof(FILE)); diff --git a/expression.c b/expression.c index 7ee8f3a..420bd02 100644 --- a/expression.c +++ b/expression.c @@ -453,7 +453,7 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack ProgramFail(Parser, "can't get the address of this"); ValPtr = TopValue->Val; - Result = VariableAllocValueFromType(Parser, TypeGetMatching(Parser, TopValue->Typ, TypePointer, 0, StrEmpty), FALSE, NULL, FALSE); + Result = VariableAllocValueFromType(Parser, TypeGetMatching(Parser, TopValue->Typ, TypePointer, 0, StrEmpty, TRUE), FALSE, NULL, FALSE); Result->Val->Pointer = (void *)ValPtr; ExpressionStackPushValueNode(Parser, StackTop, Result); break; diff --git a/type.c b/type.c index 5e7944d..c7c1a08 100644 --- a/type.c +++ b/type.c @@ -46,7 +46,7 @@ struct ValueType *TypeAdd(struct ParseState *Parser, struct ValueType *ParentTyp } /* given a parent type, get a matching derived type and make one if necessary */ -struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier) +struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier, int AllowDuplicates) { int Sizeof; int AlignBytes; @@ -55,7 +55,12 @@ struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *P ThisType = ThisType->Next; if (ThisType != NULL) - return ThisType; + { + if (AllowDuplicates) + return ThisType; + else + ProgramFail(Parser, "data type '%s' is already defined", Identifier); + } switch (Base) { @@ -433,7 +438,7 @@ struct ValueType *TypeParseBack(struct ParseState *Parser, struct ValueType *Fro if (LexGetToken(Parser, NULL, TRUE) != TokenRightSquareBracket) ProgramFail(Parser, "']' expected"); - return TypeGetMatching(Parser, TypeParseBack(Parser, FromType), TypeArray, ArraySize, StrEmpty); + return TypeGetMatching(Parser, TypeParseBack(Parser, FromType), TypeArray, ArraySize, StrEmpty, TRUE); } else { @@ -472,7 +477,7 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s if (*Typ == NULL) ProgramFail(Parser, "bad type declaration"); - *Typ = TypeGetMatching(Parser, *Typ, TypePointer, 0, StrEmpty); + *Typ = TypeGetMatching(Parser, *Typ, TypePointer, 0, StrEmpty, TRUE); break; case TokenIdentifier: