Commit 14e966b2 by alokp@chromium.org

Modified the interface of Preprocessor. Added it to the build file. Lexer…

Modified the interface of Preprocessor. Added it to the build file. Lexer changes to record leading space. git-svn-id: https://angleproject.googlecode.com/svn/trunk@1033 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 40da4c53
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
'compiler/preprocessor/new/Lexer.cpp', 'compiler/preprocessor/new/Lexer.cpp',
'compiler/preprocessor/new/Lexer.h', 'compiler/preprocessor/new/Lexer.h',
'compiler/preprocessor/new/pp_lex.cpp', 'compiler/preprocessor/new/pp_lex.cpp',
'compiler/preprocessor/new/Preprocessor.cpp',
'compiler/preprocessor/new/Preprocessor.h',
'compiler/preprocessor/new/Token.cpp', 'compiler/preprocessor/new/Token.cpp',
'compiler/preprocessor/new/Token.h', 'compiler/preprocessor/new/Token.h',
], ],
......
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1032 #define BUILD_REVISION 1033
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
#include "Lexer.h" #include "Lexer.h"
#include <cassert>
#include "Input.h" #include "Input.h"
namespace pp namespace pp
{ {
Lexer::Lexer() : mHandle(0) Lexer::Lexer() : mHandle(0), mLeadingSpace(false)
{ {
} }
...@@ -22,6 +24,10 @@ Lexer::~Lexer() ...@@ -22,6 +24,10 @@ Lexer::~Lexer()
bool Lexer::init(int count, const char* const string[], const int length[]) bool Lexer::init(int count, const char* const string[], const int length[])
{ {
assert((count >=0) && (string != NULL));
if ((count < 0) || (string == NULL))
return false;
mInput.reset(new Input(count, string, length)); mInput.reset(new Input(count, string, length));
return initLexer(); return initLexer();
} }
......
...@@ -33,6 +33,7 @@ class Lexer ...@@ -33,6 +33,7 @@ class Lexer
void destroyLexer(); void destroyLexer();
void* mHandle; // Lexer handle. void* mHandle; // Lexer handle.
bool mLeadingSpace;
std::auto_ptr<Input> mInput; // Input buffer. std::auto_ptr<Input> mInput; // Input buffer.
}; };
......
...@@ -6,41 +6,19 @@ ...@@ -6,41 +6,19 @@
#include "Preprocessor.h" #include "Preprocessor.h"
#include <algorithm>
#include "compiler/debug.h"
#include "Context.h"
#include "stl_utils.h"
namespace pp namespace pp
{ {
Preprocessor::Preprocessor() : mContext(new Context) bool Preprocessor::init(int count,
{ const char* const string[],
} const int length[])
Preprocessor::~Preprocessor()
{
delete mContext;
}
bool Preprocessor::process(int count,
const char* const string[],
const int length[])
{ {
ASSERT((count >=0) && (string != NULL)); return mLexer.init(count, string, length);
if ((count < 0) || (string == NULL))
return false;
reset();
return mContext->process(count, string, length, &mTokens);
} }
void Preprocessor::reset() int Preprocessor::lex(Token* token)
{ {
std::for_each(mTokens.begin(), mTokens.end(), Delete()); return mLexer.lex(token);
mTokens.clear();
} }
} // namespace pp } // namespace pp
......
...@@ -7,32 +7,24 @@ ...@@ -7,32 +7,24 @@
#ifndef COMPILER_PREPROCESSOR_PREPROCESSOR_H_ #ifndef COMPILER_PREPROCESSOR_PREPROCESSOR_H_
#define COMPILER_PREPROCESSOR_PREPROCESSOR_H_ #define COMPILER_PREPROCESSOR_PREPROCESSOR_H_
#include "common/angleutils.h" #include "Lexer.h"
#include "pp_utils.h"
#include "Token.h" #include "Token.h"
namespace pp namespace pp
{ {
class Context;
class Preprocessor class Preprocessor
{ {
public: public:
Preprocessor(); Preprocessor() { }
~Preprocessor();
bool process(int count, const char* const string[], const int length[]); bool init(int count, const char* const string[], const int length[]);
TokenIterator begin() const { return mTokens.begin(); } int lex(Token* token);
TokenIterator end() const { return mTokens.end(); }
private: private:
DISALLOW_COPY_AND_ASSIGN(Preprocessor); PP_DISALLOW_COPY_AND_ASSIGN(Preprocessor);
Lexer mLexer;
// Reset to initialized state.
void reset();
Context* mContext;
TokenVector mTokens; // Output.
}; };
} // namespace pp } // namespace pp
......
...@@ -101,7 +101,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".") ...@@ -101,7 +101,7 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
"|=" { return pp::Token::OP_OR_ASSIGN; } "|=" { return pp::Token::OP_OR_ASSIGN; }
{PUNCTUATOR} { return yytext[0]; } {PUNCTUATOR} { return yytext[0]; }
[ \t\v\f]+ { /* Ignore whitespace */ } [ \t\v\f]+ { return ' '; }
\n { return yytext[0]; } \n { return yytext[0]; }
<*><<EOF>> { yyterminate(); } <*><<EOF>> { yyterminate(); }
...@@ -126,6 +126,14 @@ namespace pp { ...@@ -126,6 +126,14 @@ namespace pp {
int Lexer::lex(Token* token) int Lexer::lex(Token* token)
{ {
token->type = yylex(&token->value, &token->location, mHandle); token->type = yylex(&token->value, &token->location, mHandle);
while (token->type == ' ')
{
mLeadingSpace = true;
token->type = yylex(&token->value, &token->location, mHandle);
}
token->setHasLeadingSpace(mLeadingSpace);
mLeadingSpace = false;
return token->type; return token->type;
} }
......
...@@ -969,7 +969,7 @@ YY_RULE_SETUP ...@@ -969,7 +969,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
{ /* Ignore whitespace */ } { return ' '; }
YY_BREAK YY_BREAK
case 28: case 28:
/* rule 28 can match eol */ /* rule 28 can match eol */
...@@ -2143,6 +2143,14 @@ namespace pp { ...@@ -2143,6 +2143,14 @@ namespace pp {
int Lexer::lex(Token* token) int Lexer::lex(Token* token)
{ {
token->type = pplex(&token->value,&token->location,mHandle); token->type = pplex(&token->value,&token->location,mHandle);
while (token->type == ' ')
{
mLeadingSpace = true;
token->type = pplex(&token->value,&token->location,mHandle);
}
token->setHasLeadingSpace(mLeadingSpace);
mLeadingSpace = false;
return token->type; return token->type;
} }
......
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