Commit 16efbbae by alokp@chromium.org

Complete implementation for handling #define directive.

Review URL: http://codereview.appspot.com/4963062 git-svn-id: https://angleproject.googlecode.com/svn/trunk@752 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 8a4dad60
...@@ -13,6 +13,21 @@ ...@@ -13,6 +13,21 @@
#include "stl_utils.h" #include "stl_utils.h"
#include "token_type.h" #include "token_type.h"
static bool isMacroNameReserved(const std::string* name)
{
ASSERT(name);
// Names prefixed with "GL_" are reserved.
if (name->substr(0, 3) == "GL_")
return true;
// Names containing two consecutive underscores are reserved.
if (name->find("__") != std::string::npos)
return true;
return false;
}
namespace pp namespace pp
{ {
...@@ -58,18 +73,29 @@ bool Context::process(int count, ...@@ -58,18 +73,29 @@ bool Context::process(int count,
bool Context::defineMacro(pp::Token::Location location, bool Context::defineMacro(pp::Token::Location location,
pp::Macro::Type type, pp::Macro::Type type,
std::string* identifier, std::string* name,
pp::Macro::ParameterVector* parameters, pp::TokenVector* parameters,
pp::TokenVector* replacements) pp::TokenVector* replacements)
{ {
// TODO(alokp): Check for reserved macro names and duplicate macros. std::auto_ptr<Macro> macro(new Macro(type, name, parameters, replacements));
mMacros[*identifier] = new Macro(type, identifier, parameters, replacements); if (isMacroNameReserved(name))
{
// TODO(alokp): Report error.
return false;
}
if (isMacroDefined(name))
{
// TODO(alokp): Report error.
return false;
}
mMacros[*name] = macro.release();
return true; return true;
} }
bool Context::undefineMacro(const std::string* identifier) bool Context::undefineMacro(const std::string* name)
{ {
MacroSet::iterator iter = mMacros.find(*identifier); MacroSet::iterator iter = mMacros.find(*name);
if (iter == mMacros.end()) if (iter == mMacros.end())
{ {
// TODO(alokp): Report error. // TODO(alokp): Report error.
...@@ -79,9 +105,9 @@ bool Context::undefineMacro(const std::string* identifier) ...@@ -79,9 +105,9 @@ bool Context::undefineMacro(const std::string* identifier)
return true; return true;
} }
bool Context::isMacroDefined(const std::string* identifier) bool Context::isMacroDefined(const std::string* name)
{ {
return mMacros.find(*identifier) != mMacros.end(); return mMacros.find(*name) != mMacros.end();
} }
// Reset to initialized state. // Reset to initialized state.
...@@ -96,15 +122,15 @@ void Context::reset() ...@@ -96,15 +122,15 @@ void Context::reset()
mOutput = NULL; mOutput = NULL;
} }
void Context::defineBuiltInMacro(const std::string& identifier, int value) void Context::defineBuiltInMacro(const std::string& name, int value)
{ {
std::ostringstream stream; std::ostringstream stream;
stream << value; stream << value;
Token* token = new Token(0, INT_CONSTANT, new std::string(stream.str())); Token* token = new Token(0, INT_CONSTANT, new std::string(stream.str()));
TokenVector* replacements = new pp::TokenVector(1, token); TokenVector* replacements = new pp::TokenVector(1, token);
mMacros[identifier] = new Macro(Macro::kTypeObj, mMacros[name] = new Macro(Macro::kTypeObj,
new std::string(identifier), new std::string(name),
NULL, NULL,
replacements); replacements);
} }
......
...@@ -33,11 +33,11 @@ class Context ...@@ -33,11 +33,11 @@ class Context
bool defineMacro(pp::Token::Location location, bool defineMacro(pp::Token::Location location,
pp::Macro::Type type, pp::Macro::Type type,
std::string* identifier, std::string* name,
pp::Macro::ParameterVector* parameters, pp::TokenVector* parameters,
pp::TokenVector* replacements); pp::TokenVector* replacements);
bool undefineMacro(const std::string* identifier); bool undefineMacro(const std::string* name);
bool isMacroDefined(const std::string* identifier); bool isMacroDefined(const std::string* name);
private: private:
DISALLOW_COPY_AND_ASSIGN(Context); DISALLOW_COPY_AND_ASSIGN(Context);
...@@ -46,7 +46,7 @@ class Context ...@@ -46,7 +46,7 @@ class Context
void reset(); void reset();
bool initLexer(); bool initLexer();
void destroyLexer(); void destroyLexer();
void defineBuiltInMacro(const std::string& identifier, int value); void defineBuiltInMacro(const std::string& name, int value);
bool parse(); bool parse();
void* mLexer; // Lexer handle. void* mLexer; // Lexer handle.
......
...@@ -14,11 +14,11 @@ namespace pp ...@@ -14,11 +14,11 @@ namespace pp
{ {
Macro::Macro(Type type, Macro::Macro(Type type,
std::string* identifier, std::string* name,
ParameterVector* parameters, TokenVector* parameters,
TokenVector* replacements) TokenVector* replacements)
: mType(type), : mType(type),
mIdentifier(identifier), mName(name),
mParameters(parameters), mParameters(parameters),
mReplacements(replacements) mReplacements(replacements)
{ {
...@@ -26,7 +26,7 @@ Macro::Macro(Type type, ...@@ -26,7 +26,7 @@ Macro::Macro(Type type,
Macro::~Macro() Macro::~Macro()
{ {
delete mIdentifier; delete mName;
if (mParameters) if (mParameters)
{ {
......
...@@ -24,26 +24,25 @@ class Macro ...@@ -24,26 +24,25 @@ class Macro
kTypeObj, kTypeObj,
kTypeFunc kTypeFunc
}; };
typedef std::vector<std::string*> ParameterVector;
// Takes ownership of pointer parameters. // Takes ownership of pointer parameters.
Macro(Type type, Macro(Type type,
std::string* identifier, std::string* name,
ParameterVector* parameters, TokenVector* parameters,
TokenVector* replacements); TokenVector* replacements);
~Macro(); ~Macro();
Type type() const { return mType; } Type type() const { return mType; }
const std::string* identifier() const { return mIdentifier; } const std::string* identifier() const { return mName; }
const ParameterVector* parameters() const { return mParameters; } const TokenVector* parameters() const { return mParameters; }
const TokenVector* replacements() const { return mReplacements; } const TokenVector* replacements() const { return mReplacements; }
private: private:
DISALLOW_COPY_AND_ASSIGN(Macro); DISALLOW_COPY_AND_ASSIGN(Macro);
Type mType; Type mType;
std::string* mIdentifier; std::string* mName;
ParameterVector* mParameters; TokenVector* mParameters;
TokenVector* mReplacements; TokenVector* mReplacements;
}; };
......
...@@ -40,9 +40,6 @@ std::ostream& operator<<(std::ostream& out, const Token& token) ...@@ -40,9 +40,6 @@ std::ostream& operator<<(std::ostream& out, const Token& token)
{ {
switch (token.type()) switch (token.type())
{ {
case SPACE:
out << " ";
break;
case INT_CONSTANT: case INT_CONSTANT:
case FLOAT_CONSTANT: case FLOAT_CONSTANT:
case IDENTIFIER: case IDENTIFIER:
......
...@@ -36,6 +36,8 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -36,6 +36,8 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#define YY_INPUT(buf, result, maxSize) \ #define YY_INPUT(buf, result, maxSize) \
result = yyextra->readInput(buf, maxSize); result = yyextra->readInput(buf, maxSize);
static std::string* extractMacroName(const char* str, int len);
%} %}
%option noyywrap nounput never-interactive %option noyywrap nounput never-interactive
...@@ -61,9 +63,15 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -61,9 +63,15 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
{HASH} { return HASH; } {HASH} { return HASH; }
{HASH}define { return HASH_DEFINE_OBJ; } {HASH}define{HSPACE}+{IDENTIFIER}/[ \t\n] {
{HASH}define{HSPACE}+/{IDENTIFIER}"(" { return HASH_DEFINE_FUNC; } yylval->sval = extractMacroName(yytext, yyleng);
{HASH}undef { return HASH_UNDEF; } return HASH_DEFINE_OBJ;
}
{HASH}define{HSPACE}+{IDENTIFIER}/"(" {
yylval->sval = extractMacroName(yytext, yyleng);
return HASH_DEFINE_FUNC;
}
{HASH}undef{HSPACE}+ { return HASH_UNDEF; }
{HASH}if { return HASH_IF; } {HASH}if { return HASH_IF; }
{HASH}ifdef { return HASH_IFDEF; } {HASH}ifdef { return HASH_IFDEF; }
...@@ -96,7 +104,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -96,7 +104,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
{PUNCTUATOR} { return yytext[0]; } {PUNCTUATOR} { return yytext[0]; }
{HSPACE}+ { return SPACE; } [ \t\v\f]+ { /* Ignore whitespace */ }
\n { \n {
++yylineno; yycolumn = 0; ++yylineno; yycolumn = 0;
...@@ -107,6 +115,25 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -107,6 +115,25 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
%% %%
std::string* extractMacroName(const char* str, int len)
{
// The input string is of the form {HASH}define{HSPACE}+{IDENTIFIER}
// We just need to find the last HSPACE.
ASSERT(str && (len > 8)); // strlen("#define ") == 8;
std::string* name = NULL;
for (int i = len - 1; i >= 0; --i)
{
if ((str[i] == ' ') || (str[i] == '\t'))
{
name = new std::string(str + i + 1, len - i - 1);
break;
}
}
ASSERT(name);
return name;
}
namespace pp { namespace pp {
int Context::readInput(char* buf, int maxSize) int Context::readInput(char* buf, int maxSize)
......
...@@ -36,7 +36,6 @@ WHICH GENERATES THE GLSL ES PARSER. ...@@ -36,7 +36,6 @@ WHICH GENERATES THE GLSL ES PARSER.
%union { %union {
int ival; int ival;
std::string* sval; std::string* sval;
std::vector<std::string*>* slist;
pp::Token* tval; pp::Token* tval;
pp::TokenVector* tlist; pp::TokenVector* tlist;
} }
...@@ -51,15 +50,14 @@ static void pushConditionalBlock(pp::Context* context, bool condition); ...@@ -51,15 +50,14 @@ static void pushConditionalBlock(pp::Context* context, bool condition);
static void popConditionalBlock(pp::Context* context); static void popConditionalBlock(pp::Context* context);
%} %}
%token HASH HASH_DEFINE_OBJ HASH_DEFINE_FUNC HASH_UNDEF %token HASH HASH_UNDEF
%token HASH_IF HASH_IFDEF HASH_IFNDEF HASH_ELSE HASH_ELIF HASH_ENDIF DEFINED %token HASH_IF HASH_IFDEF HASH_IFNDEF HASH_ELSE HASH_ELIF HASH_ENDIF DEFINED
%token HASH_ERROR HASH_PRAGMA HASH_EXTENSION HASH_VERSION HASH_LINE %token HASH_ERROR HASH_PRAGMA HASH_EXTENSION HASH_VERSION HASH_LINE
%token SPACE %token <sval> HASH_DEFINE_OBJ HASH_DEFINE_FUNC
%token <sval> INT_CONSTANT FLOAT_CONSTANT IDENTIFIER %token <sval> INT_CONSTANT FLOAT_CONSTANT IDENTIFIER
%type <ival> operator %type <ival> operator
%type <slist> parameter_list
%type <tval> conditional_token token %type <tval> conditional_token token
%type <tlist> text_line replacement_token_list conditional_token_list token_list %type <tlist> parameter_list replacement_list conditional_list token_list
%% %%
input input
...@@ -68,32 +66,32 @@ input ...@@ -68,32 +66,32 @@ input
; ;
line line
: text_line { : text_line
| control_line
;
text_line
: '\n'
| token_list '\n' {
// 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;
} }
| control_line
;
text_line
: '\n' { $$ = NULL; }
| token_list '\n' { $$ = $1; }
; ;
control_line control_line
: HASH '\n' : HASH '\n'
| HASH_DEFINE_OBJ IDENTIFIER replacement_token_list '\n' { | HASH_DEFINE_OBJ replacement_list '\n' {
context->defineMacro(@2.first_line, pp::Macro::kTypeObj, $2, NULL, $3); context->defineMacro(@1.first_line, pp::Macro::kTypeObj, $1, NULL, $2);
} }
| HASH_DEFINE_FUNC IDENTIFIER '(' parameter_list ')' replacement_token_list '\n' { | HASH_DEFINE_FUNC '(' parameter_list ')' replacement_list '\n' {
context->defineMacro(@2.first_line, pp::Macro::kTypeFunc, $2, $4, $6); context->defineMacro(@1.first_line, pp::Macro::kTypeFunc, $1, $3, $5);
} }
| HASH_UNDEF IDENTIFIER '\n' { | HASH_UNDEF IDENTIFIER '\n' {
context->undefineMacro($2); context->undefineMacro($2);
} }
| HASH_IF conditional_token_list '\n' { | HASH_IF conditional_list '\n' {
pushConditionalBlock(context, $2 ? true : false); pushConditionalBlock(context, $2 ? true : false);
} }
| HASH_IFDEF IDENTIFIER '\n' { | HASH_IFDEF IDENTIFIER '\n' {
...@@ -102,7 +100,7 @@ control_line ...@@ -102,7 +100,7 @@ control_line
| HASH_IFNDEF IDENTIFIER '\n' { | HASH_IFNDEF IDENTIFIER '\n' {
pushConditionalBlock(context, !context->isMacroDefined($2)); pushConditionalBlock(context, !context->isMacroDefined($2));
} }
| HASH_ELIF conditional_token_list '\n' { | HASH_ELIF conditional_list '\n' {
} }
| HASH_ELSE '\n' { | HASH_ELSE '\n' {
} }
...@@ -116,39 +114,29 @@ control_line ...@@ -116,39 +114,29 @@ control_line
| HASH_LINE '\n' | HASH_LINE '\n'
; ;
replacement_token_list replacement_list
: /* empty */ { $$ = NULL } : /* empty */ { $$ = NULL; }
| token_list | token_list
;
conditional_token_list parameter_list
: conditional_token { : /* empty */ { $$ = NULL; }
| IDENTIFIER {
$$ = new pp::TokenVector; $$ = new pp::TokenVector;
$$->push_back($1); $$->push_back(new pp::Token(@1.first_line, IDENTIFIER, $1));
} }
| conditional_token_list conditional_token { | parameter_list ',' IDENTIFIER {
$$ = $1; $$ = $1;
$$->push_back($2); $$->push_back(new pp::Token(@3.first_line, IDENTIFIER, $3));
}
;
conditional_token
: DEFINED IDENTIFIER {
}
| DEFINED '(' IDENTIFIER ')' {
} }
| token
;
parameter_list conditional_list
: /* empty */ { $$ = NULL; } : conditional_token {
| IDENTIFIER { $$ = new pp::TokenVector;
$$ = new std::vector<std::string*>();
$$->push_back($1); $$->push_back($1);
} }
| parameter_list ',' IDENTIFIER { | conditional_list conditional_token {
$$ = $1; $$ = $1;
$$->push_back($3); $$->push_back($2);
} }
; ;
...@@ -163,13 +151,18 @@ token_list ...@@ -163,13 +151,18 @@ token_list
} }
; ;
conditional_token
: DEFINED IDENTIFIER {
}
| DEFINED '(' IDENTIFIER ')' {
}
| token
;
token token
: operator { : operator {
$$ = new pp::Token(@1.first_line, $1, NULL); $$ = new pp::Token(@1.first_line, $1, NULL);
} }
| SPACE {
$$ = new pp::Token(@1.first_line, SPACE, NULL);
}
| INT_CONSTANT { | INT_CONSTANT {
$$ = new pp::Token(@1.first_line, INT_CONSTANT, $1); $$ = new pp::Token(@1.first_line, INT_CONSTANT, $1);
} }
......
...@@ -380,48 +380,38 @@ struct yy_trans_info ...@@ -380,48 +380,38 @@ struct yy_trans_info
flex_int32_t yy_verify; flex_int32_t yy_verify;
flex_int32_t yy_nxt; flex_int32_t yy_nxt;
}; };
static yyconst flex_int16_t yy_acclist[57] = static yyconst flex_int16_t yy_accept[105] =
{ 0, { 0,
24, 23, 21, 23, 22, 23, 20, 23, 20, 23, 0, 0, 24, 23, 21, 22, 20, 20, 18, 18,
18, 23, 18, 23, 17, 23, 17, 23, 21, 23, 17, 17, 21, 1, 21, 19, 19, 18, 0, 0,
1, 23, 21, 19, 19, 18, 18, 17, 17, 21, 0, 18, 17, 17, 21, 1, 1, 0, 0, 0,
1, 1, 19, 18, 17, 5, 19, 17, 17, 9, 0, 0, 0, 0, 0, 0, 19, 18, 17, 0,
8, 16, 17, 10, 12, 6, 4, 11, 17, 2, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0,
7, 13,16387, 15, 8195, 14 19, 17, 0, 0, 0, 0, 0, 0, 0, 0,
} ; 0, 0, 0, 0, 17, 0, 9, 8, 0, 0,
0, 0, 0, 16, 0, 0, 0, 17, 0, 10,
static yyconst flex_int16_t yy_accept[104] = 12, 0, 6, 0, 0, 0, 0, 11, 0, 0,
{ 0, 7, 13, 4, 0, 0, 0, 15, 0, 0, 2,
1, 1, 1, 2, 3, 5, 7, 9, 11, 13,
15, 17, 19, 21, 23, 24, 25, 26, 27, 27, 3, 0, 14, 0
27, 27, 28, 29, 30, 31, 32, 33, 33, 33,
33, 33, 33, 33, 33, 33, 33, 34, 35, 36,
36, 36, 36, 36, 36, 37, 37, 37, 37, 37,
37, 38, 39, 39, 39, 39, 39, 39, 39, 39,
39, 39, 39, 39, 39, 40, 40, 41, 42, 42,
42, 42, 42, 42, 43, 43, 43, 43, 44, 44,
45, 46, 46, 47, 47, 47, 48, 48, 50, 51,
51, 52, 53, 53, 54, 54, 55, 55, 55, 56,
56, 57, 57
} ; } ;
static yyconst flex_int32_t yy_ec[256] = static yyconst flex_int32_t yy_ec[256] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
4, 4, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 5, 1, 6, 1, 5, 5, 1, 7,
1, 2, 4, 1, 5, 1, 4, 4, 1, 6, 5, 5, 8, 5, 8, 9, 5, 10, 11, 11,
4, 4, 7, 4, 7, 8, 4, 9, 10, 10, 11, 11, 11, 11, 11, 12, 12, 5, 5, 5,
10, 10, 10, 10, 10, 11, 11, 4, 4, 4, 5, 5, 5, 1, 13, 13, 13, 13, 14, 13,
4, 4, 4, 1, 12, 12, 12, 12, 13, 12, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 16, 15, 15,
14, 14, 14, 14, 14, 14, 14, 15, 14, 14, 5, 1, 5, 5, 15, 1, 17, 13, 13, 18,
4, 1, 4, 4, 14, 1, 16, 12, 12, 17,
19, 20, 21, 15, 22, 15, 15, 23, 24, 25,
18, 19, 20, 14, 21, 14, 14, 22, 23, 24, 26, 27, 15, 28, 29, 30, 31, 32, 15, 33,
25, 26, 14, 27, 28, 29, 30, 31, 14, 32, 15, 15, 5, 5, 5, 5, 1, 1, 1, 1,
14, 14, 4, 4, 4, 4, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
...@@ -438,119 +428,112 @@ static yyconst flex_int32_t yy_ec[256] = ...@@ -438,119 +428,112 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1 1, 1, 1, 1, 1
} ; } ;
static yyconst flex_int32_t yy_meta[33] = static yyconst flex_int32_t yy_meta[34] =
{ 0, { 0,
1, 2, 1, 1, 1, 3, 1, 1, 4, 4, 1, 2, 3, 1, 1, 1, 3, 1, 1, 4,
4, 5, 6, 7, 7, 5, 5, 6, 5, 7, 4, 4, 5, 6, 7, 7, 5, 5, 6, 5,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7 7, 7, 7
} ; } ;
static yyconst flex_int16_t yy_base[109] = static yyconst flex_int16_t yy_base[111] =
{ 0, { 0,
0, 17, 171, 172, 168, 172, 172, 3, 27, 52, 0, 18, 184, 185, 11, 185, 185, 21, 28, 53,
0, 151, 27, 69, 166, 26, 28, 1, 21, 40, 0, 164, 39, 71, 12, 32, 34, 1, 39, 44,
0, 0, 0, 148, 50, 0, 0, 148, 42, 146, 0, 0, 0, 162, 64, 0, 0, 162, 46, 160,
143, 136, 138, 143, 47, 66, 69, 0, 139, 140, 157, 150, 152, 157, 70, 47, 65, 0, 153, 154,
60, 141, 130, 127, 65, 131, 138, 136, 125, 74, 62, 155, 144, 141, 67, 145, 152, 150, 139, 76,
83, 127, 129, 130, 130, 126, 121, 127, 126, 126, 85, 141, 143, 144, 144, 140, 135, 141, 140, 140,
124, 121, 122, 111, 120, 113, 172, 172, 117, 108, 138, 135, 136, 125, 134, 127, 185, 185, 131, 122,
110, 114, 114, 172, 108, 111, 108, 103, 101, 172, 124, 128, 128, 185, 122, 125, 122, 125, 123, 185,
172, 85, 172, 79, 81, 172, 71, 0, 71, 51, 185, 112, 185, 120, 113, 127, 97, 0, 107, 86,
172, 172, 44, 65, 28, 172, 42, 19, 172, 9, 185, 185, 105, 76, 81, 34, 185, 97, 10, 185,
172, 172, 100, 104, 108, 111, 116, 121 185, 103, 185, 185, 110, 114, 118, 121, 126, 132
} ; } ;
static yyconst flex_int16_t yy_def[109] = static yyconst flex_int16_t yy_def[111] =
{ 0, { 0,
103, 103, 102, 102, 102, 102, 102, 102, 102, 102, 105, 105, 104, 104, 104, 104, 104, 104, 104, 104,
104, 104, 102, 102, 102, 105, 105, 9, 18, 102, 106, 106, 104, 104, 104, 107, 107, 9, 18, 104,
106, 10, 104, 104, 102, 14, 14, 102, 102, 102, 108, 10, 106, 106, 104, 14, 14, 104, 104, 104,
102, 102, 102, 102, 102, 102, 102, 106, 104, 102, 104, 104, 104, 104, 104, 104, 104, 108, 106, 104,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
102, 104, 102, 102, 102, 102, 102, 102, 102, 102, 104, 106, 104, 104, 104, 104, 104, 104, 104, 104,
102, 102, 102, 102, 104, 102, 102, 102, 102, 102, 104, 104, 104, 104, 106, 104, 104, 104, 104, 104,
102, 102, 102, 102, 102, 102, 102, 104, 102, 102, 104, 104, 104, 104, 104, 104, 104, 106, 104, 104,
102, 102, 102, 102, 102, 102, 102, 104, 102, 102, 104, 104, 104, 104, 104, 104, 104, 106, 104, 104,
102, 102, 102, 107, 102, 102, 108, 102, 102, 108, 104, 104, 104, 104, 109, 104, 104, 110, 104, 104,
102, 0, 102, 102, 102, 102, 102, 102 104, 110, 104, 0, 104, 104, 104, 104, 104, 104
} ; } ;
static yyconst flex_int16_t yy_nxt[205] = static yyconst flex_int16_t yy_nxt[219] =
{ 0, { 0,
4, 5, 6, 7, 4, 7, 7, 8, 9, 10, 4, 5, 6, 5, 7, 4, 7, 7, 8, 9,
10, 16, 16, 16, 99, 102, 12, 4, 13, 6, 10, 10, 15, 15, 15, 15, 104, 12, 4, 13,
7, 14, 7, 7, 8, 9, 10, 10, 25, 19, 6, 5, 7, 14, 7, 7, 8, 9, 10, 10,
19, 26, 102, 12, 17, 18, 18, 19, 35, 20, 16, 16, 16, 104, 103, 12, 17, 18, 18, 19,
35, 21, 101, 35, 20, 35, 36, 99, 37, 37, 25, 20, 15, 21, 26, 35, 20, 35, 19, 19,
37, 25, 98, 50, 26, 51, 51, 51, 21, 17, 35, 36, 35, 37, 37, 37, 37, 37, 37, 99,
22, 22, 22, 41, 20, 42, 94, 96, 43, 20, 21, 17, 22, 22, 22, 25, 20, 15, 41, 26,
27, 95, 94, 44, 37, 37, 37, 37, 37, 37, 42, 20, 27, 43, 37, 37, 37, 50, 44, 51,
54, 59, 51, 51, 51, 28, 29, 55, 60, 30, 51, 51, 95, 54, 59, 51, 51, 51, 28, 29,
31, 51, 51, 51, 32, 93, 92, 91, 33, 34, 55, 60, 30, 31, 51, 51, 51, 32, 100, 100,
97, 33, 34, 101, 100, 100, 93, 96, 95, 101,
11, 11, 11, 11, 11, 11, 11, 23, 23, 23, 11, 11, 11, 11, 11, 11, 11, 23, 23, 23,
23, 16, 90, 16, 38, 38, 38, 97, 89, 88, 23, 16, 94, 16, 38, 38, 38, 98, 93, 92,
97, 97, 97, 100, 100, 100, 100, 100, 87, 86, 98, 98, 98, 102, 102, 102, 102, 102, 102, 91,
85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81,
75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71,
65, 64, 63, 62, 61, 58, 57, 56, 53, 52, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61,
49, 48, 47, 46, 45, 40, 39, 15, 24, 15, 58, 57, 56, 53, 52, 49, 48, 47, 46, 45,
102, 3, 102, 102, 102, 102, 102, 102, 102, 102, 40, 39, 24, 104, 3, 104, 104, 104, 104, 104,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
102, 102, 102, 102 104, 104, 104, 104, 104, 104, 104, 104
} ; } ;
static yyconst flex_int16_t yy_chk[205] = static yyconst flex_int16_t yy_chk[219] =
{ 0, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 8, 8, 8, 100, 18, 1, 2, 2, 2, 1, 1, 5, 15, 5, 15, 18, 1, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 13, 19, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
19, 13, 18, 2, 9, 9, 9, 9, 16, 9, 8, 8, 8, 18, 99, 2, 9, 9, 9, 9,
17, 9, 98, 16, 9, 17, 20, 97, 20, 20, 13, 9, 13, 9, 13, 16, 9, 17, 19, 19,
20, 25, 95, 35, 25, 35, 35, 35, 9, 10, 16, 20, 17, 20, 20, 20, 36, 36, 36, 96,
10, 10, 10, 29, 10, 29, 94, 93, 29, 10, 9, 10, 10, 10, 10, 25, 10, 25, 29, 25,
14, 90, 89, 29, 36, 36, 36, 37, 37, 37, 29, 10, 14, 29, 37, 37, 37, 35, 29, 35,
41, 45, 50, 50, 50, 14, 14, 41, 45, 14, 35, 35, 95, 41, 45, 50, 50, 50, 14, 14,
14, 51, 51, 51, 14, 87, 85, 84, 14, 14, 41, 45, 14, 14, 51, 51, 51, 14, 98, 98,
103, 103, 103, 103, 103, 103, 103, 104, 104, 104, 94, 14, 14, 98, 102, 102, 93, 90, 89, 102,
104, 105, 82, 105, 106, 106, 106, 107, 79, 78, 105, 105, 105, 105, 105, 105, 105, 106, 106, 106,
107, 107, 107, 108, 108, 108, 108, 108, 77, 76, 106, 107, 87, 107, 108, 108, 108, 109, 86, 85,
75, 73, 72, 71, 70, 69, 66, 65, 64, 63, 109, 109, 109, 110, 110, 110, 110, 110, 110, 84,
62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 82, 79, 78, 77, 76, 75, 73, 72, 71, 70,
52, 49, 48, 47, 46, 44, 43, 42, 40, 39, 69, 66, 65, 64, 63, 62, 61, 60, 59, 58,
34, 33, 32, 31, 30, 28, 24, 15, 12, 5, 57, 56, 55, 54, 53, 52, 49, 48, 47, 46,
3, 102, 102, 102, 102, 102, 102, 102, 102, 102, 44, 43, 42, 40, 39, 34, 33, 32, 31, 30,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 28, 24, 12, 3, 104, 104, 104, 104, 104, 104,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
102, 102, 102, 102 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
104, 104, 104, 104, 104, 104, 104, 104
} ; } ;
/* Table of booleans, true if rule could match eol. */ /* Table of booleans, true if rule could match eol. */
static yyconst flex_int32_t yy_rule_can_match_eol[24] = static yyconst flex_int32_t yy_rule_can_match_eol[24] =
{ 0, { 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, }; 0, 0, 1, 0, };
#define YY_TRAILING_MASK 0x2000 /* The intent behind this definition is that it'll catch
#define YY_TRAILING_HEAD_MASK 0x4000 * any uses of REJECT which flex missed.
#define REJECT \ */
{ \ #define REJECT reject_used_but_not_detected
*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ \
yy_cp = yyg->yy_full_match; /* restore poss. backed-over text */ \
yyg->yy_lp = yyg->yy_full_lp; /* restore orig. accepting pos. */ \
yyg->yy_state_ptr = yyg->yy_full_state; /* restore orig. state */ \
yy_current_state = *yyg->yy_state_ptr; /* restore curr. state */ \
++yyg->yy_lp; \
goto find_rule; \
}
#define yymore() yymore_used_but_not_detected #define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0 #define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET #define YY_RESTORE_YY_MORE_OFFSET
...@@ -582,6 +565,8 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh. ...@@ -582,6 +565,8 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#define YY_INPUT(buf, result, maxSize) \ #define YY_INPUT(buf, result, maxSize) \
result = yyextra->readInput(buf, maxSize); result = yyextra->readInput(buf, maxSize);
static std::string* extractMacroName(const char* str, int len);
#define INITIAL 0 #define INITIAL 0
#define YY_EXTRA_TYPE pp::Context* #define YY_EXTRA_TYPE pp::Context*
...@@ -614,17 +599,6 @@ struct yyguts_t ...@@ -614,17 +599,6 @@ struct yyguts_t
int yylineno_r; int yylineno_r;
int yy_flex_debug_r; int yy_flex_debug_r;
yy_state_type *yy_state_buf;
yy_state_type *yy_state_ptr;
char *yy_full_match;
int yy_lp;
/* These are only needed for trailing context rules,
* but there's no conditional variable for that yet. */
int yy_looking_for_trail_begin;
int yy_full_lp;
int *yy_full_state;
char *yytext_r; char *yytext_r;
int yy_more_flag; int yy_more_flag;
int yy_more_len; int yy_more_len;
...@@ -841,12 +815,6 @@ YY_DECL ...@@ -841,12 +815,6 @@ YY_DECL
YY_USER_INIT; YY_USER_INIT;
#endif #endif
/* Create the reject buffer large enough to save one state per allowed character. */
if ( ! yyg->yy_state_buf )
yyg->yy_state_buf = (yy_state_type *)ppalloc(YY_STATE_BUF_SIZE ,yyscanner);
if ( ! yyg->yy_state_buf )
YY_FATAL_ERROR( "out of dynamic memory in pplex()" );
if ( ! yyg->yy_start ) if ( ! yyg->yy_start )
yyg->yy_start = 1; /* first start state */ yyg->yy_start = 1; /* first start state */
...@@ -879,64 +847,30 @@ YY_DECL ...@@ -879,64 +847,30 @@ YY_DECL
yy_current_state = yyg->yy_start; yy_current_state = yyg->yy_start;
yy_current_state += YY_AT_BOL(); yy_current_state += YY_AT_BOL();
yyg->yy_state_ptr = yyg->yy_state_buf;
*yyg->yy_state_ptr++ = yy_current_state;
yy_match: yy_match:
do do
{ {
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
if ( yy_accept[yy_current_state] )
{
yyg->yy_last_accepting_state = yy_current_state;
yyg->yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 103 ) if ( yy_current_state >= 105 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
*yyg->yy_state_ptr++ = yy_current_state;
++yy_cp; ++yy_cp;
} }
while ( yy_current_state != 102 ); while ( yy_current_state != 104 );
yy_cp = yyg->yy_last_accepting_cpos;
yy_current_state = yyg->yy_last_accepting_state;
yy_find_action: yy_find_action:
yy_current_state = *--yyg->yy_state_ptr; yy_act = yy_accept[yy_current_state];
yyg->yy_lp = yy_accept[yy_current_state];
find_rule: /* we branch to this label when backing up */
for ( ; ; ) /* until we find what rule we matched */
{
if ( yyg->yy_lp && yyg->yy_lp < yy_accept[yy_current_state + 1] )
{
yy_act = yy_acclist[yyg->yy_lp];
if ( yy_act & YY_TRAILING_HEAD_MASK ||
yyg->yy_looking_for_trail_begin )
{
if ( yy_act == yyg->yy_looking_for_trail_begin )
{
yyg->yy_looking_for_trail_begin = 0;
yy_act &= ~YY_TRAILING_HEAD_MASK;
break;
}
}
else if ( yy_act & YY_TRAILING_MASK )
{
yyg->yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;
yyg->yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;
}
else
{
yyg->yy_full_match = yy_cp;
yyg->yy_full_state = yyg->yy_state_ptr;
yyg->yy_full_lp = yyg->yy_lp;
break;
}
++yyg->yy_lp;
goto find_rule;
}
--yy_cp;
yy_current_state = *--yyg->yy_state_ptr;
yyg->yy_lp = yy_accept[yy_current_state];
}
YY_DO_BEFORE_ACTION; YY_DO_BEFORE_ACTION;
...@@ -956,17 +890,37 @@ do_action: /* This label is used only to access EOF actions. */ ...@@ -956,17 +890,37 @@ do_action: /* This label is used only to access EOF actions. */
switch ( yy_act ) switch ( yy_act )
{ /* beginning of action switch */ { /* beginning of action switch */
case 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = yyg->yy_hold_char;
yy_cp = yyg->yy_last_accepting_cpos;
yy_current_state = yyg->yy_last_accepting_state;
goto yy_find_action;
case 1: case 1:
YY_RULE_SETUP YY_RULE_SETUP
{ return HASH; } { return HASH; }
YY_BREAK YY_BREAK
case 2: case 2:
/* rule 2 can match eol */
*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */
yyg->yy_c_buf_p = yy_cp -= 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP YY_RULE_SETUP
{ return HASH_DEFINE_OBJ; } {
yylval->sval = extractMacroName(yytext, yyleng);
return HASH_DEFINE_OBJ;
}
YY_BREAK YY_BREAK
case 3: case 3:
*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */
yyg->yy_c_buf_p = yy_cp -= 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP YY_RULE_SETUP
{ return HASH_DEFINE_FUNC; } {
yylval->sval = extractMacroName(yytext, yyleng);
return HASH_DEFINE_FUNC;
}
YY_BREAK YY_BREAK
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
...@@ -1047,7 +1001,7 @@ YY_RULE_SETUP ...@@ -1047,7 +1001,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
{ return SPACE; } { /* Ignore whitespace */ }
YY_BREAK YY_BREAK
case 22: case 22:
/* rule 22 can match eol */ /* rule 22 can match eol */
...@@ -1128,7 +1082,8 @@ ECHO; ...@@ -1128,7 +1082,8 @@ ECHO;
else else
{ {
yy_cp = yyg->yy_c_buf_p; yy_cp = yyg->yy_last_accepting_cpos;
yy_current_state = yyg->yy_last_accepting_state;
goto yy_find_action; goto yy_find_action;
} }
} }
...@@ -1254,8 +1209,37 @@ static int yy_get_next_buffer (yyscan_t yyscanner) ...@@ -1254,8 +1209,37 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( num_to_read <= 0 ) while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */ { /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
int yy_c_buf_p_offset =
(int) (yyg->yy_c_buf_p - b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
int new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
else
b->yy_buf_size *= 2;
b->yy_ch_buf = (char *)
/* Include room in for 2 EOB chars. */
pprealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
}
else
/* Can't grow it, we don't own it. */
b->yy_ch_buf = 0;
if ( ! b->yy_ch_buf )
YY_FATAL_ERROR( YY_FATAL_ERROR(
"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); "fatal error - scanner input buffer overflow" );
yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
number_to_move - 1;
} }
...@@ -1316,20 +1300,21 @@ static int yy_get_next_buffer (yyscan_t yyscanner) ...@@ -1316,20 +1300,21 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
yy_current_state = yyg->yy_start; yy_current_state = yyg->yy_start;
yy_current_state += YY_AT_BOL(); yy_current_state += YY_AT_BOL();
yyg->yy_state_ptr = yyg->yy_state_buf;
*yyg->yy_state_ptr++ = yy_current_state;
for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
{ {
register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] )
{
yyg->yy_last_accepting_state = yy_current_state;
yyg->yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 103 ) if ( yy_current_state >= 105 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
*yyg->yy_state_ptr++ = yy_current_state;
} }
return yy_current_state; return yy_current_state;
...@@ -1344,18 +1329,22 @@ static int yy_get_next_buffer (yyscan_t yyscanner) ...@@ -1344,18 +1329,22 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
{ {
register int yy_is_jam; register int yy_is_jam;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
register char *yy_cp = yyg->yy_c_buf_p;
register YY_CHAR yy_c = 1; register YY_CHAR yy_c = 1;
if ( yy_accept[yy_current_state] )
{
yyg->yy_last_accepting_state = yy_current_state;
yyg->yy_last_accepting_cpos = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[yy_current_state]; yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 103 ) if ( yy_current_state >= 105 )
yy_c = yy_meta[(unsigned int) yy_c]; yy_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 102); yy_is_jam = (yy_current_state == 104);
if ( ! yy_is_jam )
*yyg->yy_state_ptr++ = yy_current_state;
return yy_is_jam ? 0 : yy_current_state; return yy_is_jam ? 0 : yy_current_state;
} }
...@@ -2120,11 +2109,6 @@ static int yy_init_globals (yyscan_t yyscanner) ...@@ -2120,11 +2109,6 @@ static int yy_init_globals (yyscan_t yyscanner)
yyg->yy_start_stack_depth = 0; yyg->yy_start_stack_depth = 0;
yyg->yy_start_stack = NULL; yyg->yy_start_stack = NULL;
yyg->yy_state_buf = 0;
yyg->yy_state_ptr = 0;
yyg->yy_full_match = 0;
yyg->yy_lp = 0;
/* Defined in main.c */ /* Defined in main.c */
#ifdef YY_STDINIT #ifdef YY_STDINIT
yyin = stdin; yyin = stdin;
...@@ -2160,9 +2144,6 @@ int pplex_destroy (yyscan_t yyscanner) ...@@ -2160,9 +2144,6 @@ int pplex_destroy (yyscan_t yyscanner)
ppfree(yyg->yy_start_stack ,yyscanner ); ppfree(yyg->yy_start_stack ,yyscanner );
yyg->yy_start_stack = NULL; yyg->yy_start_stack = NULL;
ppfree ( yyg->yy_state_buf , yyscanner);
yyg->yy_state_buf = NULL;
/* Reset the globals. This is important in a non-reentrant scanner so the next time /* Reset the globals. This is important in a non-reentrant scanner so the next time
* pplex() is called, initialization will occur. */ * pplex() is called, initialization will occur. */
yy_init_globals( yyscanner); yy_init_globals( yyscanner);
...@@ -2221,6 +2202,25 @@ void ppfree (void * ptr , yyscan_t yyscanner) ...@@ -2221,6 +2202,25 @@ void ppfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
std::string* extractMacroName(const char* str, int len)
{
// The input string is of the form {HASH}define{HSPACE}+{IDENTIFIER}
// We just need to find the last HSPACE.
ASSERT(str && (len > 8)); // strlen("#define ") == 8;
std::string* name = NULL;
for (int i = len - 1; i >= 0; --i)
{
if ((str[i] == ' ') || (str[i] == '\t'))
{
name = new std::string(str + i + 1, len - i - 1);
break;
}
}
ASSERT(name);
return name;
}
namespace pp { namespace pp {
int Context::readInput(char* buf, int maxSize) int Context::readInput(char* buf, int maxSize)
......
...@@ -75,48 +75,46 @@ ...@@ -75,48 +75,46 @@
know about them. */ know about them. */
enum yytokentype { enum yytokentype {
HASH = 258, HASH = 258,
HASH_DEFINE_OBJ = 259, HASH_UNDEF = 259,
HASH_DEFINE_FUNC = 260, HASH_IF = 260,
HASH_UNDEF = 261, HASH_IFDEF = 261,
HASH_IF = 262, HASH_IFNDEF = 262,
HASH_IFDEF = 263, HASH_ELSE = 263,
HASH_IFNDEF = 264, HASH_ELIF = 264,
HASH_ELSE = 265, HASH_ENDIF = 265,
HASH_ELIF = 266, DEFINED = 266,
HASH_ENDIF = 267, HASH_ERROR = 267,
DEFINED = 268, HASH_PRAGMA = 268,
HASH_ERROR = 269, HASH_EXTENSION = 269,
HASH_PRAGMA = 270, HASH_VERSION = 270,
HASH_EXTENSION = 271, HASH_LINE = 271,
HASH_VERSION = 272, HASH_DEFINE_OBJ = 272,
HASH_LINE = 273, HASH_DEFINE_FUNC = 273,
SPACE = 274, INT_CONSTANT = 274,
INT_CONSTANT = 275, FLOAT_CONSTANT = 275,
FLOAT_CONSTANT = 276, IDENTIFIER = 276
IDENTIFIER = 277
}; };
#endif #endif
/* Tokens. */ /* Tokens. */
#define HASH 258 #define HASH 258
#define HASH_DEFINE_OBJ 259 #define HASH_UNDEF 259
#define HASH_DEFINE_FUNC 260 #define HASH_IF 260
#define HASH_UNDEF 261 #define HASH_IFDEF 261
#define HASH_IF 262 #define HASH_IFNDEF 262
#define HASH_IFDEF 263 #define HASH_ELSE 263
#define HASH_IFNDEF 264 #define HASH_ELIF 264
#define HASH_ELSE 265 #define HASH_ENDIF 265
#define HASH_ELIF 266 #define DEFINED 266
#define HASH_ENDIF 267 #define HASH_ERROR 267
#define DEFINED 268 #define HASH_PRAGMA 268
#define HASH_ERROR 269 #define HASH_EXTENSION 269
#define HASH_PRAGMA 270 #define HASH_VERSION 270
#define HASH_EXTENSION 271 #define HASH_LINE 271
#define HASH_VERSION 272 #define HASH_DEFINE_OBJ 272
#define HASH_LINE 273 #define HASH_DEFINE_FUNC 273
#define SPACE 274 #define INT_CONSTANT 274
#define INT_CONSTANT 275 #define FLOAT_CONSTANT 275
#define FLOAT_CONSTANT 276 #define IDENTIFIER 276
#define IDENTIFIER 277
...@@ -162,7 +160,6 @@ typedef union YYSTYPE ...@@ -162,7 +160,6 @@ typedef union YYSTYPE
{ {
int ival; int ival;
std::string* sval; std::string* sval;
std::vector<std::string*>* slist;
pp::Token* tval; pp::Token* tval;
pp::TokenVector* tlist; pp::TokenVector* tlist;
} }
...@@ -418,20 +415,20 @@ union yyalloc ...@@ -418,20 +415,20 @@ union yyalloc
/* YYFINAL -- State number of the termination state. */ /* YYFINAL -- State number of the termination state. */
#define YYFINAL 2 #define YYFINAL 2
/* YYLAST -- Last index in YYTABLE. */ /* YYLAST -- Last index in YYTABLE. */
#define YYLAST 244 #define YYLAST 247
/* YYNTOKENS -- Number of terminals. */ /* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 48 #define YYNTOKENS 47
/* YYNNTS -- Number of nonterminals. */ /* YYNNTS -- Number of nonterminals. */
#define YYNNTS 12 #define YYNNTS 12
/* YYNRULES -- Number of rules. */ /* YYNRULES -- Number of rules. */
#define YYNRULES 63 #define YYNRULES 62
/* YYNRULES -- Number of states. */ /* YYNRULES -- Number of states. */
#define YYNSTATES 94 #define YYNSTATES 91
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2 #define YYUNDEFTOK 2
#define YYMAXUTOK 277 #define YYMAXUTOK 276
#define YYTRANSLATE(YYX) \ #define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
...@@ -440,18 +437,18 @@ union yyalloc ...@@ -440,18 +437,18 @@ union yyalloc
static const yytype_uint8 yytranslate[] = static const yytype_uint8 yytranslate[] =
{ {
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
23, 2, 2, 2, 2, 2, 2, 2, 2, 2, 22, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 44, 2, 2, 2, 38, 41, 2, 2, 2, 2, 43, 2, 2, 2, 37, 40, 2,
24, 25, 37, 34, 26, 35, 33, 36, 2, 2, 23, 24, 36, 33, 25, 34, 32, 35, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 45, 46, 2, 2, 2, 2, 2, 2, 2, 2, 44, 45,
29, 43, 30, 47, 2, 2, 2, 2, 2, 2, 28, 42, 29, 46, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 27, 2, 28, 39, 2, 2, 2, 2, 2, 2, 26, 2, 27, 38, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 31, 40, 32, 42, 2, 2, 2, 2, 2, 2, 30, 39, 31, 41, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
...@@ -466,7 +463,7 @@ static const yytype_uint8 yytranslate[] = ...@@ -466,7 +463,7 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22 15, 16, 17, 18, 19, 20, 21
}; };
#if YYDEBUG #if YYDEBUG
...@@ -475,46 +472,45 @@ static const yytype_uint8 yytranslate[] = ...@@ -475,46 +472,45 @@ static const yytype_uint8 yytranslate[] =
static const yytype_uint8 yyprhs[] = static const yytype_uint8 yyprhs[] =
{ {
0, 0, 3, 4, 7, 9, 11, 13, 16, 19, 0, 0, 3, 4, 7, 9, 11, 13, 16, 19,
24, 32, 36, 40, 44, 48, 52, 55, 58, 61, 23, 30, 34, 38, 42, 46, 50, 53, 56, 59,
64, 67, 70, 73, 74, 76, 78, 81, 84, 89, 62, 65, 68, 71, 72, 74, 75, 77, 81, 83,
91, 92, 94, 98, 100, 103, 105, 107, 109, 111, 86, 88, 91, 94, 99, 101, 103, 105, 107, 109,
113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129,
133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149,
153, 155, 157, 159 151, 153, 155
}; };
/* YYRHS -- A `-1'-separated list of the rules' RHS. */ /* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] = static const yytype_int8 yyrhs[] =
{ {
49, 0, -1, -1, 49, 50, -1, 51, -1, 52, 48, 0, -1, -1, 48, 49, -1, 50, -1, 51,
-1, 23, -1, 57, 23, -1, 3, 23, -1, 4, -1, 22, -1, 55, 22, -1, 3, 22, -1, 17,
22, 53, 23, -1, 5, 22, 24, 56, 25, 53, 52, 22, -1, 18, 23, 53, 24, 52, 22, -1,
23, -1, 6, 22, 23, -1, 7, 54, 23, -1, 4, 21, 22, -1, 5, 54, 22, -1, 6, 21,
8, 22, 23, -1, 9, 22, 23, -1, 11, 54, 22, -1, 7, 21, 22, -1, 9, 54, 22, -1,
23, -1, 10, 23, -1, 12, 23, -1, 14, 23, 8, 22, -1, 10, 22, -1, 12, 22, -1, 13,
-1, 15, 23, -1, 16, 23, -1, 17, 23, -1, 22, -1, 14, 22, -1, 15, 22, -1, 16, 22,
18, 23, -1, -1, 57, -1, 55, -1, 54, 55, -1, -1, 55, -1, -1, 21, -1, 53, 25, 21,
-1, 13, 22, -1, 13, 24, 22, 25, -1, 58, -1, 56, -1, 54, 56, -1, 57, -1, 55, 57,
-1, -1, 22, -1, 56, 26, 22, -1, 58, -1, -1, 11, 21, -1, 11, 23, 21, 24, -1, 57,
57, 58, -1, 59, -1, 19, -1, 20, -1, 21, -1, 58, -1, 19, -1, 20, -1, 21, -1, 26,
-1, 22, -1, 27, -1, 28, -1, 29, -1, 30, -1, 27, -1, 28, -1, 29, -1, 23, -1, 24,
-1, 24, -1, 25, -1, 31, -1, 32, -1, 33, -1, 30, -1, 31, -1, 32, -1, 33, -1, 34,
-1, 34, -1, 35, -1, 36, -1, 37, -1, 38, -1, 35, -1, 36, -1, 37, -1, 38, -1, 39,
-1, 39, -1, 40, -1, 41, -1, 42, -1, 43, -1, 40, -1, 41, -1, 42, -1, 43, -1, 44,
-1, 44, -1, 45, -1, 46, -1, 26, -1, 47, -1, 45, -1, 25, -1, 46, -1
-1
}; };
/* 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, 65, 65, 67, 71, 77, 81, 82, 86, 87, 0, 63, 63, 65, 69, 70, 74, 75, 84, 85,
90, 93, 96, 99, 102, 105, 107, 109, 112, 113, 88, 91, 94, 97, 100, 103, 105, 107, 110, 111,
114, 115, 116, 120, 121, 125, 129, 136, 138, 140, 112, 113, 114, 118, 119, 122, 123, 127, 133, 137,
144, 145, 149, 156, 160, 167, 170, 173, 176, 179, 144, 148, 155, 157, 159, 163, 166, 169, 172, 178,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
205, 206, 207, 208 199, 200, 201
}; };
#endif #endif
...@@ -523,16 +519,16 @@ static const yytype_uint8 yyrline[] = ...@@ -523,16 +519,16 @@ static const yytype_uint8 yyrline[] =
First, the terminals, then, starting at YYNTOKENS, nonterminals. */ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] = static const char *const yytname[] =
{ {
"$end", "error", "$undefined", "HASH", "HASH_DEFINE_OBJ", "$end", "error", "$undefined", "HASH", "HASH_UNDEF", "HASH_IF",
"HASH_DEFINE_FUNC", "HASH_UNDEF", "HASH_IF", "HASH_IFDEF", "HASH_IFNDEF", "HASH_IFDEF", "HASH_IFNDEF", "HASH_ELSE", "HASH_ELIF", "HASH_ENDIF",
"HASH_ELSE", "HASH_ELIF", "HASH_ENDIF", "DEFINED", "HASH_ERROR", "DEFINED", "HASH_ERROR", "HASH_PRAGMA", "HASH_EXTENSION", "HASH_VERSION",
"HASH_PRAGMA", "HASH_EXTENSION", "HASH_VERSION", "HASH_LINE", "SPACE", "HASH_LINE", "HASH_DEFINE_OBJ", "HASH_DEFINE_FUNC", "INT_CONSTANT",
"INT_CONSTANT", "FLOAT_CONSTANT", "IDENTIFIER", "'\\n'", "'('", "')'", "FLOAT_CONSTANT", "IDENTIFIER", "'\\n'", "'('", "')'", "','", "'['",
"','", "'['", "']'", "'<'", "'>'", "'{'", "'}'", "'.'", "'+'", "'-'", "']'", "'<'", "'>'", "'{'", "'}'", "'.'", "'+'", "'-'", "'/'", "'*'",
"'/'", "'*'", "'%'", "'^'", "'|'", "'&'", "'~'", "'='", "'!'", "':'", "'%'", "'^'", "'|'", "'&'", "'~'", "'='", "'!'", "':'", "';'", "'?'",
"';'", "'?'", "$accept", "input", "line", "text_line", "control_line", "$accept", "input", "line", "text_line", "control_line",
"replacement_token_list", "conditional_token_list", "conditional_token", "replacement_list", "parameter_list", "conditional_list", "token_list",
"parameter_list", "token_list", "token", "operator", 0 "conditional_token", "token", "operator", 0
}; };
#endif #endif
...@@ -543,34 +539,34 @@ static const yytype_uint16 yytoknum[] = ...@@ -543,34 +539,34 @@ static const yytype_uint16 yytoknum[] =
{ {
0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 10, 40, 41, 44, 91, 93, 60, 275, 276, 10, 40, 41, 44, 91, 93, 60, 62,
62, 123, 125, 46, 43, 45, 47, 42, 37, 94, 123, 125, 46, 43, 45, 47, 42, 37, 94, 124,
124, 38, 126, 61, 33, 58, 59, 63 38, 126, 61, 33, 58, 59, 63
}; };
# endif # endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] = static const yytype_uint8 yyr1[] =
{ {
0, 48, 49, 49, 50, 50, 51, 51, 52, 52, 0, 47, 48, 48, 49, 49, 50, 50, 51, 51,
52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
52, 52, 52, 53, 53, 54, 54, 55, 55, 55, 51, 51, 51, 52, 52, 53, 53, 53, 54, 54,
56, 56, 56, 57, 57, 58, 58, 58, 58, 58, 55, 55, 56, 56, 56, 57, 57, 57, 57, 58,
59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
59, 59, 59, 59 58, 58, 58
}; };
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
static const yytype_uint8 yyr2[] = static const yytype_uint8 yyr2[] =
{ {
0, 2, 0, 2, 1, 1, 1, 2, 2, 4, 0, 2, 0, 2, 1, 1, 1, 2, 2, 3,
7, 3, 3, 3, 3, 3, 2, 2, 2, 2, 6, 3, 3, 3, 3, 3, 2, 2, 2, 2,
2, 2, 2, 0, 1, 1, 2, 2, 4, 1, 2, 2, 2, 0, 1, 0, 1, 3, 1, 2,
0, 1, 3, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 4, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1 1, 1, 1
}; };
/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
...@@ -579,46 +575,46 @@ static const yytype_uint8 yyr2[] = ...@@ -579,46 +575,46 @@ static const yytype_uint8 yyr2[] =
static const yytype_uint8 yydefact[] = static const yytype_uint8 yydefact[] =
{ {
2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 36, 37, 0, 0, 0, 0, 0, 0, 23, 0, 36, 37,
38, 39, 6, 44, 45, 62, 40, 41, 42, 43, 38, 6, 43, 44, 61, 39, 40, 41, 42, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 63, 3, 4, 5, 56, 57, 58, 59, 60, 62, 3, 4, 5, 0,
0, 33, 35, 8, 23, 0, 0, 0, 0, 25, 30, 35, 8, 0, 0, 0, 28, 34, 0, 0,
29, 0, 0, 16, 0, 17, 18, 19, 20, 21, 16, 0, 17, 18, 19, 20, 21, 22, 0, 24,
22, 7, 34, 0, 24, 30, 11, 27, 0, 12, 25, 7, 31, 11, 32, 0, 12, 29, 13, 14,
26, 13, 14, 15, 9, 31, 0, 0, 23, 0, 15, 9, 26, 0, 0, 23, 0, 33, 0, 27,
28, 0, 32, 10 10
}; };
/* YYDEFGOTO[NTERM-NUM]. */ /* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] = static const yytype_int8 yydefgoto[] =
{ {
-1, 1, 47, 48, 49, 73, 58, 59, 86, 74, -1, 1, 46, 47, 48, 68, 83, 55, 69, 56,
60, 52 57, 51
}; };
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */ STATE-NUM. */
#define YYPACT_NINF -29 #define YYPACT_NINF -55
static const yytype_int16 yypact[] = static const yytype_int16 yypact[] =
{ {
-29, 1, -29, -9, 29, 33, 35, 139, 36, 37, -55, 73, -55, -17, -18, 145, -10, -9, -16, 145,
38, 139, 39, 40, 41, 42, 43, 44, -29, -29, -8, 22, 23, 24, 25, 27, 201, 28, -55, -55,
-29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -55, -55, -55, -55, -55, -55, -55, -55, -55, -55,
-29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -55, -55, -55, -55, -55, -55, -55, -55, -55, -55,
-29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -55, -55, -55, -55, -55, -55, -55, -55, -55, 173,
168, -29, -29, -29, 197, 45, 47, 30, 69, -29, -55, -55, -55, 30, -19, -3, -55, -55, 31, 32,
-29, 48, 49, -29, 104, -29, -29, -29, -29, -29, -55, 109, -55, -55, -55, -55, -55, -55, 33, 201,
-29, -29, -29, 51, 197, 46, -29, -29, 53, -29, 29, -55, -55, -55, -55, 35, -55, -55, -55, -55,
-29, -29, -29, -29, -29, -29, -23, 52, 197, 54, -55, -55, -55, -15, -11, 201, 36, -55, 37, -55,
-29, 55, -29, -29 -55
}; };
/* YYPGOTO[NTERM-NUM]. */ /* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] = static const yytype_int8 yypgoto[] =
{ {
-29, -29, -29, -29, -29, -28, 68, -8, -29, 79, -55, -55, -55, -55, -55, -27, -55, 51, 60, -54,
-1, -29 -1, -55
}; };
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
...@@ -628,76 +624,76 @@ static const yytype_int8 yypgoto[] = ...@@ -628,76 +624,76 @@ static const yytype_int8 yypgoto[] =
#define YYTABLE_NINF -1 #define YYTABLE_NINF -1
static const yytype_uint8 yytable[] = static const yytype_uint8 yytable[] =
{ {
51, 2, 88, 89, 3, 4, 5, 6, 7, 8, 50, 77, 74, 53, 75, 52, 60, 77, 54, 85,
9, 10, 11, 12, 53, 13, 14, 15, 16, 17, 86, 58, 59, 87, 62, 50, 18, 19, 20, 76,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 72,
80, 54, 77, 51, 78, 55, 80, 56, 61, 62,
91, 63, 65, 66, 67, 68, 69, 70, 85, 75,
76, 81, 82, 72, 84, 87, 92, 90, 93, 64,
50, 0, 57, 0, 0, 0, 0, 51, 18, 19,
20, 21, 79, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 57, 0, 0,
0, 0, 0, 18, 19, 20, 21, 83, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 57, 0, 0, 0, 0, 0, 18, 19,
20, 21, 0, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 18, 19, 20,
21, 71, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 18, 19, 20, 21,
0, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46 42, 43, 44, 45, 63, 64, 65, 66, 72, 67,
82, 70, 73, 78, 79, 81, 84, 89, 88, 90,
61, 49, 0, 0, 0, 0, 0, 0, 72, 0,
0, 0, 0, 2, 0, 0, 3, 4, 5, 6,
7, 8, 9, 10, 50, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
54, 0, 0, 0, 0, 0, 0, 0, 18, 19,
20, 80, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 54, 0, 0, 0,
0, 0, 0, 0, 18, 19, 20, 0, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 18, 19, 20, 71, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
18, 19, 20, 0, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45
}; };
static const yytype_int8 yycheck[] = static const yytype_int8 yycheck[] =
{ {
1, 0, 25, 26, 3, 4, 5, 6, 7, 8, 1, 55, 21, 21, 23, 22, 22, 61, 11, 24,
9, 10, 11, 12, 23, 14, 15, 16, 17, 18, 25, 21, 21, 24, 22, 16, 19, 20, 21, 22,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
39, 40, 41, 42, 43, 44, 45, 46, 47, 50, 43, 44, 45, 46, 22, 22, 22, 22, 49, 22,
58, 22, 22, 54, 24, 22, 64, 22, 22, 22, 21, 23, 22, 22, 22, 22, 21, 21, 85, 22,
88, 23, 23, 23, 23, 23, 23, 23, 22, 24, 9, 1, -1, -1, -1, -1, -1, -1, 69, -1,
23, 23, 23, 74, 23, 22, 22, 25, 23, 11, -1, -1, -1, 0, -1, -1, 3, 4, 5, 6,
1, -1, 13, -1, -1, -1, -1, 88, 19, 20, 7, 8, 9, 10, 85, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
11, -1, -1, -1, -1, -1, -1, -1, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 13, -1, -1, 41, 42, 43, 44, 45, 46, 11, -1, -1, -1,
-1, -1, -1, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 19, 20, 21, -1, 23, 24,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
46, 47, 13, -1, -1, -1, -1, -1, 19, 20, 45, 46, 19, 20, 21, 22, 23, 24, 25, 26,
21, 22, -1, 24, 25, 26, 27, 28, 29, 30, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
41, 42, 43, 44, 45, 46, 47, 19, 20, 21, 19, 20, 21, -1, 23, 24, 25, 26, 27, 28,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 39, 40, 41, 42, 43, 44, 45, 46
42, 43, 44, 45, 46, 47, 19, 20, 21, 22,
-1, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47
}; };
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */ symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] = static const yytype_uint8 yystos[] =
{ {
0, 49, 0, 3, 4, 5, 6, 7, 8, 9, 0, 48, 0, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 50, 51, 52, 41, 42, 43, 44, 45, 46, 49, 50, 51, 55,
57, 58, 59, 23, 22, 22, 22, 13, 54, 55, 57, 58, 22, 21, 11, 54, 56, 57, 21, 21,
58, 22, 22, 23, 54, 23, 23, 23, 23, 23, 22, 54, 22, 22, 22, 22, 22, 22, 52, 55,
23, 23, 58, 53, 57, 24, 23, 22, 24, 23, 23, 22, 57, 22, 21, 23, 22, 56, 22, 22,
55, 23, 23, 23, 23, 22, 56, 22, 25, 26, 22, 22, 21, 53, 21, 24, 25, 24, 52, 21,
25, 53, 22, 23 22
}; };
#define yyerrok (yyerrstatus = 0) #define yyerrok (yyerrstatus = 0)
...@@ -1539,37 +1535,27 @@ yyreduce: ...@@ -1539,37 +1535,27 @@ yyreduce:
YY_REDUCE_PRINT (yyn); YY_REDUCE_PRINT (yyn);
switch (yyn) switch (yyn)
{ {
case 4: case 7:
{ {
// 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) - (2)].tlist)->begin(), (yyvsp[(1) - (2)].tlist)->end());
delete (yyvsp[(1) - (1)].tlist); delete (yyvsp[(1) - (2)].tlist);
;} ;}
break; break;
case 6:
{ (yyval.tlist) = NULL; ;}
break;
case 7:
{ (yyval.tlist) = (yyvsp[(1) - (2)].tlist); ;}
break;
case 9: case 9:
{ {
context->defineMacro((yylsp[(2) - (4)]).first_line, pp::Macro::kTypeObj, (yyvsp[(2) - (4)].sval), NULL, (yyvsp[(3) - (4)].tlist)); context->defineMacro((yylsp[(1) - (3)]).first_line, pp::Macro::kTypeObj, (yyvsp[(1) - (3)].sval), NULL, (yyvsp[(2) - (3)].tlist));
;} ;}
break; break;
case 10: case 10:
{ {
context->defineMacro((yylsp[(2) - (7)]).first_line, pp::Macro::kTypeFunc, (yyvsp[(2) - (7)].sval), (yyvsp[(4) - (7)].slist), (yyvsp[(6) - (7)].tlist)); context->defineMacro((yylsp[(1) - (6)]).first_line, pp::Macro::kTypeFunc, (yyvsp[(1) - (6)].sval), (yyvsp[(3) - (6)].tlist), (yyvsp[(5) - (6)].tlist));
;} ;}
break; break;
...@@ -1622,71 +1608,71 @@ yyreduce: ...@@ -1622,71 +1608,71 @@ yyreduce:
case 23: case 23:
{ (yyval.tlist) = NULL ;} { (yyval.tlist) = NULL; ;}
break; break;
case 25: case 25:
{ { (yyval.tlist) = NULL; ;}
(yyval.tlist) = new pp::TokenVector;
(yyval.tlist)->push_back((yyvsp[(1) - (1)].tval));
;}
break; break;
case 26: case 26:
{ {
(yyval.tlist) = (yyvsp[(1) - (2)].tlist); (yyval.tlist) = new pp::TokenVector;
(yyval.tlist)->push_back((yyvsp[(2) - (2)].tval)); (yyval.tlist)->push_back(new pp::Token((yylsp[(1) - (1)]).first_line, IDENTIFIER, (yyvsp[(1) - (1)].sval)));
;} ;}
break; break;
case 27: case 27:
{ {
(yyval.tlist) = (yyvsp[(1) - (3)].tlist);
(yyval.tlist)->push_back(new pp::Token((yylsp[(3) - (3)]).first_line, IDENTIFIER, (yyvsp[(3) - (3)].sval)));
;} ;}
break; break;
case 28: case 28:
{ {
(yyval.tlist) = new pp::TokenVector;
(yyval.tlist)->push_back((yyvsp[(1) - (1)].tval));
;} ;}
break; break;
case 30: case 29:
{ (yyval.slist) = NULL; ;} {
(yyval.tlist) = (yyvsp[(1) - (2)].tlist);
(yyval.tlist)->push_back((yyvsp[(2) - (2)].tval));
;}
break; break;
case 31: case 30:
{ {
(yyval.slist) = new std::vector<std::string*>(); (yyval.tlist) = new pp::TokenVector;
(yyval.slist)->push_back((yyvsp[(1) - (1)].sval)); (yyval.tlist)->push_back((yyvsp[(1) - (1)].tval));
;} ;}
break; break;
case 32: case 31:
{ {
(yyval.slist) = (yyvsp[(1) - (3)].slist); (yyval.tlist) = (yyvsp[(1) - (2)].tlist);
(yyval.slist)->push_back((yyvsp[(3) - (3)].sval)); (yyval.tlist)->push_back((yyvsp[(2) - (2)].tval));
;} ;}
break; break;
case 33: case 32:
{ {
(yyval.tlist) = new pp::TokenVector;
(yyval.tlist)->push_back((yyvsp[(1) - (1)].tval));
;} ;}
break; break;
case 34: case 33:
{ {
(yyval.tlist) = (yyvsp[(1) - (2)].tlist);
(yyval.tlist)->push_back((yyvsp[(2) - (2)].tval));
;} ;}
break; break;
...@@ -1700,147 +1686,140 @@ yyreduce: ...@@ -1700,147 +1686,140 @@ yyreduce:
case 36: case 36:
{ {
(yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, SPACE, NULL);
;}
break;
case 37:
{
(yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, INT_CONSTANT, (yyvsp[(1) - (1)].sval)); (yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, INT_CONSTANT, (yyvsp[(1) - (1)].sval));
;} ;}
break; break;
case 38: case 37:
{ {
(yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, FLOAT_CONSTANT, (yyvsp[(1) - (1)].sval)); (yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, FLOAT_CONSTANT, (yyvsp[(1) - (1)].sval));
;} ;}
break; break;
case 39: case 38:
{ {
(yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, IDENTIFIER, (yyvsp[(1) - (1)].sval)); (yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, IDENTIFIER, (yyvsp[(1) - (1)].sval));
;} ;}
break; break;
case 40: case 39:
{ (yyval.ival) = '['; ;} { (yyval.ival) = '['; ;}
break; break;
case 41: case 40:
{ (yyval.ival) = ']'; ;} { (yyval.ival) = ']'; ;}
break; break;
case 42: case 41:
{ (yyval.ival) = '<'; ;} { (yyval.ival) = '<'; ;}
break; break;
case 43: case 42:
{ (yyval.ival) = '>'; ;} { (yyval.ival) = '>'; ;}
break; break;
case 44: case 43:
{ (yyval.ival) = '('; ;} { (yyval.ival) = '('; ;}
break; break;
case 45: case 44:
{ (yyval.ival) = ')'; ;} { (yyval.ival) = ')'; ;}
break; break;
case 46: case 45:
{ (yyval.ival) = '{'; ;} { (yyval.ival) = '{'; ;}
break; break;
case 47: case 46:
{ (yyval.ival) = '}'; ;} { (yyval.ival) = '}'; ;}
break; break;
case 48: case 47:
{ (yyval.ival) = '.'; ;} { (yyval.ival) = '.'; ;}
break; break;
case 49: case 48:
{ (yyval.ival) = '+'; ;} { (yyval.ival) = '+'; ;}
break; break;
case 50: case 49:
{ (yyval.ival) = '-'; ;} { (yyval.ival) = '-'; ;}
break; break;
case 51: case 50:
{ (yyval.ival) = '/'; ;} { (yyval.ival) = '/'; ;}
break; break;
case 52: case 51:
{ (yyval.ival) = '*'; ;} { (yyval.ival) = '*'; ;}
break; break;
case 53: case 52:
{ (yyval.ival) = '%'; ;} { (yyval.ival) = '%'; ;}
break; break;
case 54: case 53:
{ (yyval.ival) = '^'; ;} { (yyval.ival) = '^'; ;}
break; break;
case 55: case 54:
{ (yyval.ival) = '|'; ;} { (yyval.ival) = '|'; ;}
break; break;
case 56: case 55:
{ (yyval.ival) = '&'; ;} { (yyval.ival) = '&'; ;}
break; break;
case 57: case 56:
{ (yyval.ival) = '~'; ;} { (yyval.ival) = '~'; ;}
break; break;
case 58: case 57:
{ (yyval.ival) = '='; ;} { (yyval.ival) = '='; ;}
break; break;
case 59: case 58:
{ (yyval.ival) = '!'; ;} { (yyval.ival) = '!'; ;}
break; break;
case 60: case 59:
{ (yyval.ival) = ':'; ;} { (yyval.ival) = ':'; ;}
break; break;
case 61: case 60:
{ (yyval.ival) = ';'; ;} { (yyval.ival) = ';'; ;}
break; break;
case 62: case 61:
{ (yyval.ival) = ','; ;} { (yyval.ival) = ','; ;}
break; break;
case 63: case 62:
{ (yyval.ival) = '?'; ;} { (yyval.ival) = '?'; ;}
break; break;
......
...@@ -40,48 +40,46 @@ ...@@ -40,48 +40,46 @@
know about them. */ know about them. */
enum yytokentype { enum yytokentype {
HASH = 258, HASH = 258,
HASH_DEFINE_OBJ = 259, HASH_UNDEF = 259,
HASH_DEFINE_FUNC = 260, HASH_IF = 260,
HASH_UNDEF = 261, HASH_IFDEF = 261,
HASH_IF = 262, HASH_IFNDEF = 262,
HASH_IFDEF = 263, HASH_ELSE = 263,
HASH_IFNDEF = 264, HASH_ELIF = 264,
HASH_ELSE = 265, HASH_ENDIF = 265,
HASH_ELIF = 266, DEFINED = 266,
HASH_ENDIF = 267, HASH_ERROR = 267,
DEFINED = 268, HASH_PRAGMA = 268,
HASH_ERROR = 269, HASH_EXTENSION = 269,
HASH_PRAGMA = 270, HASH_VERSION = 270,
HASH_EXTENSION = 271, HASH_LINE = 271,
HASH_VERSION = 272, HASH_DEFINE_OBJ = 272,
HASH_LINE = 273, HASH_DEFINE_FUNC = 273,
SPACE = 274, INT_CONSTANT = 274,
INT_CONSTANT = 275, FLOAT_CONSTANT = 275,
FLOAT_CONSTANT = 276, IDENTIFIER = 276
IDENTIFIER = 277
}; };
#endif #endif
/* Tokens. */ /* Tokens. */
#define HASH 258 #define HASH 258
#define HASH_DEFINE_OBJ 259 #define HASH_UNDEF 259
#define HASH_DEFINE_FUNC 260 #define HASH_IF 260
#define HASH_UNDEF 261 #define HASH_IFDEF 261
#define HASH_IF 262 #define HASH_IFNDEF 262
#define HASH_IFDEF 263 #define HASH_ELSE 263
#define HASH_IFNDEF 264 #define HASH_ELIF 264
#define HASH_ELSE 265 #define HASH_ENDIF 265
#define HASH_ELIF 266 #define DEFINED 266
#define HASH_ENDIF 267 #define HASH_ERROR 267
#define DEFINED 268 #define HASH_PRAGMA 268
#define HASH_ERROR 269 #define HASH_EXTENSION 269
#define HASH_PRAGMA 270 #define HASH_VERSION 270
#define HASH_EXTENSION 271 #define HASH_LINE 271
#define HASH_VERSION 272 #define HASH_DEFINE_OBJ 272
#define HASH_LINE 273 #define HASH_DEFINE_FUNC 273
#define SPACE 274 #define INT_CONSTANT 274
#define INT_CONSTANT 275 #define FLOAT_CONSTANT 275
#define FLOAT_CONSTANT 276 #define IDENTIFIER 276
#define IDENTIFIER 277
...@@ -92,7 +90,6 @@ typedef union YYSTYPE ...@@ -92,7 +90,6 @@ typedef union YYSTYPE
{ {
int ival; int ival;
std::string* sval; std::string* sval;
std::vector<std::string*>* slist;
pp::Token* tval; pp::Token* tval;
pp::TokenVector* tlist; pp::TokenVector* tlist;
} }
......
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