Merge remote-tracking branch 'gzdoom/master' into merge-gzdoom

This commit is contained in:
Magnus Norddahl 2023-10-19 21:05:17 +02:00
commit e75e5a387b
600 changed files with 40006 additions and 59374 deletions

View file

@ -92,7 +92,7 @@ static FxExpression *CustomTypeCast(FxTypeCast *func, FCompileContext &ctx)
delete func;
return nullptr;
}
FxExpression *x = new FxMultiNameState(s, basex->ScriptPosition);
FxExpression *x = new FxMultiNameState(s.GetChars(), basex->ScriptPosition);
x = x->Resolve(ctx);
basex = nullptr;
delete func;
@ -309,7 +309,8 @@ static bool UnravelVarArgAJump(FxVMFunctionCall *func, FCompileContext &ctx)
static bool AJumpProcessing(FxVMFunctionCall *func, FCompileContext &ctx)
{
// Unfortunately the PrintableName is the only safe thing to catch this special case here.
if (stricmp(func->Function->Variants[0].Implementation->QualifiedName, "Actor.A_Jump") == 0)
// [RL0] It's not valid to access Variant::Implementation on function pointer calls, so skip this
if (!func->FnPtrCall && stricmp(func->Function->Variants[0].Implementation->QualifiedName, "Actor.A_Jump") == 0)
{
// Unravel the varargs part of this function here so that the VM->native interface does not have to deal with it anymore.
if (func->ArgList.Size() > 2)
@ -811,10 +812,10 @@ FxMultiNameState::FxMultiNameState(const char *_statestring, const FScriptPositi
if (scopeindex >= 0)
{
scopename = FName(statestring, scopeindex, false);
scopename = FName(statestring.GetChars(), scopeindex, false);
statestring = statestring.Right((ptrdiff_t)statestring.Len() - scopeindex - 2);
}
names = MakeStateNameList(statestring);
names = MakeStateNameList(statestring.GetChars());
names.Insert(0, scopename);
scope = checkclass;
}

View file

@ -458,7 +458,7 @@ static void ParseActorFlag (FScanner &sc, Baggage &bag, int mod)
sc.MustGetString ();
part2 = sc.String;
}
HandleActorFlag(sc, bag, part1, part2, mod);
HandleActorFlag(sc, bag, part1.GetChars(), part2, mod);
}
//==========================================================================
@ -722,12 +722,12 @@ static bool ParsePropertyParams(FScanner &sc, FPropertyInfo *prop, AActor *defau
case 'S':
sc.MustGetString();
conv.s = strings[strings.Reserve(1)] = sc.String;
conv.s = (strings[strings.Reserve(1)] = sc.String).GetChars();
break;
case 'T':
sc.MustGetString();
conv.s = strings[strings.Reserve(1)] = strbin1(sc.String);
conv.s = (strings[strings.Reserve(1)] = strbin1(sc.String)).GetChars();
break;
case 'C':
@ -747,7 +747,7 @@ static bool ParsePropertyParams(FScanner &sc, FPropertyInfo *prop, AActor *defau
else
{
sc.MustGetString ();
conv.s = strings[strings.Reserve(1)] = sc.String;
conv.s = (strings[strings.Reserve(1)] = sc.String).GetChars();
pref.i = 1;
}
break;
@ -775,7 +775,7 @@ static bool ParsePropertyParams(FScanner &sc, FPropertyInfo *prop, AActor *defau
do
{
sc.MustGetString ();
conv.s = strings[strings.Reserve(1)] = sc.String;
conv.s = (strings[strings.Reserve(1)] = sc.String).GetChars();
params.Push(conv);
params[0].i++;
}
@ -961,7 +961,7 @@ static void ParseActorProperty(FScanner &sc, Baggage &bag)
sc.UnGet ();
}
FPropertyInfo *prop = FindProperty(propname);
FPropertyInfo *prop = FindProperty(propname.GetChars());
if (prop != NULL)
{
@ -976,9 +976,9 @@ static void ParseActorProperty(FScanner &sc, Baggage &bag)
FScriptPosition::ErrorCounter++;
}
}
else if (MatchString(propname, statenames) != -1)
else if (MatchString(propname.GetChars(), statenames) != -1)
{
bag.statedef.SetStateLabel(propname, CheckState (sc, bag.Info));
bag.statedef.SetStateLabel(propname.GetChars(), CheckState (sc, bag.Info));
}
else
{
@ -1129,7 +1129,7 @@ static PClassActor *ParseActorHeader(FScanner &sc, Baggage *bag)
{
PClassActor *info = CreateNewActor(sc, typeName, parentName);
info->ActorInfo()->DoomEdNum = DoomEdNum > 0 ? DoomEdNum : -1;
info->SourceLumpName = fileSystem.GetFileFullPath(sc.LumpNum);
info->SourceLumpName = fileSystem.GetFileFullPath(sc.LumpNum).c_str();
if (!info->SetReplacement(replaceName))
{

View file

@ -170,7 +170,7 @@ do_goto:
statestring += '+';
statestring += sc.String;
}
if (!bag.statedef.SetGotoLabel(statestring))
if (!bag.statedef.SetGotoLabel(statestring.GetChars()))
{
sc.ScriptError("GOTO before first state");
}
@ -207,7 +207,7 @@ do_stop:
{
do
{
bag.statedef.AddStateLabel(statestring);
bag.statedef.AddStateLabel(statestring.GetChars());
statestring = ParseStateString(sc);
if (!statestring.CompareNoCase("GOTO"))
{
@ -230,7 +230,7 @@ do_stop:
}
scp = sc;
state.sprite = GetSpriteIndex(statestring);
state.sprite = GetSpriteIndex(statestring.GetChars());
state.Misc1 = state.Misc2 = 0;
sc.MustGetString();
statestring = sc.String;
@ -334,7 +334,7 @@ endofstate:
auto funcsym = CreateAnonymousFunction(actor->VMType, nullptr, state.UseFlags);
state.ActionFunc = FunctionBuildList.AddFunction(bag.Namespace, bag.Version, funcsym, ScriptCode, FStringf("%s.StateFunction.%d", actor->TypeName.GetChars(), bag.statedef.GetStateCount()), true, bag.statedef.GetStateCount(), int(statestring.Len()), sc.LumpNum);
}
int count = bag.statedef.AddStates(&state, statestring, scp);
int count = bag.statedef.AddStates(&state, statestring.GetChars(), scp);
if (count < 0)
{
sc.ScriptError("Invalid frame character string '%s'", statestring.GetChars());

View file

@ -433,12 +433,12 @@ void ParseScripts()
if (FScriptPosition::ErrorCounter > 0)
{
// Abort if the compiler produced any errors. Also do not compile further lumps, because they very likely miss some stuff.
I_Error("%d errors, %d warnings while compiling %s", FScriptPosition::ErrorCounter, FScriptPosition::WarnCounter, fileSystem.GetFileFullPath(lump).GetChars());
I_Error("%d errors, %d warnings while compiling %s", FScriptPosition::ErrorCounter, FScriptPosition::WarnCounter, fileSystem.GetFileFullPath(lump).c_str());
}
else if (FScriptPosition::WarnCounter > 0)
{
// If we got warnings, but no errors, print the information but continue.
Printf(TEXTCOLOR_ORANGE "%d warnings while compiling %s\n", FScriptPosition::WarnCounter, fileSystem.GetFileFullPath(lump).GetChars());
Printf(TEXTCOLOR_ORANGE "%d warnings while compiling %s\n", FScriptPosition::WarnCounter, fileSystem.GetFileFullPath(lump).c_str());
}
}

View file

@ -256,6 +256,7 @@ union FPropParam
int i;
double d;
const char *s;
VMFunction* fu;
FxExpression *exp;
};
@ -313,6 +314,9 @@ int MatchString (const char *in, const char **strings);
#define PROP_STRING_PARM(var, no) \
const char *var = params[(no)+1].s;
#define PROP_NAME_PARM(var, no) \
FName var = params[(no)+1].s;
#define PROP_EXP_PARM(var, no) \
FxExpression *var = params[(no)+1].exp;
@ -325,6 +329,9 @@ int MatchString (const char *in, const char **strings);
#define PROP_DOUBLE_PARM(var, no) \
double var = params[(no)+1].d;
#define PROP_FUNC_PARM(var, no) \
auto var = params[(no)+1].fu;
#define PROP_COLOR_PARM(var, no, scriptpos) \
int var = params[(no)+1].i== 0? params[(no)+2].i : V_GetColor(params[(no)+2].s, scriptpos);

View file

@ -152,18 +152,18 @@ bool ModActorFlag(AActor *actor, const FString &flagname, bool set, bool printer
if (actor != NULL)
{
auto Level = actor->Level;
const char *dot = strchr(flagname, '.');
const char *dot = strchr(flagname.GetChars(), '.');
FFlagDef *fd;
PClassActor *cls = actor->GetClass();
if (dot != NULL)
{
FString part1(flagname.GetChars(), dot - flagname);
fd = FindFlag(cls, part1, dot + 1);
FString part1(flagname.GetChars(), dot - flagname.GetChars());
fd = FindFlag(cls, part1.GetChars(), dot + 1);
}
else
{
fd = FindFlag(cls, flagname, NULL);
fd = FindFlag(cls, flagname.GetChars(), NULL);
}
if (fd != NULL)
@ -245,7 +245,7 @@ INTBOOL CheckActorFlag(AActor *owner, const char *flagname, bool printerror)
if (dot != NULL)
{
FString part1(flagname, dot-flagname);
fd = FindFlag (cls, part1, dot+1);
fd = FindFlag (cls, part1.GetChars(), dot+1);
}
else
{
@ -1377,7 +1377,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(powerup, type, S, PowerupGiver)
{
FString st;
st.Format("%s%s", strnicmp(str, "power", 5) ? "Power" : "", str);
cls = FindClassTentative(st, pow);
cls = FindClassTentative(st.GetChars(), pow);
}
else
{

View file

@ -80,7 +80,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, SetCameraToTexture, SetCameraToTexture)
static void SetCameraTextureAspectRatio(const FString &texturename, double aspectScale, bool useTextureRatio)
{
FTextureID textureid = TexMan.CheckForTexture(texturename, ETextureType::Wall, FTextureManager::TEXMAN_Overridable);
FTextureID textureid = TexMan.CheckForTexture(texturename.GetChars(), ETextureType::Wall, FTextureManager::TEXMAN_Overridable);
if (textureid.isValid())
{
// Only proceed if the texture actually has a canvas.
@ -1026,7 +1026,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetXOffset, SetXOffset)
static void SetEnvironment(sector_t *self, const FString &env)
{
self->Level->Zones[self->ZoneNumber].Environment = S_FindEnvironment(env);
self->Level->Zones[self->ZoneNumber].Environment = S_FindEnvironment(env.GetChars());
}
DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetEnvironment, SetEnvironment)
@ -1723,7 +1723,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetXOffset, SetXOffset)
// This is needed to convert the strings to char pointers.
static void ReplaceTextures(FLevelLocals *self, const FString &from, const FString &to, int flags)
{
self->ReplaceTextures(from, to, flags);
self->ReplaceTextures(from.GetChars(), to.GetChars(), flags);
}
DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, ReplaceTextures, ReplaceTextures)
@ -1732,7 +1732,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, ReplaceTextures, ReplaceTextures)
PARAM_STRING(from);
PARAM_STRING(to);
PARAM_INT(flags);
self->ReplaceTextures(from, to, flags);
self->ReplaceTextures(from.GetChars(), to.GetChars(), flags);
return 0;
}
@ -2097,7 +2097,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, Draw, SBar_Draw)
static void SetMugshotState(DBaseStatusBar *self, const FString &statename, bool wait, bool reset)
{
self->mugshot.SetState(statename, wait, reset);
self->mugshot.SetState(statename.GetChars(), wait, reset);
}
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, SetMugshotState, SetMugshotState)
@ -2106,7 +2106,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, SetMugshotState, SetMugshotState)
PARAM_STRING(statename);
PARAM_BOOL(wait);
PARAM_BOOL(reset);
self->mugshot.SetState(statename, wait, reset);
self->mugshot.SetState(statename.GetChars(), wait, reset);
return 0;
}
@ -2201,7 +2201,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, ReceivedWeapon, ReceivedWeapon)
static int GetMugshot(DBaseStatusBar *self, int accuracy, int stateflags, const FString &def_face)
{
auto tex = self->mugshot.GetFace(self->CPlayer, def_face, accuracy, (FMugShot::StateFlags)stateflags);
auto tex = self->mugshot.GetFace(self->CPlayer, def_face.GetChars(), accuracy, (FMugShot::StateFlags)stateflags);
return (tex ? tex->GetID().GetIndex() : -1);
}
@ -2614,7 +2614,7 @@ DEFINE_ACTION_FUNCTION(DObject, S_ChangeMusic)
PARAM_INT(order);
PARAM_BOOL(looping);
PARAM_BOOL(force);
ACTION_RETURN_BOOL(S_ChangeMusic(music, order, looping, force));
ACTION_RETURN_BOOL(S_ChangeMusic(music.GetChars(), order, looping, force));
}

