20 if (existing_namespaces.empty()) {
24 return existing_namespaces.front();
28 CurrentSourcePosition::Scope scope(decl->
pos);
30#define ENUM_ITEM(name) \
31 case AstNode::Kind::k##name: \
32 return Predeclare(name::cast(decl));
35 case AstNode::Kind::kNamespaceDeclaration:
36 return Predeclare(NamespaceDeclaration::cast(decl));
37 case AstNode::Kind::kGenericCallableDeclaration:
38 return Predeclare(GenericCallableDeclaration::cast(decl));
39 case AstNode::Kind::kGenericTypeDeclaration:
40 return Predeclare(GenericTypeDeclaration::cast(decl));
49 CurrentSourcePosition::Scope scope(decl->
pos);
51#define ENUM_ITEM(name) \
52 case AstNode::Kind::k##name: \
53 return Visit(name::cast(decl));
63 std::string readable_name,
Signature signature,
64 std::optional<std::string> use_counter_name,
65 std::optional<Statement*> body) {
71 bool has_custom_interface_descriptor =
false;
72 if (decl->
kind == AstNode::Kind::kTorqueBuiltinDeclaration) {
73 has_custom_interface_descriptor =
75 ->has_custom_interface_descriptor;
78 if (varargs && !javascript) {
79 Error(
"Rest parameters require ", decl->
name,
80 " to be a JavaScript builtin");
85 Error(
"Return type of JavaScript-linkage builtins has to be JSAny.")
100 if (decl->
kind != AstNode::Kind::kExternalBuiltinDeclaration) {
106 "Parameters of JavaScript-linkage builtins have to be a "
116 const Type* parameter_type = signature.
types()[
i];
118 Error(
"Builtin do not support structs as arguments, but argument ",
123 if (!has_custom_interface_descriptor) {
124 Error(
"Builtin ", external_name,
125 " needs a custom interface descriptor, "
126 "because it uses type ",
128 ". One reason being "
129 "that the default descriptor defines xmm0 to be the first "
130 "floating point argument register, which is current used as "
131 "scratch on ia32 and cannot be allocated.");
136 if (signature.
return_type->StructSupertype() && javascript) {
138 "Builtins with JS linkage cannot return structs, but the return type "
144 Error(
"Builtins cannot have return type void.");
148 if (has_custom_interface_descriptor)
151 std::move(external_name), std::move(readable_name),
kind, flags,
152 std::move(signature), std::move(use_counter_name), body);
161 std::nullopt, std::nullopt);
162 builtin->SetIdentifierPosition(decl->
name->
pos);
170 "Missing parameters for runtime function, at least the context "
171 "parameter is required.");
176 "first parameter to runtime functions has to be the context and have "
177 "type Context or NoContext, but found type ",
184 "runtime functions can only return strong tagged values, but "
191 "runtime functions can only take strong tagged parameters, but "
199 function->SetIdentifierPosition(decl->
name->
pos);
200 function->SetPosition(decl->
pos);
210 macro->SetIdentifierPosition(decl->
name->
pos);
211 macro->SetPosition(decl->
pos);
220 (signature.
types().empty() ||
224 "@incrementUseCounter requires the builtin's first parameter to be of "
225 "type Context or NativeContext, but found type ",
226 *signature.
types()[0]);
230 builtin->SetIdentifierPosition(decl->
name->
pos);
231 builtin->SetPosition(decl->
pos);
239 macro->SetIdentifierPosition(decl->
name->
pos);
240 macro->SetPosition(decl->
pos);
260 std::vector<GenericCallable*> generic_list =
277 if (signature_with_types.
HasSameTypesAs(generic_signature_with_types,
279 if (matching_generic !=
nullptr) {
280 std::stringstream stream;
281 stream <<
"specialization of " << decl->
name
282 <<
" is ambigous, it matches more than one generic declaration ("
283 << *matching_generic <<
" and " << *
generic <<
")";
286 matching_generic =
generic;
290 if (matching_generic ==
nullptr) {
291 std::stringstream stream;
292 if (generic_list.empty()) {
293 stream <<
"no generic defined with the name " << decl->
name;
296 stream <<
"specialization of " << decl->
name
297 <<
" doesn't match any generic declaration\n";
298 stream <<
"specialization signature:";
299 stream <<
"\n " << signature_with_types;
300 stream <<
"\ncandidates are:";
320 generic_declaration, decl, decl->
body, decl->
pos);
325 if (!type->IsConstexpr()) {
326 std::stringstream stream;
327 stream <<
"extern constants must have constexpr type, but found: \""
346 const std::size_t generic_parameter_count =
348 if (generic_parameter_count !=
key.specialized_types.size()) {
349 std::stringstream stream;
350 stream <<
"Wrong generic argument count for specialization of \""
351 <<
key.generic->name() <<
"\", expected: " << generic_parameter_count
352 <<
", actual: " <<
key.specialized_types.size();
356 for (
auto type :
key.specialized_types) {
357 Identifier* generic_type_name =
key.generic->generic_parameters()[
i++].name;
365 CurrentScope::Scope generic_scope(
key.generic->ParentScope());
369 CurrentScope::Scope tmp_namespace_scope(&tmp_namespace);
376 std::optional<Statement*> body =
key.generic->CallableBody();
377 if (!body && IntrinsicDeclaration::DynamicCast(
key.generic->declaration()) ==
380 " with types <",
key.specialized_types,
"> declared at ",
381 key.generic->Position());
384 CurrentScope::Get(),
""};
385 CurrentScope::Scope generic_scope(
key.generic->ParentScope());
387 body, CurrentSourcePosition::Get());
388 result->SetIsUserDefined(
false);
389 requester.name =
result->ReadableName();
390 result->SetSpecializationRequester(requester);
391 CurrentScope::Scope callable_scope(
result);
399 std::optional<const SpecializationDeclaration*> explicit_specialization,
401 CurrentSourcePosition::Scope pos_scope(
position);
402 size_t generic_parameter_count =
key.generic->generic_parameters().size();
403 if (generic_parameter_count !=
key.specialized_types.size()) {
404 std::stringstream stream;
405 stream <<
"number of template parameters ("
406 << std::to_string(
key.specialized_types.size())
407 <<
") to intantiation of generic " <<
declaration->name
408 <<
" doesnt match the generic's declaration ("
409 << std::to_string(generic_parameter_count) <<
")";
412 if (
key.generic->GetSpecialization(
key.specialized_types)) {
413 ReportError(
"cannot redeclare specialization of ",
key.generic->name(),
414 " with types <",
key.specialized_types,
">");
418 explicit_specialization
424 std::stringstream readable_name;
427 for (
const Type* t :
key.specialized_types) {
428 if (!first) readable_name <<
", ";
432 readable_name <<
">";
434 if (MacroDeclaration::DynamicCast(
declaration) !=
nullptr) {
437 false, type_signature, *body,
true);
438 }
else if (IntrinsicDeclaration::DynamicCast(
declaration) !=
nullptr) {
443 std::optional<std::string> use_counter_name;
445 TorqueBuiltinDeclaration::DynamicCast(builtin)) {
446 use_counter_name = torque_builtin->use_counter_name;
448 use_counter_name = std::nullopt;
452 readable_name.str(), type_signature, use_counter_name, *body);
454 key.generic->AddSpecialization(
key.specialized_types, callable);
460 for (
size_t i = 0;
i < all_declarables.
size(); ++
i) {
462 if (
const TypeAlias* alias = TypeAlias::DynamicCast(declarable)) {
463 CurrentScope::Scope scope_activator(alias->ParentScope());
464 CurrentSourcePosition::Scope position_activator(alias->Position());
@ kCustomInterfaceDescriptor
SourcePosition IdentifierPosition() const
void SetIsUserDefined(bool is_user_defined)
static Signature MakeSpecializedSignature(const SpecializationKey< GenericCallable > &key)
static Callable * SpecializeImplicit(const SpecializationKey< GenericCallable > &key)
static Callable * Specialize(const SpecializationKey< GenericCallable > &key, CallableDeclaration *declaration, std::optional< const SpecializationDeclaration * > explicit_specialization, std::optional< Statement * > body, SourcePosition position)
static void DeclareSpecializedTypes(const SpecializationKey< GenericCallable > &key)
static void Visit(Ast *ast)
static Builtin * CreateBuiltin(BuiltinDeclaration *decl, std::string external_name, std::string readable_name, Signature signature, std::optional< std::string > use_counter_name, std::optional< Statement * > body)
static Intrinsic * CreateIntrinsic(const std::string &name, const Signature &signature)
static TypeAlias * DeclareType(const Identifier *name, const Type *type)
static TorqueMacro * CreateTorqueMacro(std::string external_name, std::string readable_name, bool exported_to_csa, Signature signature, std::optional< Statement * > body, bool is_user_defined)
static T * Declare(const std::string &name, T *d)
static Macro * DeclareMacro(const std::string &name, bool accessible_from_csa, std::optional< std::string > external_assembler_name, const Signature &signature, std::optional< Statement * > body, std::optional< std::string > op={}, bool is_user_defined=true)
static std::vector< Declarable * > TryLookupShallow(const QualifiedName &name)
static ExternConstant * DeclareExternConstant(Identifier *name, const Type *type, std::string value)
static Builtin * CreateBuiltin(std::string external_name, std::string readable_name, Builtin::Kind kind, Builtin::Flags flags, Signature signature, std::optional< std::string > use_counter_name, std::optional< Statement * > body)
static Namespace * DeclareNamespace(const std::string &name)
static std::vector< GenericCallable * > LookupGeneric(const std::string &name)
static RuntimeFunction * DeclareRuntimeFunction(const std::string &name, const Signature &signature)
static Intrinsic * DeclareIntrinsic(const std::string &name, const Signature &signature)
static std::string GetGeneratedCallableName(const std::string &name, const TypeVector &specialized_types)
static NamespaceConstant * DeclareNamespaceConstant(Identifier *name, const Type *type, Expression *body)
static void AddCppInclude(std::string include_path)
static const std::vector< std::unique_ptr< Declarable > > & AllDeclarables()
static bool collect_language_server_data()
static std::string MakeUniqueName(const std::string &base)
static bool collect_kythe_data()
static V8_EXPORT_PRIVATE kythe_entity_t AddConstantDefinition(const Value *constant)
static V8_EXPORT_PRIVATE kythe_entity_t AddFunctionDefinition(Callable *callable)
static V8_EXPORT_PRIVATE void AddDefinition(SourcePosition token, SourcePosition definition)
MessageBuilder & Position(SourcePosition position)
static void ResolvePredeclarations()
static void Predeclare(Ast *ast)
static const Type * GetStrongTaggedType()
static const Type * GetNoContextType()
static const Type * GetNativeContextType()
static const Type * GetVoidType()
static const Type * GetContextType()
static const Type * GetJSAnyType()
static const Type * GetNeverType()
static TypeVector ComputeTypeVector(const std::vector< TypeExpression * > &v)
static const Type * ComputeType(TypeExpression *type_expression)
static Signature MakeSignature(const CallableDeclaration *declaration)
virtual bool IsSubtypeOf(const Type *supertype) const
std::optional< const StructType * > StructSupertype() const
ZoneVector< RpoNumber > & result
void ReportError(Args &&... args)
Namespace * GetOrCreateNamespace(const std::string &name)
std::vector< T * > FilterDeclarables(const std::vector< Declarable * > list)
MessageBuilder Error(Args &&... args)
#define DCHECK_EQ(v1, v2)
TypeExpression * return_type
std::string external_assembler_name
std::optional< std::string > op
std::vector< TypeExpression * > types
NameVector parameter_names
ParameterTypes parameter_types
bool HasSameTypesAs(const Signature &other, ParameterMode mode=ParameterMode::kProcessImplicit) const
const TypeVector & types() const
std::vector< TypeExpression * > generic_parameters
std::optional< std::string > use_counter_name
std::optional< Statement * > body
std::optional< Statement * > body
#define AST_DECLARATION_NODE_KIND_LIST(V)
#define AST_TYPE_DECLARATION_NODE_KIND_LIST(V)