Commit d74fd20f authored by marja@chromium.org's avatar marja@chromium.org

Traitify ParserBase and move functions there.

(Second try, with fixes. First try: https://codereview.chromium.org/149913006/ )

The long-term goal is to move all recursive descent functions from Parser and
PreParser into ParserBase, but first they need to be unified.

Notes:
- The functions moved in this CL: ParseIdentifier, ParseIdentifierName,
ParseIdentifierNameOrGetOrSet, ParseIdentifierOrStrictReservedWord.
- IOW, this CL removes Parser::ParseIdentifier and PreParser::ParseIdentifier
and adds ParserBase::ParseIdentifier, etc.
- Error reporting used to require virtual funcs; now error reporting is moved to
the Traits too, and ParserBase no longer needs to be virtual.
- I had to move PreParser::Identifier out of the PreParser class, because
otherwise PreParserTraits cannot use it in a typedef.

BUG=v8:3126
LOG=N
R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/158913003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19265 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1f7feb96
This diff is collapsed.
......@@ -404,10 +404,44 @@ class RegExpParser BASE_EMBEDDED {
// ----------------------------------------------------------------------------
// JAVASCRIPT PARSING
// Forward declaration.
class Parser;
class SingletonLogger;
class Parser : public ParserBase {
class ParserTraits {
public:
typedef Parser* ParserType;
// Return types for traversing functions.
typedef Handle<String> IdentifierType;
explicit ParserTraits(Parser* parser) : parser_(parser) {}
// Helper functions for recursive descent.
bool is_classic_mode() const;
bool is_generator() const;
bool IsEvalOrArguments(Handle<String> identifier) const;
// Reporting errors.
void ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<const char*> args);
void ReportMessage(const char* message, Vector<Handle<String> > args);
void ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<Handle<String> > args);
// Identifiers:
static IdentifierType EmptyIdentifier() {
return Handle<String>();
}
IdentifierType GetSymbol();
private:
Parser* parser_;
};
class Parser : public ParserBase<ParserTraits> {
public:
explicit Parser(CompilationInfo* info);
~Parser() {
......@@ -427,6 +461,8 @@ class Parser : public ParserBase {
bool Parse();
private:
friend class ParserTraits;
static const int kMaxNumFunctionLocals = 131071; // 2^17-1
enum Mode {
......@@ -521,10 +557,6 @@ class Parser : public ParserBase {
Mode old_mode_;
};
virtual bool is_classic_mode() {
return top_scope_->is_classic_mode();
}
// Returns NULL if parsing failed.
FunctionLiteral* ParseProgram();
......@@ -541,17 +573,6 @@ class Parser : public ParserBase {
// Report syntax error
void ReportInvalidPreparseData(Handle<String> name, bool* ok);
void ReportMessage(const char* message, Vector<const char*> args);
void ReportMessage(const char* message, Vector<Handle<String> > args);
void ReportMessageAt(Scanner::Location location, const char* type) {
ReportMessageAt(location, type, Vector<const char*>::empty());
}
void ReportMessageAt(Scanner::Location loc,
const char* message,
Vector<const char*> args);
void ReportMessageAt(Scanner::Location loc,
const char* message,
Vector<Handle<String> > args);
void set_pre_parse_data(ScriptDataImpl *data) {
pre_parse_data_ = data;
......@@ -571,9 +592,6 @@ class Parser : public ParserBase {
? top_scope_ : top_scope_->DeclarationScope();
}
// Check if the given string is 'eval' or 'arguments'.
bool IsEvalOrArguments(Handle<String> string);
// All ParseXXX functions take as the last argument an *ok parameter
// which is set to false if parsing failed; it is unchanged otherwise.
// By making the 'exception handling' explicit, we are forced to check
......@@ -660,8 +678,6 @@ class Parser : public ParserBase {
// Magical syntax support.
Expression* ParseV8Intrinsic(bool* ok);
bool is_generator() const { return current_function_state_->is_generator(); }
bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
Handle<String> LiteralString(PretenureFlag tenured) {
......@@ -684,20 +700,10 @@ class Parser : public ParserBase {
}
}
Handle<String> GetSymbol();
// Get odd-ball literals.
Literal* GetLiteralUndefined(int position);
Literal* GetLiteralTheHole(int position);
Handle<String> ParseIdentifier(AllowEvalOrArgumentsAsIdentifier, bool* ok);
Handle<String> ParseIdentifierOrStrictReservedWord(
bool* is_strict_reserved, bool* ok);
Handle<String> ParseIdentifierName(bool* ok);
Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get,
bool* is_set,
bool* ok);
// Determine if the expression is a variable proxy and mark it as being used
// in an assignment or with a increment/decrement operator. This is currently
// used on for the statically checking assignments to harmony const bindings.
......
This diff is collapsed.
This diff is collapsed.
......@@ -1108,8 +1108,9 @@ enum ParserSyncTestResult {
kError
};
void SetParserFlags(i::ParserBase* parser, i::EnumSet<ParserFlag> flags) {
template <typename Traits>
void SetParserFlags(i::ParserBase<Traits>* parser,
i::EnumSet<ParserFlag> flags) {
parser->set_allow_lazy(flags.Contains(kAllowLazy));
parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
......
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