[torque-ls] Turn parent class name for class decl into a TypeExpression
This enables "goto definition" navigation for parent types. R=sigurds@chromium.org Bug: v8:8880 Change-Id: I3207ec8b85f0e36cbab3519b89af98bba1666406 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1593081 Commit-Queue: Simon Zünd <szuend@chromium.org> Reviewed-by: Sigurd Schneider <sigurds@chromium.org> Cr-Commit-Position: refs/heads/master@{#61169}
This commit is contained in:
parent
e8986a4e06
commit
197966859f
@ -915,7 +915,7 @@ struct ClassDeclaration : Declaration {
|
||||
DEFINE_AST_NODE_LEAF_BOILERPLATE(ClassDeclaration)
|
||||
ClassDeclaration(SourcePosition pos, Identifier* name, bool is_extern,
|
||||
bool generate_print, bool transient,
|
||||
base::Optional<std::string> super,
|
||||
base::Optional<TypeExpression*> super,
|
||||
base::Optional<std::string> generates,
|
||||
std::vector<Declaration*> methods,
|
||||
std::vector<ClassFieldExpression> fields)
|
||||
@ -924,7 +924,7 @@ struct ClassDeclaration : Declaration {
|
||||
is_extern(is_extern),
|
||||
generate_print(generate_print),
|
||||
transient(transient),
|
||||
super(std::move(super)),
|
||||
super(super),
|
||||
generates(std::move(generates)),
|
||||
methods(std::move(methods)),
|
||||
fields(std::move(fields)) {}
|
||||
@ -932,7 +932,7 @@ struct ClassDeclaration : Declaration {
|
||||
bool is_extern;
|
||||
bool generate_print;
|
||||
bool transient;
|
||||
base::Optional<std::string> super;
|
||||
base::Optional<TypeExpression*> super;
|
||||
base::Optional<std::string> generates;
|
||||
std::vector<Declaration*> methods;
|
||||
std::vector<ClassFieldExpression> fields;
|
||||
|
@ -278,9 +278,7 @@ void DeclarationVisitor::Visit(ClassDeclaration* decl) {
|
||||
if (!decl->super) {
|
||||
ReportError("Extern class must extend another type.");
|
||||
}
|
||||
// Compute the offset of the class' first member. If the class extends
|
||||
// another class, it's the size of the extended class, otherwise zero.
|
||||
const Type* super_type = Declarations::LookupType(*decl->super);
|
||||
const Type* super_type = Declarations::GetType(*decl->super);
|
||||
if (super_type != TypeOracle::GetTaggedType()) {
|
||||
const ClassType* super_class = ClassType::DynamicCast(super_type);
|
||||
if (!super_class) {
|
||||
|
@ -575,7 +575,7 @@ base::Optional<ParseResult> MakeClassDeclaration(
|
||||
if (!IsValidTypeName(name->value)) {
|
||||
NamingConventionError("Type", name->value, "UpperCamelCase");
|
||||
}
|
||||
auto extends = child_results->NextAs<base::Optional<std::string>>();
|
||||
auto extends = child_results->NextAs<base::Optional<TypeExpression*>>();
|
||||
auto generates = child_results->NextAs<base::Optional<std::string>>();
|
||||
auto methods = child_results->NextAs<std::vector<Declaration*>>();
|
||||
auto fields = child_results->NextAs<std::vector<ClassFieldExpression>>();
|
||||
@ -1650,7 +1650,7 @@ struct TorqueGrammar : Grammar {
|
||||
MakeExternConstDeclaration),
|
||||
Rule({CheckIf(Token("@generatePrint")), CheckIf(Token("extern")),
|
||||
CheckIf(Token("transient")), Token("class"), &name,
|
||||
Optional<std::string>(Sequence({Token("extends"), &identifier})),
|
||||
Optional<TypeExpression*>(Sequence({Token("extends"), &type})),
|
||||
Optional<std::string>(
|
||||
Sequence({Token("generates"), &externalString})),
|
||||
Token("{"), List<Declaration*>(&method),
|
||||
|
@ -79,6 +79,23 @@ TEST(LanguageServer, GotoTypeDefinitionNoDataForFile) {
|
||||
EXPECT_FALSE(LanguageServerData::FindDefinition(test_id, {0, 0}));
|
||||
}
|
||||
|
||||
TEST(LanguageServer, GotoDefinitionClassSuperType) {
|
||||
const std::string source =
|
||||
"type void;\n"
|
||||
"type never;\n"
|
||||
"type Tagged generates 'TNode<Object>' constexpr 'ObjectPtr';\n"
|
||||
"extern class HeapObject extends Tagged {}";
|
||||
|
||||
TestCompiler compiler;
|
||||
compiler.Compile(source);
|
||||
|
||||
// Find the definition for 'Tagged' of the 'extends' on line 3.
|
||||
const SourceId id = SourceFileMap::GetSourceId("<torque>");
|
||||
auto maybe_position = LanguageServerData::FindDefinition(id, {3, 33});
|
||||
ASSERT_TRUE(maybe_position.has_value());
|
||||
EXPECT_EQ(*maybe_position, (SourcePosition{id, {2, 5}, {2, 11}}));
|
||||
}
|
||||
|
||||
} // namespace torque
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
Loading…
Reference in New Issue
Block a user