Revision: 23266
Author: [email protected]
Date: Thu Aug 21 09:22:08 2014 UTC
Log: Refactor parser Checkpoints.
Why this is better:
1) Not needing an extra template parameter for Checkpoints ctors. This was
especially confusing since the template parameter was named Parser and
Parser is
also used as a type name and is also a concrete type. This CL makes it clear
that ParserTraits::Checkpoint is consturcted with ParserBase<ParserTraits> -
that's the only sensemaking type for the ctor param anyway.
2) This CL makes ParserBase define a Checkpoint base class (which knows how
to create and restore a checkpoint with ParserBase) which
PreParserTraits::Checkpoint and ParserTraits::Checkpoint inherit, and not
the
other way around.
This is a more intuitive way to implement the "base functionality +
extending
it" concept than the previous solution. The previous solution was to allow
Traits to define a Checkpoint class and make
ParserBase<Traits>::ParserCheckpoint
(which defines the base functionality) inherit from it.
3) This CL moves the Checkpoint class definitions out of the
SomeTraits::Type
struct; SomeTraits::Type is supposed to be a collection of typedefs and not
contain anything else.
Checkpoints were introduced in r22925 (
https://codereview.chromium.org/443903003 ).
BUG=
[email protected]
Review URL: https://codereview.chromium.org/485473004
http://code.google.com/p/v8/source/detail?r=23266
Modified:
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/src/parser.h
/branches/bleeding_edge/src/preparser.cc
/branches/bleeding_edge/src/preparser.h
=======================================
--- /branches/bleeding_edge/src/parser.cc Tue Aug 19 15:42:47 2014 UTC
+++ /branches/bleeding_edge/src/parser.cc Thu Aug 21 09:22:08 2014 UTC
@@ -341,6 +341,26 @@
//
----------------------------------------------------------------------------
// Implementation of Parser
+class ParserTraits::Checkpoint
+ : public ParserBase<ParserTraits>::CheckpointBase {
+ public:
+ explicit Checkpoint(ParserBase<ParserTraits>* parser)
+ : CheckpointBase(parser) {
+ isolate_ = parser->zone()->isolate();
+ saved_ast_node_id_ = isolate_->ast_node_id();
+ }
+
+ void Restore() {
+ CheckpointBase::Restore();
+ isolate_->set_ast_node_id(saved_ast_node_id_);
+ }
+
+ private:
+ Isolate* isolate_;
+ int saved_ast_node_id_;
+};
+
+
bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const
{
return identifier == parser_->ast_value_factory_->eval_string() ||
identifier == parser_->ast_value_factory_->arguments_string();
=======================================
--- /branches/bleeding_edge/src/parser.h Wed Aug 20 15:51:07 2014 UTC
+++ /branches/bleeding_edge/src/parser.h Thu Aug 21 09:22:08 2014 UTC
@@ -355,21 +355,6 @@
typedef Variable GeneratorVariable;
typedef v8::internal::Zone Zone;
- class Checkpoint BASE_EMBEDDED {
- public:
- template <typename Parser>
- explicit Checkpoint(Parser* parser) {
- isolate_ = parser->zone()->isolate();
- saved_ast_node_id_ = isolate_->ast_node_id();
- }
-
- void Restore() { isolate_->set_ast_node_id(saved_ast_node_id_); }
-
- private:
- Isolate* isolate_;
- int saved_ast_node_id_;
- };
-
typedef v8::internal::AstProperties AstProperties;
typedef Vector<VariableProxy*> ParameterIdentifierVector;
@@ -388,6 +373,8 @@
typedef AstNodeFactory<AstConstructionVisitor> Factory;
};
+ class Checkpoint;
+
explicit ParserTraits(Parser* parser) : parser_(parser) {}
// Custom operations executed when FunctionStates are created and
destructed.
=======================================
--- /branches/bleeding_edge/src/preparser.cc Thu Aug 7 16:42:14 2014 UTC
+++ /branches/bleeding_edge/src/preparser.cc Thu Aug 21 09:22:08 2014 UTC
@@ -32,6 +32,12 @@
namespace v8 {
namespace internal {
+class PreParserTraits::Checkpoint
+ : public ParserBase<PreParserTraits>::CheckpointBase {
+ public:
+ explicit Checkpoint(ParserBase<PreParserTraits>* parser)
+ : ParserBase<PreParserTraits>::CheckpointBase(parser) {}
+};
void PreParserTraits::ReportMessageAt(Scanner::Location location,
const char* message,
=======================================
--- /branches/bleeding_edge/src/preparser.h Wed Aug 20 15:51:07 2014 UTC
+++ /branches/bleeding_edge/src/preparser.h Thu Aug 21 09:22:08 2014 UTC
@@ -117,7 +117,7 @@
}
protected:
- friend class Traits::Type::Checkpoint;
+ friend class Traits::Checkpoint;
enum AllowEvalOrArgumentsAsIdentifier {
kAllowEvalOrArguments,
@@ -129,7 +129,7 @@
PARSE_EAGERLY
};
- class ParserCheckpoint;
+ class CheckpointBase;
//
---------------------------------------------------------------------------
// FunctionState and BlockState together implement the parser's scope
stack.
@@ -226,18 +226,16 @@
typename Traits::Type::Factory factory_;
friend class ParserTraits;
- friend class ParserCheckpoint;
+ friend class CheckpointBase;
};
// Annoyingly, arrow functions first parse as comma expressions, then
when we
// see the => we have to go back and reinterpret the arguments as being
formal
// parameters. To do so we need to reset some of the parser state back
to
// what it was before the arguments were first seen.
- class ParserCheckpoint : public Traits::Type::Checkpoint {
+ class CheckpointBase BASE_EMBEDDED {
public:
- template <typename Parser>
- explicit ParserCheckpoint(Parser* parser)
- : Traits::Type::Checkpoint(parser) {
+ explicit CheckpointBase(ParserBase* parser) {
function_state_ = parser->function_state_;
next_materialized_literal_index_ =
function_state_->next_materialized_literal_index_;
@@ -246,7 +244,6 @@
}
void Restore() {
- Traits::Type::Checkpoint::Restore();
function_state_->next_materialized_literal_index_ =
next_materialized_literal_index_;
function_state_->next_handler_index_ = next_handler_index_;
@@ -1024,13 +1021,6 @@
typedef PreParserScope Scope;
typedef PreParserScope ScopePtr;
- class Checkpoint BASE_EMBEDDED {
- public:
- template <typename Parser>
- explicit Checkpoint(Parser* parser) {}
- void Restore() {}
- };
-
// PreParser doesn't need to store generator variables.
typedef void GeneratorVariable;
// No interaction with Zones.
@@ -1054,6 +1044,8 @@
typedef PreParserFactory Factory;
};
+ class Checkpoint;
+
explicit PreParserTraits(PreParser* pre_parser) :
pre_parser_(pre_parser) {}
// Custom operations executed when FunctionStates are created and
@@ -1979,7 +1971,7 @@
}
if (fni_ != NULL) fni_->Enter();
- ParserCheckpoint checkpoint(this);
+ typename Traits::Checkpoint checkpoint(this);
ExpressionT expression =
this->ParseConditionalExpression(accept_IN, CHECK_OK);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.