-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
builtins.h
62 lines (46 loc) · 1.71 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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 <array>
#include <optional>
#include <string_view>
#include "common/enum_base.h"
#include "common/error.h"
#include "explorer/ast/declaration.h"
#include "explorer/ast/expression.h"
#include "explorer/ast/value.h"
#include "explorer/base/nonnull.h"
#include "explorer/base/source_location.h"
namespace Carbon {
CARBON_DEFINE_RAW_ENUM_CLASS(Builtin, int) {
#define CARBON_BUILTIN(Name) CARBON_RAW_ENUM_ENUMERATOR(Name)
#include "explorer/interpreter/builtins.def"
};
class Builtin : public CARBON_ENUM_BASE(Builtin) {
public:
#define CARBON_BUILTIN(Name) CARBON_ENUM_CONSTANT_DECL(Name)
#include "explorer/interpreter/builtins.def"
static const int NumBuiltins;
// Support conversion to and from an int for array indexing.
using EnumBase::AsInt;
using EnumBase::FromInt;
};
#define CARBON_BUILTIN(Name) CARBON_ENUM_CONSTANT_DEFINITION(Builtin, Name)
#include "explorer/interpreter/builtins.def"
constexpr int Builtin::NumBuiltins = Invalid.AsInt();
class Builtins {
public:
explicit Builtins() = default;
// 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*>>;
private:
std::optional<Nonnull<const Declaration*>> builtins_[Builtin::NumBuiltins] =
{};
};
} // namespace Carbon
#endif // CARBON_EXPLORER_INTERPRETER_BUILTINS_H_