Make PStruct::AddField() check for duplicates

- PStruct::AddField() now checks the symbol table for a symbol of the same
  name before adding a new field. If the name is in use, it returns NULL.
This commit is contained in:
Randy Heit 2013-08-23 21:56:18 -05:00
parent 27ddaad7ca
commit 0d1973a659
2 changed files with 9 additions and 4 deletions

View file

@ -1414,11 +1414,12 @@ PStruct::PStruct(FName name, DObject *outer)
//
// PStruct :: AddField
//
// Appends a new field to the end of a struct.
// Appends a new field to the end of a struct. Returns either the new field
// or NULL if a symbol by that name already exists.
//
//==========================================================================
PField *PStruct::AddField(FName name, PType *type)
PField *PStruct::AddField(FName name, PType *type, DWORD flags)
{
PField *field = new PField(name, type);
@ -1432,8 +1433,12 @@ PField *PStruct::AddField(FName name, PType *type)
// its fields.
Align = MAX(Align, type->Align);
if (Symbols.AddSymbol(field) == NULL)
{ // name is already in use
delete field;
return NULL;
}
Fields.Push(field);
Symbols.AddSymbol(field);
return field;
}

View file

@ -467,7 +467,7 @@ public:
TArray<PField *> Fields;
PSymbolTable Symbols;
PField *AddField(FName name, PType *type);
PField *AddField(FName name, PType *type, DWORD flags=0);
size_t PropagateMark();
protected: