Commit 8e77853d by kbr@chromium.org

Fixed 64-bit integer truncation issues in shader translator.

This is an incompatible API change, but one which is necessary in order to improve correctness of the code. The API version in ShaderLang.h is updated and, unfortunately, the define renamed to something less ambiguous due to conflicts on some Android buildbots. Temporary patches in Chromium and WebKit will be landed separately to support this upgrade. BUG=403,404,405,406,407,408,409 Review URL: https://codereview.appspot.com/7300058 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1826 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d64a53fe
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#endif #endif
#include "KHR/khrplatform.h" #include "KHR/khrplatform.h"
#include <stddef.h>
// //
// This is the platform independent interface between an OGL driver // This is the platform independent interface between an OGL driver
...@@ -36,7 +37,7 @@ extern "C" { ...@@ -36,7 +37,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 107 #define ANGLE_SH_VERSION 108
// //
// 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
...@@ -184,7 +185,7 @@ COMPILER_EXPORT int ShFinalize(); ...@@ -184,7 +185,7 @@ COMPILER_EXPORT int ShFinalize();
// The 64 bits hash function. The first parameter is the input string; the // The 64 bits hash function. The first parameter is the input string; the
// second parameter is the string length. // second parameter is the string length.
typedef khronos_uint64_t (*ShHashFunction64)(const char*, unsigned int); typedef khronos_uint64_t (*ShHashFunction64)(const char*, size_t);
// //
// Implementation dependent built-in resources (constants and extensions). // Implementation dependent built-in resources (constants and extensions).
...@@ -279,7 +280,7 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle); ...@@ -279,7 +280,7 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle);
COMPILER_EXPORT int ShCompile( COMPILER_EXPORT int ShCompile(
const ShHandle handle, const ShHandle handle,
const char* const shaderStrings[], const char* const shaderStrings[],
const int numStrings, size_t numStrings,
int compileOptions int compileOptions
); );
...@@ -307,11 +308,11 @@ COMPILER_EXPORT int ShCompile( ...@@ -307,11 +308,11 @@ COMPILER_EXPORT int ShCompile(
// SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the // SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the
// null termination character. // null termination character.
// SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile. // SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile.
// //
// params: Requested parameter // params: Requested parameter
COMPILER_EXPORT void ShGetInfo(const ShHandle handle, COMPILER_EXPORT void ShGetInfo(const ShHandle handle,
ShShaderInfo pname, ShShaderInfo pname,
int* params); size_t* params);
// Returns nul-terminated information log for a compiled shader. // Returns nul-terminated information log for a compiled shader.
// Parameters: // Parameters:
...@@ -354,7 +355,7 @@ COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode); ...@@ -354,7 +355,7 @@ COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
// mappedName are the same. // mappedName are the same.
COMPILER_EXPORT void ShGetActiveAttrib(const ShHandle handle, COMPILER_EXPORT void ShGetActiveAttrib(const ShHandle handle,
int index, int index,
int* length, size_t* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name, char* name,
...@@ -381,7 +382,7 @@ COMPILER_EXPORT void ShGetActiveAttrib(const ShHandle handle, ...@@ -381,7 +382,7 @@ COMPILER_EXPORT void ShGetActiveAttrib(const ShHandle handle,
// mappedName are the same. // mappedName are the same.
COMPILER_EXPORT void ShGetActiveUniform(const ShHandle handle, COMPILER_EXPORT void ShGetActiveUniform(const ShHandle handle,
int index, int index,
int* length, size_t* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name, char* name,
......
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1825 #define BUILD_REVISION 1826
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -135,7 +135,7 @@ bool TCompiler::Init(const ShBuiltInResources& resources) ...@@ -135,7 +135,7 @@ bool TCompiler::Init(const ShBuiltInResources& resources)
} }
bool TCompiler::compile(const char* const shaderStrings[], bool TCompiler::compile(const char* const shaderStrings[],
const int numStrings, size_t numStrings,
int compileOptions) int compileOptions)
{ {
TScopedPoolAllocator scopedAlloc(&allocator, true); TScopedPoolAllocator scopedAlloc(&allocator, true);
...@@ -150,7 +150,7 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -150,7 +150,7 @@ bool TCompiler::compile(const char* const shaderStrings[],
// First string is path of source file if flag is set. The actual source follows. // First string is path of source file if flag is set. The actual source follows.
const char* sourcePath = NULL; const char* sourcePath = NULL;
int firstSource = 0; size_t firstSource = 0;
if (compileOptions & SH_SOURCE_PATH) if (compileOptions & SH_SOURCE_PATH)
{ {
sourcePath = shaderStrings[0]; sourcePath = shaderStrings[0];
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace { namespace {
TString mapLongName(int id, const TString& name, bool isGlobal) TString mapLongName(size_t id, const TString& name, bool isGlobal)
{ {
ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE); ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE);
TStringStream stream; TStringStream stream;
...@@ -70,7 +70,7 @@ void LongNameMap::Insert(const char* originalName, const char* mappedName) ...@@ -70,7 +70,7 @@ void LongNameMap::Insert(const char* originalName, const char* mappedName)
originalName, mappedName)); originalName, mappedName));
} }
int LongNameMap::Size() const size_t LongNameMap::Size() const
{ {
return mLongNameMap.size(); return mLongNameMap.size();
} }
...@@ -115,7 +115,7 @@ TString MapLongVariableNames::mapGlobalLongName(const TString& name) ...@@ -115,7 +115,7 @@ TString MapLongVariableNames::mapGlobalLongName(const TString& name)
const char* mappedName = mGlobalMap->Find(name.c_str()); const char* mappedName = mGlobalMap->Find(name.c_str());
if (mappedName != NULL) if (mappedName != NULL)
return mappedName; return mappedName;
int id = mGlobalMap->Size(); size_t id = mGlobalMap->Size();
TString rt = mapLongName(id, name, true); TString rt = mapLongName(id, name, true);
mGlobalMap->Insert(name.c_str(), rt.c_str()); mGlobalMap->Insert(name.c_str(), rt.c_str());
return rt; return rt;
......
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
void Insert(const char* originalName, const char* mappedName); void Insert(const char* originalName, const char* mappedName);
// Return the number of entries in the map. // Return the number of entries in the map.
int Size() const; size_t Size() const;
private: private:
LongNameMap(); LongNameMap();
......
...@@ -493,7 +493,7 @@ bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction ...@@ -493,7 +493,7 @@ bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction
bool overFull = false; bool overFull = false;
bool matrixInMatrix = false; bool matrixInMatrix = false;
bool arrayArg = false; bool arrayArg = false;
for (int i = 0; i < function.getParamCount(); ++i) { for (size_t i = 0; i < function.getParamCount(); ++i) {
const TParameter& param = function.getParam(i); const TParameter& param = function.getParam(i);
size += param.type->getObjectSize(); size += param.type->getObjectSize();
...@@ -1507,7 +1507,7 @@ bool TParseContext::structNestingErrorCheck(TSourceLoc line, const TType& fieldT ...@@ -1507,7 +1507,7 @@ bool TParseContext::structNestingErrorCheck(TSourceLoc line, const TType& fieldT
// //
// Returns 0 for success. // Returns 0 for success.
// //
int PaParseStrings(int count, const char* const string[], const int length[], int PaParseStrings(size_t count, const char* const string[], const int length[],
TParseContext* context) { TParseContext* context) {
if ((count == 0) || (string == NULL)) if ((count == 0) || (string == NULL))
return 1; return 1;
......
...@@ -134,7 +134,7 @@ struct TParseContext { ...@@ -134,7 +134,7 @@ struct TParseContext {
bool structNestingErrorCheck(TSourceLoc line, const TType& fieldType); bool structNestingErrorCheck(TSourceLoc line, const TType& fieldType);
}; };
int PaParseStrings(int count, const char* const string[], const int length[], int PaParseStrings(size_t count, const char* const string[], const int length[],
TParseContext* context); TParseContext* context);
#endif // _PARSER_HELPER_INCLUDED_ #endif // _PARSER_HELPER_INCLUDED_
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
bool Init(const ShBuiltInResources& resources); bool Init(const ShBuiltInResources& resources);
bool compile(const char* const shaderStrings[], bool compile(const char* const shaderStrings[],
const int numStrings, size_t numStrings,
int compileOptions); int compileOptions);
// Get results of the last compilation. // Get results of the last compilation.
......
...@@ -21,18 +21,18 @@ ...@@ -21,18 +21,18 @@
// //
static bool checkActiveUniformAndAttribMaxLengths(const ShHandle handle, static bool checkActiveUniformAndAttribMaxLengths(const ShHandle handle,
int expectedValue) size_t expectedValue)
{ {
int activeUniformLimit = 0; size_t activeUniformLimit = 0;
ShGetInfo(handle, SH_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformLimit); ShGetInfo(handle, SH_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformLimit);
int activeAttribLimit = 0; size_t activeAttribLimit = 0;
ShGetInfo(handle, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttribLimit); ShGetInfo(handle, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttribLimit);
return (expectedValue == activeUniformLimit && expectedValue == activeAttribLimit); return (expectedValue == activeUniformLimit && expectedValue == activeAttribLimit);
} }
static bool checkMappedNameMaxLength(const ShHandle handle, int expectedValue) static bool checkMappedNameMaxLength(const ShHandle handle, size_t expectedValue)
{ {
int mappedNameMaxLength = 0; size_t mappedNameMaxLength = 0;
ShGetInfo(handle, SH_MAPPED_NAME_MAX_LENGTH, &mappedNameMaxLength); ShGetInfo(handle, SH_MAPPED_NAME_MAX_LENGTH, &mappedNameMaxLength);
return (expectedValue == mappedNameMaxLength); return (expectedValue == mappedNameMaxLength);
} }
...@@ -40,7 +40,7 @@ static bool checkMappedNameMaxLength(const ShHandle handle, int expectedValue) ...@@ -40,7 +40,7 @@ static bool checkMappedNameMaxLength(const ShHandle handle, int expectedValue)
static void getVariableInfo(ShShaderInfo varType, static void getVariableInfo(ShShaderInfo varType,
const ShHandle handle, const ShHandle handle,
int index, int index,
int* length, size_t* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name, char* name,
...@@ -69,14 +69,14 @@ static void getVariableInfo(ShShaderInfo varType, ...@@ -69,14 +69,14 @@ static void getVariableInfo(ShShaderInfo varType,
// This size must match that queried by // This size must match that queried by
// SH_ACTIVE_UNIFORM_MAX_LENGTH and SH_ACTIVE_ATTRIBUTE_MAX_LENGTH // SH_ACTIVE_UNIFORM_MAX_LENGTH and SH_ACTIVE_ATTRIBUTE_MAX_LENGTH
// in ShGetInfo, below. // in ShGetInfo, below.
int activeUniformAndAttribLength = 1 + MAX_SYMBOL_NAME_LEN; size_t activeUniformAndAttribLength = 1 + MAX_SYMBOL_NAME_LEN;
ASSERT(checkActiveUniformAndAttribMaxLengths(handle, activeUniformAndAttribLength)); ASSERT(checkActiveUniformAndAttribMaxLengths(handle, activeUniformAndAttribLength));
strncpy(name, varInfo.name.c_str(), activeUniformAndAttribLength); strncpy(name, varInfo.name.c_str(), activeUniformAndAttribLength);
name[activeUniformAndAttribLength - 1] = 0; name[activeUniformAndAttribLength - 1] = 0;
if (mappedName) { if (mappedName) {
// This size must match that queried by // This size must match that queried by
// SH_MAPPED_NAME_MAX_LENGTH in ShGetInfo, below. // SH_MAPPED_NAME_MAX_LENGTH in ShGetInfo, below.
int maxMappedNameLength = 1 + MAX_SYMBOL_NAME_LEN; size_t maxMappedNameLength = 1 + MAX_SYMBOL_NAME_LEN;
ASSERT(checkMappedNameMaxLength(handle, maxMappedNameLength)); ASSERT(checkMappedNameMaxLength(handle, maxMappedNameLength));
strncpy(mappedName, varInfo.mappedName.c_str(), maxMappedNameLength); strncpy(mappedName, varInfo.mappedName.c_str(), maxMappedNameLength);
mappedName[maxMappedNameLength - 1] = 0; mappedName[maxMappedNameLength - 1] = 0;
...@@ -177,7 +177,7 @@ void ShDestruct(ShHandle handle) ...@@ -177,7 +177,7 @@ void ShDestruct(ShHandle handle)
int ShCompile( int ShCompile(
const ShHandle handle, const ShHandle handle,
const char* const shaderStrings[], const char* const shaderStrings[],
const int numStrings, size_t numStrings,
int compileOptions) int compileOptions)
{ {
if (!InitThread()) if (!InitThread())
...@@ -195,7 +195,7 @@ int ShCompile( ...@@ -195,7 +195,7 @@ int ShCompile(
return success ? 1 : 0; return success ? 1 : 0;
} }
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params) void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params)
{ {
if (!handle || !params) if (!handle || !params)
return; return;
...@@ -283,7 +283,7 @@ void ShGetObjectCode(const ShHandle handle, char* objCode) ...@@ -283,7 +283,7 @@ void ShGetObjectCode(const ShHandle handle, char* objCode)
void ShGetActiveAttrib(const ShHandle handle, void ShGetActiveAttrib(const ShHandle handle,
int index, int index,
int* length, size_t* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name, char* name,
...@@ -295,7 +295,7 @@ void ShGetActiveAttrib(const ShHandle handle, ...@@ -295,7 +295,7 @@ void ShGetActiveAttrib(const ShHandle handle,
void ShGetActiveUniform(const ShHandle handle, void ShGetActiveUniform(const ShHandle handle,
int index, int index,
int* length, size_t* length,
int* size, int* size,
ShDataType* type, ShDataType* type,
char* name, char* name,
...@@ -326,9 +326,9 @@ void ShGetNameHashingEntry(const ShHandle handle, ...@@ -326,9 +326,9 @@ void ShGetNameHashingEntry(const ShHandle handle,
++it; ++it;
size_t len = it->first.length() + 1; size_t len = it->first.length() + 1;
int max_len = 0; size_t max_len = 0;
ShGetInfo(handle, SH_NAME_MAX_LENGTH, &max_len); ShGetInfo(handle, SH_NAME_MAX_LENGTH, &max_len);
if (static_cast<int>(len) > max_len) { if (len > max_len) {
ASSERT(false); ASSERT(false);
len = max_len; len = max_len;
} }
...@@ -339,7 +339,7 @@ void ShGetNameHashingEntry(const ShHandle handle, ...@@ -339,7 +339,7 @@ void ShGetNameHashingEntry(const ShHandle handle,
len = it->second.length() + 1; len = it->second.length() + 1;
max_len = 0; max_len = 0;
ShGetInfo(handle, SH_HASHED_NAME_MAX_LENGTH, &max_len); ShGetInfo(handle, SH_HASHED_NAME_MAX_LENGTH, &max_len);
if (static_cast<int>(len) > max_len) { if (len > max_len) {
ASSERT(false); ASSERT(false);
len = max_len; len = max_len;
} }
......
...@@ -169,8 +169,8 @@ public: ...@@ -169,8 +169,8 @@ public:
void setDefined() { defined = true; } void setDefined() { defined = true; }
bool isDefined() { return defined; } bool isDefined() { return defined; }
int getParamCount() const { return static_cast<int>(parameters.size()); } size_t getParamCount() const { return parameters.size(); }
const TParameter& getParam(int i) const { return parameters[i]; } const TParameter& getParam(size_t i) const { return parameters[i]; }
virtual void dump(TInfoSink &infoSink) const; virtual void dump(TInfoSink &infoSink) const;
TFunction(const TFunction&, TStructureMap& remapper); TFunction(const TFunction&, TStructureMap& remapper);
......
...@@ -421,7 +421,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node) ...@@ -421,7 +421,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node)
return true; return true;
// List of param indices for which loop indices are used as argument. // List of param indices for which loop indices are used as argument.
typedef std::vector<int> ParamIndex; typedef std::vector<size_t> ParamIndex;
ParamIndex pIndex; ParamIndex pIndex;
TIntermSequence& params = node->getSequence(); TIntermSequence& params = node->getSequence();
for (TIntermSequence::size_type i = 0; i < params.size(); ++i) { for (TIntermSequence::size_type i = 0; i < params.size(); ++i) {
......
...@@ -8,7 +8,7 @@ struct TParseContext; ...@@ -8,7 +8,7 @@ struct TParseContext;
extern int glslang_initialize(TParseContext* context); extern int glslang_initialize(TParseContext* context);
extern int glslang_finalize(TParseContext* context); extern int glslang_finalize(TParseContext* context);
extern int glslang_scan(int count, extern int glslang_scan(size_t count,
const char* const string[], const char* const string[],
const int length[], const int length[],
TParseContext* context); TParseContext* context);
......
...@@ -51,7 +51,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp). ...@@ -51,7 +51,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#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);
static int string_input(char* buf, int max_size, yyscan_t yyscanner); static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner);
static int check_type(yyscan_t yyscanner); static int check_type(yyscan_t yyscanner);
static int reserved_word(yyscan_t yyscanner); static int reserved_word(yyscan_t yyscanner);
%} %}
...@@ -203,10 +203,10 @@ O [0-7] ...@@ -203,10 +203,10 @@ O [0-7]
return check_type(yyscanner); return check_type(yyscanner);
} }
0[xX]{H}+ { yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); } 0[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
0{O}+ { yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); } 0{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
0{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;} 0{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
{D}+ { yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); } {D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); } {D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); } {D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
...@@ -272,11 +272,11 @@ O [0-7] ...@@ -272,11 +272,11 @@ O [0-7]
%% %%
int string_input(char* buf, int max_size, yyscan_t yyscanner) { yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
pp::Token token; pp::Token token;
yyget_extra(yyscanner)->preprocessor.lex(&token); yyget_extra(yyscanner)->preprocessor.lex(&token);
int 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 > 0) && (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_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
...@@ -341,7 +341,7 @@ int glslang_finalize(TParseContext* context) { ...@@ -341,7 +341,7 @@ int glslang_finalize(TParseContext* context) {
return 0; return 0;
} }
int glslang_scan(int 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_lineno(EncodeSourceLoc(0, 1), context->scanner);
......
...@@ -524,7 +524,7 @@ function_call ...@@ -524,7 +524,7 @@ function_call
$$->getAsAggregate()->setName(fnCandidate->getMangledName()); $$->getAsAggregate()->setName(fnCandidate->getMangledName());
TQualifier qual; TQualifier qual;
for (int i = 0; i < fnCandidate->getParamCount(); ++i) { for (size_t i = 0; i < fnCandidate->getParamCount(); ++i) {
qual = fnCandidate->getParam(i).type->getQualifier(); qual = fnCandidate->getParam(i).type->getQualifier();
if (qual == EvqOut || qual == EvqInOut) { if (qual == EvqOut || qual == EvqInOut) {
if (context->lValueErrorCheck($$->getLine(), "assign", $$->getAsAggregate()->getSequence()[i]->getAsTyped())) { if (context->lValueErrorCheck($$->getLine(), "assign", $$->getAsAggregate()->getSequence()[i]->getAsTyped())) {
...@@ -965,7 +965,7 @@ declaration ...@@ -965,7 +965,7 @@ declaration
prototype->setType(function.getReturnType()); prototype->setType(function.getReturnType());
prototype->setName(function.getName()); prototype->setName(function.getName());
for (int i = 0; i < function.getParamCount(); i++) for (size_t i = 0; i < function.getParamCount(); i++)
{ {
const TParameter &param = function.getParam(i); const TParameter &param = function.getParam(i);
if (param.name != 0) if (param.name != 0)
...@@ -1015,7 +1015,7 @@ function_prototype ...@@ -1015,7 +1015,7 @@ function_prototype
context->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString()); context->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString());
context->recover(); context->recover();
} }
for (int i = 0; i < prevDec->getParamCount(); ++i) { for (size_t i = 0; i < prevDec->getParamCount(); ++i) {
if (prevDec->getParam(i).type->getQualifier() != $1->getParam(i).type->getQualifier()) { if (prevDec->getParam(i).type->getQualifier() != $1->getParam(i).type->getQualifier()) {
context->error($2.line, "overloaded functions must have the same parameter qualifiers", $1->getParam(i).type->getQualifierString()); context->error($2.line, "overloaded functions must have the same parameter qualifiers", $1->getParam(i).type->getQualifierString());
context->recover(); context->recover();
...@@ -2085,7 +2085,7 @@ function_definition ...@@ -2085,7 +2085,7 @@ function_definition
// knows where to find parameters. // knows where to find parameters.
// //
TIntermAggregate* paramNodes = new TIntermAggregate; TIntermAggregate* paramNodes = new TIntermAggregate;
for (int i = 0; i < function->getParamCount(); i++) { for (size_t i = 0; i < function->getParamCount(); i++) {
const TParameter& param = function->getParam(i); const TParameter& param = function->getParam(i);
if (param.name != 0) { if (param.name != 0) {
TVariable *variable = new TVariable(param.name, *param.type); TVariable *variable = new TVariable(param.name, *param.type);
......
...@@ -821,7 +821,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp). ...@@ -821,7 +821,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#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);
static int string_input(char* buf, int max_size, yyscan_t yyscanner); static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner);
static int check_type(yyscan_t yyscanner); static int check_type(yyscan_t yyscanner);
static int reserved_word(yyscan_t yyscanner); static int reserved_word(yyscan_t yyscanner);
...@@ -1543,11 +1543,11 @@ YY_RULE_SETUP ...@@ -1543,11 +1543,11 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 99: case 99:
YY_RULE_SETUP YY_RULE_SETUP
{ yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); } { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
YY_BREAK YY_BREAK
case 100: case 100:
YY_RULE_SETUP YY_RULE_SETUP
{ yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); } { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
YY_BREAK YY_BREAK
case 101: case 101:
YY_RULE_SETUP YY_RULE_SETUP
...@@ -1555,7 +1555,7 @@ YY_RULE_SETUP ...@@ -1555,7 +1555,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 102: case 102:
YY_RULE_SETUP YY_RULE_SETUP
{ yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); } { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
YY_BREAK YY_BREAK
case 103: case 103:
YY_RULE_SETUP YY_RULE_SETUP
...@@ -2948,13 +2948,13 @@ void yyfree (void * ptr , yyscan_t yyscanner) ...@@ -2948,13 +2948,13 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
int string_input(char* buf, int max_size, yyscan_t yyscanner) { yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
pp::Token token; pp::Token token;
yyget_extra(yyscanner)->preprocessor.lex(&token); yyget_extra(yyscanner)->preprocessor.lex(&token);
int 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 > 0) && (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_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
if (len >= max_size) if (len >= max_size)
YY_FATAL_ERROR("Input buffer overflow"); YY_FATAL_ERROR("Input buffer overflow");
...@@ -3017,7 +3017,7 @@ int glslang_finalize(TParseContext* context) { ...@@ -3017,7 +3017,7 @@ int glslang_finalize(TParseContext* context) {
return 0; return 0;
} }
int glslang_scan(int 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_lineno(EncodeSourceLoc(0, 1),context->scanner);
......
...@@ -2468,7 +2468,7 @@ yyreduce: ...@@ -2468,7 +2468,7 @@ yyreduce:
(yyval.interm.intermTypedNode)->getAsAggregate()->setName(fnCandidate->getMangledName()); (yyval.interm.intermTypedNode)->getAsAggregate()->setName(fnCandidate->getMangledName());
TQualifier qual; TQualifier qual;
for (int i = 0; i < fnCandidate->getParamCount(); ++i) { for (size_t i = 0; i < fnCandidate->getParamCount(); ++i) {
qual = fnCandidate->getParam(i).type->getQualifier(); qual = fnCandidate->getParam(i).type->getQualifier();
if (qual == EvqOut || qual == EvqInOut) { if (qual == EvqOut || qual == EvqInOut) {
if (context->lValueErrorCheck((yyval.interm.intermTypedNode)->getLine(), "assign", (yyval.interm.intermTypedNode)->getAsAggregate()->getSequence()[i]->getAsTyped())) { if (context->lValueErrorCheck((yyval.interm.intermTypedNode)->getLine(), "assign", (yyval.interm.intermTypedNode)->getAsAggregate()->getSequence()[i]->getAsTyped())) {
...@@ -3054,7 +3054,7 @@ yyreduce: ...@@ -3054,7 +3054,7 @@ yyreduce:
prototype->setType(function.getReturnType()); prototype->setType(function.getReturnType());
prototype->setName(function.getName()); prototype->setName(function.getName());
for (int i = 0; i < function.getParamCount(); i++) for (size_t i = 0; i < function.getParamCount(); i++)
{ {
const TParameter &param = function.getParam(i); const TParameter &param = function.getParam(i);
if (param.name != 0) if (param.name != 0)
...@@ -3113,7 +3113,7 @@ yyreduce: ...@@ -3113,7 +3113,7 @@ yyreduce:
context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString()); context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString());
context->recover(); context->recover();
} }
for (int i = 0; i < prevDec->getParamCount(); ++i) { for (size_t i = 0; i < prevDec->getParamCount(); ++i) {
if (prevDec->getParam(i).type->getQualifier() != (yyvsp[(1) - (2)].interm.function)->getParam(i).type->getQualifier()) { if (prevDec->getParam(i).type->getQualifier() != (yyvsp[(1) - (2)].interm.function)->getParam(i).type->getQualifier()) {
context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same parameter qualifiers", (yyvsp[(1) - (2)].interm.function)->getParam(i).type->getQualifierString()); context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same parameter qualifiers", (yyvsp[(1) - (2)].interm.function)->getParam(i).type->getQualifierString());
context->recover(); context->recover();
......
...@@ -17,25 +17,24 @@ Input::Input() : mCount(0), mString(0) ...@@ -17,25 +17,24 @@ Input::Input() : mCount(0), mString(0)
{ {
} }
Input::Input(int count, const char* const string[], const int length[]) : Input::Input(size_t count, const char* const string[], const int length[]) :
mCount(count), mCount(count),
mString(string) mString(string)
{ {
assert(mCount >= 0);
mLength.reserve(mCount); mLength.reserve(mCount);
for (int i = 0; i < mCount; ++i) for (size_t i = 0; i < mCount; ++i)
{ {
int len = length ? length[i] : -1; int len = length ? length[i] : -1;
mLength.push_back(len < 0 ? std::strlen(mString[i]) : len); mLength.push_back(len < 0 ? std::strlen(mString[i]) : len);
} }
} }
int Input::read(char* buf, int maxSize) size_t Input::read(char* buf, size_t maxSize)
{ {
int nRead = 0; size_t nRead = 0;
while ((nRead < maxSize) && (mReadLoc.sIndex < mCount)) while ((nRead < maxSize) && (mReadLoc.sIndex < mCount))
{ {
int size = mLength[mReadLoc.sIndex] - mReadLoc.cIndex; size_t size = mLength[mReadLoc.sIndex] - mReadLoc.cIndex;
size = std::min(size, maxSize); size = std::min(size, maxSize);
std::memcpy(buf + nRead, mString[mReadLoc.sIndex] + mReadLoc.cIndex, size); std::memcpy(buf + nRead, mString[mReadLoc.sIndex] + mReadLoc.cIndex, size);
nRead += size; nRead += size;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#ifndef COMPILER_PREPROCESSOR_INPUT_H_ #ifndef COMPILER_PREPROCESSOR_INPUT_H_
#define COMPILER_PREPROCESSOR_INPUT_H_ #define COMPILER_PREPROCESSOR_INPUT_H_
#include <stddef.h>
#include <vector> #include <vector>
namespace pp namespace pp
...@@ -17,18 +18,18 @@ class Input ...@@ -17,18 +18,18 @@ class Input
{ {
public: public:
Input(); Input();
Input(int count, const char* const string[], const int length[]); Input(size_t count, const char* const string[], const int length[]);
int count() const { return mCount; } size_t count() const { return mCount; }
const char* string(int index) const { return mString[index]; } const char* string(size_t index) const { return mString[index]; }
int length(int index) const { return mLength[index]; } size_t length(size_t index) const { return mLength[index]; }
int read(char* buf, int maxSize); size_t read(char* buf, size_t maxSize);
struct Location struct Location
{ {
int sIndex; // String index; size_t sIndex; // String index;
int cIndex; // Char index. size_t cIndex; // Char index.
Location() : sIndex(0), cIndex(0) { } Location() : sIndex(0), cIndex(0) { }
}; };
...@@ -36,9 +37,9 @@ class Input ...@@ -36,9 +37,9 @@ class Input
private: private:
// Input. // Input.
int mCount; size_t mCount;
const char* const* mString; const char* const* mString;
std::vector<int> mLength; std::vector<size_t> mLength;
Location mReadLoc; Location mReadLoc;
}; };
......
...@@ -48,7 +48,7 @@ Preprocessor::~Preprocessor() ...@@ -48,7 +48,7 @@ Preprocessor::~Preprocessor()
delete mImpl; delete mImpl;
} }
bool Preprocessor::init(int count, bool Preprocessor::init(size_t count,
const char* const string[], const char* const string[],
const int length[]) const int length[])
{ {
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#ifndef COMPILER_PREPROCESSOR_PREPROCESSOR_H_ #ifndef COMPILER_PREPROCESSOR_PREPROCESSOR_H_
#define COMPILER_PREPROCESSOR_PREPROCESSOR_H_ #define COMPILER_PREPROCESSOR_PREPROCESSOR_H_
#include <stddef.h>
#include "pp_utils.h" #include "pp_utils.h"
namespace pp namespace pp
...@@ -32,7 +34,7 @@ class Preprocessor ...@@ -32,7 +34,7 @@ class Preprocessor
// Each element in the length array may contain the length of the // Each element in the length array may contain the length of the
// corresponding string or a value less than 0 to indicate that the string // corresponding string or a value less than 0 to indicate that the string
// is null terminated. // is null terminated.
bool init(int count, const char* const string[], const int length[]); bool init(size_t count, const char* const string[], const int length[]);
// Adds a pre-defined macro. // Adds a pre-defined macro.
void predefineMacro(const char* name, int value); void predefineMacro(const char* name, int value);
......
...@@ -1119,13 +1119,14 @@ case YY_STATE_EOF(COMMENT): ...@@ -1119,13 +1119,14 @@ case YY_STATE_EOF(COMMENT):
// Set the location for EOF token manually. // Set the location for EOF token manually.
pp::Input* input = &yyextra->input; pp::Input* input = &yyextra->input;
pp::Input::Location* scanLoc = &yyextra->scanLoc; pp::Input::Location* scanLoc = &yyextra->scanLoc;
int sIndexMax = std::max(0, input->count() - 1); yy_size_t sIndexMax = input->count() ? input->count() - 1 : 0;
if (scanLoc->sIndex != sIndexMax) if (scanLoc->sIndex != sIndexMax)
{ {
// We can only reach here if there are empty strings at the // We can only reach here if there are empty strings at the
// end of the input. // end of the input.
scanLoc->sIndex = sIndexMax; scanLoc->cIndex = 0; scanLoc->sIndex = sIndexMax; scanLoc->cIndex = 0;
yyfileno = sIndexMax; yylineno = 1; // FIXME: this is not 64-bit clean.
yyfileno = static_cast<int>(sIndexMax); yylineno = 1;
} }
yylloc->file = yyfileno; yylloc->file = yyfileno;
yylloc->line = yylineno; yylloc->line = yylineno;
...@@ -2294,9 +2295,8 @@ Tokenizer::~Tokenizer() ...@@ -2294,9 +2295,8 @@ Tokenizer::~Tokenizer()
destroyScanner(); destroyScanner();
} }
bool Tokenizer::init(int count, const char* const string[], const int length[]) bool Tokenizer::init(size_t count, const char* const string[], const int length[])
{ {
if (count < 0) return false;
if ((count > 0) && (string == 0)) return false; if ((count > 0) && (string == 0)) return false;
mContext.input = Input(count, string, length); mContext.input = Input(count, string, length);
......
...@@ -37,7 +37,7 @@ class Tokenizer : public Lexer ...@@ -37,7 +37,7 @@ class Tokenizer : public Lexer
Tokenizer(Diagnostics* diagnostics); Tokenizer(Diagnostics* diagnostics);
~Tokenizer(); ~Tokenizer();
bool init(int count, const char* const string[], const int length[]); bool init(size_t count, const char* const string[], const int length[]);
void setFileNumber(int file); void setFileNumber(int file);
void setLineNumber(int line); void setLineNumber(int line);
......
...@@ -239,13 +239,14 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -239,13 +239,14 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
// Set the location for EOF token manually. // Set the location for EOF token manually.
pp::Input* input = &yyextra->input; pp::Input* input = &yyextra->input;
pp::Input::Location* scanLoc = &yyextra->scanLoc; pp::Input::Location* scanLoc = &yyextra->scanLoc;
int sIndexMax = std::max(0, input->count() - 1); yy_size_t sIndexMax = input->count() ? input->count() - 1 : 0;
if (scanLoc->sIndex != sIndexMax) if (scanLoc->sIndex != sIndexMax)
{ {
// We can only reach here if there are empty strings at the // We can only reach here if there are empty strings at the
// end of the input. // end of the input.
scanLoc->sIndex = sIndexMax; scanLoc->cIndex = 0; scanLoc->sIndex = sIndexMax; scanLoc->cIndex = 0;
yyfileno = sIndexMax; yylineno = 1; // FIXME: this is not 64-bit clean.
yyfileno = static_cast<int>(sIndexMax); yylineno = 1;
} }
yylloc->file = yyfileno; yylloc->file = yyfileno;
yylloc->line = yylineno; yylloc->line = yylineno;
......
...@@ -351,14 +351,14 @@ void Shader::compileToHLSL(void *compiler) ...@@ -351,14 +351,14 @@ void Shader::compileToHLSL(void *compiler)
if (result) if (result)
{ {
int objCodeLen = 0; size_t objCodeLen = 0;
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen); ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen);
mHlsl = new char[objCodeLen]; mHlsl = new char[objCodeLen];
ShGetObjectCode(compiler, mHlsl); ShGetObjectCode(compiler, mHlsl);
} }
else else
{ {
int infoLogLen = 0; size_t infoLogLen = 0;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen); ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = new char[infoLogLen]; mInfoLog = new char[infoLogLen];
ShGetInfoLog(compiler, mInfoLog); ShGetInfoLog(compiler, mInfoLog);
......
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