27 fields.
num = (
int) compString.size();
29 error(line,
"illegal vector field selection", compString.c_str());
39 for (
int i = 0;
i < fields.
num; ++
i) {
40 switch (compString[
i]) {
91 error(line,
"illegal vector field selection", compString.c_str());
96 for (
int i = 0;
i < fields.
num; ++
i) {
98 error(line,
"vector field selection out of range", compString.c_str());
103 if (fieldSet[
i] != fieldSet[
i-1]) {
104 error(line,
"illegal - vector component fields not from the same set", compString.c_str());
125 if (compString.size() != 2) {
126 error(line,
"illegal length of matrix field selection", compString.c_str());
130 if (compString[0] ==
'_') {
131 if (compString[1] <
'0' || compString[1] >
'3') {
132 error(line,
"illegal matrix field selection", compString.c_str());
136 fields.
col = compString[1] -
'0';
137 }
else if (compString[1] ==
'_') {
138 if (compString[0] <
'0' || compString[0] >
'3') {
139 error(line,
"illegal matrix field selection", compString.c_str());
143 fields.
row = compString[0] -
'0';
145 if (compString[0] <
'0' || compString[0] >
'3' ||
146 compString[1] <
'0' || compString[1] >
'3') {
147 error(line,
"illegal matrix field selection", compString.c_str());
150 fields.
row = compString[0] -
'0';
151 fields.
col = compString[1] -
'0';
154 if (fields.
row >= matSize || fields.
col >= matSize) {
155 error(line,
"matrix field selection out of range", compString.c_str());
179 const char* reason,
const char* token,
180 const char* extraInfo)
186 srcLoc, reason, token, extraInfo);
191 const char* reason,
const char* token,
192 const char* extraInfo) {
197 srcLoc, reason, token, extraInfo);
210 std::stringstream extraInfoStream;
211 extraInfoStream <<
"cannot convert from '" << right <<
"' to '" << left <<
"'";
213 error(line,
"", op, extraInfo.c_str());
221 std::stringstream extraInfoStream;
222 extraInfoStream <<
"no operation '" << op <<
"' exists that takes an operand of type " << operand
223 <<
" (or there is no acceptable conversion)";
225 error(line,
" wrong operand type", op, extraInfo.c_str());
233 std::stringstream extraInfoStream;
234 extraInfoStream <<
"no operation '" << op <<
"' exists that takes a left-hand operand of type '" << left
235 <<
"' and a right operand of type '" << right <<
"' (or there is no acceptable conversion)";
237 error(line,
" wrong operand types ", op, extraInfo.c_str());
246 error( line,
"No precision specified for (float)",
"" );
252 error( line,
"No precision specified (int)",
"" );
276 switch(binaryNode->
getOp()) {
284 int offset[4] = {0,0,0,0};
289 for (TIntermSequence::iterator
p = aggrNode->
getSequence().begin();
293 if (offset[value] > 1) {
294 error(line,
" l-value of swizzle cannot have duplicate components", op);
305 error(line,
" l-value required", op);
311 const char* symbol = 0;
317 case EvqConst: message =
"can't modify a const";
break;
319 case EvqAttribute: message =
"can't modify an attribute";
break;
320 case EvqUniform: message =
"can't modify a uniform";
break;
321 case EvqVaryingIn: message =
"can't modify a varying";
break;
322 case EvqFragCoord: message =
"can't modify gl_FragCoord";
break;
323 case EvqFrontFacing: message =
"can't modify gl_FrontFacing";
break;
324 case EvqPointCoord: message =
"can't modify gl_PointCoord";
break;
333 message =
"can't modify a sampler";
336 message =
"can't modify void";
343 if (message == 0 && binaryNode == 0 && symNode == 0) {
344 error(line,
" l-value required", op);
360 std::stringstream extraInfoStream;
361 extraInfoStream <<
"\"" << symbol <<
"\" (" << message <<
")";
363 error(line,
" l-value required", op, extraInfo.c_str());
366 std::stringstream extraInfoStream;
367 extraInfoStream <<
"(" << message <<
")";
369 error(line,
" l-value required", op, extraInfo.c_str());
386 error(node->
getLine(),
"constant expression required",
"");
402 error(node->
getLine(),
"integer expression required", token);
418 error(line,
"only allowed at global scope", token);
434 static const char* reservedErrMsg =
"reserved built-in name";
436 if (identifier.compare(0, 3,
"gl_") == 0) {
437 error(line, reservedErrMsg,
"gl_");
441 if (identifier.compare(0, 6,
"webgl_") == 0) {
442 error(line, reservedErrMsg,
"webgl_");
445 if (identifier.compare(0, 7,
"_webgl_") == 0) {
446 error(line, reservedErrMsg,
"_webgl_");
450 error(line, reservedErrMsg,
"css_");
454 if (identifier.find(
"__") != TString::npos) {
455 error(line,
"identifiers containing two consecutive underscores (__) are reserved as possible future keywords", identifier.c_str());
472 *type =
function.getReturnType();
474 bool constructingMatrix =
false;
479 constructingMatrix =
true;
492 bool constType =
true;
494 bool overFull =
false;
495 bool matrixInMatrix =
false;
496 bool arrayArg =
false;
497 for (
size_t i = 0;
i <
function.getParamCount(); ++
i) {
502 matrixInMatrix =
true;
516 if (type->
isArray() &&
static_cast<size_t>(type->
getArraySize()) !=
function.getParamCount()) {
517 error(line,
"array constructor needs one argument per array element",
"constructor");
522 error(line,
"constructing from a non-dereferenced array",
"constructor");
526 if (matrixInMatrix && !type->
isArray()) {
527 if (
function.getParamCount() != 1) {
528 error(line,
"constructing matrix from matrix can only take one argument",
"constructor");
534 error(line,
"too many arguments",
"constructor");
539 error(line,
"Number of constructor parameters does not match the number of structure fields",
"constructor");
543 if (!type->
isMatrix() || !matrixInMatrix) {
546 error(line,
"not enough data provided for construction",
"constructor");
553 error(line,
"constructor argument does not have a type",
"constructor");
557 error(line,
"cannot convert a sampler",
"constructor");
561 error(line,
"cannot convert a void",
"constructor");
575 error(line,
"illegal use of type 'void'", identifier.c_str());
589 error(line,
"boolean expression expected",
"");
603 error(line,
"boolean expression expected",
"");
662 for (
unsigned int i = 0;
i < fields.size(); ++
i) {
680 error(line,
"array size must be a constant integer expression",
"");
687 error(line,
"array size must be a positive integer",
"");
703 error(line,
"cannot declare arrays of this qualifier",
TType(type).getCompleteString().c_str());
721 error(line,
"cannot declare arrays of arrays",
TType(type).getCompleteString().c_str());
743 bool builtIn =
false;
744 bool sameScope =
false;
746 if (symbol == 0 || !sameScope) {
757 error(line,
"INTERNAL ERROR inserting new symbol", identifier.c_str());
762 error(line,
"variable expected", identifier.c_str());
766 variable =
static_cast<TVariable*
>(symbol);
768 error(line,
"redeclaring non-array as array", identifier.c_str());
772 error(line,
"redeclaration of array with size", identifier.c_str());
777 error(line,
"redeclaration of array with a different type", identifier.c_str());
805 error(line,
"arrays may not be declared constant since they cannot be initialized", identifier.c_str());
809 error(line,
"structures containing arrays may not be declared constant since they cannot be initialized", identifier.c_str());
813 error(line,
"variables with qualifier 'const' must be initialized", identifier.c_str());
836 error(line,
"redefinition", variable->
getName().c_str());
870 TExtensionBehavior::const_iterator iter = extBehavior.find(extension.c_str());
871 if (iter == extBehavior.end()) {
872 error(line,
"extension", extension.c_str(),
"is not supported");
877 error(line,
"extension", extension.c_str(),
"is disabled");
881 warning(line,
"extension", extension.c_str(),
"is being used");
891 TExtensionBehavior::const_iterator iter = extbehavior.find(extension);
892 return (iter != extbehavior.end());
898 TExtensionBehavior::const_iterator iter = extbehavior.find(extension);
900 if (iter == extbehavior.end())
930 error(line,
"no matching overloaded function found", call->
getName().c_str());
935 error(line,
"function name expected", call->
getName().c_str());
939 return static_cast<const TFunction*
>(symbol);
961 variable =
new TVariable(&identifier, type);
963 error(line,
"redefinition", variable->
getName().c_str());
984 std::stringstream extraInfoStream;
987 error(line,
" assigning non-constant to",
"=", extraInfo.c_str());
991 if (type != initializer->
getType()) {
992 error(line,
" non-matching types for const initializer ",
1006 std::stringstream extraInfoStream;
1009 error(line,
" cannot assign to",
"=", extraInfo.c_str());
1018 if (intermNode == 0) {
1034 bool allConstant =
true;
1039 for (TIntermSequence::iterator
p = sequence.begin();
p != sequence.end(); ++
p) {
1040 if (!(*p)->getAsTyped()->getAsConstantUnion())
1059 TFieldList::const_iterator memberFields;
1087 if (newNode && newNode->getAsAggregate()) {
1089 if (constConstructor)
1090 return constConstructor;
1109 for (TIntermSequence::iterator
p = sequenceVector.begin();
1110 p != sequenceVector.end();
p++, paramCount++) {
1125 if (constConstructor)
1126 return constConstructor;
1136 bool returnVal =
false;
1194 error(line,
"unsupported construction",
"");
1201 error(line,
"can't convert",
"constructor");
1210 if (subset || (newNode != node && newNode->
getType() == *
type))
1230 std::stringstream extraInfoStream;
1231 extraInfoStream <<
"cannot convert parameter " << paramCount
1235 error(line,
"",
"constructor", extraInfo.c_str());
1255 if (tempConstantNode) {
1262 error(line,
"Cannot offset into the vector",
"Error");
1270 for (
int i = 0;
i < fields.
num;
i++) {
1272 std::stringstream extraInfoStream;
1273 extraInfoStream <<
"vector field selection out of range '" << fields.
offsets[
i] <<
"'";
1275 error(line,
"",
"[", extraInfo.c_str());
1280 constArray[
i] = unionArray[fields.
offsets[
i]];
1299 std::stringstream extraInfoStream;
1300 extraInfoStream <<
"matrix field selection out of range '" << index <<
"'";
1302 error(line,
"",
"[", extraInfo.c_str());
1307 if (tempConstantNode) {
1312 error(line,
"Cannot offset into the matrix",
"Error");
1336 std::stringstream extraInfoStream;
1337 extraInfoStream <<
"array field selection out of range '" << index <<
"'";
1339 error(line,
"",
"[", extraInfo.c_str());
1344 if (tempConstantNode) {
1349 error(line,
"Cannot offset into the array",
"Error");
1368 size_t instanceSize = 0;
1370 if (fields[
index]->
name() == identifier) {
1373 instanceSize += fields[
index]->type()->getObjectSize();
1379 if (tempConstantNode) {
1384 error(line,
"Cannot offset into the structure",
"Error");
1401 error(line,
"",
"Embedded struct definitions are not allowed");
1415 const int kWebGLMaxStructNesting = 4;
1432 std::stringstream extraInfoStream;
1433 extraInfoStream <<
"Reference of struct type " << field.
name()
1434 <<
" exceeds maximum struct nesting of " << kWebGLMaxStructNesting;
1436 error(line,
"",
"", extraInfo.c_str());
1458 error(location,
" left of '[' is not of type array, matrix, or vector ",
"expression");
1468 std::stringstream infoStream;
1469 infoStream <<
index;
1471 error(location,
"negative index", info.c_str());
1477 if (baseExpression->
isArray())
1482 else if (baseExpression->
isVector())
1490 else if (baseExpression->
isMatrix())
1498 if (baseExpression->
isArray())
1502 std::stringstream extraInfoStream;
1503 extraInfoStream <<
"array index out of range '" << index <<
"'";
1505 error(location,
"",
"[", extraInfo.c_str());
1511 error(location,
"",
"[",
"array indexes for gl_FragData must be zero when GL_EXT_draw_buffers is disabled");
1518 std::stringstream extraInfoStream;
1519 extraInfoStream <<
"field selection out of range '" << index <<
"'";
1521 error(location,
"",
"[", extraInfo.c_str());
1535 if (indexedExpression == 0)
1541 else if (baseExpression->
isArray())
1547 indexedExpression->
setType(copyOfType);
1559 else if (baseExpression->
isMatrix())
1564 else if (baseExpression->
isVector())
1574 return indexedExpression;
1584 if ((count == 0) || (
string ==
NULL))
1596 return (error == 0) && (context->
numErrors() == 0) ? 0 : 1;
void error(const TSourceLoc &loc, const char *reason, const char *token, const char *extraInfo="")
bool lValueErrorCheck(const TSourceLoc &line, const char *op, TIntermTyped *)
TSymbolTable & symbolTable
bool checksPrecisionErrors
int getDeepestStructNesting() const
TIntermTyped * foldConstConstructor(TIntermAggregate *aggrNode, const TType &type)
TIntermSequence & getSequence()
std::map< std::string, TBehavior > TExtensionBehavior
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
bool voidErrorCheck(const TSourceLoc &, const TString &, const TPublicType &)
GLsizei GLenum GLuint GLuint GLsizei GLchar * message
TIntermTyped * getLeft() const
bool arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped *expr, int &size)
virtual TIntermAggregate * getAsAggregate()
bool IsSampler(TBasicType type)
void setType(const TType &t)
TString getCompleteString() const
TIntermTyped * addConstructor(TIntermNode *, const TType *, TOperator, TFunction *, const TSourceLoc &)
TIntermTyped * getRight() const
void warning(const TSourceLoc &loc, const char *reason, const char *token, const char *extraInfo="")
int glslang_finalize(TParseContext *context)
const char * getQualifierString() const
TIntermTyped * constructBuiltIn(const TType *, TOperator, TIntermNode *, const TSourceLoc &, bool subset)
TBasicType getBasicType() const
TPrecision getPrecision() const
int glslang_parse(TParseContext *context)
TIntermTyped * addConstStruct(TString &, TIntermTyped *, const TSourceLoc &)
bool executeInitializer(const TSourceLoc &line, TString &identifier, TPublicType &pType, TIntermTyped *initializer, TIntermNode *&intermNode, TVariable *variable=0)
TBasicType getBasicType() const
bool isStructureContainingArrays() const
bool globalErrorCheck(const TSourceLoc &line, bool global, const char *token)
int getNominalSize() const
bool insert(TSymbol &symbol)
void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right)
bool isConstructor() const
bool sameElementType(const TType &right) const
EGLImageKHR EGLint * name
const TString & name() const
virtual TIntermBinary * getAsBinaryNode()
TQualifier getQualifier() const
void setQualifier(TQualifier q)
virtual bool isVariable() const
void unaryOpError(const TSourceLoc &line, const char *op, TString operand)
bool extensionErrorCheck(const TSourceLoc &line, const TString &)
int PaParseStrings(size_t count, const char *const string[], const int length[], TParseContext *context)
bool reservedErrorCheck(const TSourceLoc &line, const TString &identifier)
virtual TIntermConstantUnion * getAsConstantUnion()
const TString & getName() const
bool isWebGLBasedSpec(ShShaderSpec spec)
const TFunction * findFunction(const TSourceLoc &line, TFunction *pfnCall, bool *builtIn=0)
#define ASSERT(expression)
void exitStructDeclaration()
TQualifier getQualifier() const
const char * getBasicString(TBasicType t)
void assignError(const TSourceLoc &line, const char *op, TString left, TString right)
void writeInfo(Severity severity, const pp::SourceLocation &loc, const std::string &reason, const std::string &token, const std::string &extra)
bool constErrorCheck(TIntermTyped *node)
TIntermTyped * addConstVectorNode(TVectorFields &, TIntermTyped *, const TSourceLoc &)
const TSourceLoc & getLine() const
const TType & getType() const
bool samplerErrorCheck(const TSourceLoc &line, const TPublicType &pType, const char *reason)
bool supportsExtension(const char *extension)
ConstantUnion * getUnionArrayPointer() const
bool containsSampler(TType &type)
void trace(const char *str)
TIntermediate & intermediate
virtual TIntermTyped * getAsTyped()
void shareConstPointer(ConstantUnion *constArray)
TIntermTyped * addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc &location, TIntermTyped *indexExpression)
bool boolErrorCheck(const TSourceLoc &, const TIntermTyped *)
int getIConst(int index) const
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
virtual bool isFunction() const
const TString & getMangledName() const
void writeDebug(const std::string &str)
EGLSurface EGLint void ** value
bool areAllChildConst(TIntermAggregate *aggrNode)
bool parameterSamplerErrorCheck(const TSourceLoc &line, TQualifier qualifier, const TType &type)
bool precisionErrorCheck(const TSourceLoc &line, TPrecision precision, TBasicType type)
bool arrayErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType type, TVariable *&variable)
GLsizei const GLcharARB ** string
const char * getQualifierString(TQualifier q)
bool arrayTypeErrorCheck(const TSourceLoc &line, TPublicType type)
const TExtensionBehavior & extensionBehavior() const
virtual TIntermTyped * getAsTyped()
TIntermTyped * addConstArrayNode(int index, TIntermTyped *node, const TSourceLoc &line)
TString getCompleteString() const
int glslang_scan(size_t count, const char *const string[], const int length[], TParseContext *context)
TIntermTyped * addConstMatrixNode(int, TIntermTyped *, const TSourceLoc &)
bool integerErrorCheck(TIntermTyped *node, const char *token)
size_t getObjectSize() const
bool nonInitConstErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType &type, bool array)
const char * getBasicString() const
const TFieldList & fields() const
TStructure * getStruct() const
const TString & getSymbol() const
GLenum GLint GLint * precision
bool parseVectorFields(const TString &, int vecSize, TVectorFields &, const TSourceLoc &line)
TIntermTyped * constructStruct(TIntermNode *, TType *, int, const TSourceLoc &, bool subset)
ConstantUnion * getConstPointer()
bool enterStructDeclaration(const TSourceLoc &line, const TString &identifier)
bool paramErrorCheck(const TSourceLoc &line, TQualifier qualifier, TQualifier paramQualifier, TType *type)
int getNominalSize() const
int glslang_initialize(TParseContext *context)
virtual TIntermSymbol * getAsSymbolNode()
TSymbol * find(const TString &name, bool *builtIn=0, bool *sameScope=0)
bool arrayQualifierErrorCheck(const TSourceLoc &line, TPublicType type)
bool isExtensionEnabled(const char *extension) const
bool structQualifierErrorCheck(const TSourceLoc &line, const TPublicType &pType)
bool constructorErrorCheck(const TSourceLoc &line, TIntermNode *, TFunction &, TOperator, TType *)
bool structNestingErrorCheck(const TSourceLoc &line, const TField &field)
bool nonInitErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType &type, TVariable *&variable)
bool parseMatrixFields(const TString &, int matSize, TMatrixFields &, const TSourceLoc &line)