Blender V5.3
symbol_function.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "symbol_scope.hh"
12#include "symbol_template.hh"
13
14namespace bsl {
15
16enum class MatchRank { None = 0, Conversion = 1, Promotion = 2, Exact = 3 };
17
24 /* Single linked list of overloads. */
26
29
31
32 vector<bool> arg_const;
33 vector<SymbolClass *> arg_types;
34 vector<ast::Expr> arg_defaults;
35
36 bool is_error = false;
37 /* False if this is a template root and is not a symbol to match on. */
38 bool is_complete = true;
39 /* If true, will allow vector type casting. */
41 /* If true, is part of language builtin functions. */
42 bool is_builtin = false;
43 /* If true, this builtin function is implemented as constexpr. */
44 bool is_constexpr = false;
45 /* True for template specialization and instantiation. */
46 bool is_specialization = false;
47 /* True for force-inlined functions. */
48 bool is_inline = false;
49 /* False if this function was only forward declared. */
50 bool is_defined = true;
51
52 /* Identifier of the temporary return variable.
53 * The real identifier is then specialized per instantiation. */
54 static constexpr const char *inline_fn_ret_id = "_r";
55
57 enum class EntryPointType { FRAG, VERT, COMP, NONE } entry_point_type;
58
59 template<typename AstNodeT>
62 AstNodeT decl,
63 const string &suffix = "")
65 parent, decl.front(), string(decl.identifier().name().str()) + suffix, FUNCTION),
67 decl(decl),
68 is_inline(decl.attributes().contains_attr("force_inline")),
69 fn_type(decl.is_method() ? (decl.is_static() ? STATIC : MEMBER) : GLOBAL),
71 {
72 if (decl.is_method()) {
73 loc = decl.parent(ast::NodeType::ClassDecl).front();
74 }
75 for (ast::Attr attr : decl.attributes().template children_of_type<ast::Attr>()) {
76 string_view id = attr.identifier().str();
77 if (id == "vertex") {
78 entry_point_type = EntryPointType::VERT;
79 }
80 else if (id == "fragment") {
82 }
83 else if (id == "compute") {
85 }
86 }
87 }
88
97
98 /* Can be null if in global space. */
100 {
101 return this->parent->as_class();
102 }
103
108
109 /* To be called on the first registered overload. */
111 const SymbolTable &table,
112 const vector<SymbolClass *> &arg_types);
113
114 void add_overload(SymbolFunction *fn);
115 void add_argument(bool is_const, SymbolClass *type, ast::Expr default_value = {});
116
117 void reserve_arguments(int n);
118
119 static Result<vector<SymbolClass *>> to_arg_types(const SymbolTable &table,
120 const SymbolScope &scope,
121 ast::FuncParamList list);
122 static Result<vector<SymbolClass *>> to_arg_types(const SymbolTable &table,
123 const SymbolScope &scope,
124 ast::FuncArgList list);
125
126 private:
127 /* Returning empty indicates this is not a viable candidate */
128 optional<vector<MatchRank>> get_match_ranks(const SymbolTable &table,
129 const vector<SymbolClass *> &param_types) const;
130};
131
132} // namespace bsl
@ NONE
#define str(s)
if(state< num_states)
Definition codegen.cc:18
SymbolTemplate< SymbolFunction > SymbolFunctionTemplate
SymbolFunctionTemplate * template_data
vector< ast::Expr > arg_defaults
SymbolClass * return_type
enum bsl::SymbolFunction::EntryPointType entry_point_type
SymbolClass * parent_class()
vector< SymbolClass * > arg_types
SymbolFunction * overload_next
SymbolFunction(SymbolScope *parent, SymbolClass *return_type, AstNodeT decl, const string &suffix="")
bool is_entry_point() const
vector< bool > arg_const
SymbolFunction(SymbolScope *parent, Token tok, SymbolClass *return_type, const string &id, Type fn_type)
static constexpr const char * inline_fn_ret_id
enum bsl::SymbolFunction::Type fn_type
SymbolScope(ast::LocalScope decl)
SymbolClass * as_class()
SymbolScope * parent