V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
declarations.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_DECLARATIONS_H_
6 #define V8_TORQUE_DECLARATIONS_H_
7 
8 #include <string>
9 
10 #include "src/torque/declarable.h"
11 #include "src/torque/utils.h"
12 
13 namespace v8 {
14 namespace internal {
15 namespace torque {
16 
17 static constexpr const char* const kFromConstexprMacroName = "FromConstexpr";
18 static constexpr const char* kTrueLabelName = "_True";
19 static constexpr const char* kFalseLabelName = "_False";
20 
21 template <class T>
22 std::vector<T*> FilterDeclarables(const std::vector<Declarable*> list) {
23  std::vector<T*> result;
24  for (Declarable* declarable : list) {
25  if (T* t = T::DynamicCast(declarable)) {
26  result.push_back(t);
27  }
28  }
29  return result;
30 }
31 
32 class Declarations {
33  public:
34  static std::vector<Declarable*> TryLookup(const QualifiedName& name) {
35  return CurrentScope::Get()->Lookup(name);
36  }
37 
38  static std::vector<Declarable*> TryLookupShallow(const QualifiedName& name) {
39  return CurrentScope::Get()->LookupShallow(name);
40  }
41 
42  template <class T>
43  static std::vector<T*> TryLookup(const QualifiedName& name) {
44  return FilterDeclarables<T>(TryLookup(name));
45  }
46 
47  static std::vector<Declarable*> Lookup(const QualifiedName& name) {
48  std::vector<Declarable*> d = TryLookup(name);
49  if (d.empty()) {
50  std::stringstream s;
51  s << "cannot find \"" << name << "\"";
52  ReportError(s.str());
53  }
54  return d;
55  }
56 
57  static std::vector<Declarable*> LookupGlobalScope(const std::string& name);
58 
59  static const Type* LookupType(const QualifiedName& name);
60  static const Type* LookupType(std::string name);
61  static const Type* LookupGlobalType(const std::string& name);
62  static const Type* GetType(TypeExpression* type_expression);
63 
64  static Builtin* FindSomeInternalBuiltinWithType(
65  const FunctionPointerType* type);
66 
67  static Value* LookupValue(const QualifiedName& name);
68 
69  static Macro* TryLookupMacro(const std::string& name,
70  const TypeVector& types);
71  static base::Optional<Builtin*> TryLookupBuiltin(const QualifiedName& name);
72 
73  static std::vector<Generic*> LookupGeneric(const std::string& name);
74  static Generic* LookupUniqueGeneric(const QualifiedName& name);
75 
76  static Namespace* DeclareNamespace(const std::string& name);
77 
78  static const AbstractType* DeclareAbstractType(
79  const std::string& name, bool transient, const std::string& generated,
80  base::Optional<const AbstractType*> non_constexpr_version,
81  const base::Optional<std::string>& parent = {});
82 
83  static void DeclareType(const std::string& name, const Type* type,
84  bool redeclaration);
85 
86  static void DeclareStruct(const std::string& name,
87  const std::vector<NameAndType>& fields);
88 
89  static Macro* CreateMacro(std::string external_name,
90  std::string readable_name,
91  base::Optional<std::string> external_assembler_name,
92  Signature signature, bool transitioning,
94  static Macro* DeclareMacro(
95  const std::string& name,
96  base::Optional<std::string> external_assembler_name,
97  const Signature& signature, bool transitioning,
99 
100  static Intrinsic* CreateIntrinsic(const std::string& name,
101  const Signature& signature);
102 
103  static Intrinsic* DeclareIntrinsic(const std::string& name,
104  const Signature& signature);
105 
106  static Builtin* CreateBuiltin(std::string external_name,
107  std::string readable_name, Builtin::Kind kind,
108  Signature signature, bool transitioning,
110  static Builtin* DeclareBuiltin(const std::string& name, Builtin::Kind kind,
111  const Signature& signature, bool transitioning,
113 
114  static RuntimeFunction* DeclareRuntimeFunction(const std::string& name,
115  const Signature& signature,
116  bool transitioning);
117 
118  static void DeclareExternConstant(const std::string& name, const Type* type,
119  std::string value);
120  static NamespaceConstant* DeclareNamespaceConstant(const std::string& name,
121  const Type* type,
122  Expression* body);
123 
124  static Generic* DeclareGeneric(const std::string& name,
125  GenericDeclaration* generic);
126 
127  template <class T>
128  static T* Declare(const std::string& name, T* d) {
129  CurrentScope::Get()->AddDeclarable(name, d);
130  return d;
131  }
132  template <class T>
133  static T* Declare(const std::string& name, std::unique_ptr<T> d) {
134  return CurrentScope::Get()->AddDeclarable(name,
135  RegisterDeclarable(std::move(d)));
136  }
137 
138  static std::string GetGeneratedCallableName(
139  const std::string& name, const TypeVector& specialized_types);
140 };
141 
142 } // namespace torque
143 } // namespace internal
144 } // namespace v8
145 
146 #endif // V8_TORQUE_DECLARATIONS_H_
Definition: libplatform.h:13