From 8b8e996023875ac7fcd0935b9d69fa6f189819fb Mon Sep 17 00:00:00 2001 From: Nico Hartmann Date: Thu, 13 Jan 2022 14:59:57 +0100 Subject: [PATCH] [torque] Fix positions for type alias and structs Bug: v8:12261 Change-Id: I4872ba82676bf64fa51d5a599323382c65cc465a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3386594 Auto-Submit: Nico Hartmann Reviewed-by: Tobias Tebbi Commit-Queue: Tobias Tebbi Cr-Commit-Position: refs/heads/main@{#78606} --- src/torque/declaration-visitor.h | 17 +++++++++++++++-- src/torque/declarations.cc | 6 +++--- src/torque/declarations.h | 6 +++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/torque/declaration-visitor.h b/src/torque/declaration-visitor.h index c91cbc0f18..befbfae6ae 100644 --- a/src/torque/declaration-visitor.h +++ b/src/torque/declaration-visitor.h @@ -11,6 +11,7 @@ #include "src/base/macros.h" #include "src/torque/declarations.h" #include "src/torque/global-context.h" +#include "src/torque/kythe-data.h" #include "src/torque/types.h" #include "src/torque/utils.h" @@ -35,10 +36,22 @@ class PredeclarationVisitor { for (Declaration* child : decl->declarations) Predeclare(child); } static void Predeclare(TypeDeclaration* decl) { - Declarations::PredeclareTypeAlias(decl->name, decl, false); + TypeAlias* alias = + Declarations::PredeclareTypeAlias(decl->name, decl, false); + alias->SetPosition(decl->pos); + alias->SetIdentifierPosition(decl->name->pos); + if (GlobalContext::collect_kythe_data()) { + KytheData::AddTypeDefinition(alias); + } } static void Predeclare(StructDeclaration* decl) { - Declarations::PredeclareTypeAlias(decl->name, decl, false); + TypeAlias* alias = + Declarations::PredeclareTypeAlias(decl->name, decl, false); + alias->SetPosition(decl->pos); + alias->SetIdentifierPosition(decl->name->pos); + if (GlobalContext::collect_kythe_data()) { + KytheData::AddTypeDefinition(alias); + } } static void Predeclare(GenericTypeDeclaration* generic_decl) { Declarations::DeclareGenericType(generic_decl->declaration->name->value, diff --git a/src/torque/declarations.cc b/src/torque/declarations.cc index ed92004c92..6d349cb8a2 100644 --- a/src/torque/declarations.cc +++ b/src/torque/declarations.cc @@ -168,9 +168,9 @@ TypeAlias* Declarations::DeclareType(const Identifier* name, const Type* type) { new TypeAlias(type, true, name->pos))); } -const TypeAlias* Declarations::PredeclareTypeAlias(const Identifier* name, - TypeDeclaration* type, - bool redeclaration) { +TypeAlias* Declarations::PredeclareTypeAlias(const Identifier* name, + TypeDeclaration* type, + bool redeclaration) { CheckAlreadyDeclared(name->value, "type"); std::unique_ptr alias_ptr( new TypeAlias(type, redeclaration, name->pos)); diff --git a/src/torque/declarations.h b/src/torque/declarations.h index 739c021fec..3bd50f6e48 100644 --- a/src/torque/declarations.h +++ b/src/torque/declarations.h @@ -93,9 +93,9 @@ class Declarations { static Namespace* DeclareNamespace(const std::string& name); static TypeAlias* DeclareType(const Identifier* name, const Type* type); - static const TypeAlias* PredeclareTypeAlias(const Identifier* name, - TypeDeclaration* type, - bool redeclaration); + static TypeAlias* PredeclareTypeAlias(const Identifier* name, + TypeDeclaration* type, + bool redeclaration); static TorqueMacro* CreateTorqueMacro(std::string external_name, std::string readable_name, bool exported_to_csa,