- removed the remaining Doom-specific parts of the script compiler.

This commit is contained in:
Christoph Oelckers 2020-04-08 18:02:53 +02:00
parent 006916a0a6
commit c0217c9152
6 changed files with 54 additions and 75 deletions

View file

@ -228,26 +228,3 @@ void InitImports()
} }
} }
//==========================================================================
//
// SetImplicitArgs
//
// Adds the parameters implied by the function flags.
//
//==========================================================================
void SetImplicitArgs(TArray<PType *> *args, TArray<uint32_t> *argflags, TArray<FName> *argnames, PContainerType *cls, uint32_t funcflags, int useflags)
{
// Must be called before adding any other arguments.
assert(args == nullptr || args->Size() == 0);
assert(argflags == nullptr || argflags->Size() == 0);
if (funcflags & VARF_Method)
{
// implied self pointer
if (args != nullptr) args->Push(NewPointer(cls, !!(funcflags & VARF_ReadOnly)));
if (argflags != nullptr) argflags->Push(VARF_Implicit | VARF_ReadOnly);
if (argnames != nullptr) argnames->Push(NAME_self);
}
}

View file

@ -39,19 +39,18 @@
#include "zcc_compile.h" #include "zcc_compile.h"
#include "printf.h" #include "printf.h"
#include "symbols.h" #include "symbols.h"
//#include "v_video.h"
FSharedStringArena VMStringConstants; FSharedStringArena VMStringConstants;
static int GetIntConst(FxExpression *ex, FCompileContext &ctx) int GetIntConst(FxExpression *ex, FCompileContext &ctx)
{ {
ex = new FxIntCast(ex, false); ex = new FxIntCast(ex, false);
ex = ex->Resolve(ctx); ex = ex->Resolve(ctx);
return ex ? static_cast<FxConstant*>(ex)->GetValue().GetInt() : 0; return ex ? static_cast<FxConstant*>(ex)->GetValue().GetInt() : 0;
} }
static double GetFloatConst(FxExpression *ex, FCompileContext &ctx) double GetFloatConst(FxExpression *ex, FCompileContext &ctx)
{ {
ex = new FxFloatCast(ex); ex = new FxFloatCast(ex);
ex = ex->Resolve(ctx); ex = ex->Resolve(ctx);
@ -641,6 +640,7 @@ void ZCCCompiler::MessageV(ZCC_TreeNode *node, const char *txtcolor, const char
// ZCCCompiler :: Compile // ZCCCompiler :: Compile
// //
// Compile everything defined at this level. // Compile everything defined at this level.
// This can be overridden to add custom content.
// //
//========================================================================== //==========================================================================
@ -1347,15 +1347,13 @@ void ZCCCompiler::CompileAllFields()
type->Size = Classes[i]->ClassType()->ParentClass->Size; type->Size = Classes[i]->ClassType()->ParentClass->Size;
} }
} }
/*if (type->TypeName == NAME_Actor) if (!PrepareMetaData(type))
{ {
assert(type->MetaSize == 0); if (Classes[i]->ClassType()->ParentClass)
AddActorInfo(type); // AActor needs the actor info manually added to its meta data before adding any scripted fields. type->MetaSize = Classes[i]->ClassType()->ParentClass->MetaSize;
else
type->MetaSize = 0;
} }
else*/ if (Classes[i]->ClassType()->ParentClass)
type->MetaSize = Classes[i]->ClassType()->ParentClass->MetaSize;
else
type->MetaSize = 0;
if (CompileFields(type->VMType, Classes[i]->Fields, nullptr, &Classes[i]->TreeNodes, false, !!HasNativeChildren.CheckKey(type->TypeName))) if (CompileFields(type->VMType, Classes[i]->Fields, nullptr, &Classes[i]->TreeNodes, false, !!HasNativeChildren.CheckKey(type->TypeName)))
{ {
@ -1922,11 +1920,33 @@ PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize,
//========================================================================== //==========================================================================
// //
// SetImplicitArgs
// //
// Adds the parameters implied by the function flags.
// //
//========================================================================== //==========================================================================
void ZCCCompiler::SetImplicitArgs(TArray<PType*>* args, TArray<uint32_t>* argflags, TArray<FName>* argnames, PContainerType* cls, uint32_t funcflags, int useflags)
{
// Must be called before adding any other arguments.
assert(args == nullptr || args->Size() == 0);
assert(argflags == nullptr || argflags->Size() == 0);
if (funcflags & VARF_Method)
{
// implied self pointer
if (args != nullptr) args->Push(NewPointer(cls, !!(funcflags & VARF_ReadOnly)));
if (argflags != nullptr) argflags->Push(VARF_Implicit | VARF_ReadOnly);
if (argnames != nullptr) argnames->Push(NAME_self);
}
}
//==========================================================================
//
//
//
//==========================================================================
void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool forclass) void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool forclass)
{ {
@ -2041,14 +2061,14 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
} }
if (f->Flags & ZCC_Action) if (f->Flags & ZCC_Action)
{ {
/* implicitargs = CheckActionKeyword(f,varflags, useflags, c);
if (compileEnvironment.processActionFunc) if (implicitargs < 0)
{ {
Error(f, "'Action' not allowed as a function qualifier");
// Set state to allow continued compilation to find more errors.
varflags &= ~VARF_ReadOnly;
implicitargs = 1;
} }
else
*/
Error(f, "'Action' not allowed as a function qualifier");
} }
if (f->Flags & ZCC_Static) varflags = (varflags & ~VARF_Method) | VARF_Final, implicitargs = 0; // Static implies Final. if (f->Flags & ZCC_Static) varflags = (varflags & ~VARF_Method) | VARF_Final, implicitargs = 0; // Static implies Final.

