diff options
Diffstat (limited to 'deps/v8/src/torque/declarations.cc')
-rw-r--r-- | deps/v8/src/torque/declarations.cc | 96 |
1 files changed, 40 insertions, 56 deletions
diff --git a/deps/v8/src/torque/declarations.cc b/deps/v8/src/torque/declarations.cc index 6cf7d0c4a4..b4b414ba5c 100644 --- a/deps/v8/src/torque/declarations.cc +++ b/deps/v8/src/torque/declarations.cc @@ -5,6 +5,7 @@ #include "src/torque/declarations.h" #include "src/torque/declarable.h" #include "src/torque/global-context.h" +#include "src/torque/server-data.h" #include "src/torque/type-oracle.h" namespace v8 { @@ -59,10 +60,14 @@ std::vector<Declarable*> Declarations::LookupGlobalScope( return d; } -const Type* Declarations::LookupType(const QualifiedName& name) { +const TypeAlias* Declarations::LookupTypeAlias(const QualifiedName& name) { TypeAlias* declaration = EnsureUnique(FilterDeclarables<TypeAlias>(Lookup(name)), name, "type"); - return declaration->type(); + return declaration; +} + +const Type* Declarations::LookupType(const QualifiedName& name) { + return LookupTypeAlias(name)->type(); } const Type* Declarations::LookupType(std::string name) { @@ -79,7 +84,13 @@ const Type* Declarations::GetType(TypeExpression* type_expression) { if (auto* basic = BasicTypeExpression::DynamicCast(type_expression)) { std::string name = (basic->is_constexpr ? CONSTEXPR_TYPE_PREFIX : "") + basic->name; - return LookupType(QualifiedName{basic->namespace_qualification, name}); + const TypeAlias* alias = + LookupTypeAlias(QualifiedName{basic->namespace_qualification, name}); + if (GlobalContext::collect_language_server_data()) { + LanguageServerData::AddDefinition(type_expression->pos, + alias->GetDeclarationPosition()); + } + return alias->type(); } else if (auto* union_type = UnionTypeExpression::cast(type_expression)) { return TypeOracle::GetUnionType(GetType(union_type->a), GetType(union_type->b)); @@ -147,70 +158,42 @@ Namespace* Declarations::DeclareNamespace(const std::string& name) { } const AbstractType* Declarations::DeclareAbstractType( - const std::string& name, bool transient, const std::string& generated, + const Identifier* name, bool transient, std::string generated, base::Optional<const AbstractType*> non_constexpr_version, const base::Optional<std::string>& parent) { - CheckAlreadyDeclared<TypeAlias>(name, "type"); + CheckAlreadyDeclared<TypeAlias>(name->value, "type"); const Type* parent_type = nullptr; if (parent) { parent_type = LookupType(QualifiedName{*parent}); } + if (generated == "" && parent) { + generated = parent_type->GetGeneratedTNodeTypeName(); + } const AbstractType* type = TypeOracle::GetAbstractType( - parent_type, name, transient, generated, non_constexpr_version); + parent_type, name->value, transient, generated, non_constexpr_version); DeclareType(name, type, false); return type; } -void Declarations::DeclareType(const std::string& name, const Type* type, +void Declarations::DeclareType(const Identifier* name, const Type* type, bool redeclaration) { - CheckAlreadyDeclared<TypeAlias>(name, "type"); - Declare(name, std::unique_ptr<TypeAlias>(new TypeAlias(type, redeclaration))); + CheckAlreadyDeclared<TypeAlias>(name->value, "type"); + Declare(name->value, std::unique_ptr<TypeAlias>( + new TypeAlias(type, redeclaration, name->pos))); } -StructType* Declarations::DeclareStruct(const std::string& name, - const std::vector<Field>& fields) { - StructType* new_type = TypeOracle::GetStructType(name, fields); +StructType* Declarations::DeclareStruct(const Identifier* name) { + StructType* new_type = TypeOracle::GetStructType(name->value); DeclareType(name, new_type, false); return new_type; } ClassType* Declarations::DeclareClass(const Type* super_type, - const std::string& name, bool transient, - const std::string& generates, - std::vector<Field> fields, size_t size) { - std::vector<Field> this_struct_fields; - size_t struct_offset = 0; - const StructType* super_struct_type = nullptr; - // In order to ensure "atomicity" of object allocation, a class' - // constructors operate on a per-class internal struct rather than the class - // directly until the constructor has successfully completed and all class - // members are available. Create the appropriate struct type for use in the - // class' constructors, including a '_super' field in the struct that - // contains the values constructed by calls to super constructors. - if (const ClassType* super_class = ClassType::DynamicCast(super_type)) { - super_struct_type = super_class->struct_type(); - this_struct_fields.push_back( - {CurrentSourcePosition::Get(), - {kConstructorStructSuperFieldName, super_struct_type}, - struct_offset, - false}); - struct_offset += LoweredSlotCount(super_struct_type); - } - for (auto& field : fields) { - const Type* field_type = field.name_and_type.type; - this_struct_fields.push_back({field.pos, - {field.name_and_type.name, field_type}, - struct_offset, - false}); - struct_offset += LoweredSlotCount(field_type); - } - StructType* this_struct_type = DeclareStruct( - kClassConstructorThisStructPrefix + name, this_struct_fields); - - ClassType* new_type = - TypeOracle::GetClassType(super_type, name, transient, generates, - std::move(fields), this_struct_type, size); - this_struct_type->SetDerivedFrom(new_type); + const Identifier* name, bool is_extern, + bool transient, + const std::string& generates) { + ClassType* new_type = TypeOracle::GetClassType( + super_type, name->value, is_extern, transient, generates); DeclareType(name, new_type, false); return new_type; } @@ -304,18 +287,19 @@ RuntimeFunction* Declarations::DeclareRuntimeFunction( new RuntimeFunction(name, signature, transitioning)))); } -void Declarations::DeclareExternConstant(const std::string& name, - const Type* type, std::string value) { - CheckAlreadyDeclared<Value>(name, "constant"); +void Declarations::DeclareExternConstant(Identifier* name, const Type* type, + std::string value) { + CheckAlreadyDeclared<Value>(name->value, "constant"); ExternConstant* result = new ExternConstant(name, type, value); - Declare(name, std::unique_ptr<Declarable>(result)); + Declare(name->value, std::unique_ptr<Declarable>(result)); } -NamespaceConstant* Declarations::DeclareNamespaceConstant( - const std::string& name, const Type* type, Expression* body) { - CheckAlreadyDeclared<Value>(name, "constant"); +NamespaceConstant* Declarations::DeclareNamespaceConstant(Identifier* name, + const Type* type, + Expression* body) { + CheckAlreadyDeclared<Value>(name->value, "constant"); NamespaceConstant* result = new NamespaceConstant(name, type, body); - Declare(name, std::unique_ptr<Declarable>(result)); + Declare(name->value, std::unique_ptr<Declarable>(result)); return result; } |