Commit 054f7ed0 by Corentin Wallez Committed by Commit Bot

preprocessor: Miscellaneous cleanups

- Use full header paths in includes - Use ASSERT instead of assert - Use angle::NonCopyable instead of PP_DISALLOW_COPY_AND_ASSIGN - Use range-for in a couple places - Remove pp_utils.h BUG=angleproject:1522 Change-Id: If107fef89e8465bca65cf664926d1051c5d1e232 Reviewed-on: https://chromium-review.googlesource.com/387212 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 6a0e4e52
...@@ -112,6 +112,10 @@ static_library("preprocessor") { ...@@ -112,6 +112,10 @@ static_library("preprocessor") {
configs -= angle_undefine_configs configs -= angle_undefine_configs
configs += [ ":internal_config" ] configs += [ ":internal_config" ]
public_deps = [
":angle_common",
]
} }
config("translator_static_config") { config("translator_static_config") {
......
...@@ -156,6 +156,14 @@ size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char> ...@@ -156,6 +156,14 @@ size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char>
std::string FormatString(const char *fmt, va_list vararg); std::string FormatString(const char *fmt, va_list vararg);
std::string FormatString(const char *fmt, ...); std::string FormatString(const char *fmt, ...);
template <typename T>
std::string ToString(const T &value)
{
std::ostringstream o;
o << value;
return o.str();
}
// snprintf is not defined with MSVC prior to to msvc14 // snprintf is not defined with MSVC prior to to msvc14
#if defined(_MSC_VER) && _MSC_VER < 1900 #if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf #define snprintf _snprintf
......
...@@ -234,7 +234,6 @@ ...@@ -234,7 +234,6 @@
'compiler/preprocessor/Tokenizer.h', 'compiler/preprocessor/Tokenizer.h',
'compiler/preprocessor/Tokenizer.l', 'compiler/preprocessor/Tokenizer.l',
'compiler/preprocessor/numeric_lex.h', 'compiler/preprocessor/numeric_lex.h',
'compiler/preprocessor/pp_utils.h',
], ],
}, },
# Everything below this is duplicated in the GN build. If you change # Everything below this is duplicated in the GN build. If you change
...@@ -244,6 +243,7 @@ ...@@ -244,6 +243,7 @@
{ {
'target_name': 'preprocessor', 'target_name': 'preprocessor',
'type': 'static_library', 'type': 'static_library',
'dependencies': [ 'angle_common' ],
'includes': [ '../build/common_defines.gypi', ], 'includes': [ '../build/common_defines.gypi', ],
'sources': [ '<@(angle_preprocessor_sources)', ], 'sources': [ '<@(angle_preprocessor_sources)', ],
}, },
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "DiagnosticsBase.h" #include "compiler/preprocessor/DiagnosticsBase.h"
#include <cassert> #include "common/debug.h"
namespace pp namespace pp
{ {
...@@ -31,7 +31,7 @@ Diagnostics::Severity Diagnostics::severity(ID id) ...@@ -31,7 +31,7 @@ Diagnostics::Severity Diagnostics::severity(ID id)
if ((id > PP_WARNING_BEGIN) && (id < PP_WARNING_END)) if ((id > PP_WARNING_BEGIN) && (id < PP_WARNING_END))
return PP_WARNING; return PP_WARNING;
assert(false); UNREACHABLE();
return PP_ERROR; return PP_ERROR;
} }
...@@ -133,8 +133,8 @@ std::string Diagnostics::message(ID id) ...@@ -133,8 +133,8 @@ std::string Diagnostics::message(ID id)
return "macro name with a double underscore is reserved - unintented behavior is possible"; return "macro name with a double underscore is reserved - unintented behavior is possible";
// Warnings end. // Warnings end.
default: default:
assert(false); UNREACHABLE();
return ""; return "";
} }
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "DirectiveHandlerBase.h" #include "compiler/preprocessor/DirectiveHandlerBase.h"
namespace pp namespace pp
{ {
......
...@@ -4,19 +4,19 @@ ...@@ -4,19 +4,19 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "DirectiveParser.h" #include "compiler/preprocessor/DirectiveParser.h"
#include <algorithm> #include <algorithm>
#include <cassert>
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
#include "DiagnosticsBase.h" #include "common/debug.h"
#include "DirectiveHandlerBase.h" #include "compiler/preprocessor/DiagnosticsBase.h"
#include "ExpressionParser.h" #include "compiler/preprocessor/DirectiveHandlerBase.h"
#include "MacroExpander.h" #include "compiler/preprocessor/ExpressionParser.h"
#include "Token.h" #include "compiler/preprocessor/MacroExpander.h"
#include "Tokenizer.h" #include "compiler/preprocessor/Token.h"
#include "compiler/preprocessor/Tokenizer.h"
namespace { namespace {
enum DirectiveType enum DirectiveType
...@@ -248,7 +248,7 @@ void DirectiveParser::lex(Token *token) ...@@ -248,7 +248,7 @@ void DirectiveParser::lex(Token *token)
void DirectiveParser::parseDirective(Token *token) void DirectiveParser::parseDirective(Token *token)
{ {
assert(token->type == Token::PP_HASH); ASSERT(token->type == Token::PP_HASH);
mTokenizer->lex(token); mTokenizer->lex(token);
if (isEOD(token)) if (isEOD(token))
...@@ -314,8 +314,8 @@ void DirectiveParser::parseDirective(Token *token) ...@@ -314,8 +314,8 @@ void DirectiveParser::parseDirective(Token *token)
parseLine(token); parseLine(token);
break; break;
default: default:
assert(false); UNREACHABLE();
break; break;
} }
skipUntilEOD(mTokenizer, token); skipUntilEOD(mTokenizer, token);
...@@ -328,7 +328,7 @@ void DirectiveParser::parseDirective(Token *token) ...@@ -328,7 +328,7 @@ void DirectiveParser::parseDirective(Token *token)
void DirectiveParser::parseDefine(Token *token) void DirectiveParser::parseDefine(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_DEFINE); ASSERT(getDirective(token) == DIRECTIVE_DEFINE);
mTokenizer->lex(token); mTokenizer->lex(token);
if (token->type != Token::IDENTIFIER) if (token->type != Token::IDENTIFIER)
...@@ -428,7 +428,7 @@ void DirectiveParser::parseDefine(Token *token) ...@@ -428,7 +428,7 @@ void DirectiveParser::parseDefine(Token *token)
void DirectiveParser::parseUndef(Token *token) void DirectiveParser::parseUndef(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_UNDEF); ASSERT(getDirective(token) == DIRECTIVE_UNDEF);
mTokenizer->lex(token); mTokenizer->lex(token);
if (token->type != Token::IDENTIFIER) if (token->type != Token::IDENTIFIER)
...@@ -470,25 +470,25 @@ void DirectiveParser::parseUndef(Token *token) ...@@ -470,25 +470,25 @@ void DirectiveParser::parseUndef(Token *token)
void DirectiveParser::parseIf(Token *token) void DirectiveParser::parseIf(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_IF); ASSERT(getDirective(token) == DIRECTIVE_IF);
parseConditionalIf(token); parseConditionalIf(token);
} }
void DirectiveParser::parseIfdef(Token *token) void DirectiveParser::parseIfdef(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_IFDEF); ASSERT(getDirective(token) == DIRECTIVE_IFDEF);
parseConditionalIf(token); parseConditionalIf(token);
} }
void DirectiveParser::parseIfndef(Token *token) void DirectiveParser::parseIfndef(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_IFNDEF); ASSERT(getDirective(token) == DIRECTIVE_IFNDEF);
parseConditionalIf(token); parseConditionalIf(token);
} }
void DirectiveParser::parseElse(Token *token) void DirectiveParser::parseElse(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_ELSE); ASSERT(getDirective(token) == DIRECTIVE_ELSE);
if (mConditionalStack.empty()) if (mConditionalStack.empty())
{ {
...@@ -529,7 +529,7 @@ void DirectiveParser::parseElse(Token *token) ...@@ -529,7 +529,7 @@ void DirectiveParser::parseElse(Token *token)
void DirectiveParser::parseElif(Token *token) void DirectiveParser::parseElif(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_ELIF); ASSERT(getDirective(token) == DIRECTIVE_ELIF);
if (mConditionalStack.empty()) if (mConditionalStack.empty())
{ {
...@@ -569,7 +569,7 @@ void DirectiveParser::parseElif(Token *token) ...@@ -569,7 +569,7 @@ void DirectiveParser::parseElif(Token *token)
void DirectiveParser::parseEndif(Token *token) void DirectiveParser::parseEndif(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_ENDIF); ASSERT(getDirective(token) == DIRECTIVE_ENDIF);
if (mConditionalStack.empty()) if (mConditionalStack.empty())
{ {
...@@ -593,7 +593,7 @@ void DirectiveParser::parseEndif(Token *token) ...@@ -593,7 +593,7 @@ void DirectiveParser::parseEndif(Token *token)
void DirectiveParser::parseError(Token *token) void DirectiveParser::parseError(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_ERROR); ASSERT(getDirective(token) == DIRECTIVE_ERROR);
std::ostringstream stream; std::ostringstream stream;
mTokenizer->lex(token); mTokenizer->lex(token);
...@@ -608,7 +608,7 @@ void DirectiveParser::parseError(Token *token) ...@@ -608,7 +608,7 @@ void DirectiveParser::parseError(Token *token)
// Parses pragma of form: #pragma name[(value)]. // Parses pragma of form: #pragma name[(value)].
void DirectiveParser::parsePragma(Token *token) void DirectiveParser::parsePragma(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_PRAGMA); ASSERT(getDirective(token) == DIRECTIVE_PRAGMA);
enum State enum State
{ {
...@@ -669,7 +669,7 @@ void DirectiveParser::parsePragma(Token *token) ...@@ -669,7 +669,7 @@ void DirectiveParser::parsePragma(Token *token)
void DirectiveParser::parseExtension(Token *token) void DirectiveParser::parseExtension(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_EXTENSION); ASSERT(getDirective(token) == DIRECTIVE_EXTENSION);
enum State enum State
{ {
...@@ -750,7 +750,7 @@ void DirectiveParser::parseExtension(Token *token) ...@@ -750,7 +750,7 @@ void DirectiveParser::parseExtension(Token *token)
void DirectiveParser::parseVersion(Token *token) void DirectiveParser::parseVersion(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_VERSION); ASSERT(getDirective(token) == DIRECTIVE_VERSION);
if (mPastFirstStatement) if (mPastFirstStatement)
{ {
...@@ -837,7 +837,7 @@ void DirectiveParser::parseVersion(Token *token) ...@@ -837,7 +837,7 @@ void DirectiveParser::parseVersion(Token *token)
void DirectiveParser::parseLine(Token *token) void DirectiveParser::parseLine(Token *token)
{ {
assert(getDirective(token) == DIRECTIVE_LINE); ASSERT(getDirective(token) == DIRECTIVE_LINE);
bool valid = true; bool valid = true;
bool parsedFileNumber = false; bool parsedFileNumber = false;
...@@ -938,8 +938,8 @@ void DirectiveParser::parseConditionalIf(Token *token) ...@@ -938,8 +938,8 @@ void DirectiveParser::parseConditionalIf(Token *token)
expression = parseExpressionIfdef(token) == 0 ? 1 : 0; expression = parseExpressionIfdef(token) == 0 ? 1 : 0;
break; break;
default: default:
assert(false); UNREACHABLE();
break; break;
} }
block.skipGroup = expression == 0; block.skipGroup = expression == 0;
block.foundValidGroup = expression != 0; block.foundValidGroup = expression != 0;
...@@ -949,8 +949,7 @@ void DirectiveParser::parseConditionalIf(Token *token) ...@@ -949,8 +949,7 @@ void DirectiveParser::parseConditionalIf(Token *token)
int DirectiveParser::parseExpressionIf(Token *token) int DirectiveParser::parseExpressionIf(Token *token)
{ {
assert((getDirective(token) == DIRECTIVE_IF) || ASSERT((getDirective(token) == DIRECTIVE_IF) || (getDirective(token) == DIRECTIVE_ELIF));
(getDirective(token) == DIRECTIVE_ELIF));
DefinedParser definedParser(mTokenizer, mMacroSet, mDiagnostics); DefinedParser definedParser(mTokenizer, mMacroSet, mDiagnostics);
MacroExpander macroExpander(&definedParser, mMacroSet, mDiagnostics); MacroExpander macroExpander(&definedParser, mMacroSet, mDiagnostics);
...@@ -977,8 +976,7 @@ int DirectiveParser::parseExpressionIf(Token *token) ...@@ -977,8 +976,7 @@ int DirectiveParser::parseExpressionIf(Token *token)
int DirectiveParser::parseExpressionIfdef(Token *token) int DirectiveParser::parseExpressionIfdef(Token *token)
{ {
assert((getDirective(token) == DIRECTIVE_IFDEF) || ASSERT((getDirective(token) == DIRECTIVE_IFDEF) || (getDirective(token) == DIRECTIVE_IFNDEF));
(getDirective(token) == DIRECTIVE_IFNDEF));
mTokenizer->lex(token); mTokenizer->lex(token);
if (token->type != Token::IDENTIFIER) if (token->type != Token::IDENTIFIER)
......
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
#ifndef COMPILER_PREPROCESSOR_DIRECTIVEPARSER_H_ #ifndef COMPILER_PREPROCESSOR_DIRECTIVEPARSER_H_
#define COMPILER_PREPROCESSOR_DIRECTIVEPARSER_H_ #define COMPILER_PREPROCESSOR_DIRECTIVEPARSER_H_
#include "Lexer.h" #include "compiler/preprocessor/Lexer.h"
#include "Macro.h" #include "compiler/preprocessor/Macro.h"
#include "pp_utils.h" #include "compiler/preprocessor/SourceLocation.h"
#include "SourceLocation.h"
namespace pp namespace pp
{ {
...@@ -30,7 +29,6 @@ class DirectiveParser : public Lexer ...@@ -30,7 +29,6 @@ class DirectiveParser : public Lexer
void lex(Token *token) override; void lex(Token *token) override;
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(DirectiveParser);
void parseDirective(Token *token); void parseDirective(Token *token);
void parseDefine(Token *token); void parseDefine(Token *token);
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#ifndef COMPILER_PREPROCESSOR_EXPRESSIONPARSER_H_ #ifndef COMPILER_PREPROCESSOR_EXPRESSIONPARSER_H_
#define COMPILER_PREPROCESSOR_EXPRESSIONPARSER_H_ #define COMPILER_PREPROCESSOR_EXPRESSIONPARSER_H_
#include "DiagnosticsBase.h" #include "common/angleutils.h"
#include "pp_utils.h" #include "compiler/preprocessor/DiagnosticsBase.h"
namespace pp namespace pp
{ {
...@@ -16,7 +16,7 @@ namespace pp ...@@ -16,7 +16,7 @@ namespace pp
class Lexer; class Lexer;
struct Token; struct Token;
class ExpressionParser class ExpressionParser : angle::NonCopyable
{ {
public: public:
struct ErrorSettings struct ErrorSettings
...@@ -34,8 +34,6 @@ class ExpressionParser ...@@ -34,8 +34,6 @@ class ExpressionParser
bool *valid); bool *valid);
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(ExpressionParser);
Lexer *mLexer; Lexer *mLexer;
Diagnostics *mDiagnostics; Diagnostics *mDiagnostics;
}; };
......
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "Input.h" #include "compiler/preprocessor/Input.h"
#include <algorithm> #include <algorithm>
#include <cassert>
#include <cstring> #include <cstring>
#include "common/debug.h"
namespace pp namespace pp
{ {
...@@ -32,7 +33,7 @@ Input::Input(size_t count, const char *const string[], const int length[]) : ...@@ -32,7 +33,7 @@ Input::Input(size_t count, const char *const string[], const int length[]) :
const char *Input::skipChar() const char *Input::skipChar()
{ {
// This function should only be called when there is a character to skip. // This function should only be called when there is a character to skip.
assert(mReadLoc.cIndex < mLength[mReadLoc.sIndex]); ASSERT(mReadLoc.cIndex < mLength[mReadLoc.sIndex]);
++mReadLoc.cIndex; ++mReadLoc.cIndex;
if (mReadLoc.cIndex == mLength[mReadLoc.sIndex]) if (mReadLoc.cIndex == mLength[mReadLoc.sIndex])
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMPILER_PREPROCESSOR_INPUT_H_ #ifndef COMPILER_PREPROCESSOR_INPUT_H_
#define COMPILER_PREPROCESSOR_INPUT_H_ #define COMPILER_PREPROCESSOR_INPUT_H_
#include <stddef.h> #include <cstddef>
#include <vector> #include <vector>
namespace pp namespace pp
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "Lexer.h" #include "compiler/preprocessor/Lexer.h"
namespace pp namespace pp
{ {
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
#ifndef COMPILER_PREPROCESSOR_LEXER_H_ #ifndef COMPILER_PREPROCESSOR_LEXER_H_
#define COMPILER_PREPROCESSOR_LEXER_H_ #define COMPILER_PREPROCESSOR_LEXER_H_
#include "common/angleutils.h"
namespace pp namespace pp
{ {
struct Token; struct Token;
class Lexer class Lexer : angle::NonCopyable
{ {
public: public:
virtual ~Lexer(); virtual ~Lexer();
......
...@@ -4,11 +4,10 @@ ...@@ -4,11 +4,10 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "Macro.h" #include "compiler/preprocessor/Macro.h"
#include <sstream> #include "common/angleutils.h"
#include "compiler/preprocessor/Token.h"
#include "Token.h"
namespace pp namespace pp
{ {
...@@ -23,12 +22,9 @@ bool Macro::equals(const Macro &other) const ...@@ -23,12 +22,9 @@ bool Macro::equals(const Macro &other) const
void PredefineMacro(MacroSet *macroSet, const char *name, int value) void PredefineMacro(MacroSet *macroSet, const char *name, int value)
{ {
std::ostringstream stream;
stream << value;
Token token; Token token;
token.type = Token::CONST_INT; token.type = Token::CONST_INT;
token.text = stream.str(); token.text = ToString(value);
Macro macro; Macro macro;
macro.predefined = true; macro.predefined = true;
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "MacroExpander.h" #include "compiler/preprocessor/MacroExpander.h"
#include <algorithm> #include <algorithm>
#include <sstream>
#include "DiagnosticsBase.h" #include "common/debug.h"
#include "Token.h" #include "compiler/preprocessor/DiagnosticsBase.h"
#include "compiler/preprocessor/Token.h"
namespace pp namespace pp
{ {
...@@ -45,8 +45,6 @@ class TokenLexer : public Lexer ...@@ -45,8 +45,6 @@ class TokenLexer : public Lexer
} }
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(TokenLexer);
TokenVector mTokens; TokenVector mTokens;
TokenVector::const_iterator mIter; TokenVector::const_iterator mIter;
}; };
...@@ -60,9 +58,9 @@ MacroExpander::MacroExpander(Lexer *lexer, MacroSet *macroSet, Diagnostics *diag ...@@ -60,9 +58,9 @@ MacroExpander::MacroExpander(Lexer *lexer, MacroSet *macroSet, Diagnostics *diag
MacroExpander::~MacroExpander() MacroExpander::~MacroExpander()
{ {
for (std::size_t i = 0; i < mContextStack.size(); ++i) for (MacroContext *context : mContextStack)
{ {
delete mContextStack[i]; delete context;
} }
} }
...@@ -121,7 +119,7 @@ void MacroExpander::getToken(Token *token) ...@@ -121,7 +119,7 @@ void MacroExpander::getToken(Token *token)
} }
else else
{ {
assert(mTotalTokensInContexts == 0); ASSERT(mTotalTokensInContexts == 0);
mLexer->lex(token); mLexer->lex(token);
} }
} }
...@@ -132,11 +130,11 @@ void MacroExpander::ungetToken(const Token &token) ...@@ -132,11 +130,11 @@ void MacroExpander::ungetToken(const Token &token)
{ {
MacroContext *context = mContextStack.back(); MacroContext *context = mContextStack.back();
context->unget(); context->unget();
assert(context->replacements[context->index] == token); ASSERT(context->replacements[context->index] == token);
} }
else else
{ {
assert(!mReserveToken.get()); ASSERT(!mReserveToken.get());
mReserveToken.reset(new Token(token)); mReserveToken.reset(new Token(token));
} }
} }
...@@ -154,10 +152,10 @@ bool MacroExpander::isNextTokenLeftParen() ...@@ -154,10 +152,10 @@ bool MacroExpander::isNextTokenLeftParen()
bool MacroExpander::pushMacro(const Macro &macro, const Token &identifier) bool MacroExpander::pushMacro(const Macro &macro, const Token &identifier)
{ {
assert(!macro.disabled); ASSERT(!macro.disabled);
assert(!identifier.expansionDisabled()); ASSERT(!identifier.expansionDisabled());
assert(identifier.type == Token::IDENTIFIER); ASSERT(identifier.type == Token::IDENTIFIER);
assert(identifier.text == macro.name); ASSERT(identifier.text == macro.name);
macro.expansionCount++; macro.expansionCount++;
...@@ -178,14 +176,14 @@ bool MacroExpander::pushMacro(const Macro &macro, const Token &identifier) ...@@ -178,14 +176,14 @@ bool MacroExpander::pushMacro(const Macro &macro, const Token &identifier)
void MacroExpander::popMacro() void MacroExpander::popMacro()
{ {
assert(!mContextStack.empty()); ASSERT(!mContextStack.empty());
MacroContext *context = mContextStack.back(); MacroContext *context = mContextStack.back();
mContextStack.pop_back(); mContextStack.pop_back();
assert(context->empty()); ASSERT(context->empty());
assert(context->macro->disabled); ASSERT(context->macro->disabled);
assert(context->macro->expansionCount > 0); ASSERT(context->macro->expansionCount > 0);
context->macro->disabled = false; context->macro->disabled = false;
context->macro->expansionCount--; context->macro->expansionCount--;
mTotalTokensInContexts -= context->replacements.size(); mTotalTokensInContexts -= context->replacements.size();
...@@ -213,25 +211,21 @@ bool MacroExpander::expandMacro(const Macro &macro, ...@@ -213,25 +211,21 @@ bool MacroExpander::expandMacro(const Macro &macro,
const char kLine[] = "__LINE__"; const char kLine[] = "__LINE__";
const char kFile[] = "__FILE__"; const char kFile[] = "__FILE__";
assert(replacements->size() == 1); ASSERT(replacements->size() == 1);
Token& repl = replacements->front(); Token& repl = replacements->front();
if (macro.name == kLine) if (macro.name == kLine)
{ {
std::ostringstream stream; repl.text = ToString(identifier.location.line);
stream << identifier.location.line;
repl.text = stream.str();
} }
else if (macro.name == kFile) else if (macro.name == kFile)
{ {
std::ostringstream stream; repl.text = ToString(identifier.location.file);
stream << identifier.location.file;
repl.text = stream.str();
} }
} }
} }
else else
{ {
assert(macro.type == Macro::kTypeFunc); ASSERT(macro.type == Macro::kTypeFunc);
std::vector<MacroArg> args; std::vector<MacroArg> args;
args.reserve(macro.parameters.size()); args.reserve(macro.parameters.size());
if (!collectMacroArgs(macro, identifier, &args, &replacementLocation)) if (!collectMacroArgs(macro, identifier, &args, &replacementLocation))
...@@ -262,10 +256,12 @@ bool MacroExpander::collectMacroArgs(const Macro &macro, ...@@ -262,10 +256,12 @@ bool MacroExpander::collectMacroArgs(const Macro &macro,
{ {
Token token; Token token;
getToken(&token); getToken(&token);
assert(token.type == '('); ASSERT(token.type == '(');
args->push_back(MacroArg()); args->push_back(MacroArg());
for (int openParens = 1; openParens != 0; )
int openParens = 1;
while (openParens != 0)
{ {
getToken(&token); getToken(&token);
...@@ -332,9 +328,8 @@ bool MacroExpander::collectMacroArgs(const Macro &macro, ...@@ -332,9 +328,8 @@ bool MacroExpander::collectMacroArgs(const Macro &macro,
// This step expands each argument individually before they are // This step expands each argument individually before they are
// inserted into the macro body. // inserted into the macro body.
size_t numTokens = 0; size_t numTokens = 0;
for (std::size_t i = 0; i < args->size(); ++i) for (auto &arg : *args)
{ {
MacroArg &arg = args->at(i);
TokenLexer lexer(&arg); TokenLexer lexer(&arg);
MacroExpander expander(&lexer, mMacroSet, mDiagnostics); MacroExpander expander(&lexer, mMacroSet, mDiagnostics);
...@@ -401,5 +396,25 @@ void MacroExpander::replaceMacroParams(const Macro &macro, ...@@ -401,5 +396,25 @@ void MacroExpander::replaceMacroParams(const Macro &macro,
} }
} }
MacroExpander::MacroContext::MacroContext() : macro(0), index(0)
{
}
bool MacroExpander::MacroContext::empty() const
{
return index == replacements.size();
}
const Token &MacroExpander::MacroContext::get()
{
return replacements[index++];
}
void MacroExpander::MacroContext::unget()
{
ASSERT(index > 0);
--index;
}
} // namespace pp } // namespace pp
...@@ -7,13 +7,11 @@ ...@@ -7,13 +7,11 @@
#ifndef COMPILER_PREPROCESSOR_MACROEXPANDER_H_ #ifndef COMPILER_PREPROCESSOR_MACROEXPANDER_H_
#define COMPILER_PREPROCESSOR_MACROEXPANDER_H_ #define COMPILER_PREPROCESSOR_MACROEXPANDER_H_
#include <cassert>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "Lexer.h" #include "compiler/preprocessor/Lexer.h"
#include "Macro.h" #include "compiler/preprocessor/Macro.h"
#include "pp_utils.h"
namespace pp namespace pp
{ {
...@@ -30,8 +28,6 @@ class MacroExpander : public Lexer ...@@ -30,8 +28,6 @@ class MacroExpander : public Lexer
void lex(Token *token) override; void lex(Token *token) override;
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(MacroExpander);
void getToken(Token *token); void getToken(Token *token);
void ungetToken(const Token &token); void ungetToken(const Token &token);
bool isNextTokenLeftParen(); bool isNextTokenLeftParen();
...@@ -54,28 +50,14 @@ class MacroExpander : public Lexer ...@@ -54,28 +50,14 @@ class MacroExpander : public Lexer
struct MacroContext struct MacroContext
{ {
MacroContext();
bool empty() const;
const Token &get();
void unget();
const Macro *macro; const Macro *macro;
std::size_t index; std::size_t index;
std::vector<Token> replacements; std::vector<Token> replacements;
MacroContext()
: macro(0),
index(0)
{
}
bool empty() const
{
return index == replacements.size();
}
const Token &get()
{
return replacements[index++];
}
void unget()
{
assert(index > 0);
--index;
}
}; };
Lexer *mLexer; Lexer *mLexer;
......
...@@ -4,16 +4,15 @@ ...@@ -4,16 +4,15 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "Preprocessor.h" #include "compiler/preprocessor/Preprocessor.h"
#include <cassert> #include "common/debug.h"
#include "compiler/preprocessor/DiagnosticsBase.h"
#include "DiagnosticsBase.h" #include "compiler/preprocessor/DirectiveParser.h"
#include "DirectiveParser.h" #include "compiler/preprocessor/Macro.h"
#include "Macro.h" #include "compiler/preprocessor/MacroExpander.h"
#include "MacroExpander.h" #include "compiler/preprocessor/Token.h"
#include "Token.h" #include "compiler/preprocessor/Tokenizer.h"
#include "Tokenizer.h"
namespace pp namespace pp
{ {
...@@ -78,8 +77,8 @@ void Preprocessor::lex(Token *token) ...@@ -78,8 +77,8 @@ void Preprocessor::lex(Token *token)
// Convert preprocessing tokens to compiler tokens or report // Convert preprocessing tokens to compiler tokens or report
// diagnostics. // diagnostics.
case Token::PP_HASH: case Token::PP_HASH:
assert(false); UNREACHABLE();
break; break;
case Token::PP_NUMBER: case Token::PP_NUMBER:
mImpl->diagnostics->report(Diagnostics::PP_INVALID_NUMBER, mImpl->diagnostics->report(Diagnostics::PP_INVALID_NUMBER,
token->location, token->text); token->location, token->text);
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#ifndef COMPILER_PREPROCESSOR_PREPROCESSOR_H_ #ifndef COMPILER_PREPROCESSOR_PREPROCESSOR_H_
#define COMPILER_PREPROCESSOR_PREPROCESSOR_H_ #define COMPILER_PREPROCESSOR_PREPROCESSOR_H_
#include <stddef.h> #include <cstddef>
#include "pp_utils.h" #include "common/angleutils.h"
namespace pp namespace pp
{ {
...@@ -19,7 +19,7 @@ class DirectiveHandler; ...@@ -19,7 +19,7 @@ class DirectiveHandler;
struct PreprocessorImpl; struct PreprocessorImpl;
struct Token; struct Token;
class Preprocessor class Preprocessor : angle::NonCopyable
{ {
public: public:
Preprocessor(Diagnostics *diagnostics, DirectiveHandler *directiveHandler); Preprocessor(Diagnostics *diagnostics, DirectiveHandler *directiveHandler);
...@@ -44,8 +44,6 @@ class Preprocessor ...@@ -44,8 +44,6 @@ class Preprocessor
void setMaxTokenSize(size_t maxTokenSize); void setMaxTokenSize(size_t maxTokenSize);
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(Preprocessor);
PreprocessorImpl *mImpl; PreprocessorImpl *mImpl;
}; };
......
...@@ -4,11 +4,10 @@ ...@@ -4,11 +4,10 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "Token.h" #include "compiler/preprocessor/Token.h"
#include <cassert> #include "common/debug.h"
#include "compiler/preprocessor/numeric_lex.h"
#include "numeric_lex.h"
namespace pp namespace pp
{ {
...@@ -55,19 +54,19 @@ void Token::setExpansionDisabled(bool disable) ...@@ -55,19 +54,19 @@ void Token::setExpansionDisabled(bool disable)
bool Token::iValue(int *value) const bool Token::iValue(int *value) const
{ {
assert(type == CONST_INT); ASSERT(type == CONST_INT);
return numeric_lex_int(text, value); return numeric_lex_int(text, value);
} }
bool Token::uValue(unsigned int *value) const bool Token::uValue(unsigned int *value) const
{ {
assert(type == CONST_INT); ASSERT(type == CONST_INT);
return numeric_lex_int(text, value); return numeric_lex_int(text, value);
} }
bool Token::fValue(float *value) const bool Token::fValue(float *value) const
{ {
assert(type == CONST_FLOAT); ASSERT(type == CONST_FLOAT);
return numeric_lex_float(text, value); return numeric_lex_float(text, value);
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
#include "SourceLocation.h" #include "compiler/preprocessor/SourceLocation.h"
namespace pp namespace pp
{ {
...@@ -113,7 +113,7 @@ inline bool operator!=(const Token &lhs, const Token &rhs) ...@@ -113,7 +113,7 @@ inline bool operator!=(const Token &lhs, const Token &rhs)
return !lhs.equals(rhs); return !lhs.equals(rhs);
} }
extern std::ostream &operator<<(std::ostream &out, const Token &token); std::ostream &operator<<(std::ostream &out, const Token &token);
} // namepsace pp } // namepsace pp
......
...@@ -720,10 +720,10 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -720,10 +720,10 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#pragma warning(disable: 4005) #pragma warning(disable: 4005)
#endif #endif
#include "Tokenizer.h" #include "compiler/preprocessor/Tokenizer.h"
#include "DiagnosticsBase.h" #include "compiler/preprocessor/DiagnosticsBase.h"
#include "Token.h" #include "compiler/preprocessor/Token.h"
#if defined(__GNUC__) #if defined(__GNUC__)
// Triggered by the auto-generated yy_fatal_error function. // Triggered by the auto-generated yy_fatal_error function.
...@@ -2794,9 +2794,7 @@ void ppfree (void * ptr , yyscan_t yyscanner) ...@@ -2794,9 +2794,7 @@ void ppfree (void * ptr , yyscan_t yyscanner)
namespace pp { namespace pp {
Tokenizer::Tokenizer(Diagnostics *diagnostics) Tokenizer::Tokenizer(Diagnostics *diagnostics) : mHandle(nullptr), mMaxTokenSize(256)
: mHandle(0),
mMaxTokenSize(256)
{ {
mContext.diagnostics = diagnostics; mContext.diagnostics = diagnostics;
} }
...@@ -2853,7 +2851,7 @@ void Tokenizer::lex(Token *token) ...@@ -2853,7 +2851,7 @@ void Tokenizer::lex(Token *token)
bool Tokenizer::initScanner() bool Tokenizer::initScanner()
{ {
if ((mHandle == NULL) && pplex_init_extra(&mContext,&mHandle)) if ((mHandle == nullptr) && pplex_init_extra(&mContext, &mHandle))
return false; return false;
pprestart(0,mHandle); pprestart(0,mHandle);
...@@ -2862,11 +2860,11 @@ bool Tokenizer::initScanner() ...@@ -2862,11 +2860,11 @@ bool Tokenizer::initScanner()
void Tokenizer::destroyScanner() void Tokenizer::destroyScanner()
{ {
if (mHandle == NULL) if (mHandle == nullptr)
return; return;
pplex_destroy(mHandle); pplex_destroy(mHandle);
mHandle = NULL; mHandle = nullptr;
} }
} // namespace pp } // namespace pp
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#ifndef COMPILER_PREPROCESSOR_TOKENIZER_H_ #ifndef COMPILER_PREPROCESSOR_TOKENIZER_H_
#define COMPILER_PREPROCESSOR_TOKENIZER_H_ #define COMPILER_PREPROCESSOR_TOKENIZER_H_
#include "Input.h" #include "common/angleutils.h"
#include "Lexer.h" #include "compiler/preprocessor/Input.h"
#include "pp_utils.h" #include "compiler/preprocessor/Lexer.h"
namespace pp namespace pp
{ {
...@@ -45,7 +45,6 @@ class Tokenizer : public Lexer ...@@ -45,7 +45,6 @@ class Tokenizer : public Lexer
void lex(Token *token) override; void lex(Token *token) override;
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(Tokenizer);
bool initScanner(); bool initScanner();
void destroyScanner(); void destroyScanner();
......
...@@ -27,10 +27,10 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -27,10 +27,10 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#pragma warning(disable: 4005) #pragma warning(disable: 4005)
#endif #endif
#include "Tokenizer.h" #include "compiler/preprocessor/Tokenizer.h"
#include "DiagnosticsBase.h" #include "compiler/preprocessor/DiagnosticsBase.h"
#include "Token.h" #include "compiler/preprocessor/Token.h"
#if defined(__GNUC__) #if defined(__GNUC__)
// Triggered by the auto-generated yy_fatal_error function. // Triggered by the auto-generated yy_fatal_error function.
...@@ -280,9 +280,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -280,9 +280,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
namespace pp { namespace pp {
Tokenizer::Tokenizer(Diagnostics *diagnostics) Tokenizer::Tokenizer(Diagnostics *diagnostics) : mHandle(nullptr), mMaxTokenSize(256)
: mHandle(0),
mMaxTokenSize(256)
{ {
mContext.diagnostics = diagnostics; mContext.diagnostics = diagnostics;
} }
...@@ -339,7 +337,7 @@ void Tokenizer::lex(Token *token) ...@@ -339,7 +337,7 @@ void Tokenizer::lex(Token *token)
bool Tokenizer::initScanner() bool Tokenizer::initScanner()
{ {
if ((mHandle == NULL) && yylex_init_extra(&mContext, &mHandle)) if ((mHandle == nullptr) && yylex_init_extra(&mContext, &mHandle))
return false; return false;
yyrestart(0, mHandle); yyrestart(0, mHandle);
...@@ -348,11 +346,11 @@ bool Tokenizer::initScanner() ...@@ -348,11 +346,11 @@ bool Tokenizer::initScanner()
void Tokenizer::destroyScanner() void Tokenizer::destroyScanner()
{ {
if (mHandle == NULL) if (mHandle == nullptr)
return; return;
yylex_destroy(mHandle); yylex_destroy(mHandle);
mHandle = NULL; mHandle = nullptr;
} }
} // namespace pp } // namespace pp
......
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// pp_utils.h: Common preprocessor utilities
#ifndef COMPILER_PREPROCESSOR_PPUTILS_H_
#define COMPILER_PREPROCESSOR_PPUTILS_H_
// A macro to disallow the copy constructor and operator= functions
// This must be used in the private: declarations for a class.
#define PP_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName &); \
void operator=(const TypeName &)
#endif // COMPILER_PREPROCESSOR_PPUTILS_H_
...@@ -523,7 +523,7 @@ BindingInfo Program::getFragmentInputBindingInfo(GLint index) const ...@@ -523,7 +523,7 @@ BindingInfo Program::getFragmentInputBindingInfo(GLint index) const
if (arrayIndex == GL_INVALID_INDEX) if (arrayIndex == GL_INVALID_INDEX)
arrayIndex = 0; arrayIndex = 0;
ret.name = in.mappedName + "[" + std::to_string(arrayIndex) + "]"; ret.name = in.mappedName + "[" + ToString(arrayIndex) + "]";
} }
else else
{ {
......
...@@ -577,7 +577,7 @@ void ProgramGL::postLink() ...@@ -577,7 +577,7 @@ void ProgramGL::postLink()
for (GLint arrayIndex = 1; arrayIndex < arraySize; ++arrayIndex) for (GLint arrayIndex = 1; arrayIndex < arraySize; ++arrayIndex)
{ {
PathRenderingFragmentInput arrayElementInput; PathRenderingFragmentInput arrayElementInput;
arrayElementInput.name = name + "[" + std::to_string(arrayIndex) + "]"; arrayElementInput.name = name + "[" + ToString(arrayIndex) + "]";
arrayElementInput.location = baseLocation + arrayIndex; arrayElementInput.location = baseLocation + arrayIndex;
mPathRenderingFragmentInputs.push_back(std::move(arrayElementInput)); mPathRenderingFragmentInputs.push_back(std::move(arrayElementInput));
} }
......
...@@ -564,7 +564,7 @@ TEST_P(UniformTestES3, ReturnsOnlyOneArrayElement) ...@@ -564,7 +564,7 @@ TEST_P(UniformTestES3, ReturnsOnlyOneArrayElement)
for (const auto &array : uniformArrays) for (const auto &array : uniformArrays)
{ {
uniformStream << "uniform " << array.type << " " << array.name << "[" uniformStream << "uniform " << array.type << " " << array.name << "["
<< std::to_string(kArraySize) << "];\n"; << ToString(kArraySize) << "];\n";
// We need to make use of the uniforms or they get compiled out. // We need to make use of the uniforms or they get compiled out.
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
...@@ -610,7 +610,7 @@ TEST_P(UniformTestES3, ReturnsOnlyOneArrayElement) ...@@ -610,7 +610,7 @@ TEST_P(UniformTestES3, ReturnsOnlyOneArrayElement)
{ {
for (size_t index = 0; index < kArraySize; index++) for (size_t index = 0; index < kArraySize; index++)
{ {
std::string strIndex = "[" + std::to_string(index) + "]"; std::string strIndex = "[" + ToString(index) + "]";
// Check all the different glGetUniformv functions // Check all the different glGetUniformv functions
CheckOneElement<float>(glGetUniformfv, mProgram, uniformArray.name + strIndex, CheckOneElement<float>(glGetUniformfv, mProgram, uniformArray.name + strIndex,
uniformArray.components, 42.4242f); uniformArray.components, 42.4242f);
......
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