GCC Middle and Back End API Reference
program-point.h
Go to the documentation of this file.
1/* Classes for representing locations within the program.
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_PROGRAM_POINT_H
22#define GCC_ANALYZER_PROGRAM_POINT_H
23
24#include "pretty-print.h"
26#include "analyzer/supergraph.h"
27
28namespace ana {
29
30class format
31{
32public:
33 format (bool newlines) : m_newlines (newlines) {}
34
35 void spacer (pretty_printer *pp) const
36 {
37 if (m_newlines)
38 pp_newline (pp);
39 else
40 pp_space (pp);
41 }
42
44};
45
46/* A class for representing a location within the program, including
47 interprocedural information.
48
49 This represents a fine-grained location within the supergraph (or
50 within one of its nodes), along with a call string giving the
51 interprocedural context. */
52
54{
55public:
56 program_point (const supernode *snode,
58 : m_snode (snode),
60 {
61 }
62
63 void print (pretty_printer *pp, const format &f) const;
64 void dump () const;
65
66 std::unique_ptr<text_art::tree_widget>
68
70
71 std::unique_ptr<json::object> to_json () const;
72
73 hashval_t hash () const;
74 bool operator== (const program_point &other) const
75 {
76 return (m_snode == other.m_snode
77 && m_call_string == other.m_call_string);
78 }
79 bool operator!= (const program_point &other) const
80 {
81 return !(*this == other);
82 }
83
84 /* Accessors. */
85
86 const supernode *get_supernode () const
87 {
88 return m_snode;
89 }
90 const call_string &get_call_string () const { return *m_call_string; }
91
93 {
94 return m_snode ? m_snode->get_function () : nullptr;
95 }
96 function *get_function_at_depth (unsigned depth) const;
98 {
99 function *fn = get_function ();
100 return fn ? fn->decl : nullptr;
101 }
102 location_t get_location () const
103 {
105 }
106
107 /* Get the number of frames we expect at this program point.
108 This will be one more than the length of the call_string
109 (which stores the parent callsites), apart from the origin
110 node, which doesn't have any frames. */
111 int get_stack_depth () const
112 {
113 if (m_snode == nullptr)
114 // Origin
115 return 0;
116 return get_call_string ().length () + 1;
117 }
118
119 bool state_merge_at_p () const
120 {
121 if (m_snode)
123 return false;
124 }
125
126 /* Factory functions for making various kinds of program_point. */
129 const supergraph &sg,
130 const function &fun);
131
133 void validate () const;
134
135 static bool effectively_intraprocedural_p (const program_point &point_a,
136 const program_point &point_b);
137
138 private:
141};
142
143} // namespace ana
144
145#endif /* GCC_ANALYZER_PROGRAM_POINT_H */
Definition call-string.h:44
unsigned length() const
Definition call-string.h:104
Definition program-point.h:31
void spacer(pretty_printer *pp) const
Definition program-point.h:35
format(bool newlines)
Definition program-point.h:33
bool m_newlines
Definition program-point.h:43
location_t get_location() const
Definition program-point.h:102
const supernode * m_snode
Definition program-point.h:139
function * get_function() const
Definition program-point.h:92
bool operator!=(const program_point &other) const
Definition program-point.h:79
void print(pretty_printer *pp, const format &f) const
std::unique_ptr< json::object > to_json() const
std::unique_ptr< text_art::tree_widget > make_dump_widget(symbolic::node_dump_state &nds) const
bool operator==(const program_point &other) const
Definition program-point.h:74
bool state_merge_at_p() const
Definition program-point.h:119
program_point(const supernode *snode, const call_string &call_string)
Definition program-point.h:56
const supernode * get_supernode() const
Definition program-point.h:86
static program_point from_function_entry(const region_model_manager &mgr, const supergraph &sg, const function &fun)
void dump() const
int get_stack_depth() const
Definition program-point.h:111
const call_string & get_call_string() const
Definition program-point.h:90
void print_source_line(pretty_printer *pp) const
function * get_function_at_depth(unsigned depth) const
void pop_from_call_stack()
static bool effectively_intraprocedural_p(const program_point &point_a, const program_point &point_b)
void validate() const
static program_point origin(const region_model_manager &mgr)
tree get_fndecl() const
Definition program-point.h:97
hashval_t hash() const
const call_string * m_call_string
Definition program-point.h:140
Definition region-model-manager.h:36
Definition supergraph.h:105
Definition supergraph.h:227
bool m_state_merger_node
Definition supergraph.h:275
location_t get_location() const
Definition supergraph.h:261
function * get_function() const
Definition supergraph.h:240
Definition pretty-print.h:241
union tree_node * tree
Definition coretypes.h:97
#define UNKNOWN_LOCATION
Definition input.h:32
Definition access-diagram.h:30
@ other
Definition common.h:535
void pp_newline(pretty_printer *pp)
Definition pretty-print.cc:2738
#define pp_space(PP)
Definition pretty-print.h:490
Definition symbolic-nodes.h:276
Definition function.h:249
tree decl
Definition function.h:285