Commit b81c401d by alokp@chromium.org

Modified Token class to store various types of data. Added debug code to dump…

Modified Token class to store various types of data. Added debug code to dump token to an output stream. Review URL: http://codereview.appspot.com/4920041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@737 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent ebbec2e7
......@@ -6,34 +6,53 @@
#include "Token.h"
#include "token_type.h"
static const int kLocationLineSize = 16; // in bits.
static const int kLocationLineMask = (1 << kLocationLineSize) - 1;
namespace pp
{
Token::Token() : mLocation(-1), mType(-1), mValue(0)
Token::Location Token::encodeLocation(int line, int file)
{
return (file << kLocationLineSize) | (line & kLocationLineMask);
}
Token::Token(Location l, int t) : mLocation(l), mType(t)
void Token::decodeLocation(Location loc, int* line, int* file)
{
if (file) *file = loc >> kLocationLineSize;
if (line) *line = loc & kLocationLineMask;
}
Token::Token(Location l, int t, const std::string& s) : mLocation(l), mType(t), mValue(s)
Token::Token(Location location, int type, std::string* value)
: mLocation(location),
mType(type),
mValue(value)
{
}
Token::Location Token::encodeLocation(int line, int file)
{
return (file << kLocationLineSize) | (line & kLocationLineMask);
Token::~Token() {
delete mValue;
}
void Token::decodeLocation(Location loc, int* line, int* file)
std::ostream& operator<<(std::ostream& out, const Token& token)
{
if (file) *file = loc >> kLocationLineSize;
if (line) *line = loc & kLocationLineMask;
switch (token.type())
{
case SPACE:
out << " ";
break;
case INT_CONSTANT:
case FLOAT_CONSTANT:
case IDENTIFIER:
out << *(token.value());
break;
default:
out << static_cast<char>(token.type());
break;
}
return out;
}
} // namespace pp
......@@ -17,27 +17,28 @@ class Token
{
public:
typedef int Location;
Token();
Token(Location l, int t);
Token(Location l, int t, const std::string& s);
static Location encodeLocation(int line, int file);
static void decodeLocation(Location loc, int* line, int* file);
// Takes ownership of string.
Token(Location location, int type, std::string* value);
~Token();
Location location() const { return mLocation; }
int type() const { return mType; }
const std::string& value() const { return mValue; }
const std::string* value() const { return mValue; }
private:
Location mLocation;
int mType;
std::string mValue;
std::string* mValue;
};
typedef std::vector<Token*> TokenVector;
typedef TokenVector::const_iterator TokenIterator;
extern std::ostream& operator<<(std::ostream& out, const Token& token);
} // namepsace pp
#endif // COMPILER_PREPROCESSOR_TOKEN_H_
......@@ -34,7 +34,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
yylloc->first_column = yycolumn + 1; \
yycolumn += yyleng; \
} while(0);
#define YY_INPUT(buf, result, maxSize) \
result = readInput(yyextra, buf, maxSize);
......@@ -56,6 +56,10 @@ DECIMAL_CONSTANT [1-9][0-9]*
OCTAL_CONSTANT 0[0-7]*
HEXADECIMAL_CONSTANT 0[xX][0-9a-fA-F]+
DIGIT [0-9]
EXPONENT_PART [eE][+-]?{DIGIT}+
FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
%%
{HASH} { return HASH; }
......@@ -79,13 +83,18 @@ HEXADECIMAL_CONSTANT 0[xX][0-9a-fA-F]+
{HASH}line { return HASH_LINE; }
{IDENTIFIER} {
yylval->tval = new pp::Token(yylineno, IDENTIFIER, std::string(yytext, yyleng));
yylval->sval = new std::string(yytext, yyleng);
return IDENTIFIER;
}
{DECIMAL_CONSTANT}|{OCTAL_CONSTANT}|{HEXADECIMAL_CONSTANT} {
yylval->tval = new pp::Token(yylineno, INTEGER_CONSTANT, std::string(yytext, yyleng));
return INTEGER_CONSTANT;
yylval->sval = new std::string(yytext, yyleng);
return INT_CONSTANT;
}
({DIGIT}+{EXPONENT_PART})|({FRACTIONAL_CONSTANT}{EXPONENT_PART}?) {
yylval->sval = new std::string(yytext, yyleng);
return FLOAT_CONSTANT;
}
{PUNCTUATOR} { return yytext[0]; }
......
......@@ -36,6 +36,8 @@ WHICH GENERATES THE GLSL ES PARSER.
%union {
int ival;
std::string* sval;
std::vector<std::string*>* slist;
pp::Token* tval;
pp::TokenVector* tlist;
}
......@@ -49,11 +51,11 @@ static void yyerror(YYLTYPE* llocp,
static void defineMacro(pp::Context* context,
YYLTYPE* llocp,
pp::Macro::Type type,
pp::Token* identifier,
pp::TokenVector* parameters,
const std::string* identifier,
std::vector<std::string*>* parameters,
pp::TokenVector* replacements);
static void undefineMacro(pp::Context* context, pp::Token* identifier);
static bool isMacroDefined(pp::Context* context, pp::Token* identifier);
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 popConditionalBlock(pp::Context* context);
%}
......@@ -62,10 +64,11 @@ static void popConditionalBlock(pp::Context* context);
%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 SPACE
%token <tval> IDENTIFIER INTEGER_CONSTANT FLOAT_CONSTANT
%token <sval> INT_CONSTANT FLOAT_CONSTANT IDENTIFIER
%type <ival> operator
%type <slist> parameter_list
%type <tval> conditional_token token
%type <tlist> text_line parameter_list replacement_token_list conditional_token_list token_list
%type <tlist> text_line replacement_token_list conditional_token_list token_list
%%
input
......@@ -74,7 +77,12 @@ input
;
line
: text_line
: text_line {
// TODO(alokp): Expand macros.
pp::TokenVector* out = context->output;
out->insert(out->end(), $1->begin(), $1->end());
delete $1;
}
| control_line
;
......@@ -144,7 +152,7 @@ conditional_token
parameter_list
: /* empty */ { $$ = NULL; }
| IDENTIFIER {
$$ = new pp::TokenVector;
$$ = new std::vector<std::string*>();
$$->push_back($1);
}
| parameter_list ',' IDENTIFIER {
......@@ -155,7 +163,6 @@ parameter_list
token_list
: token {
//context->ppData.skipWS = false;
$$ = new pp::TokenVector;
$$->push_back($1);
}
......@@ -166,11 +173,21 @@ token_list
;
token
: IDENTIFIER
| INTEGER_CONSTANT
| FLOAT_CONSTANT
| SPACE { $$ = new pp::Token(@1.first_line, SPACE); }
| operator { $$ = new pp::Token(@1.first_line, $1); }
: operator {
$$ = new pp::Token(@1.first_line, $1, NULL);
}
| SPACE {
$$ = new pp::Token(@1.first_line, SPACE, NULL);
}
| INT_CONSTANT {
$$ = new pp::Token(@1.first_line, INT_CONSTANT, $1);
}
| FLOAT_CONSTANT {
$$ = new pp::Token(@1.first_line, FLOAT_CONSTANT, $1);
}
| IDENTIFIER {
$$ = new pp::Token(@1.first_line, IDENTIFIER, $1);
}
;
operator
......@@ -209,17 +226,17 @@ void yyerror(YYLTYPE* llocp, pp::Context* context, const char* reason)
void defineMacro(pp::Context* context,
YYLTYPE* llocp,
pp::Macro::Type type,
pp::Token* identifier,
pp::TokenVector* parameters,
const std::string* identifier,
std::vector<std::string*>* parameters,
pp::TokenVector* replacements)
{
}
void undefineMacro(pp::Context* context, pp::Token* identifier)
void undefineMacro(pp::Context* context, const std::string* identifier)
{
}
bool isMacroDefined(pp::Context* context, pp::Token* identifier)
bool isMacroDefined(pp::Context* context, const std::string* identifier)
{
return false;
}
......
......@@ -371,8 +371,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 22
#define YY_END_OF_BUFFER 23
#define YY_NUM_RULES 23
#define YY_END_OF_BUFFER 24
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
......@@ -380,28 +380,30 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_acclist[51] =
static yyconst flex_int16_t yy_acclist[57] =
{ 0,
23, 22, 20, 22, 21, 22, 19, 22, 18, 22,
18, 22, 17, 22, 17, 22, 20, 22, 1, 22,
20, 18, 18, 17, 17, 20, 1, 1, 18, 17,
5, 17, 17, 9, 8, 16, 17, 10, 12, 6,
4, 11, 17, 2, 7, 13,16387, 15, 8195, 14
24, 23, 21, 23, 22, 23, 20, 23, 20, 23,
18, 23, 18, 23, 17, 23, 17, 23, 21, 23,
1, 23, 21, 19, 19, 18, 18, 17, 17, 21,
1, 1, 19, 18, 17, 5, 19, 17, 17, 9,
8, 16, 17, 10, 12, 6, 4, 11, 17, 2,
7, 13,16387, 15, 8195, 14
} ;
static yyconst flex_int16_t yy_accept[94] =
static yyconst flex_int16_t yy_accept[104] =
{ 0,
1, 1, 1, 2, 3, 5, 7, 9, 11, 13,
15, 17, 19, 21, 22, 23, 23, 24, 25, 26,
27, 28, 29, 29, 29, 29, 29, 29, 29, 29,
30, 31, 31, 31, 31, 31, 31, 32, 32, 32,
32, 32, 33, 33, 33, 33, 33, 33, 33, 33,
33, 33, 33, 33, 33, 34, 34, 35, 36, 36,
36, 36, 36, 36, 37, 37, 37, 37, 38, 38,
39, 40, 40, 41, 41, 41, 42, 42, 44, 45,
45, 46, 47, 47, 48, 48, 49, 49, 49, 50,
50, 51, 51
15, 17, 19, 21, 23, 24, 25, 26, 27, 27,
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] =
......@@ -410,16 +412,16 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 4, 1, 5, 1, 4, 4, 1, 6,
4, 4, 4, 4, 4, 4, 4, 7, 8, 8,
8, 8, 8, 8, 8, 9, 9, 4, 4, 4,
4, 4, 4, 1, 10, 10, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 12, 11, 11,
4, 1, 4, 4, 11, 1, 13, 10, 10, 14,
15, 16, 17, 11, 18, 11, 11, 19, 20, 21,
22, 23, 11, 24, 25, 26, 27, 28, 11, 29,
11, 11, 4, 4, 4, 4, 1, 1, 1, 1,
4, 4, 7, 4, 7, 8, 4, 9, 10, 10,
10, 10, 10, 10, 10, 11, 11, 4, 4, 4,
4, 4, 4, 1, 12, 12, 12, 12, 13, 12,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 15, 14, 14,
4, 1, 4, 4, 14, 1, 16, 12, 12, 17,
18, 19, 20, 14, 21, 14, 14, 22, 23, 24,
25, 26, 14, 27, 28, 29, 30, 31, 14, 32,
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,
......@@ -436,90 +438,105 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst flex_int32_t yy_meta[30] =
static yyconst flex_int32_t yy_meta[33] =
{ 0,
1, 2, 1, 1, 1, 3, 4, 4, 4, 5,
6, 6, 5, 5, 5, 5, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6
1, 2, 1, 1, 1, 3, 1, 1, 4, 4,
4, 5, 6, 7, 7, 5, 5, 6, 5, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7
} ;
static yyconst flex_int16_t yy_base[98] =
static yyconst flex_int16_t yy_base[109] =
{ 0,
0, 14, 127, 128, 124, 128, 128, 17, 3, 0,
110, 25, 45, 122, 24, 0, 26, 0, 107, 34,
0, 0, 107, 19, 105, 102, 95, 97, 102, 0,
98, 99, 19, 100, 89, 86, 28, 90, 97, 95,
84, 86, 88, 89, 89, 85, 80, 86, 85, 85,
83, 80, 81, 70, 79, 66, 128, 128, 70, 47,
49, 53, 52, 128, 46, 49, 44, 47, 43, 128,
128, 32, 128, 40, 42, 128, 32, 0, 51, 34,
128, 128, 30, 48, 23, 128, 35, 5, 128, 7,
128, 128, 73, 76, 79, 83, 87
0, 17, 171, 172, 168, 172, 172, 3, 27, 52,
0, 151, 27, 69, 166, 26, 28, 1, 21, 40,
0, 0, 0, 148, 50, 0, 0, 148, 42, 146,
143, 136, 138, 143, 47, 66, 69, 0, 139, 140,
60, 141, 130, 127, 65, 131, 138, 136, 125, 74,
83, 127, 129, 130, 130, 126, 121, 127, 126, 126,
124, 121, 122, 111, 120, 113, 172, 172, 117, 108,
110, 114, 114, 172, 108, 111, 108, 103, 101, 172,
172, 85, 172, 79, 81, 172, 71, 0, 71, 51,
172, 172, 44, 65, 28, 172, 42, 19, 172, 9,
172, 172, 100, 104, 108, 111, 116, 121
} ;
static yyconst flex_int16_t yy_def[98] =
static yyconst flex_int16_t yy_def[109] =
{ 0,
93, 93, 92, 92, 92, 92, 92, 92, 92, 94,
94, 92, 92, 92, 92, 95, 92, 94, 94, 92,
13, 13, 92, 92, 92, 92, 92, 92, 92, 95,
94, 92, 92, 92, 92, 92, 92, 92, 92, 92,
92, 94, 92, 92, 92, 92, 92, 92, 92, 92,
92, 92, 92, 92, 94, 92, 92, 92, 92, 92,
92, 92, 92, 92, 92, 92, 92, 94, 92, 92,
92, 92, 92, 92, 92, 92, 92, 94, 92, 92,
92, 92, 92, 96, 92, 92, 97, 92, 92, 97,
92, 0, 92, 92, 92, 92, 92
103, 103, 102, 102, 102, 102, 102, 102, 102, 102,
104, 104, 102, 102, 102, 105, 105, 9, 18, 102,
106, 10, 104, 104, 102, 14, 14, 102, 102, 102,
102, 102, 102, 102, 102, 102, 102, 106, 104, 102,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
102, 104, 102, 102, 102, 102, 102, 102, 102, 102,
102, 102, 102, 102, 104, 102, 102, 102, 102, 102,
102, 102, 102, 102, 102, 102, 102, 104, 102, 102,
102, 102, 102, 102, 102, 102, 102, 104, 102, 102,
102, 102, 102, 107, 102, 102, 108, 102, 102, 108,
102, 0, 102, 102, 102, 102, 102, 102
} ;
static yyconst flex_int16_t yy_nxt[158] =
static yyconst flex_int16_t yy_nxt[205] =
{ 0,
4, 5, 6, 7, 4, 7, 8, 9, 9, 17,
17, 17, 89, 11, 4, 12, 6, 7, 13, 7,
8, 9, 9, 15, 15, 91, 20, 11, 16, 21,
15, 15, 17, 17, 17, 20, 44, 33, 21, 34,
89, 49, 35, 45, 88, 16, 22, 36, 50, 84,
86, 85, 84, 83, 82, 81, 80, 79, 23, 24,
78, 77, 25, 26, 76, 75, 74, 27, 73, 72,
71, 28, 29, 10, 10, 10, 10, 10, 10, 18,
18, 18, 30, 30, 87, 70, 69, 87, 87, 90,
90, 90, 90, 68, 67, 66, 65, 64, 63, 62,
61, 60, 59, 58, 57, 56, 55, 54, 53, 52,
51, 48, 47, 46, 43, 42, 41, 40, 39, 38,
37, 32, 31, 14, 19, 14, 92, 3, 92, 92,
92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
92, 92, 92, 92, 92, 92, 92
4, 5, 6, 7, 4, 7, 7, 8, 9, 10,
10, 16, 16, 16, 99, 102, 12, 4, 13, 6,
7, 14, 7, 7, 8, 9, 10, 10, 25, 19,
19, 26, 102, 12, 17, 18, 18, 19, 35, 20,
35, 21, 101, 35, 20, 35, 36, 99, 37, 37,
37, 25, 98, 50, 26, 51, 51, 51, 21, 17,
22, 22, 22, 41, 20, 42, 94, 96, 43, 20,
27, 95, 94, 44, 37, 37, 37, 37, 37, 37,
54, 59, 51, 51, 51, 28, 29, 55, 60, 30,
31, 51, 51, 51, 32, 93, 92, 91, 33, 34,
11, 11, 11, 11, 11, 11, 11, 23, 23, 23,
23, 16, 90, 16, 38, 38, 38, 97, 89, 88,
97, 97, 97, 100, 100, 100, 100, 100, 87, 86,
85, 84, 83, 82, 81, 80, 79, 78, 77, 76,
75, 74, 73, 72, 71, 70, 69, 68, 67, 66,
65, 64, 63, 62, 61, 58, 57, 56, 53, 52,
49, 48, 47, 46, 45, 40, 39, 15, 24, 15,
102, 3, 102, 102, 102, 102, 102, 102, 102, 102,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
102, 102, 102, 102
} ;
static yyconst flex_int16_t yy_chk[158] =
static yyconst flex_int16_t yy_chk[205] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 9,
9, 9, 90, 1, 2, 2, 2, 2, 2, 2,
2, 2, 2, 8, 8, 88, 12, 2, 8, 12,
15, 15, 17, 17, 17, 20, 33, 24, 20, 24,
87, 37, 24, 33, 85, 8, 13, 24, 37, 84,
83, 80, 79, 77, 75, 74, 72, 69, 13, 13,
68, 67, 13, 13, 66, 65, 63, 13, 62, 61,
60, 13, 13, 93, 93, 93, 93, 93, 93, 94,
94, 94, 95, 95, 96, 59, 56, 96, 96, 97,
97, 97, 97, 55, 54, 53, 52, 51, 50, 49,
48, 47, 46, 45, 44, 43, 42, 41, 40, 39,
38, 36, 35, 34, 32, 31, 29, 28, 27, 26,
25, 23, 19, 14, 11, 5, 3, 92, 92, 92,
92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
92, 92, 92, 92, 92, 92, 92
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 8, 8, 8, 100, 18, 1, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 13, 19,
19, 13, 18, 2, 9, 9, 9, 9, 16, 9,
17, 9, 98, 16, 9, 17, 20, 97, 20, 20,
20, 25, 95, 35, 25, 35, 35, 35, 9, 10,
10, 10, 10, 29, 10, 29, 94, 93, 29, 10,
14, 90, 89, 29, 36, 36, 36, 37, 37, 37,
41, 45, 50, 50, 50, 14, 14, 41, 45, 14,
14, 51, 51, 51, 14, 87, 85, 84, 14, 14,
103, 103, 103, 103, 103, 103, 103, 104, 104, 104,
104, 105, 82, 105, 106, 106, 106, 107, 79, 78,
107, 107, 107, 108, 108, 108, 108, 108, 77, 76,
75, 73, 72, 71, 70, 69, 66, 65, 64, 63,
62, 61, 60, 59, 58, 57, 56, 55, 54, 53,
52, 49, 48, 47, 46, 44, 43, 42, 40, 39,
34, 33, 32, 31, 30, 28, 24, 15, 12, 5,
3, 102, 102, 102, 102, 102, 102, 102, 102, 102,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
102, 102, 102, 102, 102, 102, 102, 102, 102, 102,
102, 102, 102, 102
} ;
/* Table of booleans, true if rule could match eol. */
static yyconst flex_int32_t yy_rule_can_match_eol[23] =
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, 1, 0, };
0, 0, 1, 0, };
#define YY_TRAILING_MASK 0x2000
#define YY_TRAILING_HEAD_MASK 0x4000
......@@ -562,7 +579,7 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
yylloc->first_column = yycolumn + 1; \
yycolumn += yyleng; \
} while(0);
#define YY_INPUT(buf, result, maxSize) \
result = readInput(yyextra, buf, maxSize);
......@@ -876,14 +893,14 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 93 )
if ( yy_current_state >= 103 )
yy_c = yy_meta[(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;
}
while ( yy_current_state != 92 );
while ( yy_current_state != 102 );
yy_find_action:
yy_current_state = *--yyg->yy_state_ptr;
......@@ -1009,27 +1026,34 @@ YY_RULE_SETUP
case 17:
YY_RULE_SETUP
{
yylval->tval = new pp::Token(yylineno, IDENTIFIER, std::string(yytext, yyleng));
yylval->sval = new std::string(yytext, yyleng);
return IDENTIFIER;
}
YY_BREAK
case 18:
YY_RULE_SETUP
{
yylval->tval = new pp::Token(yylineno, INTEGER_CONSTANT, std::string(yytext, yyleng));
return INTEGER_CONSTANT;
yylval->sval = new std::string(yytext, yyleng);
return INT_CONSTANT;
}
YY_BREAK
case 19:
YY_RULE_SETUP
{ return yytext[0]; }
{
yylval->sval = new std::string(yytext, yyleng);
return FLOAT_CONSTANT;
}
YY_BREAK
case 20:
YY_RULE_SETUP
{ return SPACE; }
{ return yytext[0]; }
YY_BREAK
case 21:
/* rule 21 can match eol */
YY_RULE_SETUP
{ return SPACE; }
YY_BREAK
case 22:
/* rule 22 can match eol */
YY_RULE_SETUP
{
++yylineno; yycolumn = 0;
......@@ -1039,7 +1063,7 @@ YY_RULE_SETUP
case YY_STATE_EOF(INITIAL):
{ yyterminate(); }
YY_BREAK
case 22:
case 23:
YY_RULE_SETUP
ECHO;
YY_BREAK
......@@ -1304,7 +1328,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 93 )
if ( yy_current_state >= 103 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
......@@ -1328,11 +1352,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 93 )
if ( yy_current_state >= 103 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 92);
yy_is_jam = (yy_current_state == 102);
if ( ! yy_is_jam )
*yyg->yy_state_ptr++ = yy_current_state;
......
......@@ -91,9 +91,9 @@
HASH_VERSION = 272,
HASH_LINE = 273,
SPACE = 274,
IDENTIFIER = 275,
INTEGER_CONSTANT = 276,
FLOAT_CONSTANT = 277
INT_CONSTANT = 275,
FLOAT_CONSTANT = 276,
IDENTIFIER = 277
};
#endif
/* Tokens. */
......@@ -114,9 +114,9 @@
#define HASH_VERSION 272
#define HASH_LINE 273
#define SPACE 274
#define IDENTIFIER 275
#define INTEGER_CONSTANT 276
#define FLOAT_CONSTANT 277
#define INT_CONSTANT 275
#define FLOAT_CONSTANT 276
#define IDENTIFIER 277
......@@ -162,6 +162,8 @@ typedef union YYSTYPE
{
int ival;
std::string* sval;
std::vector<std::string*>* slist;
pp::Token* tval;
pp::TokenVector* tlist;
}
......@@ -198,11 +200,11 @@ static void yyerror(YYLTYPE* llocp,
static void defineMacro(pp::Context* context,
YYLTYPE* llocp,
pp::Macro::Type type,
pp::Token* identifier,
pp::TokenVector* parameters,
const std::string* identifier,
std::vector<std::string*>* parameters,
pp::TokenVector* replacements);
static void undefineMacro(pp::Context* context, pp::Token* identifier);
static bool isMacroDefined(pp::Context* context, pp::Token* identifier);
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 popConditionalBlock(pp::Context* context);
......@@ -495,16 +497,16 @@ static const yytype_int8 yyrhs[] =
{
49, 0, -1, -1, 49, 50, -1, 51, -1, 52,
-1, 23, -1, 57, 23, -1, 3, 23, -1, 4,
20, 53, 23, -1, 5, 20, 24, 56, 25, 53,
23, -1, 6, 20, 23, -1, 7, 54, 23, -1,
8, 20, 23, -1, 9, 20, 23, -1, 11, 54,
22, 53, 23, -1, 5, 22, 24, 56, 25, 53,
23, -1, 6, 22, 23, -1, 7, 54, 23, -1,
8, 22, 23, -1, 9, 22, 23, -1, 11, 54,
23, -1, 10, 23, -1, 12, 23, -1, 14, 23,
-1, 15, 23, -1, 16, 23, -1, 17, 23, -1,
18, 23, -1, -1, 57, -1, 55, -1, 54, 55,
-1, 13, 20, -1, 13, 24, 20, 25, -1, 58,
-1, -1, 20, -1, 56, 26, 20, -1, 58, -1,
57, 58, -1, 20, -1, 21, -1, 22, -1, 19,
-1, 59, -1, 27, -1, 28, -1, 29, -1, 30,
-1, 13, 22, -1, 13, 24, 22, 25, -1, 58,
-1, -1, 22, -1, 56, 26, 22, -1, 58, -1,
57, 58, -1, 59, -1, 19, -1, 20, -1, 21,
-1, 22, -1, 27, -1, 28, -1, 29, -1, 30,
-1, 24, -1, 25, -1, 31, -1, 32, -1, 33,
-1, 34, -1, 35, -1, 36, -1, 37, -1, 38,
-1, 39, -1, 40, -1, 41, -1, 42, -1, 43,
......@@ -515,13 +517,13 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
0, 71, 71, 73, 77, 78, 82, 83, 87, 88,
91, 94, 97, 100, 103, 106, 108, 110, 113, 114,
115, 116, 117, 121, 122, 126, 130, 137, 139, 141,
145, 146, 150, 157, 162, 169, 170, 171, 172, 173,
177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200
0, 74, 74, 76, 80, 86, 90, 91, 95, 96,
99, 102, 105, 108, 111, 114, 116, 118, 121, 122,
123, 124, 125, 129, 130, 134, 138, 145, 147, 149,
153, 154, 158, 165, 169, 176, 179, 182, 185, 188,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
214, 215, 216, 217
};
#endif
......@@ -534,12 +536,12 @@ static const char *const yytname[] =
"HASH_DEFINE_FUNC", "HASH_UNDEF", "HASH_IF", "HASH_IFDEF", "HASH_IFNDEF",
"HASH_ELSE", "HASH_ELIF", "HASH_ENDIF", "DEFINED", "HASH_ERROR",
"HASH_PRAGMA", "HASH_EXTENSION", "HASH_VERSION", "HASH_LINE", "SPACE",
"IDENTIFIER", "INTEGER_CONSTANT", "FLOAT_CONSTANT", "'\\n'", "'('",
"')'", "','", "'['", "']'", "'<'", "'>'", "'{'", "'}'", "'.'", "'+'",
"'-'", "'/'", "'*'", "'%'", "'^'", "'|'", "'&'", "'~'", "'='", "'!'",
"':'", "';'", "'?'", "$accept", "input", "line", "text_line",
"control_line", "replacement_token_list", "conditional_token_list",
"conditional_token", "parameter_list", "token_list", "token", "operator", 0
"INT_CONSTANT", "FLOAT_CONSTANT", "IDENTIFIER", "'\\n'", "'('", "')'",
"','", "'['", "']'", "'<'", "'>'", "'{'", "'}'", "'.'", "'+'", "'-'",
"'/'", "'*'", "'%'", "'^'", "'|'", "'&'", "'~'", "'='", "'!'", "':'",
"';'", "'?'", "$accept", "input", "line", "text_line", "control_line",
"replacement_token_list", "conditional_token_list", "conditional_token",
"parameter_list", "token_list", "token", "operator", 0
};
#endif
......@@ -586,11 +588,11 @@ static const yytype_uint8 yyr2[] =
static const yytype_uint8 yydefact[] =
{
2, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 38, 35,
36, 37, 6, 44, 45, 62, 40, 41, 42, 43,
0, 0, 0, 0, 0, 0, 0, 0, 36, 37,
38, 39, 6, 44, 45, 62, 40, 41, 42, 43,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 63, 3, 4, 5,
0, 33, 39, 8, 23, 0, 0, 0, 0, 25,
0, 33, 35, 8, 23, 0, 0, 0, 0, 25,
29, 0, 0, 16, 0, 17, 18, 19, 20, 21,
22, 7, 34, 0, 24, 30, 11, 27, 0, 12,
26, 13, 14, 15, 9, 31, 0, 0, 23, 0,
......@@ -606,26 +608,26 @@ static const yytype_int8 yydefgoto[] =
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
#define YYPACT_NINF -28
#define YYPACT_NINF -29
static const yytype_int16 yypact[] =
{
-28, 1, -28, -9, 32, 34, 37, 139, 38, 39,
40, 139, 41, 42, 43, 44, 45, 46, -28, -28,
-28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
-28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
-28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
168, -28, -28, -28, 197, 36, 47, 31, 69, -28,
-28, 48, 49, -28, 104, -28, -28, -28, -28, -28,
-28, -28, -28, 51, 197, 55, -28, -28, 56, -28,
-28, -28, -28, -28, -28, -28, -23, 52, 197, 58,
-28, 57, -28, -28
-29, 1, -29, -9, 29, 33, 35, 139, 36, 37,
38, 139, 39, 40, 41, 42, 43, 44, -29, -29,
-29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
-29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
-29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
168, -29, -29, -29, 197, 45, 47, 30, 69, -29,
-29, 48, 49, -29, 104, -29, -29, -29, -29, -29,
-29, -29, -29, 51, 197, 46, -29, -29, 53, -29,
-29, -29, -29, -29, -29, -29, -23, 52, 197, 54,
-29, 55, -29, -29
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
-28, -28, -28, -28, -28, -27, 68, -8, -28, 61,
-1, -28
-29, -29, -29, -29, -29, -28, 68, -8, -29, 79,
-1, -29
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
......@@ -640,10 +642,10 @@ static const yytype_uint8 yytable[] =
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, 72,
80, 77, 54, 51, 55, 78, 80, 56, 61, 62,
75, 91, 50, 63, 65, 66, 67, 68, 69, 70,
76, 81, 82, 72, 84, 85, 87, 90, 92, 64,
93, 0, 57, 0, 0, 0, 0, 51, 18, 19,
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,
......@@ -669,10 +671,10 @@ static const yytype_int8 yycheck[] =
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, 47, 50,
58, 20, 20, 54, 20, 24, 64, 20, 20, 20,
24, 88, 1, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 74, 23, 20, 20, 25, 20, 11,
23, -1, 13, -1, -1, -1, -1, 88, 19, 20,
58, 22, 22, 54, 24, 22, 64, 22, 22, 22,
88, 23, 23, 23, 23, 23, 23, 23, 22, 24,
23, 23, 23, 74, 23, 22, 22, 25, 23, 11,
1, -1, 13, -1, -1, -1, -1, 88, 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, 47, 13, -1, -1,
......@@ -700,11 +702,11 @@ static const yytype_uint8 yystos[] =
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, 47, 50, 51, 52,
57, 58, 59, 23, 20, 20, 20, 13, 54, 55,
58, 20, 20, 23, 54, 23, 23, 23, 23, 23,
23, 23, 58, 53, 57, 24, 23, 20, 24, 23,
55, 23, 23, 23, 23, 20, 56, 20, 25, 26,
25, 53, 20, 23
57, 58, 59, 23, 22, 22, 22, 13, 54, 55,
58, 22, 22, 23, 54, 23, 23, 23, 23, 23,
23, 23, 58, 53, 57, 24, 23, 22, 24, 23,
55, 23, 23, 23, 23, 22, 56, 22, 25, 26,
25, 53, 22, 23
};
#define yyerrok (yyerrstatus = 0)
......@@ -1546,7 +1548,17 @@ yyreduce:
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 6:
case 4:
{
// TODO(alokp): Expand macros.
pp::TokenVector* out = context->output;
out->insert(out->end(), (yyvsp[(1) - (1)].tlist)->begin(), (yyvsp[(1) - (1)].tlist)->end());
delete (yyvsp[(1) - (1)].tlist);
;}
break;
case 6:
{ (yyval.tlist) = NULL; ;}
break;
......@@ -1559,21 +1571,21 @@ yyreduce:
case 9:
{
defineMacro(context, & (yylsp[(2) - (4)]), pp::Macro::kTypeObj, (yyvsp[(2) - (4)].tval), NULL, (yyvsp[(3) - (4)].tlist));
defineMacro(context, & (yylsp[(2) - (4)]), pp::Macro::kTypeObj, (yyvsp[(2) - (4)].sval), NULL, (yyvsp[(3) - (4)].tlist));
;}
break;
case 10:
{
defineMacro(context, & (yylsp[(2) - (7)]), pp::Macro::kTypeFunc, (yyvsp[(2) - (7)].tval), (yyvsp[(4) - (7)].tlist), (yyvsp[(6) - (7)].tlist));
defineMacro(context, & (yylsp[(2) - (7)]), pp::Macro::kTypeFunc, (yyvsp[(2) - (7)].sval), (yyvsp[(4) - (7)].slist), (yyvsp[(6) - (7)].tlist));
;}
break;
case 11:
{
undefineMacro(context, (yyvsp[(2) - (3)].tval));
undefineMacro(context, (yyvsp[(2) - (3)].sval));
;}
break;
......@@ -1587,14 +1599,14 @@ yyreduce:
case 13:
{
pushConditionalBlock(context, isMacroDefined(context, (yyvsp[(2) - (3)].tval)));
pushConditionalBlock(context, isMacroDefined(context, (yyvsp[(2) - (3)].sval)));
;}
break;
case 14:
{
pushConditionalBlock(context, !isMacroDefined(context, (yyvsp[(2) - (3)].tval)));
pushConditionalBlock(context, !isMacroDefined(context, (yyvsp[(2) - (3)].sval)));
;}
break;
......@@ -1652,29 +1664,28 @@ yyreduce:
case 30:
{ (yyval.tlist) = NULL; ;}
{ (yyval.slist) = NULL; ;}
break;
case 31:
{
(yyval.tlist) = new pp::TokenVector;
(yyval.tlist)->push_back((yyvsp[(1) - (1)].tval));
(yyval.slist) = new std::vector<std::string*>();
(yyval.slist)->push_back((yyvsp[(1) - (1)].sval));
;}
break;
case 32:
{
(yyval.tlist) = (yyvsp[(1) - (3)].tlist);
(yyval.tlist)->push_back((yyvsp[(3) - (3)].tval));
(yyval.slist) = (yyvsp[(1) - (3)].slist);
(yyval.slist)->push_back((yyvsp[(3) - (3)].sval));
;}
break;
case 33:
{
//context->ppData.skipWS = false;
(yyval.tlist) = new pp::TokenVector;
(yyval.tlist)->push_back((yyvsp[(1) - (1)].tval));
;}
......@@ -1688,14 +1699,39 @@ yyreduce:
;}
break;
case 35:
{
(yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, (yyvsp[(1) - (1)].ival), NULL);
;}
break;
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));
;}
break;
case 38:
{ (yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, SPACE); ;}
{
(yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, FLOAT_CONSTANT, (yyvsp[(1) - (1)].sval));
;}
break;
case 39:
{ (yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, (yyvsp[(1) - (1)].ival)); ;}
{
(yyval.tval) = new pp::Token((yylsp[(1) - (1)]).first_line, IDENTIFIER, (yyvsp[(1) - (1)].sval));
;}
break;
case 40:
......@@ -2050,17 +2086,17 @@ void yyerror(YYLTYPE* llocp, pp::Context* context, const char* reason)
void defineMacro(pp::Context* context,
YYLTYPE* llocp,
pp::Macro::Type type,
pp::Token* identifier,
pp::TokenVector* parameters,
const std::string* identifier,
std::vector<std::string*>* parameters,
pp::TokenVector* replacements)
{
}
void undefineMacro(pp::Context* context, pp::Token* identifier)
void undefineMacro(pp::Context* context, const std::string* identifier)
{
}
bool isMacroDefined(pp::Context* context, pp::Token* identifier)
bool isMacroDefined(pp::Context* context, const std::string* identifier)
{
return false;
}
......
......@@ -56,9 +56,9 @@
HASH_VERSION = 272,
HASH_LINE = 273,
SPACE = 274,
IDENTIFIER = 275,
INTEGER_CONSTANT = 276,
FLOAT_CONSTANT = 277
INT_CONSTANT = 275,
FLOAT_CONSTANT = 276,
IDENTIFIER = 277
};
#endif
/* Tokens. */
......@@ -79,9 +79,9 @@
#define HASH_VERSION 272
#define HASH_LINE 273
#define SPACE 274
#define IDENTIFIER 275
#define INTEGER_CONSTANT 276
#define FLOAT_CONSTANT 277
#define INT_CONSTANT 275
#define FLOAT_CONSTANT 276
#define IDENTIFIER 277
......@@ -91,6 +91,8 @@ typedef union YYSTYPE
{
int ival;
std::string* sval;
std::vector<std::string*>* slist;
pp::Token* tval;
pp::TokenVector* tlist;
}
......
//
// 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.
//
#ifndef COMPILER_PREPROCESSOR_TOKEN_TYPE_H_
#define COMPILER_PREPROCESSOR_TOKEN_TYPE_H_
#include "pp_tab.h"
#endif // COMPILER_PREPROCESSOR_TOKEN_TYPE_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