View file

@ -50,6 +50,7 @@ bool isActor(PContainerType *type);
void AddActorInfo(PClass *cls);
int GetIntConst(FxExpression* ex, FCompileContext& ctx);
double GetFloatConst(FxExpression* ex, FCompileContext& ctx);
VMFunction* GetFuncConst(FxExpression* ex, FCompileContext& ctx);
//==========================================================================
//
@ -69,6 +70,7 @@ int ZCCDoomCompiler::Compile()
InitDefaults();
InitFunctions();
CompileStates();
InitDefaultFunctionPointers();
return FScriptPosition::ErrorCounter;
}
@ -282,6 +284,10 @@ void ZCCDoomCompiler::DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *pr
conv.d = GetFloatConst(ex, ctx);
break;
case 'G':
conv.fu = GetFuncConst(ex, ctx);
break;
case 'Z': // an optional string. Does not allow any numeric value.
if (ex->ValueType != TypeString)
{
@ -390,6 +396,46 @@ void ZCCDoomCompiler::DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *pr
//
//==========================================================================
PFunction * FindFunctionPointer(PClass * cls, int fn_name);
PFunction *NativeFunctionPointerCast(PFunction *from, const PFunctionPointer *to);
struct FunctionPointerProperties
{
ZCC_PropertyStmt *prop;
PClass * cls;
FName name;
const PFunctionPointer * type;
PFunction ** addr;
};
TArray<FunctionPointerProperties> DefaultFunctionPointers;
void ZCCDoomCompiler::InitDefaultFunctionPointers()
{
for(auto &d : DefaultFunctionPointers)
{
PFunction * fn = FindFunctionPointer(d.cls, d.name.GetIndex());
if(!fn)
{
Error(d.prop, "Could not find function '%s' in class '%s'",d.name.GetChars(), d.cls->TypeName.GetChars());
}
else
{
PFunction * casted = NativeFunctionPointerCast(fn,d.type);
if(!casted)
{
FString fn_proto_name = PFunctionPointer::GenerateNameForError(fn);
Error(d.prop, "Function has incompatible types, cannot convert from '%s' to '%s'",fn_proto_name.GetChars(), d.type->DescriptiveName());
}
else
{
(*d.addr) = casted;
}
}
}
DefaultFunctionPointers.Clear();
}
void ZCCDoomCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *property, AActor *defaults, Baggage &bag)
{
ZCC_ExprConstant one;
@ -603,6 +649,44 @@ void ZCCDoomCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *
*(PClass**)addr = cls;
}
}
else if (f->Type->isFunctionPointer())
{
const char * fn_str = GetStringConst(ex, ctx);
if (*fn_str == 0 || !stricmp(fn_str, "none"))
{
*(PFunction**)addr = nullptr;
}
else
{
TArray<FString> fn_info(FString(fn_str).Split("::", FString::TOK_SKIPEMPTY));
if(fn_info.Size() != 2)
{
Error(property, "Malformed function pointer property \"%s\", must be \"Class::Function\"",fn_str);
}
PClass * cls = PClass::FindClass(fn_info[0]);
if(!cls)
{
Error(property, "Could not find class '%s'",fn_info[0].GetChars());
*(PFunction**)addr = nullptr;
}
else
{
FName fn_name(fn_info[1], true);
if(fn_name.GetIndex() == 0)
{
Error(property, "Could not find function '%s' in class '%s'",fn_info[1].GetChars(),fn_info[0].GetChars());
*(PFunction**)addr = nullptr;
}
else
{
DefaultFunctionPointers.Push({property, cls, fn_name, static_cast<const PFunctionPointer *>(f->Type), (PFunction**)addr});
*(PFunction**)addr = nullptr;
}
}
}
}
else
{
Error(property, "unhandled property type %s", f->Type->DescriptiveName());
@ -650,7 +734,7 @@ void ZCCDoomCompiler::ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt
}
FPropertyInfo *property = FindProperty(propname);
FPropertyInfo *property = FindProperty(propname.GetChars());
if (property != nullptr && property->category != CAT_INFO)
{
@ -987,7 +1071,7 @@ void ZCCDoomCompiler::CompileStates()
{
auto sl = static_cast<ZCC_StateLabel *>(st);
statename = FName(sl->Label).GetChars();
statedef.AddStateLabel(statename);
statedef.AddStateLabel(statename.GetChars());
break;
}
case AST_StateLine:
@ -1046,7 +1130,7 @@ void ZCCDoomCompiler::CompileStates()
auto l = sl->Lights;
do
{
AddStateLight(&state, StringConstFromNode(l, c->Type()));
AddStateLight(&state, StringConstFromNode(l, c->Type()).GetChars());
l = static_cast<decltype(l)>(l->SiblingNext);
} while (l != sl->Lights);
}
@ -1097,7 +1181,7 @@ void ZCCDoomCompiler::CompileStates()
statename.AppendFormat("+%d", offset);
}
}
if (!statedef.SetGotoLabel(statename))
if (!statedef.SetGotoLabel(statename.GetChars()))
{
Error(sg, "GOTO before first state");
}

View file

@ -25,6 +25,7 @@ private:
void ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt *prop, Baggage &bag);
void ProcessDefaultFlag(PClassActor *cls, ZCC_FlagStmt *flg);
void InitDefaults() override final;
void InitDefaultFunctionPointers();
FxExpression *SetupActionFunction(PClass *cls, ZCC_TreeNode *af, int StateFlags);
void CompileStates();
int CheckActionKeyword(ZCC_FuncDeclarator *f, uint32_t &varflags, int useflags, ZCC_StructWork *c);