Commit f832c9dd by Jamie Madill Committed by Commit Bot

Fix style in the preprocessor.

Again using git cl format. BUG=angleproject:650 Change-Id: I8898d00bfc6a50db50bffd2cc30c3eda7c08c6c2 Reviewed-on: https://chromium-review.googlesource.com/419097Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent d7b1ab58
......@@ -15,9 +15,7 @@ Diagnostics::~Diagnostics()
{
}
void Diagnostics::report(ID id,
const SourceLocation &loc,
const std::string &text)
void Diagnostics::report(ID id, const SourceLocation &loc, const std::string &text)
{
// TODO(alokp): Keep a count of errors and warnings.
print(id, loc, text);
......@@ -132,7 +130,8 @@ std::string Diagnostics::message(ID id)
case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1:
return "extension directive should occur before any non-preprocessor tokens";
case PP_WARNING_MACRO_NAME_RESERVED:
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.
default:
UNREACHABLE();
......
......@@ -86,9 +86,7 @@ class Diagnostics
Severity severity(ID id);
std::string message(ID id);
virtual void print(ID id,
const SourceLocation &loc,
const std::string &text) = 0;
virtual void print(ID id, const SourceLocation &loc, const std::string &text) = 0;
};
} // namespace pp
......
......@@ -23,8 +23,7 @@ class DirectiveHandler
public:
virtual ~DirectiveHandler();
virtual void handleError(const SourceLocation &loc,
const std::string &msg) = 0;
virtual void handleError(const SourceLocation &loc, const std::string &msg) = 0;
// Handle pragma of form: #pragma name[(value)]
virtual void handlePragma(const SourceLocation &loc,
......@@ -36,8 +35,7 @@ class DirectiveHandler
const std::string &name,
const std::string &behavior) = 0;
virtual void handleVersion(const SourceLocation &loc,
int version) = 0;
virtual void handleVersion(const SourceLocation &loc, int version) = 0;
};
} // namespace pp
......
......@@ -18,7 +18,8 @@
#include "compiler/preprocessor/Token.h"
#include "compiler/preprocessor/Tokenizer.h"
namespace {
namespace
{
enum DirectiveType
{
DIRECTIVE_NONE,
......@@ -110,7 +111,7 @@ bool isEOD(const pp::Token *token)
void skipUntilEOD(pp::Lexer *lexer, pp::Token *token)
{
while(!isEOD(token))
while (!isEOD(token))
{
lexer->lex(token);
}
......@@ -127,8 +128,7 @@ bool hasDoubleUnderscores(const std::string &name)
return (name.find("__") != std::string::npos);
}
bool isMacroPredefined(const std::string &name,
const pp::MacroSet &macroSet)
bool isMacroPredefined(const std::string &name, const pp::MacroSet &macroSet)
{
pp::MacroSet::const_iterator iter = macroSet.find(name);
return iter != macroSet.end() ? iter->second.predefined : false;
......@@ -236,14 +236,13 @@ void DirectiveParser::lex(Token *token)
if (!mConditionalStack.empty())
{
const ConditionalBlock &block = mConditionalStack.back();
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNTERMINATED,
block.location, block.type);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNTERMINATED, block.location,
block.type);
}
break;
}
}
while (skipping() || (token->type == '\n'));
} while (skipping() || (token->type == '\n'));
mPastFirstStatement = true;
}
......@@ -269,11 +268,11 @@ void DirectiveParser::parseDirective(Token *token)
return;
}
switch(directive)
switch (directive)
{
case DIRECTIVE_NONE:
mDiagnostics->report(Diagnostics::PP_DIRECTIVE_INVALID_NAME,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_DIRECTIVE_INVALID_NAME, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
break;
case DIRECTIVE_DEFINE:
......@@ -323,8 +322,7 @@ void DirectiveParser::parseDirective(Token *token)
skipUntilEOD(mTokenizer, token);
if (token->type == Token::LAST)
{
mDiagnostics->report(Diagnostics::PP_EOF_IN_DIRECTIVE,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_EOF_IN_DIRECTIVE, token->location, token->text);
}
}
......@@ -335,20 +333,18 @@ void DirectiveParser::parseDefine(Token *token)
mTokenizer->lex(token);
if (token->type != Token::IDENTIFIER)
{
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location, token->text);
return;
}
if (isMacroPredefined(token->text, *mMacroSet))
{
mDiagnostics->report(Diagnostics::PP_MACRO_PREDEFINED_REDEFINED,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_MACRO_PREDEFINED_REDEFINED, token->location,
token->text);
return;
}
if (isMacroNameReserved(token->text))
{
mDiagnostics->report(Diagnostics::PP_MACRO_NAME_RESERVED,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_MACRO_NAME_RESERVED, token->location, token->text);
return;
}
// Using double underscores is allowed, but may result in unintended
......@@ -377,7 +373,8 @@ void DirectiveParser::parseDefine(Token *token)
if (token->type != Token::IDENTIFIER)
break;
if (std::find(macro.parameters.begin(), macro.parameters.end(), token->text) != macro.parameters.end())
if (std::find(macro.parameters.begin(), macro.parameters.end(), token->text) !=
macro.parameters.end())
{
mDiagnostics->report(Diagnostics::PP_MACRO_DUPLICATE_PARAMETER_NAMES,
token->location, token->text);
......@@ -387,14 +384,11 @@ void DirectiveParser::parseDefine(Token *token)
macro.parameters.push_back(token->text);
mTokenizer->lex(token); // Get ','.
}
while (token->type == ',');
} while (token->type == ',');
if (token->type != ')')
{
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location,
token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location, token->text);
return;
}
mTokenizer->lex(token); // Get ')'.
......@@ -420,9 +414,7 @@ void DirectiveParser::parseDefine(Token *token)
MacroSet::const_iterator iter = mMacroSet->find(macro.name);
if (iter != mMacroSet->end() && !macro.equals(iter->second))
{
mDiagnostics->report(Diagnostics::PP_MACRO_REDEFINED,
token->location,
macro.name);
mDiagnostics->report(Diagnostics::PP_MACRO_REDEFINED, token->location, macro.name);
return;
}
mMacroSet->insert(std::make_pair(macro.name, macro));
......@@ -435,8 +427,7 @@ void DirectiveParser::parseUndef(Token *token)
mTokenizer->lex(token);
if (token->type != Token::IDENTIFIER)
{
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location, token->text);
return;
}
......@@ -445,8 +436,8 @@ void DirectiveParser::parseUndef(Token *token)
{
if (iter->second.predefined)
{
mDiagnostics->report(Diagnostics::PP_MACRO_PREDEFINED_UNDEFINED,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_MACRO_PREDEFINED_UNDEFINED, token->location,
token->text);
return;
}
else if (iter->second.expansionCount > 0)
......@@ -464,8 +455,7 @@ void DirectiveParser::parseUndef(Token *token)
mTokenizer->lex(token);
if (!isEOD(token))
{
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location, token->text);
skipUntilEOD(mTokenizer, token);
}
}
......@@ -494,8 +484,8 @@ void DirectiveParser::parseElse(Token *token)
if (mConditionalStack.empty())
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ELSE_WITHOUT_IF,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ELSE_WITHOUT_IF, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
return;
}
......@@ -509,8 +499,8 @@ void DirectiveParser::parseElse(Token *token)
}
if (block.foundElseGroup)
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ELSE_AFTER_ELSE,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ELSE_AFTER_ELSE, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
return;
}
......@@ -523,8 +513,8 @@ void DirectiveParser::parseElse(Token *token)
mTokenizer->lex(token);
if (!isEOD(token))
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
}
}
......@@ -535,8 +525,8 @@ void DirectiveParser::parseElif(Token *token)
if (mConditionalStack.empty())
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ELIF_WITHOUT_IF,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ELIF_WITHOUT_IF, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
return;
}
......@@ -550,8 +540,8 @@ void DirectiveParser::parseElif(Token *token)
}
if (block.foundElseGroup)
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ELIF_AFTER_ELSE,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ELIF_AFTER_ELSE, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
return;
}
......@@ -575,8 +565,8 @@ void DirectiveParser::parseEndif(Token *token)
if (mConditionalStack.empty())
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ENDIF_WITHOUT_IF,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_ENDIF_WITHOUT_IF, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
return;
}
......@@ -587,8 +577,8 @@ void DirectiveParser::parseEndif(Token *token)
mTokenizer->lex(token);
if (!isEOD(token))
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
}
}
......@@ -632,7 +622,7 @@ void DirectiveParser::parsePragma(Token *token)
}
while ((token->type != '\n') && (token->type != Token::LAST))
{
switch(state++)
switch (state++)
{
case PRAGMA_NAME:
name = token->text;
......@@ -660,8 +650,7 @@ void DirectiveParser::parsePragma(Token *token)
(state == RIGHT_PAREN + 1)); // With value.
if (!valid)
{
mDiagnostics->report(Diagnostics::PP_UNRECOGNIZED_PRAGMA,
token->location, name);
mDiagnostics->report(Diagnostics::PP_UNRECOGNIZED_PRAGMA, token->location, name);
}
else if (state > PRAGMA_NAME) // Do not notify for empty pragma.
{
......@@ -692,17 +681,18 @@ void DirectiveParser::parseExtension(Token *token)
case EXT_NAME:
if (valid && (token->type != Token::IDENTIFIER))
{
mDiagnostics->report(Diagnostics::PP_INVALID_EXTENSION_NAME,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_INVALID_EXTENSION_NAME, token->location,
token->text);
valid = false;
}
if (valid) name = token->text;
if (valid)
name = token->text;
break;
case COLON:
if (valid && (token->type != ':'))
{
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location,
token->text);
valid = false;
}
break;
......@@ -713,13 +703,14 @@ void DirectiveParser::parseExtension(Token *token)
token->location, token->text);
valid = false;
}
if (valid) behavior = token->text;
if (valid)
behavior = token->text;
break;
default:
if (valid)
{
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location,
token->text);
valid = false;
}
break;
......@@ -728,8 +719,8 @@ void DirectiveParser::parseExtension(Token *token)
}
if (valid && (state != EXT_BEHAVIOR + 1))
{
mDiagnostics->report(Diagnostics::PP_INVALID_EXTENSION_DIRECTIVE,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_INVALID_EXTENSION_DIRECTIVE, token->location,
token->text);
valid = false;
}
if (valid && mSeenNonPreprocessorToken)
......@@ -756,8 +747,8 @@ void DirectiveParser::parseVersion(Token *token)
if (mPastFirstStatement)
{
mDiagnostics->report(Diagnostics::PP_VERSION_NOT_FIRST_STATEMENT,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_VERSION_NOT_FIRST_STATEMENT, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
return;
}
......@@ -781,14 +772,14 @@ void DirectiveParser::parseVersion(Token *token)
case VERSION_NUMBER:
if (token->type != Token::CONST_INT)
{
mDiagnostics->report(Diagnostics::PP_INVALID_VERSION_NUMBER,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_INVALID_VERSION_NUMBER, token->location,
token->text);
valid = false;
}
if (valid && !token->iValue(&version))
{
mDiagnostics->report(Diagnostics::PP_INTEGER_OVERFLOW,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_INTEGER_OVERFLOW, token->location,
token->text);
valid = false;
}
if (valid)
......@@ -799,15 +790,15 @@ void DirectiveParser::parseVersion(Token *token)
case VERSION_PROFILE:
if (token->type != Token::IDENTIFIER || token->text != "es")
{
mDiagnostics->report(Diagnostics::PP_INVALID_VERSION_DIRECTIVE,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_INVALID_VERSION_DIRECTIVE, token->location,
token->text);
valid = false;
}
state = VERSION_ENDLINE;
break;
default:
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location,
token->text);
valid = false;
break;
}
......@@ -817,15 +808,15 @@ void DirectiveParser::parseVersion(Token *token)
if (valid && (state != VERSION_ENDLINE))
{
mDiagnostics->report(Diagnostics::PP_INVALID_VERSION_DIRECTIVE,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_INVALID_VERSION_DIRECTIVE, token->location,
token->text);
valid = false;
}
if (valid && version >= 300 && token->location.line > 1)
{
mDiagnostics->report(Diagnostics::PP_VERSION_NOT_FIRST_LINE_ESSL3,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_VERSION_NOT_FIRST_LINE_ESSL3, token->location,
token->text);
valid = false;
}
......@@ -883,8 +874,8 @@ void DirectiveParser::parseLine(Token *token)
{
if (valid)
{
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location,
token->text);
valid = false;
}
skipUntilEOD(mTokenizer, token);
......@@ -904,7 +895,7 @@ bool DirectiveParser::skipping() const
if (mConditionalStack.empty())
return false;
const ConditionalBlock& block = mConditionalStack.back();
const ConditionalBlock &block = mConditionalStack.back();
return block.skipBlock || block.skipGroup;
}
......@@ -968,8 +959,8 @@ int DirectiveParser::parseExpressionIf(Token *token)
// Check if there are tokens after #if expression.
if (!isEOD(token))
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
}
......@@ -983,8 +974,7 @@ int DirectiveParser::parseExpressionIfdef(Token *token)
mTokenizer->lex(token);
if (token->type != Token::IDENTIFIER)
{
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location, token->text);
skipUntilEOD(mTokenizer, token);
return 0;
}
......@@ -996,8 +986,8 @@ int DirectiveParser::parseExpressionIfdef(Token *token)
mTokenizer->lex(token);
if (!isEOD(token))
{
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
token->location, token->text);
mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN, token->location,
token->text);
skipUntilEOD(mTokenizer, token);
}
return expression;
......
......@@ -30,7 +30,6 @@ class DirectiveParser : public Lexer
void lex(Token *token) override;
private:
void parseDirective(Token *token);
void parseDefine(Token *token);
void parseUndef(Token *token);
......@@ -61,15 +60,13 @@ class DirectiveParser : public Lexer
bool foundElseGroup;
ConditionalBlock()
: skipBlock(false),
skipGroup(false),
foundValidGroup(false),
foundElseGroup(false)
: skipBlock(false), skipGroup(false), foundValidGroup(false), foundElseGroup(false)
{
}
};
bool mPastFirstStatement;
bool mSeenNonPreprocessorToken; // Tracks if a non-preprocessor token has been seen yet. Some macros, such as
bool mSeenNonPreprocessorToken; // Tracks if a non-preprocessor token has been seen yet. Some
// macros, such as
// #extension must be declared before all shader code.
std::vector<ConditionalBlock> mConditionalStack;
Tokenizer *mTokenizer;
......
......@@ -18,9 +18,8 @@ Input::Input() : mCount(0), mString(0)
{
}
Input::Input(size_t count, const char *const string[], const int length[]) :
mCount(count),
mString(string)
Input::Input(size_t count, const char *const string[], const int length[])
: mCount(count), mString(string)
{
mLength.reserve(mCount);
for (size_t i = 0; i < mCount; ++i)
......@@ -114,4 +113,3 @@ size_t Input::read(char *buf, size_t maxSize, int *lineNo)
}
} // namespace pp
......@@ -20,18 +20,9 @@ class Input
Input();
Input(size_t count, const char *const string[], const int length[]);
size_t count() const
{
return mCount;
}
const char *string(size_t index) const
{
return mString[index];
}
size_t length(size_t index) const
{
return mLength[index];
}
size_t count() const { return mCount; }
const char *string(size_t index) const { return mString[index]; }
size_t length(size_t index) const { return mLength[index]; }
size_t read(char *buf, size_t maxSize, int *lineNo);
......@@ -40,11 +31,7 @@ class Input
size_t sIndex; // String index;
size_t cIndex; // Char index.
Location()
: sIndex(0),
cIndex(0)
{
}
Location() : sIndex(0), cIndex(0) {}
};
const Location &readLoc() const { return mReadLoc; }
......@@ -55,7 +42,7 @@ class Input
// Input.
size_t mCount;
const char * const *mString;
const char *const *mString;
std::vector<size_t> mLength;
Location mReadLoc;
......
......@@ -14,9 +14,7 @@ namespace pp
bool Macro::equals(const Macro &other) const
{
return (type == other.type) &&
(name == other.name) &&
(parameters == other.parameters) &&
return (type == other.type) && (name == other.name) && (parameters == other.parameters) &&
(replacements == other.replacements);
}
......@@ -36,4 +34,3 @@ void PredefineMacro(MacroSet *macroSet, const char *name, int value)
}
} // namespace pp
......@@ -115,7 +115,7 @@ void MacroExpander::lex(Token *token)
if (iter == mMacroSet->end())
break;
const Macro& macro = iter->second;
const Macro &macro = iter->second;
if (macro.disabled)
{
// If a particular token is not expanded, it is never expanded.
......@@ -248,8 +248,7 @@ bool MacroExpander::expandMacro(const Macro &macro,
SourceLocation replacementLocation = identifier.location;
if (macro.type == Macro::kTypeObj)
{
replacements->assign(macro.replacements.begin(),
macro.replacements.end());
replacements->assign(macro.replacements.begin(), macro.replacements.end());
if (macro.predefined)
{
......@@ -257,7 +256,7 @@ bool MacroExpander::expandMacro(const Macro &macro,
const char kFile[] = "__FILE__";
ASSERT(replacements->size() == 1);
Token& repl = replacements->front();
Token &repl = replacements->front();
if (macro.name == kLine)
{
repl.text = ToString(identifier.location.line);
......@@ -281,7 +280,7 @@ bool MacroExpander::expandMacro(const Macro &macro,
for (std::size_t i = 0; i < replacements->size(); ++i)
{
Token& repl = replacements->at(i);
Token &repl = replacements->at(i);
if (i == 0)
{
// The first token in the replacement list inherits the padding
......@@ -317,8 +316,8 @@ bool MacroExpander::collectMacroArgs(const Macro &macro,
if (token.type == Token::LAST)
{
mDiagnostics->report(Diagnostics::PP_MACRO_UNTERMINATED_INVOCATION,
identifier.location, identifier.text);
mDiagnostics->report(Diagnostics::PP_MACRO_UNTERMINATED_INVOCATION, identifier.location,
identifier.text);
// Do not lose EOF token.
ungetToken(token);
return false;
......@@ -367,9 +366,9 @@ bool MacroExpander::collectMacroArgs(const Macro &macro,
// Validate the number of arguments.
if (args->size() != params.size())
{
Diagnostics::ID id = args->size() < macro.parameters.size() ?
Diagnostics::PP_MACRO_TOO_FEW_ARGS :
Diagnostics::PP_MACRO_TOO_MANY_ARGS;
Diagnostics::ID id = args->size() < macro.parameters.size()
? Diagnostics::PP_MACRO_TOO_FEW_ARGS
: Diagnostics::PP_MACRO_TOO_MANY_ARGS;
mDiagnostics->report(id, identifier.location, identifier.text);
return false;
}
......@@ -430,8 +429,8 @@ void MacroExpander::replaceMacroParams(const Macro &macro,
// TODO(alokp): Optimize this.
// There is no need to search for macro params every time.
// The param index can be cached with the replacement token.
Macro::Parameters::const_iterator iter = std::find(
macro.parameters.begin(), macro.parameters.end(), repl.text);
Macro::Parameters::const_iterator iter =
std::find(macro.parameters.begin(), macro.parameters.end(), repl.text);
if (iter == macro.parameters.end())
{
replacements->push_back(repl);
......@@ -473,4 +472,3 @@ void MacroExpander::MacroContext::unget()
}
} // namespace pp
......@@ -38,9 +38,7 @@ class MacroExpander : public Lexer
bool pushMacro(const Macro &macro, const Token &identifier);
void popMacro();
bool expandMacro(const Macro &macro,
const Token &identifier,
std::vector<Token> *replacements);
bool expandMacro(const Macro &macro, const Token &identifier, std::vector<Token> *replacements);
typedef std::vector<Token> MacroArg;
bool collectMacroArgs(const Macro &macro,
......
......@@ -52,9 +52,7 @@ Preprocessor::~Preprocessor()
delete mImpl;
}
bool Preprocessor::init(size_t count,
const char * const string[],
const int length[])
bool Preprocessor::init(size_t count, const char *const string[], const int length[])
{
static const int kDefaultGLSLVersion = 100;
......@@ -87,12 +85,12 @@ void Preprocessor::lex(Token *token)
UNREACHABLE();
break;
case Token::PP_NUMBER:
mImpl->diagnostics->report(Diagnostics::PP_INVALID_NUMBER,
token->location, token->text);
mImpl->diagnostics->report(Diagnostics::PP_INVALID_NUMBER, token->location,
token->text);
break;
case Token::PP_OTHER:
mImpl->diagnostics->report(Diagnostics::PP_INVALID_CHARACTER,
token->location, token->text);
mImpl->diagnostics->report(Diagnostics::PP_INVALID_CHARACTER, token->location,
token->text);
break;
default:
validToken = true;
......
......@@ -42,7 +42,7 @@ class Preprocessor : angle::NonCopyable
// Each element in the length array may contain the length of the
// corresponding string or a value less than 0 to indicate that the string
// is null terminated.
bool init(size_t count, const char * const string[], const int length[]);
bool init(size_t count, const char *const string[], const int length[]);
// Adds a pre-defined macro.
void predefineMacro(const char *name, int value);
......
......@@ -12,16 +12,8 @@ namespace pp
struct SourceLocation
{
SourceLocation()
: file(0),
line(0)
{
}
SourceLocation(int f, int l)
: file(f),
line(l)
{
}
SourceLocation() : file(0), line(0) {}
SourceLocation(int f, int l) : file(f), line(l) {}
bool equals(const SourceLocation &other) const
{
......
......@@ -22,9 +22,7 @@ void Token::reset()
bool Token::equals(const Token &other) const
{
return (type == other.type) &&
(flags == other.flags) &&
(location == other.location) &&
return (type == other.type) && (flags == other.flags) && (location == other.location) &&
(text == other.text);
}
......
......@@ -62,33 +62,20 @@ struct Token
EXPANSION_DISABLED = 1 << 2
};
Token()
: type(0),
flags(0)
{
}
Token() : type(0), flags(0) {}
void reset();
bool equals(const Token &other) const;
// Returns true if this is the first token on line.
// It disregards any leading whitespace.
bool atStartOfLine() const
{
return (flags & AT_START_OF_LINE) != 0;
}
bool atStartOfLine() const { return (flags & AT_START_OF_LINE) != 0; }
void setAtStartOfLine(bool start);
bool hasLeadingSpace() const
{
return (flags & HAS_LEADING_SPACE) != 0;
}
bool hasLeadingSpace() const { return (flags & HAS_LEADING_SPACE) != 0; }
void setHasLeadingSpace(bool space);
bool expansionDisabled() const
{
return (flags & EXPANSION_DISABLED) != 0;
}
bool expansionDisabled() const { return (flags & EXPANSION_DISABLED) != 0; }
void setExpansionDisabled(bool disable);
// Converts text into numeric value for CONST_INT and CONST_FLOAT token.
......
......@@ -36,7 +36,7 @@ class Tokenizer : public Lexer
Tokenizer(Diagnostics *diagnostics);
~Tokenizer();
bool init(size_t count, const char * const string[], const int length[]);
bool init(size_t count, const char *const string[], const int length[]);
void setFileNumber(int file);
void setLineNumber(int line);
......
......@@ -12,13 +12,12 @@
#include <cmath>
#include <sstream>
namespace pp {
namespace pp
{
inline std::ios::fmtflags numeric_base_int(const std::string &str)
{
if ((str.size() >= 2) &&
(str[0] == '0') &&
(str[1] == 'x' || str[1] == 'X'))
if ((str.size() >= 2) && (str[0] == '0') && (str[1] == 'x' || str[1] == 'X'))
{
return std::ios::hex;
}
......@@ -34,7 +33,7 @@ inline std::ios::fmtflags numeric_base_int(const std::string &str)
// of the correct form. They can only fail if the parsed value is too big,
// in which case false is returned.
template<typename IntType>
template <typename IntType>
bool numeric_lex_int(const std::string &str, IntType *value)
{
std::istringstream stream(str);
......@@ -46,7 +45,7 @@ bool numeric_lex_int(const std::string &str, IntType *value)
return !stream.fail();
}
template<typename FloatType>
template <typename FloatType>
bool numeric_lex_float(const std::string &str, FloatType *value)
{
// On 64-bit Intel Android, istringstream is broken. Until this is fixed in
......
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