CodeSonar C++ API
[For improved navigation, enable JavaScript.]
cs_point_decl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2025, an unpublished work by CodeSecure, Inc.
3  * ALL RIGHTS RESERVED
4  *
5  * Copyright (c) 2013-2023, an unpublished work by GrammaTech, Inc.
6  * ALL RIGHTS RESERVED
7  *
8  * This software is furnished under a license and may be used and
9  * copied only in accordance with the terms of such license and the
10  * inclusion of the above copyright notice. This software or any
11  * other copies thereof may not be provided or otherwise made
12  * available to any other person. Title to and ownership of the
13  * software is retained by CodeSecure, Inc.
14  */
15 
16 #ifndef CS_POINT_DECL_HPP
17 #define CS_POINT_DECL_HPP
18 
19 #include "cs_binaries.h"
20 #include "cs_point_fwd.hpp"
21 #include "cs_result.hpp"
22 #include "cs_sfileinst_decl.hpp"
23 #include "cs_compunit_decl.hpp"
24 #include "cs_ast_decl.hpp"
25 #include "cs_int_pair_set.hpp"
26 #include "cs_ir_boilerplate.hpp"
27 #include "cs_symbol_decl.hpp"
28 #include "cs_point_set_decl.hpp"
29 #include "cs_symbol_set.hpp"
30 #include "cs_basic_block_fwd.hpp"
31 #include "cs_scratchpad.hpp"
32 #include "cs_point_kind.hpp"
33 #include "cs_point_syntax.hpp"
34 
37 namespace cs{
38  template<>
39  class cglue<exceptional_return>
40  {
41  cglue();
42  friend class scratchpad<exceptional_return>;
43  public:
44  typedef exceptional_return type;
45  typedef cs_exceptional_return ctype;
46  CS_CXX_API_CGLUE_ACCESS_MODIFIER:
47  static exceptional_return wrap(const ctype &c);
48  /* unwrap intentionally omitted due to memory ownership
49  * confusion.
50  */
51  };
52 
53 
66  class point{
67 
73  CS_IR_BOILERPLATE(point);
74 
75 
93  csuint64 stable_hash() const
94  {
95  return cs_pdg_vertex_stable_hash(inner);
96  }
97 
98 
121  int stable_cmp(const point& other) const
122  {
123  return cs_pdg_vertex_stable_compare(inner, other.inner);
124  }
125 
126 
142  csint64 id() const
143  {
144  return cs_pdg_vertex_id(inner);
145  }
146 
147 
153  {
154  return cglue<point_kind>::wrap(cs_pdg_vertex_kind(inner));
155  }
156 
157 
163  {
164  return cglue<point_syntax_kind>::wrap(cs_pdg_vertex_syntax_kind(inner));
165  }
166 
167 
174  {
175  return cglue<point_syntax_element>::wrap(cs_pdg_vertex_syntax_element(inner));
176  }
177 
178 
183  procedure get_procedure() const;
184 
185 
206  {
207  cs_ast rv;
208  check(cs_pdg_vertex_ast(
209  inner, cglue<ast_family>::unwrap(fam), &rv));
210  return ast::;
211  }
212 
226  {
227  cs_ast rv;
228  return cs_pdg_vertex_ast(
229  inner, cglue<ast_family>::unwrap(fam), &rv) == CS_SUCCESS;
230  }
231 
245  void set_ast(ast_family fam, ast val)
246  {
247  check(cs_pdg_vertex_set_ast(inner, cglue<ast_family>::unwrap(fam),
248  cglue<ast>::unwrap(val)));
249  }
263  {
264  cs_sfid sfid;
265  cs_const_int_pair_set rv;
266  check(cs_pdg_vertex_charpos(inner, &sfid, &rv));
268  sfileinst::,
269  cglue<int_pair_set>::wrap(rv, true));
270  }
271 
272 
284  {
285  cs_sfid s;
286  cs_line ln;
287  check(cs_pdg_vertex_file_line(
288  inner, &s, &ln));
289  return sfileinst_line_pair(sfileinst::, ln);
290  }
291 
292 
306  std::string characters(size_t limit=SIZE_MAX) const
307  {
308  string_scratchpad::
309  to_string_functor1_limit<point, cs_pdg_vertex_characters>
310  functor(inner, limit);
311  return string_scratchpad::to_string(functor);
312  }
313 
314 
331  symbol declared_symbol() const;
348  symbol_set declared_symbols() const
349  {
350  cs_abs_loc_set rv;
351  check(cs_pdg_vertex_symbols(inner, &rv));
352  return cglue<symbol_set>::wrap(rv, false);
353  }
369  size_t rank() const
370  {
371  size_t rv;
372  check(cs_pdg_vertex_rank(inner, &rv));
373  return rv;
374  }
375 
389  symbol_set ids_decl_uses() const
390  {
391  cs_const_abs_loc_set rv;
392  check(cs_pdg_vertex_ids_decl_uses(inner, &rv));
393  return cglue<symbol_set>::wrap(rv, true);
394  }
410  symbol_set ids_used() const
411  {
412  cs_const_abs_loc_set rv;
413  check(cs_pdg_vertex_ids_used(inner, &rv));
414  return cglue<symbol_set>::wrap(rv, true);
415  }
432  symbol_set ids_killed() const
433  {
434  cs_const_abs_loc_set rv;
435  check(cs_pdg_vertex_ids_killed(inner, &rv));
436  return cglue<symbol_set>::wrap(rv, true);
437  }
455  symbol_set ids_cond_killed() const
456  {
457  cs_const_abs_loc_set rv;
458  check(cs_pdg_vertex_ids_cond_killed(inner, &rv));
459  return cglue<symbol_set>::wrap(rv, true);
460  }
477  symbol_set actual_points_to() const
478  {
479  cs_const_abs_loc_set rv;
480  check(cs_pdg_vertex_ids_cond_killed(inner, &rv));
481  return cglue<symbol_set>::wrap(rv, true);
482  }
504  std::vector<symbol> parameter_symbols() const
505  {
506  typedef scratchpad<symbol> sp;
507  sp::to_vector_functor1
508  <point, cs_pdg_vertex_parameter_symbols>
509  functor(inner);
510  return sp::to_vector(functor);
511  }
537  cfg_edge_set cfg_successors() const;
565  cfg_edge_set cfg_predecessors() const;
595  cfg_edge_set cfg_inter_targets() const;
596 
597 
617  cfg_edge_set cfg_inter_sources() const;
639  cfg_edge_set cfg_targets() const;
640 
641 
661  cfg_edge_set cfg_sources() const;
683  basic_block get_basic_block() const;
710  {
711  cs_pdg_vertex rv;
712  check(cs_pdg_vertex_solitary_cfg_target(
713  inner, &rv));
714  return point::;
715  }
716 
741  point solitary_cfg_source() const
742  {
743  cs_pdg_vertex rv;
744  check(cs_pdg_vertex_solitary_cfg_source(
745  inner, &rv));
746  return point::;
747  }
764  pdg_edge_set inter_targets() const;
781  pdg_edge_set inter_sources() const;
794  bool summary_edge(point to_pt) const
795  {
796  cs_boolean rv;
797  check(cs_pdg_vertex_summary_edge(
798  inner, to_pt.inner, &rv));
799  return !!rv;
800  }
817  pdg_edge_set intra_targets() const;
834  pdg_edge_set intra_sources() const;
867  {
868  cs_pdg_vertex_set rv;
869  check(cs_pdg_vertex_actual_to_formals(inner, &rv));
870  return cglue<point_set>::wrap(rv, false);
871  }
872 
873 
886  {
887  cs_pdg_vertex_set rv;
888  check(cs_pdg_vertex_actuals_in(inner, &rv));
889  return cglue<point_set>::wrap(rv, false);
890  }
891 
892 
905  {
906  cs_pdg_vertex_set rv;
907  check(cs_pdg_vertex_actuals_out(inner, &rv));
908  return cglue<point_set>::wrap(rv, false);
909  }
910 
911 
921  void set_actual_outs(const std::vector<point>& ao_vertices)
922  {
923  check(cs_pdg_vertex_set_actual_outs(
924  inner, ao_vertices.size(),
925  reinterpret_cast<const cs_pdg_vertex*>(&ao_vertices[0])));
926  }
939  void set_actual_ins(const std::vector<point>& ai_vertices)
940  {
941  check(cs_pdg_vertex_set_actual_ins(
942  inner, ai_vertices.size(),
943  reinterpret_cast<const cs_pdg_vertex*>(&ai_vertices[0])));
944  }
958  std::vector<point> actuals_in_as_list() const
959  {
960  typedef scratchpad<point> sp;
961  sp::to_vector_functor1<point, cs_pdg_vertex_actuals_in_as_list>
962  functor(inner);
963  return sp::to_vector(functor);
964  }
965 
966 
976  std::vector<point> actuals_out_as_list() const
977  {
978  typedef scratchpad<point> sp;
979  sp::to_vector_functor1
980  <point, cs_pdg_vertex_actuals_out_as_list>
981  functor(inner);
982  return sp::to_vector(functor);
983  }
984 
1000  point actual_in(size_t _rank) const
1001  {
1002  cs_pdg_vertex rv;
1003  check(cs_pdg_vertex_actual_in(inner, _rank, &rv));
1004  return point::;
1005  }
1006 
1007 
1027  point actual_out(size_t _rank) const
1028  {
1029  cs_pdg_vertex rv;
1030  check(cs_pdg_vertex_actual_out(inner, _rank, &rv));
1031  return point::;
1032  }
1033 
1034 
1056  {
1057  cs_pdg_vertex rv;
1058  check(cs_pdg_vertex_call_site(inner, &rv));
1059  return point::;
1060  }
1061 
1062 
1076  procedure callee() const;
1077 
1078 
1100  point normal_return() const
1101  {
1102  cs_pdg_vertex rv;
1103  check(cs_pdg_vertex_normal_return(inner, &rv));
1104  return point::;
1105  }
1128  std::vector<exceptional_return> exceptional_returns() const;
1149  labeled_pdg_edge_set labeled_intra_control_sources() const;
1170  labeled_pdg_edge_set labeled_intra_control_targets() const;
1186  bool is_inside_macro() const
1187  { return cs_pdg_vertex_is_inside_macro( inner )?true:false; }
1188 
1189 
1210  { return cs_pdg_vertex_is_implicit_actual_in( inner )?true:false; }
1211 
1212 
1227  std::string source_pp() const
1228  {
1229  string_scratchpad::
1230  to_string_functor1_limit<point, cs_pdg_vertex_source_pp>
1231  functor(inner, -1);
1232  return string_scratchpad::to_string(functor);
1233  }
1249  csuint64 condition_number() const
1250  { return cs_pdg_vertex_condition_number(inner); }
1261  std::string as_string() const
1262  { return cs_pdg_vertex_string(inner); }
1263 
1264 
1267  std::string as_repr() const
1268  { return CS_AS_REPR_FROM_STRING(point); }
1269 
1304  {
1305  effective_address addr;
1306  check(cs_pdg_vertex_ea(inner, &addr));
1307  return addr;
1308  }
1309 
1310 
1327  {
1328  effective_address addr;
1329  check(cs_pdg_vertex_affiliated_ea(inner, &addr));
1330  return addr;
1331  }
1332 
1346  std::string as_smtlib() const
1347  {
1348  string_scratchpad::
1349  to_string_functor1_limit<point, cs_pdg_vertex_to_smt>
1350  functor(inner, -1);
1351  return string_scratchpad::to_string(functor);
1352  }
1377  std::string semantics(bool noexc = false) const
1378  {
1379  if (noexc) {
1380  string_scratchpad::
1381  to_string_functor1_limit<point, cs_pdg_vertex_to_semantics_noexc>
1382  functor(inner, -1);
1383  return string_scratchpad::to_string(functor);
1384  }
1385  else {
1386  string_scratchpad::
1387  to_string_functor1_limit<point, cs_pdg_vertex_to_semantics>
1388  functor(inner, -1);
1389  return string_scratchpad::to_string(functor);
1390  }
1391  }
1410  std::string handle() const
1411  {
1412  string_scratchpad::
1413  to_string_functor1_limit<point, cs_pdg_vertex_get_handle>
1414  functor(inner, -1);
1415  return string_scratchpad::to_string(functor);
1416  }
1417 
1418 #if defined(CSONAR_API_SWIG_HPP) || !defined(SWIG)
1419  // The following are declared here so they can belong to
1420  // the point class, but are defined only in CodeSonar.
1421 
1423  /* documented in csonar_visitor.hpp */
1424  procedure adjusted_callee() const;
1425 
1426  /* documented in csonar_visitor.hpp */
1427  iterator_adapter<point_adjusted_callees_iterator_policy> adjusted_callees() const;
1428 
1429  /* documented in csonar_visitor.hpp */
1431 
1432  /* documented in csonar_visitor.hpp */
1433  iterator_adapter<point_adjusted_callees_no_reroute_iterator_policy> adjusted_callees_no_reroute() const;
1434 
1435  // These are on-demand versions of ids_used() and ids_killed(),
1436  // which are not supported by CodeSonar, as well as an
1437  // on-demand enumerator of references.
1438 
1439  /* documented in csonar_visitor.hpp */
1441 
1442  /* documented in csonar_visitor.hpp */
1444 
1445  /* documented in csonar_visitor.hpp */
1449 #endif
1450  };
1451 
1452  CS_IR_BOILERPLATE_FRIENDS_PLUS_OSTREAM(point, cs)
1453 }
1454 
1455 #endif /* CS_POINT_DECL_HPP */
Enumeration class: the syntax kind associated with a program point (point), indicating the kind of so...
Definition: cs_point_syntax.hpp:52
Namespace for CodeSonar/CodeSurfer API.
Definition: cs_ast.hpp:33
point_set actuals_in() const
Get the actual-in and global-actual-in points associated with a call site point.
Definition: cs_point_decl.hpp:885
Enumeration class: program point (point) kind.
Definition: cs_point_kind.hpp:29
iterator_adapter< point_adjusted_callees_no_reroute_iterator_policy > adjusted_callees_no_reroute() const
Get an iterator over the callee procedures (procedure) from a point, ignoring any translations incurr...
Definition: csonar_visitor.hpp:6088
std::vector< point > actuals_out_as_list() const
Get the actual-out points associated with a call site point.
Definition: cs_point_decl.hpp:976
int stable_cmp(const point &other) const
Compare with another point, with stable results across sufficiently-similar analyses.
Definition: cs_point_decl.hpp:121
std::pair< cs::sfileinst, cs::line_number > sfileinst_line_pair
A std::pair (sfi, line) where:
Definition: cs_tplt_instantiations.hpp:107
point actual_in(size_t _rank) const
Get the actual-in, having the specified rank, associated with a call site point.
Definition: cs_point_decl.hpp:1000
std::string handle() const
Get a handle for this point.
Definition: cs_point_decl.hpp:1413
cfg_edge_set cfg_targets() const
Get the intra-procedural successors of a point.
Definition: cs_point.hpp:94
A function or variable.
Definition: cs_symbol_decl.hpp:243
cfg_edge_set cfg_inter_targets() const
Get the inter-procedural successors of a point.
Definition: cs_point.hpp:78
bool is_implicit_actual_in() const
Check: is a point an actual-in that is implicitly generated?
Definition: cs_point_decl.hpp:1209
point_set actual_to_formals() const
Get the formal-in points associated with an actual-in point.
Definition: cs_point_decl.hpp:866
A single program point.
Definition: cs_point_decl.hpp:66
std::string as_string() const
Get a string representation of a point containing information useful for debugging.
Definition: cs_point_decl.hpp:1261
std::vector< point > actuals_in_as_list() const
Get the actual-in and global-actual-in points associated with a call site point.
Definition: cs_point_decl.hpp:958
An Abstract Syntax Tree (AST).
Definition: cs_ast_decl.hpp:448
std::pair< cs::point, std::string > exceptional_return
A std::pair (p, s) where:
Definition: cs_tplt_instantiations.hpp:394
symbol_vector csonar_enum_killed() const
Get the list of killed symbols (symbol) for a point, computing the list on-demand.
Definition: csonar_visitor.hpp:5719
ast get_ast(ast_family fam=ast_family::DEFAULT) const
Get the AST associated with a point.
Definition: cs_point_decl.hpp:205
symbol_vector csonar_enum_referenced() const
Get the list of referenced symbols (symbol) for a point, computing the list on-demand.
Definition: csonar_visitor.hpp:5735
effective_address get_affiliated_address() const
[Binary analyses only] Get the effective address affiliated with a point, if there is one...
Definition: cs_point_decl.hpp:1329
A single procedure/function/method.
Definition: cs_procedure_decl.hpp:173
procedure adjusted_callee() const
Get the callee procedure of a call site point, taking into account any translations incurred by csona...
Definition: csonar_visitor.hpp:5642
Enumeration class: the element of source code statement from which a point was generated.
Definition: cs_point_syntax.hpp:80
point solitary_cfg_target() const
Get the CFG successor of a point that has exactly one successor CFG edge.
Definition: cs_point_decl.hpp:709
sfileinst_line_pair file_line() const
Get the file instance and (smallest offset) line for a point.
Definition: cs_point_decl.hpp:283
csuint64 condition_number() const
[CodeSonar only] Get the condition number of a point.
Definition: cs_point_decl.hpp:1249
static const ast_family DEFAULT
Represents the first AST family, whatever it might be.
Definition: cs_ast_decl.hpp:25
point_kind get_kind() const
Get a point&#39;s kind.
Definition: cs_point_decl.hpp:152
A set of points (point).
Definition: cs_tplt_instantiations.hpp:214
std::string as_repr() const
Get a representation of a point object that includes information useful for debugging.
Definition: cs_point_decl.hpp:1270
point call_site() const
Get the call site of a subordinate point.
Definition: cs_point_decl.hpp:1055
csuint64 stable_hash() const
Get a hash value for a point, with stable results across sufficiently-similar analyses.
Definition: cs_point_decl.hpp:93
procedure adjusted_callee_no_reroute() const
Get the callee procedure of a call site point, ignoring any translations incurred by csonar_replace_*...
Definition: csonar_visitor.hpp:5686
point_syntax_element get_syntax_element() const
Get a point&#39;s syntax element.
Definition: cs_point_decl.hpp:173
std::pair< cs::sfileinst, cs::int_pair_set > sfileinst_int_pair_set_pair
std::pair (sfi, ips) where:
Definition: cs_tplt_instantiations.hpp:307
std::string characters(size_t limit=SIZE_MAX) const
Get a string representation of a point.
Definition: cs_point_decl.hpp:306
procedure get_procedure() const
Get the procedure containing a point.
Definition: cs_point.hpp:41
std::string source_pp() const
[CodeSonar only] Get a string containing a pretty printed version of an actual-in, expression, call-site, or control-point point.
Definition: cs_point_decl.hpp:1227
A set of symbols (symbol).
Definition: cs_tplt_instantiations.hpp:231
effective_address get_address() const
[Binary analyses only] Get the effective address of a point, if it has one.
Definition: cs_point_decl.hpp:1306
std::vector< symbol > symbol_vector
A std::vector of symbol .
Definition: cs_tplt_instantiations.hpp:246
Enumeration class for AST family.
Definition: cs_ast_decl.hpp:50
point_syntax_kind get_syntax_kind() const
Get a point&#39;s syntax kind.
Definition: cs_point_decl.hpp:162
cs::iterator_adapter< point_adjusted_callees_iterator_policy >
iterator_adapter< point_adjusted_callees_iterator_policy > adjusted_callees() const
Get an iterator over the callee procedures (procedure) from a point, taking into account any translat...
Definition: csonar_visitor.hpp:6064
point_set actuals_out() const
Get the actual-out and global-actual-out points associated with a call site point.
Definition: cs_point_decl.hpp:904
point actual_out(size_t _rank) const
Get the actual-out, having the specified rank, associated with a call site point. ...
Definition: cs_point_decl.hpp:1027
bool has_ast(ast_family fam=ast_family::DEFAULT) const
Check: does a point have an associated AST (ast) of the specified family (ast_family)?
Definition: cs_point_decl.hpp:225
bool is_inside_macro() const
Check: is a point entirely contained inside a macro?
Definition: cs_point_decl.hpp:1186
symbol_vector csonar_enum_used() const
Get the list of used symbols (symbol) for a point, computing the list on-demand.
Definition: csonar_visitor.hpp:5703
cs_ea effective_address
An effective address: used for binary analyses to hold the address of an entity such as a point or sy...
Definition: cs_types.hpp:392
size_t rank() const
Get the rank of a point.
Definition: cs_point_decl.hpp:369
sfileinst_int_pair_set_pair charpos() const
Get the character positions (in the source code) for a point.
Definition: cs_point_decl.hpp:262
procedure callee() const
Get the callee procedure associated with a call-site point.
Definition: cs_point.hpp:48
csint64 id() const
Get a point&#39;s unique identifier.
Definition: cs_point_decl.hpp:142