Commit d526f989 by Zhenyao Mo

Fix code style violation in compiler/preprocessor

BUG=angle:650 TEST=no behavior change Change-Id: Ib52f15f6471fc7897b66d11baee11216cf08158a Reviewed-on: https://chromium-review.googlesource.com/199591Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent ae1990c8
...@@ -16,8 +16,8 @@ Diagnostics::~Diagnostics() ...@@ -16,8 +16,8 @@ Diagnostics::~Diagnostics()
} }
void Diagnostics::report(ID id, void Diagnostics::report(ID id,
const SourceLocation& loc, const SourceLocation &loc,
const std::string& text) const std::string &text)
{ {
// TODO(alokp): Keep a count of errors and warnings. // TODO(alokp): Keep a count of errors and warnings.
print(id, loc, text); print(id, loc, text);
...@@ -41,86 +41,86 @@ std::string Diagnostics::message(ID id) ...@@ -41,86 +41,86 @@ std::string Diagnostics::message(ID id)
{ {
// Errors begin. // Errors begin.
case PP_INTERNAL_ERROR: case PP_INTERNAL_ERROR:
return "internal error"; return "internal error";
case PP_OUT_OF_MEMORY: case PP_OUT_OF_MEMORY:
return "out of memory"; return "out of memory";
case PP_INVALID_CHARACTER: case PP_INVALID_CHARACTER:
return "invalid character"; return "invalid character";
case PP_INVALID_NUMBER: case PP_INVALID_NUMBER:
return "invalid number"; return "invalid number";
case PP_INTEGER_OVERFLOW: case PP_INTEGER_OVERFLOW:
return "integer overflow"; return "integer overflow";
case PP_FLOAT_OVERFLOW: case PP_FLOAT_OVERFLOW:
return "float overflow"; return "float overflow";
case PP_TOKEN_TOO_LONG: case PP_TOKEN_TOO_LONG:
return "token too long"; return "token too long";
case PP_INVALID_EXPRESSION: case PP_INVALID_EXPRESSION:
return "invalid expression"; return "invalid expression";
case PP_DIVISION_BY_ZERO: case PP_DIVISION_BY_ZERO:
return "division by zero"; return "division by zero";
case PP_EOF_IN_COMMENT: case PP_EOF_IN_COMMENT:
return "unexpected end of file found in comment"; return "unexpected end of file found in comment";
case PP_UNEXPECTED_TOKEN: case PP_UNEXPECTED_TOKEN:
return "unexpected token"; return "unexpected token";
case PP_DIRECTIVE_INVALID_NAME: case PP_DIRECTIVE_INVALID_NAME:
return "invalid directive name"; return "invalid directive name";
case PP_MACRO_NAME_RESERVED: case PP_MACRO_NAME_RESERVED:
return "macro name is reserved"; return "macro name is reserved";
case PP_MACRO_REDEFINED: case PP_MACRO_REDEFINED:
return "macro redefined"; return "macro redefined";
case PP_MACRO_PREDEFINED_REDEFINED: case PP_MACRO_PREDEFINED_REDEFINED:
return "predefined macro redefined"; return "predefined macro redefined";
case PP_MACRO_PREDEFINED_UNDEFINED: case PP_MACRO_PREDEFINED_UNDEFINED:
return "predefined macro undefined"; return "predefined macro undefined";
case PP_MACRO_UNTERMINATED_INVOCATION: case PP_MACRO_UNTERMINATED_INVOCATION:
return "unterminated macro invocation"; return "unterminated macro invocation";
case PP_MACRO_TOO_FEW_ARGS: case PP_MACRO_TOO_FEW_ARGS:
return "Not enough arguments for macro"; return "Not enough arguments for macro";
case PP_MACRO_TOO_MANY_ARGS: case PP_MACRO_TOO_MANY_ARGS:
return "Too many arguments for macro"; return "Too many arguments for macro";
case PP_CONDITIONAL_ENDIF_WITHOUT_IF: case PP_CONDITIONAL_ENDIF_WITHOUT_IF:
return "unexpected #endif found without a matching #if"; return "unexpected #endif found without a matching #if";
case PP_CONDITIONAL_ELSE_WITHOUT_IF: case PP_CONDITIONAL_ELSE_WITHOUT_IF:
return "unexpected #else found without a matching #if"; return "unexpected #else found without a matching #if";
case PP_CONDITIONAL_ELSE_AFTER_ELSE: case PP_CONDITIONAL_ELSE_AFTER_ELSE:
return "unexpected #else found after another #else"; return "unexpected #else found after another #else";
case PP_CONDITIONAL_ELIF_WITHOUT_IF: case PP_CONDITIONAL_ELIF_WITHOUT_IF:
return "unexpected #elif found without a matching #if"; return "unexpected #elif found without a matching #if";
case PP_CONDITIONAL_ELIF_AFTER_ELSE: case PP_CONDITIONAL_ELIF_AFTER_ELSE:
return "unexpected #elif found after #else"; return "unexpected #elif found after #else";
case PP_CONDITIONAL_UNTERMINATED: case PP_CONDITIONAL_UNTERMINATED:
return "unexpected end of file found in conditional block"; return "unexpected end of file found in conditional block";
case PP_INVALID_EXTENSION_NAME: case PP_INVALID_EXTENSION_NAME:
return "invalid extension name"; return "invalid extension name";
case PP_INVALID_EXTENSION_BEHAVIOR: case PP_INVALID_EXTENSION_BEHAVIOR:
return "invalid extension behavior"; return "invalid extension behavior";
case PP_INVALID_EXTENSION_DIRECTIVE: case PP_INVALID_EXTENSION_DIRECTIVE:
return "invalid extension directive"; return "invalid extension directive";
case PP_INVALID_VERSION_NUMBER: case PP_INVALID_VERSION_NUMBER:
return "invalid version number"; return "invalid version number";
case PP_INVALID_VERSION_DIRECTIVE: case PP_INVALID_VERSION_DIRECTIVE:
return "invalid version directive"; return "invalid version directive";
case PP_VERSION_NOT_FIRST_STATEMENT: case PP_VERSION_NOT_FIRST_STATEMENT:
return "#version directive must occur before anything else, " return "#version directive must occur before anything else, "
"except for comments and white space"; "except for comments and white space";
case PP_INVALID_LINE_NUMBER: case PP_INVALID_LINE_NUMBER:
return "invalid line number"; return "invalid line number";
case PP_INVALID_FILE_NUMBER: case PP_INVALID_FILE_NUMBER:
return "invalid file number"; return "invalid file number";
case PP_INVALID_LINE_DIRECTIVE: case PP_INVALID_LINE_DIRECTIVE:
return "invalid line directive"; return "invalid line directive";
// Errors end. // Errors end.
// Warnings begin. // Warnings begin.
case PP_EOF_IN_DIRECTIVE: case PP_EOF_IN_DIRECTIVE:
return "unexpected end of file found in directive"; return "unexpected end of file found in directive";
case PP_CONDITIONAL_UNEXPECTED_TOKEN: case PP_CONDITIONAL_UNEXPECTED_TOKEN:
return "unexpected token after conditional expression"; return "unexpected token after conditional expression";
case PP_UNRECOGNIZED_PRAGMA: case PP_UNRECOGNIZED_PRAGMA:
return "unrecognized pragma"; return "unrecognized pragma";
// Warnings end. // Warnings end.
default: default:
assert(false); assert(false);
return ""; return "";
} }
} }
......
...@@ -72,15 +72,15 @@ class Diagnostics ...@@ -72,15 +72,15 @@ class Diagnostics
virtual ~Diagnostics(); virtual ~Diagnostics();
void report(ID id, const SourceLocation& loc, const std::string& text); void report(ID id, const SourceLocation &loc, const std::string &text);
protected: protected:
Severity severity(ID id); Severity severity(ID id);
std::string message(ID id); std::string message(ID id);
virtual void print(ID id, virtual void print(ID id,
const SourceLocation& loc, const SourceLocation &loc,
const std::string& text) = 0; const std::string &text) = 0;
}; };
} // namespace pp } // namespace pp
......
...@@ -23,19 +23,19 @@ class DirectiveHandler ...@@ -23,19 +23,19 @@ class DirectiveHandler
public: public:
virtual ~DirectiveHandler(); virtual ~DirectiveHandler();
virtual void handleError(const SourceLocation& loc, virtual void handleError(const SourceLocation &loc,
const std::string& msg) = 0; const std::string &msg) = 0;
// Handle pragma of form: #pragma name[(value)] // Handle pragma of form: #pragma name[(value)]
virtual void handlePragma(const SourceLocation& loc, virtual void handlePragma(const SourceLocation &loc,
const std::string& name, const std::string &name,
const std::string& value) = 0; const std::string &value) = 0;
virtual void handleExtension(const SourceLocation& loc, virtual void handleExtension(const SourceLocation &loc,
const std::string& name, const std::string &name,
const std::string& behavior) = 0; const std::string &behavior) = 0;
virtual void handleVersion(const SourceLocation& loc, virtual void handleVersion(const SourceLocation &loc,
int version) = 0; int version) = 0;
}; };
......
...@@ -22,35 +22,35 @@ class Tokenizer; ...@@ -22,35 +22,35 @@ class Tokenizer;
class DirectiveParser : public Lexer class DirectiveParser : public Lexer
{ {
public: public:
DirectiveParser(Tokenizer* tokenizer, DirectiveParser(Tokenizer *tokenizer,
MacroSet* macroSet, MacroSet *macroSet,
Diagnostics* diagnostics, Diagnostics *diagnostics,
DirectiveHandler* directiveHandler); DirectiveHandler *directiveHandler);
virtual void lex(Token* token); virtual void lex(Token *token);
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(DirectiveParser); PP_DISALLOW_COPY_AND_ASSIGN(DirectiveParser);
void parseDirective(Token* token); void parseDirective(Token *token);
void parseDefine(Token* token); void parseDefine(Token *token);
void parseUndef(Token* token); void parseUndef(Token *token);
void parseIf(Token* token); void parseIf(Token *token);
void parseIfdef(Token* token); void parseIfdef(Token *token);
void parseIfndef(Token* token); void parseIfndef(Token *token);
void parseElse(Token* token); void parseElse(Token *token);
void parseElif(Token* token); void parseElif(Token *token);
void parseEndif(Token* token); void parseEndif(Token *token);
void parseError(Token* token); void parseError(Token *token);
void parsePragma(Token* token); void parsePragma(Token *token);
void parseExtension(Token* token); void parseExtension(Token *token);
void parseVersion(Token* token); void parseVersion(Token *token);
void parseLine(Token* token); void parseLine(Token *token);
bool skipping() const; bool skipping() const;
void parseConditionalIf(Token* token); void parseConditionalIf(Token *token);
int parseExpressionIf(Token* token); int parseExpressionIf(Token *token);
int parseExpressionIfdef(Token* token); int parseExpressionIfdef(Token *token);
struct ConditionalBlock struct ConditionalBlock
{ {
...@@ -61,20 +61,20 @@ class DirectiveParser : public Lexer ...@@ -61,20 +61,20 @@ class DirectiveParser : public Lexer
bool foundValidGroup; bool foundValidGroup;
bool foundElseGroup; bool foundElseGroup;
ConditionalBlock() : ConditionalBlock()
skipBlock(false), : skipBlock(false),
skipGroup(false), skipGroup(false),
foundValidGroup(false), foundValidGroup(false),
foundElseGroup(false) foundElseGroup(false)
{ {
} }
}; };
bool mPastFirstStatement; bool mPastFirstStatement;
std::vector<ConditionalBlock> mConditionalStack; std::vector<ConditionalBlock> mConditionalStack;
Tokenizer* mTokenizer; Tokenizer *mTokenizer;
MacroSet* mMacroSet; MacroSet *mMacroSet;
Diagnostics* mDiagnostics; Diagnostics *mDiagnostics;
DirectiveHandler* mDirectiveHandler; DirectiveHandler *mDirectiveHandler;
}; };
} // namespace pp } // namespace pp
......
...@@ -1891,15 +1891,14 @@ yyreturn: ...@@ -1891,15 +1891,14 @@ yyreturn:
int yylex(YYSTYPE* lvalp, Context* context) int yylex(YYSTYPE *lvalp, Context *context)
{ {
int type = 0; int type = 0;
pp::Token* token = context->token; pp::Token *token = context->token;
switch (token->type) switch (token->type)
{ {
case pp::Token::CONST_INT: case pp::Token::CONST_INT: {
{
unsigned int val = 0; unsigned int val = 0;
if (!token->uValue(&val)) if (!token->uValue(&val))
{ {
...@@ -1910,39 +1909,59 @@ int yylex(YYSTYPE* lvalp, Context* context) ...@@ -1910,39 +1909,59 @@ int yylex(YYSTYPE* lvalp, Context* context)
type = TOK_CONST_INT; type = TOK_CONST_INT;
break; break;
} }
case pp::Token::OP_OR: type = TOK_OP_OR; break; case pp::Token::OP_OR:
case pp::Token::OP_AND: type = TOK_OP_AND; break; type = TOK_OP_OR;
case pp::Token::OP_NE: type = TOK_OP_NE; break; break;
case pp::Token::OP_EQ: type = TOK_OP_EQ; break; case pp::Token::OP_AND:
case pp::Token::OP_GE: type = TOK_OP_GE; break; type = TOK_OP_AND;
case pp::Token::OP_LE: type = TOK_OP_LE; break; break;
case pp::Token::OP_RIGHT: type = TOK_OP_RIGHT; break; case pp::Token::OP_NE:
case pp::Token::OP_LEFT: type = TOK_OP_LEFT; break; type = TOK_OP_NE;
case '|': type = '|'; break; break;
case '^': type = '^'; break; case pp::Token::OP_EQ:
case '&': type = '&'; break; type = TOK_OP_EQ;
case '>': type = '>'; break; break;
case '<': type = '<'; break; case pp::Token::OP_GE:
case '-': type = '-'; break; type = TOK_OP_GE;
case '+': type = '+'; break; break;
case '%': type = '%'; break; case pp::Token::OP_LE:
case '/': type = '/'; break; type = TOK_OP_LE;
case '*': type = '*'; break; break;
case '!': type = '!'; break; case pp::Token::OP_RIGHT:
case '~': type = '~'; break; type = TOK_OP_RIGHT;
case '(': type = '('; break; break;
case ')': type = ')'; break; case pp::Token::OP_LEFT:
type = TOK_OP_LEFT;
break;
case '|':
case '^':
case '&':
case '>':
case '<':
case '-':
case '+':
case '%':
case '/':
case '*':
case '!':
case '~':
case '(':
case ')':
type = token->type;
break;
default: break; default:
break;
} }
// Advance to the next token if the current one is valid. // Advance to the next token if the current one is valid.
if (type != 0) context->lexer->lex(token); if (type != 0)
context->lexer->lex(token);
return type; return type;
} }
void yyerror(Context* context, const char* reason) void yyerror(Context *context, const char *reason)
{ {
context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION, context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION,
context->token->location, context->token->location,
...@@ -1951,13 +1970,13 @@ void yyerror(Context* context, const char* reason) ...@@ -1951,13 +1970,13 @@ void yyerror(Context* context, const char* reason)
namespace pp { namespace pp {
ExpressionParser::ExpressionParser(Lexer* lexer, Diagnostics* diagnostics) : ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
mLexer(lexer), : mLexer(lexer),
mDiagnostics(diagnostics) mDiagnostics(diagnostics)
{ {
} }
bool ExpressionParser::parse(Token* token, int* result) bool ExpressionParser::parse(Token *token, int *result)
{ {
Context context; Context context;
context.diagnostics = mDiagnostics; context.diagnostics = mDiagnostics;
......
...@@ -19,15 +19,15 @@ struct Token; ...@@ -19,15 +19,15 @@ struct Token;
class ExpressionParser class ExpressionParser
{ {
public: public:
ExpressionParser(Lexer* lexer, Diagnostics* diagnostics); ExpressionParser(Lexer *lexer, Diagnostics *diagnostics);
bool parse(Token* token, int* result); bool parse(Token *token, int *result);
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(ExpressionParser); PP_DISALLOW_COPY_AND_ASSIGN(ExpressionParser);
Lexer* mLexer; Lexer *mLexer;
Diagnostics* mDiagnostics; Diagnostics *mDiagnostics;
}; };
} // namespace pp } // namespace pp
......
...@@ -195,15 +195,14 @@ expression ...@@ -195,15 +195,14 @@ expression
%% %%
int yylex(YYSTYPE* lvalp, Context* context) int yylex(YYSTYPE *lvalp, Context *context)
{ {
int type = 0; int type = 0;
pp::Token* token = context->token; pp::Token *token = context->token;
switch (token->type) switch (token->type)
{ {
case pp::Token::CONST_INT: case pp::Token::CONST_INT: {
{
unsigned int val = 0; unsigned int val = 0;
if (!token->uValue(&val)) if (!token->uValue(&val))
{ {
...@@ -214,39 +213,59 @@ int yylex(YYSTYPE* lvalp, Context* context) ...@@ -214,39 +213,59 @@ int yylex(YYSTYPE* lvalp, Context* context)
type = TOK_CONST_INT; type = TOK_CONST_INT;
break; break;
} }
case pp::Token::OP_OR: type = TOK_OP_OR; break; case pp::Token::OP_OR:
case pp::Token::OP_AND: type = TOK_OP_AND; break; type = TOK_OP_OR;
case pp::Token::OP_NE: type = TOK_OP_NE; break; break;
case pp::Token::OP_EQ: type = TOK_OP_EQ; break; case pp::Token::OP_AND:
case pp::Token::OP_GE: type = TOK_OP_GE; break; type = TOK_OP_AND;
case pp::Token::OP_LE: type = TOK_OP_LE; break; break;
case pp::Token::OP_RIGHT: type = TOK_OP_RIGHT; break; case pp::Token::OP_NE:
case pp::Token::OP_LEFT: type = TOK_OP_LEFT; break; type = TOK_OP_NE;
case '|': type = '|'; break; break;
case '^': type = '^'; break; case pp::Token::OP_EQ:
case '&': type = '&'; break; type = TOK_OP_EQ;
case '>': type = '>'; break; break;
case '<': type = '<'; break; case pp::Token::OP_GE:
case '-': type = '-'; break; type = TOK_OP_GE;
case '+': type = '+'; break; break;
case '%': type = '%'; break; case pp::Token::OP_LE:
case '/': type = '/'; break; type = TOK_OP_LE;
case '*': type = '*'; break; break;
case '!': type = '!'; break; case pp::Token::OP_RIGHT:
case '~': type = '~'; break; type = TOK_OP_RIGHT;
case '(': type = '('; break; break;
case ')': type = ')'; break; case pp::Token::OP_LEFT:
type = TOK_OP_LEFT;
break;
case '|':
case '^':
case '&':
case '>':
case '<':
case '-':
case '+':
case '%':
case '/':
case '*':
case '!':
case '~':
case '(':
case ')':
type = token->type;
break;
default: break; default:
break;
} }
// Advance to the next token if the current one is valid. // Advance to the next token if the current one is valid.
if (type != 0) context->lexer->lex(token); if (type != 0)
context->lexer->lex(token);
return type; return type;
} }
void yyerror(Context* context, const char* reason) void yyerror(Context *context, const char *reason)
{ {
context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION, context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION,
context->token->location, context->token->location,
...@@ -255,13 +274,13 @@ void yyerror(Context* context, const char* reason) ...@@ -255,13 +274,13 @@ void yyerror(Context* context, const char* reason)
namespace pp { namespace pp {
ExpressionParser::ExpressionParser(Lexer* lexer, Diagnostics* diagnostics) : ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
mLexer(lexer), : mLexer(lexer),
mDiagnostics(diagnostics) mDiagnostics(diagnostics)
{ {
} }
bool ExpressionParser::parse(Token* token, int* result) bool ExpressionParser::parse(Token *token, int *result)
{ {
Context context; Context context;
context.diagnostics = mDiagnostics; context.diagnostics = mDiagnostics;
......
...@@ -17,7 +17,7 @@ Input::Input() : mCount(0), mString(0) ...@@ -17,7 +17,7 @@ Input::Input() : mCount(0), mString(0)
{ {
} }
Input::Input(size_t count, const char* const string[], const int length[]) : Input::Input(size_t count, const char *const string[], const int length[]) :
mCount(count), mCount(count),
mString(string) mString(string)
{ {
...@@ -29,7 +29,7 @@ Input::Input(size_t count, const char* const string[], const int length[]) : ...@@ -29,7 +29,7 @@ Input::Input(size_t count, const char* const string[], const int length[]) :
} }
} }
size_t Input::read(char* buf, size_t maxSize) size_t Input::read(char *buf, size_t maxSize)
{ {
size_t nRead = 0; size_t nRead = 0;
while ((nRead < maxSize) && (mReadLoc.sIndex < mCount)) while ((nRead < maxSize) && (mReadLoc.sIndex < mCount))
......
...@@ -18,27 +18,40 @@ class Input ...@@ -18,27 +18,40 @@ class Input
{ {
public: public:
Input(); Input();
Input(size_t count, const char* const string[], const int length[]); Input(size_t count, const char *const string[], const int length[]);
size_t count() const { return mCount; } size_t count() const
const char* string(size_t index) const { return mString[index]; } {
size_t length(size_t index) const { return mLength[index]; } 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); size_t read(char *buf, size_t maxSize);
struct Location struct Location
{ {
size_t sIndex; // String index; size_t sIndex; // String index;
size_t cIndex; // Char index. size_t cIndex; // Char index.
Location() : sIndex(0), cIndex(0) { } Location()
: sIndex(0),
cIndex(0)
{
}
}; };
const Location& readLoc() const { return mReadLoc; } const Location &readLoc() const { return mReadLoc; }
private: private:
// Input. // Input.
size_t mCount; size_t mCount;
const char* const* mString; const char * const *mString;
std::vector<size_t> mLength; std::vector<size_t> mLength;
Location mReadLoc; Location mReadLoc;
......
...@@ -17,7 +17,7 @@ class Lexer ...@@ -17,7 +17,7 @@ class Lexer
public: public:
virtual ~Lexer(); virtual ~Lexer();
virtual void lex(Token* token) = 0; virtual void lex(Token *token) = 0;
}; };
} // namespace pp } // namespace pp
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace pp namespace pp
{ {
bool Macro::equals(const Macro& other) const bool Macro::equals(const Macro &other) const
{ {
return (type == other.type) && return (type == other.type) &&
(name == other.name) && (name == other.name) &&
......
...@@ -26,8 +26,13 @@ struct Macro ...@@ -26,8 +26,13 @@ struct Macro
typedef std::vector<std::string> Parameters; typedef std::vector<std::string> Parameters;
typedef std::vector<Token> Replacements; typedef std::vector<Token> Replacements;
Macro() : predefined(false), disabled(false), type(kTypeObj) { } Macro()
bool equals(const Macro& other) const; : predefined(false),
disabled(false),
type(kTypeObj)
{
}
bool equals(const Macro &other) const;
bool predefined; bool predefined;
mutable bool disabled; mutable bool disabled;
......
...@@ -20,13 +20,13 @@ class TokenLexer : public Lexer ...@@ -20,13 +20,13 @@ class TokenLexer : public Lexer
public: public:
typedef std::vector<Token> TokenVector; typedef std::vector<Token> TokenVector;
TokenLexer(TokenVector* tokens) TokenLexer(TokenVector *tokens)
{ {
tokens->swap(mTokens); tokens->swap(mTokens);
mIter = mTokens.begin(); mIter = mTokens.begin();
} }
virtual void lex(Token* token) virtual void lex(Token *token)
{ {
if (mIter == mTokens.end()) if (mIter == mTokens.end())
{ {
...@@ -46,12 +46,12 @@ class TokenLexer : public Lexer ...@@ -46,12 +46,12 @@ class TokenLexer : public Lexer
TokenVector::const_iterator mIter; TokenVector::const_iterator mIter;
}; };
MacroExpander::MacroExpander(Lexer* lexer, MacroExpander::MacroExpander(Lexer *lexer,
MacroSet* macroSet, MacroSet *macroSet,
Diagnostics* diagnostics) : Diagnostics *diagnostics)
mLexer(lexer), : mLexer(lexer),
mMacroSet(macroSet), mMacroSet(macroSet),
mDiagnostics(diagnostics) mDiagnostics(diagnostics)
{ {
} }
...@@ -63,7 +63,7 @@ MacroExpander::~MacroExpander() ...@@ -63,7 +63,7 @@ MacroExpander::~MacroExpander()
} }
} }
void MacroExpander::lex(Token* token) void MacroExpander::lex(Token *token)
{ {
while (true) while (true)
{ {
...@@ -97,7 +97,7 @@ void MacroExpander::lex(Token* token) ...@@ -97,7 +97,7 @@ void MacroExpander::lex(Token* token)
} }
} }
void MacroExpander::getToken(Token* token) void MacroExpander::getToken(Token *token)
{ {
if (mReserveToken.get()) if (mReserveToken.get())
{ {
...@@ -122,11 +122,11 @@ void MacroExpander::getToken(Token* token) ...@@ -122,11 +122,11 @@ void MacroExpander::getToken(Token* token)
} }
} }
void MacroExpander::ungetToken(const Token& token) void MacroExpander::ungetToken(const Token &token)
{ {
if (!mContextStack.empty()) if (!mContextStack.empty())
{ {
MacroContext* context = mContextStack.back(); MacroContext *context = mContextStack.back();
context->unget(); context->unget();
assert(context->replacements[context->index] == token); assert(context->replacements[context->index] == token);
} }
...@@ -148,7 +148,7 @@ bool MacroExpander::isNextTokenLeftParen() ...@@ -148,7 +148,7 @@ bool MacroExpander::isNextTokenLeftParen()
return lparen; return lparen;
} }
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());
...@@ -162,7 +162,7 @@ bool MacroExpander::pushMacro(const Macro& macro, const Token& identifier) ...@@ -162,7 +162,7 @@ bool MacroExpander::pushMacro(const Macro& macro, const Token& identifier)
// Macro is disabled for expansion until it is popped off the stack. // Macro is disabled for expansion until it is popped off the stack.
macro.disabled = true; macro.disabled = true;
MacroContext* context = new MacroContext; MacroContext *context = new MacroContext;
context->macro = &macro; context->macro = &macro;
context->replacements.swap(replacements); context->replacements.swap(replacements);
mContextStack.push_back(context); mContextStack.push_back(context);
...@@ -173,7 +173,7 @@ void MacroExpander::popMacro() ...@@ -173,7 +173,7 @@ 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());
...@@ -182,9 +182,9 @@ void MacroExpander::popMacro() ...@@ -182,9 +182,9 @@ void MacroExpander::popMacro()
delete context; delete context;
} }
bool MacroExpander::expandMacro(const Macro& macro, bool MacroExpander::expandMacro(const Macro &macro,
const Token& identifier, const Token &identifier,
std::vector<Token>* replacements) std::vector<Token> *replacements)
{ {
replacements->clear(); replacements->clear();
if (macro.type == Macro::kTypeObj) if (macro.type == Macro::kTypeObj)
...@@ -239,9 +239,9 @@ bool MacroExpander::expandMacro(const Macro& macro, ...@@ -239,9 +239,9 @@ bool MacroExpander::expandMacro(const Macro& macro,
return true; return true;
} }
bool MacroExpander::collectMacroArgs(const Macro& macro, bool MacroExpander::collectMacroArgs(const Macro &macro,
const Token& identifier, const Token &identifier,
std::vector<MacroArg>* args) std::vector<MacroArg> *args)
{ {
Token token; Token token;
getToken(&token); getToken(&token);
...@@ -276,7 +276,8 @@ bool MacroExpander::collectMacroArgs(const Macro& macro, ...@@ -276,7 +276,8 @@ bool MacroExpander::collectMacroArgs(const Macro& macro,
// The individual arguments are separated by comma tokens, but // The individual arguments are separated by comma tokens, but
// the comma tokens between matching inner parentheses do not // the comma tokens between matching inner parentheses do not
// seperate arguments. // seperate arguments.
if (openParens == 1) args->push_back(MacroArg()); if (openParens == 1)
args->push_back(MacroArg());
isArg = openParens != 1; isArg = openParens != 1;
break; break;
default: default:
...@@ -285,14 +286,15 @@ bool MacroExpander::collectMacroArgs(const Macro& macro, ...@@ -285,14 +286,15 @@ bool MacroExpander::collectMacroArgs(const Macro& macro,
} }
if (isArg) if (isArg)
{ {
MacroArg& arg = args->back(); MacroArg &arg = args->back();
// Initial whitespace is not part of the argument. // Initial whitespace is not part of the argument.
if (arg.empty()) token.setHasLeadingSpace(false); if (arg.empty())
token.setHasLeadingSpace(false);
arg.push_back(token); arg.push_back(token);
} }
} }
const Macro::Parameters& params = macro.parameters; const Macro::Parameters &params = macro.parameters;
// If there is only one empty argument, it is equivalent to no argument. // If there is only one empty argument, it is equivalent to no argument.
if (params.empty() && (args->size() == 1) && args->front().empty()) if (params.empty() && (args->size() == 1) && args->front().empty())
{ {
...@@ -313,7 +315,7 @@ bool MacroExpander::collectMacroArgs(const Macro& macro, ...@@ -313,7 +315,7 @@ bool MacroExpander::collectMacroArgs(const Macro& macro,
// inserted into the macro body. // inserted into the macro body.
for (std::size_t i = 0; i < args->size(); ++i) for (std::size_t i = 0; i < args->size(); ++i)
{ {
MacroArg& arg = args->at(i); MacroArg &arg = args->at(i);
TokenLexer lexer(&arg); TokenLexer lexer(&arg);
MacroExpander expander(&lexer, mMacroSet, mDiagnostics); MacroExpander expander(&lexer, mMacroSet, mDiagnostics);
...@@ -328,13 +330,13 @@ bool MacroExpander::collectMacroArgs(const Macro& macro, ...@@ -328,13 +330,13 @@ bool MacroExpander::collectMacroArgs(const Macro& macro,
return true; return true;
} }
void MacroExpander::replaceMacroParams(const Macro& macro, void MacroExpander::replaceMacroParams(const Macro &macro,
const std::vector<MacroArg>& args, const std::vector<MacroArg> &args,
std::vector<Token>* replacements) std::vector<Token> *replacements)
{ {
for (std::size_t i = 0; i < macro.replacements.size(); ++i) for (std::size_t i = 0; i < macro.replacements.size(); ++i)
{ {
const Token& repl = macro.replacements[i]; const Token &repl = macro.replacements[i];
if (repl.type != Token::IDENTIFIER) if (repl.type != Token::IDENTIFIER)
{ {
replacements->push_back(repl); replacements->push_back(repl);
...@@ -353,7 +355,7 @@ void MacroExpander::replaceMacroParams(const Macro& macro, ...@@ -353,7 +355,7 @@ void MacroExpander::replaceMacroParams(const Macro& macro,
} }
std::size_t iArg = std::distance(macro.parameters.begin(), iter); std::size_t iArg = std::distance(macro.parameters.begin(), iter);
const MacroArg& arg = args[iArg]; const MacroArg &arg = args[iArg];
if (arg.empty()) if (arg.empty())
{ {
continue; continue;
......
...@@ -23,51 +23,65 @@ class Diagnostics; ...@@ -23,51 +23,65 @@ class Diagnostics;
class MacroExpander : public Lexer class MacroExpander : public Lexer
{ {
public: public:
MacroExpander(Lexer* lexer, MacroSet* macroSet, Diagnostics* diagnostics); MacroExpander(Lexer *lexer, MacroSet *macroSet, Diagnostics *diagnostics);
virtual ~MacroExpander(); virtual ~MacroExpander();
virtual void lex(Token* token); virtual void lex(Token *token);
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(MacroExpander); 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();
bool pushMacro(const Macro& macro, const Token& identifier); bool pushMacro(const Macro &macro, const Token &identifier);
void popMacro(); void popMacro();
bool expandMacro(const Macro& macro, bool expandMacro(const Macro &macro,
const Token& identifier, const Token &identifier,
std::vector<Token>* replacements); std::vector<Token> *replacements);
typedef std::vector<Token> MacroArg; typedef std::vector<Token> MacroArg;
bool collectMacroArgs(const Macro& macro, bool collectMacroArgs(const Macro &macro,
const Token& identifier, const Token &identifier,
std::vector<MacroArg>* args); std::vector<MacroArg> *args);
void replaceMacroParams(const Macro& macro, void replaceMacroParams(const Macro &macro,
const std::vector<MacroArg>& args, const std::vector<MacroArg> &args,
std::vector<Token>* replacements); std::vector<Token> *replacements);
struct MacroContext struct MacroContext
{ {
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) { } MacroContext()
bool empty() const { return index == replacements.size(); } : macro(0),
const Token& get() { return replacements[index++]; } index(0)
void unget() { assert(index > 0); --index; } {
}
bool empty() const
{
return index == replacements.size();
}
const Token &get()
{
return replacements[index++];
}
void unget()
{
assert(index > 0);
--index;
}
}; };
Lexer* mLexer; Lexer *mLexer;
MacroSet* mMacroSet; MacroSet *mMacroSet;
Diagnostics* mDiagnostics; Diagnostics *mDiagnostics;
std::auto_ptr<Token> mReserveToken; std::auto_ptr<Token> mReserveToken;
std::vector<MacroContext*> mContextStack; std::vector<MacroContext *> mContextStack;
}; };
} // namespace pp } // namespace pp
......
...@@ -21,24 +21,24 @@ namespace pp ...@@ -21,24 +21,24 @@ namespace pp
struct PreprocessorImpl struct PreprocessorImpl
{ {
Diagnostics* diagnostics; Diagnostics *diagnostics;
MacroSet macroSet; MacroSet macroSet;
Tokenizer tokenizer; Tokenizer tokenizer;
DirectiveParser directiveParser; DirectiveParser directiveParser;
MacroExpander macroExpander; MacroExpander macroExpander;
PreprocessorImpl(Diagnostics* diag, PreprocessorImpl(Diagnostics *diag,
DirectiveHandler* directiveHandler) : DirectiveHandler *directiveHandler)
diagnostics(diag), : diagnostics(diag),
tokenizer(diag), tokenizer(diag),
directiveParser(&tokenizer, &macroSet, diag, directiveHandler), directiveParser(&tokenizer, &macroSet, diag, directiveHandler),
macroExpander(&directiveParser, &macroSet, diag) macroExpander(&directiveParser, &macroSet, diag)
{ {
} }
}; };
Preprocessor::Preprocessor(Diagnostics* diagnostics, Preprocessor::Preprocessor(Diagnostics *diagnostics,
DirectiveHandler* directiveHandler) DirectiveHandler *directiveHandler)
{ {
mImpl = new PreprocessorImpl(diagnostics, directiveHandler); mImpl = new PreprocessorImpl(diagnostics, directiveHandler);
} }
...@@ -49,7 +49,7 @@ Preprocessor::~Preprocessor() ...@@ -49,7 +49,7 @@ Preprocessor::~Preprocessor()
} }
bool Preprocessor::init(size_t count, bool Preprocessor::init(size_t count,
const char* const string[], const char * const string[],
const int length[]) const int length[])
{ {
static const int kGLSLVersion = 100; static const int kGLSLVersion = 100;
...@@ -63,7 +63,7 @@ bool Preprocessor::init(size_t count, ...@@ -63,7 +63,7 @@ bool Preprocessor::init(size_t count,
return mImpl->tokenizer.init(count, string, length); return mImpl->tokenizer.init(count, string, length);
} }
void Preprocessor::predefineMacro(const char* name, int value) void Preprocessor::predefineMacro(const char *name, int value)
{ {
std::ostringstream stream; std::ostringstream stream;
stream << value; stream << value;
...@@ -81,7 +81,7 @@ void Preprocessor::predefineMacro(const char* name, int value) ...@@ -81,7 +81,7 @@ void Preprocessor::predefineMacro(const char* name, int value)
mImpl->macroSet[name] = macro; mImpl->macroSet[name] = macro;
} }
void Preprocessor::lex(Token* token) void Preprocessor::lex(Token *token)
{ {
bool validToken = false; bool validToken = false;
while (!validToken) while (!validToken)
......
...@@ -22,7 +22,7 @@ struct Token; ...@@ -22,7 +22,7 @@ struct Token;
class Preprocessor class Preprocessor
{ {
public: public:
Preprocessor(Diagnostics* diagnostics, DirectiveHandler* directiveHandler); Preprocessor(Diagnostics *diagnostics, DirectiveHandler *directiveHandler);
~Preprocessor(); ~Preprocessor();
// count: specifies the number of elements in the string and length arrays. // count: specifies the number of elements in the string and length arrays.
...@@ -34,11 +34,11 @@ class Preprocessor ...@@ -34,11 +34,11 @@ class Preprocessor
// Each element in the length array may contain the length of the // 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 // corresponding string or a value less than 0 to indicate that the string
// is null terminated. // 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. // Adds a pre-defined macro.
void predefineMacro(const char* name, int value); void predefineMacro(const char *name, int value);
void lex(Token* token); void lex(Token *token);
// Set maximum preprocessor token size // Set maximum preprocessor token size
void setMaxTokenSize(size_t maxTokenSize); void setMaxTokenSize(size_t maxTokenSize);
...@@ -46,7 +46,7 @@ class Preprocessor ...@@ -46,7 +46,7 @@ class Preprocessor
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(Preprocessor); PP_DISALLOW_COPY_AND_ASSIGN(Preprocessor);
PreprocessorImpl* mImpl; PreprocessorImpl *mImpl;
}; };
} // namespace pp } // namespace pp
......
...@@ -12,10 +12,18 @@ namespace pp ...@@ -12,10 +12,18 @@ namespace pp
struct SourceLocation struct SourceLocation
{ {
SourceLocation() : file(0), line(0) { } SourceLocation()
SourceLocation(int f, int l) : file(f), line(l) { } : file(0),
line(0)
{
}
SourceLocation(int f, int l)
: file(f),
line(l)
{
}
bool equals(const SourceLocation& other) const bool equals(const SourceLocation &other) const
{ {
return (file == other.file) && (line == other.line); return (file == other.file) && (line == other.line);
} }
...@@ -24,12 +32,12 @@ struct SourceLocation ...@@ -24,12 +32,12 @@ struct SourceLocation
int line; int line;
}; };
inline bool operator==(const SourceLocation& lhs, const SourceLocation& rhs) inline bool operator==(const SourceLocation &lhs, const SourceLocation &rhs)
{ {
return lhs.equals(rhs); return lhs.equals(rhs);
} }
inline bool operator!=(const SourceLocation& lhs, const SourceLocation& rhs) inline bool operator!=(const SourceLocation &lhs, const SourceLocation &rhs)
{ {
return !lhs.equals(rhs); return !lhs.equals(rhs);
} }
......
...@@ -21,7 +21,7 @@ void Token::reset() ...@@ -21,7 +21,7 @@ void Token::reset()
text.clear(); text.clear();
} }
bool Token::equals(const Token& other) const bool Token::equals(const Token &other) const
{ {
return (type == other.type) && return (type == other.type) &&
(flags == other.flags) && (flags == other.flags) &&
...@@ -53,25 +53,25 @@ void Token::setExpansionDisabled(bool disable) ...@@ -53,25 +53,25 @@ void Token::setExpansionDisabled(bool disable)
flags &= ~EXPANSION_DISABLED; flags &= ~EXPANSION_DISABLED;
} }
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);
} }
std::ostream& operator<<(std::ostream& out, const Token& token) std::ostream &operator<<(std::ostream &out, const Token &token)
{ {
if (token.hasLeadingSpace()) if (token.hasLeadingSpace())
out << " "; out << " ";
......
...@@ -62,27 +62,40 @@ struct Token ...@@ -62,27 +62,40 @@ struct Token
EXPANSION_DISABLED = 1 << 2 EXPANSION_DISABLED = 1 << 2
}; };
Token() : type(0), flags(0) { } Token()
: type(0),
flags(0)
{
}
void reset(); void reset();
bool equals(const Token& other) const; bool equals(const Token &other) const;
// Returns true if this is the first token on line. // Returns true if this is the first token on line.
// It disregards any leading whitespace. // 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); 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); void setHasLeadingSpace(bool space);
bool expansionDisabled() const { return (flags & EXPANSION_DISABLED) != 0; } bool expansionDisabled() const
{
return (flags & EXPANSION_DISABLED) != 0;
}
void setExpansionDisabled(bool disable); void setExpansionDisabled(bool disable);
// Converts text into numeric value for CONST_INT and CONST_FLOAT token. // Converts text into numeric value for CONST_INT and CONST_FLOAT token.
// Returns false if the parsed value cannot fit into an int or float. // Returns false if the parsed value cannot fit into an int or float.
bool iValue(int* value) const; bool iValue(int *value) const;
bool uValue(unsigned int* value) const; bool uValue(unsigned int *value) const;
bool fValue(float* value) const; bool fValue(float *value) const;
int type; int type;
unsigned int flags; unsigned int flags;
...@@ -90,17 +103,17 @@ struct Token ...@@ -90,17 +103,17 @@ struct Token
std::string text; std::string text;
}; };
inline bool operator==(const Token& lhs, const Token& rhs) inline bool operator==(const Token &lhs, const Token &rhs)
{ {
return lhs.equals(rhs); return lhs.equals(rhs);
} }
inline bool operator!=(const Token& lhs, const Token& rhs) 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); extern std::ostream &operator<<(std::ostream &out, const Token &token);
} // namepsace pp } // namepsace pp
#endif // COMPILER_PREPROCESSOR_TOKEN_H_ #endif // COMPILER_PREPROCESSOR_TOKEN_H_
...@@ -2316,7 +2316,7 @@ void ppfree (void * ptr , yyscan_t yyscanner) ...@@ -2316,7 +2316,7 @@ void ppfree (void * ptr , yyscan_t yyscanner)
namespace pp { namespace pp {
Tokenizer::Tokenizer(Diagnostics* diagnostics) Tokenizer::Tokenizer(Diagnostics *diagnostics)
: mHandle(0), : mHandle(0),
mMaxTokenSize(256) mMaxTokenSize(256)
{ {
...@@ -2328,9 +2328,10 @@ Tokenizer::~Tokenizer() ...@@ -2328,9 +2328,10 @@ Tokenizer::~Tokenizer()
destroyScanner(); destroyScanner();
} }
bool Tokenizer::init(size_t count, const char* const string[], const int length[]) bool Tokenizer::init(size_t count, const char * const string[], const int length[])
{ {
if ((count > 0) && (string == 0)) return false; if ((count > 0) && (string == 0))
return false;
mContext.input = Input(count, string, length); mContext.input = Input(count, string, length);
return initScanner(); return initScanner();
...@@ -2353,7 +2354,7 @@ void Tokenizer::setMaxTokenSize(size_t maxTokenSize) ...@@ -2353,7 +2354,7 @@ void Tokenizer::setMaxTokenSize(size_t maxTokenSize)
mMaxTokenSize = maxTokenSize; mMaxTokenSize = maxTokenSize;
} }
void Tokenizer::lex(Token* token) void Tokenizer::lex(Token *token)
{ {
token->type = pplex(&token->text,&token->location,mHandle); token->type = pplex(&token->text,&token->location,mHandle);
if (token->text.size() > mMaxTokenSize) if (token->text.size() > mMaxTokenSize)
......
...@@ -21,7 +21,7 @@ class Tokenizer : public Lexer ...@@ -21,7 +21,7 @@ class Tokenizer : public Lexer
public: public:
struct Context struct Context
{ {
Diagnostics* diagnostics; Diagnostics *diagnostics;
Input input; Input input;
// The location where yytext points to. Token location should track // The location where yytext points to. Token location should track
...@@ -33,23 +33,23 @@ class Tokenizer : public Lexer ...@@ -33,23 +33,23 @@ class Tokenizer : public Lexer
bool lineStart; bool lineStart;
}; };
Tokenizer(Diagnostics* diagnostics); Tokenizer(Diagnostics *diagnostics);
~Tokenizer(); ~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 setFileNumber(int file);
void setLineNumber(int line); void setLineNumber(int line);
void setMaxTokenSize(size_t maxTokenSize); void setMaxTokenSize(size_t maxTokenSize);
virtual void lex(Token* token); virtual void lex(Token *token);
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(Tokenizer); PP_DISALLOW_COPY_AND_ASSIGN(Tokenizer);
bool initScanner(); bool initScanner();
void destroyScanner(); void destroyScanner();
void* mHandle; // Scanner handle. void *mHandle; // Scanner handle.
Context mContext; // Scanner extra. Context mContext; // Scanner extra.
size_t mMaxTokenSize; // Maximum token size size_t mMaxTokenSize; // Maximum token size
}; };
......
...@@ -267,7 +267,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -267,7 +267,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
namespace pp { namespace pp {
Tokenizer::Tokenizer(Diagnostics* diagnostics) : mHandle(0) Tokenizer::Tokenizer(Diagnostics *diagnostics) : mHandle(0)
{ {
mContext.diagnostics = diagnostics; mContext.diagnostics = diagnostics;
} }
...@@ -277,9 +277,10 @@ Tokenizer::~Tokenizer() ...@@ -277,9 +277,10 @@ Tokenizer::~Tokenizer()
destroyScanner(); destroyScanner();
} }
bool Tokenizer::init(size_t count, const char* const string[], const int length[]) bool Tokenizer::init(size_t count, const char * const string[], const int length[])
{ {
if ((count > 0) && (string == 0)) return false; if ((count > 0) && (string == 0))
return false;
mContext.input = Input(count, string, length); mContext.input = Input(count, string, length);
return initScanner(); return initScanner();
...@@ -302,7 +303,7 @@ void Tokenizer::setMaxTokenSize(size_t maxTokenSize) ...@@ -302,7 +303,7 @@ void Tokenizer::setMaxTokenSize(size_t maxTokenSize)
mMaxTokenSize = maxTokenSize; mMaxTokenSize = maxTokenSize;
} }
void Tokenizer::lex(Token* token) void Tokenizer::lex(Token *token)
{ {
token->type = yylex(&token->text, &token->location, mHandle); token->type = yylex(&token->text, &token->location, mHandle);
if (token->text.size() > mMaxTokenSize) if (token->text.size() > mMaxTokenSize)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
namespace pp { namespace pp {
inline std::ios::fmtflags numeric_base_int(const std::string& str) inline std::ios::fmtflags numeric_base_int(const std::string &str)
{ {
if ((str.size() >= 2) && if ((str.size() >= 2) &&
(str[0] == '0') && (str[0] == '0') &&
...@@ -21,7 +21,7 @@ inline std::ios::fmtflags numeric_base_int(const std::string& str) ...@@ -21,7 +21,7 @@ inline std::ios::fmtflags numeric_base_int(const std::string& str)
{ {
return std::ios::hex; return std::ios::hex;
} }
else if ((str.size() >= 1) && (str[0] == '0')) if ((str.size() >= 1) && (str[0] == '0'))
{ {
return std::ios::oct; return std::ios::oct;
} }
...@@ -34,7 +34,7 @@ inline std::ios::fmtflags numeric_base_int(const std::string& str) ...@@ -34,7 +34,7 @@ inline std::ios::fmtflags numeric_base_int(const std::string& str)
// in which case false is returned. // in which case false is returned.
template<typename IntType> template<typename IntType>
bool numeric_lex_int(const std::string& str, IntType* value) bool numeric_lex_int(const std::string &str, IntType *value)
{ {
std::istringstream stream(str); std::istringstream stream(str);
// This should not be necessary, but MSVS has a buggy implementation. // This should not be necessary, but MSVS has a buggy implementation.
...@@ -46,7 +46,7 @@ bool numeric_lex_int(const std::string& str, IntType* value) ...@@ -46,7 +46,7 @@ bool numeric_lex_int(const std::string& str, IntType* value)
} }
template<typename FloatType> template<typename FloatType>
bool numeric_lex_float(const std::string& str, FloatType* value) bool numeric_lex_float(const std::string &str, FloatType *value)
{ {
std::istringstream stream(str); std::istringstream stream(str);
// Force "C" locale so that decimal character is always '.', and // Force "C" locale so that decimal character is always '.', and
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// A macro to disallow the copy constructor and operator= functions // A macro to disallow the copy constructor and operator= functions
// This must be used in the private: declarations for a class. // This must be used in the private: declarations for a class.
#define PP_DISALLOW_COPY_AND_ASSIGN(TypeName) \ #define PP_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \ TypeName(const TypeName &); \
void operator=(const TypeName&) void operator=(const TypeName &)
#endif // COMPILER_PREPROCESSOR_PPUTILS_H_ #endif // COMPILER_PREPROCESSOR_PPUTILS_H_
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