v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
declaration-visitor.h
Go to the documentation of this file.
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 <optional>
9#include <string>
10
11#include "src/base/macros.h"
15#include "src/torque/types.h"
16#include "src/torque/utils.h"
17
18namespace v8::internal::torque {
19
20Namespace* GetOrCreateNamespace(const std::string& name);
21
23 public:
24 static void Predeclare(Ast* ast) {
25 CurrentScope::Scope current_namespace(GlobalContext::GetDefaultNamespace());
26 for (Declaration* child : ast->declarations()) Predeclare(child);
27 }
28 static void ResolvePredeclarations();
29
30 private:
31 static void Predeclare(Declaration* decl);
32 static void Predeclare(NamespaceDeclaration* decl) {
33 CurrentScope::Scope current_scope(GetOrCreateNamespace(decl->name));
34 for (Declaration* child : decl->declarations) Predeclare(child);
35 }
36 static void Predeclare(TypeDeclaration* decl) {
37 TypeAlias* alias =
38 Declarations::PredeclareTypeAlias(decl->name, decl, false);
39 alias->SetPosition(decl->pos);
40 alias->SetIdentifierPosition(decl->name->pos);
43 }
44 }
45 static void Predeclare(StructDeclaration* decl) {
46 TypeAlias* alias =
47 Declarations::PredeclareTypeAlias(decl->name, decl, false);
48 alias->SetPosition(decl->pos);
49 alias->SetIdentifierPosition(decl->name->pos);
52 }
53 }
54 static void Predeclare(GenericTypeDeclaration* generic_decl) {
56 generic_decl);
57 }
58 static void Predeclare(GenericCallableDeclaration* generic_decl) {
60 generic_decl);
61 }
62};
63
65 public:
66 static void Visit(Ast* ast) {
67 CurrentScope::Scope current_namespace(GlobalContext::GetDefaultNamespace());
68 for (Declaration* child : ast->declarations()) Visit(child);
69 }
70 static void Visit(Declaration* decl);
71 static void Visit(NamespaceDeclaration* decl) {
72 CurrentScope::Scope current_scope(GetOrCreateNamespace(decl->name));
73 for (Declaration* child : decl->declarations) Visit(child);
74 }
75
76 static void Visit(TypeDeclaration* decl) {
77 // Looking up the type will trigger type computation; this ensures errors
78 // are reported even if the type is unused.
80 }
81 static void Visit(StructDeclaration* decl) {
83 }
84
86 std::string external_name,
87 std::string readable_name, Signature signature,
88 std::optional<std::string> use_counter_name,
89 std::optional<Statement*> body);
90
91 static void Visit(ExternalBuiltinDeclaration* decl);
92 static void Visit(ExternalRuntimeDeclaration* decl);
93 static void Visit(ExternalMacroDeclaration* decl);
94 static void Visit(TorqueBuiltinDeclaration* decl);
95 static void Visit(TorqueMacroDeclaration* decl);
96 static void Visit(IntrinsicDeclaration* decl);
97
98 static void Visit(ConstDeclaration* decl);
99 static void Visit(GenericCallableDeclaration* decl) {
100 // The PredeclarationVisitor already handled this case.
101 }
102 static void Visit(GenericTypeDeclaration* decl) {
103 // The PredeclarationVisitor already handled this case.
104 }
105 static void Visit(SpecializationDeclaration* decl);
106 static void Visit(ExternConstDeclaration* decl);
107 static void Visit(CppIncludeDeclaration* decl);
108
113 static Callable* Specialize(
116 std::optional<const SpecializationDeclaration*> explicit_specialization,
117 std::optional<Statement*> body, SourcePosition position);
118
119 private:
120 static void DeclareSpecializedTypes(
122};
123
124} // namespace v8::internal::torque
125
126#endif // V8_TORQUE_DECLARATION_VISITOR_H_
std::vector< Declaration * > & declarations()
Definition ast.h:216
void SetIdentifierPosition(const SourcePosition &position)
Definition declarable.h:107
void SetPosition(const SourcePosition &position)
Definition declarable.h:97
static Signature MakeSpecializedSignature(const SpecializationKey< GenericCallable > &key)
static void Visit(GenericTypeDeclaration *decl)
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 Visit(TypeDeclaration *decl)
static void Visit(StructDeclaration *decl)
static void DeclareSpecializedTypes(const SpecializationKey< GenericCallable > &key)
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 void Visit(GenericCallableDeclaration *decl)
static void Visit(NamespaceDeclaration *decl)
static GenericCallable * DeclareGenericCallable(const std::string &name, GenericCallableDeclaration *ast_node)
static const Type * LookupType(const QualifiedName &name)
static TypeAlias * PredeclareTypeAlias(const Identifier *name, TypeDeclaration *type, bool redeclaration)
static GenericType * DeclareGenericType(const std::string &name, GenericTypeDeclaration *ast_node)
static Namespace * GetDefaultNamespace()
static V8_EXPORT_PRIVATE kythe_entity_t AddTypeDefinition(const Declarable *type_decl)
static void Predeclare(NamespaceDeclaration *decl)
static void Predeclare(GenericTypeDeclaration *generic_decl)
static void Predeclare(TypeDeclaration *decl)
static void Predeclare(StructDeclaration *decl)
static void Predeclare(GenericCallableDeclaration *generic_decl)
int position
Definition liveedit.cc:290
Namespace * GetOrCreateNamespace(const std::string &name)
SourcePosition pos
Definition ast.h:112
std::vector< Declaration * > declarations
Definition ast.h:185
Symbol declaration