Commit 30a487c7 by alokp@chromium.org

Minor refactoring for Input class. Chnaged a raw array to std::vector.

git-svn-id: https://angleproject.googlecode.com/svn/trunk@1068 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 519c32ba
...@@ -12,30 +12,23 @@ ...@@ -12,30 +12,23 @@
namespace pp namespace pp
{ {
Input::Input() : mCount(0), mString(0), mLength(0) Input::Input() : mCount(0), mString(0)
{ {
} }
Input::Input(int count, const char* const string[], const int length[]) : Input::Input(int count, const char* const string[], const int length[]) :
mCount(count), mCount(count),
mString(string), mString(string)
mLength(0)
{ {
assert(mCount >= 0); assert(mCount >= 0);
mLength = mCount > 0 ? new int[mCount] : 0; mLength.reserve(mCount);
for (int i = 0; i < mCount; ++i) for (int i = 0; i < mCount; ++i)
{ {
mLength[i] = length ? length[i] : -1; int len = length ? length[i] : -1;
if (mLength[i] < 0) mLength.push_back(len < 0 ? strlen(mString[i]) : len);
mLength[i] = strlen(mString[i]);
} }
} }
Input::~Input()
{
if (mLength) delete [] mLength;
}
int Input::read(char* buf, int maxSize) int Input::read(char* buf, int maxSize)
{ {
int nRead = 0; int nRead = 0;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMPILER_PREPROCESSOR_INPUT_H_ #ifndef COMPILER_PREPROCESSOR_INPUT_H_
#define COMPILER_PREPROCESSOR_INPUT_H_ #define COMPILER_PREPROCESSOR_INPUT_H_
#include "pp_utils.h" #include <vector>
namespace pp namespace pp
{ {
...@@ -18,7 +18,6 @@ class Input ...@@ -18,7 +18,6 @@ class Input
public: public:
Input(); Input();
Input(int count, const char* const string[], const int length[]); Input(int count, const char* const string[], const int length[]);
~Input();
int count() const { return mCount; } int count() const { return mCount; }
const char* string(int index) const { return mString[index]; } const char* string(int index) const { return mString[index]; }
...@@ -36,12 +35,10 @@ class Input ...@@ -36,12 +35,10 @@ class Input
const Location& readLoc() const { return mReadLoc; } const Location& readLoc() const { return mReadLoc; }
private: private:
PP_DISALLOW_COPY_AND_ASSIGN(Input);
// Input. // Input.
int mCount; int mCount;
const char* const* mString; const char* const* mString;
int* mLength; std::vector<int> mLength;
Location mReadLoc; Location mReadLoc;
}; };
......
...@@ -25,7 +25,7 @@ bool Lexer::init(int count, const char* const string[], const int length[]) ...@@ -25,7 +25,7 @@ bool Lexer::init(int count, const char* const string[], const int length[])
if (count < 0) return false; if (count < 0) return false;
if ((count > 0) && (string == 0)) return false; if ((count > 0) && (string == 0)) return false;
mContext.input.reset(new Input(count, string, length)); mContext.input = Input(count, string, length);
return initLexer(); return initLexer();
} }
......
...@@ -22,7 +22,7 @@ class Lexer ...@@ -22,7 +22,7 @@ class Lexer
public: public:
struct Context struct Context
{ {
std::auto_ptr<Input> input; Input input;
// The location where yytext points to. Token location should track // The location where yytext points to. Token location should track
// scanLoc instead of Input::mReadLoc because they may not be the same // scanLoc instead of Input::mReadLoc because they may not be the same
// if text is buffered up in the lexer input buffer. // if text is buffered up in the lexer input buffer.
......
...@@ -40,7 +40,7 @@ typedef pp::Token::Location YYLTYPE; ...@@ -40,7 +40,7 @@ typedef pp::Token::Location YYLTYPE;
#define YY_USER_ACTION \ #define YY_USER_ACTION \
do { \ do { \
pp::Input* input = yyextra->input.get(); \ pp::Input* input = &yyextra->input; \
pp::Input::Location* scanLoc = &yyextra->scanLoc; \ pp::Input::Location* scanLoc = &yyextra->scanLoc; \
while (scanLoc->cIndex >= input->length(scanLoc->sIndex)) \ while (scanLoc->cIndex >= input->length(scanLoc->sIndex)) \
{ \ { \
...@@ -53,7 +53,7 @@ typedef pp::Token::Location YYLTYPE; ...@@ -53,7 +53,7 @@ typedef pp::Token::Location YYLTYPE;
} while(0); } while(0);
#define YY_INPUT(buf, result, maxSize) \ #define YY_INPUT(buf, result, maxSize) \
result = yyextra->input->read(buf, maxSize); result = yyextra->input.read(buf, maxSize);
%} %}
......
...@@ -531,7 +531,7 @@ typedef pp::Token::Location YYLTYPE; ...@@ -531,7 +531,7 @@ typedef pp::Token::Location YYLTYPE;
#define YY_USER_ACTION \ #define YY_USER_ACTION \
do { \ do { \
pp::Input* input = yyextra->input.get(); \ pp::Input* input = &yyextra->input; \
pp::Input::Location* scanLoc = &yyextra->scanLoc; \ pp::Input::Location* scanLoc = &yyextra->scanLoc; \
while (scanLoc->cIndex >= input->length(scanLoc->sIndex)) \ while (scanLoc->cIndex >= input->length(scanLoc->sIndex)) \
{ \ { \
...@@ -544,7 +544,7 @@ typedef pp::Token::Location YYLTYPE; ...@@ -544,7 +544,7 @@ typedef pp::Token::Location YYLTYPE;
} while(0); } while(0);
#define YY_INPUT(buf, result, maxSize) \ #define YY_INPUT(buf, result, maxSize) \
result = yyextra->input->read(buf, maxSize); result = yyextra->input.read(buf, maxSize);
#define INITIAL 0 #define INITIAL 0
#define COMMENT 1 #define COMMENT 1
......
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