Line data Source code
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 111264 : std::vector<T*> FilterDeclarables(const std::vector<Declarable*> list) {
23 : std::vector<T*> result;
24 329827 : for (Declarable* declarable : list) {
25 107299 : if (T* t = T::DynamicCast(declarable)) {
26 106066 : result.push_back(t);
27 : }
28 : }
29 111264 : return result;
30 : }
31 :
32 : class Declarations {
33 : public:
34 32570 : static std::vector<Declarable*> TryLookup(const QualifiedName& name) {
35 32570 : return CurrentScope::Get()->Lookup(name);
36 : }
37 :
38 4102 : static std::vector<Declarable*> TryLookupShallow(const QualifiedName& name) {
39 4102 : return CurrentScope::Get()->LookupShallow(name);
40 : }
41 :
42 : template <class T>
43 1589 : static std::vector<T*> TryLookup(const QualifiedName& name) {
44 3178 : return FilterDeclarables<T>(TryLookup(name));
45 : }
46 :
47 30981 : static std::vector<Declarable*> Lookup(const QualifiedName& name) {
48 30981 : std::vector<Declarable*> d = TryLookup(name);
49 30981 : if (d.empty()) {
50 0 : ReportError("cannot find \"", name, "\"");
51 : }
52 30981 : return d;
53 : }
54 :
55 : static std::vector<Declarable*> LookupGlobalScope(const std::string& name);
56 :
57 : static const Type* LookupType(const QualifiedName& name);
58 : static const Type* LookupType(std::string name);
59 : static const Type* LookupGlobalType(const std::string& name);
60 : static const Type* GetType(TypeExpression* type_expression);
61 :
62 : static Builtin* FindSomeInternalBuiltinWithType(
63 : const BuiltinPointerType* type);
64 :
65 : static Value* LookupValue(const QualifiedName& name);
66 :
67 : static Macro* TryLookupMacro(const std::string& name,
68 : const TypeVector& types);
69 : static base::Optional<Builtin*> TryLookupBuiltin(const QualifiedName& name);
70 :
71 : static std::vector<Generic*> LookupGeneric(const std::string& name);
72 : static Generic* LookupUniqueGeneric(const QualifiedName& name);
73 :
74 : static Namespace* DeclareNamespace(const std::string& name);
75 :
76 : static const AbstractType* DeclareAbstractType(
77 : const std::string& name, bool transient, const std::string& generated,
78 : base::Optional<const AbstractType*> non_constexpr_version,
79 : const base::Optional<std::string>& parent = {});
80 :
81 : static void DeclareType(const std::string& name, const Type* type,
82 : bool redeclaration);
83 :
84 : static StructType* DeclareStruct(const std::string& name,
85 : const std::vector<Field>& fields);
86 :
87 : static ClassType* DeclareClass(base::Optional<std::string> parent,
88 : const std::string& name, bool transient,
89 : const std::string& generates,
90 : std::vector<Field> fields, size_t size);
91 :
92 : static Macro* CreateMacro(std::string external_name,
93 : std::string readable_name,
94 : base::Optional<std::string> external_assembler_name,
95 : Signature signature, bool transitioning,
96 : base::Optional<Statement*> body);
97 : static Macro* DeclareMacro(
98 : const std::string& name,
99 : base::Optional<std::string> external_assembler_name,
100 : const Signature& signature, bool transitioning,
101 : base::Optional<Statement*> body, base::Optional<std::string> op = {});
102 :
103 : static Method* CreateMethod(AggregateType* class_type,
104 : const std::string& name, Signature signature,
105 : bool transitioning, Statement* body);
106 :
107 : static Intrinsic* CreateIntrinsic(const std::string& name,
108 : const Signature& signature);
109 :
110 : static Intrinsic* DeclareIntrinsic(const std::string& name,
111 : const Signature& signature);
112 :
113 : static Builtin* CreateBuiltin(std::string external_name,
114 : std::string readable_name, Builtin::Kind kind,
115 : Signature signature, bool transitioning,
116 : base::Optional<Statement*> body);
117 : static Builtin* DeclareBuiltin(const std::string& name, Builtin::Kind kind,
118 : const Signature& signature, bool transitioning,
119 : base::Optional<Statement*> body);
120 :
121 : static RuntimeFunction* DeclareRuntimeFunction(const std::string& name,
122 : const Signature& signature,
123 : bool transitioning);
124 :
125 : static void DeclareExternConstant(const std::string& name, const Type* type,
126 : std::string value);
127 : static NamespaceConstant* DeclareNamespaceConstant(const std::string& name,
128 : const Type* type,
129 : Expression* body);
130 :
131 : static Generic* DeclareGeneric(const std::string& name,
132 : GenericDeclaration* generic);
133 :
134 : template <class T>
135 675 : static T* Declare(const std::string& name, T* d) {
136 675 : CurrentScope::Get()->AddDeclarable(name, d);
137 675 : return d;
138 : }
139 : template <class T>
140 4012 : static T* Declare(const std::string& name, std::unique_ptr<T> d) {
141 : return CurrentScope::Get()->AddDeclarable(name,
142 8024 : RegisterDeclarable(std::move(d)));
143 : }
144 : static Macro* DeclareOperator(const std::string& name, Macro* m);
145 :
146 : static std::string GetGeneratedCallableName(
147 : const std::string& name, const TypeVector& specialized_types);
148 : };
149 :
150 : } // namespace torque
151 : } // namespace internal
152 : } // namespace v8
153 :
154 : #endif // V8_TORQUE_DECLARATIONS_H_
|