Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_AST_AST_H_ | 5 #ifndef V8_AST_AST_H_ |
| 6 #define V8_AST_AST_H_ | 6 #define V8_AST_AST_H_ |
| 7 | 7 |
| 8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
| 9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
| 10 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 100 |
| 101 // Optional type nodes are intentionally not in in AST_NODE_LIST. | 101 // Optional type nodes are intentionally not in in AST_NODE_LIST. |
| 102 // Visitors should not have to worry about them. | 102 // Visitors should not have to worry about them. |
| 103 #define TYPESYSTEM_NODE_LIST(V) \ | 103 #define TYPESYSTEM_NODE_LIST(V) \ |
| 104 V(PredefinedType) \ | 104 V(PredefinedType) \ |
| 105 V(ThisType) \ | 105 V(ThisType) \ |
| 106 V(UnionType) \ | 106 V(UnionType) \ |
| 107 V(IntersectionType) \ | 107 V(IntersectionType) \ |
| 108 V(ArrayType) \ | 108 V(ArrayType) \ |
| 109 V(TupleType) \ | 109 V(TupleType) \ |
| 110 V(FunctionType) \ | 110 V(ObjectType) \ |
| 111 V(TypeMember) \ | |
| 111 V(TypeParameter) \ | 112 V(TypeParameter) \ |
| 112 V(FormalParameter) \ | 113 V(FormalParameter) \ |
| 113 V(TypeReference) \ | 114 V(TypeReference) \ |
| 114 V(StringLiteralType) \ | 115 V(StringLiteralType) \ |
| 115 V(QueryType) \ | 116 V(QueryType) \ |
| 116 V(TypeOrParameters) | 117 V(TypeOrParameters) |
| 117 | 118 |
| 118 // Forward declarations | 119 // Forward declarations |
| 119 class AstNodeFactory; | 120 class AstNodeFactory; |
| 120 class AstVisitor; | 121 class AstVisitor; |
| (...skipping 3008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3129 friend class Type; | 3130 friend class Type; |
| 3130 | 3131 |
| 3131 private: | 3132 private: |
| 3132 Type* binder_; | 3133 Type* binder_; |
| 3133 bool optional_; | 3134 bool optional_; |
| 3134 bool spread_; | 3135 bool spread_; |
| 3135 Type* type_; | 3136 Type* type_; |
| 3136 }; | 3137 }; |
| 3137 | 3138 |
| 3138 | 3139 |
| 3139 // Class for function and constructor types. | |
| 3140 class FunctionType : public Type { | |
| 3141 public: | |
| 3142 DECLARE_NODE_TYPE(FunctionType) | |
| 3143 | |
| 3144 bool IsConstructorType() const { return constructor_; } | |
| 3145 ZoneList<TypeParameter*>* type_parameters() const { return type_parameters_; } | |
| 3146 ZoneList<FormalParameter*>* parameters() const { return parameters_; } | |
| 3147 Type* result_type() const { return result_type_; } | |
| 3148 | |
| 3149 protected: | |
| 3150 FunctionType(Zone* zone, ZoneList<TypeParameter*>* type_parameters, | |
| 3151 ZoneList<FormalParameter*>* parameters, Type* result_type, | |
| 3152 int pos, bool constructor = false) | |
| 3153 : Type(zone, pos), | |
| 3154 type_parameters_(type_parameters), | |
| 3155 parameters_(parameters), | |
| 3156 result_type_(result_type), | |
| 3157 constructor_(constructor) {} | |
| 3158 | |
| 3159 private: | |
| 3160 ZoneList<TypeParameter*>* type_parameters_; | |
| 3161 ZoneList<FormalParameter*>* parameters_; | |
| 3162 Type* result_type_; | |
| 3163 bool constructor_; | |
| 3164 }; | |
| 3165 | |
| 3166 | |
| 3167 // Class for type references. | 3140 // Class for type references. |
| 3168 // It also covers binding identifiers. | 3141 // It also covers binding identifiers. |
| 3169 class TypeReference : public Type { | 3142 class TypeReference : public Type { |
| 3170 public: | 3143 public: |
| 3171 DECLARE_NODE_TYPE(TypeReference) | 3144 DECLARE_NODE_TYPE(TypeReference) |
| 3172 | 3145 |
| 3173 const AstRawString* name() const { return name_; } | 3146 const AstRawString* name() const { return name_; } |
| 3174 ZoneList<Type*>* type_arguments() const { return type_arguments_; } | 3147 ZoneList<Type*>* type_arguments() const { return type_arguments_; } |
| 3175 | 3148 |
| 3176 bool IsValidBindingIdentifier() const { | 3149 bool IsValidBindingIdentifier() const { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3233 | 3206 |
| 3234 protected: | 3207 protected: |
| 3235 TypeOrParameters(Zone* zone, ZoneList<FormalParameter*>* parameters, int pos) | 3208 TypeOrParameters(Zone* zone, ZoneList<FormalParameter*>* parameters, int pos) |
| 3236 : Type(zone, pos), parameters_(parameters) {} | 3209 : Type(zone, pos), parameters_(parameters) {} |
| 3237 | 3210 |
| 3238 private: | 3211 private: |
| 3239 ZoneList<FormalParameter*>* parameters_; | 3212 ZoneList<FormalParameter*>* parameters_; |
| 3240 }; | 3213 }; |
| 3241 | 3214 |
| 3242 | 3215 |
| 3216 // Class for object type members. | |
| 3217 // It also covers binding properties. | |
| 3218 class TypeMember : public AstNode { | |
| 3219 public: | |
| 3220 DECLARE_NODE_TYPE(TypeMember) | |
| 3221 | |
| 3222 enum IndexType { | |
| 3223 kNoIndexType, | |
| 3224 kNumberIndexType, | |
| 3225 kStringIndexType | |
| 3226 }; | |
| 3227 | |
| 3228 Expression* property() const { return property_; } | |
| 3229 IndexType index_type() const { return index_type_; } | |
| 3230 bool optional() const { return optional_; } | |
|
rossberg
2016/04/07 15:09:02
Nit: is_optional, is_constructor?
nickie
2016/04/08 09:50:57
Done.
| |
| 3231 bool constructor() const { return constructor_; } | |
| 3232 ZoneList<TypeParameter*>* type_parameters() const { return type_parameters_; } | |
| 3233 ZoneList<FormalParameter*>* parameters() const { return parameters_; } | |
| 3234 Type* type() const { return type_; } | |
| 3235 bool IsValidType() const { return valid_type_; } | |
| 3236 bool IsValidBindingIdentifierOrPattern() const { return valid_binder_; } | |
| 3237 | |
| 3238 protected: | |
| 3239 TypeMember(Zone* zone, Expression* property, bool optional, | |
| 3240 ZoneList<typesystem::TypeParameter*>* type_parameters, | |
| 3241 ZoneList<typesystem::FormalParameter*>* parameters, | |
| 3242 typesystem::Type* type, bool valid_type, bool valid_binder, | |
| 3243 int pos, bool constructor = false) | |
| 3244 : AstNode(pos), | |
| 3245 property_(property), | |
| 3246 index_type_(kNoIndexType), | |
| 3247 optional_(optional), | |
| 3248 constructor_(constructor), | |
| 3249 valid_type_(valid_type), | |
| 3250 valid_binder_(valid_binder), | |
| 3251 type_parameters_(type_parameters), | |
| 3252 parameters_(parameters), | |
| 3253 type_(type) {} | |
| 3254 TypeMember(Zone* zone, Expression* property, | |
| 3255 typesystem::TypeMember::IndexType index_type, | |
| 3256 typesystem::Type* type, int pos) | |
| 3257 : AstNode(pos), | |
| 3258 property_(property), | |
| 3259 index_type_(index_type), | |
| 3260 optional_(false), | |
| 3261 constructor_(false), | |
| 3262 valid_type_(true), | |
| 3263 valid_binder_(false), | |
| 3264 type_parameters_(nullptr), | |
| 3265 parameters_(nullptr), | |
| 3266 type_(type) {} | |
| 3267 | |
| 3268 private: | |
| 3269 Expression* property_; | |
| 3270 IndexType index_type_; | |
| 3271 bool optional_; | |
| 3272 bool constructor_; | |
| 3273 bool valid_type_; | |
| 3274 bool valid_binder_; | |
| 3275 ZoneList<typesystem::TypeParameter*>* type_parameters_; | |
| 3276 ZoneList<typesystem::FormalParameter*>* parameters_; | |
| 3277 typesystem::Type* type_; | |
| 3278 }; | |
| 3279 | |
| 3280 | |
| 3281 // Class for object types. | |
| 3282 // It also covers binding object patterns. | |
| 3283 class ObjectType : public Type { | |
| 3284 public: | |
| 3285 DECLARE_NODE_TYPE(ObjectType) | |
| 3286 | |
| 3287 ZoneList<TypeMember*>* members() const { return members_; } | |
| 3288 bool IsValidType() const { return valid_type_; } | |
| 3289 bool IsValidBindingPattern() const { return valid_binder_; } | |
| 3290 | |
| 3291 protected: | |
| 3292 ObjectType(Zone* zone, ZoneList<TypeMember*>* members, bool valid_type, | |
| 3293 bool valid_binder, int pos) | |
| 3294 : Type(zone, pos), | |
| 3295 members_(members), | |
| 3296 valid_type_(valid_type), | |
| 3297 valid_binder_(valid_binder) {} | |
| 3298 | |
| 3299 private: | |
| 3300 ZoneList<TypeMember*>* members_; | |
| 3301 bool valid_type_; | |
| 3302 bool valid_binder_; | |
| 3303 }; | |
| 3304 | |
| 3305 | |
| 3243 V8_INLINE bool Type::IsValidType() const { | 3306 V8_INLINE bool Type::IsValidType() const { |
| 3244 if (IsTypeOrParameters()) { | 3307 if (IsTypeOrParameters()) { |
| 3245 ZoneList<FormalParameter*>* parameters = AsTypeOrParameters()->parameters(); | 3308 ZoneList<FormalParameter*>* parameters = AsTypeOrParameters()->parameters(); |
| 3246 return parameters->length() == 1 && parameters->at(0)->IsValidType(); | 3309 return parameters->length() == 1 && parameters->at(0)->IsValidType(); |
| 3247 } | 3310 } |
| 3248 if (IsTupleType()) return AsTupleType()->IsValidType(); | 3311 if (IsTupleType()) return AsTupleType()->IsValidType(); |
| 3312 if (IsObjectType()) return AsObjectType()->IsValidType(); | |
| 3249 return true; | 3313 return true; |
| 3250 } | 3314 } |
| 3251 | 3315 |
| 3252 V8_INLINE bool Type::IsValidBindingIdentifierOrPattern() const { | 3316 V8_INLINE bool Type::IsValidBindingIdentifierOrPattern() const { |
| 3253 if (IsTypeReference()) return AsTypeReference()->IsValidBindingIdentifier(); | 3317 if (IsTypeReference()) return AsTypeReference()->IsValidBindingIdentifier(); |
| 3254 if (IsTupleType()) return AsTupleType()->IsValidBindingPattern(); | 3318 if (IsTupleType()) return AsTupleType()->IsValidBindingPattern(); |
| 3319 if (IsObjectType()) return AsObjectType()->IsValidBindingPattern(); | |
| 3255 if (IsPredefinedType()) return AsPredefinedType()->IsValidBindingIdentifier(); | 3320 if (IsPredefinedType()) return AsPredefinedType()->IsValidBindingIdentifier(); |
| 3256 return false; | 3321 return false; |
| 3257 } | 3322 } |
| 3258 | 3323 |
| 3259 V8_INLINE Type* Type::Uncover(bool* ok) { | 3324 V8_INLINE Type* Type::Uncover(bool* ok) { |
| 3260 if (IsTypeOrParameters()) { | 3325 if (IsTypeOrParameters()) { |
| 3261 ZoneList<FormalParameter*>* parameters = AsTypeOrParameters()->parameters(); | 3326 ZoneList<FormalParameter*>* parameters = AsTypeOrParameters()->parameters(); |
| 3262 if (parameters->length() == 1 && parameters->at(0)->IsValidType()) | 3327 if (parameters->length() == 1 && parameters->at(0)->IsValidType()) |
| 3263 return parameters->at(0)->type(); | 3328 return parameters->at(0)->type(); |
| 3264 } else if (IsTupleType()) { | 3329 } else if (IsTupleType()) { |
| 3265 if (AsTupleType()->IsValidType()) return this; | 3330 if (AsTupleType()->IsValidType()) return this; |
| 3331 } else if (IsObjectType()) { | |
| 3332 if (AsObjectType()->IsValidType()) return this; | |
| 3266 } else { | 3333 } else { |
| 3267 return this; | 3334 return this; |
| 3268 } | 3335 } |
| 3269 *ok = false; | 3336 *ok = false; |
| 3270 return nullptr; | 3337 return nullptr; |
| 3271 } | 3338 } |
| 3272 | 3339 |
| 3273 V8_INLINE ZoneList<FormalParameter*>* Type::AsValidParameterList( | 3340 V8_INLINE ZoneList<FormalParameter*>* Type::AsValidParameterList( |
| 3274 Zone* zone, bool* ok) const { | 3341 Zone* zone, bool* ok) const { |
| 3275 if (!IsTypeOrParameters()) { | 3342 if (!IsTypeOrParameters()) { |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3857 return new (local_zone_) typesystem::ArrayType(local_zone_, base, pos); | 3924 return new (local_zone_) typesystem::ArrayType(local_zone_, base, pos); |
| 3858 } | 3925 } |
| 3859 | 3926 |
| 3860 typesystem::TupleType* NewTupleType(ZoneList<typesystem::Type*>* elements, | 3927 typesystem::TupleType* NewTupleType(ZoneList<typesystem::Type*>* elements, |
| 3861 bool valid_type, bool valid_binder, | 3928 bool valid_type, bool valid_binder, |
| 3862 bool spread, int pos) { | 3929 bool spread, int pos) { |
| 3863 return new (local_zone_) typesystem::TupleType( | 3930 return new (local_zone_) typesystem::TupleType( |
| 3864 local_zone_, elements, valid_type, valid_binder, spread, pos); | 3931 local_zone_, elements, valid_type, valid_binder, spread, pos); |
| 3865 } | 3932 } |
| 3866 | 3933 |
| 3867 typesystem::FunctionType* NewFunctionType( | 3934 typesystem::ObjectType* NewObjectType( |
| 3935 ZoneList<typesystem::TypeMember*>* members, bool valid_type, | |
| 3936 bool valid_binder, int pos) { | |
| 3937 return new (local_zone_) typesystem::ObjectType( | |
| 3938 local_zone_, members, valid_type, valid_binder, pos); | |
| 3939 } | |
| 3940 | |
| 3941 typesystem::ObjectType* NewFunctionType( | |
| 3868 ZoneList<typesystem::TypeParameter*>* type_parameters, | 3942 ZoneList<typesystem::TypeParameter*>* type_parameters, |
| 3869 ZoneList<typesystem::FormalParameter*>* parameters, | 3943 ZoneList<typesystem::FormalParameter*>* parameters, |
| 3870 typesystem::Type* result_type, int pos, bool constructor = false) { | 3944 typesystem::Type* result_type, int pos, bool constructor = false) { |
| 3945 ZoneList<typesystem::TypeMember*>* members = | |
| 3946 new (local_zone_) ZoneList<typesystem::TypeMember*>(1, local_zone_); | |
| 3947 members->Add(NewTypeMember(nullptr, false, type_parameters, parameters, | |
| 3948 result_type, true, false, pos, constructor), | |
| 3949 local_zone_); | |
| 3871 return new (local_zone_) | 3950 return new (local_zone_) |
| 3872 typesystem::FunctionType(local_zone_, type_parameters, parameters, | 3951 typesystem::ObjectType(local_zone_, members, true, false, pos); |
| 3873 result_type, pos, constructor); | |
| 3874 } | 3952 } |
| 3875 | 3953 |
| 3876 typesystem::TypeReference* NewTypeReference( | 3954 typesystem::TypeReference* NewTypeReference( |
| 3877 const AstRawString* name, ZoneList<typesystem::Type*>* type_arguments, | 3955 const AstRawString* name, ZoneList<typesystem::Type*>* type_arguments, |
| 3878 int pos) { | 3956 int pos) { |
| 3879 return new (local_zone_) | 3957 return new (local_zone_) |
| 3880 typesystem::TypeReference(local_zone_, name, type_arguments, pos); | 3958 typesystem::TypeReference(local_zone_, name, type_arguments, pos); |
| 3881 } | 3959 } |
| 3882 | 3960 |
| 3883 typesystem::StringLiteralType* NewStringLiteralType( | 3961 typesystem::StringLiteralType* NewStringLiteralType( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 3913 typesystem::TypeOrParameters(local_zone_, parameters, pos); | 3991 typesystem::TypeOrParameters(local_zone_, parameters, pos); |
| 3914 } | 3992 } |
| 3915 | 3993 |
| 3916 typesystem::TypeParameter* NewTypeParameter(const AstRawString* name, | 3994 typesystem::TypeParameter* NewTypeParameter(const AstRawString* name, |
| 3917 typesystem::Type* extends, | 3995 typesystem::Type* extends, |
| 3918 int pos) { | 3996 int pos) { |
| 3919 return new (local_zone_) | 3997 return new (local_zone_) |
| 3920 typesystem::TypeParameter(local_zone_, name, extends, pos); | 3998 typesystem::TypeParameter(local_zone_, name, extends, pos); |
| 3921 } | 3999 } |
| 3922 | 4000 |
| 4001 typesystem::TypeMember* NewTypeMember( | |
| 4002 Expression* property, bool optional, | |
| 4003 ZoneList<typesystem::TypeParameter*>* type_parameters, | |
| 4004 ZoneList<typesystem::FormalParameter*>* parameters, | |
| 4005 typesystem::Type* type, bool valid_type, bool valid_binder, int pos, | |
| 4006 bool constructor = false) { | |
| 4007 return new (local_zone_) typesystem::TypeMember( | |
| 4008 local_zone_, property, optional, type_parameters, parameters, type, | |
| 4009 valid_type, valid_binder, pos, constructor); | |
| 4010 } | |
| 4011 | |
| 4012 typesystem::TypeMember* NewTypeMember( | |
| 4013 Expression* property, typesystem::TypeMember::IndexType index_type, | |
| 4014 typesystem::Type* type, int pos) { | |
| 4015 return new (local_zone_) | |
| 4016 typesystem::TypeMember(local_zone_, property, index_type, type, pos); | |
| 4017 } | |
| 4018 | |
| 3923 Zone* zone() const { return local_zone_; } | 4019 Zone* zone() const { return local_zone_; } |
| 3924 | 4020 |
| 3925 // Handles use of temporary zones when parsing inner function bodies. | 4021 // Handles use of temporary zones when parsing inner function bodies. |
| 3926 class BodyScope { | 4022 class BodyScope { |
| 3927 public: | 4023 public: |
| 3928 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool use_temp_zone) | 4024 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool use_temp_zone) |
| 3929 : factory_(factory), prev_zone_(factory->local_zone_) { | 4025 : factory_(factory), prev_zone_(factory->local_zone_) { |
| 3930 if (use_temp_zone) { | 4026 if (use_temp_zone) { |
| 3931 factory->local_zone_ = temp_zone; | 4027 factory->local_zone_ = temp_zone; |
| 3932 } | 4028 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4005 : NULL; \ | 4101 : NULL; \ |
| 4006 } | 4102 } |
| 4007 TYPESYSTEM_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 4103 TYPESYSTEM_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 4008 #undef DECLARE_NODE_FUNCTIONS | 4104 #undef DECLARE_NODE_FUNCTIONS |
| 4009 | 4105 |
| 4010 | 4106 |
| 4011 } // namespace internal | 4107 } // namespace internal |
| 4012 } // namespace v8 | 4108 } // namespace v8 |
| 4013 | 4109 |
| 4014 #endif // V8_AST_AST_H_ | 4110 #endif // V8_AST_AST_H_ |
| OLD | NEW |