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
EOF_IN_COMMENT,
EOF_IN_DIRECTIVE,
UNEXPECTED_TOKEN,
DIRECTIVE_INVALID_NAME,
MACRO_NAME_RESERVED,
MACRO_REDEFINED,
MACRO_PREDEFINED_REDEFINED,
......@@ -43,6 +44,12 @@ class Diagnostics
MACRO_UNTERMINATED_INVOCATION,
MACRO_TOO_FEW_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_BEHAVIOR,
INVALID_EXTENSION_DIRECTIVE,
......@@ -54,6 +61,7 @@ class Diagnostics
ERROR_END,
WARNING_BEGIN,
CONDITIONAL_UNEXPECTED_TOKEN,
UNRECOGNIZED_PRAGMA,
WARNING_END
};
......
......@@ -10,6 +10,7 @@
#include "Lexer.h"
#include "Macro.h"
#include "pp_utils.h"
#include "SourceLocation.h"
namespace pp
{
......@@ -46,6 +47,29 @@ class DirectiveParser : public Lexer
void parseVersion(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;
MacroSet* mMacroSet;
Diagnostics* mDiagnostics;
......
......@@ -91,12 +91,23 @@
#include "ExpressionParser.h"
#include <cassert>
#include <cstdlib>
#include <sstream>
#include "Diagnostics.h"
#include "Lexer.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 {
struct Context
{
......@@ -108,7 +119,7 @@ struct Context
} // namespace
static int yylex(int* lvalp, Context* context);
static int yylex(YYSTYPE* lvalp, Context* context);
static void yyerror(Context* context, const char* reason);
......@@ -456,9 +467,9 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
0, 74, 74, 81, 82, 85, 88, 91, 94, 97,
100, 103, 106, 109, 112, 115, 118, 121, 124, 127,
140, 153, 156, 159, 162, 165, 168
0, 85, 85, 92, 93, 96, 99, 102, 105, 108,
111, 114, 117, 120, 123, 126, 129, 132, 135, 138,
151, 164, 167, 170, 173, 176, 179
};
#endif
......@@ -1425,7 +1436,7 @@ yyreduce:
case 2:
{
*(context->result) = (yyvsp[(1) - (1)]);
*(context->result) = static_cast<int>((yyvsp[(1) - (1)]));
YYACCEPT;
}
break;
......@@ -1825,7 +1836,7 @@ yyreturn:
int yylex(int* lvalp, Context* context)
int yylex(YYSTYPE* lvalp, Context* context)
{
int type = 0;
......@@ -1833,7 +1844,7 @@ int yylex(int* lvalp, Context* context)
switch (token->type)
{
case pp::Token::CONST_INT:
*lvalp = atoi(token->value.c_str());
*lvalp = strtoll(token->value.c_str(), NULL, 0);
type = CONST_INT;
break;
......
......@@ -28,12 +28,23 @@ WHICH GENERATES THE GLSL ES preprocessor expression parser.
#include "ExpressionParser.h"
#include <cassert>
#include <cstdlib>
#include <sstream>
#include "Diagnostics.h"
#include "Lexer.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 {
struct Context
{
......@@ -51,7 +62,7 @@ struct 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);
%}
......@@ -72,7 +83,7 @@ static void yyerror(Context* context, const char* reason);
input
: expression {
*(context->result) = $1;
*(context->result) = static_cast<int>($1);
YYACCEPT;
}
;
......@@ -172,7 +183,7 @@ expression
%%
int yylex(int* lvalp, Context* context)
int yylex(YYSTYPE* lvalp, Context* context)
{
int type = 0;
......@@ -180,7 +191,7 @@ int yylex(int* lvalp, Context* context)
switch (token->type)
{
case pp::Token::CONST_INT:
*lvalp = atoi(token->value.c_str());
*lvalp = strtoll(token->value.c_str(), NULL, 0);
type = CONST_INT;
break;
......
......@@ -48,6 +48,7 @@
'preprocessor_tests/error_test.cpp',
'preprocessor_tests/extension_test.cpp',
'preprocessor_tests/identifier_test.cpp',
'preprocessor_tests/if_test.cpp',
'preprocessor_tests/input_test.cpp',
'preprocessor_tests/location_test.cpp',
'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