Commit fd747b86 by zmo@google.com

Implement shader identifier name mapping.

The name mapping happens when an identifier is longer than 32 characters. The name mapping is behind a flag, so it won't happen by default. Also, functions to query the mapped names are added. The purpose of this CL is for the drivers that can't handle long names. For example, linux NVIDIA driver can't handle 256 character name, whereas WebGL spec requires that. This CL also fixes the issue that some of the TIntermSymbols' ids are 0s. ANGLEBUG=144 TEST=test manually with shaders with long identifier names. Review URL: http://codereview.appspot.com/4428058 git-svn-id: https://angleproject.googlecode.com/svn/trunk@619 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent eef864ad
...@@ -17,7 +17,7 @@ extern "C" { ...@@ -17,7 +17,7 @@ extern "C" {
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented everytime the API changes. // It is incremented everytime the API changes.
#define SH_VERSION 103 #define SH_VERSION 104
// //
// The names of the following enums have been derived by replacing GL prefix // The names of the following enums have been derived by replacing GL prefix
...@@ -62,18 +62,20 @@ typedef enum { ...@@ -62,18 +62,20 @@ typedef enum {
SH_ACTIVE_UNIFORMS = 0x8B86, SH_ACTIVE_UNIFORMS = 0x8B86,
SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87, SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
SH_ACTIVE_ATTRIBUTES = 0x8B89, SH_ACTIVE_ATTRIBUTES = 0x8B89,
SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
SH_MAPPED_NAME_MAX_LENGTH = 0x8B8B
} ShShaderInfo; } ShShaderInfo;
// Compile options. // Compile options.
typedef enum { typedef enum {
SH_VALIDATE = 0, SH_VALIDATE = 0,
SH_VALIDATE_LOOP_INDEXING = 0x0001, SH_VALIDATE_LOOP_INDEXING = 0x0001,
SH_INTERMEDIATE_TREE = 0x0002, SH_INTERMEDIATE_TREE = 0x0002,
SH_OBJECT_CODE = 0x0004, SH_OBJECT_CODE = 0x0004,
SH_ATTRIBUTES_UNIFORMS = 0x0008, SH_ATTRIBUTES_UNIFORMS = 0x0008,
SH_LINE_DIRECTIVES = 0x0010, SH_LINE_DIRECTIVES = 0x0010,
SH_SOURCE_PATH = 0x0200 SH_SOURCE_PATH = 0x0020,
SH_MAP_LONG_VARIABLE_NAMES = 0x0040
} ShCompileOptions; } ShCompileOptions;
// //
...@@ -185,6 +187,8 @@ int ShCompile( ...@@ -185,6 +187,8 @@ int ShCompile(
// SH_ACTIVE_UNIFORM_MAX_LENGTH: the length of the longest active uniform // SH_ACTIVE_UNIFORM_MAX_LENGTH: the length of the longest active uniform
// variable name including the null // variable name including the null
// termination character. // termination character.
// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including
// the null termination character.
// //
// params: Requested parameter // params: Requested parameter
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params); void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params);
...@@ -223,12 +227,18 @@ void ShGetObjectCode(const ShHandle handle, char* objCode); ...@@ -223,12 +227,18 @@ void ShGetObjectCode(const ShHandle handle, char* objCode);
// accomodate the attribute variable name. The size of the buffer // accomodate the attribute variable name. The size of the buffer
// required to store the attribute variable name can be obtained by // required to store the attribute variable name can be obtained by
// calling ShGetInfo with SH_ACTIVE_ATTRIBUTE_MAX_LENGTH. // calling ShGetInfo with SH_ACTIVE_ATTRIBUTE_MAX_LENGTH.
// mappedName: Returns a null terminated string containing the mapped name of
// the attribute variable, It is assumed that mappedName has enough
// memory (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care
// about the mapped name. If the name is not mapped, then name and
// mappedName are the same.
void ShGetActiveAttrib(const ShHandle handle, void ShGetActiveAttrib(const ShHandle handle,
int index, int index,
int* length, int* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name); char* name,
char* mappedName);
// Returns information about an active uniform variable. // Returns information about an active uniform variable.
// Parameters: // Parameters:
...@@ -244,12 +254,18 @@ void ShGetActiveAttrib(const ShHandle handle, ...@@ -244,12 +254,18 @@ void ShGetActiveAttrib(const ShHandle handle,
// accomodate the uniform variable name. The size of the buffer required // accomodate the uniform variable name. The size of the buffer required
// to store the uniform variable name can be obtained by calling // to store the uniform variable name can be obtained by calling
// ShGetInfo with SH_ACTIVE_UNIFORMS_MAX_LENGTH. // ShGetInfo with SH_ACTIVE_UNIFORMS_MAX_LENGTH.
// mappedName: Returns a null terminated string containing the mapped name of
// the uniform variable, It is assumed that mappedName has enough
// memory (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care
// about the mapped name. If the name is not mapped, then name and
// mappedName are the same.
void ShGetActiveUniform(const ShHandle handle, void ShGetActiveUniform(const ShHandle handle,
int index, int index,
int* length, int* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name); char* name,
char* mappedName);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
'compiler/intermOut.cpp', 'compiler/intermOut.cpp',
'compiler/IntermTraverse.cpp', 'compiler/IntermTraverse.cpp',
'compiler/localintermediate.h', 'compiler/localintermediate.h',
'compiler/MapLongVariableNames.cpp',
'compiler/MapLongVariableNames.h',
'compiler/MMap.h', 'compiler/MMap.h',
'compiler/osinclude.h', 'compiler/osinclude.h',
'compiler/parseConst.cpp', 'compiler/parseConst.cpp',
......
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 618 #define BUILD_REVISION 619
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "compiler/ParseHelper.h" #include "compiler/ParseHelper.h"
#include "compiler/ShHandle.h" #include "compiler/ShHandle.h"
#include "compiler/ValidateLimitations.h" #include "compiler/ValidateLimitations.h"
#include "compiler/MapLongVariableNames.h"
namespace { namespace {
bool InitializeSymbolTable( bool InitializeSymbolTable(
...@@ -147,14 +148,20 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -147,14 +148,20 @@ bool TCompiler::compile(const char* const shaderStrings[],
if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING)) if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING))
success = validateLimitations(root); success = validateLimitations(root);
// Call mapLongVariableNames() before collectAttribsUniforms() so in
// collectAttribsUniforms() we already have the mapped symbol names and
// we could composite mapped and original variable names.
if (compileOptions & SH_MAP_LONG_VARIABLE_NAMES)
mapLongVariableNames(root);
if (success && (compileOptions & SH_ATTRIBUTES_UNIFORMS))
collectAttribsUniforms(root);
if (success && (compileOptions & SH_INTERMEDIATE_TREE)) if (success && (compileOptions & SH_INTERMEDIATE_TREE))
intermediate.outputTree(root); intermediate.outputTree(root);
if (success && (compileOptions & SH_OBJECT_CODE)) if (success && (compileOptions & SH_OBJECT_CODE))
translate(root); translate(root);
if (success && (compileOptions & SH_ATTRIBUTES_UNIFORMS))
collectAttribsUniforms(root);
} }
// Cleanup memory. // Cleanup memory.
...@@ -197,3 +204,14 @@ void TCompiler::collectAttribsUniforms(TIntermNode* root) ...@@ -197,3 +204,14 @@ void TCompiler::collectAttribsUniforms(TIntermNode* root)
CollectAttribsUniforms collect(attribs, uniforms); CollectAttribsUniforms collect(attribs, uniforms);
root->traverse(&collect); root->traverse(&collect);
} }
void TCompiler::mapLongVariableNames(TIntermNode* root)
{
MapLongVariableNames map;
root->traverse(&map);
}
int TCompiler::getMappedNameMaxLength() const
{
return MAX_IDENTIFIER_NAME_SIZE + 1;
}
//
// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/MapLongVariableNames.h"
namespace {
TString mapLongName(int id, const TString& name)
{
ASSERT(name.size() > MAX_IDENTIFIER_NAME_SIZE);
TStringStream stream;
stream << "webgl_" << id << "_";
stream << name.substr(0, MAX_IDENTIFIER_NAME_SIZE - stream.str().size());
return stream.str();
}
} // anonymous namespace
void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
{
ASSERT(symbol != NULL);
if (symbol->getSymbol().size() > MAX_IDENTIFIER_NAME_SIZE)
symbol->setSymbol(mapLongName(symbol->getId(), symbol->getSymbol()));
}
void MapLongVariableNames::visitConstantUnion(TIntermConstantUnion*)
{
}
bool MapLongVariableNames::visitBinary(Visit, TIntermBinary*)
{
return true;
}
bool MapLongVariableNames::visitUnary(Visit, TIntermUnary*)
{
return true;
}
bool MapLongVariableNames::visitSelection(Visit, TIntermSelection*)
{
return true;
}
bool MapLongVariableNames::visitAggregate(Visit, TIntermAggregate* node)
{
return true;
}
bool MapLongVariableNames::visitLoop(Visit, TIntermLoop*)
{
return true;
}
bool MapLongVariableNames::visitBranch(Visit, TIntermBranch*)
{
return true;
}
//
// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_MAP_LONG_VARIABLE_NAMES_H_
#define COMPILER_MAP_LONG_VARIABLE_NAMES_H_
#include "GLSLANG/ShaderLang.h"
#include "compiler/intermediate.h"
#include "compiler/VariableInfo.h"
// This size does not include '\0' in the end.
#define MAX_IDENTIFIER_NAME_SIZE 32
// Traverses intermediate tree to map attributes and uniforms names that are
// longer than MAX_IDENTIFIER_NAME_SIZE to MAX_IDENTIFIER_NAME_SIZE.
class MapLongVariableNames : public TIntermTraverser {
public:
MapLongVariableNames() { }
virtual void visitSymbol(TIntermSymbol*);
virtual void visitConstantUnion(TIntermConstantUnion*);
virtual bool visitBinary(Visit, TIntermBinary*);
virtual bool visitUnary(Visit, TIntermUnary*);
virtual bool visitSelection(Visit, TIntermSelection*);
virtual bool visitAggregate(Visit, TIntermAggregate*);
virtual bool visitLoop(Visit, TIntermLoop*);
virtual bool visitBranch(Visit, TIntermBranch*);
};
#endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_
\ No newline at end of file
...@@ -882,16 +882,17 @@ bool TParseContext::nonInitConstErrorCheck(int line, TString& identifier, TPubli ...@@ -882,16 +882,17 @@ bool TParseContext::nonInitConstErrorCheck(int line, TString& identifier, TPubli
// //
// Returns true if there was an error. // Returns true if there was an error.
// //
bool TParseContext::nonInitErrorCheck(int line, TString& identifier, TPublicType& type) bool TParseContext::nonInitErrorCheck(int line, TString& identifier, TPublicType& type, TVariable*& variable)
{ {
if (reservedErrorCheck(line, identifier)) if (reservedErrorCheck(line, identifier))
recover(); recover();
TVariable* variable = new TVariable(&identifier, TType(type)); variable = new TVariable(&identifier, TType(type));
if (! symbolTable.insert(*variable)) { if (! symbolTable.insert(*variable)) {
error(line, "redefinition", variable->getName().c_str(), ""); error(line, "redefinition", variable->getName().c_str(), "");
delete variable; delete variable;
variable = 0;
return true; return true;
} }
......
...@@ -81,7 +81,7 @@ struct TParseContext { ...@@ -81,7 +81,7 @@ struct TParseContext {
bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type); bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type);
bool containsSampler(TType& type); bool containsSampler(TType& type);
bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type); bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type);
bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type); bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type, TVariable*& variable);
bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type); bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type);
bool extensionErrorCheck(int line, const TString&); bool extensionErrorCheck(int line, const TString&);
const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0); const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0);
......
...@@ -57,6 +57,7 @@ public: ...@@ -57,6 +57,7 @@ public:
TInfoSink& getInfoSink() { return infoSink; } TInfoSink& getInfoSink() { return infoSink; }
const TVariableInfoList& getAttribs() const { return attribs; } const TVariableInfoList& getAttribs() const { return attribs; }
const TVariableInfoList& getUniforms() const { return uniforms; } const TVariableInfoList& getUniforms() const { return uniforms; }
int getMappedNameMaxLength() const;
protected: protected:
ShShaderType getShaderType() const { return shaderType; } ShShaderType getShaderType() const { return shaderType; }
...@@ -70,6 +71,8 @@ protected: ...@@ -70,6 +71,8 @@ protected:
bool validateLimitations(TIntermNode* root); bool validateLimitations(TIntermNode* root);
// Collect info for all attribs and uniforms. // Collect info for all attribs and uniforms.
void collectAttribsUniforms(TIntermNode* root); void collectAttribsUniforms(TIntermNode* root);
// Map long variable names into shorter ones.
void mapLongVariableNames(TIntermNode* root);
// Translate to object code. // Translate to object code.
virtual void translate(TIntermNode* root) = 0; virtual void translate(TIntermNode* root) = 0;
......
...@@ -37,7 +37,8 @@ static void getVariableInfo(ShShaderInfo varType, ...@@ -37,7 +37,8 @@ static void getVariableInfo(ShShaderInfo varType,
int* length, int* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name) char* name,
char* mappedName)
{ {
if (!handle || !size || !type || !name) if (!handle || !size || !type || !name)
return; return;
...@@ -59,6 +60,8 @@ static void getVariableInfo(ShShaderInfo varType, ...@@ -59,6 +60,8 @@ static void getVariableInfo(ShShaderInfo varType,
*size = varInfo.size; *size = varInfo.size;
*type = varInfo.type; *type = varInfo.type;
strcpy(name, varInfo.name.c_str()); strcpy(name, varInfo.name.c_str());
if (mappedName)
strcpy(mappedName, varInfo.mappedName.c_str());
} }
// //
...@@ -194,7 +197,9 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params) ...@@ -194,7 +197,9 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params)
case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH: case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
*params = getVariableMaxLength(compiler->getAttribs()); *params = getVariableMaxLength(compiler->getAttribs());
break; break;
case SH_MAPPED_NAME_MAX_LENGTH:
*params = compiler->getMappedNameMaxLength();
break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
...@@ -236,10 +241,11 @@ void ShGetActiveAttrib(const ShHandle handle, ...@@ -236,10 +241,11 @@ void ShGetActiveAttrib(const ShHandle handle,
int* length, int* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name) char* name,
char* mappedName)
{ {
getVariableInfo(SH_ACTIVE_ATTRIBUTES, getVariableInfo(SH_ACTIVE_ATTRIBUTES,
handle, index, length, size, type, name); handle, index, length, size, type, name, mappedName);
} }
void ShGetActiveUniform(const ShHandle handle, void ShGetActiveUniform(const ShHandle handle,
...@@ -247,8 +253,9 @@ void ShGetActiveUniform(const ShHandle handle, ...@@ -247,8 +253,9 @@ void ShGetActiveUniform(const ShHandle handle,
int* length, int* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name) char* name,
char* mappedName)
{ {
getVariableInfo(SH_ACTIVE_UNIFORMS, getVariableInfo(SH_ACTIVE_UNIFORMS,
handle, index, length, size, type, name); handle, index, length, size, type, name, mappedName);
} }
...@@ -70,32 +70,37 @@ static ShDataType getVariableDataType(const TType& type) ...@@ -70,32 +70,37 @@ static ShDataType getVariableDataType(const TType& type)
static void getBuiltInVariableInfo(const TType& type, static void getBuiltInVariableInfo(const TType& type,
const TString& name, const TString& name,
const TString& mappedName,
TVariableInfoList& infoList); TVariableInfoList& infoList);
static void getUserDefinedVariableInfo(const TType& type, static void getUserDefinedVariableInfo(const TType& type,
const TString& name, const TString& name,
const TString& mappedName,
TVariableInfoList& infoList); TVariableInfoList& infoList);
// Returns info for an attribute or uniform. // Returns info for an attribute or uniform.
static void getVariableInfo(const TType& type, static void getVariableInfo(const TType& type,
const TString& name, const TString& name,
const TString& mappedName,
TVariableInfoList& infoList) TVariableInfoList& infoList)
{ {
if (type.getBasicType() == EbtStruct) { if (type.getBasicType() == EbtStruct) {
if (type.isArray()) { if (type.isArray()) {
for (int i = 0; i < type.getArraySize(); ++i) { for (int i = 0; i < type.getArraySize(); ++i) {
TString lname = name + arrayBrackets(i); TString lname = name + arrayBrackets(i);
getUserDefinedVariableInfo(type, lname, infoList); TString lmappedName = mappedName + arrayBrackets(i);
getUserDefinedVariableInfo(type, lname, lmappedName, infoList);
} }
} else { } else {
getUserDefinedVariableInfo(type, name, infoList); getUserDefinedVariableInfo(type, name, mappedName, infoList);
} }
} else { } else {
getBuiltInVariableInfo(type, name, infoList); getBuiltInVariableInfo(type, name, mappedName, infoList);
} }
} }
void getBuiltInVariableInfo(const TType& type, void getBuiltInVariableInfo(const TType& type,
const TString& name, const TString& name,
const TString& mappedName,
TVariableInfoList& infoList) TVariableInfoList& infoList)
{ {
ASSERT(type.getBasicType() != EbtStruct); ASSERT(type.getBasicType() != EbtStruct);
...@@ -103,9 +108,11 @@ void getBuiltInVariableInfo(const TType& type, ...@@ -103,9 +108,11 @@ void getBuiltInVariableInfo(const TType& type,
TVariableInfo varInfo; TVariableInfo varInfo;
if (type.isArray()) { if (type.isArray()) {
varInfo.name = (name + "[0]").c_str(); varInfo.name = (name + "[0]").c_str();
varInfo.mappedName = (mappedName + "[0]").c_str();
varInfo.size = type.getArraySize(); varInfo.size = type.getArraySize();
} else { } else {
varInfo.name = name.c_str(); varInfo.name = name.c_str();
varInfo.mappedName = mappedName.c_str();
varInfo.size = 1; varInfo.size = 1;
} }
varInfo.type = getVariableDataType(type); varInfo.type = getVariableDataType(type);
...@@ -114,16 +121,17 @@ void getBuiltInVariableInfo(const TType& type, ...@@ -114,16 +121,17 @@ void getBuiltInVariableInfo(const TType& type,
void getUserDefinedVariableInfo(const TType& type, void getUserDefinedVariableInfo(const TType& type,
const TString& name, const TString& name,
const TString& mappedName,
TVariableInfoList& infoList) TVariableInfoList& infoList)
{ {
ASSERT(type.getBasicType() == EbtStruct); ASSERT(type.getBasicType() == EbtStruct);
TString lname = name + ".";
const TTypeList* structure = type.getStruct(); const TTypeList* structure = type.getStruct();
for (size_t i = 0; i < structure->size(); ++i) { for (size_t i = 0; i < structure->size(); ++i) {
const TType* fieldType = (*structure)[i].type; const TType* fieldType = (*structure)[i].type;
getVariableInfo(*fieldType, getVariableInfo(*fieldType,
lname + fieldType->getFieldName(), name + "." + fieldType->getFieldName(),
mappedName + "." + fieldType->getFieldName(),
infoList); infoList);
} }
} }
...@@ -186,7 +194,9 @@ bool CollectAttribsUniforms::visitAggregate(Visit, TIntermAggregate* node) ...@@ -186,7 +194,9 @@ bool CollectAttribsUniforms::visitAggregate(Visit, TIntermAggregate* node)
// cannot be initialized in a shader, we must have only // cannot be initialized in a shader, we must have only
// TIntermSymbol nodes in the sequence. // TIntermSymbol nodes in the sequence.
ASSERT(variable != NULL); ASSERT(variable != NULL);
getVariableInfo(variable->getType(), variable->getSymbol(), getVariableInfo(variable->getType(),
variable->getOriginalSymbol(),
variable->getSymbol(),
infoList); infoList);
} }
} }
......
// //
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
#ifndef COMPILER_VARIABLE_INFO_H_
#define COMPILER_VARIABLE_INFO_H_
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "compiler/intermediate.h" #include "compiler/intermediate.h"
...@@ -11,6 +14,7 @@ ...@@ -11,6 +14,7 @@
// It is currently being used to store info about active attribs and uniforms. // It is currently being used to store info about active attribs and uniforms.
struct TVariableInfo { struct TVariableInfo {
TPersistString name; TPersistString name;
TPersistString mappedName;
ShDataType type; ShDataType type;
int size; int size;
}; };
...@@ -36,3 +40,4 @@ private: ...@@ -36,3 +40,4 @@ private:
TVariableInfoList& mUniforms; TVariableInfoList& mUniforms;
}; };
#endif // COMPILER_VARIABLE_INFO_H_
\ No newline at end of file
...@@ -1185,7 +1185,8 @@ init_declarator_list ...@@ -1185,7 +1185,8 @@ init_declarator_list
} }
} }
| init_declarator_list COMMA IDENTIFIER { | init_declarator_list COMMA IDENTIFIER {
$$.intermAggregate = context->intermediate.growAggregate($1.intermNode, context->intermediate.addSymbol(0, *$3.string, TType($1.type), $3.line), $3.line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$3.string, TType($1.type), $3.line);
$$.intermAggregate = context->intermediate.growAggregate($1.intermNode, symbol, $3.line);
if (context->structQualifierErrorCheck($3.line, $$.type)) if (context->structQualifierErrorCheck($3.line, $$.type))
context->recover(); context->recover();
...@@ -1193,8 +1194,11 @@ init_declarator_list ...@@ -1193,8 +1194,11 @@ init_declarator_list
if (context->nonInitConstErrorCheck($3.line, *$3.string, $$.type)) if (context->nonInitConstErrorCheck($3.line, *$3.string, $$.type))
context->recover(); context->recover();
if (context->nonInitErrorCheck($3.line, *$3.string, $$.type)) TVariable* variable = 0;
if (context->nonInitErrorCheck($3.line, *$3.string, $$.type, variable))
context->recover(); context->recover();
if (symbol && variable)
symbol->setId(variable->getUniqueId());
} }
| init_declarator_list COMMA IDENTIFIER LEFT_BRACKET RIGHT_BRACKET { | init_declarator_list COMMA IDENTIFIER LEFT_BRACKET RIGHT_BRACKET {
if (context->structQualifierErrorCheck($3.line, $1.type)) if (context->structQualifierErrorCheck($3.line, $1.type))
...@@ -1230,12 +1234,12 @@ init_declarator_list ...@@ -1230,12 +1234,12 @@ init_declarator_list
if (context->arraySizeErrorCheck($4.line, $5, size)) if (context->arraySizeErrorCheck($4.line, $5, size))
context->recover(); context->recover();
$1.type.setArray(true, size); $1.type.setArray(true, size);
TVariable* variable; TVariable* variable = 0;
if (context->arrayErrorCheck($4.line, *$3.string, $1.type, variable)) if (context->arrayErrorCheck($4.line, *$3.string, $1.type, variable))
context->recover(); context->recover();
TType type = TType($1.type); TType type = TType($1.type);
type.setArraySize(size); type.setArraySize(size);
$$.intermAggregate = context->intermediate.growAggregate($1.intermNode, context->intermediate.addSymbol(0, *$3.string, type, $3.line), $3.line); $$.intermAggregate = context->intermediate.growAggregate($1.intermNode, context->intermediate.addSymbol(variable ? variable->getUniqueId() : 0, *$3.string, type, $3.line), $3.line);
} }
} }
| init_declarator_list COMMA IDENTIFIER EQUAL initializer { | init_declarator_list COMMA IDENTIFIER EQUAL initializer {
...@@ -1266,7 +1270,8 @@ single_declaration ...@@ -1266,7 +1270,8 @@ single_declaration
$$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, "", TType($1), $1.line), $1.line); $$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, "", TType($1), $1.line), $1.line);
} }
| fully_specified_type IDENTIFIER { | fully_specified_type IDENTIFIER {
$$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line);
$$.intermAggregate = context->intermediate.makeAggregate(symbol, $2.line);
if (context->structQualifierErrorCheck($2.line, $$.type)) if (context->structQualifierErrorCheck($2.line, $$.type))
context->recover(); context->recover();
...@@ -1276,11 +1281,15 @@ single_declaration ...@@ -1276,11 +1281,15 @@ single_declaration
$$.type = $1; $$.type = $1;
if (context->nonInitErrorCheck($2.line, *$2.string, $$.type)) TVariable* variable = 0;
if (context->nonInitErrorCheck($2.line, *$2.string, $$.type, variable))
context->recover(); context->recover();
if (variable && symbol)
symbol->setId(variable->getUniqueId());
} }
| fully_specified_type IDENTIFIER LEFT_BRACKET RIGHT_BRACKET { | fully_specified_type IDENTIFIER LEFT_BRACKET RIGHT_BRACKET {
$$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line), $2.line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$2.string, TType($1), $2.line);
$$.intermAggregate = context->intermediate.makeAggregate(symbol, $2.line);
if (context->structQualifierErrorCheck($2.line, $1)) if (context->structQualifierErrorCheck($2.line, $1))
context->recover(); context->recover();
...@@ -1294,9 +1303,11 @@ single_declaration ...@@ -1294,9 +1303,11 @@ single_declaration
context->recover(); context->recover();
else { else {
$1.setArray(true); $1.setArray(true);
TVariable* variable; TVariable* variable = 0;
if (context->arrayErrorCheck($3.line, *$2.string, $1, variable)) if (context->arrayErrorCheck($3.line, *$2.string, $1, variable))
context->recover(); context->recover();
if (variable && symbol)
symbol->setId(variable->getUniqueId());
} }
} }
| fully_specified_type IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET { | fully_specified_type IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET {
...@@ -1305,7 +1316,8 @@ single_declaration ...@@ -1305,7 +1316,8 @@ single_declaration
if (context->arraySizeErrorCheck($2.line, $4, size)) if (context->arraySizeErrorCheck($2.line, $4, size))
context->recover(); context->recover();
type.setArraySize(size); type.setArraySize(size);
$$.intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *$2.string, type, $2.line), $2.line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *$2.string, type, $2.line);
$$.intermAggregate = context->intermediate.makeAggregate(symbol, $2.line);
if (context->structQualifierErrorCheck($2.line, $1)) if (context->structQualifierErrorCheck($2.line, $1))
context->recover(); context->recover();
...@@ -1323,9 +1335,11 @@ single_declaration ...@@ -1323,9 +1335,11 @@ single_declaration
context->recover(); context->recover();
$1.setArray(true, size); $1.setArray(true, size);
TVariable* variable; TVariable* variable = 0;
if (context->arrayErrorCheck($3.line, *$2.string, $1, variable)) if (context->arrayErrorCheck($3.line, *$2.string, $1, variable))
context->recover(); context->recover();
if (variable && symbol)
symbol->setId(variable->getUniqueId());
} }
} }
| fully_specified_type IDENTIFIER EQUAL initializer { | fully_specified_type IDENTIFIER EQUAL initializer {
......
...@@ -325,7 +325,7 @@ typedef union YYSTYPE ...@@ -325,7 +325,7 @@ typedef union YYSTYPE
}; };
} interm; } interm;
} }
/* Line 187 of yacc.c. */ /* Line 193 of yacc.c. */
YYSTYPE; YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
...@@ -415,7 +415,7 @@ typedef short int yytype_int16; ...@@ -415,7 +415,7 @@ typedef short int yytype_int16;
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
#ifndef YY_ #ifndef YY_
# if YYENABLE_NLS # if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS # if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(msgid) dgettext ("bison-runtime", msgid) # define YY_(msgid) dgettext ("bison-runtime", msgid)
...@@ -738,17 +738,17 @@ static const yytype_uint16 yyrline[] = ...@@ -738,17 +738,17 @@ static const yytype_uint16 yyrline[] =
893, 910, 911, 924, 925, 926, 927, 928, 932, 935, 893, 910, 911, 924, 925, 926, 927, 928, 932, 935,
946, 954, 979, 984, 991, 1027, 1030, 1037, 1045, 1066, 946, 954, 979, 984, 991, 1027, 1030, 1037, 1045, 1066,
1085, 1096, 1125, 1130, 1140, 1145, 1155, 1158, 1161, 1164, 1085, 1096, 1125, 1130, 1140, 1145, 1155, 1158, 1161, 1164,
1170, 1177, 1187, 1199, 1217, 1241, 1264, 1268, 1282, 1302, 1170, 1177, 1187, 1203, 1221, 1245, 1268, 1272, 1290, 1313,
1331, 1351, 1427, 1436, 1459, 1462, 1468, 1476, 1484, 1492, 1345, 1365, 1441, 1450, 1473, 1476, 1482, 1490, 1498, 1506,
1495, 1502, 1505, 1508, 1514, 1517, 1532, 1536, 1540, 1544, 1509, 1516, 1519, 1522, 1528, 1531, 1546, 1550, 1554, 1558,
1553, 1558, 1563, 1568, 1573, 1578, 1583, 1588, 1593, 1598, 1567, 1572, 1577, 1582, 1587, 1592, 1597, 1602, 1607, 1612,
1604, 1610, 1616, 1621, 1626, 1631, 1644, 1657, 1665, 1668, 1618, 1624, 1630, 1635, 1640, 1645, 1658, 1671, 1679, 1682,
1683, 1714, 1718, 1724, 1732, 1748, 1752, 1756, 1757, 1763, 1697, 1728, 1732, 1738, 1746, 1762, 1766, 1770, 1771, 1777,
1764, 1765, 1766, 1767, 1771, 1772, 1772, 1772, 1782, 1783, 1778, 1779, 1780, 1781, 1785, 1786, 1786, 1786, 1796, 1797,
1788, 1791, 1801, 1804, 1810, 1811, 1815, 1823, 1827, 1837, 1802, 1805, 1815, 1818, 1824, 1825, 1829, 1837, 1841, 1851,
1842, 1859, 1859, 1864, 1864, 1871, 1871, 1879, 1882, 1888, 1856, 1873, 1873, 1878, 1878, 1885, 1885, 1893, 1896, 1902,
1891, 1897, 1901, 1908, 1915, 1922, 1929, 1940, 1949, 1953, 1905, 1911, 1915, 1922, 1929, 1936, 1943, 1954, 1963, 1967,
1960, 1963, 1969, 1969 1974, 1977, 1983, 1983
}; };
#endif #endif
...@@ -1361,7 +1361,7 @@ while (YYID (0)) ...@@ -1361,7 +1361,7 @@ while (YYID (0))
we won't break user code: when these are the locations we know. */ we won't break user code: when these are the locations we know. */
#ifndef YY_LOCATION_PRINT #ifndef YY_LOCATION_PRINT
# if YYLTYPE_IS_TRIVIAL # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
# define YY_LOCATION_PRINT(File, Loc) \ # define YY_LOCATION_PRINT(File, Loc) \
fprintf (File, "%d.%d-%d.%d", \ fprintf (File, "%d.%d-%d.%d", \
(Loc).first_line, (Loc).first_column, \ (Loc).first_line, (Loc).first_column, \
...@@ -3373,7 +3373,8 @@ yyreduce: ...@@ -3373,7 +3373,8 @@ yyreduce:
case 92: case 92:
{ {
(yyval.interm).intermAggregate = context->intermediate.growAggregate((yyvsp[(1) - (3)].interm).intermNode, context->intermediate.addSymbol(0, *(yyvsp[(3) - (3)].lex).string, TType((yyvsp[(1) - (3)].interm).type), (yyvsp[(3) - (3)].lex).line), (yyvsp[(3) - (3)].lex).line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *(yyvsp[(3) - (3)].lex).string, TType((yyvsp[(1) - (3)].interm).type), (yyvsp[(3) - (3)].lex).line);
(yyval.interm).intermAggregate = context->intermediate.growAggregate((yyvsp[(1) - (3)].interm).intermNode, symbol, (yyvsp[(3) - (3)].lex).line);
if (context->structQualifierErrorCheck((yyvsp[(3) - (3)].lex).line, (yyval.interm).type)) if (context->structQualifierErrorCheck((yyvsp[(3) - (3)].lex).line, (yyval.interm).type))
context->recover(); context->recover();
...@@ -3381,8 +3382,11 @@ yyreduce: ...@@ -3381,8 +3382,11 @@ yyreduce:
if (context->nonInitConstErrorCheck((yyvsp[(3) - (3)].lex).line, *(yyvsp[(3) - (3)].lex).string, (yyval.interm).type)) if (context->nonInitConstErrorCheck((yyvsp[(3) - (3)].lex).line, *(yyvsp[(3) - (3)].lex).string, (yyval.interm).type))
context->recover(); context->recover();
if (context->nonInitErrorCheck((yyvsp[(3) - (3)].lex).line, *(yyvsp[(3) - (3)].lex).string, (yyval.interm).type)) TVariable* variable = 0;
if (context->nonInitErrorCheck((yyvsp[(3) - (3)].lex).line, *(yyvsp[(3) - (3)].lex).string, (yyval.interm).type, variable))
context->recover(); context->recover();
if (symbol && variable)
symbol->setId(variable->getUniqueId());
;} ;}
break; break;
...@@ -3426,12 +3430,12 @@ yyreduce: ...@@ -3426,12 +3430,12 @@ yyreduce:
if (context->arraySizeErrorCheck((yyvsp[(4) - (6)].lex).line, (yyvsp[(5) - (6)].interm.intermTypedNode), size)) if (context->arraySizeErrorCheck((yyvsp[(4) - (6)].lex).line, (yyvsp[(5) - (6)].interm.intermTypedNode), size))
context->recover(); context->recover();
(yyvsp[(1) - (6)].interm).type.setArray(true, size); (yyvsp[(1) - (6)].interm).type.setArray(true, size);
TVariable* variable; TVariable* variable = 0;
if (context->arrayErrorCheck((yyvsp[(4) - (6)].lex).line, *(yyvsp[(3) - (6)].lex).string, (yyvsp[(1) - (6)].interm).type, variable)) if (context->arrayErrorCheck((yyvsp[(4) - (6)].lex).line, *(yyvsp[(3) - (6)].lex).string, (yyvsp[(1) - (6)].interm).type, variable))
context->recover(); context->recover();
TType type = TType((yyvsp[(1) - (6)].interm).type); TType type = TType((yyvsp[(1) - (6)].interm).type);
type.setArraySize(size); type.setArraySize(size);
(yyval.interm).intermAggregate = context->intermediate.growAggregate((yyvsp[(1) - (6)].interm).intermNode, context->intermediate.addSymbol(0, *(yyvsp[(3) - (6)].lex).string, type, (yyvsp[(3) - (6)].lex).line), (yyvsp[(3) - (6)].lex).line); (yyval.interm).intermAggregate = context->intermediate.growAggregate((yyvsp[(1) - (6)].interm).intermNode, context->intermediate.addSymbol(variable ? variable->getUniqueId() : 0, *(yyvsp[(3) - (6)].lex).string, type, (yyvsp[(3) - (6)].lex).line), (yyvsp[(3) - (6)].lex).line);
} }
;} ;}
break; break;
...@@ -3471,7 +3475,8 @@ yyreduce: ...@@ -3471,7 +3475,8 @@ yyreduce:
case 97: case 97:
{ {
(yyval.interm).intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *(yyvsp[(2) - (2)].lex).string, TType((yyvsp[(1) - (2)].interm.type)), (yyvsp[(2) - (2)].lex).line), (yyvsp[(2) - (2)].lex).line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *(yyvsp[(2) - (2)].lex).string, TType((yyvsp[(1) - (2)].interm.type)), (yyvsp[(2) - (2)].lex).line);
(yyval.interm).intermAggregate = context->intermediate.makeAggregate(symbol, (yyvsp[(2) - (2)].lex).line);
if (context->structQualifierErrorCheck((yyvsp[(2) - (2)].lex).line, (yyval.interm).type)) if (context->structQualifierErrorCheck((yyvsp[(2) - (2)].lex).line, (yyval.interm).type))
context->recover(); context->recover();
...@@ -3481,15 +3486,19 @@ yyreduce: ...@@ -3481,15 +3486,19 @@ yyreduce:
(yyval.interm).type = (yyvsp[(1) - (2)].interm.type); (yyval.interm).type = (yyvsp[(1) - (2)].interm.type);
if (context->nonInitErrorCheck((yyvsp[(2) - (2)].lex).line, *(yyvsp[(2) - (2)].lex).string, (yyval.interm).type)) TVariable* variable = 0;
if (context->nonInitErrorCheck((yyvsp[(2) - (2)].lex).line, *(yyvsp[(2) - (2)].lex).string, (yyval.interm).type, variable))
context->recover(); context->recover();
if (variable && symbol)
symbol->setId(variable->getUniqueId());
;} ;}
break; break;
case 98: case 98:
{ {
(yyval.interm).intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *(yyvsp[(2) - (4)].lex).string, TType((yyvsp[(1) - (4)].interm.type)), (yyvsp[(2) - (4)].lex).line), (yyvsp[(2) - (4)].lex).line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *(yyvsp[(2) - (4)].lex).string, TType((yyvsp[(1) - (4)].interm.type)), (yyvsp[(2) - (4)].lex).line);
(yyval.interm).intermAggregate = context->intermediate.makeAggregate(symbol, (yyvsp[(2) - (4)].lex).line);
if (context->structQualifierErrorCheck((yyvsp[(2) - (4)].lex).line, (yyvsp[(1) - (4)].interm.type))) if (context->structQualifierErrorCheck((yyvsp[(2) - (4)].lex).line, (yyvsp[(1) - (4)].interm.type)))
context->recover(); context->recover();
...@@ -3503,9 +3512,11 @@ yyreduce: ...@@ -3503,9 +3512,11 @@ yyreduce:
context->recover(); context->recover();
else { else {
(yyvsp[(1) - (4)].interm.type).setArray(true); (yyvsp[(1) - (4)].interm.type).setArray(true);
TVariable* variable; TVariable* variable = 0;
if (context->arrayErrorCheck((yyvsp[(3) - (4)].lex).line, *(yyvsp[(2) - (4)].lex).string, (yyvsp[(1) - (4)].interm.type), variable)) if (context->arrayErrorCheck((yyvsp[(3) - (4)].lex).line, *(yyvsp[(2) - (4)].lex).string, (yyvsp[(1) - (4)].interm.type), variable))
context->recover(); context->recover();
if (variable && symbol)
symbol->setId(variable->getUniqueId());
} }
;} ;}
break; break;
...@@ -3518,7 +3529,8 @@ yyreduce: ...@@ -3518,7 +3529,8 @@ yyreduce:
if (context->arraySizeErrorCheck((yyvsp[(2) - (5)].lex).line, (yyvsp[(4) - (5)].interm.intermTypedNode), size)) if (context->arraySizeErrorCheck((yyvsp[(2) - (5)].lex).line, (yyvsp[(4) - (5)].interm.intermTypedNode), size))
context->recover(); context->recover();
type.setArraySize(size); type.setArraySize(size);
(yyval.interm).intermAggregate = context->intermediate.makeAggregate(context->intermediate.addSymbol(0, *(yyvsp[(2) - (5)].lex).string, type, (yyvsp[(2) - (5)].lex).line), (yyvsp[(2) - (5)].lex).line); TIntermSymbol* symbol = context->intermediate.addSymbol(0, *(yyvsp[(2) - (5)].lex).string, type, (yyvsp[(2) - (5)].lex).line);
(yyval.interm).intermAggregate = context->intermediate.makeAggregate(symbol, (yyvsp[(2) - (5)].lex).line);
if (context->structQualifierErrorCheck((yyvsp[(2) - (5)].lex).line, (yyvsp[(1) - (5)].interm.type))) if (context->structQualifierErrorCheck((yyvsp[(2) - (5)].lex).line, (yyvsp[(1) - (5)].interm.type)))
context->recover(); context->recover();
...@@ -3536,9 +3548,11 @@ yyreduce: ...@@ -3536,9 +3548,11 @@ yyreduce:
context->recover(); context->recover();
(yyvsp[(1) - (5)].interm.type).setArray(true, size); (yyvsp[(1) - (5)].interm.type).setArray(true, size);
TVariable* variable; TVariable* variable = 0;
if (context->arrayErrorCheck((yyvsp[(3) - (5)].lex).line, *(yyvsp[(2) - (5)].lex).string, (yyvsp[(1) - (5)].interm.type), variable)) if (context->arrayErrorCheck((yyvsp[(3) - (5)].lex).line, *(yyvsp[(2) - (5)].lex).string, (yyvsp[(1) - (5)].interm.type), variable))
context->recover(); context->recover();
if (variable && symbol)
symbol->setId(variable->getUniqueId());
} }
;} ;}
break; break;
......
...@@ -262,7 +262,7 @@ typedef union YYSTYPE ...@@ -262,7 +262,7 @@ typedef union YYSTYPE
}; };
} interm; } interm;
} }
/* Line 1489 of yacc.c. */ /* Line 1529 of yacc.c. */
YYSTYPE; YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
......
...@@ -332,17 +332,23 @@ public: ...@@ -332,17 +332,23 @@ public:
// per process globalpoolallocator, then it causes increased memory usage per compile // per process globalpoolallocator, then it causes increased memory usage per compile
// it is essential to use "symbol = sym" to assign to symbol // it is essential to use "symbol = sym" to assign to symbol
TIntermSymbol(int i, const TString& sym, const TType& t) : TIntermSymbol(int i, const TString& sym, const TType& t) :
TIntermTyped(t), id(i) { symbol = sym;} TIntermTyped(t), id(i) { symbol = sym; originalSymbol = sym; }
int getId() const { return id; } int getId() const { return id; }
const TString& getSymbol() const { return symbol; } const TString& getSymbol() const { return symbol; }
void setId(int newId) { id = newId; }
void setSymbol(const TString& sym) { symbol = sym; }
const TString& getOriginalSymbol() const { return originalSymbol; }
virtual void traverse(TIntermTraverser*); virtual void traverse(TIntermTraverser*);
virtual TIntermSymbol* getAsSymbolNode() { return this; } virtual TIntermSymbol* getAsSymbolNode() { return this; }
protected: protected:
int id; int id;
TString symbol; TString symbol;
TString originalSymbol;
}; };
class TIntermConstantUnion : public TIntermTyped { class TIntermConstantUnion : public TIntermTyped {
......
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