Commit 17e7cf55 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque] Introduce is_user_defined flag for Torque macros

The Torque compiler generates macros for accessing fields in classes.
These are currently indistiguishable from user defined macros. To
improve the upcoming symbol search in the Torque Language Server, this
CL introduces a flag on macros to differentiate user defined and auto
generated macros.

R=sigurds@chromium.org

Bug: v8:7793
Change-Id: I84a8ab14535ec779494b5b2e887fda8fc4edf3e5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1598688Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61261}
parent ac377868
......@@ -312,14 +312,17 @@ class Macro : public Callable {
return external_assembler_name_;
}
bool is_user_defined() const { return is_user_defined_; }
protected:
Macro(Declarable::Kind kind, std::string external_name,
std::string readable_name, std::string external_assembler_name,
const Signature& signature, bool transitioning,
base::Optional<Statement*> body)
base::Optional<Statement*> body, bool is_user_defined)
: Callable(kind, std::move(external_name), std::move(readable_name),
signature, transitioning, body),
external_assembler_name_(std::move(external_assembler_name)) {
external_assembler_name_(std::move(external_assembler_name)),
is_user_defined_(is_user_defined) {
if (signature.parameter_types.var_args) {
ReportError("Varargs are not supported for macros.");
}
......@@ -329,12 +332,14 @@ class Macro : public Callable {
friend class Declarations;
Macro(std::string external_name, std::string readable_name,
std::string external_assembler_name, const Signature& signature,
bool transitioning, base::Optional<Statement*> body)
bool transitioning, base::Optional<Statement*> body,
bool is_user_defined)
: Macro(Declarable::kMacro, std::move(external_name),
std::move(readable_name), external_assembler_name, signature,
transitioning, body) {}
transitioning, body, is_user_defined) {}
std::string external_assembler_name_;
bool is_user_defined_;
};
class Method : public Macro {
......@@ -355,7 +360,7 @@ class Method : public Macro {
const Signature& signature, bool transitioning, Statement* body)
: Macro(Declarable::kMethod, std::move(external_name),
std::move(readable_name), std::move(external_assembler_name),
signature, transitioning, body),
signature, transitioning, body, true),
aggregate_type_(aggregate_type) {}
AggregateType* aggregate_type_;
};
......
......@@ -449,9 +449,9 @@ Callable* DeclarationVisitor::Specialize(
readable_name << ">";
Callable* callable;
if (MacroDeclaration::DynamicCast(declaration) != nullptr) {
callable = Declarations::CreateMacro(generated_name, readable_name.str(),
base::nullopt, type_signature,
declaration->transitioning, *body);
callable = Declarations::CreateMacro(
generated_name, readable_name.str(), base::nullopt, type_signature,
declaration->transitioning, *body, true);
} else if (IntrinsicDeclaration::DynamicCast(declaration) != nullptr) {
callable = Declarations::CreateIntrinsic(declaration->name, type_signature);
} else {
......@@ -572,7 +572,7 @@ void DeclarationVisitor::FinalizeClassFieldsAndMethods(
MakeNode<ReturnStatement>(MakeNode<FieldAccessExpression>(
parameter, MakeNode<Identifier>(field.name_and_type.name)));
Declarations::DeclareMacro(load_macro_name, base::nullopt, load_signature,
false, load_body);
false, load_body, base::nullopt, false);
// Store accessor
IdentifierExpression* value = MakeNode<IdentifierExpression>(
......@@ -593,7 +593,7 @@ void DeclarationVisitor::FinalizeClassFieldsAndMethods(
parameter, MakeNode<Identifier>(field.name_and_type.name)),
value));
Declarations::DeclareMacro(store_macro_name, base::nullopt, store_signature,
false, store_body);
false, store_body, base::nullopt, false);
}
DeclareMethods(class_type, class_declaration->methods);
......
......@@ -211,27 +211,28 @@ ClassType* Declarations::DeclareClass(const Type* super_type,
Macro* Declarations::CreateMacro(
std::string external_name, std::string readable_name,
base::Optional<std::string> external_assembler_name, Signature signature,
bool transitioning, base::Optional<Statement*> body) {
bool transitioning, base::Optional<Statement*> body, bool is_user_defined) {
if (!external_assembler_name) {
external_assembler_name = CurrentNamespace()->ExternalName();
}
return RegisterDeclarable(std::unique_ptr<Macro>(
new Macro(std::move(external_name), std::move(readable_name),
std::move(*external_assembler_name), std::move(signature),
transitioning, body)));
transitioning, body, is_user_defined)));
}
Macro* Declarations::DeclareMacro(
const std::string& name,
base::Optional<std::string> external_assembler_name,
const Signature& signature, bool transitioning,
base::Optional<Statement*> body, base::Optional<std::string> op) {
base::Optional<Statement*> body, base::Optional<std::string> op,
bool is_user_defined) {
if (TryLookupMacro(name, signature.GetExplicitTypes())) {
ReportError("cannot redeclare macro ", name,
" with identical explicit parameters");
}
Macro* macro = CreateMacro(name, name, std::move(external_assembler_name),
signature, transitioning, body);
signature, transitioning, body, is_user_defined);
Declare(name, macro);
if (op) {
if (TryLookupMacro(*op, signature.GetExplicitTypes())) {
......
......@@ -92,12 +92,14 @@ class Declarations {
std::string readable_name,
base::Optional<std::string> external_assembler_name,
Signature signature, bool transitioning,
base::Optional<Statement*> body);
base::Optional<Statement*> body,
bool is_user_defined);
static Macro* DeclareMacro(
const std::string& name,
base::Optional<std::string> external_assembler_name,
const Signature& signature, bool transitioning,
base::Optional<Statement*> body, base::Optional<std::string> op = {});
base::Optional<Statement*> body, base::Optional<std::string> op = {},
bool is_user_defined = true);
static Method* CreateMethod(AggregateType* class_type,
const std::string& name, Signature signature,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment