Commit 40da4c53 by alokp@chromium.org

Added HAS_LEADING_SPACE flag to pp::Token. Split the new preprocessor into a separate target.

git-svn-id: https://angleproject.googlecode.com/svn/trunk@1032 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent beadd5d2
......@@ -11,8 +11,24 @@
},
'targets': [
{
'target_name': 'preprocessor',
'type': 'static_library',
'include_dirs': [
],
'sources': [
'compiler/preprocessor/new/Input.cpp',
'compiler/preprocessor/new/Input.h',
'compiler/preprocessor/new/Lexer.cpp',
'compiler/preprocessor/new/Lexer.h',
'compiler/preprocessor/new/pp_lex.cpp',
'compiler/preprocessor/new/Token.cpp',
'compiler/preprocessor/new/Token.h',
],
},
{
'target_name': 'translator_common',
'type': 'static_library',
'dependencies': ['preprocessor'],
'include_dirs': [
'.',
'../include',
......@@ -73,14 +89,6 @@
'compiler/ValidateLimitations.h',
'compiler/VariableInfo.cpp',
'compiler/VariableInfo.h',
# New Preprocessor
'compiler/preprocessor/new/Input.cpp',
'compiler/preprocessor/new/Input.h',
'compiler/preprocessor/new/Lexer.cpp',
'compiler/preprocessor/new/Lexer.h',
'compiler/preprocessor/new/pp_lex.cpp',
'compiler/preprocessor/new/Token.cpp',
'compiler/preprocessor/new/Token.h',
# Old preprocessor
'compiler/preprocessor/atom.c',
'compiler/preprocessor/atom.h',
......
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 1031
#define BUILD_REVISION 1032
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -6,10 +6,9 @@
#include "Input.h"
#include <cassert>
#include <cstdio>
#include "compiler/debug.h"
namespace pp
{
......@@ -22,13 +21,13 @@ Input::Input(int count, const char* const string[], const int length[])
mError(kErrorNone),
mState(kStateInitial)
{
ASSERT(mCount >= 0);
assert(mCount >= 0);
switchToNextString();
}
bool Input::eof() const
{
ASSERT(mIndex <= mCount);
assert(mIndex <= mCount);
return mIndex == mCount;
}
......@@ -96,7 +95,7 @@ int Input::read(char* buf, int bufSize)
break;
default:
ASSERT(false);
assert(false);
break;
}
}
......@@ -114,7 +113,7 @@ int Input::getChar()
// Switch to next string if the current one is fully read.
int length = stringLength(mIndex);
// We never read from empty string.
ASSERT(length != 0);
assert(length != 0);
if (((length < 0) && (str[mSize] == '\0')) ||
((length > 0) && (mSize == length)))
switchToNextString();
......@@ -137,7 +136,7 @@ int Input::peekChar()
void Input::switchToNextString()
{
ASSERT(mIndex < mCount);
assert(mIndex < mCount);
mSize = 0;
do
......@@ -148,7 +147,7 @@ void Input::switchToNextString()
bool Input::isStringEmpty(int index)
{
ASSERT(index < mCount);
assert(index < mCount);
const char* str = mString[mIndex];
int length = stringLength(mIndex);
......@@ -157,7 +156,7 @@ bool Input::isStringEmpty(int index)
int Input::stringLength(int index)
{
ASSERT(index < mCount);
assert(index < mCount);
return mLength ? mLength[index] : -1;
}
......
......@@ -8,8 +8,8 @@
#define COMPILER_PREPROCESSOR_LEXER_H_
#include <memory>
#include "common/angleutils.h"
#include "pp_utils.h"
#include "Token.h"
namespace pp
......@@ -28,7 +28,7 @@ class Lexer
int lex(Token* token);
private:
DISALLOW_COPY_AND_ASSIGN(Lexer);
PP_DISALLOW_COPY_AND_ASSIGN(Lexer);
bool initLexer();
void destroyLexer();
......
......@@ -11,6 +11,9 @@ namespace pp
std::ostream& operator<<(std::ostream& out, const Token& token)
{
if (token.hasLeadingSpace())
out << " ";
out << token.value;
return out;
}
......
......@@ -43,13 +43,43 @@ struct Token
OP_XOR_ASSIGN,
OP_OR_ASSIGN
};
enum Flags
{
HAS_LEADING_SPACE = 1 << 0
};
struct Location
{
Location() : line(0), string(0) { }
bool equals(const Location& other) const
{
return (line == other.line) && (string == other.string);
}
int line;
int string;
};
Token() : type(0), flags(0) { }
bool equals(const Token& other) const
{
return (type == other.type) &&
(flags == other.flags) &&
(location.equals(other.location)) &&
(value == other.value);
}
bool hasLeadingSpace() const { return (flags & HAS_LEADING_SPACE) != 0; }
void setHasLeadingSpace(bool space)
{
if (space)
flags |= HAS_LEADING_SPACE;
else
flags &= ~HAS_LEADING_SPACE;
}
int type;
int flags;
Location location;
std::string value;
};
......
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// pp_utils.h: Common preprocessor utilities
#ifndef COMPILER_PREPROCESSOR_PPUTILS_H_
#define COMPILER_PREPROCESSOR_PPUTILS_H_
// A macro to disallow the copy constructor and operator= functions
// This must be used in the private: declarations for a class.
#define PP_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
#endif // COMPILER_PREPROCESSOR_PPUTILS_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