Commit d39ec4c1 by alokp@chromium.org

Implemented conditional processing.

Review URL: https://codereview.appspot.com/6333046 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1168 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 8b8f02dc
...@@ -36,6 +36,7 @@ class Diagnostics ...@@ -36,6 +36,7 @@ class Diagnostics
EOF_IN_COMMENT, EOF_IN_COMMENT,
EOF_IN_DIRECTIVE, EOF_IN_DIRECTIVE,
UNEXPECTED_TOKEN, UNEXPECTED_TOKEN,
DIRECTIVE_INVALID_NAME,
MACRO_NAME_RESERVED, MACRO_NAME_RESERVED,
MACRO_REDEFINED, MACRO_REDEFINED,
MACRO_PREDEFINED_REDEFINED, MACRO_PREDEFINED_REDEFINED,
...@@ -43,6 +44,12 @@ class Diagnostics ...@@ -43,6 +44,12 @@ class Diagnostics
MACRO_UNTERMINATED_INVOCATION, MACRO_UNTERMINATED_INVOCATION,
MACRO_TOO_FEW_ARGS, MACRO_TOO_FEW_ARGS,
MACRO_TOO_MANY_ARGS, MACRO_TOO_MANY_ARGS,
CONDITIONAL_ENDIF_WITHOUT_IF,
CONDITIONAL_ELSE_WITHOUT_IF,
CONDITIONAL_ELSE_AFTER_ELSE,
CONDITIONAL_ELIF_WITHOUT_IF,
CONDITIONAL_ELIF_AFTER_ELSE,
CONDITIONAL_UNTERMINATED,
INVALID_EXTENSION_NAME, INVALID_EXTENSION_NAME,
INVALID_EXTENSION_BEHAVIOR, INVALID_EXTENSION_BEHAVIOR,
INVALID_EXTENSION_DIRECTIVE, INVALID_EXTENSION_DIRECTIVE,
...@@ -54,6 +61,7 @@ class Diagnostics ...@@ -54,6 +61,7 @@ class Diagnostics
ERROR_END, ERROR_END,
WARNING_BEGIN, WARNING_BEGIN,
CONDITIONAL_UNEXPECTED_TOKEN,
UNRECOGNIZED_PRAGMA, UNRECOGNIZED_PRAGMA,
WARNING_END WARNING_END
}; };
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "Lexer.h" #include "Lexer.h"
#include "Macro.h" #include "Macro.h"
#include "pp_utils.h" #include "pp_utils.h"
#include "SourceLocation.h"
namespace pp namespace pp
{ {
...@@ -46,6 +47,29 @@ class DirectiveParser : public Lexer ...@@ -46,6 +47,29 @@ class DirectiveParser : public Lexer
void parseVersion(Token* token); void parseVersion(Token* token);
void parseLine(Token* token); void parseLine(Token* token);
bool skipping() const;
void parseConditionalIf(Token* token);
int parseExpressionIf(Token* token);
int parseExpressionIfdef(Token* token);
struct ConditionalBlock
{
std::string type;
SourceLocation location;
bool skipBlock;
bool skipGroup;
bool foundValidGroup;
bool foundElseGroup;
ConditionalBlock() :
skipBlock(false),
skipGroup(false),
foundValidGroup(false),
foundElseGroup(false)
{
}
};
std::vector<ConditionalBlock> mConditionalStack;
Tokenizer* mTokenizer; Tokenizer* mTokenizer;
MacroSet* mMacroSet; MacroSet* mMacroSet;
Diagnostics* mDiagnostics; Diagnostics* mDiagnostics;
......
...@@ -91,12 +91,23 @@ ...@@ -91,12 +91,23 @@
#include "ExpressionParser.h" #include "ExpressionParser.h"
#include <cassert> #include <cassert>
#include <cstdlib>
#include <sstream> #include <sstream>
#include "Diagnostics.h" #include "Diagnostics.h"
#include "Lexer.h" #include "Lexer.h"
#include "Token.h" #include "Token.h"
#if defined(_MSC_VER)
typedef __int64 YYSTYPE;
#define strtoll _strtoi64
#else
#include <stdint.h>
typedef intmax_t YYSTYPE;
#endif // _MSC_VER
#define YYSTYPE_IS_TRIVIAL 1
#define YYSTYPE_IS_DECLARED 1
namespace { namespace {
struct Context struct Context
{ {
...@@ -108,7 +119,7 @@ struct Context ...@@ -108,7 +119,7 @@ struct Context
} // namespace } // namespace
static int yylex(int* lvalp, Context* context); static int yylex(YYSTYPE* lvalp, Context* context);
static void yyerror(Context* context, const char* reason); static void yyerror(Context* context, const char* reason);
...@@ -456,9 +467,9 @@ static const yytype_int8 yyrhs[] = ...@@ -456,9 +467,9 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] = static const yytype_uint8 yyrline[] =
{ {
0, 74, 74, 81, 82, 85, 88, 91, 94, 97, 0, 85, 85, 92, 93, 96, 99, 102, 105, 108,
100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138,
140, 153, 156, 159, 162, 165, 168 151, 164, 167, 170, 173, 176, 179
}; };
#endif #endif
...@@ -1425,7 +1436,7 @@ yyreduce: ...@@ -1425,7 +1436,7 @@ yyreduce:
case 2: case 2:
{ {
*(context->result) = (yyvsp[(1) - (1)]); *(context->result) = static_cast<int>((yyvsp[(1) - (1)]));
YYACCEPT; YYACCEPT;
} }
break; break;
...@@ -1825,7 +1836,7 @@ yyreturn: ...@@ -1825,7 +1836,7 @@ yyreturn:
int yylex(int* lvalp, Context* context) int yylex(YYSTYPE* lvalp, Context* context)
{ {
int type = 0; int type = 0;
...@@ -1833,7 +1844,7 @@ int yylex(int* lvalp, Context* context) ...@@ -1833,7 +1844,7 @@ int yylex(int* lvalp, Context* context)
switch (token->type) switch (token->type)
{ {
case pp::Token::CONST_INT: case pp::Token::CONST_INT:
*lvalp = atoi(token->value.c_str()); *lvalp = strtoll(token->value.c_str(), NULL, 0);
type = CONST_INT; type = CONST_INT;
break; break;
......
...@@ -28,12 +28,23 @@ WHICH GENERATES THE GLSL ES preprocessor expression parser. ...@@ -28,12 +28,23 @@ WHICH GENERATES THE GLSL ES preprocessor expression parser.
#include "ExpressionParser.h" #include "ExpressionParser.h"
#include <cassert> #include <cassert>
#include <cstdlib>
#include <sstream> #include <sstream>
#include "Diagnostics.h" #include "Diagnostics.h"
#include "Lexer.h" #include "Lexer.h"
#include "Token.h" #include "Token.h"
#if defined(_MSC_VER)
typedef __int64 YYSTYPE;
#define strtoll _strtoi64
#else
#include <stdint.h>
typedef intmax_t YYSTYPE;
#endif // _MSC_VER
#define YYSTYPE_IS_TRIVIAL 1
#define YYSTYPE_IS_DECLARED 1
namespace { namespace {
struct Context struct Context
{ {
...@@ -51,7 +62,7 @@ struct Context ...@@ -51,7 +62,7 @@ struct Context
%lex-param {Context *context} %lex-param {Context *context}
%{ %{
static int yylex(int* lvalp, Context* context); static int yylex(YYSTYPE* lvalp, Context* context);
static void yyerror(Context* context, const char* reason); static void yyerror(Context* context, const char* reason);
%} %}
...@@ -72,7 +83,7 @@ static void yyerror(Context* context, const char* reason); ...@@ -72,7 +83,7 @@ static void yyerror(Context* context, const char* reason);
input input
: expression { : expression {
*(context->result) = $1; *(context->result) = static_cast<int>($1);
YYACCEPT; YYACCEPT;
} }
; ;
...@@ -172,7 +183,7 @@ expression ...@@ -172,7 +183,7 @@ expression
%% %%
int yylex(int* lvalp, Context* context) int yylex(YYSTYPE* lvalp, Context* context)
{ {
int type = 0; int type = 0;
...@@ -180,7 +191,7 @@ int yylex(int* lvalp, Context* context) ...@@ -180,7 +191,7 @@ int yylex(int* lvalp, Context* context)
switch (token->type) switch (token->type)
{ {
case pp::Token::CONST_INT: case pp::Token::CONST_INT:
*lvalp = atoi(token->value.c_str()); *lvalp = strtoll(token->value.c_str(), NULL, 0);
type = CONST_INT; type = CONST_INT;
break; break;
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
'preprocessor_tests/error_test.cpp', 'preprocessor_tests/error_test.cpp',
'preprocessor_tests/extension_test.cpp', 'preprocessor_tests/extension_test.cpp',
'preprocessor_tests/identifier_test.cpp', 'preprocessor_tests/identifier_test.cpp',
'preprocessor_tests/if_test.cpp',
'preprocessor_tests/input_test.cpp', 'preprocessor_tests/input_test.cpp',
'preprocessor_tests/location_test.cpp', 'preprocessor_tests/location_test.cpp',
'preprocessor_tests/MockDiagnostics.h', 'preprocessor_tests/MockDiagnostics.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