mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-02-27 22:31:07 +00:00
- no more Simplify for global constants as well.
This commit is contained in:
parent
061ba48dc1
commit
68c3f42a53
6 changed files with 105 additions and 46 deletions
|
@ -1043,7 +1043,7 @@ class PSymbolConstString : public PSymbolConst
|
||||||
public:
|
public:
|
||||||
FString Str;
|
FString Str;
|
||||||
|
|
||||||
PSymbolConstString(FName name, FString &str) : PSymbolConst(name, TypeString), Str(str) {}
|
PSymbolConstString(FName name, const FString &str) : PSymbolConst(name, TypeString), Str(str) {}
|
||||||
PSymbolConstString() {}
|
PSymbolConstString() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1008,6 +1008,7 @@ void FScanner::CheckOpen()
|
||||||
int FScriptPosition::ErrorCounter;
|
int FScriptPosition::ErrorCounter;
|
||||||
int FScriptPosition::WarnCounter;
|
int FScriptPosition::WarnCounter;
|
||||||
bool FScriptPosition::StrictErrors; // makes all OPTERROR messages real errors.
|
bool FScriptPosition::StrictErrors; // makes all OPTERROR messages real errors.
|
||||||
|
bool FScriptPosition::errorout; // call I_Error instead of printing the error itself.
|
||||||
|
|
||||||
FScriptPosition::FScriptPosition(const FScriptPosition &other)
|
FScriptPosition::FScriptPosition(const FScriptPosition &other)
|
||||||
{
|
{
|
||||||
|
|
|
@ -144,9 +144,9 @@ struct FScriptPosition
|
||||||
static int WarnCounter;
|
static int WarnCounter;
|
||||||
static int ErrorCounter;
|
static int ErrorCounter;
|
||||||
static bool StrictErrors;
|
static bool StrictErrors;
|
||||||
|
static bool errorout;
|
||||||
FString FileName;
|
FString FileName;
|
||||||
int ScriptLine;
|
int ScriptLine;
|
||||||
bool errorout = false;
|
|
||||||
|
|
||||||
FScriptPosition()
|
FScriptPosition()
|
||||||
{
|
{
|
||||||
|
|
|
@ -5829,7 +5829,7 @@ FxExpression *FxIdentifier::ResolveMember(FCompileContext &ctx, PStruct *classct
|
||||||
return x->Resolve(ctx);
|
return x->Resolve(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((sym = objtype->Symbols.FindSymbolInTable(Identifier, symtbl)) != nullptr)
|
if (objtype != nullptr && (sym = objtype->Symbols.FindSymbolInTable(Identifier, symtbl)) != nullptr)
|
||||||
{
|
{
|
||||||
if (sym->IsKindOf(RUNTIME_CLASS(PSymbolConst)))
|
if (sym->IsKindOf(RUNTIME_CLASS(PSymbolConst)))
|
||||||
{
|
{
|
||||||
|
@ -7168,7 +7168,6 @@ static bool CheckArgSize(FName fname, FArgumentList &args, int min, int max, FSc
|
||||||
|
|
||||||
FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
||||||
{
|
{
|
||||||
ABORT(ctx.Class);
|
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
|
||||||
for (auto a : ArgList)
|
for (auto a : ArgList)
|
||||||
|
@ -7181,6 +7180,8 @@ FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx.Class != nullptr)
|
||||||
|
{
|
||||||
PFunction *afd = FindClassMemberFunction(ctx.Class, ctx.Class, MethodName, ScriptPosition, &error);
|
PFunction *afd = FindClassMemberFunction(ctx.Class, ctx.Class, MethodName, ScriptPosition, &error);
|
||||||
|
|
||||||
if (afd != nullptr)
|
if (afd != nullptr)
|
||||||
|
@ -7203,6 +7204,7 @@ FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
||||||
delete this;
|
delete this;
|
||||||
return x->Resolve(ctx);
|
return x->Resolve(ctx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < countof(FxFlops); ++i)
|
for (size_t i = 0; i < countof(FxFlops); ++i)
|
||||||
{
|
{
|
||||||
|
@ -7228,7 +7230,7 @@ FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
||||||
if (special != 0 && min >= 0)
|
if (special != 0 && min >= 0)
|
||||||
{
|
{
|
||||||
int paramcount = ArgList.Size();
|
int paramcount = ArgList.Size();
|
||||||
if (ctx.Function == nullptr)
|
if (ctx.Function == nullptr || ctx.Class == nullptr)
|
||||||
{
|
{
|
||||||
ScriptPosition.Message(MSG_ERROR, "Unable to call action special %s from constant declaration", MethodName.GetChars());
|
ScriptPosition.Message(MSG_ERROR, "Unable to call action special %s from constant declaration", MethodName.GetChars());
|
||||||
delete this;
|
delete this;
|
||||||
|
@ -7459,13 +7461,20 @@ FxMemberFunctionCall::~FxMemberFunctionCall()
|
||||||
|
|
||||||
FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
|
FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
|
||||||
{
|
{
|
||||||
ABORT(ctx.Class);
|
|
||||||
PStruct *cls;
|
PStruct *cls;
|
||||||
bool staticonly = false;
|
bool staticonly = false;
|
||||||
bool novirtual = false;
|
bool novirtual = false;
|
||||||
|
|
||||||
PStruct *ccls = nullptr;
|
PStruct *ccls = nullptr;
|
||||||
|
|
||||||
|
if (ctx.Class == nullptr)
|
||||||
|
{
|
||||||
|
// There's no way that a member function call can resolve to a constant so abort right away.
|
||||||
|
ScriptPosition.Message(MSG_ERROR, "Expression is not constant.");
|
||||||
|
delete this;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto a : ArgList)
|
for (auto a : ArgList)
|
||||||
{
|
{
|
||||||
if (a == nullptr)
|
if (a == nullptr)
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
#include "p_lnspec.h"
|
#include "p_lnspec.h"
|
||||||
#include "i_system.h"
|
#include "i_system.h"
|
||||||
#include "gdtoa.h"
|
#include "gdtoa.h"
|
||||||
#include "codegeneration/codegen.h"
|
|
||||||
#include "vmbuilder.h"
|
#include "vmbuilder.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
@ -642,11 +641,11 @@ void ZCCCompiler::CreateClassTypes()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void ZCCCompiler::CopyConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PSymbolTable *ot)
|
void ZCCCompiler::CopyConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PStruct *cls, PSymbolTable *ot)
|
||||||
{
|
{
|
||||||
for (auto c : Constants)
|
for (auto c : Constants)
|
||||||
{
|
{
|
||||||
dest.Push({ c, ot });
|
dest.Push({ c, cls, ot });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,14 +664,14 @@ void ZCCCompiler::CompileAllConstants()
|
||||||
// put all constants in one list to make resolving this easier.
|
// put all constants in one list to make resolving this easier.
|
||||||
TArray<ZCC_ConstantWork> constantwork;
|
TArray<ZCC_ConstantWork> constantwork;
|
||||||
|
|
||||||
CopyConstants(constantwork, Constants, OutputSymbols);
|
CopyConstants(constantwork, Constants, nullptr, OutputSymbols);
|
||||||
for (auto c : Classes)
|
for (auto c : Classes)
|
||||||
{
|
{
|
||||||
CopyConstants(constantwork, c->Constants, &c->Type()->Symbols);
|
CopyConstants(constantwork, c->Constants, c->Type(), &c->Type()->Symbols);
|
||||||
}
|
}
|
||||||
for (auto s : Structs)
|
for (auto s : Structs)
|
||||||
{
|
{
|
||||||
CopyConstants(constantwork, s->Constants, &s->Type()->Symbols);
|
CopyConstants(constantwork, s->Constants, s->Type(), &s->Type()->Symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before starting to resolve the list, let's create symbols for all already resolved ones first (i.e. all literal constants), to reduce work.
|
// Before starting to resolve the list, let's create symbols for all already resolved ones first (i.e. all literal constants), to reduce work.
|
||||||
|
@ -693,7 +692,7 @@ void ZCCCompiler::CompileAllConstants()
|
||||||
donesomething = false;
|
donesomething = false;
|
||||||
for (unsigned i = 0; i < constantwork.Size(); i++)
|
for (unsigned i = 0; i < constantwork.Size(); i++)
|
||||||
{
|
{
|
||||||
if (CompileConstant(constantwork[i].node, constantwork[i].outputtable))
|
if (CompileConstant(&constantwork[i]))
|
||||||
{
|
{
|
||||||
AddConstant(constantwork[i]);
|
AddConstant(constantwork[i]);
|
||||||
// Remove the constant from the list
|
// Remove the constant from the list
|
||||||
|
@ -721,6 +720,9 @@ void ZCCCompiler::AddConstant(ZCC_ConstantWork &constant)
|
||||||
{
|
{
|
||||||
auto def = constant.node;
|
auto def = constant.node;
|
||||||
auto val = def->Value;
|
auto val = def->Value;
|
||||||
|
ExpVal &c = constant.constval;
|
||||||
|
|
||||||
|
// This is for literal constants.
|
||||||
if (val->NodeType == AST_ExprConstant)
|
if (val->NodeType == AST_ExprConstant)
|
||||||
{
|
{
|
||||||
ZCC_ExprConstant *cval = static_cast<ZCC_ExprConstant *>(val);
|
ZCC_ExprConstant *cval = static_cast<ZCC_ExprConstant *>(val);
|
||||||
|
@ -747,14 +749,40 @@ void ZCCCompiler::AddConstant(ZCC_ConstantWork &constant)
|
||||||
Error(def->Value, "Bad type for constant definiton");
|
Error(def->Value, "Bad type for constant definiton");
|
||||||
def->Symbol = nullptr;
|
def->Symbol = nullptr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (c.Type == TypeString)
|
||||||
|
{
|
||||||
|
def->Symbol = new PSymbolConstString(def->NodeName, c.GetString());
|
||||||
|
}
|
||||||
|
else if (c.Type->IsA(RUNTIME_CLASS(PInt)))
|
||||||
|
{
|
||||||
|
// How do we get an Enum type in here without screwing everything up???
|
||||||
|
//auto type = def->Type != nullptr ? def->Type : cval->Type;
|
||||||
|
def->Symbol = new PSymbolConstNumeric(def->NodeName, c.Type, c.GetInt());
|
||||||
|
}
|
||||||
|
else if (c.Type->IsA(RUNTIME_CLASS(PFloat)))
|
||||||
|
{
|
||||||
|
if (def->Type != nullptr)
|
||||||
|
{
|
||||||
|
Error(def, "Enum members must be integer values");
|
||||||
|
}
|
||||||
|
def->Symbol = new PSymbolConstNumeric(def->NodeName, c.Type, c.GetFloat());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error(def->Value, "Bad type for constant definiton");
|
||||||
|
def->Symbol = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (def->Symbol == nullptr)
|
if (def->Symbol == nullptr)
|
||||||
{
|
{
|
||||||
// Create a dummy constant so we don't make any undefined value warnings.
|
// Create a dummy constant so we don't make any undefined value warnings.
|
||||||
def->Symbol = new PSymbolConstNumeric(def->NodeName, TypeError, 0);
|
def->Symbol = new PSymbolConstNumeric(def->NodeName, TypeError, 0);
|
||||||
}
|
}
|
||||||
constant.outputtable->ReplaceSymbol(def->Symbol);
|
constant.Outputtable->ReplaceSymbol(def->Symbol);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -766,13 +794,31 @@ void ZCCCompiler::AddConstant(ZCC_ConstantWork &constant)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
bool ZCCCompiler::CompileConstant(ZCC_ConstantDef *def, PSymbolTable *sym)
|
bool ZCCCompiler::CompileConstant(ZCC_ConstantWork *work)
|
||||||
{
|
{
|
||||||
assert(def->Symbol == nullptr);
|
FCompileContext ctx(work->cls, false);
|
||||||
|
FxExpression *exp = ConvertNode(work->node->Value);
|
||||||
ZCC_Expression *val = Simplify(def->Value, sym, true);
|
try
|
||||||
def->Value = val;
|
{
|
||||||
return (val->NodeType == AST_ExprConstant);
|
FScriptPosition::errorout = true;
|
||||||
|
exp = exp->Resolve(ctx);
|
||||||
|
if (exp == nullptr) return false;
|
||||||
|
FScriptPosition::errorout = false;
|
||||||
|
if (!exp->isConstant())
|
||||||
|
{
|
||||||
|
delete exp;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
work->constval = static_cast<FxConstant*>(exp)->GetValue();
|
||||||
|
delete exp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
// eat the reported error and treat this as a temorary failure. All unresolved contants will be reported at the end.
|
||||||
|
FScriptPosition::errorout = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define ZCC_COMPILE_H
|
#define ZCC_COMPILE_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "codegeneration/codegen.h"
|
||||||
|
|
||||||
struct Baggage;
|
struct Baggage;
|
||||||
struct FPropertyInfo;
|
struct FPropertyInfo;
|
||||||
|
@ -77,7 +78,9 @@ struct ZCC_PropertyWork
|
||||||
struct ZCC_ConstantWork
|
struct ZCC_ConstantWork
|
||||||
{
|
{
|
||||||
ZCC_ConstantDef *node;
|
ZCC_ConstantDef *node;
|
||||||
PSymbolTable *outputtable;
|
PStruct *cls;
|
||||||
|
PSymbolTable *Outputtable;
|
||||||
|
ExpVal constval;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ZCCCompiler
|
class ZCCCompiler
|
||||||
|
@ -93,10 +96,10 @@ private:
|
||||||
void ProcessStruct(ZCC_Struct *node, PSymbolTreeNode *tnode, ZCC_Class *outer);
|
void ProcessStruct(ZCC_Struct *node, PSymbolTreeNode *tnode, ZCC_Class *outer);
|
||||||
void CreateStructTypes();
|
void CreateStructTypes();
|
||||||
void CreateClassTypes();
|
void CreateClassTypes();
|
||||||
void CopyConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PSymbolTable *ot);
|
void CopyConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PStruct *cls, PSymbolTable *ot);
|
||||||
void CompileAllConstants();
|
void CompileAllConstants();
|
||||||
void AddConstant(ZCC_ConstantWork &constant);
|
void AddConstant(ZCC_ConstantWork &constant);
|
||||||
bool CompileConstant(ZCC_ConstantDef *def, PSymbolTable *Symbols);
|
bool CompileConstant(ZCC_ConstantWork *def);
|
||||||
|
|
||||||
void CompileAllFields();
|
void CompileAllFields();
|
||||||
bool CompileFields(PStruct *type, TArray<ZCC_VarDeclarator *> &Fields, PClass *Outer, PSymbolTable *TreeNodes, bool forstruct, bool hasnativechildren = false);
|
bool CompileFields(PStruct *type, TArray<ZCC_VarDeclarator *> &Fields, PClass *Outer, PSymbolTable *TreeNodes, bool forstruct, bool hasnativechildren = false);
|
||||||
|
|
Loading…
Reference in a new issue