Web: Optional error management and error tightening.

Saves about 6.5K
This commit is contained in:
John Kessenich 2019-08-10 10:41:15 -06:00
parent fb4f2333da
commit d8834df992
10 changed files with 1144 additions and 1109 deletions

View File

@ -67,6 +67,8 @@ void TParseContextBase::outputMessage(const TSourceLoc& loc, const char* szReaso
} }
} }
#if !defined(GLSLANG_WEB) || defined(GLSLANG_WEB_DEVEL)
void C_DECL TParseContextBase::error(const TSourceLoc& loc, const char* szReason, const char* szToken, void C_DECL TParseContextBase::error(const TSourceLoc& loc, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) const char* szExtraInfoFormat, ...)
{ {
@ -113,6 +115,8 @@ void C_DECL TParseContextBase::ppWarn(const TSourceLoc& loc, const char* szReaso
va_end(args); va_end(args);
} }
#endif
// //
// Both test and if necessary, spit out an error, to see if the node is really // Both test and if necessary, spit out an error, to see if the node is really
// an l-value that can be operated on this way. // an l-value that can be operated on this way.

View File

@ -5813,6 +5813,7 @@ void TParseContext::layoutQualifierCheck(const TSourceLoc& loc, const TQualifier
// output block declarations, and output block member declarations." // output block declarations, and output block member declarations."
switch (qualifier.storage) { switch (qualifier.storage) {
#ifndef GLSLANG_WEB
case EvqVaryingIn: case EvqVaryingIn:
{ {
const char* feature = "location qualifier on input"; const char* feature = "location qualifier on input";
@ -5847,6 +5848,7 @@ void TParseContext::layoutQualifierCheck(const TSourceLoc& loc, const TQualifier
} }
break; break;
} }
#endif
case EvqUniform: case EvqUniform:
case EvqBuffer: case EvqBuffer:
{ {
@ -7243,6 +7245,7 @@ void TParseContext::declareBlock(const TSourceLoc& loc, TTypeList& typeList, con
if (memberQualifier.hasLocation()) { if (memberQualifier.hasLocation()) {
const char* feature = "location on block member"; const char* feature = "location on block member";
switch (currentBlockQualifier.storage) { switch (currentBlockQualifier.storage) {
#ifndef GLSLANG_WEB
case EvqVaryingIn: case EvqVaryingIn:
case EvqVaryingOut: case EvqVaryingOut:
requireProfile(memberLoc, ECoreProfile | ECompatibilityProfile | EEsProfile, feature); requireProfile(memberLoc, ECoreProfile | ECompatibilityProfile | EEsProfile, feature);
@ -7250,6 +7253,7 @@ void TParseContext::declareBlock(const TSourceLoc& loc, TTypeList& typeList, con
profileRequires(memberLoc, EEsProfile, 320, Num_AEP_shader_io_blocks, AEP_shader_io_blocks, feature); profileRequires(memberLoc, EEsProfile, 320, Num_AEP_shader_io_blocks, AEP_shader_io_blocks, feature);
memberWithLocation = true; memberWithLocation = true;
break; break;
#endif
default: default:
error(memberLoc, "can only use in an in/out block", feature, ""); error(memberLoc, "can only use in an in/out block", feature, "");
break; break;

View File

@ -97,6 +97,7 @@ public:
} }
virtual ~TParseContextBase() { } virtual ~TParseContextBase() { }
#if !defined(GLSLANG_WEB) || defined(GLSLANG_WEB_DEVEL)
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken, virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...); const char* szExtraInfoFormat, ...);
virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken, virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
@ -105,6 +106,7 @@ public:
const char* szExtraInfoFormat, ...); const char* szExtraInfoFormat, ...);
virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken, virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...); const char* szExtraInfoFormat, ...);
#endif
virtual void setLimits(const TBuiltInResource&) = 0; virtual void setLimits(const TBuiltInResource&) = 0;

View File

@ -563,9 +563,8 @@ const char* StageName(EShLanguage stage)
void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions, const char* const extensions[], const char* featureDesc) void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions, const char* const extensions[], const char* featureDesc)
{ {
if (profile & profileMask) { if (profile & profileMask) {
bool okay = false; bool okay = minVersion > 0 && version >= minVersion;
if (minVersion > 0 && version >= minVersion) #ifndef GLSLANG_WEB
okay = true;
for (int i = 0; i < numExtensions; ++i) { for (int i = 0; i < numExtensions; ++i) {
switch (getExtensionBehavior(extensions[i])) { switch (getExtensionBehavior(extensions[i])) {
case EBhWarn: case EBhWarn:
@ -578,7 +577,7 @@ void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int
default: break; // some compilers want this default: break; // some compilers want this
} }
} }
#endif
if (! okay) if (! okay)
error(loc, "not supported for this version or the enabled extensions", featureDesc, ""); error(loc, "not supported for this version or the enabled extensions", featureDesc, "");
} }

View File

@ -300,7 +300,7 @@ GLSLANG_WEB_EXCLUDE_OFF
%type <interm.intermTypedNode> conditional_expression constant_expression %type <interm.intermTypedNode> conditional_expression constant_expression
%type <interm.intermTypedNode> logical_or_expression logical_xor_expression logical_and_expression %type <interm.intermTypedNode> logical_or_expression logical_xor_expression logical_and_expression
%type <interm.intermTypedNode> shift_expression and_expression exclusive_or_expression inclusive_or_expression %type <interm.intermTypedNode> shift_expression and_expression exclusive_or_expression inclusive_or_expression
%type <interm.intermTypedNode> function_call initializer initializer_list condition conditionopt %type <interm.intermTypedNode> function_call initializer condition conditionopt
%type <interm.intermNode> translation_unit function_definition %type <interm.intermNode> translation_unit function_definition
%type <interm.intermNode> statement simple_statement %type <interm.intermNode> statement simple_statement
@ -342,6 +342,7 @@ GLSLANG_WEB_EXCLUDE_ON
%type <interm.typeList> type_name_list %type <interm.typeList> type_name_list
%type <interm.attributes> attribute attribute_list single_attribute %type <interm.attributes> attribute attribute_list single_attribute
%type <interm.intermNode> demote_statement %type <interm.intermNode> demote_statement
%type <interm.intermTypedNode> initializer_list
GLSLANG_WEB_EXCLUDE_OFF GLSLANG_WEB_EXCLUDE_OFF
%start translation_unit %start translation_unit
@ -857,7 +858,6 @@ declaration
} }
| PRECISION precision_qualifier type_specifier SEMICOLON { | PRECISION precision_qualifier type_specifier SEMICOLON {
parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "precision statement"); parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "precision statement");
// lazy setting of the previous scope's defaults, has effect only the first time it is called in a particular scope // lazy setting of the previous scope's defaults, has effect only the first time it is called in a particular scope
parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]); parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]);
parseContext.setDefaultPrecision($1.loc, $3, $2.qualifier.precision); parseContext.setDefaultPrecision($1.loc, $3, $2.qualifier.precision);
@ -1137,7 +1137,6 @@ fully_specified_type
parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type"); parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type"); parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
} }
parseContext.precisionQualifierCheck($$.loc, $$.basicType, $$.qualifier); parseContext.precisionQualifierCheck($$.loc, $$.basicType, $$.qualifier);
} }
| type_qualifier type_specifier { | type_qualifier type_specifier {
@ -3339,6 +3338,7 @@ initializer
: assignment_expression { : assignment_expression {
$$ = $1; $$ = $1;
} }
GLSLANG_WEB_EXCLUDE_ON
| LEFT_BRACE initializer_list RIGHT_BRACE { | LEFT_BRACE initializer_list RIGHT_BRACE {
const char* initFeature = "{ } style initializers"; const char* initFeature = "{ } style initializers";
parseContext.requireProfile($1.loc, ~EEsProfile, initFeature); parseContext.requireProfile($1.loc, ~EEsProfile, initFeature);
@ -3351,8 +3351,10 @@ initializer
parseContext.profileRequires($1.loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature); parseContext.profileRequires($1.loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
$$ = $2; $$ = $2;
} }
GLSLANG_WEB_EXCLUDE_OFF
; ;
GLSLANG_WEB_EXCLUDE_ON
initializer_list initializer_list
: initializer { : initializer {
$$ = parseContext.intermediate.growAggregate(0, $1, $1->getLoc()); $$ = parseContext.intermediate.growAggregate(0, $1, $1->getLoc());
@ -3361,6 +3363,7 @@ initializer_list
$$ = parseContext.intermediate.growAggregate($1, $3); $$ = parseContext.intermediate.growAggregate($1, $3);
} }
; ;
GLSLANG_WEB_EXCLUDE_OFF
declaration_statement declaration_statement
: declaration { $$ = $1; } : declaration { $$ = $1; }
@ -3726,11 +3729,13 @@ external_declaration
| declaration { | declaration {
$$ = $1; $$ = $1;
} }
GLSLANG_WEB_EXCLUDE_ON
| SEMICOLON { | SEMICOLON {
parseContext.requireProfile($1.loc, ~EEsProfile, "extraneous semicolon"); parseContext.requireProfile($1.loc, ~EEsProfile, "extraneous semicolon");
parseContext.profileRequires($1.loc, ~EEsProfile, 460, nullptr, "extraneous semicolon"); parseContext.profileRequires($1.loc, ~EEsProfile, 460, nullptr, "extraneous semicolon");
$$ = nullptr; $$ = nullptr;
} }
GLSLANG_WEB_EXCLUDE_OFF
; ;
function_definition function_definition

View File

@ -300,7 +300,7 @@ extern int yylex(YYSTYPE*, TParseContext&);
%type <interm.intermTypedNode> conditional_expression constant_expression %type <interm.intermTypedNode> conditional_expression constant_expression
%type <interm.intermTypedNode> logical_or_expression logical_xor_expression logical_and_expression %type <interm.intermTypedNode> logical_or_expression logical_xor_expression logical_and_expression
%type <interm.intermTypedNode> shift_expression and_expression exclusive_or_expression inclusive_or_expression %type <interm.intermTypedNode> shift_expression and_expression exclusive_or_expression inclusive_or_expression
%type <interm.intermTypedNode> function_call initializer initializer_list condition conditionopt %type <interm.intermTypedNode> function_call initializer condition conditionopt
%type <interm.intermNode> translation_unit function_definition %type <interm.intermNode> translation_unit function_definition
%type <interm.intermNode> statement simple_statement %type <interm.intermNode> statement simple_statement
@ -342,6 +342,7 @@ extern int yylex(YYSTYPE*, TParseContext&);
%type <interm.typeList> type_name_list %type <interm.typeList> type_name_list
%type <interm.attributes> attribute attribute_list single_attribute %type <interm.attributes> attribute attribute_list single_attribute
%type <interm.intermNode> demote_statement %type <interm.intermNode> demote_statement
%type <interm.intermTypedNode> initializer_list
%start translation_unit %start translation_unit
@ -857,7 +858,6 @@ declaration
} }
| PRECISION precision_qualifier type_specifier SEMICOLON { | PRECISION precision_qualifier type_specifier SEMICOLON {
parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "precision statement"); parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "precision statement");
// lazy setting of the previous scope's defaults, has effect only the first time it is called in a particular scope // lazy setting of the previous scope's defaults, has effect only the first time it is called in a particular scope
parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]); parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]);
parseContext.setDefaultPrecision($1.loc, $3, $2.qualifier.precision); parseContext.setDefaultPrecision($1.loc, $3, $2.qualifier.precision);
@ -1137,7 +1137,6 @@ fully_specified_type
parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type"); parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type");
parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type"); parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
} }
parseContext.precisionQualifierCheck($$.loc, $$.basicType, $$.qualifier); parseContext.precisionQualifierCheck($$.loc, $$.basicType, $$.qualifier);
} }
| type_qualifier type_specifier { | type_qualifier type_specifier {
@ -3339,6 +3338,7 @@ initializer
: assignment_expression { : assignment_expression {
$$ = $1; $$ = $1;
} }
| LEFT_BRACE initializer_list RIGHT_BRACE { | LEFT_BRACE initializer_list RIGHT_BRACE {
const char* initFeature = "{ } style initializers"; const char* initFeature = "{ } style initializers";
parseContext.requireProfile($1.loc, ~EEsProfile, initFeature); parseContext.requireProfile($1.loc, ~EEsProfile, initFeature);
@ -3351,8 +3351,10 @@ initializer
parseContext.profileRequires($1.loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature); parseContext.profileRequires($1.loc, ~EEsProfile, 420, E_GL_ARB_shading_language_420pack, initFeature);
$$ = $2; $$ = $2;
} }
; ;
initializer_list initializer_list
: initializer { : initializer {
$$ = parseContext.intermediate.growAggregate(0, $1, $1->getLoc()); $$ = parseContext.intermediate.growAggregate(0, $1, $1->getLoc());
@ -3362,6 +3364,7 @@ initializer_list
} }
; ;
declaration_statement declaration_statement
: declaration { $$ = $1; } : declaration { $$ = $1; }
; ;
@ -3726,11 +3729,13 @@ external_declaration
| declaration { | declaration {
$$ = $1; $$ = $1;
} }
| SEMICOLON { | SEMICOLON {
parseContext.requireProfile($1.loc, ~EEsProfile, "extraneous semicolon"); parseContext.requireProfile($1.loc, ~EEsProfile, "extraneous semicolon");
parseContext.profileRequires($1.loc, ~EEsProfile, 460, nullptr, "extraneous semicolon"); parseContext.profileRequires($1.loc, ~EEsProfile, 460, nullptr, "extraneous semicolon");
$$ = nullptr; $$ = nullptr;
} }
; ;
function_definition function_definition

File diff suppressed because it is too large Load Diff

View File

@ -56,8 +56,10 @@ namespace glslang {
// //
void TIntermediate::error(TInfoSink& infoSink, const char* message) void TIntermediate::error(TInfoSink& infoSink, const char* message)
{ {
#ifndef GLSLANG_WEB
infoSink.info.prefix(EPrefixError); infoSink.info.prefix(EPrefixError);
infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n"; infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n";
#endif
++numErrors; ++numErrors;
} }
@ -65,8 +67,10 @@ void TIntermediate::error(TInfoSink& infoSink, const char* message)
// Link-time warning. // Link-time warning.
void TIntermediate::warn(TInfoSink& infoSink, const char* message) void TIntermediate::warn(TInfoSink& infoSink, const char* message)
{ {
#ifndef GLSLANG_WEB
infoSink.info.prefix(EPrefixWarning); infoSink.info.prefix(EPrefixWarning);
infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n"; infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n";
#endif
} }
// TODO: 4.4 offset/align: "Two blocks linked together in the same program with the same block // TODO: 4.4 offset/align: "Two blocks linked together in the same program with the same block

View File

@ -137,6 +137,17 @@ public:
virtual void requireVulkan(const TSourceLoc&, const char* op); virtual void requireVulkan(const TSourceLoc&, const char* op);
virtual void requireSpv(const TSourceLoc&, const char* op); virtual void requireSpv(const TSourceLoc&, const char* op);
#if defined(GLSLANG_WEB) && !defined(GLSLANG_WEB_DEVEL)
void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) { addError(); }
void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) { }
void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) { addError(); }
void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) { }
#else
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken, virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) = 0; const char* szExtraInfoFormat, ...) = 0;
virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken, virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
@ -145,6 +156,7 @@ public:
const char* szExtraInfoFormat, ...) = 0; const char* szExtraInfoFormat, ...) = 0;
virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken, virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
const char* szExtraInfoFormat, ...) = 0; const char* szExtraInfoFormat, ...) = 0;
#endif
void addError() { ++numErrors; } void addError() { ++numErrors; }
int getNumErrors() const { return numErrors; } int getNumErrors() const { return numErrors; }

View File

@ -116,6 +116,7 @@ int TPpContext::TokenStream::getToken(TParseContextBase& parseContext, TPpToken
int atom = stream[currentPos++].get(*ppToken); int atom = stream[currentPos++].get(*ppToken);
ppToken->loc = parseContext.getCurrentLoc(); ppToken->loc = parseContext.getCurrentLoc();
#ifndef GLSLANG_WEB
// Check for ##, unless the current # is the last character // Check for ##, unless the current # is the last character
if (atom == '#') { if (atom == '#') {
if (peekToken('#')) { if (peekToken('#')) {
@ -125,6 +126,7 @@ int TPpContext::TokenStream::getToken(TParseContextBase& parseContext, TPpToken
atom = PpAtomPaste; atom = PpAtomPaste;
} }
} }
#endif
return atom; return atom;
} }