diff --git a/src/actor.h b/src/actor.h index 7a7e55518..666ca67f8 100644 --- a/src/actor.h +++ b/src/actor.h @@ -33,7 +33,6 @@ // States are tied to finite states are tied to animation frames. #include "info.h" -#include #include "doomdef.h" #include "textures/textures.h" #include "r_data/renderstyle.h" diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 8bb16a687..31a5ec784 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -791,7 +791,7 @@ void SetDehParams(FState *state, int codepointer) // Let's identify the codepointer we're dealing with. PFunction *sym; - sym = dyn_cast(RUNTIME_CLASS(AWeapon)->Symbols.FindSymbol(FName(MBFCodePointers[codepointer].name), true)); + sym = dyn_cast(RUNTIME_CLASS(AWeapon)->FindSymbol(FName(MBFCodePointers[codepointer].name), true)); if (sym == NULL) return; if (codepointer < 0 || (unsigned)codepointer >= countof(MBFCodePointerFactories)) @@ -2118,7 +2118,7 @@ static int PatchCodePtrs (int dummy) // This skips the action table and goes directly to the internal symbol table // DEH compatible functions are easy to recognize. - PFunction *sym = dyn_cast(RUNTIME_CLASS(AWeapon)->Symbols.FindSymbol(symname, true)); + PFunction *sym = dyn_cast(RUNTIME_CLASS(AWeapon)->FindSymbol(symname, true)); if (sym == NULL) { Printf(TEXTCOLOR_RED "Frame %d: Unknown code pointer '%s'\n", frame, Line2); @@ -2744,7 +2744,7 @@ static bool LoadDehSupp () // or AActor so this will find all of them. FString name = "A_"; name << sc.String; - PFunction *sym = dyn_cast(RUNTIME_CLASS(AWeapon)->Symbols.FindSymbol(name, true)); + PFunction *sym = dyn_cast(RUNTIME_CLASS(AWeapon)->FindSymbol(name, true)); if (sym == NULL) { sc.ScriptError("Unknown code pointer '%s'", sc.String); @@ -3116,7 +3116,7 @@ void FinishDehPatch () { if (AmmoPerAttacks[j].ptr == nullptr) { - auto p = dyn_cast(RUNTIME_CLASS(AWeapon)->Symbols.FindSymbol(AmmoPerAttacks[j].func, true)); + auto p = dyn_cast(RUNTIME_CLASS(AWeapon)->FindSymbol(AmmoPerAttacks[j].func, true)); if (p != nullptr) AmmoPerAttacks[j].ptr = p->Variants[0].Implementation; } if (state->ActionFunc == AmmoPerAttacks[j].ptr) diff --git a/src/dobject.cpp b/src/dobject.cpp index a28ff62fc..ca2a3e32f 100644 --- a/src/dobject.cpp +++ b/src/dobject.cpp @@ -625,7 +625,7 @@ DEFINE_ACTION_FUNCTION(DObject, MSTime) void *DObject::ScriptVar(FName field, PType *type) { auto cls = GetClass(); - auto sym = dyn_cast(cls->Symbols.FindSymbol(field, true)); + auto sym = dyn_cast(cls->FindSymbol(field, true)); if (sym && (sym->Type == type || type == nullptr)) { if (!(sym->Flags & VARF_Meta)) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index abbe60dca..96314d025 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -2088,7 +2088,7 @@ void PDynArray::SetDefaultValue(void *base, unsigned offset, TArray *special) const { - if (ElementType->IsKindOf(RUNTIME_CLASS(PPointer)) && !ElementType->IsKindOf(RUNTIME_CLASS(PClassPointer)) && static_cast(ElementType)->PointedType->IsKindOf(RUNTIME_CLASS(PClass))) + if (ElementType->IsKindOf(RUNTIME_CLASS(PObjectPointer))) { // Add to the list of pointer arrays for this class. special->Push(offset); @@ -3554,6 +3554,11 @@ int PClass::FindVirtualIndex(FName name, PPrototype *proto) return -1; } +PSymbol *PClass::FindSymbol(FName symname, bool searchparents) const +{ + return Symbols.FindSymbol(symname, searchparents); +} + //========================================================================== // // PClass :: BuildFlatPointers @@ -3722,7 +3727,7 @@ VMFunction *PClass::FindFunction(FName clsname, FName funcname) { auto cls = PClass::FindClass(clsname); if (!cls) return nullptr; - auto func = dyn_cast(cls->Symbols.FindSymbol(funcname, true)); + auto func = dyn_cast(cls->FindSymbol(funcname, true)); if (!func) return nullptr; return func->Variants[0].Implementation; } @@ -3731,7 +3736,7 @@ void PClass::FindFunction(VMFunction **pptr, FName clsname, FName funcname) { auto cls = PClass::FindClass(clsname); if (!cls) return; - auto func = dyn_cast(cls->Symbols.FindSymbol(funcname, true)); + auto func = dyn_cast(cls->FindSymbol(funcname, true)); if (!func) return; *pptr = func->Variants[0].Implementation; FunctionPtrList.Push(pptr); diff --git a/src/dobjtype.h b/src/dobjtype.h index a4d0f4402..27248e955 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -614,6 +614,7 @@ public: bool ReadAllFields(FSerializer &ar, void *addr) const; void InitializeDefaults(); int FindVirtualIndex(FName name, PPrototype *proto); + PSymbol *FindSymbol(FName symname, bool searchparents) const; static void StaticInit(); static void StaticShutdown(); diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index be14b2f09..5f7d4bfe5 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -1127,7 +1127,7 @@ DMenuItemBase * CreateOptionMenuItemStaticText(const char *name, bool v) auto p = c->CreateNew(); FString namestr = name; VMValue params[] = { p, &namestr, v }; - auto f = dyn_cast(c->Symbols.FindSymbol("Init", false)); + auto f = dyn_cast(c->FindSymbol("Init", false)); GlobalVMStack.Call(f->Variants[0].Implementation, params, countof(params), nullptr, 0); return (DMenuItemBase*)p; } @@ -1138,7 +1138,7 @@ DMenuItemBase * CreateOptionMenuItemJoyConfigMenu(const char *label, IJoystickCo auto p = c->CreateNew(); FString namestr = label; VMValue params[] = { p, &namestr, joy }; - auto f = dyn_cast(c->Symbols.FindSymbol("Init", false)); + auto f = dyn_cast(c->FindSymbol("Init", false)); GlobalVMStack.Call(f->Variants[0].Implementation, params, countof(params), nullptr, 0); return (DMenuItemBase*)p; } @@ -1149,7 +1149,7 @@ DMenuItemBase * CreateOptionMenuItemSubmenu(const char *label, FName cmd, int ce auto p = c->CreateNew(); FString namestr = label; VMValue params[] = { p, &namestr, cmd.GetIndex(), center }; - auto f = dyn_cast(c->Symbols.FindSymbol("Init", false)); + auto f = dyn_cast(c->FindSymbol("Init", false)); GlobalVMStack.Call(f->Variants[0].Implementation, params, countof(params), nullptr, 0); return (DMenuItemBase*)p; } @@ -1160,7 +1160,7 @@ DMenuItemBase * CreateOptionMenuItemControl(const char *label, FName cmd, FKeyBi auto p = c->CreateNew(); FString namestr = label; VMValue params[] = { p, &namestr, cmd.GetIndex(), bindings }; - auto f = dyn_cast(c->Symbols.FindSymbol("Init", false)); + auto f = dyn_cast(c->FindSymbol("Init", false)); GlobalVMStack.Call(f->Variants[0].Implementation, params, countof(params), nullptr, 0); return (DMenuItemBase*)p; } @@ -1171,7 +1171,7 @@ DMenuItemBase * CreateListMenuItemPatch(double x, double y, int height, int hotk auto p = c->CreateNew(); FString keystr = FString(char(hotkey)); VMValue params[] = { p, x, y, height, tex.GetIndex(), &keystr, command.GetIndex(), param }; - auto f = dyn_cast(c->Symbols.FindSymbol("InitDirect", false)); + auto f = dyn_cast(c->FindSymbol("InitDirect", false)); GlobalVMStack.Call(f->Variants[0].Implementation, params, countof(params), nullptr, 0); return (DMenuItemBase*)p; } @@ -1183,7 +1183,7 @@ DMenuItemBase * CreateListMenuItemText(double x, double y, int height, int hotke FString keystr = FString(char(hotkey)); FString textstr = text; VMValue params[] = { p, x, y, height, &keystr, &textstr, font, int(color1.d), int(color2.d), command.GetIndex(), param }; - auto f = dyn_cast(c->Symbols.FindSymbol("InitDirect", false)); + auto f = dyn_cast(c->FindSymbol("InitDirect", false)); GlobalVMStack.Call(f->Variants[0].Implementation, params, countof(params), nullptr, 0); return (DMenuItemBase*)p; } diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index ce7137293..458a89502 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -371,7 +371,7 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) PClass *cls = PClass::FindClass(buildname); if (cls != nullptr && cls->IsDescendantOf("ListMenuItem")) { - auto func = dyn_cast(cls->Symbols.FindSymbol("Init", true)); + auto func = dyn_cast(cls->FindSymbol("Init", true)); if (func != nullptr && !(func->Variants[0].Flags & (VARF_Protected | VARF_Private))) // skip internal classes which have a protexted init method. { auto &args = func->Variants[0].Proto->ArgumentTypes; @@ -746,7 +746,7 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc) PClass *cls = PClass::FindClass(buildname); if (cls != nullptr && cls->IsDescendantOf("OptionMenuItem")) { - auto func = dyn_cast(cls->Symbols.FindSymbol("Init", true)); + auto func = dyn_cast(cls->FindSymbol("Init", true)); if (func != nullptr && !(func->Variants[0].Flags & (VARF_Protected | VARF_Private))) // skip internal classes which have a protexted init method. { auto &args = func->Variants[0].Proto->ArgumentTypes; diff --git a/src/menu/messagebox.cpp b/src/menu/messagebox.cpp index 514331d7f..a7a69dbb5 100644 --- a/src/menu/messagebox.cpp +++ b/src/menu/messagebox.cpp @@ -70,7 +70,7 @@ DMenu *CreateMessageBoxMenu(DMenu *parent, const char *message, int messagemode, FString namestr = message; VMValue params[] = { p, parent, &namestr, messagemode, playsound, action.GetIndex(), reinterpret_cast(handler) }; - auto f = dyn_cast(c->Symbols.FindSymbol("Init", false)); + auto f = dyn_cast(c->FindSymbol("Init", false)); GlobalVMStack.Call(f->Variants[0].Implementation, params, countof(params), nullptr, 0); return (DMenu*)p; } diff --git a/src/p_acs.cpp b/src/p_acs.cpp index f198f7e10..0feb013f4 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -5012,7 +5012,7 @@ int DLevelScript::LineFromID(int id) bool GetVarAddrType(AActor *self, FName varname, int index, void *&addr, PType *&type, bool readonly) { - PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); + PField *var = dyn_cast(self->GetClass()->FindSymbol(varname, true)); PArray *arraytype; if (var == NULL || (!readonly && (var->Flags & VARF_Native))) @@ -5362,7 +5362,7 @@ static int ScriptCall(AActor *activator, unsigned argc, int32_t *args) { I_Error("ACS call to unknown class in script function %s.%s", clsname, funcname); } - auto funcsym = dyn_cast(cls->Symbols.FindSymbol(funcname, true)); + auto funcsym = dyn_cast(cls->FindSymbol(funcname, true)); if (funcsym == nullptr) { I_Error("ACS call to unknown script function %s.%s", clsname, funcname); diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 5ffc88384..a23316bd1 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -4749,7 +4749,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_ChangeVelocity) static PField *GetVar(DObject *self, FName varname) { - PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); + PField *var = dyn_cast(self->GetClass()->FindSymbol(varname, true)); if (var == NULL || (var->Flags & (VARF_Native | VARF_Private | VARF_Protected | VARF_Static)) || !var->Type->IsKindOf(RUNTIME_CLASS(PBasicType))) { @@ -4798,7 +4798,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_SetUserVarFloat) static PField *GetArrayVar(DObject *self, FName varname, int pos) { - PField *var = dyn_cast(self->GetClass()->Symbols.FindSymbol(varname, true)); + PField *var = dyn_cast(self->GetClass()->FindSymbol(varname, true)); if (var == NULL || (var->Flags & (VARF_Native | VARF_Private | VARF_Protected | VARF_Static)) || !var->Type->IsKindOf(RUNTIME_CLASS(PArray)) || diff --git a/src/p_setup.cpp b/src/p_setup.cpp index eccad199e..e91de462a 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1616,7 +1616,7 @@ static void SetMapThingUserData(AActor *actor, unsigned udi) { FName varname = MapThingsUserData[udi].Property; int value = MapThingsUserData[udi].Value; - PField *var = dyn_cast(actor->GetClass()->Symbols.FindSymbol(varname, true)); + PField *var = dyn_cast(actor->GetClass()->FindSymbol(varname, true)); udi++; diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 8414762b0..a87e249a8 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -224,6 +224,12 @@ static PClass *FindClassType(FName name, FCompileContext &ctx) return nullptr; } +bool isActor(PStruct *type) +{ + auto cls = dyn_cast(type); + return cls ? cls->IsDescendantOf(RUNTIME_CLASS(AActor)) : false; +} + //========================================================================== // // ExpEmit @@ -5963,7 +5969,7 @@ FxExpression *FxIdentifier::Resolve(FCompileContext& ctx) delete this; return nullptr; } - if (!ctx.Function->Variants[0].SelfClass->IsKindOf(RUNTIME_CLASS(PClassActor))) + if (!isActor(ctx.Function->Variants[0].SelfClass)) { ScriptPosition.Message(MSG_ERROR, "'Default' requires an actor type."); delete this; @@ -6123,7 +6129,7 @@ FxExpression *FxIdentifier::ResolveMember(FCompileContext &ctx, PStruct *classct if (Identifier == NAME_Default) { - if (!objtype->IsKindOf(RUNTIME_CLASS(PClassActor))) + if (!isActor(objtype)) { ScriptPosition.Message(MSG_ERROR, "'Default' requires an actor type."); delete object; @@ -7689,7 +7695,7 @@ FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx) delete this; return nullptr; } - FxExpression *self = (ctx.Function && (ctx.Function->Variants[0].Flags & VARF_Method) && ctx.Class->IsKindOf(RUNTIME_CLASS(PClassActor))) ? new FxSelf(ScriptPosition) : (FxExpression*)new FxConstant(ScriptPosition); + FxExpression *self = (ctx.Function && (ctx.Function->Variants[0].Flags & VARF_Method) && isActor(ctx.Class)) ? new FxSelf(ScriptPosition) : (FxExpression*)new FxConstant(ScriptPosition); FxExpression *x = new FxActionSpecialCall(self, special, ArgList, ScriptPosition); delete this; return x->Resolve(ctx); @@ -10693,9 +10699,9 @@ int BuiltinNameToClass(VMValue *param, TArray &defaultparam, int numpar // Let the caller check this. Making this an error with a message is only taking away options from the user. cls = nullptr; } - ret->SetObject(const_cast(cls)); + ret->SetPointer(const_cast(cls)); } - else ret->SetObject(nullptr); + else ret->SetPointer(nullptr); return 1; } @@ -10810,7 +10816,7 @@ int BuiltinClassCast(VMValue *param, TArray &defaultparam, int numparam PARAM_PROLOGUE; PARAM_CLASS(from, DObject); PARAM_CLASS(to, DObject); - ACTION_RETURN_OBJECT(from && to && from->IsDescendantOf(to) ? from : nullptr); + ACTION_RETURN_POINTER(from && to && from->IsDescendantOf(to) ? from : nullptr); } ExpEmit FxClassPtrCast::Emit(VMFunctionBuilder *build) diff --git a/src/scripting/decorate/thingdef_exp.cpp b/src/scripting/decorate/thingdef_exp.cpp index 6757a2382..56aaf25df 100644 --- a/src/scripting/decorate/thingdef_exp.cpp +++ b/src/scripting/decorate/thingdef_exp.cpp @@ -505,7 +505,7 @@ static FxExpression *ParseExpression0 (FScanner &sc, PClassActor *cls) default: if (cls != nullptr) { - func = dyn_cast(cls->Symbols.FindSymbol(identifier, true)); + func = dyn_cast(cls->FindSymbol(identifier, true)); // There is an action function ACS_NamedExecuteWithResult which must be ignored here for this to work. if (func != nullptr && identifier != NAME_ACS_NamedExecuteWithResult) diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index 7b31336fd..ea1c50ee4 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -964,7 +964,7 @@ static void ParseActorProperty(FScanner &sc, Baggage &bag) FName name(propname, true); if (name != NAME_None) { - auto propp = dyn_cast(bag.Info->Symbols.FindSymbol(name, true)); + auto propp = dyn_cast(bag.Info->FindSymbol(name, true)); if (propp != nullptr) { DispatchScriptProperty(sc, propp, (AActor *)bag.Info->Defaults, bag); diff --git a/src/scripting/decorate/thingdef_states.cpp b/src/scripting/decorate/thingdef_states.cpp index 12684a30b..3aa4c5afb 100644 --- a/src/scripting/decorate/thingdef_states.cpp +++ b/src/scripting/decorate/thingdef_states.cpp @@ -97,7 +97,7 @@ FxVMFunctionCall *DoActionSpecials(FScanner &sc, FState & state, Baggage &bag) { sc.ScriptError ("Too many arguments to %s", specname.GetChars()); } - auto f = dyn_cast(RUNTIME_CLASS(AActor)->Symbols.FindSymbol("A_CallSpecial", false)); + auto f = dyn_cast(RUNTIME_CLASS(AActor)->FindSymbol("A_CallSpecial", false)); assert(f != nullptr); return new FxVMFunctionCall(new FxSelf(sc), f, args, sc, false); } @@ -583,7 +583,7 @@ FxVMFunctionCall *ParseAction(FScanner &sc, FState state, FString statestring, B FName symname = FName(sc.String, true); symname = CheckCastKludges(symname); - PFunction *afd = dyn_cast(bag.Info->Symbols.FindSymbol(symname, true)); + PFunction *afd = dyn_cast(bag.Info->FindSymbol(symname, true)); if (afd != NULL) { FArgumentList args; diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 01a79dfc1..7c5608211 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -733,7 +733,7 @@ FieldDesc *FindField(PStruct *cls, const char * string) VMFunction *FindVMFunction(PClass *cls, const char *name) { - auto f = dyn_cast(cls->Symbols.FindSymbol(name, true)); + auto f = dyn_cast(cls->FindSymbol(name, true)); return f == nullptr ? nullptr : f->Variants[0].Implementation; } diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index b2a922b46..0d363c2be 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -342,7 +342,7 @@ void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int in FName name(propname, true); if (name != NAME_None) { - auto propp = dyn_cast(info->Symbols.FindSymbol(name, true)); + auto propp = dyn_cast(info->FindSymbol(name, true)); if (propp != nullptr) { *((char*)defaults + propp->Variables[0]->Offset) = set ? 1 : 0; diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 572e5a422..be7ff8182 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1404,7 +1404,7 @@ bool ZCCCompiler::CompileProperties(PClass *type, TArray &Proper { do { - auto f = dyn_cast(type->Symbols.FindSymbol(id->Id, true)); + auto f = dyn_cast(type->FindSymbol(id->Id, true)); if (f == nullptr) { Error(id, "Variable %s not found in %s", FName(id->Id).GetChars(), type->TypeName.GetChars()); @@ -2113,7 +2113,7 @@ void ZCCCompiler::ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt *pro FName name(propname, true); if (name != NAME_None) { - auto propp = dyn_cast(cls->Symbols.FindSymbol(name, true)); + auto propp = dyn_cast(cls->FindSymbol(name, true)); if (propp != nullptr) { DispatchScriptProperty(propp, prop, (AActor *)bag.Info->Defaults, bag); diff --git a/src/virtual.h b/src/virtual.h index a25e543ac..67d950433 100644 --- a/src/virtual.h +++ b/src/virtual.h @@ -1,7 +1,7 @@ inline unsigned GetVirtualIndex(PClass *cls, const char *funcname) { // Look up the virtual function index in the defining class because this may have gotten overloaded in subclasses with something different than a virtual override. - auto sym = dyn_cast(cls->Symbols.FindSymbol(funcname, false)); + auto sym = dyn_cast(cls->FindSymbol(funcname, false)); assert(sym != nullptr); auto VIndex = sym->Variants[0].Implementation->VirtualIndex; return VIndex;