Commit c022c3af by alokp@chromium.org

WebGL spec specifies maximum length of all types of tokens - not just identifier…

WebGL spec specifies maximum length of all types of tokens - not just identifier tokens. And it also means preprocessing-tokens, not compiler tokens. Note that this implies that non-compliant tokens even inside excluded #if blocks will trigger error. TODO: This behavior should be implemented as a preprocessor option, so that a GLES2 compiler can choose to disable it. Review URL: https://codereview.appspot.com/6355066 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1193 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 08b3e40f
...@@ -52,8 +52,8 @@ std::string Diagnostics::message(ID id) ...@@ -52,8 +52,8 @@ std::string Diagnostics::message(ID id)
return "integer overflow"; return "integer overflow";
case FLOAT_OVERFLOW: case FLOAT_OVERFLOW:
return "float overflow"; return "float overflow";
case IDENTIFIER_OVERFLOW: case TOKEN_TOO_LONG:
return "identifier buffer overflow"; return "token too long";
case INVALID_EXPRESSION: case INVALID_EXPRESSION:
return "invalid expression"; return "invalid expression";
case DIVISION_BY_ZERO: case DIVISION_BY_ZERO:
......
...@@ -33,7 +33,7 @@ class Diagnostics ...@@ -33,7 +33,7 @@ class Diagnostics
INVALID_NUMBER, INVALID_NUMBER,
INTEGER_OVERFLOW, INTEGER_OVERFLOW,
FLOAT_OVERFLOW, FLOAT_OVERFLOW,
IDENTIFIER_OVERFLOW, TOKEN_TOO_LONG,
INVALID_EXPRESSION, INVALID_EXPRESSION,
DIVISION_BY_ZERO, DIVISION_BY_ZERO,
EOF_IN_COMMENT, EOF_IN_COMMENT,
......
...@@ -347,12 +347,6 @@ void DirectiveParser::parseDefine(Token* token) ...@@ -347,12 +347,6 @@ void DirectiveParser::parseDefine(Token* token)
token->location, token->text); token->location, token->text);
return; return;
} }
if (token->text.size() > Token::kMaxIdentifierLength)
{
mDiagnostics->report(Diagnostics::IDENTIFIER_OVERFLOW,
token->location, token->text);
return;
}
Macro macro; Macro macro;
macro.type = Macro::kTypeObj; macro.type = Macro::kTypeObj;
......
...@@ -123,19 +123,6 @@ void Preprocessor::lex(Token* token) ...@@ -123,19 +123,6 @@ void Preprocessor::lex(Token* token)
validToken = true; validToken = true;
break; break;
} }
case Token::IDENTIFIER:
{
if (token->text.size() > Token::kMaxIdentifierLength)
{
// Do not mark the token as invalid.
// Just emit the diagnostic and clamp string length.
mImpl->diagnostics->report(Diagnostics::IDENTIFIER_OVERFLOW,
token->location, token->text);
token->text.erase(Token::kMaxIdentifierLength);
}
validToken = true;
break;
}
case Token::PP_NUMBER: case Token::PP_NUMBER:
mImpl->diagnostics->report(Diagnostics::INVALID_NUMBER, mImpl->diagnostics->report(Diagnostics::INVALID_NUMBER,
token->location, token->text); token->location, token->text);
......
...@@ -31,10 +31,6 @@ static bool atoi_t(const std::string& str, IntType* value) ...@@ -31,10 +31,6 @@ static bool atoi_t(const std::string& str, IntType* value)
namespace pp namespace pp
{ {
// TODO(alokp): This should be specified by preprocessor client,
// i.e., the compiler.
const size_t Token::kMaxIdentifierLength = 256;
void Token::reset() void Token::reset()
{ {
type = 0; type = 0;
......
...@@ -61,7 +61,6 @@ struct Token ...@@ -61,7 +61,6 @@ struct Token
HAS_LEADING_SPACE = 1 << 1, HAS_LEADING_SPACE = 1 << 1,
EXPANSION_DISABLED = 1 << 2 EXPANSION_DISABLED = 1 << 2
}; };
static const size_t kMaxIdentifierLength;
Token() : type(0), flags(0) { } Token() : type(0), flags(0) { }
......
...@@ -2280,6 +2280,10 @@ void ppfree (void * ptr , yyscan_t yyscanner) ...@@ -2280,6 +2280,10 @@ void ppfree (void * ptr , yyscan_t yyscanner)
namespace pp { namespace pp {
// TODO(alokp): Maximum token length should ideally be specified by
// the preprocessor client, i.e., the compiler.
const size_t Tokenizer::kMaxTokenLength = 256;
Tokenizer::Tokenizer(Diagnostics* diagnostics) : mHandle(0) Tokenizer::Tokenizer(Diagnostics* diagnostics) : mHandle(0)
{ {
mContext.diagnostics = diagnostics; mContext.diagnostics = diagnostics;
...@@ -2314,6 +2318,13 @@ void Tokenizer::setLineNumber(int line) ...@@ -2314,6 +2318,13 @@ void Tokenizer::setLineNumber(int line)
void Tokenizer::lex(Token* token) void Tokenizer::lex(Token* token)
{ {
token->type = pplex(&token->text,&token->location,mHandle); token->type = pplex(&token->text,&token->location,mHandle);
if (token->text.size() > kMaxTokenLength)
{
mContext.diagnostics->report(Diagnostics::TOKEN_TOO_LONG,
token->location, token->text);
token->text.erase(kMaxTokenLength);
}
token->flags = 0; token->flags = 0;
token->setAtStartOfLine(mContext.lineStart); token->setAtStartOfLine(mContext.lineStart);
......
...@@ -32,6 +32,7 @@ class Tokenizer : public Lexer ...@@ -32,6 +32,7 @@ class Tokenizer : public Lexer
bool leadingSpace; bool leadingSpace;
bool lineStart; bool lineStart;
}; };
static const size_t kMaxTokenLength;
Tokenizer(Diagnostics* diagnostics); Tokenizer(Diagnostics* diagnostics);
~Tokenizer(); ~Tokenizer();
......
...@@ -264,6 +264,10 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -264,6 +264,10 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
namespace pp { namespace pp {
// TODO(alokp): Maximum token length should ideally be specified by
// the preprocessor client, i.e., the compiler.
const size_t Tokenizer::kMaxTokenLength = 256;
Tokenizer::Tokenizer(Diagnostics* diagnostics) : mHandle(0) Tokenizer::Tokenizer(Diagnostics* diagnostics) : mHandle(0)
{ {
mContext.diagnostics = diagnostics; mContext.diagnostics = diagnostics;
...@@ -298,6 +302,13 @@ void Tokenizer::setLineNumber(int line) ...@@ -298,6 +302,13 @@ void Tokenizer::setLineNumber(int line)
void Tokenizer::lex(Token* token) void Tokenizer::lex(Token* token)
{ {
token->type = yylex(&token->text, &token->location, mHandle); token->type = yylex(&token->text, &token->location, mHandle);
if (token->text.size() > kMaxTokenLength)
{
mContext.diagnostics->report(Diagnostics::TOKEN_TOO_LONG,
token->location, token->text);
token->text.erase(kMaxTokenLength);
}
token->flags = 0; token->flags = 0;
token->setAtStartOfLine(mContext.lineStart); token->setAtStartOfLine(mContext.lineStart);
......
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