mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
- separated the Doom specific parts of the ZScript parser from the core into a subclass.
This commit is contained in:
parent
2838f5792c
commit
466ed4e8f2
10 changed files with 1218 additions and 1062 deletions
|
@ -207,10 +207,6 @@ endif()
|
||||||
|
|
||||||
# Decide on SSE setup
|
# Decide on SSE setup
|
||||||
|
|
||||||
set( SSE_MATTERS NO )
|
|
||||||
|
|
||||||
# with global use of SSE 2 we do not need special handling for selected files
|
|
||||||
if (NOT ZDOOM_USE_SSE2)
|
|
||||||
# SSE only matters on 32-bit targets. We check compiler flags to know if we can do it.
|
# SSE only matters on 32-bit targets. We check compiler flags to know if we can do it.
|
||||||
if( CMAKE_SIZEOF_VOID_P MATCHES "4" AND NOT CMAKE_OSX_ARCHITECTURES MATCHES ppc )
|
if( CMAKE_SIZEOF_VOID_P MATCHES "4" AND NOT CMAKE_OSX_ARCHITECTURES MATCHES ppc )
|
||||||
CHECK_CXX_COMPILER_FLAG( "-msse2 -mfpmath=sse" CAN_DO_MFPMATH )
|
CHECK_CXX_COMPILER_FLAG( "-msse2 -mfpmath=sse" CAN_DO_MFPMATH )
|
||||||
|
@ -218,12 +214,9 @@ if (NOT ZDOOM_USE_SSE2)
|
||||||
if( CAN_DO_MFPMATH )
|
if( CAN_DO_MFPMATH )
|
||||||
set( SSE1_ENABLE "-msse -mfpmath=sse" )
|
set( SSE1_ENABLE "-msse -mfpmath=sse" )
|
||||||
set( SSE2_ENABLE "-msse2 -mfpmath=sse" )
|
set( SSE2_ENABLE "-msse2 -mfpmath=sse" )
|
||||||
set( SSE_MATTERS YES )
|
|
||||||
elseif( CAN_DO_ARCHSSE2 )
|
elseif( CAN_DO_ARCHSSE2 )
|
||||||
set( SSE1_ENABLE -arch:SSE )
|
set( SSE1_ENABLE -arch:SSE )
|
||||||
set( SSE2_ENABLE -arch:SSE2 )
|
set( SSE2_ENABLE -arch:SSE2 )
|
||||||
set( SSE_MATTERS YES )
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -1051,6 +1044,7 @@ set (PCH_SOURCES
|
||||||
scripting/decorate/thingdef_states.cpp
|
scripting/decorate/thingdef_states.cpp
|
||||||
scripting/zscript/ast.cpp
|
scripting/zscript/ast.cpp
|
||||||
scripting/zscript/zcc_compile.cpp
|
scripting/zscript/zcc_compile.cpp
|
||||||
|
scripting/zscript/zcc_compile_doom.cpp
|
||||||
scripting/zscript/zcc_parser.cpp
|
scripting/zscript/zcc_parser.cpp
|
||||||
rendering/swrenderer/textures/r_swtexture.cpp
|
rendering/swrenderer/textures/r_swtexture.cpp
|
||||||
rendering/swrenderer/textures/warptexture.cpp
|
rendering/swrenderer/textures/warptexture.cpp
|
||||||
|
@ -1254,6 +1248,7 @@ include_directories( .
|
||||||
common/scripting/jit
|
common/scripting/jit
|
||||||
common/scripting/core
|
common/scripting/core
|
||||||
common/scripting/interface
|
common/scripting/interface
|
||||||
|
common/scripting/frontend
|
||||||
common/scripting/backend
|
common/scripting/backend
|
||||||
g_statusbar
|
g_statusbar
|
||||||
console
|
console
|
||||||
|
@ -1272,6 +1267,7 @@ include_directories( .
|
||||||
utility
|
utility
|
||||||
utility/nodebuilder
|
utility/nodebuilder
|
||||||
scripting
|
scripting
|
||||||
|
scripting/zscript
|
||||||
rendering
|
rendering
|
||||||
rendering/vulkan/thirdparty
|
rendering/vulkan/thirdparty
|
||||||
../libraries/gdtoa
|
../libraries/gdtoa
|
||||||
|
@ -1453,6 +1449,8 @@ source_group("Common\\Objects" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/
|
||||||
source_group("Common\\Fonts" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/fonts/.+")
|
source_group("Common\\Fonts" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/fonts/.+")
|
||||||
source_group("Common\\File System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/filesystem/.+")
|
source_group("Common\\File System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/filesystem/.+")
|
||||||
source_group("Common\\Scripting" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/.+")
|
source_group("Common\\Scripting" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/.+")
|
||||||
|
source_group("Common\\Scripting\\Interface" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/interface/.+")
|
||||||
|
source_group("Common\\Scripting\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/backend/.+")
|
||||||
source_group("Common\\Scripting\\Core" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/core/.+")
|
source_group("Common\\Scripting\\Core" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/core/.+")
|
||||||
source_group("Common\\Scripting\\JIT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/jit/.+")
|
source_group("Common\\Scripting\\JIT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/jit/.+")
|
||||||
source_group("Common\\Scripting\\VM" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/vm/.+")
|
source_group("Common\\Scripting\\VM" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/vm/.+")
|
||||||
|
|
|
@ -53,6 +53,8 @@
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "thingdef.h"
|
#include "thingdef.h"
|
||||||
|
#include "zcc_parser.h"
|
||||||
|
#include "zcc_compile_doom.h"
|
||||||
|
|
||||||
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
||||||
void InitThingdef();
|
void InitThingdef();
|
||||||
|
@ -408,6 +410,34 @@ void ParseAllDecorate();
|
||||||
void SynthesizeFlagFields();
|
void SynthesizeFlagFields();
|
||||||
void SetDoomCompileEnvironment();
|
void SetDoomCompileEnvironment();
|
||||||
|
|
||||||
|
void ParseScripts()
|
||||||
|
{
|
||||||
|
int lump, lastlump = 0;
|
||||||
|
FScriptPosition::ResetErrorCounter();
|
||||||
|
|
||||||
|
while ((lump = fileSystem.FindLump("ZSCRIPT", &lastlump)) != -1)
|
||||||
|
{
|
||||||
|
ZCCParseState state;
|
||||||
|
auto newns = ParseOneScript(lump, state);
|
||||||
|
PSymbolTable symtable;
|
||||||
|
|
||||||
|
ZCCDoomCompiler cc(state, NULL, symtable, newns, lump, state.ParseVersion);
|
||||||
|
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(lump).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(lump).GetChars());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LoadActors()
|
void LoadActors()
|
||||||
{
|
{
|
||||||
cycle_t timer;
|
cycle_t timer;
|
||||||
|
|
|
@ -191,10 +191,6 @@ inline void ResetBaggage (Baggage *bag, PClassActor *stateclass)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
AFuncDesc *FindFunction(PContainerType *cls, const char * string);
|
|
||||||
FieldDesc *FindField(PContainerType *cls, const char * string);
|
|
||||||
|
|
||||||
|
|
||||||
FxExpression *ParseExpression(FScanner &sc, PClassActor *cls, PNamespace *resolvenspc = nullptr);
|
FxExpression *ParseExpression(FScanner &sc, PClassActor *cls, PNamespace *resolvenspc = nullptr);
|
||||||
void ParseStates(FScanner &sc, PClassActor *actor, AActor *defaults, Baggage &bag);
|
void ParseStates(FScanner &sc, PClassActor *actor, AActor *defaults, Baggage &bag);
|
||||||
void ParseFunctionParameters(FScanner &sc, PClassActor *cls, TArray<FxExpression *> &out_params,
|
void ParseFunctionParameters(FScanner &sc, PClassActor *cls, TArray<FxExpression *> &out_params,
|
||||||
|
|
|
@ -1606,24 +1606,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, ReplaceTextures, ReplaceTextures)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//=====================================================================================
|
|
||||||
//
|
|
||||||
// textures
|
|
||||||
//
|
|
||||||
//=====================================================================================
|
|
||||||
|
|
||||||
void SetCameraToTexture(AActor *viewpoint, const FString &texturename, double fov);
|
|
||||||
|
|
||||||
DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, SetCameraToTexture, SetCameraToTexture)
|
|
||||||
{
|
|
||||||
PARAM_PROLOGUE;
|
|
||||||
PARAM_OBJECT(viewpoint, AActor);
|
|
||||||
PARAM_STRING(texturename); // [ZZ] there is no point in having this as FTextureID because it's easier to refer to a cameratexture by name and it isn't executed too often to cache it.
|
|
||||||
PARAM_FLOAT(fov);
|
|
||||||
SetCameraToTexture(viewpoint, texturename, fov);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int CheckForTexture(const FString& name, int type, int flags)
|
static int CheckForTexture(const FString& name, int type, int flags)
|
||||||
{
|
{
|
||||||
return TexMan.CheckForTexture(name, static_cast<ETextureType>(type), flags).GetIndex();
|
return TexMan.CheckForTexture(name, static_cast<ETextureType>(type), flags).GetIndex();
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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);
|
||||||
|
|
1100
src/scripting/zscript/zcc_compile_doom.cpp
Normal file
1100
src/scripting/zscript/zcc_compile_doom.cpp
Normal file
File diff suppressed because it is too large
Load diff
34
src/scripting/zscript/zcc_compile_doom.h
Normal file
34
src/scripting/zscript/zcc_compile_doom.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#pragma once
|
||||||
|
#include "zcc_compile.h"
|
||||||
|
|
||||||
|
void SetImplicitArgs(TArray<PType*>* args, TArray<uint32_t>* argflags, TArray<FName>* argnames, PContainerType* cls, uint32_t funcflags, int useflags);
|
||||||
|
|
||||||
|
class ZCCDoomCompiler : public ZCCCompiler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ZCCDoomCompiler(ZCC_AST &tree, DObject *outer, PSymbolTable &symbols, PNamespace *outnamespace, int lumpnum, const VersionInfo & ver)
|
||||||
|
: ZCCCompiler(tree, outer, symbols, outnamespace, lumpnum, ver)
|
||||||
|
{}
|
||||||
|
int Compile() override;
|
||||||
|
protected:
|
||||||
|
bool PrepareMetaData(PClass *type) override;
|
||||||
|
void SetImplicitArgs(TArray<PType*>* args, TArray<uint32_t>* argflags, TArray<FName>* argnames, PContainerType* cls, uint32_t funcflags, int useflags) override
|
||||||
|
{
|
||||||
|
::SetImplicitArgs(args, argflags, argnames, cls, funcflags, useflags);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void CompileAllProperties();
|
||||||
|
bool CompileProperties(PClass *type, TArray<ZCC_Property *> &Properties, FName prefix);
|
||||||
|
bool CompileFlagDefs(PClass *type, TArray<ZCC_FlagDef *> &Properties, FName prefix);
|
||||||
|
void DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *property, AActor *defaults, Baggage &bag);
|
||||||
|
void DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *property, AActor *defaults, Baggage &bag);
|
||||||
|
void ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt *prop, Baggage &bag);
|
||||||
|
void ProcessDefaultFlag(PClassActor *cls, ZCC_FlagStmt *flg);
|
||||||
|
void InitDefaults();
|
||||||
|
FxExpression *SetupActionFunction(PClass *cls, ZCC_TreeNode *af, int StateFlags);
|
||||||
|
void CompileStates();
|
||||||
|
int CheckActionKeyword(ZCC_FuncDeclarator *f, uint32_t &varflags, int useflags, ZCC_StructWork *c);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue