Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report statement errors #3559

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion StandAlone/StandAlone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ enum TOptions : uint64_t {
EOptionInvertY = (1ull << 30),
EOptionDumpBareVersion = (1ull << 31),
EOptionCompileOnly = (1ull << 32),
EOptionReportStatements = (1ull << 33),
};
bool targetHlslFunctionality1 = false;
bool SpvToolsDisassembler = false;
Expand Down Expand Up @@ -898,6 +899,8 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
Options |= EOptionDumpVersions;
} else if (lowerword == "no-link") {
Options |= EOptionCompileOnly;
} else if (lowerword == "report-statements") {
Options |= EOptionReportStatements;
} else if (lowerword == "help") {
usage();
break;
Expand Down Expand Up @@ -1132,6 +1135,8 @@ void SetMessageOptions(EShMessages& messages)
{
if (Options & EOptionRelaxedErrors)
messages = (EShMessages)(messages | EShMsgRelaxedErrors);
if (Options & EOptionReportStatements)
messages = (EShMessages)(messages | EShMsgReportStatements);
if (Options & EOptionIntermediate)
messages = (EShMessages)(messages | EShMsgAST);
if (Options & EOptionSuppressWarnings)
Expand Down Expand Up @@ -2117,7 +2122,8 @@ void usage()
" initialized with the shader binary code\n"
" --no-link Only compile shader; do not link (GLSL-only)\n"
" NOTE: this option will set the export linkage\n"
" attribute on all functions\n");
" attribute on all functions\n"
" --report-statements Report errors on statement\n");

exit(EFailUsage);
}
Expand Down
1 change: 1 addition & 0 deletions glslang/Include/glslang_c_shader_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ typedef enum {
GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT = (1 << 14),
GLSLANG_MSG_ENHANCED = (1 << 15),
GLSLANG_MSG_ABSOLUTE_PATH = (1 << 16),
GLSLANG_MSG_REPORT_STATEMENTS = (1 << 17),
LAST_ELEMENT_MARKER(GLSLANG_MSG_COUNT),
} glslang_messages_t;

Expand Down
10 changes: 8 additions & 2 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,18 @@ bool TParseContext::parseShaderStrings(TPpContext& ppContext, TInputScanner& inp
// Note though that to stop cascading errors, we set EOF, which
// will usually cause a syntax error, so be more accurate that
// compilation is terminating.
void TParseContext::parserError(const char* s)
void TParseContext::parserError(const TSourceLoc& location, const char* s)
{
if (! getScanner()->atEndOfInput() || numErrors == 0)
error(getCurrentLoc(), "", "", s, "");
error(location, "", "", s, "");
else
{
// if the end of file is received, output the origional error
if ((messages & EShMsgReportStatements) == EShMsgReportStatements) {
error(location, "", "", s, "");
}
error(getCurrentLoc(), "compilation terminated", "", "");
}
}

void TParseContext::growGlobalUniformBlock(const TSourceLoc& loc, TType& memberType, const TString& memberName, TTypeList* typeList)
Expand Down
26 changes: 25 additions & 1 deletion glslang/MachineIndependent/ParseHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,30 @@ class TParseContextBase : public TParseVersions {
int endInvocationInterlockCount;
bool compileOnly = false;

std::vector<glslang::TSourceLoc> _statement;
std::vector<int> _terminator;
std::vector<std::string> _source;


void push_back(const glslang::TSourceLoc& location, int symbol, const std::string&& debug) {

if ( (messages & EShMsgReportStatements) == EShMsgReportStatements)
{
_statement.push_back(location);
_terminator.push_back(symbol);
_source.emplace_back(debug);
}
}

void pop_back() {
if ((messages & EShMsgReportStatements) == EShMsgReportStatements)
{
_statement.pop_back();
_terminator.pop_back();
_source.pop_back();
}
}

protected:
TParseContextBase(TParseContextBase&);
TParseContextBase& operator=(TParseContextBase&);
Expand Down Expand Up @@ -315,7 +339,7 @@ class TParseContext : public TParseContextBase {

void setLimits(const TBuiltInResource&) override;
bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override;
void parserError(const char* s); // for bison's yyerror
void parserError(const TSourceLoc& location, const char* s); // for bison's yyerror

virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr) override;
virtual void growAtomicCounterBlock(int binding, const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr) override;
Expand Down
8 changes: 6 additions & 2 deletions glslang/MachineIndependent/Scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#include "preprocessor/PpTokens.h"

// Required to avoid missing prototype warnings for some compilers
int yylex(YYSTYPE*, glslang::TParseContext&);
int yylex(YYSTYPE*, YYLTYPE, glslang::TParseContext&);

namespace glslang {

Expand Down Expand Up @@ -289,9 +289,13 @@ class TParserToken {
} // end namespace glslang

// This is the function the glslang parser (i.e., bison) calls to get its next token
int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
int yylex(YYSTYPE* glslangTokenDesc, YYLTYPE* l, glslang::TParseContext& parseContext)
{
glslang::TParserToken token(*glslangTokenDesc);
l->column = token.sType.lex.loc.column;
l->line = token.sType.lex.loc.line;
l->name = token.sType.lex.loc.name;
l->string = token.sType.lex.loc.string;

return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
}
Expand Down
1 change: 1 addition & 0 deletions glslang/MachineIndependent/ShaderLang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ bool ProcessDeferred(
lengths[1] = strlen(strings[1]);
names[1] = nullptr;
assert(2 == numPre);

if (requireNonempty) {
const int postIndex = numStrings + numPre;
strings[postIndex] = "\n int;";
Expand Down
Loading