mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 15:21:51 +00:00
- count errors in the parser and abort afterward if there were some.
- use FScriptPosition's error counter throughout the compiler so that there is only one counter for everything, not two. Parts of the compiler use FScriptPosition, so this is easier to handle than having a separate counter in the compiler class. It also avoids having to pass the compiler object to any function where an error may be output. The TreeNodes contain sufficient data to be converted to an FScriptPosition and using that for error message formatting.
This commit is contained in:
parent
5f5da26321
commit
2cb5839c11
8 changed files with 32 additions and 8 deletions
|
@ -1248,6 +1248,7 @@ set (PCH_SOURCES
|
|||
scripting/thingdef_data.cpp
|
||||
scripting/thingdef_properties.cpp
|
||||
scripting/codegeneration/codegen.cpp
|
||||
scripting/codegeneration/functioncalls.cpp
|
||||
scripting/decorate/olddecorations.cpp
|
||||
scripting/decorate/thingdef_exp.cpp
|
||||
scripting/decorate/thingdef_parse.cpp
|
||||
|
|
|
@ -1006,6 +1006,7 @@ void FScanner::CheckOpen()
|
|||
//
|
||||
//==========================================================================
|
||||
int FScriptPosition::ErrorCounter;
|
||||
int FScriptPosition::WarnCounter;
|
||||
bool FScriptPosition::StrictErrors; // makes all OPTERRPR messages real errors.
|
||||
|
||||
FScriptPosition::FScriptPosition(const FScriptPosition &other)
|
||||
|
@ -1072,6 +1073,7 @@ void FScriptPosition::Message (int severity, const char *message, ...) const
|
|||
return;
|
||||
|
||||
case MSG_WARNING:
|
||||
WarnCounter++;
|
||||
type = "warning";
|
||||
color = TEXTCOLOR_YELLOW;
|
||||
break;
|
||||
|
|
|
@ -139,6 +139,7 @@ enum
|
|||
|
||||
struct FScriptPosition
|
||||
{
|
||||
static int WarnCounter;
|
||||
static int ErrorCounter;
|
||||
static bool StrictErrors;
|
||||
FString FileName;
|
||||
|
@ -155,6 +156,7 @@ struct FScriptPosition
|
|||
void Message(int severity, const char *message,...) const;
|
||||
static void ResetErrorCounter()
|
||||
{
|
||||
WarnCounter = 0;
|
||||
ErrorCounter = 0;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -127,6 +127,7 @@ void LoadActors ()
|
|||
|
||||
InitThingdef();
|
||||
ParseScripts();
|
||||
|
||||
ParseAllDecorate();
|
||||
|
||||
FunctionBuildList.Build();
|
||||
|
|
|
@ -99,6 +99,7 @@ static void SetNodeLine(ZCC_TreeNode *name, int line)
|
|||
}
|
||||
}
|
||||
stat->sc->ScriptMessage("%s\n%s\n", unexpected.GetChars(), expecting.GetChars());
|
||||
FScriptPosition::ErrorCounter++;
|
||||
}
|
||||
%parse_accept { DPrintf(DMSG_SPAMMY, "Input accepted\n"); }
|
||||
%parse_failure { /**failed = true;*/ }
|
||||
|
|
|
@ -203,8 +203,9 @@ void ZCCCompiler::ProcessStruct(ZCC_Struct *cnode, PSymbolTreeNode *treenode, ZC
|
|||
//==========================================================================
|
||||
|
||||
ZCCCompiler::ZCCCompiler(ZCC_AST &ast, DObject *_outer, PSymbolTable &_symbols, PSymbolTable &_outsymbols)
|
||||
: Outer(_outer), GlobalTreeNodes(&_symbols), OutputSymbols(&_outsymbols), AST(ast), ErrorCount(0), WarnCount(0)
|
||||
: Outer(_outer), GlobalTreeNodes(&_symbols), OutputSymbols(&_outsymbols), AST(ast)
|
||||
{
|
||||
FScriptPosition::ResetErrorCounter();
|
||||
// Group top-level nodes by type
|
||||
if (ast.TopNode != NULL)
|
||||
{
|
||||
|
@ -320,7 +321,7 @@ void ZCCCompiler::Warn(ZCC_TreeNode *node, const char *msg, ...)
|
|||
MessageV(node, TEXTCOLOR_ORANGE, msg, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
WarnCount++;
|
||||
FScriptPosition::WarnCounter++;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -338,7 +339,7 @@ void ZCCCompiler::Error(ZCC_TreeNode *node, const char *msg, ...)
|
|||
MessageV(node, TEXTCOLOR_RED, msg, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
ErrorCount++;
|
||||
FScriptPosition::ErrorCounter++;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -376,7 +377,7 @@ int ZCCCompiler::Compile()
|
|||
InitDefaults();
|
||||
InitFunctions();
|
||||
CompileStates();
|
||||
return ErrorCount;
|
||||
return FScriptPosition::ErrorCounter;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -1678,7 +1679,6 @@ void ZCCCompiler::DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *proper
|
|||
}
|
||||
}
|
||||
// call the handler
|
||||
FScriptPosition::ErrorCounter = 0;
|
||||
try
|
||||
{
|
||||
prop->Handler(defaults, bag.Info, bag, ¶ms[0]);
|
||||
|
@ -1687,7 +1687,6 @@ void ZCCCompiler::DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *proper
|
|||
{
|
||||
Error(property, "%s", error.GetMessage());
|
||||
}
|
||||
ErrorCount += FScriptPosition::ErrorCounter;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -146,8 +146,6 @@ private:
|
|||
PSymbolTable *GlobalTreeNodes;
|
||||
PSymbolTable *OutputSymbols;
|
||||
ZCC_AST *
|
||||
int ErrorCount;
|
||||
int WarnCount;
|
||||
};
|
||||
|
||||
void ZCC_InitConversions();
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "cmdlib.h"
|
||||
#include "m_alloc.h"
|
||||
#include "i_system.h"
|
||||
#include "v_text.h"
|
||||
#include "zcc_parser.h"
|
||||
#include "zcc_compile.h"
|
||||
|
||||
|
@ -323,6 +324,12 @@ static void DoParse(int lumpnum)
|
|||
ZCCParse(parser, 0, value, &state);
|
||||
ZCCParseFree(parser, free);
|
||||
|
||||
// If the parser fails, there is no point starting the compiler, because it'd only flood the output with endless errors.
|
||||
if (FScriptPosition::ErrorCounter > 0)
|
||||
{
|
||||
I_Error("%d errors while parsing %s", FScriptPosition::ErrorCounter, Wads.GetLumpFullPath(lumpnum));
|
||||
}
|
||||
|
||||
{
|
||||
// Make a dump of the AST before running the compiler for diagnostic purposes.
|
||||
#ifdef _DEBUG
|
||||
|
@ -347,11 +354,24 @@ static void DoParse(int lumpnum)
|
|||
symtable.SetName("Global_Node");
|
||||
ZCCCompiler cc(state, NULL, symtable, GlobalSymbols);
|
||||
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, Wads.GetLumpFullPath(lumpnum));
|
||||
}
|
||||
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", FScriptPosition::WarnCounter, Wads.GetLumpFullPath(lumpnum));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ParseScripts()
|
||||
{
|
||||
int lump, lastlump = 0;
|
||||
FScriptPosition::ResetErrorCounter();
|
||||
while ((lump = Wads.FindLump("ZSCRIPT", &lastlump)) != -1)
|
||||
{
|
||||
DoParse(lump);
|
||||
|
|
Loading…
Reference in a new issue