Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Unified Diff: src/ast.h

Issue 9348057: Split AST Declaration class, in preparation for new module declaration forms. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Jakob's comments. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/arm/full-codegen-arm.cc ('k') | src/ast.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index bc2c67e0e27ddf5ccbbfb046085a46d3989508a8..12337023c1f47f67f482cfe0c04a4e5953762644 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -59,6 +59,9 @@ namespace internal {
// Nodes of the abstract syntax tree. Only concrete classes are
// enumerated here.
+#define DECLARATION_NODE_LIST(V) \
+ V(VariableDeclaration) \
+
#define STATEMENT_NODE_LIST(V) \
V(Block) \
V(ExpressionStatement) \
@@ -99,7 +102,7 @@ namespace internal {
V(ThisFunction)
#define AST_NODE_LIST(V) \
- V(Declaration) \
+ DECLARATION_NODE_LIST(V) \
STATEMENT_NODE_LIST(V) \
EXPRESSION_NODE_LIST(V)
@@ -107,6 +110,7 @@ namespace internal {
class AstConstructionVisitor;
template<class> class AstNodeFactory;
class AstVisitor;
+class Declaration;
class BreakableStatement;
class Expression;
class IterationStatement;
@@ -202,6 +206,7 @@ class AstNode: public ZoneObject {
AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
#undef DECLARE_NODE_FUNCTIONS
+ virtual Declaration* AsDeclaration() { return NULL; }
virtual Statement* AsStatement() { return NULL; }
virtual Expression* AsExpression() { return NULL; }
virtual TargetCollector* AsTargetCollector() { return NULL; }
@@ -433,43 +438,63 @@ class Block: public BreakableStatement {
class Declaration: public AstNode {
public:
- DECLARE_NODE_TYPE(Declaration)
-
VariableProxy* proxy() const { return proxy_; }
VariableMode mode() const { return mode_; }
- FunctionLiteral* fun() const { return fun_; } // may be NULL
- bool IsInlineable() const;
Scope* scope() const { return scope_; }
+ virtual bool IsInlineable() const;
- protected:
- template<class> friend class AstNodeFactory;
+ virtual Declaration* AsDeclaration() { return this; }
+ virtual VariableDeclaration* AsVariableDeclaration() { return NULL; }
+ protected:
Declaration(VariableProxy* proxy,
VariableMode mode,
- FunctionLiteral* fun,
Scope* scope)
: proxy_(proxy),
mode_(mode),
- fun_(fun),
scope_(scope) {
ASSERT(mode == VAR ||
mode == CONST ||
mode == CONST_HARMONY ||
mode == LET);
- // At the moment there are no "const functions"'s in JavaScript...
- ASSERT(fun == NULL || mode == VAR || mode == LET);
}
private:
VariableProxy* proxy_;
VariableMode mode_;
- FunctionLiteral* fun_;
// Nested scope from which the declaration originated.
Scope* scope_;
};
+class VariableDeclaration: public Declaration {
+ public:
+ DECLARE_NODE_TYPE(VariableDeclaration)
+
+ virtual VariableDeclaration* AsVariableDeclaration() { return this; }
+
+ FunctionLiteral* fun() const { return fun_; } // may be NULL
+ virtual bool IsInlineable() const;
+
+ protected:
+ template<class> friend class AstNodeFactory;
+
+ VariableDeclaration(VariableProxy* proxy,
+ VariableMode mode,
+ FunctionLiteral* fun,
+ Scope* scope)
+ : Declaration(proxy, mode, scope),
+ fun_(fun) {
+ // At the moment there are no "const functions"'s in JavaScript...
+ ASSERT(fun == NULL || mode == VAR || mode == LET);
+ }
+
+ private:
+ FunctionLiteral* fun_;
+};
+
+
class IterationStatement: public BreakableStatement {
public:
// Type testing & conversion.
@@ -2368,6 +2393,15 @@ class AstNodeFactory BASE_EMBEDDED {
visitor_.Visit##NodeType((node)); \
return node;
+ VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
+ VariableMode mode,
+ FunctionLiteral* fun,
+ Scope* scope) {
+ VariableDeclaration* decl =
+ new(zone_) VariableDeclaration(proxy, mode, fun, scope);
+ VISIT_AND_RETURN(VariableDeclaration, decl)
+ }
+
Block* NewBlock(ZoneStringList* labels,
int capacity,
bool is_initializer_block) {
@@ -2376,14 +2410,6 @@ class AstNodeFactory BASE_EMBEDDED {
VISIT_AND_RETURN(Block, block)
}
- Declaration* NewDeclaration(VariableProxy* proxy,
- VariableMode mode,
- FunctionLiteral* fun,
- Scope* scope) {
- Declaration* decl = new(zone_) Declaration(proxy, mode, fun, scope);
- VISIT_AND_RETURN(Declaration, decl)
- }
-
#define STATEMENT_WITH_LABELS(NodeType) \
NodeType* New##NodeType(ZoneStringList* labels) { \
NodeType* stmt = new(zone_) NodeType(isolate_, labels); \
« no previous file with comments | « src/arm/full-codegen-arm.cc ('k') | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698