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