14#include <llvm/Support/Casting.h>
15#include <llvm/Support/raw_ostream.h>
72 vector<GenericKey> generic = {}, vector<unique_ptr<ty::Generic>>
primary_generics = {})
76 [[nodiscard]]
auto fn_body() -> ast::FnDecl::Body&;
78 [[nodiscard]]
auto ast() const -> const
ast::Stmt&;
79 [[nodiscard]] auto
ast() ->
ast::Stmt&;
84 [[nodiscard]]
auto ret() const -> optional<ty::Type>;
85 [[nodiscard]] auto
arg_count() const ->
size_t;
86 [[nodiscard]] auto
arg_types() const -> vector<ty::Type>;
87 [[nodiscard]] auto
arg_names() const -> vector<
string>;
88 [[nodiscard]] auto
arg_nodes() const -> const vector<
ast::TypeName>&;
89 [[nodiscard]] auto
args() const -> vector<
FnArg>;
90 [[nodiscard]] auto
varargs() const ->
bool;
91 [[nodiscard]] auto
primitive() const ->
bool;
92 [[nodiscard]] auto
abstract() const ->
bool;
94 [[nodiscard]] auto
local() const ->
bool;
99 [[nodiscard]] auto
name() const noexcept ->
string;
105 template <std::invocable<
ast::TypeName&> F, typename..., typename T = std::invoke_result_t<F,
ast::TypeName&>>
106 auto visit_map_args(F fn) const -> std::vector<T> {
107 std::vector<T> vec = {};
110 for (
auto& i :
ast->args)
111 vec.emplace_back(std::move<T>(fn(i)));
123 auto args = llvm::zip(this->args, other.args);
124 auto opaque_eq = [](
const auto& p) {
return std::get<0>(p).opaque_equal(std::get<1>(p)); };
125 return this->name == other.name && std::all_of(
args.begin(),
args.end(), opaque_eq) &&
126 this->ret.has_value() == other.ret.has_value() && (!this->ret || this->ret->opaque_equal(*other.ret));
154 vector<GenericKey> generic = {}, vector<unique_ptr<ty::Generic>>
primary_generics = {})
noexcept
158 [[nodiscard]]
auto ast() const noexcept -> const auto& {
return st_ast; }
159 [[nodiscard]]
auto ast() noexcept -> auto& {
return st_ast; }
167 [[nodiscard]]
auto name() const noexcept ->
string;
185 [[nodiscard]]
auto ast() const noexcept -> const auto& {
return cn_ast; }
186 [[nodiscard]]
auto ast() noexcept -> auto& {
return cn_ast; }
189 [[nodiscard]]
auto name() const noexcept ->
string;
190 [[nodiscard]] auto referred_to_by(const
ast::ConstExpr& expr) const ->
bool {
191 if (
name() != expr.name)
194 if (
self_ty.has_value() != expr.parent.has_value())
197 if (
self_ty.has_value() && expr.parent.has_value())
198 return self_ty->name() == expr.parent.value();
213 if (
const auto*
subs = this->
subs(); subs !=
nullptr)
219 return visit([](std::monostate )
noexcept ->
const Substitutions* {
return nullptr; },
224 return &decl->get_subs();
229 return visit([](std::monostate )
noexcept ->
Substitutions* {
return nullptr; },
234 return &decl->get_subs();
238 [[nodiscard]]
auto ast() const noexcept -> const
ast::AST* {
239 return visit([](std::monostate )
noexcept ->
const ast::AST* {
return nullptr; },
240 [](
const auto* decl)
noexcept ->
const ast::AST* {
return &decl->ast(); });
243 [[nodiscard]]
auto ast() noexcept ->
ast::AST* {
244 return visit([](std::monostate )
noexcept ->
ast::AST* {
return nullptr; },
245 [](
auto* decl)
noexcept ->
ast::AST* {
return &decl->ast(); });
248 [[nodiscard]]
auto self_ty() const noexcept -> optional<ty::Type> {
249 return visit([](std::monostate )
noexcept {
return optional<ty::Type>{}; },
250 [](
const auto* decl)
noexcept {
return decl->get_self_ty(); });
255 [](
auto&& )
noexcept {
return false; });
266 Val(llvm::Value* llvm_val) noexcept :
llvm(llvm_val) {}
267 Val(llvm::Value* llvm_val,
InScope* scope_val) noexcept :
llvm(llvm_val), scope(scope_val) {}
269 operator llvm::Value*()
const {
return llvm; }
289 static auto name_or_stdin(
const fs::path& path) ->
string {
return path.empty() ?
"<stdin>"s : path.native(); }
292 : path(move(path)),
name(name_or_stdin(this->path)),
294#ifdef YUME_SPEW_LIST_TOKENS
295 llvm::outs() <<
"tokens:\n";
296 for (
auto& i : tokens)
297 llvm::outs() <<
" " << i <<
"\n";
298 llvm::outs() <<
"\n";
299 llvm::outs().flush();
All nodes in the AST tree of the program inherit from this class.
An iterator-like holding Tokens, used when parsing.
A "qualified" type, with a non-stackable qualifier, i.e. mut.
visitable_variant< ast::FnDecl *, ast::CtorDecl *, ast::LambdaExpr * > Def_t
auto tokenize(std::istream &in, const string &source_file) -> vector< Token >
Consume the contents of the input stream and create corresponding tokens, ignoring insignificant whit...
visitable_variant< std::monostate, Fn *, Struct *, Const * > DeclLike_t
A constant declaration in the compiler.
auto get_self_ty() const noexcept -> optional< ty::Type >
Const(ast::ConstDecl &ast_decl, ast::Program *member=nullptr, optional< ty::Type > parent=std::nullopt) noexcept
optional< ty::Type > self_ty
If this function is in the body of a struct, this points to its type.
auto ast() const noexcept -> const auto &
auto ast() noexcept -> auto &
ast::Program * member
The program this declaration is a member of.
A common base between declarations in the compiler: Fn, Struct and Const. Its value may also be absen...
auto fully_substituted() const noexcept -> bool
auto ast() noexcept -> ast::AST *
auto subs() noexcept -> Substitutions *
auto opaque_self() const noexcept -> bool
auto subs() const noexcept -> const Substitutions *
auto ast() const noexcept -> const ast::AST *
auto self_ty() const noexcept -> optional< ty::Type >
FnArg(ty::Type type, string name, const ast::AST &ast)
A function declaration in the compiler.
ast::Program * member
The program this declaration is a member of.
Fn(Def def, ast::Program *member, optional< ty::Type > parent, Substitutions subs)
optional< ty::Type > self_ty
If this function is in the body of a struct, this points to its type. Used for the self type.
auto arg_names() const -> vector< string >
std::unordered_map< Substitutions, unique_ptr< Fn > > instantiations
auto fn_body() -> ast::FnDecl::Body &
auto create_instantiation(Substitutions &subs) noexcept -> Fn &
Fn(Def def, ast::Program *member, optional< ty::Type > parent, nullable< Substitutions * > parent_subs, vector< GenericKey > generic={}, vector< unique_ptr< ty::Generic > > primary_generics={})
auto primitive() const -> bool
auto compound_body() -> ast::Compound &
auto local() const -> bool
Def def
The ast node that defines this declaration.
auto extern_decl() const -> bool
auto get_self_ty() const -> optional< ty::Type >
auto arg_types() const -> vector< ty::Type >
auto extern_linkage() const -> bool
auto varargs() const -> bool
auto get_subs() -> Substitutions &
auto get_subs() const -> const Substitutions &
auto abstract() const -> bool
auto args() const -> vector< FnArg >
auto arg_count() const -> size_t
auto ast() const -> const ast::Stmt &
void make_extern_linkage(bool value=true)
Substitutions subs
If this is an instantiation of a template, a mapping between type variables and their substitutions.
auto has_annotation(const string &name) const -> bool
const ty::Function * fn_ty
vector< unique_ptr< ty::Generic > > primary_generics
auto arg_nodes() const -> const vector< ast::TypeName > &
auto ret() const -> optional< ty::Type >
auto name() const noexcept -> string
auto get_or_create_instantiation(Substitutions &subs) noexcept -> std::pair< bool, Fn & >
A local variable in function scope. Used to track destructing when the scope ends.
A source file with its associated Syntax Tree.
vector< yume::Token > tokens
static auto name_or_stdin(const fs::path &path) -> string
SourceFile(std::istream &in, fs::path path)
ast::TokenIterator iterator
unique_ptr< ast::Program > program
A struct declaration in the compiler.
Substitutions subs
If this is an instantiation of a template, a mapping between type variables and their substitutions.
vector< unique_ptr< ty::Generic > > primary_generics
auto name() const noexcept -> string
auto has_annotation(const string &name) const -> bool
auto body() const noexcept -> const auto &
auto get_subs() const -> const Substitutions &
std::unordered_map< Substitutions, unique_ptr< Struct > > instantiations
auto get_or_create_instantiation(Substitutions &subs) noexcept -> std::pair< bool, Struct & >
auto body() noexcept -> auto &
auto get_self_ty() const noexcept -> optional< ty::Type >
auto get_subs() -> Substitutions &
auto create_instantiation(Substitutions &subs) noexcept -> Struct &
Struct(ast::StructDecl &ast_decl, ast::Program *member, optional< ty::Type > type, Substitutions subs) noexcept
auto ast() const noexcept -> const auto &
auto ast() noexcept -> auto &
Struct(ast::StructDecl &ast_decl, ast::Program *member, optional< ty::Type > type, nullable< Substitutions * > parent_subs, vector< GenericKey > generic={}, vector< unique_ptr< ty::Generic > > primary_generics={}) noexcept
std::vector< VTableEntry > vtable_members
nullable< llvm::GlobalVariable * > vtable_memo
optional< ty::Type > self_ty
The type of this struct. Used for the self type.
ast::Program * member
The program this declaration is a member of.
auto fully_substituted() const -> bool
auto operator==(const VTableEntry &other) const noexcept -> bool
A value of a complied expression.
Val(llvm::Value *llvm_val) noexcept
Val(llvm::Value *llvm_val, InScope *scope_val) noexcept
A declaration of a constant (const).
static constexpr auto ANN_OVERRIDE
The top level structure of a file of source code.
static auto parse(TokenIterator &tokens, diagnostic::NotesHolder ¬es) -> unique_ptr< Program >
A declaration of a struct (struct) or an interface (interface).
std::unordered_set< string > annotations
auto visit(Us... us) -> decltype(auto)