GCC Middle and Back End API Reference
callsite-expr.h
Go to the documentation of this file.
1/* User-facing descriptions of expressions at call sites.
2 Copyright (C) 2019-2026 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_ANALYZER_CALLSITE_EXPR_H
22#define GCC_ANALYZER_CALLSITE_EXPR_H
23
24#include "pretty-print-markup.h"
25
26namespace ana {
27
28/* An ID representing an expression at a callsite:
29 either a parameter index, or the return value (or unknown). */
30
32{
33 public:
34 callsite_expr () : m_val (-1) {}
35
37 {
38 return callsite_expr (idx + 1);
39 }
40
42 {
43 return callsite_expr (0);
44 }
45
46 bool param_p () const
47 {
48 return m_val > 0;
49 }
50
51 /* Get 1-based param number. */
52 int param_num () const
53 {
55 return m_val;
56 }
57
58 tree get_param_tree (tree fndecl) const;
59
60 bool
62 location_t *out_loc) const;
63
64 bool return_value_p () const
65 {
66 return m_val == 0;
67 }
68
69 private:
70 callsite_expr (int val) : m_val (val) {}
71
72 int m_val; /* 1-based parm, 0 for return value, or -1 for "unknown". */
73};
74
76{
77public:
79
80 void
81 add_to_phase_2 (pp_markup::context &ctxt) final override
82 {
83
84 if (m_expr.return_value_p ())
85 pp_string (&ctxt.m_pp, "return value");
86 else if (m_expr.param_p ())
87 {
88 /* We can't call pp_printf directly on ctxt.m_pp from within
89 formatting. As a workaround, work with a clone of the pp. */
90 std::unique_ptr<pretty_printer> pp (ctxt.m_pp.clone ());
91 pp_printf (pp.get (), "parameter %i", m_expr.param_num ());
92 pp_string (&ctxt.m_pp, pp_formatted_text (pp.get ()));
93 }
94 else
95 pp_string (&ctxt.m_pp, "unknown");
96 }
97
98private:
100};
101
102} // namespace ana
103
104#endif /* GCC_ANALYZER_CALLSITE_EXPR_H */
callsite_expr_element(callsite_expr expr)
Definition callsite-expr.h:78
callsite_expr m_expr
Definition callsite-expr.h:99
void add_to_phase_2(pp_markup::context &ctxt) final override
Definition callsite-expr.h:81
Definition callsite-expr.h:32
static callsite_expr from_zero_based_param(int idx)
Definition callsite-expr.h:36
int param_num() const
Definition callsite-expr.h:52
callsite_expr()
Definition callsite-expr.h:34
tree get_param_tree(tree fndecl) const
int m_val
Definition callsite-expr.h:72
static callsite_expr from_return_value()
Definition callsite-expr.h:41
bool return_value_p() const
Definition callsite-expr.h:64
callsite_expr(int val)
Definition callsite-expr.h:70
bool param_p() const
Definition callsite-expr.h:46
bool maybe_get_param_location(tree fndecl, location_t *out_loc) const
Definition genmatch.cc:1506
Definition pretty-print-markup.h:30
pp_markup::element pp_element
Definition coretypes.h:177
union tree_node * tree
Definition coretypes.h:97
Definition access-diagram.h:30
void pp_printf(pretty_printer *pp, const char *msg,...)
Definition pretty-print.cc:2683
const char * pp_formatted_text(pretty_printer *pp)
Definition pretty-print.cc:2660
void pp_string(pretty_printer *pp, const char *str)
Definition pretty-print.cc:2764
#define gcc_assert(EXPR)
Definition system.h:817