39 int library_line_count = 0);
44 analyzer->enterScope();
64 [[nodiscard]]
const std::map<std::string, std::vector<FunctionSignature>>&
66 return function_signatures;
69 [[nodiscard]]
const std::map<std::string, std::vector<FunctionDef*>>&
74 [[nodiscard]]
const std::map<std::string, std::pair<std::string, Range>>&
76 return written_properties;
93 void analyzeStmt(
Stmt* stmt);
108 std::map<std::string, std::shared_ptr<Symbol>>& symbols)
const;
110 struct ForwardGotoInfo {
112 std::map<std::string, std::shared_ptr<Symbol>> symbols_at_goto;
117 std::shared_ptr<Symbol> defineSymbol(
SymbolKind kind,
118 const std::string& name,
Type type,
120 std::shared_ptr<Symbol> resolveSymbol(
const std::string& name,
123 void reportError(
const std::string& message,
const Range& range);
124 void reportWarning(
const std::string& message,
const Range& range);
125 bool builtinParamTypeIsEvaluatable(
126 const std::vector<struct BuiltinFunction>& overloads,
size_t param_idx);
128 const FunctionSignature*
129 resolveOverload(
const std::string& name,
130 const std::vector<std::unique_ptr<Expr>>& args,
131 const Range& range, CallExpr* call_expr =
nullptr);
133 void collectLabels(Stmt* stmt, std::set<std::string>& labels,
134 const std::string& context,
const Range& context_range);
136 void validateGlobalDependencies(Stmt* stmt);
137 void validateFunctionCall(
const CallExpr& expr);
139 void collectUsedGlobals(
Expr* expr, std::set<std::string>& used_globals);
140 void collectUsedGlobalsInStmt(Stmt* stmt,
141 std::set<std::string>& used_globals);
143 bool pathAlwaysReturns(Stmt* stmt);
145 void validateClipReference(
const std::string& clip_name,
const Range& range,
146 bool allow_buffer =
true);
150 int num_intermediate_inputs;
151 int library_line_count;
152 bool has_result =
false;
153 bool result_defined_in_global_scope =
false;
155 std::unique_ptr<SymbolTable> global_scope;
156 SymbolTable* current_scope;
158 std::vector<std::unique_ptr<SymbolTable>> scope_stack;
160 std::set<std::string> defined_global_vars;
162 std::map<std::string, std::vector<FunctionSignature>> function_signatures;
163 std::map<std::string, std::vector<FunctionDef*>> function_defs;
165 std::set<std::string> global_labels;
166 std::set<std::string> current_function_labels;
168 std::vector<Diagnostic> diagnostics;
170 std::map<std::string, std::vector<ForwardGotoInfo>> current_pending_gotos;
171 std::set<std::string> current_labels_seen;
173 std::map<std::string, std::pair<std::string, Range>> written_properties;
175 const FunctionSignature* current_function =
nullptr;
177 std::vector<std::string> function_call_stack;
179 std::map<std::string, std::set<std::string>> function_call_graph;
181 bool detectCycleInCallGraph(
const std::string& func_name,
182 std::set<std::string>& visiting,
183 std::set<std::string>& visited,
184 std::vector<std::string>& cycle_path);
ScopeGuard & operator=(const ScopeGuard &)=delete
ScopeGuard & operator=(ScopeGuard &&)=delete
ScopeGuard(ScopeGuard &&)=delete
ScopeGuard(SemanticAnalyzer *analyzer)
ScopeGuard(const ScopeGuard &)=delete
const std::map< std::string, std::pair< std::string, Range > > & getWrittenProperties() const
const std::vector< Diagnostic > & getDiagnostics() const
const std::map< std::string, std::vector< FunctionSignature > > & getFunctionSignatures() const
bool analyze(const Program *program)
const std::map< std::string, std::vector< FunctionDef * > > & getFunctionDefs() const
SemanticAnalyzer(Mode mode, int num_inputs, int num_intermediate_inputs=0, int library_line_count=0)