Yume
overload.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "compiler/vals.hpp"
5#include "token.hpp"
7#include "ty/substitution.hpp"
8#include "util.hpp"
9#include <llvm/Support/raw_ostream.h>
10#include <utility>
11#include <vector>
12
13namespace yume::ast {
14class AST;
15} // namespace yume::ast
16namespace llvm {
17class raw_ostream;
18}
19
20namespace yume::semantic {
21
22struct Overload {
23 Fn* fn{};
24 vector<ty::Compat> compatibilities{};
26 bool viable = false;
27
28 Overload() = delete;
29 explicit Overload(Fn* fn) noexcept : fn{fn}, subs{fn->subs} {}
30
31 [[nodiscard]] auto better_candidate_than(Overload other) const -> bool;
32 void dump(llvm::raw_ostream& stream) const;
33
34 [[nodiscard]] auto location() const -> Loc { return fn->ast().location(); }
35};
36
39 vector<Overload> overloads;
40 vector<ast::AST*> args;
41 unique_ptr<diagnostic::StringNotesHolder> notes = std::make_unique<diagnostic::StringNotesHolder>();
42
43 [[nodiscard]] auto empty() const -> bool { return overloads.empty(); }
44 void dump(llvm::raw_ostream& stream, bool hide_invalid = false) const;
46 [[nodiscard]] auto is_valid_overload(Overload& overload) -> bool;
47 [[nodiscard]] auto try_best_viable_overload() const -> const Overload*;
48 [[nodiscard]] auto best_viable_overload() const -> Overload;
49};
50
51} // namespace yume::semantic
All nodes in the AST tree of the program inherit from this class.
Definition: ast.hpp:224
Definition: ast.hpp:20
Definition: ast.cpp:8
A function declaration in the compiler.
Definition: vals.hpp:52
auto ast() const -> const ast::Stmt &
Definition: vals.cpp:74
Substitutions subs
If this is an instantiation of a template, a mapping between type variables and their substitutions.
Definition: vals.hpp:63
Represents a location in source code, as a range starting at a line and column and ending at some oth...
Definition: token.hpp:26
unique_ptr< diagnostic::StringNotesHolder > notes
Definition: overload.hpp:41
auto is_valid_overload(Overload &overload) -> bool
Definition: overload.cpp:116
vector< Overload > overloads
Definition: overload.hpp:39
auto try_best_viable_overload() const -> const Overload *
Definition: overload.cpp:287
vector< ast::AST * > args
Definition: overload.hpp:40
void dump(llvm::raw_ostream &stream, bool hide_invalid=false) const
Definition: overload.cpp:66
auto best_viable_overload() const -> Overload
Definition: overload.cpp:300
auto empty() const -> bool
Definition: overload.hpp:43
vector< ty::Compat > compatibilities
Definition: overload.hpp:24
Overload(Fn *fn) noexcept
Definition: overload.hpp:29
Substitutions subs
Definition: overload.hpp:25
auto location() const -> Loc
Definition: overload.hpp:34
void dump(llvm::raw_ostream &stream) const
Definition: overload.cpp:47
auto better_candidate_than(Overload other) const -> bool
Definition: overload.cpp:264