Commit 3a01d1bc by alokp@chromium.org

Preparation for macro expansion.

Review URL: http://codereview.appspot.com/4919045 git-svn-id: https://angleproject.googlecode.com/svn/trunk@741 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent e4eb9911
...@@ -6,15 +6,107 @@ ...@@ -6,15 +6,107 @@
#include "Context.h" #include "Context.h"
#include <algorithm>
#include <sstream>
#include "compiler/debug.h"
#include "stl_utils.h"
#include "token_type.h"
namespace pp namespace pp
{ {
Context::Context(int count, const char* const string[], const int length[], Context::Context()
TokenVector* output) : mLexer(NULL),
: input(count, string, length), mInput(NULL),
output(output), mOutput(NULL)
lexer(NULL) {
}
Context::~Context()
{ {
destroyLexer();
}
bool Context::init()
{
return initLexer();
// TODO(alokp): Define built-in macros here so that we do not need to
// define them everytime in process().
}
bool Context::process(int count,
const char* const string[],
const int length[],
TokenVector* output)
{
ASSERT((count >=0) && (string != NULL) && (output != NULL));
// Setup.
mInput = new Input(count, string, length);
mOutput = output;
defineBuiltInMacro("GL_ES", 1);
// Parse.
bool success = parse();
// Cleanup.
reset();
return success;
}
bool Context::defineMacro(pp::Token::Location location,
pp::Macro::Type type,
std::string* identifier,
pp::Macro::ParameterVector* parameters,
pp::TokenVector* replacements)
{
// TODO(alokp): Check for reserved macro names and duplicate macros.
mMacros[*identifier] = new Macro(type, identifier, parameters, replacements);
return true;
}
bool Context::undefineMacro(const std::string* identifier)
{
MacroSet::iterator iter = mMacros.find(*identifier);
if (iter == mMacros.end())
{
// TODO(alokp): Report error.
return false;
}
mMacros.erase(iter);
return true;
}
bool Context::isMacroDefined(const std::string* identifier)
{
return mMacros.find(*identifier) != mMacros.end();
}
// Reset to initialized state.
void Context::reset()
{
std::for_each(mMacros.begin(), mMacros.end(), DeleteSecond());
mMacros.clear();
delete mInput;
mInput = NULL;
mOutput = NULL;
}
void Context::defineBuiltInMacro(const std::string& identifier, int value)
{
std::ostringstream stream;
stream << value;
Token* token = new Token(0, INT_CONSTANT, new std::string(stream.str()));
TokenVector* replacements = new pp::TokenVector(1, token);
mMacros[identifier] = new Macro(Macro::kTypeObj,
new std::string(identifier),
NULL,
replacements);
} }
} // namespace pp } // namespace pp
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#ifndef COMPILER_PREPROCESSOR_CONTEXT_H_ #ifndef COMPILER_PREPROCESSOR_CONTEXT_H_
#define COMPILER_PREPROCESSOR_CONTEXT_H_ #define COMPILER_PREPROCESSOR_CONTEXT_H_
#include <map>
#include "common/angleutils.h"
#include "Input.h" #include "Input.h"
#include "Macro.h" #include "Macro.h"
#include "Token.h" #include "Token.h"
...@@ -14,16 +17,42 @@ ...@@ -14,16 +17,42 @@
namespace pp namespace pp
{ {
struct Context class Context
{ {
Context(int count, const char* const string[], const int length[], public:
TokenVector* output); Context();
~Context();
Input input;
TokenVector* output; bool init();
bool process(int count, const char* const string[], const int length[],
void* lexer; // Lexer handle. TokenVector* output);
MacroSet macros; // Defined macros.
void* lexer() { return mLexer; }
int readInput(char* buf, int maxSize);
TokenVector* output() { return mOutput; }
bool defineMacro(pp::Token::Location location,
pp::Macro::Type type,
std::string* identifier,
pp::Macro::ParameterVector* parameters,
pp::TokenVector* replacements);
bool undefineMacro(const std::string* identifier);
bool isMacroDefined(const std::string* identifier);
private:
DISALLOW_COPY_AND_ASSIGN(Context);
typedef std::map<std::string, Macro*> MacroSet;
void reset();
bool initLexer();
void destroyLexer();
void defineBuiltInMacro(const std::string& identifier, int value);
bool parse();
void* mLexer; // Lexer handle.
Input* mInput;
TokenVector* mOutput;
MacroSet mMacros; // Defined macros.
}; };
} // namespace pp } // namespace pp
......
//
// Copyright (c) 2011 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.
//
#include "Macro.h"
#include <algorithm>
#include "stl_utils.h"
namespace pp
{
Macro::Macro(Type type,
std::string* identifier,
ParameterVector* parameters,
TokenVector* replacements)
: mType(type),
mIdentifier(identifier),
mParameters(parameters),
mReplacements(replacements)
{
}
Macro::~Macro()
{
delete mIdentifier;
if (mParameters)
{
std::for_each(mParameters->begin(), mParameters->end(), Delete());
delete mParameters;
}
if (mReplacements)
{
std::for_each(mReplacements->begin(), mReplacements->end(), Delete());
delete mReplacements;
}
}
} // namespace pp
...@@ -7,27 +7,45 @@ ...@@ -7,27 +7,45 @@
#ifndef COMPILER_PREPROCESSOR_MACRO_H_ #ifndef COMPILER_PREPROCESSOR_MACRO_H_
#define COMPILER_PREPROCESSOR_MACRO_H_ #define COMPILER_PREPROCESSOR_MACRO_H_
#include <map>
#include <string> #include <string>
#include <vector>
#include "common/angleutils.h"
#include "Token.h" #include "Token.h"
namespace pp namespace pp
{ {
struct Macro class Macro
{ {
public:
enum Type enum Type
{ {
kTypeObj, kTypeObj,
kTypeFunc kTypeFunc
}; };
Type type; typedef std::vector<std::string*> ParameterVector;
std::string identifier;
TokenVector parameters; // Takes ownership of pointer parameters.
TokenVector replacements; Macro(Type type,
std::string* identifier,
ParameterVector* parameters,
TokenVector* replacements);
~Macro();
Type type() const { return mType; }
const std::string* identifier() const { return mIdentifier; }
const ParameterVector* parameters() const { return mParameters; }
const TokenVector* replacements() const { return mReplacements; }
private:
DISALLOW_COPY_AND_ASSIGN(Macro);
Type mType;
std::string* mIdentifier;
ParameterVector* mParameters;
TokenVector* mReplacements;
}; };
typedef std::map<std::string, Macro> MacroSet;
} // namespace pp } // namespace pp
#endif COMPILER_PREPROCESSOR_MACRO_H_ #endif COMPILER_PREPROCESSOR_MACRO_H_
......
...@@ -6,12 +6,30 @@ ...@@ -6,12 +6,30 @@
#include "Preprocessor.h" #include "Preprocessor.h"
#include <algorithm>
#include "compiler/debug.h" #include "compiler/debug.h"
#include "Context.h" #include "Context.h"
#include "stl_utils.h"
namespace pp namespace pp
{ {
Preprocessor::Preprocessor() : mContext(NULL)
{
}
Preprocessor::~Preprocessor()
{
delete mContext;
}
bool Preprocessor::init()
{
mContext = new Context;
return mContext->init();
}
bool Preprocessor::process(int count, bool Preprocessor::process(int count,
const char* const string[], const char* const string[],
const int length[]) const int length[])
...@@ -20,22 +38,14 @@ bool Preprocessor::process(int count, ...@@ -20,22 +38,14 @@ bool Preprocessor::process(int count,
if ((count < 0) || (string == NULL)) if ((count < 0) || (string == NULL))
return false; return false;
clearResults(); reset();
Context context(count, string, length, &mTokens);
if (!initLexer(&context))
return false;
bool success = parse(&context);
destroyLexer(&context); return mContext->process(count, string, length, &mTokens);
return success;
} }
void Preprocessor::clearResults() void Preprocessor::reset()
{ {
for (TokenVector::iterator i = mTokens.begin(); i != mTokens.end(); ++i) std::for_each(mTokens.begin(), mTokens.end(), Delete());
delete (*i);
mTokens.clear(); mTokens.clear();
} }
......
...@@ -13,27 +13,27 @@ ...@@ -13,27 +13,27 @@
namespace pp namespace pp
{ {
struct Context; class Context;
class Preprocessor class Preprocessor
{ {
public: public:
Preprocessor() { } Preprocessor();
~Preprocessor();
bool process(int count, const char* const string[], const int length[]); bool init();
bool process(int count, const char* const string[], const int length[]);
TokenIterator begin() const { return mTokens.begin(); } TokenIterator begin() const { return mTokens.begin(); }
TokenIterator end() const { return mTokens.end(); } TokenIterator end() const { return mTokens.end(); }
private: private:
DISALLOW_COPY_AND_ASSIGN(Preprocessor); DISALLOW_COPY_AND_ASSIGN(Preprocessor);
static bool initLexer(Context* context); // Reset to initialized state.
static void destroyLexer(Context* context); void reset();
static bool parse(Context* context);
void clearResults();
Context* mContext;
TokenVector mTokens; // Output. TokenVector mTokens; // Output.
}; };
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "common/angleutils.h"
namespace pp namespace pp
{ {
...@@ -29,6 +31,8 @@ class Token ...@@ -29,6 +31,8 @@ class Token
const std::string* value() const { return mValue; } const std::string* value() const { return mValue; }
private: private:
DISALLOW_COPY_AND_ASSIGN(Token);
Location mLocation; Location mLocation;
int mType; int mType;
std::string* mValue; std::string* mValue;
......
...@@ -26,7 +26,6 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -26,7 +26,6 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#include "compiler/debug.h" #include "compiler/debug.h"
#include "Context.h" #include "Context.h"
#include "pp_tab.h" #include "pp_tab.h"
#include "Preprocessor.h"
#define YY_USER_ACTION \ #define YY_USER_ACTION \
do { \ do { \
...@@ -36,9 +35,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -36,9 +35,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
} while(0); } while(0);
#define YY_INPUT(buf, result, maxSize) \ #define YY_INPUT(buf, result, maxSize) \
result = readInput(yyextra, buf, maxSize); result = yyextra->readInput(buf, maxSize);
static int readInput(pp::Context* context, char* buf, int maxSize);
%} %}
%option noyywrap nounput never-interactive %option noyywrap nounput never-interactive
...@@ -110,24 +107,23 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -110,24 +107,23 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
%% %%
int readInput(pp::Context* context, char* buf, int maxSize) namespace pp {
{
yyscan_t lexer = context->lexer;
ASSERT(lexer);
int Context::readInput(char* buf, int maxSize)
{
int nread = YY_NULL; int nread = YY_NULL;
while (!context->input.eof() && while (!mInput->eof() &&
(context->input.error() == pp::Input::kErrorNone) && (mInput->error() == pp::Input::kErrorNone) &&
(nread == YY_NULL)) (nread == YY_NULL))
{ {
int line = 0, file = 0; int line = 0, file = 0;
pp::Token::decodeLocation(yyget_lineno(lexer), &line, &file); pp::Token::decodeLocation(yyget_lineno(mLexer), &line, &file);
file = context->input.stringIndex(); file = mInput->stringIndex();
yyset_lineno(pp::Token::encodeLocation(line, file), lexer); yyset_lineno(pp::Token::encodeLocation(line, file), mLexer);
nread = context->input.read(buf, maxSize); nread = mInput->read(buf, maxSize);
if (context->input.error() == pp::Input::kErrorUnexpectedEOF) if (mInput->error() == pp::Input::kErrorUnexpectedEOF)
{ {
// TODO(alokp): Report error. // TODO(alokp): Report error.
} }
...@@ -135,27 +131,23 @@ int readInput(pp::Context* context, char* buf, int maxSize) ...@@ -135,27 +131,23 @@ int readInput(pp::Context* context, char* buf, int maxSize)
return nread; return nread;
} }
namespace pp { bool Context::initLexer()
bool Preprocessor::initLexer(Context* context)
{ {
ASSERT(context->lexer == NULL); ASSERT(mLexer == NULL);
yyscan_t lexer = 0; if (yylex_init_extra(this, &mLexer))
if (yylex_init_extra(context, &lexer))
return false; return false;
context->lexer = lexer; yyrestart(0, mLexer);
yyrestart(0, lexer);
return true; return true;
} }
void Preprocessor::destroyLexer(Context* context) void Context::destroyLexer()
{ {
ASSERT(context->lexer); ASSERT(mLexer);
yylex_destroy(context->lexer); yylex_destroy(mLexer);
context->lexer = 0; mLexer = NULL;
} }
} // namespace pp } // namespace pp
......
...@@ -23,9 +23,8 @@ WHICH GENERATES THE GLSL ES PARSER. ...@@ -23,9 +23,8 @@ WHICH GENERATES THE GLSL ES PARSER.
// This file is auto-generated by generate_glslang_parser.sh. DO NOT EDIT! // This file is auto-generated by generate_glslang_parser.sh. DO NOT EDIT!
#include "Context.h" #include "Context.h"
#include "Preprocessor.h"
#define YYLEX_PARAM context->lexer #define YYLEX_PARAM context->lexer()
#define YYDEBUG 1 #define YYDEBUG 1
%} %}
...@@ -48,14 +47,6 @@ static void yyerror(YYLTYPE* llocp, ...@@ -48,14 +47,6 @@ static void yyerror(YYLTYPE* llocp,
pp::Context* context, pp::Context* context,
const char* reason); const char* reason);
static void defineMacro(pp::Context* context,
YYLTYPE* llocp,
pp::Macro::Type type,
const std::string* identifier,
std::vector<std::string*>* parameters,
pp::TokenVector* replacements);
static void undefineMacro(pp::Context* context, const std::string* identifier);
static bool isMacroDefined(pp::Context* context, const std::string* identifier);
static void pushConditionalBlock(pp::Context* context, bool condition); static void pushConditionalBlock(pp::Context* context, bool condition);
static void popConditionalBlock(pp::Context* context); static void popConditionalBlock(pp::Context* context);
%} %}
...@@ -79,7 +70,7 @@ input ...@@ -79,7 +70,7 @@ input
line line
: text_line { : text_line {
// TODO(alokp): Expand macros. // TODO(alokp): Expand macros.
pp::TokenVector* out = context->output; pp::TokenVector* out = context->output();
out->insert(out->end(), $1->begin(), $1->end()); out->insert(out->end(), $1->begin(), $1->end());
delete $1; delete $1;
} }
...@@ -94,22 +85,22 @@ text_line ...@@ -94,22 +85,22 @@ text_line
control_line control_line
: HASH '\n' : HASH '\n'
| HASH_DEFINE_OBJ IDENTIFIER replacement_token_list '\n' { | HASH_DEFINE_OBJ IDENTIFIER replacement_token_list '\n' {
defineMacro(context, & @2, pp::Macro::kTypeObj, $2, NULL, $3); context->defineMacro(@2.first_line, pp::Macro::kTypeObj, $2, NULL, $3);
} }
| HASH_DEFINE_FUNC IDENTIFIER '(' parameter_list ')' replacement_token_list '\n' { | HASH_DEFINE_FUNC IDENTIFIER '(' parameter_list ')' replacement_token_list '\n' {
defineMacro(context, & @2, pp::Macro::kTypeFunc, $2, $4, $6); context->defineMacro(@2.first_line, pp::Macro::kTypeFunc, $2, $4, $6);
} }
| HASH_UNDEF IDENTIFIER '\n' { | HASH_UNDEF IDENTIFIER '\n' {
undefineMacro(context, $2); context->undefineMacro($2);
} }
| HASH_IF conditional_token_list '\n' { | HASH_IF conditional_token_list '\n' {
pushConditionalBlock(context, $2 ? true : false); pushConditionalBlock(context, $2 ? true : false);
} }
| HASH_IFDEF IDENTIFIER '\n' { | HASH_IFDEF IDENTIFIER '\n' {
pushConditionalBlock(context, isMacroDefined(context, $2)); pushConditionalBlock(context, context->isMacroDefined($2));
} }
| HASH_IFNDEF IDENTIFIER '\n' { | HASH_IFNDEF IDENTIFIER '\n' {
pushConditionalBlock(context, !isMacroDefined(context, $2)); pushConditionalBlock(context, !context->isMacroDefined($2));
} }
| HASH_ELIF conditional_token_list '\n' { | HASH_ELIF conditional_token_list '\n' {
} }
...@@ -223,24 +214,6 @@ void yyerror(YYLTYPE* llocp, pp::Context* context, const char* reason) ...@@ -223,24 +214,6 @@ void yyerror(YYLTYPE* llocp, pp::Context* context, const char* reason)
{ {
} }
void defineMacro(pp::Context* context,
YYLTYPE* llocp,
pp::Macro::Type type,
const std::string* identifier,
std::vector<std::string*>* parameters,
pp::TokenVector* replacements)
{
}
void undefineMacro(pp::Context* context, const std::string* identifier)
{
}
bool isMacroDefined(pp::Context* context, const std::string* identifier)
{
return false;
}
void pushConditionalBlock(pp::Context* context, bool condition) void pushConditionalBlock(pp::Context* context, bool condition)
{ {
} }
...@@ -250,10 +223,10 @@ void popConditionalBlock(pp::Context* context) ...@@ -250,10 +223,10 @@ void popConditionalBlock(pp::Context* context)
} }
namespace pp { namespace pp {
bool Preprocessor::parse(Context* context) bool Context::parse()
{ {
yydebug = 1; yydebug = 1;
return yyparse(context) == 0 ? true : false; return yyparse(this) == 0 ? true : false;
} }
} // namespace pp } // namespace pp
...@@ -571,7 +571,6 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -571,7 +571,6 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#include "compiler/debug.h" #include "compiler/debug.h"
#include "Context.h" #include "Context.h"
#include "pp_tab.h" #include "pp_tab.h"
#include "Preprocessor.h"
#define YY_USER_ACTION \ #define YY_USER_ACTION \
do { \ do { \
...@@ -581,9 +580,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -581,9 +580,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
} while(0); } while(0);
#define YY_INPUT(buf, result, maxSize) \ #define YY_INPUT(buf, result, maxSize) \
result = readInput(yyextra, buf, maxSize); result = yyextra->readInput(buf, maxSize);
static int readInput(pp::Context* context, char* buf, int maxSize);
#define INITIAL 0 #define INITIAL 0
...@@ -2224,24 +2221,23 @@ void ppfree (void * ptr , yyscan_t yyscanner) ...@@ -2224,24 +2221,23 @@ void ppfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
int readInput(pp::Context* context, char* buf, int maxSize) namespace pp {
{
yyscan_t lexer = context->lexer;
ASSERT(lexer);
int Context::readInput(char* buf, int maxSize)
{
int nread = YY_NULL; int nread = YY_NULL;
while (!context->input.eof() && while (!mInput->eof() &&
(context->input.error() == pp::Input::kErrorNone) && (mInput->error() == pp::Input::kErrorNone) &&
(nread == YY_NULL)) (nread == YY_NULL))
{ {
int line = 0, file = 0; int line = 0, file = 0;
pp::Token::decodeLocation(ppget_lineno(lexer), &line, &file); pp::Token::decodeLocation(ppget_lineno(mLexer), &line, &file);
file = context->input.stringIndex(); file = mInput->stringIndex();
ppset_lineno(pp::Token::encodeLocation(line, file),lexer); ppset_lineno(pp::Token::encodeLocation(line, file),mLexer);
nread = context->input.read(buf, maxSize); nread = mInput->read(buf, maxSize);
if (context->input.error() == pp::Input::kErrorUnexpectedEOF) if (mInput->error() == pp::Input::kErrorUnexpectedEOF)
{ {
// TODO(alokp): Report error. // TODO(alokp): Report error.
} }
...@@ -2249,27 +2245,23 @@ int readInput(pp::Context* context, char* buf, int maxSize) ...@@ -2249,27 +2245,23 @@ int readInput(pp::Context* context, char* buf, int maxSize)
return nread; return nread;
} }
namespace pp { bool Context::initLexer()
bool Preprocessor::initLexer(Context* context)
{ {
ASSERT(context->lexer == NULL); ASSERT(mLexer == NULL);
yyscan_t lexer = 0; if (pplex_init_extra(this,&mLexer))
if (pplex_init_extra(context,&lexer))
return false; return false;
context->lexer = lexer; pprestart(0,mLexer);
pprestart(0,lexer);
return true; return true;
} }
void Preprocessor::destroyLexer(Context* context) void Context::destroyLexer()
{ {
ASSERT(context->lexer); ASSERT(mLexer);
pplex_destroy(context->lexer); pplex_destroy(mLexer);
context->lexer = 0; mLexer = NULL;
} }
} // namespace pp } // namespace pp
......
...@@ -133,9 +133,8 @@ ...@@ -133,9 +133,8 @@
// This file is auto-generated by generate_glslang_parser.sh. DO NOT EDIT! // This file is auto-generated by generate_glslang_parser.sh. DO NOT EDIT!
#include "Context.h" #include "Context.h"
#include "Preprocessor.h"
#define YYLEX_PARAM context->lexer #define YYLEX_PARAM context->lexer()
#define YYDEBUG 1 #define YYDEBUG 1
...@@ -197,14 +196,6 @@ static void yyerror(YYLTYPE* llocp, ...@@ -197,14 +196,6 @@ static void yyerror(YYLTYPE* llocp,
pp::Context* context, pp::Context* context,
const char* reason); const char* reason);
static void defineMacro(pp::Context* context,
YYLTYPE* llocp,
pp::Macro::Type type,
const std::string* identifier,
std::vector<std::string*>* parameters,
pp::TokenVector* replacements);
static void undefineMacro(pp::Context* context, const std::string* identifier);
static bool isMacroDefined(pp::Context* context, const std::string* identifier);
static void pushConditionalBlock(pp::Context* context, bool condition); static void pushConditionalBlock(pp::Context* context, bool condition);
static void popConditionalBlock(pp::Context* context); static void popConditionalBlock(pp::Context* context);
...@@ -517,13 +508,13 @@ static const yytype_int8 yyrhs[] = ...@@ -517,13 +508,13 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] = static const yytype_uint8 yyrline[] =
{ {
0, 74, 74, 76, 80, 86, 90, 91, 95, 96, 0, 65, 65, 67, 71, 77, 81, 82, 86, 87,
99, 102, 105, 108, 111, 114, 116, 118, 121, 122, 90, 93, 96, 99, 102, 105, 107, 109, 112, 113,
123, 124, 125, 129, 130, 134, 138, 145, 147, 149, 114, 115, 116, 120, 121, 125, 129, 136, 138, 140,
153, 154, 158, 165, 169, 176, 179, 182, 185, 188, 144, 145, 149, 156, 160, 167, 170, 173, 176, 179,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
214, 215, 216, 217 205, 206, 207, 208
}; };
#endif #endif
...@@ -1552,7 +1543,7 @@ yyreduce: ...@@ -1552,7 +1543,7 @@ yyreduce:
{ {
// TODO(alokp): Expand macros. // TODO(alokp): Expand macros.
pp::TokenVector* out = context->output; pp::TokenVector* out = context->output();
out->insert(out->end(), (yyvsp[(1) - (1)].tlist)->begin(), (yyvsp[(1) - (1)].tlist)->end()); out->insert(out->end(), (yyvsp[(1) - (1)].tlist)->begin(), (yyvsp[(1) - (1)].tlist)->end());
delete (yyvsp[(1) - (1)].tlist); delete (yyvsp[(1) - (1)].tlist);
;} ;}
...@@ -1571,21 +1562,21 @@ yyreduce: ...@@ -1571,21 +1562,21 @@ yyreduce:
case 9: case 9:
{ {
defineMacro(context, & (yylsp[(2) - (4)]), pp::Macro::kTypeObj, (yyvsp[(2) - (4)].sval), NULL, (yyvsp[(3) - (4)].tlist)); context->defineMacro((yylsp[(2) - (4)]).first_line, pp::Macro::kTypeObj, (yyvsp[(2) - (4)].sval), NULL, (yyvsp[(3) - (4)].tlist));
;} ;}
break; break;
case 10: case 10:
{ {
defineMacro(context, & (yylsp[(2) - (7)]), pp::Macro::kTypeFunc, (yyvsp[(2) - (7)].sval), (yyvsp[(4) - (7)].slist), (yyvsp[(6) - (7)].tlist)); context->defineMacro((yylsp[(2) - (7)]).first_line, pp::Macro::kTypeFunc, (yyvsp[(2) - (7)].sval), (yyvsp[(4) - (7)].slist), (yyvsp[(6) - (7)].tlist));
;} ;}
break; break;
case 11: case 11:
{ {
undefineMacro(context, (yyvsp[(2) - (3)].sval)); context->undefineMacro((yyvsp[(2) - (3)].sval));
;} ;}
break; break;
...@@ -1599,14 +1590,14 @@ yyreduce: ...@@ -1599,14 +1590,14 @@ yyreduce:
case 13: case 13:
{ {
pushConditionalBlock(context, isMacroDefined(context, (yyvsp[(2) - (3)].sval))); pushConditionalBlock(context, context->isMacroDefined((yyvsp[(2) - (3)].sval)));
;} ;}
break; break;
case 14: case 14:
{ {
pushConditionalBlock(context, !isMacroDefined(context, (yyvsp[(2) - (3)].sval))); pushConditionalBlock(context, !context->isMacroDefined((yyvsp[(2) - (3)].sval)));
;} ;}
break; break;
...@@ -2083,24 +2074,6 @@ void yyerror(YYLTYPE* llocp, pp::Context* context, const char* reason) ...@@ -2083,24 +2074,6 @@ void yyerror(YYLTYPE* llocp, pp::Context* context, const char* reason)
{ {
} }
void defineMacro(pp::Context* context,
YYLTYPE* llocp,
pp::Macro::Type type,
const std::string* identifier,
std::vector<std::string*>* parameters,
pp::TokenVector* replacements)
{
}
void undefineMacro(pp::Context* context, const std::string* identifier)
{
}
bool isMacroDefined(pp::Context* context, const std::string* identifier)
{
return false;
}
void pushConditionalBlock(pp::Context* context, bool condition) void pushConditionalBlock(pp::Context* context, bool condition)
{ {
} }
...@@ -2110,10 +2083,10 @@ void popConditionalBlock(pp::Context* context) ...@@ -2110,10 +2083,10 @@ void popConditionalBlock(pp::Context* context)
} }
namespace pp { namespace pp {
bool Preprocessor::parse(Context* context) bool Context::parse()
{ {
yydebug = 1; yydebug = 1;
return yyparse(context) == 0 ? true : false; return yyparse(this) == 0 ? true : false;
} }
} // namespace pp } // namespace pp
......
//
// Copyright (c) 2011 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.
//
// stl_utils.h: Common STL utilities.
#ifndef COMMON_STLUTILS_H_
#define COMMON_STLUTILS_H_
namespace pp
{
struct Delete
{
template<class T>
void operator() (T x) { delete x; }
};
struct DeleteSecond
{
template<class A, class B>
void operator() (std::pair<A, B>& x) { delete x.second; }
};
} // namespace pp
#endif // COMMON_STLUTILS_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