View file

@ -106,11 +106,14 @@ class ZCCCompiler
{ {
public: public:
ZCCCompiler(ZCC_AST &tree, DObject *outer, PSymbolTable &symbols, PNamespace *outnamespace, int lumpnum, const VersionInfo & ver); ZCCCompiler(ZCC_AST &tree, DObject *outer, PSymbolTable &symbols, PNamespace *outnamespace, int lumpnum, const VersionInfo & ver);
~ZCCCompiler(); virtual ~ZCCCompiler();
int Compile(); virtual int Compile();
private: protected:
const char * GetStringConst(FxExpression *ex, FCompileContext &ctx); const char * GetStringConst(FxExpression *ex, FCompileContext &ctx);
virtual int CheckActionKeyword(ZCC_FuncDeclarator* f, uint32_t &varflags, int useflags, ZCC_StructWork *c) { return -1; } // stock implementation does not support this.
virtual bool PrepareMetaData(PClass *type) { return false; }
virtual void SetImplicitArgs(TArray<PType*>* args, TArray<uint32_t>* argflags, TArray<FName>* argnames, PContainerType* cls, uint32_t funcflags, int useflags);
int IntConstFromNode(ZCC_TreeNode *node, PContainerType *cls); int IntConstFromNode(ZCC_TreeNode *node, PContainerType *cls);
FString StringConstFromNode(ZCC_TreeNode *node, PContainerType *cls); FString StringConstFromNode(ZCC_TreeNode *node, PContainerType *cls);

View file

@ -350,16 +350,20 @@ parse_end:
//**-------------------------------------------------------------------------- //**--------------------------------------------------------------------------
static void DoParse(int lumpnum) PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
{ {
FScanner sc; FScanner sc;
void *parser; void *parser;
ZCCToken value; ZCCToken value;
auto baselump = lumpnum; int lumpnum = baselump;
auto fileno = fileSystem.GetFileContainer(lumpnum); auto fileno = fileSystem.GetFileContainer(lumpnum);
if (TokenMap.CountUsed() == 0)
{
InitTokenMap();
}
parser = ZCCParseAlloc(malloc); parser = ZCCParseAlloc(malloc);
ZCCParseState state;
#ifndef NDEBUG #ifndef NDEBUG
FILE *f = nullptr; FILE *f = nullptr;
@ -471,37 +475,8 @@ static void DoParse(int lumpnum)
} }
} }
PSymbolTable symtable;
auto newns = fileSystem.GetFileContainer(baselump) == 0 ? Namespaces.GlobalNamespace : Namespaces.NewNamespace(fileSystem.GetFileContainer(baselump)); auto newns = fileSystem.GetFileContainer(baselump) == 0 ? Namespaces.GlobalNamespace : Namespaces.NewNamespace(fileSystem.GetFileContainer(baselump));
ZCCCompiler cc(state, NULL, symtable, newns, baselump, state.ParseVersion); return newns;
cc.Compile();
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(baselump).GetChars());
}
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(baselump).GetChars());
}
}
void ParseScripts()
{
if (TokenMap.CountUsed() == 0)
{
InitTokenMap();
}
int lump, lastlump = 0;
FScriptPosition::ResetErrorCounter();
while ((lump = fileSystem.FindLump("ZSCRIPT", &lastlump)) != -1)
{
DoParse(lump);
}
} }
static FString ZCCTokenName(int terminal) static FString ZCCTokenName(int terminal)

View file

@ -618,4 +618,7 @@ const char *GetMixinTypeString(EZCCMixinType type);
ZCC_TreeNode *TreeNodeDeepCopy(ZCC_AST *ast, ZCC_TreeNode *orig, bool copySiblings); ZCC_TreeNode *TreeNodeDeepCopy(ZCC_AST *ast, ZCC_TreeNode *orig, bool copySiblings);
// Main entry point for the parser. Returns some data needed by the compiler.
PNamespace* ParseOneScript(const int baselump, ZCCParseState& state);
#endif #endif

View file

@ -1,6 +1,7 @@
cmake_minimum_required( VERSION 2.8.7 ) cmake_minimum_required( VERSION 2.8.7 )
add_subdirectory( re2c ) add_subdirectory( re2c )
add_subdirectory( lemon )
add_subdirectory( zipdir ) add_subdirectory( zipdir )
set( CROSS_EXPORTS ${CROSS_EXPORTS} PARENT_SCOPE ) set( CROSS_EXPORTS ${CROSS_EXPORTS} PARENT_SCOPE )