From b227a2f5084245cabb78237fad7d0bf24db82a0b Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 29 Oct 2013 13:51:25 -0500 Subject: [PATCH] Add the basic types to the global symbol table --- src/dobjtype.cpp | 26 ++++++++++++++++++++++++++ src/dobjtype.h | 15 +++++++++++++++ src/namedef.h | 10 +++++++++- src/thingdef/thingdef.cpp | 1 - src/thingdef/thingdef_exp.h | 1 - src/zscript/zcc_expr.cpp | 2 -- 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index aaa507c09..22e2f73c3 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -58,6 +58,7 @@ // PUBLIC DATA DEFINITIONS ------------------------------------------------- FTypeTable TypeTable; +PSymbolTable GlobalSymbols; TArray PClass::AllClasses; bool PClass::bShutdown; @@ -458,6 +459,7 @@ void PType::GetTypeIDs(intptr_t &id1, intptr_t &id2) const void PType::StaticInit() { + // Set up TypeTable hash keys. RUNTIME_CLASS(PErrorType)->TypeTableType = RUNTIME_CLASS(PErrorType); RUNTIME_CLASS(PVoidType)->TypeTableType = RUNTIME_CLASS(PVoidType); RUNTIME_CLASS(PInt)->TypeTableType = RUNTIME_CLASS(PInt); @@ -481,6 +483,7 @@ void PType::StaticInit() RUNTIME_CLASS(PFixed)->TypeTableType = RUNTIME_CLASS(PFixed); RUNTIME_CLASS(PAngle)->TypeTableType = RUNTIME_CLASS(PAngle); + // Create types and add them type the type table. TypeTable.AddType(TypeError = new PErrorType); TypeTable.AddType(TypeVoid = new PVoidType); TypeTable.AddType(TypeSInt8 = new PInt(1, false)); @@ -499,6 +502,26 @@ void PType::StaticInit() TypeTable.AddType(TypeState = new PStatePointer); TypeTable.AddType(TypeFixed = new PFixed); TypeTable.AddType(TypeAngle = new PAngle); + + // Add types to the global symbol table. + GlobalSymbols.AddSymbol(new PSymbolType(NAME_sbyte, TypeSInt8)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_byte, TypeUInt8)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_short, TypeSInt16)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_ushort, TypeUInt16)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_int, TypeSInt32)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_uint, TypeUInt32)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_bool, TypeBool)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_float, TypeFloat64)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_double, TypeFloat64)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_float32, TypeFloat32)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_float64, TypeFloat64)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_string, TypeString)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_name, TypeName)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_sound, TypeSound)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_color, TypeColor)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_state, TypeState)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_fixed, TypeFixed)); + GlobalSymbols.AddSymbol(new PSymbolType(NAME_angle, TypeAngle)); } @@ -2454,6 +2477,9 @@ IMPLEMENT_ABSTRACT_CLASS(PSymbol); IMPLEMENT_CLASS(PSymbolConst); IMPLEMENT_CLASS(PSymbolConstNumeric); IMPLEMENT_CLASS(PSymbolConstString); +IMPLEMENT_POINTY_CLASS(PSymbolType) + DECLARE_POINTER(Type) +END_POINTERS IMPLEMENT_POINTY_CLASS(PSymbolVMFunction) DECLARE_POINTER(Function) END_POINTERS diff --git a/src/dobjtype.h b/src/dobjtype.h index b66f68340..e1e5df710 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -55,6 +55,19 @@ public: PSymbolVMFunction() : PSymbol(NAME_None) {} }; +// A symbol for a type ------------------------------------------------------ + +class PSymbolType : public PSymbol +{ + DECLARE_CLASS(PSymbolType, PSymbol); + HAS_OBJECT_POINTERS; +public: + class PType *Type; + + PSymbolType(FName name, class PType *ty) : PSymbol(name), Type(ty) {} + PSymbolType() : PSymbol(NAME_None) {} +}; + // A symbol table ----------------------------------------------------------- struct PSymbolTable @@ -89,6 +102,8 @@ private: friend class DObject; }; +extern PSymbolTable GlobalSymbols; + // Basic information shared by all types ------------------------------------ // Only one copy of a type is ever instantiated at one time. diff --git a/src/namedef.h b/src/namedef.h index 8f762125e..ed9f9183b 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -578,7 +578,7 @@ xx(DecoNameToClass) xx(DecoFindMultiNameState) xx(DecoFindSingleNameState) -// fallback names for ZScript parser +// basic type names xx(default) xx(sbyte) xx(byte) @@ -588,8 +588,16 @@ xx(int) xx(uint) xx(bool) xx(float) +xx(float32) +xx(float64) xx(double) xx(string) xx(vector) xx(map) xx(array) +xx(name) +xx(sound) +xx(color) +xx(state) +xx(fixed) +xx(angle) diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index 049e017bc..8b93b7e54 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -74,7 +74,6 @@ void ParseDecorate (FScanner &sc); // STATIC FUNCTION PROTOTYPES -------------------------------------------- PClassActor *QuestItemClasses[31]; -PSymbolTable GlobalSymbols; //========================================================================== // diff --git a/src/thingdef/thingdef_exp.h b/src/thingdef/thingdef_exp.h index 1b3e5d854..9be15cb37 100644 --- a/src/thingdef/thingdef_exp.h +++ b/src/thingdef/thingdef_exp.h @@ -50,7 +50,6 @@ #define SAFE_RESOLVE(p,c) RESOLVE(p,c); ABORT(p) class VMFunctionBuilder; -extern PSymbolTable GlobalSymbols; //========================================================================== // diff --git a/src/zscript/zcc_expr.cpp b/src/zscript/zcc_expr.cpp index 9d5f1e683..3f5aec298 100644 --- a/src/zscript/zcc_expr.cpp +++ b/src/zscript/zcc_expr.cpp @@ -10,8 +10,6 @@ #define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) -extern PSymbolTable GlobalSymbols; - ZCC_OpInfoType ZCC_OpInfo[PEX_COUNT_OF] = { #define xx(a,n) { n, #a, NULL },