Commit 075edd84 by Jamie Madill Committed by Shannon Woods

Refactor location tracking.

R=kbr@chromium.org Review URL: https://codereview.appspot.com/9078046 git-svn-id: https://angleproject.googlecode.com/svn/trunk@2202 736b8ea6-26fd-11df-bfd4-992fa37f6226 TRAC #23333 Authored-by: alokp@chromium.org Signed-off-by: Shannon Woods Signed-off-by Nicolas Capens Merged-by: Jamie Madill
parent 7a217def
...@@ -14,24 +14,12 @@ ...@@ -14,24 +14,12 @@
#include "compiler/PoolAlloc.h" #include "compiler/PoolAlloc.h"
// We need two pieces of information to report errors/warnings - string and struct TSourceLoc {
// line number. We encode these into a single int so that it can be easily int first_file;
// incremented/decremented by lexer. The right SOURCE_LOC_LINE_SIZE bits store int first_line;
// line number while the rest store the string number. Since the shaders are int last_file;
// usually small, we should not run out of memory. SOURCE_LOC_LINE_SIZE int last_line;
// can be increased to alleviate this issue. };
typedef int TSourceLoc;
const unsigned int SOURCE_LOC_LINE_SIZE = 16; // in bits.
const unsigned int SOURCE_LOC_LINE_MASK = (1 << SOURCE_LOC_LINE_SIZE) - 1;
inline TSourceLoc EncodeSourceLoc(int string, int line) {
return (string << SOURCE_LOC_LINE_SIZE) | (line & SOURCE_LOC_LINE_MASK);
}
inline void DecodeSourceLoc(TSourceLoc loc, int* string, int* line) {
if (string) *string = loc >> SOURCE_LOC_LINE_SIZE;
if (line) *line = loc & SOURCE_LOC_LINE_MASK;
}
// //
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme. // Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
......
...@@ -127,8 +127,10 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -127,8 +127,10 @@ bool TCompiler::compile(const char* const shaderStrings[],
// We preserve symbols at the built-in level from compile-to-compile. // We preserve symbols at the built-in level from compile-to-compile.
// Start pushing the user-defined symbols at global level. // Start pushing the user-defined symbols at global level.
symbolTable.push(); symbolTable.push();
if (!symbolTable.atGlobalLevel()) if (!symbolTable.atGlobalLevel()) {
infoSink.info.message(EPrefixInternalError, "Wrong symbol table level"); infoSink.info.prefix(EPrefixInternalError);
infoSink.info << "Wrong symbol table level";
}
// Parse shader. // Parse shader.
bool success = bool success =
...@@ -180,7 +182,8 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -180,7 +182,8 @@ bool TCompiler::compile(const char* const shaderStrings[],
if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) { if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) {
success = enforcePackingRestrictions(); success = enforcePackingRestrictions();
if (!success) { if (!success) {
infoSink.info.message(EPrefixError, "too many uniforms"); infoSink.info.prefix(EPrefixError);
infoSink.info << "too many uniforms";
} }
} }
} }
...@@ -265,10 +268,12 @@ bool TCompiler::detectRecursion(TIntermNode* root) ...@@ -265,10 +268,12 @@ bool TCompiler::detectRecursion(TIntermNode* root)
case DetectRecursion::kErrorNone: case DetectRecursion::kErrorNone:
return true; return true;
case DetectRecursion::kErrorMissingMain: case DetectRecursion::kErrorMissingMain:
infoSink.info.message(EPrefixError, "Missing main()"); infoSink.info.prefix(EPrefixError);
infoSink.info << "Missing main()";
return false; return false;
case DetectRecursion::kErrorRecursion: case DetectRecursion::kErrorRecursion:
infoSink.info.message(EPrefixError, "Function recursion detected"); infoSink.info.prefix(EPrefixError);
infoSink.info << "Function recursion detected";
return false; return false;
default: default:
UNREACHABLE(); UNREACHABLE();
......
...@@ -46,7 +46,7 @@ void TDiagnostics::writeInfo(Severity severity, ...@@ -46,7 +46,7 @@ void TDiagnostics::writeInfo(Severity severity,
TInfoSinkBase& sink = mInfoSink.info; TInfoSinkBase& sink = mInfoSink.info;
/* VC++ format: file(linenum) : error #: 'token' : extrainfo */ /* VC++ format: file(linenum) : error #: 'token' : extrainfo */
sink.prefix(prefix); sink.prefix(prefix);
sink.location(EncodeSourceLoc(loc.file, loc.line)); sink.location(loc.file, loc.line);
sink << "'" << token << "' : " << reason << " " << extra << "\n"; sink << "'" << token << "' : " << reason << " " << extra << "\n";
} }
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "compiler/InfoSink.h" #include "compiler/InfoSink.h"
void TInfoSinkBase::prefix(TPrefixType message) { void TInfoSinkBase::prefix(TPrefixType p) {
switch(message) { switch(p) {
case EPrefixNone: case EPrefixNone:
break; break;
case EPrefixWarning: case EPrefixWarning:
...@@ -31,29 +31,24 @@ void TInfoSinkBase::prefix(TPrefixType message) { ...@@ -31,29 +31,24 @@ void TInfoSinkBase::prefix(TPrefixType message) {
} }
} }
void TInfoSinkBase::location(TSourceLoc loc) { void TInfoSinkBase::location(int file, int line) {
int string = 0, line = 0;
DecodeSourceLoc(loc, &string, &line);
TPersistStringStream stream; TPersistStringStream stream;
if (line) if (line)
stream << string << ":" << line; stream << file << ":" << line;
else else
stream << string << ":? "; stream << file << ":? ";
stream << ": "; stream << ": ";
sink.append(stream.str()); sink.append(stream.str());
} }
void TInfoSinkBase::message(TPrefixType message, const char* s) { void TInfoSinkBase::location(const TSourceLoc& loc) {
prefix(message); location(loc.first_file, loc.first_line);
sink.append(s);
sink.append("\n");
} }
void TInfoSinkBase::message(TPrefixType message, const char* s, TSourceLoc loc) { void TInfoSinkBase::message(TPrefixType p, const TSourceLoc& loc, const char* m) {
prefix(message); prefix(p);
location(loc); location(loc);
sink.append(s); sink.append(m);
sink.append("\n"); sink.append("\n");
} }
...@@ -96,10 +96,10 @@ public: ...@@ -96,10 +96,10 @@ public:
const TPersistString& str() const { return sink; } const TPersistString& str() const { return sink; }
const char* c_str() const { return sink.c_str(); } const char* c_str() const { return sink.c_str(); }
void prefix(TPrefixType message); void prefix(TPrefixType p);
void location(TSourceLoc loc); void location(int file, int line);
void message(TPrefixType message, const char* s); void location(const TSourceLoc& loc);
void message(TPrefixType message, const char* s, TSourceLoc loc); void message(TPrefixType p, const TSourceLoc& loc, const char* m);
private: private:
TPersistString sink; TPersistString sink;
......
...@@ -1936,7 +1936,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1936,7 +1936,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
if (mInsideFunction) if (mInsideFunction)
{ {
outputLineDirective(node->getLine()); outputLineDirective(node->getLine().first_line);
out << "{\n"; out << "{\n";
mScopeDepth++; mScopeDepth++;
...@@ -1953,7 +1953,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1953,7 +1953,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
for (TIntermSequence::iterator sit = node->getSequence().begin(); sit != node->getSequence().end(); sit++) for (TIntermSequence::iterator sit = node->getSequence().begin(); sit != node->getSequence().end(); sit++)
{ {
outputLineDirective((*sit)->getLine()); outputLineDirective((*sit)->getLine().first_line);
traverseStatements(*sit); traverseStatements(*sit);
...@@ -1962,7 +1962,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1962,7 +1962,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
if (mInsideFunction) if (mInsideFunction)
{ {
outputLineDirective(node->getEndLine()); outputLineDirective(node->getLine().last_line);
out << "}\n"; out << "}\n";
mScopeDepth--; mScopeDepth--;
...@@ -2395,7 +2395,7 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node) ...@@ -2395,7 +2395,7 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
out << ")\n"; out << ")\n";
outputLineDirective(node->getLine()); outputLineDirective(node->getLine().first_line);
out << "{\n"; out << "{\n";
if (node->getTrueBlock()) if (node->getTrueBlock())
...@@ -2403,20 +2403,20 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node) ...@@ -2403,20 +2403,20 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
traverseStatements(node->getTrueBlock()); traverseStatements(node->getTrueBlock());
} }
outputLineDirective(node->getLine()); outputLineDirective(node->getLine().first_line);
out << ";\n}\n"; out << ";\n}\n";
if (node->getFalseBlock()) if (node->getFalseBlock())
{ {
out << "else\n"; out << "else\n";
outputLineDirective(node->getFalseBlock()->getLine()); outputLineDirective(node->getFalseBlock()->getLine().first_line);
out << "{\n"; out << "{\n";
outputLineDirective(node->getFalseBlock()->getLine()); outputLineDirective(node->getFalseBlock()->getLine().first_line);
traverseStatements(node->getFalseBlock()); traverseStatements(node->getFalseBlock());
outputLineDirective(node->getFalseBlock()->getLine()); outputLineDirective(node->getFalseBlock()->getLine().first_line);
out << ";\n}\n"; out << ";\n}\n";
} }
} }
...@@ -2452,7 +2452,7 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) ...@@ -2452,7 +2452,7 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node)
{ {
out << "{do\n"; out << "{do\n";
outputLineDirective(node->getLine()); outputLineDirective(node->getLine().first_line);
out << "{\n"; out << "{\n";
} }
else else
...@@ -2480,7 +2480,7 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) ...@@ -2480,7 +2480,7 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node)
out << ")\n"; out << ")\n";
outputLineDirective(node->getLine()); outputLineDirective(node->getLine().first_line);
out << "{\n"; out << "{\n";
} }
...@@ -2489,12 +2489,12 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) ...@@ -2489,12 +2489,12 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node)
traverseStatements(node->getBody()); traverseStatements(node->getBody());
} }
outputLineDirective(node->getLine()); outputLineDirective(node->getLine().first_line);
out << ";}\n"; out << ";}\n";
if (node->getType() == ELoopDoWhile) if (node->getType() == ELoopDoWhile)
{ {
outputLineDirective(node->getCondition()->getLine()); outputLineDirective(node->getCondition()->getLine().first_line);
out << "while(\n"; out << "while(\n";
node->getCondition()->traverse(this); node->getCondition()->traverse(this);
...@@ -2766,7 +2766,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) ...@@ -2766,7 +2766,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
out << increment; out << increment;
out << ")\n"; out << ")\n";
outputLineDirective(node->getLine()); outputLineDirective(node->getLine().first_line);
out << "{\n"; out << "{\n";
if (node->getBody()) if (node->getBody())
...@@ -2774,7 +2774,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) ...@@ -2774,7 +2774,7 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
node->getBody()->traverse(this); node->getBody()->traverse(this);
} }
outputLineDirective(node->getLine()); outputLineDirective(node->getLine().first_line);
out << ";}\n"; out << ";}\n";
if (!firstLoopFragment) if (!firstLoopFragment)
......
...@@ -19,7 +19,7 @@ struct TPublicType; ...@@ -19,7 +19,7 @@ struct TPublicType;
// //
struct TTypeLine { struct TTypeLine {
TType* type; TType* type;
int line; TSourceLoc line;
}; };
typedef TVector<TTypeLine> TTypeList; typedef TVector<TTypeLine> TTypeList;
...@@ -288,9 +288,9 @@ struct TPublicType ...@@ -288,9 +288,9 @@ struct TPublicType
bool array; bool array;
int arraySize; int arraySize;
TType* userDef; TType* userDef;
int line; TSourceLoc line;
void setBasic(TBasicType bt, TQualifier q, int ln = 0) void setBasic(TBasicType bt, TQualifier q, const TSourceLoc& ln)
{ {
type = bt; type = bt;
layoutQualifier = TLayoutQualifier::create(); layoutQualifier = TLayoutQualifier::create();
......
...@@ -47,7 +47,10 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp). ...@@ -47,7 +47,10 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#pragma warning(disable : 4102) #pragma warning(disable : 4102)
#endif #endif
#define YY_USER_ACTION yylval->lex.line = yylineno; #define YY_USER_ACTION \
yylloc->first_file = yylloc->last_file = yycolumn; \
yylloc->first_line = yylloc->last_line = yylineno;
#define YY_INPUT(buf, result, max_size) \ #define YY_INPUT(buf, result, max_size) \
result = string_input(buf, max_size, yyscanner); result = string_input(buf, max_size, yyscanner);
...@@ -62,7 +65,7 @@ static int floatsuffix_check(TParseContext* context); ...@@ -62,7 +65,7 @@ static int floatsuffix_check(TParseContext* context);
%} %}
%option noyywrap nounput never-interactive %option noyywrap nounput never-interactive
%option yylineno reentrant bison-bridge %option yylineno reentrant bison-bridge bison-locations
%option extra-type="TParseContext*" %option extra-type="TParseContext*"
D [0-9] D [0-9]
...@@ -377,7 +380,8 @@ yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) { ...@@ -377,7 +380,8 @@ yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size(); yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
if (len < max_size) if (len < max_size)
memcpy(buf, token.text.c_str(), len); memcpy(buf, token.text.c_str(), len);
yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner); yyset_column(token.location.file, yyscanner);
yyset_lineno(token.location.line, yyscanner);
if (len >= max_size) if (len >= max_size)
YY_FATAL_ERROR("Input buffer overflow"); YY_FATAL_ERROR("Input buffer overflow");
...@@ -404,7 +408,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -404,7 +408,7 @@ int check_type(yyscan_t yyscanner) {
int reserved_word(yyscan_t yyscanner) { int reserved_word(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
yyextra->error(yylineno, "Illegal use of reserved word", yytext, ""); yyextra->error(*yylloc, "Illegal use of reserved word", yytext, "");
yyextra->recover(); yyextra->recover();
return 0; return 0;
} }
...@@ -457,7 +461,7 @@ int uint_constant(TParseContext *context) ...@@ -457,7 +461,7 @@ int uint_constant(TParseContext *context)
if (context->shaderVersion < 300) if (context->shaderVersion < 300)
{ {
context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, ""); context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
context->recover(); context->recover();
return 0; return 0;
} }
...@@ -473,7 +477,7 @@ int floatsuffix_check(TParseContext* context) ...@@ -473,7 +477,7 @@ int floatsuffix_check(TParseContext* context)
if (context->shaderVersion < 300) if (context->shaderVersion < 300)
{ {
context->error(yylineno, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext); context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
context->recover(); context->recover();
return 0; return 0;
} }
...@@ -481,13 +485,6 @@ int floatsuffix_check(TParseContext* context) ...@@ -481,13 +485,6 @@ int floatsuffix_check(TParseContext* context)
return(FLOATCONSTANT); return(FLOATCONSTANT);
} }
void yyerror(TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
context->error(yylineno, reason, yytext);
context->recover();
}
int glslang_initialize(TParseContext* context) { int glslang_initialize(TParseContext* context) {
yyscan_t scanner = NULL; yyscan_t scanner = NULL;
if (yylex_init_extra(context, &scanner)) if (yylex_init_extra(context, &scanner))
...@@ -510,7 +507,8 @@ int glslang_finalize(TParseContext* context) { ...@@ -510,7 +507,8 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[], int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) { TParseContext* context) {
yyrestart(NULL, context->scanner); yyrestart(NULL, context->scanner);
yyset_lineno(EncodeSourceLoc(0, 1), context->scanner); yyset_column(0, context->scanner);
yyset_lineno(1, context->scanner);
// Initialize preprocessor. // Initialize preprocessor.
if (!context->preprocessor.init(count, string, length)) if (!context->preprocessor.init(count, string, length))
......
...@@ -994,7 +994,10 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp). ...@@ -994,7 +994,10 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#pragma warning(disable : 4102) #pragma warning(disable : 4102)
#endif #endif
#define YY_USER_ACTION yylval->lex.line = yylineno; #define YY_USER_ACTION \
yylloc->first_file = yylloc->last_file = yycolumn; \
yylloc->first_line = yylloc->last_line = yylineno;
#define YY_INPUT(buf, result, max_size) \ #define YY_INPUT(buf, result, max_size) \
result = string_input(buf, max_size, yyscanner); result = string_input(buf, max_size, yyscanner);
...@@ -1045,6 +1048,8 @@ struct yyguts_t ...@@ -1045,6 +1048,8 @@ struct yyguts_t
YYSTYPE * yylval_r; YYSTYPE * yylval_r;
YYLTYPE * yylloc_r;
}; /* end struct yyguts_t */ }; /* end struct yyguts_t */
static int yy_init_globals (yyscan_t yyscanner ); static int yy_init_globals (yyscan_t yyscanner );
...@@ -1053,6 +1058,8 @@ static int yy_init_globals (yyscan_t yyscanner ); ...@@ -1053,6 +1058,8 @@ static int yy_init_globals (yyscan_t yyscanner );
* from bison output in section 1.*/ * from bison output in section 1.*/
# define yylval yyg->yylval_r # define yylval yyg->yylval_r
# define yylloc yyg->yylloc_r
int yylex_init (yyscan_t* scanner); int yylex_init (yyscan_t* scanner);
int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
...@@ -1090,6 +1097,10 @@ YYSTYPE * yyget_lval (yyscan_t yyscanner ); ...@@ -1090,6 +1097,10 @@ YYSTYPE * yyget_lval (yyscan_t yyscanner );
void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
YYLTYPE *yyget_lloc (yyscan_t yyscanner );
void yyset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in /* Macros after this point can all be overridden by user definitions in
* section 1. * section 1.
*/ */
...@@ -1196,10 +1207,10 @@ static int input (yyscan_t yyscanner ); ...@@ -1196,10 +1207,10 @@ static int input (yyscan_t yyscanner );
#define YY_DECL_IS_OURS 1 #define YY_DECL_IS_OURS 1
extern int yylex \ extern int yylex \
(YYSTYPE * yylval_param ,yyscan_t yyscanner); (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
#define YY_DECL int yylex \ #define YY_DECL int yylex \
(YYSTYPE * yylval_param , yyscan_t yyscanner) (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
#endif /* !YY_DECL */ #endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng /* Code executed at the beginning of each rule, after yytext and yyleng
...@@ -1230,6 +1241,8 @@ YY_DECL ...@@ -1230,6 +1241,8 @@ YY_DECL
yylval = yylval_param; yylval = yylval_param;
yylloc = yylloc_param;
if ( !yyg->yy_init ) if ( !yyg->yy_init )
{ {
yyg->yy_init = 1; yyg->yy_init = 1;
...@@ -2952,6 +2965,18 @@ void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) ...@@ -2952,6 +2965,18 @@ void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
yylval = yylval_param; yylval = yylval_param;
} }
YYLTYPE *yyget_lloc (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yylloc;
}
void yyset_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yylloc = yylloc_param;
}
/* User-visible API */ /* User-visible API */
/* yylex_init is special because it creates the scanner itself, so it is /* yylex_init is special because it creates the scanner itself, so it is
...@@ -3133,7 +3158,8 @@ yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) { ...@@ -3133,7 +3158,8 @@ yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size(); yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
if (len < max_size) if (len < max_size)
memcpy(buf, token.text.c_str(), len); memcpy(buf, token.text.c_str(), len);
yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line),yyscanner); yyset_column(token.location.file,yyscanner);
yyset_lineno(token.location.line,yyscanner);
if (len >= max_size) if (len >= max_size)
YY_FATAL_ERROR("Input buffer overflow"); YY_FATAL_ERROR("Input buffer overflow");
...@@ -3160,7 +3186,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -3160,7 +3186,7 @@ int check_type(yyscan_t yyscanner) {
int reserved_word(yyscan_t yyscanner) { int reserved_word(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
yyextra->error(yylineno, "Illegal use of reserved word", yytext, ""); yyextra->error(*yylloc, "Illegal use of reserved word", yytext, "");
yyextra->recover(); yyextra->recover();
return 0; return 0;
} }
...@@ -3213,7 +3239,7 @@ int uint_constant(TParseContext *context) ...@@ -3213,7 +3239,7 @@ int uint_constant(TParseContext *context)
if (context->shaderVersion < 300) if (context->shaderVersion < 300)
{ {
context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, ""); context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
context->recover(); context->recover();
return 0; return 0;
} }
...@@ -3229,7 +3255,7 @@ int floatsuffix_check(TParseContext* context) ...@@ -3229,7 +3255,7 @@ int floatsuffix_check(TParseContext* context)
if (context->shaderVersion < 300) if (context->shaderVersion < 300)
{ {
context->error(yylineno, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext); context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
context->recover(); context->recover();
return 0; return 0;
} }
...@@ -3237,13 +3263,6 @@ int floatsuffix_check(TParseContext* context) ...@@ -3237,13 +3263,6 @@ int floatsuffix_check(TParseContext* context)
return(FLOATCONSTANT); return(FLOATCONSTANT);
} }
void yyerror(TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
context->error(yylineno, reason, yytext);
context->recover();
}
int glslang_initialize(TParseContext* context) { int glslang_initialize(TParseContext* context) {
yyscan_t scanner = NULL; yyscan_t scanner = NULL;
if (yylex_init_extra(context,&scanner)) if (yylex_init_extra(context,&scanner))
...@@ -3266,7 +3285,8 @@ int glslang_finalize(TParseContext* context) { ...@@ -3266,7 +3285,8 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[], int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) { TParseContext* context) {
yyrestart(NULL,context->scanner); yyrestart(NULL,context->scanner);
yyset_lineno(EncodeSourceLoc(0, 1),context->scanner); yyset_column(0,context->scanner);
yyset_lineno(1,context->scanner);
// Initialize preprocessor. // Initialize preprocessor.
if (!context->preprocessor.init(count, string, length)) if (!context->preprocessor.init(count, string, length))
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -39,6 +39,14 @@ ...@@ -39,6 +39,14 @@
#if YYDEBUG #if YYDEBUG
extern int yydebug; extern int yydebug;
#endif #endif
/* "%code requires" blocks. */
#define YYLTYPE TSourceLoc
#define YYLTYPE_IS_DECLARED 1
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
...@@ -179,7 +187,6 @@ typedef union YYSTYPE ...@@ -179,7 +187,6 @@ typedef union YYSTYPE
struct { struct {
TSourceLoc line;
union { union {
TString *string; TString *string;
float f; float f;
...@@ -190,7 +197,6 @@ typedef union YYSTYPE ...@@ -190,7 +197,6 @@ typedef union YYSTYPE
TSymbol* symbol; TSymbol* symbol;
} lex; } lex;
struct { struct {
TSourceLoc line;
TOperator op; TOperator op;
union { union {
TIntermNode* intermNode; TIntermNode* intermNode;
...@@ -218,6 +224,19 @@ typedef union YYSTYPE ...@@ -218,6 +224,19 @@ typedef union YYSTYPE
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1
#endif #endif
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
#ifdef YYPARSE_PARAM #ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus #if defined __STDC__ || defined __cplusplus
......
...@@ -196,7 +196,9 @@ bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary* node) ...@@ -196,7 +196,9 @@ bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary* node)
case EOpAny: out << "any"; break; case EOpAny: out << "any"; break;
case EOpAll: out << "all"; break; case EOpAll: out << "all"; break;
default: out.message(EPrefixError, "Bad unary op"); default:
out.prefix(EPrefixError);
out << "Bad unary op";
} }
out << " (" << node->getCompleteString() << ")"; out << " (" << node->getCompleteString() << ")";
...@@ -211,7 +213,8 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate* node) ...@@ -211,7 +213,8 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
TInfoSinkBase& out = sink; TInfoSinkBase& out = sink;
if (node->getOp() == EOpNull) { if (node->getOp() == EOpNull) {
out.message(EPrefixError, "node is still EOpNull!"); out.prefix(EPrefixError);
out << "node is still EOpNull!";
return true; return true;
} }
...@@ -274,7 +277,9 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate* node) ...@@ -274,7 +277,9 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
case EOpDeclaration: out << "Declaration: "; break; case EOpDeclaration: out << "Declaration: "; break;
default: out.message(EPrefixError, "Bad aggregation op"); default:
out.prefix(EPrefixError);
out << "Bad aggregation op";
} }
if (node->getOp() != EOpSequence && node->getOp() != EOpParameters) if (node->getOp() != EOpSequence && node->getOp() != EOpParameters)
...@@ -349,7 +354,7 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -349,7 +354,7 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
out << " (const uint)\n"; out << " (const uint)\n";
break; break;
default: default:
out.message(EPrefixInternalError, "Unknown constant", node->getLine()); out.message(EPrefixInternalError, node->getLine(), "Unknown constant");
break; break;
} }
} }
......
...@@ -217,10 +217,16 @@ class TIntermNode { ...@@ -217,10 +217,16 @@ class TIntermNode {
public: public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
TIntermNode() : line(0) {} TIntermNode() {
// TODO: Move this to TSourceLoc constructor
// after getting rid of TPublicType.
line.first_file = line.last_file = 0;
line.first_line = line.last_line = 0;
}
virtual ~TIntermNode() { }
TSourceLoc getLine() const { return line; } const TSourceLoc& getLine() const { return line; }
void setLine(TSourceLoc l) { line = l; } void setLine(const TSourceLoc& l) { line = l; }
virtual void traverse(TIntermTraverser*) = 0; virtual void traverse(TIntermTraverser*) = 0;
virtual TIntermTyped* getAsTyped() { return 0; } virtual TIntermTyped* getAsTyped() { return 0; }
...@@ -231,7 +237,6 @@ public: ...@@ -231,7 +237,6 @@ public:
virtual TIntermSelection* getAsSelectionNode() { return 0; } virtual TIntermSelection* getAsSelectionNode() { return 0; }
virtual TIntermSymbol* getAsSymbolNode() { return 0; } virtual TIntermSymbol* getAsSymbolNode() { return 0; }
virtual TIntermLoop* getAsLoopNode() { return 0; } virtual TIntermLoop* getAsLoopNode() { return 0; }
virtual ~TIntermNode() { }
protected: protected:
TSourceLoc line; TSourceLoc line;
...@@ -470,7 +475,7 @@ typedef TVector<int> TQualifierList; ...@@ -470,7 +475,7 @@ typedef TVector<int> TQualifierList;
// //
class TIntermAggregate : public TIntermOperator { class TIntermAggregate : public TIntermOperator {
public: public:
TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), endLine(0), useEmulatedFunction(false) { } TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), useEmulatedFunction(false) { }
TIntermAggregate(TOperator o) : TIntermOperator(o), useEmulatedFunction(false) { } TIntermAggregate(TOperator o) : TIntermOperator(o), useEmulatedFunction(false) { }
~TIntermAggregate() { } ~TIntermAggregate() { }
...@@ -490,9 +495,6 @@ public: ...@@ -490,9 +495,6 @@ public:
void setDebug(bool d) { debug = d; } void setDebug(bool d) { debug = d; }
bool getDebug() { return debug; } bool getDebug() { return debug; }
void setEndLine(TSourceLoc line) { endLine = line; }
TSourceLoc getEndLine() const { return endLine; }
void setUseEmulatedFunction() { useEmulatedFunction = true; } void setUseEmulatedFunction() { useEmulatedFunction = true; }
bool getUseEmulatedFunction() { return useEmulatedFunction; } bool getUseEmulatedFunction() { return useEmulatedFunction; }
...@@ -505,7 +507,6 @@ protected: ...@@ -505,7 +507,6 @@ protected:
bool optimize; bool optimize;
bool debug; bool debug;
TSourceLoc endLine;
// If set to true, replace the built-in function call with an emulated one // If set to true, replace the built-in function call with an emulated one
// to work around driver bugs. // to work around driver bugs.
......
...@@ -24,34 +24,33 @@ public: ...@@ -24,34 +24,33 @@ public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
TIntermediate(TInfoSink& i) : infoSink(i) { } TIntermediate(TInfoSink& i) : infoSink(i) { }
TIntermSymbol* addSymbol(int Id, const TString&, const TType&, TSourceLoc); TIntermSymbol* addSymbol(int Id, const TString&, const TType&, const TSourceLoc&);
TIntermTyped* addConversion(TOperator, const TType&, TIntermTyped*); TIntermTyped* addConversion(TOperator, const TType&, TIntermTyped*);
TIntermTyped* addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc); TIntermTyped* addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc); TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, TSourceLoc); TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, const TSourceLoc&);
TIntermTyped* addUnaryMath(TOperator op, TIntermNode* child, TSourceLoc); TIntermTyped* addUnaryMath(TOperator op, TIntermNode* child, const TSourceLoc&);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc); TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc&);
TIntermAggregate* makeAggregate(TIntermNode* node, TSourceLoc); TIntermAggregate* makeAggregate(TIntermNode* node, const TSourceLoc&);
TIntermAggregate* setAggregateOperator(TIntermNode*, TOperator, TSourceLoc); TIntermAggregate* setAggregateOperator(TIntermNode*, TOperator, const TSourceLoc&);
TIntermNode* addSelection(TIntermTyped* cond, TIntermNodePair code, TSourceLoc); TIntermNode* addSelection(TIntermTyped* cond, TIntermNodePair code, const TSourceLoc&);
TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, TSourceLoc); TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, const TSourceLoc&);
TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, TSourceLoc); TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermConstantUnion* addConstantUnion(ConstantUnion*, const TType&, TSourceLoc); TIntermConstantUnion* addConstantUnion(ConstantUnion*, const TType&, const TSourceLoc&);
TIntermTyped* promoteConstantUnion(TBasicType, TIntermConstantUnion*) ; TIntermTyped* promoteConstantUnion(TBasicType, TIntermConstantUnion*) ;
bool parseConstTree(TSourceLoc, TIntermNode*, ConstantUnion*, TOperator, TType, bool singleConstantParam = false); bool parseConstTree(const TSourceLoc&, TIntermNode*, ConstantUnion*, TOperator, TType, bool singleConstantParam = false);
TIntermNode* addLoop(TLoopType, TIntermNode*, TIntermTyped*, TIntermTyped*, TIntermNode*, TSourceLoc); TIntermNode* addLoop(TLoopType, TIntermNode*, TIntermTyped*, TIntermTyped*, TIntermNode*, const TSourceLoc&);
TIntermBranch* addBranch(TOperator, TSourceLoc); TIntermBranch* addBranch(TOperator, const TSourceLoc&);
TIntermBranch* addBranch(TOperator, TIntermTyped*, TSourceLoc); TIntermBranch* addBranch(TOperator, TIntermTyped*, const TSourceLoc&);
TIntermTyped* addSwizzle(TVectorFields&, TSourceLoc); TIntermTyped* addSwizzle(TVectorFields&, const TSourceLoc&);
bool postProcess(TIntermNode*); bool postProcess(TIntermNode*);
void remove(TIntermNode*); void remove(TIntermNode*);
void outputTree(TIntermNode*); void outputTree(TIntermNode*);
protected:
TInfoSink& infoSink;
private: private:
void operator=(TIntermediate&); // prevent assignments void operator=(TIntermediate&); // prevent assignments
TInfoSink& infoSink;
}; };
#endif // _LOCAL_INTERMEDIATE_INCLUDED_ #endif // _LOCAL_INTERMEDIATE_INCLUDED_
...@@ -61,7 +61,7 @@ protected: ...@@ -61,7 +61,7 @@ protected:
void TConstTraverser::visitSymbol(TIntermSymbol* node) void TConstTraverser::visitSymbol(TIntermSymbol* node)
{ {
infoSink.info.message(EPrefixInternalError, "Symbol Node found in constant constructor", node->getLine()); infoSink.info.message(EPrefixInternalError, node->getLine(), "Symbol Node found in constant constructor");
return; return;
} }
...@@ -74,12 +74,12 @@ bool TConstTraverser::visitBinary(Visit visit, TIntermBinary* node) ...@@ -74,12 +74,12 @@ bool TConstTraverser::visitBinary(Visit visit, TIntermBinary* node)
TString buf; TString buf;
buf.append("'constructor' : assigning non-constant to "); buf.append("'constructor' : assigning non-constant to ");
buf.append(type.getCompleteString()); buf.append(type.getCompleteString());
infoSink.info.message(EPrefixError, buf.c_str(), node->getLine()); infoSink.info.message(EPrefixError, node->getLine(), buf.c_str());
error = true; error = true;
return false; return false;
} }
infoSink.info.message(EPrefixInternalError, "Binary Node found in constant constructor", node->getLine()); infoSink.info.message(EPrefixInternalError, node->getLine(), "Binary Node found in constant constructor");
return false; return false;
} }
...@@ -89,7 +89,7 @@ bool TConstTraverser::visitUnary(Visit visit, TIntermUnary* node) ...@@ -89,7 +89,7 @@ bool TConstTraverser::visitUnary(Visit visit, TIntermUnary* node)
TString buf; TString buf;
buf.append("'constructor' : assigning non-constant to "); buf.append("'constructor' : assigning non-constant to ");
buf.append(type.getCompleteString()); buf.append(type.getCompleteString());
infoSink.info.message(EPrefixError, buf.c_str(), node->getLine()); infoSink.info.message(EPrefixError, node->getLine(), buf.c_str());
error = true; error = true;
return false; return false;
} }
...@@ -100,7 +100,7 @@ bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node) ...@@ -100,7 +100,7 @@ bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
TString buf; TString buf;
buf.append("'constructor' : assigning non-constant to "); buf.append("'constructor' : assigning non-constant to ");
buf.append(type.getCompleteString()); buf.append(type.getCompleteString());
infoSink.info.message(EPrefixError, buf.c_str(), node->getLine()); infoSink.info.message(EPrefixError, node->getLine(), buf.c_str());
error = true; error = true;
return false; return false;
} }
...@@ -146,7 +146,7 @@ bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node) ...@@ -146,7 +146,7 @@ bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
bool TConstTraverser::visitSelection(Visit visit, TIntermSelection* node) bool TConstTraverser::visitSelection(Visit visit, TIntermSelection* node)
{ {
infoSink.info.message(EPrefixInternalError, "Selection Node found in constant constructor", node->getLine()); infoSink.info.message(EPrefixInternalError, node->getLine(), "Selection Node found in constant constructor");
error = true; error = true;
return false; return false;
} }
...@@ -219,14 +219,14 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -219,14 +219,14 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
bool TConstTraverser::visitLoop(Visit visit, TIntermLoop* node) bool TConstTraverser::visitLoop(Visit visit, TIntermLoop* node)
{ {
infoSink.info.message(EPrefixInternalError, "Loop Node found in constant constructor", node->getLine()); infoSink.info.message(EPrefixInternalError, node->getLine(), "Loop Node found in constant constructor");
error = true; error = true;
return false; return false;
} }
bool TConstTraverser::visitBranch(Visit visit, TIntermBranch* node) bool TConstTraverser::visitBranch(Visit visit, TIntermBranch* node)
{ {
infoSink.info.message(EPrefixInternalError, "Branch Node found in constant constructor", node->getLine()); infoSink.info.message(EPrefixInternalError, node->getLine(), "Branch Node found in constant constructor");
error = true; error = true;
return false; return false;
} }
...@@ -236,7 +236,7 @@ bool TConstTraverser::visitBranch(Visit visit, TIntermBranch* node) ...@@ -236,7 +236,7 @@ bool TConstTraverser::visitBranch(Visit visit, TIntermBranch* node)
// Individual functions can be initialized to 0 to skip processing of that // Individual functions can be initialized to 0 to skip processing of that
// type of node. It's children will still be processed. // type of node. It's children will still be processed.
// //
bool TIntermediate::parseConstTree(TSourceLoc line, TIntermNode* root, ConstantUnion* unionArray, TOperator constructorType, TType t, bool singleConstantParam) bool TIntermediate::parseConstTree(const TSourceLoc& line, TIntermNode* root, ConstantUnion* unionArray, TOperator constructorType, TType t, bool singleConstantParam)
{ {
if (root == 0) if (root == 0)
return false; return false;
......
...@@ -10,8 +10,8 @@ void RestrictVertexShaderTiming::visitSymbol(TIntermSymbol* node) ...@@ -10,8 +10,8 @@ void RestrictVertexShaderTiming::visitSymbol(TIntermSymbol* node)
{ {
if (IsSampler(node->getBasicType())) { if (IsSampler(node->getBasicType())) {
++mNumErrors; ++mNumErrors;
mSink.prefix(EPrefixError); mSink.message(EPrefixError,
mSink.location(node->getLine()); node->getLine(),
mSink << "Samplers are not permitted in vertex shaders.\n"; "Samplers are not permitted in vertex shaders.\n");
} }
} }
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