V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
declaration-visitor.h
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_TORQUE_DECLARATION_VISITOR_H_
6 #define V8_TORQUE_DECLARATION_VISITOR_H_
7 
8 #include <set>
9 #include <string>
10 
11 #include "src/base/macros.h"
12 #include "src/torque/declarations.h"
13 #include "src/torque/file-visitor.h"
14 #include "src/torque/global-context.h"
15 #include "src/torque/types.h"
16 #include "src/torque/utils.h"
17 
18 namespace v8 {
19 namespace internal {
20 namespace torque {
21 
23  public:
24  void Visit(Ast* ast) {
25  CurrentScope::Scope current_namespace(GlobalContext::GetDefaultNamespace());
26  for (Declaration* child : ast->declarations()) Visit(child);
27  }
28 
29  void Visit(Declaration* decl);
30 
31  Namespace* GetOrCreateNamespace(const std::string& name) {
32  std::vector<Namespace*> existing_namespaces = FilterDeclarables<Namespace>(
33  Declarations::TryLookupShallow(QualifiedName(name)));
34  if (existing_namespaces.empty()) {
35  return Declarations::DeclareNamespace(name);
36  }
37  DCHECK_EQ(1, existing_namespaces.size());
38  return existing_namespaces.front();
39  }
40 
41  void Visit(NamespaceDeclaration* decl) {
42  CurrentScope::Scope current_scope(GetOrCreateNamespace(decl->name));
43  for (Declaration* child : decl->declarations) Visit(child);
44  }
45 
46  void Visit(TypeDeclaration* decl);
47 
48  void Visit(TypeAliasDeclaration* decl) {
49  const Type* type = Declarations::GetType(decl->type);
50  type->AddAlias(decl->name);
51  Declarations::DeclareType(decl->name, type, true);
52  }
53 
54  Builtin* CreateBuiltin(BuiltinDeclaration* decl, std::string external_name,
55  std::string readable_name, Signature signature,
57  void Visit(ExternalBuiltinDeclaration* decl, const Signature& signature,
59  Declarations::Declare(
60  decl->name,
61  CreateBuiltin(decl, decl->name, decl->name, signature, base::nullopt));
62  }
63 
64  void Visit(ExternalRuntimeDeclaration* decl, const Signature& sig,
66  void Visit(ExternalMacroDeclaration* decl, const Signature& sig,
68  void Visit(TorqueBuiltinDeclaration* decl, const Signature& signature,
70  void Visit(TorqueMacroDeclaration* decl, const Signature& signature,
72  void Visit(IntrinsicDeclaration* decl, const Signature& signature,
74 
75  void Visit(CallableNode* decl, const Signature& signature,
77 
78  void Visit(ConstDeclaration* decl);
79  void Visit(StandardDeclaration* decl);
80  void Visit(GenericDeclaration* decl);
81  void Visit(SpecializationDeclaration* decl);
82  void Visit(ExternConstDeclaration* decl);
83  void Visit(StructDeclaration* decl);
84 
85  Signature MakeSpecializedSignature(const SpecializationKey& key);
86  Callable* SpecializeImplicit(const SpecializationKey& key);
87  Callable* Specialize(const SpecializationKey& key, CallableNode* declaration,
90 
91  private:
92  void DeclareSpecializedTypes(const SpecializationKey& key);
93 };
94 
95 } // namespace torque
96 } // namespace internal
97 } // namespace v8
98 
99 #endif // V8_TORQUE_DECLARATION_VISITOR_H_
Definition: libplatform.h:13