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)
return "integer overflow";
case FLOAT_OVERFLOW:
return "float overflow";
case IDENTIFIER_OVERFLOW:
return "identifier buffer overflow";
case TOKEN_TOO_LONG:
return "token too long";
case INVALID_EXPRESSION:
return "invalid expression";
case DIVISION_BY_ZERO:
......
......@@ -33,7 +33,7 @@ class Diagnostics
INVALID_NUMBER,
INTEGER_OVERFLOW,
FLOAT_OVERFLOW,
IDENTIFIER_OVERFLOW,
TOKEN_TOO_LONG,
INVALID_EXPRESSION,
DIVISION_BY_ZERO,
EOF_IN_COMMENT,
......
......@@ -347,12 +347,6 @@ void DirectiveParser::parseDefine(Token* token)
token->location, token->text);
return;
}
if (token->text.size() > Token::kMaxIdentifierLength)
{
mDiagnostics->report(Diagnostics::IDENTIFIER_OVERFLOW,
token->location, token->text);
return;
}
Macro macro;
macro.type = Macro::kTypeObj;
......
......@@ -123,19 +123,6 @@ void Preprocessor::lex(Token* token)
validToken = true;
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:
mImpl->diagnostics->report(Diagnostics::INVALID_NUMBER,
token->location, token->text);
......
......@@ -31,10 +31,6 @@ static bool atoi_t(const std::string& str, IntType* value)
namespace pp
{
// TODO(alokp): This should be specified by preprocessor client,
// i.e., the compiler.
const size_t Token::kMaxIdentifierLength = 256;
void Token::reset()
{
type = 0;
......
......@@ -61,7 +61,6 @@ struct Token
HAS_LEADING_SPACE = 1 << 1,
EXPANSION_DISABLED = 1 << 2
};
static const size_t kMaxIdentifierLength;
Token() : type(0), flags(0) { }
......
......@@ -2280,6 +2280,10 @@ void ppfree (void * ptr , yyscan_t yyscanner)
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)
{
mContext.diagnostics = diagnostics;
......@@ -2314,6 +2318,13 @@ void Tokenizer::setLineNumber(int line)
void Tokenizer::lex(Token* token)
{
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->setAtStartOfLine(mContext.lineStart);
......
......@@ -32,6 +32,7 @@ class Tokenizer : public Lexer
bool leadingSpace;
bool lineStart;
};
static const size_t kMaxTokenLength;
Tokenizer(Diagnostics* diagnostics);
~Tokenizer();
......
......@@ -264,6 +264,10 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
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)
{
mContext.diagnostics = diagnostics;
......@@ -298,6 +302,13 @@ void Tokenizer::setLineNumber(int line)
void Tokenizer::lex(Token* token)
{
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->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