diff --git a/src/torque/declarable.h b/src/torque/declarable.h index ef829f1446..fab1ef0542 100644 --- a/src/torque/declarable.h +++ b/src/torque/declarable.h @@ -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 body) + base::Optional 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 body) + bool transitioning, base::Optional 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_; }; diff --git a/src/torque/declaration-visitor.cc b/src/torque/declaration-visitor.cc index 1a553afbcb..7d0e11d236 100644 --- a/src/torque/declaration-visitor.cc +++ b/src/torque/declaration-visitor.cc @@ -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(MakeNode( parameter, MakeNode(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( @@ -593,7 +593,7 @@ void DeclarationVisitor::FinalizeClassFieldsAndMethods( parameter, MakeNode(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); diff --git a/src/torque/declarations.cc b/src/torque/declarations.cc index fb08980a0e..833c57865e 100644 --- a/src/torque/declarations.cc +++ b/src/torque/declarations.cc @@ -211,27 +211,28 @@ ClassType* Declarations::DeclareClass(const Type* super_type, Macro* Declarations::CreateMacro( std::string external_name, std::string readable_name, base::Optional external_assembler_name, Signature signature, - bool transitioning, base::Optional body) { + bool transitioning, base::Optional body, bool is_user_defined) { if (!external_assembler_name) { external_assembler_name = CurrentNamespace()->ExternalName(); } return RegisterDeclarable(std::unique_ptr( 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 external_assembler_name, const Signature& signature, bool transitioning, - base::Optional body, base::Optional op) { + base::Optional body, base::Optional 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())) { diff --git a/src/torque/declarations.h b/src/torque/declarations.h index 75dd4b0459..f4de27779e 100644 --- a/src/torque/declarations.h +++ b/src/torque/declarations.h @@ -92,12 +92,14 @@ class Declarations { std::string readable_name, base::Optional external_assembler_name, Signature signature, bool transitioning, - base::Optional body); + base::Optional body, + bool is_user_defined); static Macro* DeclareMacro( const std::string& name, base::Optional external_assembler_name, const Signature& signature, bool transitioning, - base::Optional body, base::Optional op = {}); + base::Optional body, base::Optional op = {}, + bool is_user_defined = true); static Method* CreateMethod(AggregateType* class_type, const std::string& name, Signature signature,