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