14using namespace blender::gpu::shader::parser::ast;
20 std::optional<AstNodeException> error;
34 auto [cls, _] = scope.
lookup_class(table, arg.type().identifier());
40static string to_str(
const vector<SymbolClass *> &types)
42 string parameters = types.empty() ?
", " :
"";
44 parameters +=
", " + cls->identifier +
"";
46 return "(" + parameters.substr(2) +
")";
49optional<vector<MatchRank>> SymbolFunction::get_match_ranks(
53 if (param_types.size() >
arg_types.size()) {
57 vector<MatchRank> ranks;
58 for (
size_t i = 0; i < param_types.size(); ++i) {
59 MatchRank rank = table.get_conversion_rank(
64 ranks.push_back(rank);
69 for (
size_t i = param_types.size(); i <
arg_types.size(); ++i) {
79 const std::vector<MatchRank> &best)
81 bool has_strictly_better_arg =
false;
83 for (
size_t i = 0; i < candidate.size(); ++i) {
84 if (candidate[i] < best[i]) {
87 if (candidate[i] > best[i]) {
88 has_strictly_better_arg =
true;
92 return has_strictly_better_arg;
100 vector<MatchRank> best_ranks;
101 bool is_ambiguous =
false;
104 if (!
fn->is_complete) {
108 auto current_ranks_opt =
fn->get_match_ranks(table,
arg_types);
109 if (!current_ranks_opt) {
113 const vector<MatchRank> ¤t_ranks = *current_ranks_opt;
117 best_ranks = std::move(current_ranks);
123 if (current_is_better) {
125 best_ranks = std::move(current_ranks);
126 is_ambiguous =
false;
128 else if (best_is_better) {
135 bool current_is_template =
fn->is_specialization;
138 if (!current_is_template && best_is_template) {
141 best_ranks = std::move(current_ranks);
142 is_ambiguous =
false;
144 else if (current_is_template && !best_is_template) {
156 if (best_fn && !is_ambiguous) {
157 return {best_fn, {}};
162 if (
fn->is_complete) {
163 candidates +=
"\ncandidate: " +
fn->return_type->original +
" " +
fn->original +
static bool is_strictly_better(const std::vector< MatchRank > &candidate, const std::vector< MatchRank > &best)
static string to_str(const vector< SymbolClass * > &types)
AstNodeException(ast::Node node, Diag diag, const string ¶m1="", const string ¶m2="", const string ¶m3="")
void reserve_arguments(int n)
vector< ast::Expr > arg_defaults
void add_argument(bool is_const, SymbolClass *type, ast::Expr default_value={})
Result< SymbolFunction * > lookup_overload(ast::IdQualified id, const SymbolTable &table, const vector< SymbolClass * > &arg_types)
void add_overload(SymbolFunction *fn)
vector< SymbolClass * > arg_types
SymbolFunction * overload_next
SymbolFunction(SymbolScope *parent, SymbolClass *return_type, AstNodeT decl, const string &suffix="")
static Result< vector< SymbolClass * > > to_arg_types(const SymbolTable &table, const SymbolScope &scope, ast::FuncParamList list)
bool allow_vector_promotion
enum bsl::SymbolScope::Type type
SymbolScope(ast::LocalScope decl)
Result< SymbolFunction * > lookup_function(const SymbolTable &table, ast::IdQualified id, optional< SourceLocation > loc=nullopt) const
Result< SymbolClass * > lookup_class(const SymbolTable &table, ast::IdQualified id, optional< SourceLocation > loc=nullopt) const
static constexpr const char * err_symbol
Result< ExpressionResult > expr_type_analysis(const SymbolScope &scope, ast::Node start_node, bool is_reference=false) const