Commit 197d5294 by Geoff Lang Committed by Commit Bot

Wrap all preprocessor code in the angle namespace.

BUG=836820 BUG=801364 Change-Id: I08b6a2f9f12b689e09df6efd916c313e71e8a051 Reviewed-on: https://chromium-review.googlesource.com/1028581 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 23dc90b8
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include "common/debug.h" #include "common/debug.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -141,3 +144,5 @@ const char *Diagnostics::message(ID id) ...@@ -141,3 +144,5 @@ const char *Diagnostics::message(ID id)
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include <string> #include <string>
namespace angle
{
namespace pp namespace pp
{ {
...@@ -87,4 +90,6 @@ class Diagnostics ...@@ -87,4 +90,6 @@ class Diagnostics
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_DIAGNOSTICSBASE_H_ #endif // COMPILER_PREPROCESSOR_DIAGNOSTICSBASE_H_
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include "compiler/preprocessor/DirectiveHandlerBase.h" #include "compiler/preprocessor/DirectiveHandlerBase.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -14,3 +17,5 @@ DirectiveHandler::~DirectiveHandler() ...@@ -14,3 +17,5 @@ DirectiveHandler::~DirectiveHandler()
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include <string> #include <string>
namespace angle
{
namespace pp namespace pp
{ {
...@@ -40,4 +43,6 @@ class DirectiveHandler ...@@ -40,4 +43,6 @@ class DirectiveHandler
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_DIRECTIVEHANDLERBASE_H_ #endif // COMPILER_PREPROCESSOR_DIRECTIVEHANDLERBASE_H_
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
#include "compiler/preprocessor/Tokenizer.h" #include "compiler/preprocessor/Tokenizer.h"
namespace angle
{
namespace namespace
{ {
enum DirectiveType enum DirectiveType
...@@ -998,3 +1001,5 @@ int DirectiveParser::parseExpressionIfdef(Token *token) ...@@ -998,3 +1001,5 @@ int DirectiveParser::parseExpressionIfdef(Token *token)
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "compiler/preprocessor/Macro.h" #include "compiler/preprocessor/Macro.h"
#include "compiler/preprocessor/SourceLocation.h" #include "compiler/preprocessor/SourceLocation.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -80,4 +83,6 @@ class DirectiveParser : public Lexer ...@@ -80,4 +83,6 @@ class DirectiveParser : public Lexer
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_DIRECTIVEPARSER_H_ #endif // COMPILER_PREPROCESSOR_DIRECTIVEPARSER_H_
...@@ -117,13 +117,13 @@ typedef uint32_t UNSIGNED_TYPE; ...@@ -117,13 +117,13 @@ typedef uint32_t UNSIGNED_TYPE;
namespace { namespace {
struct Context struct Context
{ {
pp::Diagnostics* diagnostics; angle::pp::Diagnostics *diagnostics;
pp::Lexer* lexer; angle::pp::Lexer *lexer;
pp::Token* token; angle::pp::Token *token;
int* result; int* result;
bool parsePresetToken; bool parsePresetToken;
pp::ExpressionParser::ErrorSettings errorSettings; angle::pp::ExpressionParser::ErrorSettings errorSettings;
bool *valid; bool *valid;
void startIgnoreErrors() { ++ignoreErrors; } void startIgnoreErrors() { ++ignoreErrors; }
...@@ -1497,9 +1497,8 @@ yyreduce: ...@@ -1497,9 +1497,8 @@ yyreduce:
std::ostringstream stream; std::ostringstream stream;
stream << (yyvsp[-2]) << " >> " << (yyvsp[0]); stream << (yyvsp[-2]) << " >> " << (yyvsp[0]);
std::string text = stream.str(); std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_UNDEFINED_SHIFT, context->diagnostics->report(angle::pp::Diagnostics::PP_UNDEFINED_SHIFT,
context->token->location, context->token->location, text.c_str());
text.c_str());
*(context->valid) = false; *(context->valid) = false;
} }
(yyval) = static_cast<YYSTYPE>(0); (yyval) = static_cast<YYSTYPE>(0);
...@@ -1527,9 +1526,8 @@ yyreduce: ...@@ -1527,9 +1526,8 @@ yyreduce:
std::ostringstream stream; std::ostringstream stream;
stream << (yyvsp[-2]) << " << " << (yyvsp[0]); stream << (yyvsp[-2]) << " << " << (yyvsp[0]);
std::string text = stream.str(); std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_UNDEFINED_SHIFT, context->diagnostics->report(angle::pp::Diagnostics::PP_UNDEFINED_SHIFT,
context->token->location, context->token->location, text.c_str());
text.c_str());
*(context->valid) = false; *(context->valid) = false;
} }
(yyval) = static_cast<YYSTYPE>(0); (yyval) = static_cast<YYSTYPE>(0);
...@@ -1570,9 +1568,8 @@ yyreduce: ...@@ -1570,9 +1568,8 @@ yyreduce:
std::ostringstream stream; std::ostringstream stream;
stream << (yyvsp[-2]) << " % " << (yyvsp[0]); stream << (yyvsp[-2]) << " % " << (yyvsp[0]);
std::string text = stream.str(); std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO, context->diagnostics->report(angle::pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location, context->token->location, text.c_str());
text.c_str());
*(context->valid) = false; *(context->valid) = false;
} }
(yyval) = static_cast<YYSTYPE>(0); (yyval) = static_cast<YYSTYPE>(0);
...@@ -1601,9 +1598,8 @@ yyreduce: ...@@ -1601,9 +1598,8 @@ yyreduce:
std::ostringstream stream; std::ostringstream stream;
stream << (yyvsp[-2]) << " / " << (yyvsp[0]); stream << (yyvsp[-2]) << " / " << (yyvsp[0]);
std::string text = stream.str(); std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO, context->diagnostics->report(angle::pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location, context->token->location, text.c_str());
text.c_str());
*(context->valid) = false; *(context->valid) = false;
} }
(yyval) = static_cast<YYSTYPE>(0); (yyval) = static_cast<YYSTYPE>(0);
...@@ -1914,7 +1910,7 @@ yyreturn: ...@@ -1914,7 +1910,7 @@ yyreturn:
int yylex(YYSTYPE *lvalp, Context *context) int yylex(YYSTYPE *lvalp, Context *context)
{ {
pp::Token *token = context->token; angle::pp::Token *token = context->token;
if (!context->parsePresetToken) if (!context->parsePresetToken)
{ {
context->lexer->lex(token); context->lexer->lex(token);
...@@ -1925,48 +1921,50 @@ int yylex(YYSTYPE *lvalp, Context *context) ...@@ -1925,48 +1921,50 @@ int yylex(YYSTYPE *lvalp, Context *context)
switch (token->type) switch (token->type)
{ {
case pp::Token::CONST_INT: { case angle::pp::Token::CONST_INT:
unsigned int val = 0;
int testVal = 0;
if (!token->uValue(&val) || (!token->iValue(&testVal) &&
context->errorSettings.integerLiteralsMustFit32BitSignedRange))
{ {
context->diagnostics->report(pp::Diagnostics::PP_INTEGER_OVERFLOW, unsigned int val = 0;
token->location, token->text); int testVal = 0;
*(context->valid) = false; if (!token->uValue(&val) ||
} (!token->iValue(&testVal) &&
*lvalp = static_cast<YYSTYPE>(val); context->errorSettings.integerLiteralsMustFit32BitSignedRange))
type = TOK_CONST_INT; {
break; context->diagnostics->report(angle::pp::Diagnostics::PP_INTEGER_OVERFLOW,
token->location, token->text);
*(context->valid) = false;
}
*lvalp = static_cast<YYSTYPE>(val);
type = TOK_CONST_INT;
break;
} }
case pp::Token::IDENTIFIER: case angle::pp::Token::IDENTIFIER:
*lvalp = static_cast<YYSTYPE>(-1); *lvalp = static_cast<YYSTYPE>(-1);
type = TOK_IDENTIFIER; type = TOK_IDENTIFIER;
break; break;
case pp::Token::OP_OR: case angle::pp::Token::OP_OR:
type = TOK_OP_OR; type = TOK_OP_OR;
break; break;
case pp::Token::OP_AND: case angle::pp::Token::OP_AND:
type = TOK_OP_AND; type = TOK_OP_AND;
break; break;
case pp::Token::OP_NE: case angle::pp::Token::OP_NE:
type = TOK_OP_NE; type = TOK_OP_NE;
break; break;
case pp::Token::OP_EQ: case angle::pp::Token::OP_EQ:
type = TOK_OP_EQ; type = TOK_OP_EQ;
break; break;
case pp::Token::OP_GE: case angle::pp::Token::OP_GE:
type = TOK_OP_GE; type = TOK_OP_GE;
break; break;
case pp::Token::OP_LE: case angle::pp::Token::OP_LE:
type = TOK_OP_LE; type = TOK_OP_LE;
break; break;
case pp::Token::OP_RIGHT: case angle::pp::Token::OP_RIGHT:
type = TOK_OP_RIGHT; type = TOK_OP_RIGHT;
break; break;
case pp::Token::OP_LEFT: case angle::pp::Token::OP_LEFT:
type = TOK_OP_LEFT; type = TOK_OP_LEFT;
break; break;
case '|': case '|':
case '^': case '^':
case '&': case '&':
...@@ -1993,11 +1991,13 @@ int yylex(YYSTYPE *lvalp, Context *context) ...@@ -1993,11 +1991,13 @@ int yylex(YYSTYPE *lvalp, Context *context)
void yyerror(Context *context, const char *reason) void yyerror(Context *context, const char *reason)
{ {
context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION, context->diagnostics->report(angle::pp::Diagnostics::PP_INVALID_EXPRESSION,
context->token->location, context->token->location, reason);
reason);
} }
namespace angle
{
namespace pp { namespace pp {
ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics) ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
...@@ -2042,3 +2042,5 @@ bool ExpressionParser::parse(Token *token, ...@@ -2042,3 +2042,5 @@ bool ExpressionParser::parse(Token *token,
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/preprocessor/DiagnosticsBase.h" #include "compiler/preprocessor/DiagnosticsBase.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -40,4 +43,6 @@ class ExpressionParser : angle::NonCopyable ...@@ -40,4 +43,6 @@ class ExpressionParser : angle::NonCopyable
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_EXPRESSIONPARSER_H_ #endif // COMPILER_PREPROCESSOR_EXPRESSIONPARSER_H_
...@@ -59,13 +59,13 @@ typedef uint32_t UNSIGNED_TYPE; ...@@ -59,13 +59,13 @@ typedef uint32_t UNSIGNED_TYPE;
namespace { namespace {
struct Context struct Context
{ {
pp::Diagnostics* diagnostics; angle::pp::Diagnostics *diagnostics;
pp::Lexer* lexer; angle::pp::Lexer *lexer;
pp::Token* token; angle::pp::Token *token;
int* result; int* result;
bool parsePresetToken; bool parsePresetToken;
pp::ExpressionParser::ErrorSettings errorSettings; angle::pp::ExpressionParser::ErrorSettings errorSettings;
bool *valid; bool *valid;
void startIgnoreErrors() { ++ignoreErrors; } void startIgnoreErrors() { ++ignoreErrors; }
...@@ -201,7 +201,7 @@ expression ...@@ -201,7 +201,7 @@ expression
std::ostringstream stream; std::ostringstream stream;
stream << $1 << " >> " << $3; stream << $1 << " >> " << $3;
std::string text = stream.str(); std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_UNDEFINED_SHIFT, context->diagnostics->report(angle::pp::Diagnostics::PP_UNDEFINED_SHIFT,
context->token->location, context->token->location,
text.c_str()); text.c_str());
*(context->valid) = false; *(context->valid) = false;
...@@ -226,7 +226,7 @@ expression ...@@ -226,7 +226,7 @@ expression
std::ostringstream stream; std::ostringstream stream;
stream << $1 << " << " << $3; stream << $1 << " << " << $3;
std::string text = stream.str(); std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_UNDEFINED_SHIFT, context->diagnostics->report(angle::pp::Diagnostics::PP_UNDEFINED_SHIFT,
context->token->location, context->token->location,
text.c_str()); text.c_str());
*(context->valid) = false; *(context->valid) = false;
...@@ -254,7 +254,7 @@ expression ...@@ -254,7 +254,7 @@ expression
std::ostringstream stream; std::ostringstream stream;
stream << $1 << " % " << $3; stream << $1 << " % " << $3;
std::string text = stream.str(); std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO, context->diagnostics->report(angle::pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location, context->token->location,
text.c_str()); text.c_str());
*(context->valid) = false; *(context->valid) = false;
...@@ -280,7 +280,7 @@ expression ...@@ -280,7 +280,7 @@ expression
std::ostringstream stream; std::ostringstream stream;
stream << $1 << " / " << $3; stream << $1 << " / " << $3;
std::string text = stream.str(); std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO, context->diagnostics->report(angle::pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location, context->token->location,
text.c_str()); text.c_str());
*(context->valid) = false; *(context->valid) = false;
...@@ -332,7 +332,7 @@ expression ...@@ -332,7 +332,7 @@ expression
int yylex(YYSTYPE *lvalp, Context *context) int yylex(YYSTYPE *lvalp, Context *context)
{ {
pp::Token *token = context->token; angle::pp::Token *token = context->token;
if (!context->parsePresetToken) if (!context->parsePresetToken)
{ {
context->lexer->lex(token); context->lexer->lex(token);
...@@ -343,13 +343,13 @@ int yylex(YYSTYPE *lvalp, Context *context) ...@@ -343,13 +343,13 @@ int yylex(YYSTYPE *lvalp, Context *context)
switch (token->type) switch (token->type)
{ {
case pp::Token::CONST_INT: { case angle::pp::Token::CONST_INT: {
unsigned int val = 0; unsigned int val = 0;
int testVal = 0; int testVal = 0;
if (!token->uValue(&val) || (!token->iValue(&testVal) && if (!token->uValue(&val) || (!token->iValue(&testVal) &&
context->errorSettings.integerLiteralsMustFit32BitSignedRange)) context->errorSettings.integerLiteralsMustFit32BitSignedRange))
{ {
context->diagnostics->report(pp::Diagnostics::PP_INTEGER_OVERFLOW, context->diagnostics->report(angle::pp::Diagnostics::PP_INTEGER_OVERFLOW,
token->location, token->text); token->location, token->text);
*(context->valid) = false; *(context->valid) = false;
} }
...@@ -357,32 +357,32 @@ int yylex(YYSTYPE *lvalp, Context *context) ...@@ -357,32 +357,32 @@ int yylex(YYSTYPE *lvalp, Context *context)
type = TOK_CONST_INT; type = TOK_CONST_INT;
break; break;
} }
case pp::Token::IDENTIFIER: case angle::pp::Token::IDENTIFIER:
*lvalp = static_cast<YYSTYPE>(-1); *lvalp = static_cast<YYSTYPE>(-1);
type = TOK_IDENTIFIER; type = TOK_IDENTIFIER;
break; break;
case pp::Token::OP_OR: case angle::pp::Token::OP_OR:
type = TOK_OP_OR; type = TOK_OP_OR;
break; break;
case pp::Token::OP_AND: case angle::pp::Token::OP_AND:
type = TOK_OP_AND; type = TOK_OP_AND;
break; break;
case pp::Token::OP_NE: case angle::pp::Token::OP_NE:
type = TOK_OP_NE; type = TOK_OP_NE;
break; break;
case pp::Token::OP_EQ: case angle::pp::Token::OP_EQ:
type = TOK_OP_EQ; type = TOK_OP_EQ;
break; break;
case pp::Token::OP_GE: case angle::pp::Token::OP_GE:
type = TOK_OP_GE; type = TOK_OP_GE;
break; break;
case pp::Token::OP_LE: case angle::pp::Token::OP_LE:
type = TOK_OP_LE; type = TOK_OP_LE;
break; break;
case pp::Token::OP_RIGHT: case angle::pp::Token::OP_RIGHT:
type = TOK_OP_RIGHT; type = TOK_OP_RIGHT;
break; break;
case pp::Token::OP_LEFT: case angle::pp::Token::OP_LEFT:
type = TOK_OP_LEFT; type = TOK_OP_LEFT;
break; break;
case '|': case '|':
...@@ -411,11 +411,13 @@ int yylex(YYSTYPE *lvalp, Context *context) ...@@ -411,11 +411,13 @@ int yylex(YYSTYPE *lvalp, Context *context)
void yyerror(Context *context, const char *reason) void yyerror(Context *context, const char *reason)
{ {
context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION, context->diagnostics->report(angle::pp::Diagnostics::PP_INVALID_EXPRESSION,
context->token->location, context->token->location,
reason); reason);
} }
namespace angle {
namespace pp { namespace pp {
ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics) ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
...@@ -460,3 +462,5 @@ bool ExpressionParser::parse(Token *token, ...@@ -460,3 +462,5 @@ bool ExpressionParser::parse(Token *token,
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "common/debug.h" #include "common/debug.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -127,3 +130,5 @@ size_t Input::read(char *buf, size_t maxSize, int *lineNo) ...@@ -127,3 +130,5 @@ size_t Input::read(char *buf, size_t maxSize, int *lineNo)
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include <cstddef> #include <cstddef>
#include <vector> #include <vector>
namespace angle
{
namespace pp namespace pp
{ {
...@@ -51,4 +54,6 @@ class Input ...@@ -51,4 +54,6 @@ class Input
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_INPUT_H_ #endif // COMPILER_PREPROCESSOR_INPUT_H_
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include "compiler/preprocessor/Lexer.h" #include "compiler/preprocessor/Lexer.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -14,3 +17,5 @@ Lexer::~Lexer() ...@@ -14,3 +17,5 @@ Lexer::~Lexer()
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "common/angleutils.h" #include "common/angleutils.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -24,4 +27,6 @@ class Lexer : angle::NonCopyable ...@@ -24,4 +27,6 @@ class Lexer : angle::NonCopyable
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_LEXER_H_ #endif // COMPILER_PREPROCESSOR_LEXER_H_
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -42,3 +45,5 @@ void PredefineMacro(MacroSet *macroSet, const char *name, int value) ...@@ -42,3 +45,5 @@ void PredefineMacro(MacroSet *macroSet, const char *name, int value)
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace angle
{
namespace pp namespace pp
{ {
...@@ -47,4 +50,6 @@ void PredefineMacro(MacroSet *macroSet, const char *name, int value); ...@@ -47,4 +50,6 @@ void PredefineMacro(MacroSet *macroSet, const char *name, int value);
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_MACRO_H_ #endif // COMPILER_PREPROCESSOR_MACRO_H_
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "compiler/preprocessor/DiagnosticsBase.h" #include "compiler/preprocessor/DiagnosticsBase.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -479,3 +482,5 @@ void MacroExpander::MacroContext::unget() ...@@ -479,3 +482,5 @@ void MacroExpander::MacroContext::unget()
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include "compiler/preprocessor/Lexer.h" #include "compiler/preprocessor/Lexer.h"
#include "compiler/preprocessor/Macro.h" #include "compiler/preprocessor/Macro.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -80,4 +83,6 @@ class MacroExpander : public Lexer ...@@ -80,4 +83,6 @@ class MacroExpander : public Lexer
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_MACROEXPANDER_H_ #endif // COMPILER_PREPROCESSOR_MACROEXPANDER_H_
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
#include "compiler/preprocessor/Tokenizer.h" #include "compiler/preprocessor/Tokenizer.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -105,3 +108,5 @@ void Preprocessor::setMaxTokenSize(size_t maxTokenSize) ...@@ -105,3 +108,5 @@ void Preprocessor::setMaxTokenSize(size_t maxTokenSize)
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "common/angleutils.h" #include "common/angleutils.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -57,4 +60,6 @@ class Preprocessor : angle::NonCopyable ...@@ -57,4 +60,6 @@ class Preprocessor : angle::NonCopyable
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_PREPROCESSOR_H_ #endif // COMPILER_PREPROCESSOR_PREPROCESSOR_H_
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#ifndef COMPILER_PREPROCESSOR_SOURCELOCATION_H_ #ifndef COMPILER_PREPROCESSOR_SOURCELOCATION_H_
#define COMPILER_PREPROCESSOR_SOURCELOCATION_H_ #define COMPILER_PREPROCESSOR_SOURCELOCATION_H_
namespace angle
{
namespace pp namespace pp
{ {
...@@ -36,4 +39,6 @@ inline bool operator!=(const SourceLocation &lhs, const SourceLocation &rhs) ...@@ -36,4 +39,6 @@ inline bool operator!=(const SourceLocation &lhs, const SourceLocation &rhs)
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_SOURCELOCATION_H_ #endif // COMPILER_PREPROCESSOR_SOURCELOCATION_H_
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "common/debug.h" #include "common/debug.h"
#include "compiler/preprocessor/numeric_lex.h" #include "compiler/preprocessor/numeric_lex.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -78,3 +81,5 @@ std::ostream &operator<<(std::ostream &out, const Token &token) ...@@ -78,3 +81,5 @@ std::ostream &operator<<(std::ostream &out, const Token &token)
} }
} // namespace pp } // namespace pp
} // namespace angle
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "compiler/preprocessor/SourceLocation.h" #include "compiler/preprocessor/SourceLocation.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -104,6 +107,8 @@ inline bool operator!=(const Token &lhs, const Token &rhs) ...@@ -104,6 +107,8 @@ inline bool operator!=(const Token &lhs, const Token &rhs)
std::ostream &operator<<(std::ostream &out, const Token &token); std::ostream &operator<<(std::ostream &out, const Token &token);
} // namepsace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_TOKEN_H_ #endif // COMPILER_PREPROCESSOR_TOKEN_H_
...@@ -924,7 +924,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -924,7 +924,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#endif #endif
typedef std::string YYSTYPE; typedef std::string YYSTYPE;
typedef pp::SourceLocation YYLTYPE; typedef angle::pp::SourceLocation YYLTYPE;
// Use the unused yycolumn variable to track file (string) number. // Use the unused yycolumn variable to track file (string) number.
#define yyfileno yycolumn #define yyfileno yycolumn
...@@ -941,18 +941,19 @@ typedef pp::SourceLocation YYLTYPE; ...@@ -941,18 +941,19 @@ typedef pp::SourceLocation YYLTYPE;
#define YY_USER_ACTION \ #define YY_USER_ACTION \
do \ do \
{ \ { \
pp::Input* input = &yyextra->input; \ angle::pp::Input *input = &yyextra->input; \
pp::Input::Location* scanLoc = &yyextra->scanLoc; \ angle::pp::Input::Location *scanLoc = &yyextra->scanLoc; \
while ((scanLoc->sIndex < input->count()) && \ while ((scanLoc->sIndex < input->count()) && \
(scanLoc->cIndex >= input->length(scanLoc->sIndex))) \ (scanLoc->cIndex >= input->length(scanLoc->sIndex))) \
{ \ { \
scanLoc->cIndex -= input->length(scanLoc->sIndex++); \ scanLoc->cIndex -= input->length(scanLoc->sIndex++); \
++yyfileno; yylineno = 1; \ ++yyfileno; \
yylineno = 1; \
} \ } \
yylloc->file = yyfileno; \ yylloc->file = yyfileno; \
yylloc->line = yylineno; \ yylloc->line = yylineno; \
scanLoc->cIndex += yyleng; \ scanLoc->cIndex += yyleng; \
} while(0); } while (0);
#define YY_INPUT(buf, result, maxSize) \ #define YY_INPUT(buf, result, maxSize) \
result = yyextra->input.read(buf, maxSize, &yylineno); result = yyextra->input.read(buf, maxSize, &yylineno);
...@@ -964,15 +965,7 @@ typedef pp::SourceLocation YYLTYPE; ...@@ -964,15 +965,7 @@ typedef pp::SourceLocation YYLTYPE;
#define INITIAL 0 #define INITIAL 0
#define COMMENT 1 #define COMMENT 1
#define YY_EXTRA_TYPE angle::pp::Tokenizer::Context *
#define YY_EXTRA_TYPE pp::Tokenizer::Context*
/* Holds the entire state of the reentrant scanner. */ /* Holds the entire state of the reentrant scanner. */
struct yyguts_t struct yyguts_t
...@@ -1436,7 +1429,7 @@ YY_RULE_SETUP ...@@ -1436,7 +1429,7 @@ YY_RULE_SETUP
if (yylineno == INT_MAX) if (yylineno == INT_MAX)
{ {
*yylval = "Integer overflow on line number"; *yylval = "Integer overflow on line number";
return pp::Token::GOT_ERROR; return angle::pp::Token::GOT_ERROR;
} }
++yylineno; ++yylineno;
} }
...@@ -1453,28 +1446,28 @@ YY_RULE_SETUP ...@@ -1453,28 +1446,28 @@ YY_RULE_SETUP
{ {
// # is only valid at start of line for preprocessor directives. // # is only valid at start of line for preprocessor directives.
yylval->assign(1, yytext[0]); yylval->assign(1, yytext[0]);
return yyextra->lineStart ? pp::Token::PP_HASH : pp::Token::PP_OTHER; return yyextra->lineStart ? angle::pp::Token::PP_HASH : angle::pp::Token::PP_OTHER;
} }
YY_BREAK YY_BREAK
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::IDENTIFIER; return angle::pp::Token::IDENTIFIER;
} }
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::CONST_INT; return angle::pp::Token::CONST_INT;
} }
YY_BREAK YY_BREAK
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::CONST_FLOAT; return angle::pp::Token::CONST_FLOAT;
} }
YY_BREAK YY_BREAK
/* Anything that starts with a {DIGIT} or .{DIGIT} must be a number. */ /* Anything that starts with a {DIGIT} or .{DIGIT} must be a number. */
...@@ -1483,154 +1476,154 @@ case 11: ...@@ -1483,154 +1476,154 @@ case 11:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::PP_NUMBER; return angle::pp::Token::PP_NUMBER;
} }
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_INC; return angle::pp::Token::OP_INC;
} }
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_DEC; return angle::pp::Token::OP_DEC;
} }
YY_BREAK YY_BREAK
case 14: case 14:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_LEFT; return angle::pp::Token::OP_LEFT;
} }
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_RIGHT; return angle::pp::Token::OP_RIGHT;
} }
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_LE; return angle::pp::Token::OP_LE;
} }
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_GE; return angle::pp::Token::OP_GE;
} }
YY_BREAK YY_BREAK
case 18: case 18:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_EQ; return angle::pp::Token::OP_EQ;
} }
YY_BREAK YY_BREAK
case 19: case 19:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_NE; return angle::pp::Token::OP_NE;
} }
YY_BREAK YY_BREAK
case 20: case 20:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_AND; return angle::pp::Token::OP_AND;
} }
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_XOR; return angle::pp::Token::OP_XOR;
} }
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_OR; return angle::pp::Token::OP_OR;
} }
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_ADD_ASSIGN; return angle::pp::Token::OP_ADD_ASSIGN;
} }
YY_BREAK YY_BREAK
case 24: case 24:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_SUB_ASSIGN; return angle::pp::Token::OP_SUB_ASSIGN;
} }
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_MUL_ASSIGN; return angle::pp::Token::OP_MUL_ASSIGN;
} }
YY_BREAK YY_BREAK
case 26: case 26:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_DIV_ASSIGN; return angle::pp::Token::OP_DIV_ASSIGN;
} }
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_MOD_ASSIGN; return angle::pp::Token::OP_MOD_ASSIGN;
} }
YY_BREAK YY_BREAK
case 28: case 28:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_LEFT_ASSIGN; return angle::pp::Token::OP_LEFT_ASSIGN;
} }
YY_BREAK YY_BREAK
case 29: case 29:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_RIGHT_ASSIGN; return angle::pp::Token::OP_RIGHT_ASSIGN;
} }
YY_BREAK YY_BREAK
case 30: case 30:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_AND_ASSIGN; return angle::pp::Token::OP_AND_ASSIGN;
} }
YY_BREAK YY_BREAK
case 31: case 31:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_XOR_ASSIGN; return angle::pp::Token::OP_XOR_ASSIGN;
} }
YY_BREAK YY_BREAK
case 32: case 32:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_OR_ASSIGN; return angle::pp::Token::OP_OR_ASSIGN;
} }
YY_BREAK YY_BREAK
case 33: case 33:
...@@ -1651,7 +1644,7 @@ YY_RULE_SETUP ...@@ -1651,7 +1644,7 @@ YY_RULE_SETUP
if (yylineno == INT_MAX) if (yylineno == INT_MAX)
{ {
*yylval = "Integer overflow on line number"; *yylval = "Integer overflow on line number";
return pp::Token::GOT_ERROR; return angle::pp::Token::GOT_ERROR;
} }
++yylineno; ++yylineno;
yylval->assign(1, '\n'); yylval->assign(1, '\n');
...@@ -1662,7 +1655,7 @@ case 36: ...@@ -1662,7 +1655,7 @@ case 36:
YY_RULE_SETUP YY_RULE_SETUP
{ {
yylval->assign(1, yytext[0]); yylval->assign(1, yytext[0]);
return pp::Token::PP_OTHER; return angle::pp::Token::PP_OTHER;
} }
YY_BREAK YY_BREAK
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
...@@ -1670,8 +1663,8 @@ case YY_STATE_EOF(COMMENT): ...@@ -1670,8 +1663,8 @@ case YY_STATE_EOF(COMMENT):
{ {
// YY_USER_ACTION is not invoked for handling EOF. // YY_USER_ACTION is not invoked for handling EOF.
// Set the location for EOF token manually. // Set the location for EOF token manually.
pp::Input* input = &yyextra->input; angle::pp::Input *input = &yyextra->input;
pp::Input::Location* scanLoc = &yyextra->scanLoc; angle::pp::Input::Location *scanLoc = &yyextra->scanLoc;
yy_size_t sIndexMax = input->count() ? input->count() - 1 : 0; yy_size_t sIndexMax = input->count() ? input->count() - 1 : 0;
if (scanLoc->sIndex != sIndexMax) if (scanLoc->sIndex != sIndexMax)
{ {
...@@ -1688,14 +1681,14 @@ case YY_STATE_EOF(COMMENT): ...@@ -1688,14 +1681,14 @@ case YY_STATE_EOF(COMMENT):
// Line number overflows fake EOFs to exit early, check for this case. // Line number overflows fake EOFs to exit early, check for this case.
if (yylineno == INT_MAX) if (yylineno == INT_MAX)
{ {
yyextra->diagnostics->report(pp::Diagnostics::PP_TOKENIZER_ERROR, yyextra->diagnostics->report(angle::pp::Diagnostics::PP_TOKENIZER_ERROR,
pp::SourceLocation(yyfileno, yylineno), angle::pp::SourceLocation(yyfileno, yylineno),
"Integer overflow on line number"); "Integer overflow on line number");
} }
else if (YY_START == COMMENT) else if (YY_START == COMMENT)
{ {
yyextra->diagnostics->report(pp::Diagnostics::PP_EOF_IN_COMMENT, yyextra->diagnostics->report(angle::pp::Diagnostics::PP_EOF_IN_COMMENT,
pp::SourceLocation(yyfileno, yylineno), angle::pp::SourceLocation(yyfileno, yylineno),
"EOF while in a comment"); "EOF while in a comment");
} }
yyterminate(); yyterminate();
...@@ -2976,12 +2969,8 @@ void yyfree (void * ptr , yyscan_t yyscanner) ...@@ -2976,12 +2969,8 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
namespace angle
{
namespace pp { namespace pp {
...@@ -3071,4 +3060,4 @@ void Tokenizer::destroyScanner() ...@@ -3071,4 +3060,4 @@ void Tokenizer::destroyScanner()
} // namespace pp } // namespace pp
} // namespace angle
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "compiler/preprocessor/Input.h" #include "compiler/preprocessor/Input.h"
#include "compiler/preprocessor/Lexer.h" #include "compiler/preprocessor/Lexer.h"
namespace angle
{
namespace pp namespace pp
{ {
...@@ -55,4 +58,6 @@ class Tokenizer : public Lexer ...@@ -55,4 +58,6 @@ class Tokenizer : public Lexer
} // namespace pp } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_TOKENIZER_H_ #endif // COMPILER_PREPROCESSOR_TOKENIZER_H_
...@@ -51,7 +51,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -51,7 +51,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#endif #endif
typedef std::string YYSTYPE; typedef std::string YYSTYPE;
typedef pp::SourceLocation YYLTYPE; typedef angle::pp::SourceLocation YYLTYPE;
// Use the unused yycolumn variable to track file (string) number. // Use the unused yycolumn variable to track file (string) number.
#define yyfileno yycolumn #define yyfileno yycolumn
...@@ -68,8 +68,8 @@ typedef pp::SourceLocation YYLTYPE; ...@@ -68,8 +68,8 @@ typedef pp::SourceLocation YYLTYPE;
#define YY_USER_ACTION \ #define YY_USER_ACTION \
do \ do \
{ \ { \
pp::Input* input = &yyextra->input; \ angle::pp::Input* input = &yyextra->input; \
pp::Input::Location* scanLoc = &yyextra->scanLoc; \ angle::pp::Input::Location* scanLoc = &yyextra->scanLoc; \
while ((scanLoc->sIndex < input->count()) && \ while ((scanLoc->sIndex < input->count()) && \
(scanLoc->cIndex >= input->length(scanLoc->sIndex))) \ (scanLoc->cIndex >= input->length(scanLoc->sIndex))) \
{ \ { \
...@@ -89,7 +89,7 @@ typedef pp::SourceLocation YYLTYPE; ...@@ -89,7 +89,7 @@ typedef pp::SourceLocation YYLTYPE;
%option noyywrap nounput never-interactive %option noyywrap nounput never-interactive
%option reentrant bison-bridge bison-locations %option reentrant bison-bridge bison-locations
%option prefix="pp" %option prefix="pp"
%option extra-type="pp::Tokenizer::Context*" %option extra-type="angle::pp::Tokenizer::Context*"
%x COMMENT %x COMMENT
NEWLINE \n|\r|\r\n NEWLINE \n|\r|\r\n
...@@ -119,7 +119,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -119,7 +119,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
if (yylineno == INT_MAX) if (yylineno == INT_MAX)
{ {
*yylval = "Integer overflow on line number"; *yylval = "Integer overflow on line number";
return pp::Token::GOT_ERROR; return angle::pp::Token::GOT_ERROR;
} }
++yylineno; ++yylineno;
} }
...@@ -131,114 +131,114 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -131,114 +131,114 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
# { # {
// # is only valid at start of line for preprocessor directives. // # is only valid at start of line for preprocessor directives.
yylval->assign(1, yytext[0]); yylval->assign(1, yytext[0]);
return yyextra->lineStart ? pp::Token::PP_HASH : pp::Token::PP_OTHER; return yyextra->lineStart ? angle::pp::Token::PP_HASH : angle::pp::Token::PP_OTHER;
} }
{IDENTIFIER} { {IDENTIFIER} {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::IDENTIFIER; return angle::pp::Token::IDENTIFIER;
} }
({DECIMAL_CONSTANT}[uU]?)|({OCTAL_CONSTANT}[uU]?)|({HEXADECIMAL_CONSTANT}[uU]?) { ({DECIMAL_CONSTANT}[uU]?)|({OCTAL_CONSTANT}[uU]?)|({HEXADECIMAL_CONSTANT}[uU]?) {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::CONST_INT; return angle::pp::Token::CONST_INT;
} }
({DIGIT}+{EXPONENT_PART}[fF]?)|({FRACTIONAL_CONSTANT}{EXPONENT_PART}?[fF]?) { ({DIGIT}+{EXPONENT_PART}[fF]?)|({FRACTIONAL_CONSTANT}{EXPONENT_PART}?[fF]?) {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::CONST_FLOAT; return angle::pp::Token::CONST_FLOAT;
} }
/* Anything that starts with a {DIGIT} or .{DIGIT} must be a number. */ /* Anything that starts with a {DIGIT} or .{DIGIT} must be a number. */
/* Rule to catch all invalid integers and floats. */ /* Rule to catch all invalid integers and floats. */
({DIGIT}+[_a-zA-Z0-9.]*)|("."{DIGIT}+[_a-zA-Z0-9.]*) { ({DIGIT}+[_a-zA-Z0-9.]*)|("."{DIGIT}+[_a-zA-Z0-9.]*) {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::PP_NUMBER; return angle::pp::Token::PP_NUMBER;
} }
"++" { "++" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_INC; return angle::pp::Token::OP_INC;
} }
"--" { "--" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_DEC; return angle::pp::Token::OP_DEC;
} }
"<<" { "<<" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_LEFT; return angle::pp::Token::OP_LEFT;
} }
">>" { ">>" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_RIGHT; return angle::pp::Token::OP_RIGHT;
} }
"<=" { "<=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_LE; return angle::pp::Token::OP_LE;
} }
">=" { ">=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_GE; return angle::pp::Token::OP_GE;
} }
"==" { "==" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_EQ; return angle::pp::Token::OP_EQ;
} }
"!=" { "!=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_NE; return angle::pp::Token::OP_NE;
} }
"&&" { "&&" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_AND; return angle::pp::Token::OP_AND;
} }
"^^" { "^^" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_XOR; return angle::pp::Token::OP_XOR;
} }
"||" { "||" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_OR; return angle::pp::Token::OP_OR;
} }
"+=" { "+=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_ADD_ASSIGN; return angle::pp::Token::OP_ADD_ASSIGN;
} }
"-=" { "-=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_SUB_ASSIGN; return angle::pp::Token::OP_SUB_ASSIGN;
} }
"*=" { "*=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_MUL_ASSIGN; return angle::pp::Token::OP_MUL_ASSIGN;
} }
"/=" { "/=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_DIV_ASSIGN; return angle::pp::Token::OP_DIV_ASSIGN;
} }
"%=" { "%=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_MOD_ASSIGN; return angle::pp::Token::OP_MOD_ASSIGN;
} }
"<<=" { "<<=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_LEFT_ASSIGN; return angle::pp::Token::OP_LEFT_ASSIGN;
} }
">>=" { ">>=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_RIGHT_ASSIGN; return angle::pp::Token::OP_RIGHT_ASSIGN;
} }
"&=" { "&=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_AND_ASSIGN; return angle::pp::Token::OP_AND_ASSIGN;
} }
"^=" { "^=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_XOR_ASSIGN; return angle::pp::Token::OP_XOR_ASSIGN;
} }
"|=" { "|=" {
yylval->assign(yytext, yyleng); yylval->assign(yytext, yyleng);
return pp::Token::OP_OR_ASSIGN; return angle::pp::Token::OP_OR_ASSIGN;
} }
{PUNCTUATOR} { {PUNCTUATOR} {
...@@ -252,7 +252,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -252,7 +252,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
if (yylineno == INT_MAX) if (yylineno == INT_MAX)
{ {
*yylval = "Integer overflow on line number"; *yylval = "Integer overflow on line number";
return pp::Token::GOT_ERROR; return angle::pp::Token::GOT_ERROR;
} }
++yylineno; ++yylineno;
yylval->assign(1, '\n'); yylval->assign(1, '\n');
...@@ -261,14 +261,14 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -261,14 +261,14 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
. { . {
yylval->assign(1, yytext[0]); yylval->assign(1, yytext[0]);
return pp::Token::PP_OTHER; return angle::pp::Token::PP_OTHER;
} }
<*><<EOF>> { <*><<EOF>> {
// YY_USER_ACTION is not invoked for handling EOF. // YY_USER_ACTION is not invoked for handling EOF.
// Set the location for EOF token manually. // Set the location for EOF token manually.
pp::Input* input = &yyextra->input; angle::pp::Input* input = &yyextra->input;
pp::Input::Location* scanLoc = &yyextra->scanLoc; angle::pp::Input::Location* scanLoc = &yyextra->scanLoc;
yy_size_t sIndexMax = input->count() ? input->count() - 1 : 0; yy_size_t sIndexMax = input->count() ? input->count() - 1 : 0;
if (scanLoc->sIndex != sIndexMax) if (scanLoc->sIndex != sIndexMax)
{ {
...@@ -284,14 +284,14 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -284,14 +284,14 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
// Line number overflows fake EOFs to exit early, check for this case. // Line number overflows fake EOFs to exit early, check for this case.
if (yylineno == INT_MAX) { if (yylineno == INT_MAX) {
yyextra->diagnostics->report(pp::Diagnostics::PP_TOKENIZER_ERROR, yyextra->diagnostics->report(angle::pp::Diagnostics::PP_TOKENIZER_ERROR,
pp::SourceLocation(yyfileno, yylineno), angle::pp::SourceLocation(yyfileno, yylineno),
"Integer overflow on line number"); "Integer overflow on line number");
} }
else if (YY_START == COMMENT) else if (YY_START == COMMENT)
{ {
yyextra->diagnostics->report(pp::Diagnostics::PP_EOF_IN_COMMENT, yyextra->diagnostics->report(angle::pp::Diagnostics::PP_EOF_IN_COMMENT,
pp::SourceLocation(yyfileno, yylineno), angle::pp::SourceLocation(yyfileno, yylineno),
"EOF while in a comment"); "EOF while in a comment");
} }
yyterminate(); yyterminate();
...@@ -299,6 +299,8 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -299,6 +299,8 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
%% %%
namespace angle {
namespace pp { namespace pp {
Tokenizer::Tokenizer(Diagnostics *diagnostics) : mHandle(nullptr), mMaxTokenSize(256) Tokenizer::Tokenizer(Diagnostics *diagnostics) : mHandle(nullptr), mMaxTokenSize(256)
...@@ -387,3 +389,5 @@ void Tokenizer::destroyScanner() ...@@ -387,3 +389,5 @@ void Tokenizer::destroyScanner()
} // namespace pp } // namespace pp
} // namespace angle
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include <cmath> #include <cmath>
#include <sstream> #include <sstream>
namespace angle
{
namespace pp namespace pp
{ {
...@@ -54,6 +57,8 @@ bool numeric_lex_float(const std::string &str, FloatType *value) ...@@ -54,6 +57,8 @@ bool numeric_lex_float(const std::string &str, FloatType *value)
return errno != ERANGE && std::isfinite(*value); return errno != ERANGE && std::isfinite(*value);
} }
} // namespace pp. } // namespace pp
} // namespace angle
#endif // COMPILER_PREPROCESSOR_NUMERICLEX_H_ #endif // COMPILER_PREPROCESSOR_NUMERICLEX_H_
...@@ -24,7 +24,7 @@ TDiagnostics::~TDiagnostics() ...@@ -24,7 +24,7 @@ TDiagnostics::~TDiagnostics()
} }
void TDiagnostics::writeInfo(Severity severity, void TDiagnostics::writeInfo(Severity severity,
const pp::SourceLocation &loc, const angle::pp::SourceLocation &loc,
const char *reason, const char *reason,
const char *token) const char *token)
{ {
...@@ -54,19 +54,23 @@ void TDiagnostics::globalError(const char *message) ...@@ -54,19 +54,23 @@ void TDiagnostics::globalError(const char *message)
mInfoSink << message << "\n"; mInfoSink << message << "\n";
} }
void TDiagnostics::error(const pp::SourceLocation &loc, const char *reason, const char *token) void TDiagnostics::error(const angle::pp::SourceLocation &loc,
const char *reason,
const char *token)
{ {
writeInfo(SH_ERROR, loc, reason, token); writeInfo(SH_ERROR, loc, reason, token);
} }
void TDiagnostics::warning(const pp::SourceLocation &loc, const char *reason, const char *token) void TDiagnostics::warning(const angle::pp::SourceLocation &loc,
const char *reason,
const char *token)
{ {
writeInfo(SH_WARNING, loc, reason, token); writeInfo(SH_WARNING, loc, reason, token);
} }
void TDiagnostics::error(const TSourceLoc &loc, const char *reason, const char *token) void TDiagnostics::error(const TSourceLoc &loc, const char *reason, const char *token)
{ {
pp::SourceLocation srcLoc; angle::pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file; srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line; srcLoc.line = loc.first_line;
error(srcLoc, reason, token); error(srcLoc, reason, token);
...@@ -74,13 +78,13 @@ void TDiagnostics::error(const TSourceLoc &loc, const char *reason, const char * ...@@ -74,13 +78,13 @@ void TDiagnostics::error(const TSourceLoc &loc, const char *reason, const char *
void TDiagnostics::warning(const TSourceLoc &loc, const char *reason, const char *token) void TDiagnostics::warning(const TSourceLoc &loc, const char *reason, const char *token)
{ {
pp::SourceLocation srcLoc; angle::pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file; srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line; srcLoc.line = loc.first_line;
warning(srcLoc, reason, token); warning(srcLoc, reason, token);
} }
void TDiagnostics::print(ID id, const pp::SourceLocation &loc, const std::string &text) void TDiagnostics::print(ID id, const angle::pp::SourceLocation &loc, const std::string &text)
{ {
writeInfo(isError(id) ? SH_ERROR : SH_WARNING, loc, message(id), text.c_str()); writeInfo(isError(id) ? SH_ERROR : SH_WARNING, loc, message(id), text.c_str());
} }
......
...@@ -17,7 +17,7 @@ namespace sh ...@@ -17,7 +17,7 @@ namespace sh
class TInfoSinkBase; class TInfoSinkBase;
struct TSourceLoc; struct TSourceLoc;
class TDiagnostics : public pp::Diagnostics, angle::NonCopyable class TDiagnostics : public angle::pp::Diagnostics, angle::NonCopyable
{ {
public: public:
TDiagnostics(TInfoSinkBase &infoSink); TDiagnostics(TInfoSinkBase &infoSink);
...@@ -26,8 +26,8 @@ class TDiagnostics : public pp::Diagnostics, angle::NonCopyable ...@@ -26,8 +26,8 @@ class TDiagnostics : public pp::Diagnostics, angle::NonCopyable
int numErrors() const { return mNumErrors; } int numErrors() const { return mNumErrors; }
int numWarnings() const { return mNumWarnings; } int numWarnings() const { return mNumWarnings; }
void error(const pp::SourceLocation &loc, const char *reason, const char *token); void error(const angle::pp::SourceLocation &loc, const char *reason, const char *token);
void warning(const pp::SourceLocation &loc, const char *reason, const char *token); void warning(const angle::pp::SourceLocation &loc, const char *reason, const char *token);
void error(const TSourceLoc &loc, const char *reason, const char *token); void error(const TSourceLoc &loc, const char *reason, const char *token);
void warning(const TSourceLoc &loc, const char *reason, const char *token); void warning(const TSourceLoc &loc, const char *reason, const char *token);
...@@ -38,11 +38,11 @@ class TDiagnostics : public pp::Diagnostics, angle::NonCopyable ...@@ -38,11 +38,11 @@ class TDiagnostics : public pp::Diagnostics, angle::NonCopyable
protected: protected:
void writeInfo(Severity severity, void writeInfo(Severity severity,
const pp::SourceLocation &loc, const angle::pp::SourceLocation &loc,
const char *reason, const char *reason,
const char *token); const char *token);
void print(ID id, const pp::SourceLocation &loc, const std::string &text) override; void print(ID id, const angle::pp::SourceLocation &loc, const std::string &text) override;
private: private:
TInfoSinkBase &mInfoSink; TInfoSinkBase &mInfoSink;
......
...@@ -50,12 +50,12 @@ TDirectiveHandler::~TDirectiveHandler() ...@@ -50,12 +50,12 @@ TDirectiveHandler::~TDirectiveHandler()
{ {
} }
void TDirectiveHandler::handleError(const pp::SourceLocation &loc, const std::string &msg) void TDirectiveHandler::handleError(const angle::pp::SourceLocation &loc, const std::string &msg)
{ {
mDiagnostics.error(loc, msg.c_str(), ""); mDiagnostics.error(loc, msg.c_str(), "");
} }
void TDirectiveHandler::handlePragma(const pp::SourceLocation &loc, void TDirectiveHandler::handlePragma(const angle::pp::SourceLocation &loc,
const std::string &name, const std::string &name,
const std::string &value, const std::string &value,
bool stdgl) bool stdgl)
...@@ -119,7 +119,7 @@ void TDirectiveHandler::handlePragma(const pp::SourceLocation &loc, ...@@ -119,7 +119,7 @@ void TDirectiveHandler::handlePragma(const pp::SourceLocation &loc,
} }
else else
{ {
mDiagnostics.report(pp::Diagnostics::PP_UNRECOGNIZED_PRAGMA, loc, name); mDiagnostics.report(angle::pp::Diagnostics::PP_UNRECOGNIZED_PRAGMA, loc, name);
return; return;
} }
...@@ -130,7 +130,7 @@ void TDirectiveHandler::handlePragma(const pp::SourceLocation &loc, ...@@ -130,7 +130,7 @@ void TDirectiveHandler::handlePragma(const pp::SourceLocation &loc,
} }
} }
void TDirectiveHandler::handleExtension(const pp::SourceLocation &loc, void TDirectiveHandler::handleExtension(const angle::pp::SourceLocation &loc,
const std::string &name, const std::string &name,
const std::string &behavior) const std::string &behavior)
{ {
...@@ -185,7 +185,7 @@ void TDirectiveHandler::handleExtension(const pp::SourceLocation &loc, ...@@ -185,7 +185,7 @@ void TDirectiveHandler::handleExtension(const pp::SourceLocation &loc,
} }
} }
void TDirectiveHandler::handleVersion(const pp::SourceLocation &loc, int version) void TDirectiveHandler::handleVersion(const angle::pp::SourceLocation &loc, int version)
{ {
if (version == 100 || version == 300 || version == 310) if (version == 100 || version == 300 || version == 310)
{ {
......
...@@ -17,7 +17,7 @@ namespace sh ...@@ -17,7 +17,7 @@ namespace sh
{ {
class TDiagnostics; class TDiagnostics;
class TDirectiveHandler : public pp::DirectiveHandler, angle::NonCopyable class TDirectiveHandler : public angle::pp::DirectiveHandler, angle::NonCopyable
{ {
public: public:
TDirectiveHandler(TExtensionBehavior &extBehavior, TDirectiveHandler(TExtensionBehavior &extBehavior,
...@@ -30,18 +30,18 @@ class TDirectiveHandler : public pp::DirectiveHandler, angle::NonCopyable ...@@ -30,18 +30,18 @@ class TDirectiveHandler : public pp::DirectiveHandler, angle::NonCopyable
const TPragma &pragma() const { return mPragma; } const TPragma &pragma() const { return mPragma; }
const TExtensionBehavior &extensionBehavior() const { return mExtensionBehavior; } const TExtensionBehavior &extensionBehavior() const { return mExtensionBehavior; }
void handleError(const pp::SourceLocation &loc, const std::string &msg) override; void handleError(const angle::pp::SourceLocation &loc, const std::string &msg) override;
void handlePragma(const pp::SourceLocation &loc, void handlePragma(const angle::pp::SourceLocation &loc,
const std::string &name, const std::string &name,
const std::string &value, const std::string &value,
bool stdgl) override; bool stdgl) override;
void handleExtension(const pp::SourceLocation &loc, void handleExtension(const angle::pp::SourceLocation &loc,
const std::string &name, const std::string &name,
const std::string &behavior) override; const std::string &behavior) override;
void handleVersion(const pp::SourceLocation &loc, int version) override; void handleVersion(const angle::pp::SourceLocation &loc, int version) override;
private: private:
TPragma mPragma; TPragma mPragma;
......
...@@ -194,7 +194,7 @@ TParseContext::TParseContext(TSymbolTable &symt, ...@@ -194,7 +194,7 @@ TParseContext::TParseContext(TSymbolTable &symt,
mShaderVersion, mShaderVersion,
mShaderType, mShaderType,
resources.WEBGL_debug_shader_precision == 1), resources.WEBGL_debug_shader_precision == 1),
mPreprocessor(mDiagnostics, &mDirectiveHandler, pp::PreprocessorSettings()), mPreprocessor(mDiagnostics, &mDirectiveHandler, angle::pp::PreprocessorSettings()),
mScanner(nullptr), mScanner(nullptr),
mMinProgramTexelOffset(resources.MinProgramTexelOffset), mMinProgramTexelOffset(resources.MinProgramTexelOffset),
mMaxProgramTexelOffset(resources.MaxProgramTexelOffset), mMaxProgramTexelOffset(resources.MaxProgramTexelOffset),
...@@ -1755,7 +1755,7 @@ void TParseContext::handleExtensionDirective(const TSourceLoc &loc, ...@@ -1755,7 +1755,7 @@ void TParseContext::handleExtensionDirective(const TSourceLoc &loc,
const char *extName, const char *extName,
const char *behavior) const char *behavior)
{ {
pp::SourceLocation srcLoc; angle::pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file; srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line; srcLoc.line = loc.first_line;
mDirectiveHandler.handleExtension(srcLoc, extName, behavior); mDirectiveHandler.handleExtension(srcLoc, extName, behavior);
...@@ -1766,7 +1766,7 @@ void TParseContext::handlePragmaDirective(const TSourceLoc &loc, ...@@ -1766,7 +1766,7 @@ void TParseContext::handlePragmaDirective(const TSourceLoc &loc,
const char *value, const char *value,
bool stdgl) bool stdgl)
{ {
pp::SourceLocation srcLoc; angle::pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file; srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line; srcLoc.line = loc.first_line;
mDirectiveHandler.handlePragma(srcLoc, name, value, stdgl); mDirectiveHandler.handlePragma(srcLoc, name, value, stdgl);
......
...@@ -43,8 +43,8 @@ class TParseContext : angle::NonCopyable ...@@ -43,8 +43,8 @@ class TParseContext : angle::NonCopyable
const ShBuiltInResources &resources); const ShBuiltInResources &resources);
~TParseContext(); ~TParseContext();
const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; } const angle::pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
pp::Preprocessor &getPreprocessor() { return mPreprocessor; } angle::pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
void *getScanner() const { return mScanner; } void *getScanner() const { return mScanner; }
void setScanner(void *scanner) { mScanner = scanner; } void setScanner(void *scanner) { mScanner = scanner; }
int getShaderVersion() const { return mShaderVersion; } int getShaderVersion() const { return mShaderVersion; }
...@@ -607,7 +607,7 @@ class TParseContext : angle::NonCopyable ...@@ -607,7 +607,7 @@ class TParseContext : angle::NonCopyable
TString mHashErrMsg; TString mHashErrMsg;
TDiagnostics *mDiagnostics; TDiagnostics *mDiagnostics;
TDirectiveHandler mDirectiveHandler; TDirectiveHandler mDirectiveHandler;
pp::Preprocessor mPreprocessor; angle::pp::Preprocessor mPreprocessor;
void *mScanner; void *mScanner;
int mMinProgramTexelOffset; int mMinProgramTexelOffset;
int mMaxProgramTexelOffset; int mMaxProgramTexelOffset;
......
...@@ -426,9 +426,9 @@ O [0-7] ...@@ -426,9 +426,9 @@ O [0-7]
%% %%
yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) { yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
pp::Token token; angle::pp::Token token;
yyget_extra(yyscanner)->getPreprocessor().lex(&token); yyget_extra(yyscanner)->getPreprocessor().lex(&token);
yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size(); yy_size_t len = token.type == angle::pp::Token::LAST ? 0 : token.text.size();
if (len < max_size) if (len < max_size)
memcpy(buf, token.text.c_str(), len); memcpy(buf, token.text.c_str(), len);
yyset_column(token.location.file, yyscanner); yyset_column(token.location.file, yyscanner);
...@@ -680,7 +680,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[], ...@@ -680,7 +680,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
yyset_lineno(1, context->getScanner()); yyset_lineno(1, context->getScanner());
// Initialize preprocessor. // Initialize preprocessor.
pp::Preprocessor *preprocessor = &context->getPreprocessor(); angle::pp::Preprocessor *preprocessor = &context->getPreprocessor();
if (!preprocessor->init(count, string, length)) if (!preprocessor->init(count, string, length))
return 1; return 1;
......
...@@ -3782,9 +3782,9 @@ void yyfree (void * ptr , yyscan_t yyscanner) ...@@ -3782,9 +3782,9 @@ void yyfree (void * ptr , yyscan_t yyscanner)
yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) { yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
pp::Token token; angle::pp::Token token;
yyget_extra(yyscanner)->getPreprocessor().lex(&token); yyget_extra(yyscanner)->getPreprocessor().lex(&token);
yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size(); yy_size_t len = token.type == angle::pp::Token::LAST ? 0 : token.text.size();
if (len < max_size) if (len < max_size)
memcpy(buf, token.text.c_str(), len); memcpy(buf, token.text.c_str(), len);
yyset_column(token.location.file, yyscanner); yyset_column(token.location.file, yyscanner);
...@@ -4036,7 +4036,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[], ...@@ -4036,7 +4036,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
yyset_lineno(1, context->getScanner()); yyset_lineno(1, context->getScanner());
// Initialize preprocessor. // Initialize preprocessor.
pp::Preprocessor *preprocessor = &context->getPreprocessor(); angle::pp::Preprocessor *preprocessor = &context->getPreprocessor();
if (!preprocessor->init(count, string, length)) if (!preprocessor->init(count, string, length))
return 1; return 1;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
bool atoi_clamp(const char *str, unsigned int *value) bool atoi_clamp(const char *str, unsigned int *value)
{ {
bool success = pp::numeric_lex_int(str, value); bool success = angle::pp::numeric_lex_int(str, value);
if (!success) if (!success)
*value = std::numeric_limits<unsigned int>::max(); *value = std::numeric_limits<unsigned int>::max();
return success; return success;
...@@ -184,7 +184,7 @@ float NumericLexFloat32OutOfRangeToInfinity(const std::string &str) ...@@ -184,7 +184,7 @@ float NumericLexFloat32OutOfRangeToInfinity(const std::string &str)
bool strtof_clamp(const std::string &str, float *value) bool strtof_clamp(const std::string &str, float *value)
{ {
// Try the standard float parsing path first. // Try the standard float parsing path first.
bool success = pp::numeric_lex_float(str, value); bool success = angle::pp::numeric_lex_float(str, value);
// If the standard path doesn't succeed, take the path that can handle the following corner // If the standard path doesn't succeed, take the path that can handle the following corner
// cases: // cases:
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "compiler/preprocessor/DiagnosticsBase.h" #include "compiler/preprocessor/DiagnosticsBase.h"
namespace angle
{
class MockDiagnostics : public pp::Diagnostics class MockDiagnostics : public pp::Diagnostics
{ {
public: public:
...@@ -17,4 +20,6 @@ class MockDiagnostics : public pp::Diagnostics ...@@ -17,4 +20,6 @@ class MockDiagnostics : public pp::Diagnostics
void(ID id, const pp::SourceLocation& loc, const std::string& text)); void(ID id, const pp::SourceLocation& loc, const std::string& text));
}; };
} // namespace angle
#endif // PREPROCESSOR_TESTS_MOCK_DIAGNOSTICS_H_ #endif // PREPROCESSOR_TESTS_MOCK_DIAGNOSTICS_H_
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "compiler/preprocessor/DirectiveHandlerBase.h" #include "compiler/preprocessor/DirectiveHandlerBase.h"
namespace angle
{
class MockDirectiveHandler : public pp::DirectiveHandler class MockDirectiveHandler : public pp::DirectiveHandler
{ {
public: public:
...@@ -31,4 +34,6 @@ class MockDirectiveHandler : public pp::DirectiveHandler ...@@ -31,4 +34,6 @@ class MockDirectiveHandler : public pp::DirectiveHandler
void(const pp::SourceLocation& loc, int version)); void(const pp::SourceLocation& loc, int version));
}; };
} // namespace angle
#endif // PREPROCESSOR_TESTS_MOCK_DIRECTIVE_HANDLER_H_ #endif // PREPROCESSOR_TESTS_MOCK_DIRECTIVE_HANDLER_H_
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
void SimplePreprocessorTest::preprocess(const char *input, void SimplePreprocessorTest::preprocess(const char *input,
std::stringstream *output, std::stringstream *output,
pp::Preprocessor *preprocessor) pp::Preprocessor *preprocessor)
...@@ -64,4 +67,6 @@ void SimplePreprocessorTest::lexSingleToken(size_t count, ...@@ -64,4 +67,6 @@ void SimplePreprocessorTest::lexSingleToken(size_t count,
pp::Preprocessor preprocessor(&mDiagnostics, &mDirectiveHandler, pp::PreprocessorSettings()); pp::Preprocessor preprocessor(&mDiagnostics, &mDirectiveHandler, pp::PreprocessorSettings());
ASSERT_TRUE(preprocessor.init(count, input, nullptr)); ASSERT_TRUE(preprocessor.init(count, input, nullptr));
preprocessor.lex(token); preprocessor.lex(token);
} }
\ No newline at end of file
} // namespace angle
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#ifndef PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_ #ifndef PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_
#define PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_ #define PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_
namespace angle
{
class PreprocessorTest : public testing::Test class PreprocessorTest : public testing::Test
{ {
protected: protected:
...@@ -47,4 +50,6 @@ class SimplePreprocessorTest : public testing::Test ...@@ -47,4 +50,6 @@ class SimplePreprocessorTest : public testing::Test
void preprocess(const char *input, std::stringstream *output, pp::Preprocessor *preprocessor); void preprocess(const char *input, std::stringstream *output, pp::Preprocessor *preprocessor);
}; };
} // namespace angle
#endif // PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_ #endif // PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class CharTest : public PreprocessorTest, class CharTest : public PreprocessorTest,
public testing::WithParamInterface<int> public testing::WithParamInterface<int>
{ {
...@@ -96,3 +99,4 @@ TEST_P(CharTest, Identified) ...@@ -96,3 +99,4 @@ TEST_P(CharTest, Identified)
INSTANTIATE_TEST_CASE_P(All, CharTest, INSTANTIATE_TEST_CASE_P(All, CharTest,
testing::Range(CHAR_MIN, CHAR_MAX + 1)); testing::Range(CHAR_MIN, CHAR_MAX + 1));
} // namespace angle
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class CommentTest : public SimplePreprocessorTest, public testing::WithParamInterface<const char *> class CommentTest : public SimplePreprocessorTest, public testing::WithParamInterface<const char *>
{ {
}; };
...@@ -59,3 +62,5 @@ TEST_F(BlockCommentTest, UnterminatedComment) ...@@ -59,3 +62,5 @@ TEST_F(BlockCommentTest, UnterminatedComment)
preprocess(str); preprocess(str);
} }
} // namespace angle
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
using testing::_; using testing::_;
class DefineTest : public SimplePreprocessorTest class DefineTest : public SimplePreprocessorTest
...@@ -1029,3 +1032,5 @@ TEST_F(DefineTest, LongMacroInvocationChain) ...@@ -1029,3 +1032,5 @@ TEST_F(DefineTest, LongMacroInvocationChain)
preprocess(inputStream.str().c_str(), settings); preprocess(inputStream.str().c_str(), settings);
} }
} // namespace angle
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class ErrorTest : public SimplePreprocessorTest class ErrorTest : public SimplePreprocessorTest
{ {
}; };
...@@ -90,3 +93,5 @@ TEST_F(ErrorTest, MissingNewline) ...@@ -90,3 +93,5 @@ TEST_F(ErrorTest, MissingNewline)
preprocess(str, expected); preprocess(str, expected);
} }
} // namespace angle
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class ExtensionTest : public SimplePreprocessorTest class ExtensionTest : public SimplePreprocessorTest
{ {
}; };
...@@ -134,3 +137,5 @@ static const ExtensionTestParam kParams[] = { ...@@ -134,3 +137,5 @@ static const ExtensionTestParam kParams[] = {
{"#extension foo : bar baz\n", pp::Diagnostics::PP_UNEXPECTED_TOKEN} {"#extension foo : bar baz\n", pp::Diagnostics::PP_UNEXPECTED_TOKEN}
}; };
INSTANTIATE_TEST_CASE_P(All, InvalidExtensionTest, testing::ValuesIn(kParams)); INSTANTIATE_TEST_CASE_P(All, InvalidExtensionTest, testing::ValuesIn(kParams));
} // namespace angle
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
#define CLOSED_RANGE(x, y) testing::Range(x, static_cast<char>((y) + 1)) #define CLOSED_RANGE(x, y) testing::Range(x, static_cast<char>((y) + 1))
class IdentifierTest : public SimplePreprocessorTest class IdentifierTest : public SimplePreprocessorTest
...@@ -161,3 +164,5 @@ TEST_F(IdentifierTest, AllLetters) ...@@ -161,3 +164,5 @@ TEST_F(IdentifierTest, AllLetters)
expectIdentifier(str); expectIdentifier(str);
} }
} // namespace angle
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class IfTest : public SimplePreprocessorTest class IfTest : public SimplePreprocessorTest
{ {
}; };
...@@ -1035,3 +1038,5 @@ TEST_F(IfTest, BitShiftRightOperatorNegativeLHS) ...@@ -1035,3 +1038,5 @@ TEST_F(IfTest, BitShiftRightOperatorNegativeLHS)
preprocess(str, expected); preprocess(str, expected);
} }
} // namespace angle
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include "compiler/preprocessor/Input.h" #include "compiler/preprocessor/Input.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class InitTest : public PreprocessorTest class InitTest : public PreprocessorTest
{ {
}; };
...@@ -176,3 +179,5 @@ TEST(InputTest, ReadStringsWithLineContinuation) ...@@ -176,3 +179,5 @@ TEST(InputTest, ReadStringsWithLineContinuation)
EXPECT_EQ(2, lineNo); EXPECT_EQ(2, lineNo);
EXPECT_STREQ("foobar", buf); EXPECT_STREQ("foobar", buf);
} }
} // namespace angle
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class LocationTest : public PreprocessorTest class LocationTest : public PreprocessorTest
{ {
protected: protected:
...@@ -411,3 +414,5 @@ static const LineExpressionTestParam kParamsLineExpressionTest[] = { ...@@ -411,3 +414,5 @@ static const LineExpressionTestParam kParamsLineExpressionTest[] = {
{"16 >> 2", 4}}; {"16 >> 2", 4}};
INSTANTIATE_TEST_CASE_P(All, LineExpressionTest, testing::ValuesIn(kParamsLineExpressionTest)); INSTANTIATE_TEST_CASE_P(All, LineExpressionTest, testing::ValuesIn(kParamsLineExpressionTest));
} // namespace angle
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
#define CLOSED_RANGE(x, y) testing::Range(x, static_cast<char>((y) + 1)) #define CLOSED_RANGE(x, y) testing::Range(x, static_cast<char>((y) + 1))
class InvalidNumberTest : public SimplePreprocessorTest, class InvalidNumberTest : public SimplePreprocessorTest,
...@@ -164,3 +167,5 @@ TEST_F(FloatTest, FractionScientific) ...@@ -164,3 +167,5 @@ TEST_F(FloatTest, FractionScientific)
SCOPED_TRACE("FractionScientific"); SCOPED_TRACE("FractionScientific");
expectFloat("0.1e+2"); expectFloat("0.1e+2");
} }
} // namespace angle
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
struct OperatorTestParam struct OperatorTestParam
{ {
const char* str; const char* str;
...@@ -76,3 +79,4 @@ static const OperatorTestParam kOperators[] = { ...@@ -76,3 +79,4 @@ static const OperatorTestParam kOperators[] = {
INSTANTIATE_TEST_CASE_P(All, OperatorTest, INSTANTIATE_TEST_CASE_P(All, OperatorTest,
testing::ValuesIn(kOperators)); testing::ValuesIn(kOperators));
} // namespace angle
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class PragmaTest : public SimplePreprocessorTest class PragmaTest : public SimplePreprocessorTest
{ {
}; };
...@@ -152,3 +155,5 @@ INSTANTIATE_TEST_CASE_P(All, InvalidPragmaTest, testing::Values( ...@@ -152,3 +155,5 @@ INSTANTIATE_TEST_CASE_P(All, InvalidPragmaTest, testing::Values(
"#pragma foo(bar\n", // Missing right paren. "#pragma foo(bar\n", // Missing right paren.
"#pragma foo bar\n", // Missing parens. "#pragma foo bar\n", // Missing parens.
"#pragma foo(bar) baz\n")); // Extra tokens. "#pragma foo(bar) baz\n")); // Extra tokens.
} // namespace angle
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class SpaceTest : public PreprocessorTest class SpaceTest : public PreprocessorTest
{ {
protected: protected:
...@@ -106,3 +109,5 @@ TEST_F(SpaceTest, LeadingSpace) ...@@ -106,3 +109,5 @@ TEST_F(SpaceTest, LeadingSpace)
EXPECT_EQ("bar", token.text); EXPECT_EQ("bar", token.text);
EXPECT_FALSE(token.hasLeadingSpace()); EXPECT_FALSE(token.hasLeadingSpace());
} }
} // namespace angle
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
TEST(TokenTest, DefaultConstructor) TEST(TokenTest, DefaultConstructor)
{ {
pp::Token token; pp::Token token;
...@@ -88,3 +91,5 @@ TEST(TokenTest, Write) ...@@ -88,3 +91,5 @@ TEST(TokenTest, Write)
EXPECT_TRUE(out2.good()); EXPECT_TRUE(out2.good());
EXPECT_EQ(" foo", out2.str()); EXPECT_EQ(" foo", out2.str());
} }
} // namespace angle
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include "PreprocessorTest.h" #include "PreprocessorTest.h"
#include "compiler/preprocessor/Token.h" #include "compiler/preprocessor/Token.h"
namespace angle
{
class VersionTest : public SimplePreprocessorTest class VersionTest : public SimplePreprocessorTest
{ {
}; };
...@@ -202,3 +205,5 @@ static const VersionTestParam kParams[] = { ...@@ -202,3 +205,5 @@ static const VersionTestParam kParams[] = {
}; };
INSTANTIATE_TEST_CASE_P(All, InvalidVersionTest, testing::ValuesIn(kParams)); INSTANTIATE_TEST_CASE_P(All, InvalidVersionTest, testing::ValuesIn(kParams));
} // namespace angle
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