Index: src/ast.h |
diff --git a/src/ast.h b/src/ast.h |
index c5a924c43d914f10246f7b8513a0cb0417dfae01..db4a173848dccaaf73499677138d0c3d3ba7e297 100644 |
--- a/src/ast.h |
+++ b/src/ast.h |
@@ -40,12 +40,13 @@ namespace internal { |
// Nodes of the abstract syntax tree. Only concrete classes are |
// enumerated here. |
-#define DECLARATION_NODE_LIST(V) \ |
- V(VariableDeclaration) \ |
- V(FunctionDeclaration) \ |
- V(ModuleDeclaration) \ |
- V(ImportDeclaration) \ |
- V(ExportDeclaration) \ |
+#define DECLARATION_NODE_LIST(V) \ |
+ V(VariableDeclaration) \ |
+ V(FunctionDeclaration) \ |
+ V(ClassDeclaration) \ |
+ V(ModuleDeclaration) \ |
+ V(ImportDeclaration) \ |
+ V(ExportDeclaration) |
#define MODULE_NODE_LIST(V) \ |
V(ModuleLiteral) \ |
@@ -73,28 +74,29 @@ namespace internal { |
V(TryFinallyStatement) \ |
V(DebuggerStatement) |
-#define EXPRESSION_NODE_LIST(V) \ |
- V(FunctionLiteral) \ |
- V(NativeFunctionLiteral) \ |
- V(Conditional) \ |
- V(VariableProxy) \ |
- V(Literal) \ |
- V(RegExpLiteral) \ |
- V(ObjectLiteral) \ |
- V(ArrayLiteral) \ |
- V(Assignment) \ |
- V(Yield) \ |
- V(Throw) \ |
- V(Property) \ |
- V(Call) \ |
- V(CallNew) \ |
- V(CallRuntime) \ |
- V(UnaryOperation) \ |
- V(CountOperation) \ |
- V(BinaryOperation) \ |
- V(CompareOperation) \ |
- V(ThisFunction) \ |
- V(SuperReference) \ |
+#define EXPRESSION_NODE_LIST(V) \ |
+ V(FunctionLiteral) \ |
+ V(ClassLiteral) \ |
+ V(NativeFunctionLiteral) \ |
+ V(Conditional) \ |
+ V(VariableProxy) \ |
+ V(Literal) \ |
+ V(RegExpLiteral) \ |
+ V(ObjectLiteral) \ |
+ V(ArrayLiteral) \ |
+ V(Assignment) \ |
+ V(Yield) \ |
+ V(Throw) \ |
+ V(Property) \ |
+ V(Call) \ |
+ V(CallNew) \ |
+ V(CallRuntime) \ |
+ V(UnaryOperation) \ |
+ V(CountOperation) \ |
+ V(BinaryOperation) \ |
+ V(CompareOperation) \ |
+ V(ThisFunction) \ |
+ V(SuperReference) \ |
V(CaseClause) |
#define AST_NODE_LIST(V) \ |
@@ -560,6 +562,27 @@ class FunctionDeclaration FINAL : public Declaration { |
}; |
+class ClassDeclaration FINAL : public Declaration { |
+ public: |
+ DECLARE_NODE_TYPE(ClassDeclaration) |
+ |
+ ClassLiteral* classLiteral() const { return classLiteral_; } |
+ virtual InitializationFlag initialization() const OVERRIDE { |
+ return kCreatedInitialized; |
+ } |
+ |
+ protected: |
+ ClassDeclaration(Zone* zone, VariableProxy* proxy, ClassLiteral* classLiteral, |
+ Scope* scope, int pos) |
+ : Declaration(zone, proxy, LET, scope, pos), classLiteral_(classLiteral) { |
+ DCHECK(classLiteral != NULL); |
+ } |
+ |
+ private: |
+ ClassLiteral* classLiteral_; |
+}; |
+ |
+ |
class ModuleDeclaration FINAL : public Declaration { |
public: |
DECLARE_NODE_TYPE(ModuleDeclaration) |
@@ -1459,7 +1482,8 @@ class ObjectLiteralProperty FINAL : public ZoneObject { |
}; |
ObjectLiteralProperty(Zone* zone, AstValueFactory* ast_value_factory, |
- Literal* key, Expression* value); |
+ Literal* key, Expression* value, |
+ bool is_static = false); |
Literal* key() { return key_; } |
Expression* value() { return value_; } |
@@ -1478,7 +1502,8 @@ class ObjectLiteralProperty FINAL : public ZoneObject { |
protected: |
template<class> friend class AstNodeFactory; |
- ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value); |
+ ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value, |
+ bool is_static = false); |
void set_key(Literal* key) { key_ = key; } |
private: |
@@ -1487,6 +1512,7 @@ class ObjectLiteralProperty FINAL : public ZoneObject { |
Kind kind_; |
bool emit_store_; |
Handle<Map> receiver_type_; |
+ bool is_static_; |
}; |
@@ -2498,6 +2524,37 @@ class FunctionLiteral FINAL : public Expression { |
}; |
+class ClassLiteral FINAL : public Expression { |
+ public: |
+ typedef ObjectLiteralProperty Property; |
+ |
+ DECLARE_NODE_TYPE(ClassLiteral) |
+ |
+ Handle<String> name() const { return raw_name_->string(); } |
+ const AstRawString* raw_name() const { return raw_name_; } |
+ Expression* extends() const { return extends_; } |
+ ZoneList<Property*>* properties() const { return properties_; } |
+ |
+ protected: |
+ ClassLiteral(Zone* zone, const AstRawString* name, Expression* extends, |
+ ZoneList<Property*>* properties, |
+ AstValueFactory* ast_value_factory, int position, IdGen* id_gen) |
+ : Expression(zone, position, id_gen), |
+ raw_name_(name), |
+ raw_inferred_name_(ast_value_factory->empty_string()), |
+ extends_(extends), |
+ properties_(properties) {} |
+ |
+ private: |
+ const AstRawString* raw_name_; |
+ Handle<String> name_; |
+ const AstString* raw_inferred_name_; |
+ Handle<String> inferred_name_; |
+ Expression* extends_; |
+ ZoneList<Property*>* properties_; |
+}; |
+ |
+ |
class NativeFunctionLiteral FINAL : public Expression { |
public: |
DECLARE_NODE_TYPE(NativeFunctionLiteral) |
@@ -3052,6 +3109,13 @@ class AstNodeFactory FINAL BASE_EMBEDDED { |
VISIT_AND_RETURN(FunctionDeclaration, decl) |
} |
+ ClassDeclaration* NewClassDeclaration(VariableProxy* proxy, ClassLiteral* lit, |
+ Scope* scope, int pos) { |
+ ClassDeclaration* decl = |
+ new (zone_) ClassDeclaration(zone_, proxy, lit, scope, pos); |
+ VISIT_AND_RETURN(ClassDeclaration, decl) |
+ } |
+ |
ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy, |
Module* module, |
Scope* scope, |
@@ -3289,16 +3353,17 @@ class AstNodeFactory FINAL BASE_EMBEDDED { |
} |
ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, |
- Expression* value) { |
- return new (zone_) |
- ObjectLiteral::Property(zone_, ast_value_factory_, key, value); |
+ Expression* value, |
+ bool is_static) { |
+ return new (zone_) ObjectLiteral::Property(zone_, ast_value_factory_, key, |
+ value, is_static); |
} |
ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, |
FunctionLiteral* value, |
- int pos) { |
+ int pos, bool is_static) { |
ObjectLiteral::Property* prop = |
- new(zone_) ObjectLiteral::Property(zone_, is_getter, value); |
+ new (zone_) ObjectLiteral::Property(zone_, is_getter, value, is_static); |
prop->set_key(NewStringLiteral(value->raw_name(), pos)); |
return prop; // Not an AST node, will not be visited. |
} |
@@ -3454,6 +3519,15 @@ class AstNodeFactory FINAL BASE_EMBEDDED { |
return lit; |
} |
+ ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends, |
+ ZoneList<ObjectLiteral::Property*>* properties, |
+ AstValueFactory* ast_value_factory, |
+ int position) { |
+ ClassLiteral* lit = new (zone_) ClassLiteral( |
+ zone_, name, extends, properties, ast_value_factory, position, id_gen_); |
+ VISIT_AND_RETURN(ClassLiteral, lit) |
+ } |
+ |
NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, |
v8::Extension* extension, |
int pos) { |