forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltins.h
48 lines (35 loc) · 1.47 KB
/
builtins.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_EXPLORER_INTERPRETER_BUILTINS_H_
#define CARBON_EXPLORER_INTERPRETER_BUILTINS_H_
#include <optional>
#include "common/error.h"
#include "explorer/ast/declaration.h"
#include "explorer/ast/expression.h"
#include "explorer/common/nonnull.h"
#include "explorer/common/source_location.h"
#include "explorer/interpreter/value.h"
namespace Carbon {
class Builtins {
public:
explicit Builtins() {}
enum class Builtin { ImplicitAs, Last = ImplicitAs };
// TODO: In C++20, replace with `using enum Builtin;`.
static constexpr Builtin ImplicitAs = Builtin::ImplicitAs;
// Register a declaration that might be a builtin.
void Register(Nonnull<const Declaration*> decl);
// Get a registered builtin.
auto Get(SourceLocation source_loc, Builtin builtin) const
-> ErrorOr<Nonnull<const Declaration*>>;
// Get the source name of a builtin.
static constexpr auto GetName(Builtin builtin) -> const char* {
return BuiltinNames[static_cast<int>(builtin)];
}
private:
static constexpr int NumBuiltins = static_cast<int>(Builtin::Last) + 1;
static constexpr const char* BuiltinNames[NumBuiltins] = {"ImplicitAs"};
std::optional<Nonnull<const Declaration*>> builtins_[NumBuiltins] = {};
};
} // namespace Carbon
#endif // CARBON_EXPLORER_INTERPRETER_BUILTINS_H_