Commit fd8e1010 by John Kessenich

Simply compile-time error handling: mostly removed the need to test an error…

Simply compile-time error handling: mostly removed the need to test an error occurred and the need to call recover(). git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@21959 e7fa87d3-cd2b-0410-9028-fcbf551c1848
parent fbe01520
...@@ -74,8 +74,7 @@ struct TParseContext { ...@@ -74,8 +74,7 @@ struct TParseContext {
TInfoSink& infoSink; TInfoSink& infoSink;
EShLanguage language; // vertex or fragment language EShLanguage language; // vertex or fragment language
TIntermNode* treeRoot; // root of parse tree being created TIntermNode* treeRoot; // root of parse tree being created
bool recoveredFromError; // true if a parse error has occurred, but we continue to parse int numErrors; // number of compile-time errors encountered
int numErrors;
bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier
int loopNestingLevel; // 0 if outside all loops int loopNestingLevel; // 0 if outside all loops
TList<TIntermSequence*> switchSequenceStack; // case, node, case, case, node, ...; ensure only one node between cases; stack of them for nesting TList<TIntermSequence*> switchSequenceStack; // case, node, case, case, node, ...; ensure only one node between cases; stack of them for nesting
...@@ -101,44 +100,43 @@ struct TParseContext { ...@@ -101,44 +100,43 @@ struct TParseContext {
void C_DECL error(TSourceLoc, const char *szReason, const char *szToken, void C_DECL error(TSourceLoc, const char *szReason, const char *szToken,
const char *szExtraInfoFormat, ...); const char *szExtraInfoFormat, ...);
bool reservedErrorCheck(int line, const TString& identifier); bool reservedErrorCheck(int line, const TString& identifier);
void recover();
TIntermTyped* handleVariable(int line, TSymbol* symbol, TString* string); TIntermTyped* handleVariable(int line, TSymbol* symbol, TString* string);
bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line); bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line);
void assignError(int line, const char* op, TString left, TString right); void assignError(int line, const char* op, TString left, TString right);
void unaryOpError(int line, const char* op, TString operand); void unaryOpError(int line, const char* op, TString operand);
void binaryOpError(int line, const char* op, TString left, TString right); void binaryOpError(int line, const char* op, TString left, TString right);
void variableErrorCheck(TIntermTyped*& nodePtr); void variableCheck(TIntermTyped*& nodePtr);
bool lValueErrorCheck(int line, const char* op, TIntermTyped*); bool lValueErrorCheck(int line, const char* op, TIntermTyped*);
bool constErrorCheck(TIntermTyped* node); void constCheck(TIntermTyped* node);
bool integerErrorCheck(TIntermTyped* node, const char* token); void integerCheck(TIntermTyped* node, const char* token);
bool globalErrorCheck(int line, bool global, const char* token); void globalCheck(int line, bool global, const char* token);
bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*); bool constructorError(int line, TIntermNode*, TFunction&, TOperator, TType*);
bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size); void arraySizeCheck(int line, TIntermTyped* expr, int& size);
bool arrayQualifierErrorCheck(int line, const TPublicType&); bool arrayQualifierError(int line, const TPublicType&);
bool arraySizeRequiredErrorCheck(int line, int& size); void arraySizeRequiredCheck(int line, int& size);
bool arrayErrorCheck(int line, TString& identifier, const TPublicType&, TVariable*& variable); void arrayCheck(int line, TString& identifier, const TPublicType&, TVariable*& variable);
bool insertBuiltInArrayAtGlobalLevel(); bool insertBuiltInArrayAtGlobalLevel();
bool voidErrorCheck(int, const TString&, const TPublicType&); bool voidErrorCheck(int, const TString&, const TPublicType&);
bool boolErrorCheck(int, const TIntermTyped*); void boolCheck(int, const TIntermTyped*);
bool boolErrorCheck(int, const TPublicType&); void boolCheck(int, const TPublicType&);
bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason); bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason);
bool globalQualifierFixAndErrorCheck(int line, TQualifier&, const TPublicType&); void globalQualifierFix(int line, TQualifier&, const TPublicType&);
bool structQualifierErrorCheck(int line, const TPublicType& pType); bool structQualifierErrorCheck(int line, const TPublicType& pType);
bool mergeQualifiersErrorCheck(int line, TPublicType& dst, const TPublicType& src, bool force); void mergeQualifiers(int line, TPublicType& dst, const TPublicType& src, bool force);
void setDefaultPrecision(int line, TPublicType&, TPrecisionQualifier); void setDefaultPrecision(int line, TPublicType&, TPrecisionQualifier);
bool parameterSamplerErrorCheck(int line, TStorageQualifier qualifier, const TType& type); void parameterSamplerCheck(int line, TStorageQualifier qualifier, const TType& type);
bool containsSampler(const TType& type); bool containsSampler(const TType& type);
bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type); void nonInitConstCheck(int line, TString& identifier, TPublicType& type);
bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type); void nonInitCheck(int line, TString& identifier, TPublicType& type);
bool paramErrorCheck(int line, TStorageQualifier qualifier, TType* type); void paramCheck(int line, TStorageQualifier qualifier, TType* type);
void setLayoutQualifier(int line, TPublicType&, TString&); void setLayoutQualifier(int line, TPublicType&, TString&);
void setLayoutQualifier(int line, TPublicType&, TString&, int); void setLayoutQualifier(int line, TPublicType&, TString&, int);
void mergeLayoutQualifiers(int line, TQualifier& dest, const TQualifier& src); void mergeLayoutQualifiers(int line, TQualifier& dest, const TQualifier& src);
const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0); const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0);
bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, bool executeInitializerError(TSourceLoc line, TString& identifier, TPublicType& pType,
TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
TIntermTyped* addConstructor(TIntermNode*, const TType&, TOperator, TFunction*, TSourceLoc); TIntermTyped* addConstructor(TIntermNode*, const TType&, TOperator, TFunction*, TSourceLoc);
TIntermTyped* constructStruct(TIntermNode*, const TType&, int, TSourceLoc); TIntermTyped* constructStruct(TIntermNode*, const TType&, int, TSourceLoc);
...@@ -153,6 +151,7 @@ struct TParseContext { ...@@ -153,6 +151,7 @@ struct TParseContext {
TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc); TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc);
bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc); bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc);
void requireProfile(int line, EProfileMask profileMask, const char *featureDesc); void requireProfile(int line, EProfileMask profileMask, const char *featureDesc);
void requireStage(int line, EShLanguageMask languageMask, const char *featureDesc); void requireStage(int line, EShLanguageMask languageMask, const char *featureDesc);
void profileRequires(int line, EProfile callingProfile, int minVersion, int numExtensions, const char* extensions[], const char *featureDesc); void profileRequires(int line, EProfile callingProfile, int minVersion, int numExtensions, const char* extensions[], const char *featureDesc);
......
...@@ -66,10 +66,8 @@ const char* ProfileName[EProfileCount] = { ...@@ -66,10 +66,8 @@ const char* ProfileName[EProfileCount] = {
// //
void TParseContext::requireProfile(int line, EProfileMask profileMask, const char *featureDesc) void TParseContext::requireProfile(int line, EProfileMask profileMask, const char *featureDesc)
{ {
if (((1 << profile) & profileMask) == 0) { if (((1 << profile) & profileMask) == 0)
error(line, "not supported with this profile:", featureDesc, ProfileName[profile]); error(line, "not supported with this profile:", featureDesc, ProfileName[profile]);
recover();
}
} }
// //
...@@ -79,10 +77,8 @@ void TParseContext::requireProfile(int line, EProfileMask profileMask, const cha ...@@ -79,10 +77,8 @@ void TParseContext::requireProfile(int line, EProfileMask profileMask, const cha
// //
void TParseContext::requireStage(int line, EShLanguageMask languageMask, const char *featureDesc) void TParseContext::requireStage(int line, EShLanguageMask languageMask, const char *featureDesc)
{ {
if (((1 << language) & languageMask) == 0) { if (((1 << language) & languageMask) == 0)
error(line, "not supported in this stage:", featureDesc, StageName[language]); error(line, "not supported in this stage:", featureDesc, StageName[language]);
recover();
}
} }
// //
...@@ -112,10 +108,8 @@ void TParseContext::profileRequires(int line, EProfile callingProfile, int minVe ...@@ -112,10 +108,8 @@ void TParseContext::profileRequires(int line, EProfile callingProfile, int minVe
} }
} }
if (! okay) { if (! okay)
error(line, "not supported for this version or the enabled extensions", featureDesc, ""); error(line, "not supported for this version or the enabled extensions", featureDesc, "");
recover();
}
} }
} }
...@@ -133,15 +127,13 @@ void TParseContext::checkDeprecated(int line, EProfile callingProfile, int depVe ...@@ -133,15 +127,13 @@ void TParseContext::checkDeprecated(int line, EProfile callingProfile, int depVe
{ {
if (profile == callingProfile) { if (profile == callingProfile) {
if (version >= depVersion) { if (version >= depVersion) {
if (forwardCompatible) { if (forwardCompatible)
error(line, "deprecated, may be removed in future release", featureDesc, ""); error(line, "deprecated, may be removed in future release", featureDesc, "");
recover(); else if (! (messages & EShMsgSuppressWarnings))
} else if (! (messages & EShMsgSuppressWarnings)) {
infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " + infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " +
String(depVersion) + "; may be removed in future release").c_str(), line); String(depVersion) + "; may be removed in future release").c_str(), line);
} }
} }
}
} }
// //
...@@ -156,7 +148,6 @@ void TParseContext::requireNotRemoved(int line, EProfile callingProfile, int rem ...@@ -156,7 +148,6 @@ void TParseContext::requireNotRemoved(int line, EProfile callingProfile, int rem
char buf[maxSize]; char buf[maxSize];
snprintf(buf, maxSize, "%s profile; removed in version %d", ProfileName[profile], removedVersion); snprintf(buf, maxSize, "%s profile; removed in version %d", ProfileName[profile], removedVersion);
error(line, "no longer supported in", featureDesc, buf); error(line, "no longer supported in", featureDesc, buf);
recover();
} }
} }
} }
......
...@@ -536,12 +536,12 @@ int yy_input(char* buf, int max_size); ...@@ -536,12 +536,12 @@ int yy_input(char* buf, int max_size);
0[xX]{H}+ { pyylval->lex.line = yylineno; pyylval->lex.i = strtoul(yytext, 0, 0); return INTCONSTANT; } 0[xX]{H}+ { pyylval->lex.line = yylineno; pyylval->lex.i = strtoul(yytext, 0, 0); return INTCONSTANT; }
0{O}+ { pyylval->lex.line = yylineno; pyylval->lex.i = strtoul(yytext, 0, 0); return INTCONSTANT; } 0{O}+ { pyylval->lex.line = yylineno; pyylval->lex.i = strtoul(yytext, 0, 0); return INTCONSTANT; }
0{D}+ { pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); parseContext.recover(); return 0;} 0{D}+ { pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); return 0;}
{D}+ { pyylval->lex.line = yylineno; pyylval->lex.i = strtoul(yytext, 0, 0); return INTCONSTANT; } {D}+ { pyylval->lex.line = yylineno; pyylval->lex.i = strtoul(yytext, 0, 0); return INTCONSTANT; }
0[xX]{H}+{U} { pyylval->lex.line = yylineno; pyylval->lex.u = strtoul(yytext, 0, 0); return UINTCONSTANT; } 0[xX]{H}+{U} { pyylval->lex.line = yylineno; pyylval->lex.u = strtoul(yytext, 0, 0); return UINTCONSTANT; }
0{O}+{U} { pyylval->lex.line = yylineno; pyylval->lex.u = strtoul(yytext, 0, 0); return UINTCONSTANT; } 0{O}+{U} { pyylval->lex.line = yylineno; pyylval->lex.u = strtoul(yytext, 0, 0); return UINTCONSTANT; }
0{D}+{U} { pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); parseContext.recover(); return 0;} 0{D}+{U} { pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); return 0;}
{D}+{U} { pyylval->lex.line = yylineno; pyylval->lex.u = strtoul(yytext, 0, 0); return UINTCONSTANT; } {D}+{U} { pyylval->lex.line = yylineno; pyylval->lex.u = strtoul(yytext, 0, 0); return UINTCONSTANT; }
{D}+{F} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return FLOATCONSTANT; } {D}+{F} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return FLOATCONSTANT; }
...@@ -657,7 +657,7 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon ...@@ -657,7 +657,7 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
if (! argv[i]) { if (! argv[i]) {
parseContextLocal.error(0, "Null shader source string", "", ""); parseContextLocal.error(0, "Null shader source string", "", "");
parseContextLocal.recover();
return 1; return 1;
} }
} }
...@@ -709,7 +709,7 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon ...@@ -709,7 +709,7 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
ret = yyparse((void*)(&parseContextLocal)); ret = yyparse((void*)(&parseContextLocal));
#endif #endif
delete writeablePreamble; delete writeablePreamble;
if (cpp->CompileError == 1 || parseContextLocal.recoveredFromError || parseContextLocal.numErrors > 0) if (cpp->CompileError == 1 || parseContextLocal.numErrors > 0)
return 1; return 1;
else else
return 0; return 0;
...@@ -725,20 +725,15 @@ void yyerror(const char *s) ...@@ -725,20 +725,15 @@ void yyerror(const char *s)
TParseContext& pc = *((TParseContext *)cpp->pC); TParseContext& pc = *((TParseContext *)cpp->pC);
if (pc.AfterEOF) { if (pc.AfterEOF) {
if (cpp->tokensBeforeEOF == 1) { if (cpp->tokensBeforeEOF == 1)
GlobalParseContext->error(yylineno, "", "pre-mature EOF", s, ""); GlobalParseContext->error(yylineno, "", "pre-mature EOF", s, "");
GlobalParseContext->recover(); } else
}
} else {
GlobalParseContext->error(yylineno, "", yytext, s, ""); GlobalParseContext->error(yylineno, "", yytext, s, "");
GlobalParseContext->recover();
}
} }
void PaReservedWord() void PaReservedWord()
{ {
GlobalParseContext->error(yylineno, "Reserved word.", yytext, "", ""); GlobalParseContext->error(yylineno, "Reserved word.", yytext, "", "");
GlobalParseContext->recover();
} }
int PaIdentOrType(const char* yytext, TParseContext& parseContextLocal, YYSTYPE* pyylval) int PaIdentOrType(const char* yytext, TParseContext& parseContextLocal, YYSTYPE* pyylval)
...@@ -907,6 +902,7 @@ int Pa2ndGenerationImage(TParseContext& pc, int line, const char* text, YYSTYPE* ...@@ -907,6 +902,7 @@ int Pa2ndGenerationImage(TParseContext& pc, int line, const char* text, YYSTYPE*
return PaIdentOrType(text, pc, pyylval); return PaIdentOrType(text, pc, pyylval);
} }
// TODO: CPP: is this dead code? Combine with other comment parsers.
int PaParseComment(int& lineno, TParseContext& parseContextLocal) int PaParseComment(int& lineno, TParseContext& parseContextLocal)
{ {
int transitionFlag = 0; int transitionFlag = 0;
...@@ -926,14 +922,14 @@ int PaParseComment(int& lineno, TParseContext& parseContextLocal) ...@@ -926,14 +922,14 @@ int PaParseComment(int& lineno, TParseContext& parseContextLocal)
} }
break; break;
case EOF : case EOF :
/* Raise error message here */
parseContextLocal.error(yylineno, "End of shader found before end of comment.", "", "", ""); parseContextLocal.error(yylineno, "End of shader found before end of comment.", "", "", "");
GlobalParseContext->recover();
return YY_NULL; return YY_NULL;
default : /* Any other character will be a part of the comment */ default : /* Any other character will be a part of the comment */
transitionFlag = 0; transitionFlag = 0;
} }
} }
return 1; return 1;
} }
...@@ -959,7 +955,6 @@ void ShPpErrorToInfoLog(const char *msg) ...@@ -959,7 +955,6 @@ void ShPpErrorToInfoLog(const char *msg)
TParseContext& pc = *((TParseContext *)cpp->pC); TParseContext& pc = *((TParseContext *)cpp->pC);
pc.error(yylineno, "", "Preprocessor", msg, ""); pc.error(yylineno, "", "Preprocessor", msg, "");
GlobalParseContext->recover();
} }
// return 1 if error // return 1 if error
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment