Commit 253fdd10 by Alexis Hetu Committed by Alexis Hétu

Completed conversion of TSourceLoc into a struct

TSourceLoc was defined as an int, but is meant to be used as a struct to carry all the information provided by the parser, so the conversion was made in this cl. Change-Id: I6015d11aafda96914ec7b2c37883ffbc963a08fe Reviewed-on: https://swiftshader-review.googlesource.com/3664Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 76079bcf
......@@ -14,24 +14,12 @@
#include "PoolAlloc.h"
// We need two pieces of information to report errors/warnings - string and
// line number. We encode these into a single int so that it can be easily
// incremented/decremented by lexer. The right SOURCE_LOC_LINE_SIZE bits store
// line number while the rest store the string number. Since the shaders are
// usually small, we should not run out of memory. SOURCE_LOC_LINE_SIZE
// 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;
}
struct TSourceLoc {
int first_file;
int first_line;
int last_file;
int last_line;
};
//
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
......
......@@ -52,7 +52,10 @@ void TDiagnostics::writeInfo(Severity severity,
TInfoSinkBase& sink = mInfoSink.info;
/* VC++ format: file(linenum) : error #: 'token' : extrainfo */
sink.prefix(prefix);
sink.location(EncodeSourceLoc(loc.file, loc.line));
TSourceLoc sourceLoc;
sourceLoc.first_file = sourceLoc.last_file = loc.file;
sourceLoc.first_line = sourceLoc.last_line = loc.line;
sink.location(sourceLoc);
sink << "'" << token << "' : " << reason << " " << extra << "\n";
}
......
......@@ -31,9 +31,8 @@ void TInfoSinkBase::prefix(TPrefixType message) {
}
}
void TInfoSinkBase::location(TSourceLoc loc) {
int string = 0, line = 0;
DecodeSourceLoc(loc, &string, &line);
void TInfoSinkBase::location(const TSourceLoc& loc) {
int string = loc.first_file, line = loc.first_line;
TPersistStringStream stream;
if (line)
......
......@@ -97,7 +97,7 @@ public:
const char* c_str() const { return sink.c_str(); }
void prefix(TPrefixType message);
void location(TSourceLoc loc);
void location(const TSourceLoc& loc);
void message(TPrefixType message, const char* s);
void message(TPrefixType message, const char* s, TSourceLoc loc);
......
......@@ -400,9 +400,10 @@ void InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TS
// Depth range in window coordinates
//
TFieldList *fields = NewPoolTFieldList();
TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), 0);
TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), 0);
TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), 0);
TSourceLoc zeroSourceLoc = { 0, 0, 0, 0 };
TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
fields->push_back(near);
fields->push_back(far);
fields->push_back(diff);
......
......@@ -177,7 +177,7 @@ const char* getOperatorString(TOperator op) {
//
// Returns the added node.
//
TIntermSymbol* TIntermediate::addSymbol(int id, const TString& name, const TType& type, TSourceLoc line)
TIntermSymbol* TIntermediate::addSymbol(int id, const TString& name, const TType& type, const TSourceLoc &line)
{
TIntermSymbol* node = new TIntermSymbol(id, name, type);
node->setLine(line);
......@@ -190,7 +190,7 @@ TIntermSymbol* TIntermediate::addSymbol(int id, const TString& name, const TType
//
// Returns the added node.
//
TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc line)
TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc &line)
{
switch (op) {
case EOpEqual:
......@@ -247,8 +247,6 @@ TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIn
// one and promote it to the right type.
//
TIntermBinary* node = new TIntermBinary(op);
if (line == 0)
line = right->getLine();
node->setLine(line);
node->setLeft(left);
......@@ -276,7 +274,7 @@ TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIn
//
// Returns the added node.
//
TIntermTyped* TIntermediate::addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc line)
TIntermTyped* TIntermediate::addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc &line)
{
if (left->getType().getStruct() || right->getType().getStruct())
{
......@@ -287,8 +285,6 @@ TIntermTyped* TIntermediate::addAssign(TOperator op, TIntermTyped* left, TInterm
}
TIntermBinary* node = new TIntermBinary(op);
if(line == 0)
line = left->getLine();
node->setLine(line);
node->setLeft(left);
......@@ -306,11 +302,9 @@ TIntermTyped* TIntermediate::addAssign(TOperator op, TIntermTyped* left, TInterm
// Returns the added node.
// The caller should set the type of the returned node.
//
TIntermTyped* TIntermediate::addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, TSourceLoc line)
TIntermTyped* TIntermediate::addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, const TSourceLoc &line)
{
TIntermBinary* node = new TIntermBinary(op);
if (line == 0)
line = index->getLine();
node->setLine(line);
node->setLeft(base);
node->setRight(index);
......@@ -325,7 +319,7 @@ TIntermTyped* TIntermediate::addIndex(TOperator op, TIntermTyped* base, TIntermT
//
// Returns the added node.
//
TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode, TSourceLoc line)
TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode, const TSourceLoc &line)
{
TIntermUnary* node;
TIntermTyped* child = childNode->getAsTyped();
......@@ -366,8 +360,6 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode,
// Make a new node for the operator.
//
node = new TIntermUnary(op);
if (line == 0)
line = child->getLine();
node->setLine(line);
node->setOperand(child);
......@@ -394,7 +386,7 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode,
// Returns an aggregate node, which could be the one passed in if
// it was already an aggregate but no operator was set.
//
TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperator op, TSourceLoc line)
TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperator op, const TSourceLoc &line)
{
TIntermAggregate* aggNode;
......@@ -409,8 +401,6 @@ TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperat
//
aggNode = new TIntermAggregate();
aggNode->getSequence().push_back(node);
if (line == 0)
line = node->getLine();
}
} else
aggNode = new TIntermAggregate();
......@@ -419,8 +409,6 @@ TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperat
// Set the operator.
//
aggNode->setOp(op);
if (line != 0)
aggNode->setLine(line);
return aggNode;
}
......@@ -432,7 +420,7 @@ TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperat
// Returns the resulting aggregate, unless 0 was passed in for
// both existing nodes.
//
TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc line)
TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc &line)
{
if (left == 0 && right == 0)
return 0;
......@@ -449,8 +437,7 @@ TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* r
if (right)
aggNode->getSequence().push_back(right);
if (line != 0)
aggNode->setLine(line);
aggNode->setLine(line);
return aggNode;
}
......@@ -460,7 +447,7 @@ TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* r
//
// Returns an aggregate, unless 0 was passed in for the existing node.
//
TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node, TSourceLoc line)
TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node, const TSourceLoc &line)
{
if (node == 0)
return 0;
......@@ -468,10 +455,7 @@ TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node, TSourceLoc lin
TIntermAggregate* aggNode = new TIntermAggregate;
aggNode->getSequence().push_back(node);
if (line != 0)
aggNode->setLine(line);
else
aggNode->setLine(node->getLine());
aggNode->setLine(line);
return aggNode;
}
......@@ -483,7 +467,7 @@ TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node, TSourceLoc lin
//
// Returns the selection node created.
//
TIntermNode* TIntermediate::addSelection(TIntermTyped* cond, TIntermNodePair nodePair, TSourceLoc line)
TIntermNode* TIntermediate::addSelection(TIntermTyped* cond, TIntermNodePair nodePair, const TSourceLoc &line)
{
//
// For compile time constant selections, prune the code and
......@@ -504,7 +488,7 @@ TIntermNode* TIntermediate::addSelection(TIntermTyped* cond, TIntermNodePair nod
}
TIntermTyped* TIntermediate::addComma(TIntermTyped* left, TIntermTyped* right, TSourceLoc line)
TIntermTyped* TIntermediate::addComma(TIntermTyped* left, TIntermTyped* right, const TSourceLoc &line)
{
if (left->getType().getQualifier() == EvqConstExpr && right->getType().getQualifier() == EvqConstExpr) {
return right;
......@@ -524,7 +508,7 @@ TIntermTyped* TIntermediate::addComma(TIntermTyped* left, TIntermTyped* right, T
//
// Returns the selection node created, or 0 if one could not be.
//
TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, TSourceLoc line)
TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, const TSourceLoc &line)
{
if (trueBlock->getType() != falseBlock->getType())
{
......@@ -574,7 +558,7 @@ TIntermCase *TIntermediate::addCase(TIntermTyped *condition, const TSourceLoc &l
// Returns the constant union node created.
//
TIntermConstantUnion* TIntermediate::addConstantUnion(ConstantUnion* unionArrayPointer, const TType& t, TSourceLoc line)
TIntermConstantUnion* TIntermediate::addConstantUnion(ConstantUnion* unionArrayPointer, const TType& t, const TSourceLoc &line)
{
TIntermConstantUnion* node = new TIntermConstantUnion(unionArrayPointer, t);
node->setLine(line);
......@@ -582,7 +566,7 @@ TIntermConstantUnion* TIntermediate::addConstantUnion(ConstantUnion* unionArrayP
return node;
}
TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, TSourceLoc line)
TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, const TSourceLoc &line)
{
TIntermAggregate* node = new TIntermAggregate(EOpSequence);
......@@ -605,7 +589,7 @@ TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, TSourceLoc line)
//
// Create loop nodes.
//
TIntermNode* TIntermediate::addLoop(TLoopType type, TIntermNode* init, TIntermTyped* cond, TIntermTyped* expr, TIntermNode* body, TSourceLoc line)
TIntermNode* TIntermediate::addLoop(TLoopType type, TIntermNode* init, TIntermTyped* cond, TIntermTyped* expr, TIntermNode* body, const TSourceLoc &line)
{
TIntermNode* node = new TIntermLoop(type, init, cond, expr, body);
node->setLine(line);
......@@ -616,12 +600,12 @@ TIntermNode* TIntermediate::addLoop(TLoopType type, TIntermNode* init, TIntermTy
//
// Add branches.
//
TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TSourceLoc line)
TIntermBranch* TIntermediate::addBranch(TOperator branchOp, const TSourceLoc &line)
{
return addBranch(branchOp, 0, line);
}
TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TIntermTyped* expression, TSourceLoc line)
TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TIntermTyped* expression, const TSourceLoc &line)
{
TIntermBranch* node = new TIntermBranch(branchOp, expression);
node->setLine(line);
......
......@@ -180,8 +180,7 @@ void TParseContext::error(const TSourceLoc& loc,
const char* reason, const char* token,
const char* extraInfo)
{
pp::SourceLocation srcLoc;
DecodeSourceLoc(loc, &srcLoc.file, &srcLoc.line);
pp::SourceLocation srcLoc(loc.first_file, loc.first_line);
mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR,
srcLoc, reason, token, extraInfo);
......@@ -190,8 +189,7 @@ void TParseContext::error(const TSourceLoc& loc,
void TParseContext::warning(const TSourceLoc& loc,
const char* reason, const char* token,
const char* extraInfo) {
pp::SourceLocation srcLoc;
DecodeSourceLoc(loc, &srcLoc.file, &srcLoc.line);
pp::SourceLocation srcLoc(loc.first_file, loc.first_line);
mDiagnostics.writeInfo(pp::Diagnostics::PP_WARNING,
srcLoc, reason, token, extraInfo);
}
......@@ -1064,15 +1062,13 @@ bool TParseContext::supportsExtension(const char* extension)
void TParseContext::handleExtensionDirective(const TSourceLoc &line, const char* extName, const char* behavior)
{
pp::SourceLocation loc;
DecodeSourceLoc(line, &loc.file, &loc.line);
pp::SourceLocation loc(line.first_file, line.first_line);
mDirectiveHandler.handleExtension(loc, extName, behavior);
}
void TParseContext::handlePragmaDirective(const TSourceLoc &line, const char* name, const char* value)
{
pp::SourceLocation loc;
DecodeSourceLoc(line, &loc.file, &loc.line);
pp::SourceLocation loc(line.first_file, line.first_line);
mDirectiveHandler.handlePragma(loc, name, value);
}
......
......@@ -47,7 +47,10 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#pragma warning(disable : 4102)
#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) \
result = string_input(buf, max_size, yyscanner);
......@@ -399,7 +402,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();
if (len < max_size)
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)
YY_FATAL_ERROR("Input buffer overflow");
......@@ -555,7 +559,8 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) {
yyrestart(NULL, context->getScanner());
yyset_lineno(EncodeSourceLoc(0, 1), context->getScanner());
yyset_column(0, context->getScanner());
yyset_lineno(1, context->getScanner());
context->AfterEOF = false;
// Initialize preprocessor.
......
......@@ -53,7 +53,6 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
%union {
struct {
TSourceLoc line;
union {
TString *string;
float f;
......@@ -64,7 +63,6 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
TSymbol* symbol;
} lex;
struct {
TSourceLoc line;
TOperator op;
union {
TIntermNode* intermNode;
......@@ -91,7 +89,21 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
extern int yylex(YYSTYPE* yylval, YYLTYPE* yylloc, void* yyscanner);
extern void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason);
#define YYLLOC_DEFAULT(Current, Rhs, N) do { (Current) = YYRHSLOC(Rhs, N ? 1 : 0); } while (0)
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) { \
(Current).first_file = YYRHSLOC(Rhs, 1).first_file; \
(Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
(Current).last_file = YYRHSLOC(Rhs, N).last_file; \
(Current).last_line = YYRHSLOC(Rhs, N).last_line; \
} \
else { \
(Current).first_file = YYRHSLOC(Rhs, 0).last_file; \
(Current).first_line = YYRHSLOC(Rhs, 0).last_line; \
(Current).last_file = YYRHSLOC(Rhs, 0).last_file; \
(Current).last_line = YYRHSLOC(Rhs, 0).last_line; \
} \
} while (0)
#define FRAG_VERT_ONLY(S, L) { \
if (context->getShaderType() != GL_FRAGMENT_SHADER && \
......@@ -300,11 +312,9 @@ function_call_or_method
function_call_generic
: function_call_header_with_parameters RIGHT_PAREN {
$$ = $1;
$$.line = @2;
}
| function_call_header_no_parameters RIGHT_PAREN {
$$ = $1;
$$.line = @2;
}
;
......@@ -411,12 +421,12 @@ unary_expression
// Grammar Note: No traditional style type casts.
unary_operator
: PLUS { $$.line = @1; $$.op = EOpNull; }
| DASH { $$.line = @1; $$.op = EOpNegative; }
| BANG { $$.line = @1; $$.op = EOpLogicalNot; }
: PLUS { $$.op = EOpNull; }
| DASH { $$.op = EOpNegative; }
| BANG { $$.op = EOpLogicalNot; }
| TILDE {
ES3_ONLY("~", @1, "bit-wise operator");
$$.line = @1; $$.op = EOpBitwiseNot;
$$.op = EOpBitwiseNot;
}
;
// Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
......@@ -548,23 +558,28 @@ assignment_expression
;
assignment_operator
: EQUAL { $$.line = @1; $$.op = EOpAssign; }
| MUL_ASSIGN { FRAG_VERT_ONLY("*=", @1); $$.line = @1; $$.op = EOpMulAssign; }
| DIV_ASSIGN { FRAG_VERT_ONLY("/=", @1); $$.line = @1; $$.op = EOpDivAssign; }
: EQUAL { $$.op = EOpAssign; }
| MUL_ASSIGN { FRAG_VERT_ONLY("*=", @1); $$.op = EOpMulAssign; }
| DIV_ASSIGN { FRAG_VERT_ONLY("/=", @1); $$.op = EOpDivAssign; }
| MOD_ASSIGN { ES3_ONLY("%=", @1, "integer modulus operator");
FRAG_VERT_ONLY("%=", @1); $$.line = @1; $$.op = EOpIModAssign; }
| ADD_ASSIGN { $$.line = @1; $$.op = EOpAddAssign; }
| SUB_ASSIGN { $$.line = @1; $$.op = EOpSubAssign; }
FRAG_VERT_ONLY("%=", @1); $$.op = EOpIModAssign; }
| ADD_ASSIGN { $$.op = EOpAddAssign; }
| SUB_ASSIGN { $$.op = EOpSubAssign; }
| LEFT_ASSIGN { ES3_ONLY("<<=", @1, "bit-wise operator");
FRAG_VERT_ONLY("<<=", @1); $$.line = @1; $$.op = EOpBitShiftLeftAssign; }
FRAG_VERT_ONLY("<<=", @1);
$$.op = EOpBitShiftLeftAssign; }
| RIGHT_ASSIGN { ES3_ONLY(">>=", @1, "bit-wise operator");
FRAG_VERT_ONLY(">>=", @1); $$.line = @1; $$.op = EOpBitShiftRightAssign; }
FRAG_VERT_ONLY(">>=", @1);
$$.op = EOpBitShiftRightAssign; }
| AND_ASSIGN { ES3_ONLY("&=", @1, "bit-wise operator");
FRAG_VERT_ONLY("&=", @1); $$.line = @1; $$.op = EOpBitwiseAndAssign; }
FRAG_VERT_ONLY("&=", @1);
$$.op = EOpBitwiseAndAssign; }
| XOR_ASSIGN { ES3_ONLY("^=", @1, "bit-wise operator");
FRAG_VERT_ONLY("^=", @1); $$.line = @1; $$.op = EOpBitwiseXorAssign; }
FRAG_VERT_ONLY("^=", @1);
$$.op = EOpBitwiseXorAssign; }
| OR_ASSIGN { ES3_ONLY("|=", @1, "bit-wise operator");
FRAG_VERT_ONLY("|=", @1); $$.line = @1; $$.op = EOpBitwiseOrAssign; }
FRAG_VERT_ONLY("|=", @1);
$$.op = EOpBitwiseOrAssign; }
;
expression
......@@ -686,7 +701,6 @@ function_prototype
// being redeclared. So, pass back up this declaration, not the one in the symbol table.
//
$$.function = $1;
$$.line = @2;
// We're at the inner scope level of the function's arguments and body statement.
// Add the function prototype to the surrounding scope instead.
......@@ -763,7 +777,6 @@ parameter_declarator
if (context->reservedErrorCheck(@2, *$2.string))
context->recover();
TParameter param = {$2.string, new TType($1)};
$$.line = @2;
$$.param = param;
}
| type_specifier IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET {
......@@ -781,7 +794,6 @@ parameter_declarator
TType* type = new TType($1);
TParameter param = { $2.string, type };
$$.line = @2;
$$.param = param;
}
;
......@@ -990,17 +1002,14 @@ type_qualifier
storage_qualifier
: CONST_QUAL {
$$.qualifier = EvqConstExpr;
$$.line = @1;
}
| IN_QUAL {
ES3_ONLY("in", @1, "storage qualifier");
$$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentIn : EvqVertexIn;
$$.line = @1;
}
| OUT_QUAL {
ES3_ONLY("out", @1, "storage qualifier");
$$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqVertexOut;
$$.line = @1;
}
| CENTROID IN_QUAL {
ES3_ONLY("centroid in", @1, "storage qualifier");
......@@ -1010,7 +1019,6 @@ storage_qualifier
context->recover();
}
$$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqCentroidIn : EvqVertexIn;
$$.line = @2;
}
| CENTROID OUT_QUAL {
ES3_ONLY("centroid out", @1, "storage qualifier");
......@@ -1020,13 +1028,11 @@ storage_qualifier
context->recover();
}
$$.qualifier = (context->getShaderType() == GL_FRAGMENT_SHADER) ? EvqFragmentOut : EvqCentroidOut;
$$.line = @2;
}
| UNIFORM {
if (context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "uniform"))
context->recover();
$$.qualifier = EvqUniform;
$$.line = @1;
}
;
......@@ -1480,10 +1486,10 @@ compound_statement_no_new_scope
statement_list
: statement {
$$ = context->intermediate.makeAggregate($1, 0);
$$ = context->intermediate.makeAggregate($1, @$);
}
| statement_list statement {
$$ = context->intermediate.growAggregate($1, $2, 0);
$$ = context->intermediate.growAggregate($1, $2, @$);
}
;
......@@ -1628,7 +1634,7 @@ translation_unit
context->setTreeRoot($$);
}
| translation_unit external_declaration {
$$ = context->intermediate.growAggregate($1, $2, 0);
$$ = context->intermediate.growAggregate($1, $2, @$);
context->setTreeRoot($$);
}
;
......@@ -1736,7 +1742,7 @@ function_definition
context->recover();
}
$$ = context->intermediate.growAggregate($1.intermAggregate, $3, 0);
$$ = context->intermediate.growAggregate($1.intermAggregate, $3, @$);
context->intermediate.setAggregateOperator($$, EOpFunction, @1);
$$->getAsAggregate()->setName($1.function->getMangledName().c_str());
$$->getAsAggregate()->setType($1.function->getReturnType());
......
......@@ -1034,7 +1034,10 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#pragma warning(disable : 4102)
#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) \
result = string_input(buf, max_size, yyscanner);
......@@ -3291,7 +3294,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();
if (len < max_size)
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)
YY_FATAL_ERROR("Input buffer overflow");
......@@ -3447,7 +3451,8 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) {
yyrestart(NULL,context->getScanner());
yyset_lineno(EncodeSourceLoc(0, 1),context->getScanner());
yyset_column(0,context->getScanner());
yyset_lineno(1,context->getScanner());
context->AfterEOF = false;
// Initialize preprocessor.
......
......@@ -183,7 +183,6 @@ typedef union YYSTYPE
struct {
TSourceLoc line;
union {
TString *string;
float f;
......@@ -194,7 +193,6 @@ typedef union YYSTYPE
TSymbol* symbol;
} lex;
struct {
TSourceLoc line;
TOperator op;
union {
TIntermNode* intermNode;
......
......@@ -252,10 +252,16 @@ class TIntermNode {
public:
POOL_ALLOCATOR_NEW_DELETE();
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;
}
TSourceLoc getLine() const { return line; }
void setLine(TSourceLoc l) { line = l; }
const TSourceLoc& getLine() const { return line; }
void setLine(const TSourceLoc& l) { line = l; }
virtual void traverse(TIntermTraverser*) = 0;
virtual TIntermTyped* getAsTyped() { return 0; }
......@@ -496,7 +502,7 @@ typedef TVector<int> TQualifierList;
//
class TIntermAggregate : public TIntermOperator {
public:
TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), endLine(0) { }
TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false) { endLine = { 0, 0, 0, 0 }; }
TIntermAggregate(TOperator o) : TIntermOperator(o) { }
~TIntermAggregate() { }
......@@ -516,8 +522,8 @@ public:
void setDebug(bool d) { debug = d; }
bool getDebug() { return debug; }
void setEndLine(TSourceLoc line) { endLine = line; }
TSourceLoc getEndLine() const { return endLine; }
void setEndLine(const TSourceLoc& line) { endLine = line; }
const TSourceLoc& getEndLine() const { return endLine; }
protected:
TIntermAggregate(const TIntermAggregate&); // disallow copy constructor
......
......@@ -23,26 +23,26 @@ public:
POOL_ALLOCATOR_NEW_DELETE();
TIntermediate(TInfoSink& i) : infoSink(i) { }
TIntermSymbol* addSymbol(int Id, const TString&, const TType&, TSourceLoc);
TIntermTyped* addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc);
TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc);
TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, TSourceLoc);
TIntermTyped* addUnaryMath(TOperator op, TIntermNode* child, TSourceLoc);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc);
TIntermAggregate* makeAggregate(TIntermNode* node, TSourceLoc);
TIntermAggregate* setAggregateOperator(TIntermNode*, TOperator, TSourceLoc);
TIntermNode* addSelection(TIntermTyped* cond, TIntermNodePair code, TSourceLoc);
TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, TSourceLoc);
TIntermSymbol* addSymbol(int Id, const TString&, const TType&, const TSourceLoc&);
TIntermTyped* addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, const TSourceLoc&);
TIntermTyped* addUnaryMath(TOperator op, TIntermNode* child, const TSourceLoc&);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc&);
TIntermAggregate* makeAggregate(TIntermNode* node, const TSourceLoc&);
TIntermAggregate* setAggregateOperator(TIntermNode*, TOperator, const TSourceLoc&);
TIntermNode* addSelection(TIntermTyped* cond, TIntermNodePair code, const TSourceLoc&);
TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, const TSourceLoc&);
TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &line);
TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &line);
TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, TSourceLoc);
TIntermConstantUnion* addConstantUnion(ConstantUnion*, const TType&, TSourceLoc);
TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, const TSourceLoc&);
TIntermConstantUnion* addConstantUnion(ConstantUnion*, const TType&, const TSourceLoc&);
TIntermTyped* promoteConstantUnion(TBasicType, TIntermConstantUnion*);
bool parseConstTree(TSourceLoc, TIntermNode*, ConstantUnion*, TOperator, TType, bool singleConstantParam = false);
TIntermNode* addLoop(TLoopType, TIntermNode*, TIntermTyped*, TIntermTyped*, TIntermNode*, TSourceLoc);
TIntermBranch* addBranch(TOperator, TSourceLoc);
TIntermBranch* addBranch(TOperator, TIntermTyped*, TSourceLoc);
TIntermTyped* addSwizzle(TVectorFields&, TSourceLoc);
bool parseConstTree(const TSourceLoc&, TIntermNode*, ConstantUnion*, TOperator, TType, bool singleConstantParam = false);
TIntermNode* addLoop(TLoopType, TIntermNode*, TIntermTyped*, TIntermTyped*, TIntermNode*, const TSourceLoc&);
TIntermBranch* addBranch(TOperator, const TSourceLoc&);
TIntermBranch* addBranch(TOperator, TIntermTyped*, const TSourceLoc&);
TIntermTyped* addSwizzle(TVectorFields&, const TSourceLoc&);
bool postProcess(TIntermNode*);
void outputTree(TIntermNode*);
......
......@@ -228,7 +228,7 @@ bool TConstTraverser::visitBranch(Visit visit, TIntermBranch* node)
// Individual functions can be initialized to 0 to skip processing of that
// 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)
return false;
......
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