CBMC
generic_parameter_specialization_map.h
Go to the documentation of this file.
1 
3 #ifndef CPROVER_JAVA_BYTECODE_GENERIC_PARAMETER_SPECIALIZATION_MAP_H
4 #define CPROVER_JAVA_BYTECODE_GENERIC_PARAMETER_SPECIALIZATION_MAP_H
5 
6 #include <stack>
7 #include <vector>
8 
9 #include <util/string_utils.h>
10 
11 #include "expr2java.h"
12 #include "java_types.h"
13 
24 {
25 private:
28  {
29  std::size_t container_index;
30  std::size_t param_index;
31  };
33  std::unordered_map<irep_idt, container_paramt> param_to_container;
36  std::vector<std::stack<std::vector<reference_typet>>>
38 
39 public:
44  std::size_t insert(
45  const std::vector<java_generic_parametert> &parameters,
46  std::vector<reference_typet> types);
47 
50  void pop(std::size_t container_index);
51 
57  std::optional<reference_typet> pop(const irep_idt &parameter_name);
58 
61  struct printert
62  {
64  const namespacet &ns;
65 
68  const namespacet &ns)
69  : map(map), ns(ns)
70  {
71  }
72  };
73 
74  template <typename ostreamt>
75  friend ostreamt &operator<<(ostreamt &stm, const printert &map);
76 };
77 
85 template <typename ostreamt>
86 ostreamt &operator<<(
87  ostreamt &stm,
89 {
90  if(map.map.container_to_specializations.empty())
91  stm << "empty map";
92  else
93  stm << "map:\n";
94  std::vector<std::vector<irep_idt>> container_to_params(
96  for(const auto &elt : map.map.param_to_container)
97  {
98  std::vector<irep_idt> &params =
99  container_to_params[elt.second.container_index];
100  if(params.size() < elt.second.param_index + 1)
101  params.resize(elt.second.param_index + 1);
102  params[elt.second.param_index] = elt.first;
103  }
104  const namespacet &ns = map.ns;
105  for(std::size_t index = 0; index < container_to_params.size(); ++index)
106  {
107  stm << "<";
108  join_strings(
109  stm,
110  container_to_params.at(index).begin(),
111  container_to_params.at(index).end(),
112  ", ");
113  stm << ">: ";
114  std::stack<std::vector<reference_typet>> stack =
115  map.map.container_to_specializations.at(index);
116  while(!stack.empty())
117  {
118  stm << "<";
119  join_strings(
120  stm,
121  stack.top().begin(),
122  stack.top().end(),
123  ", ",
124  [&ns](const reference_typet &pointer_type) {
125  if(is_java_generic_parameter(pointer_type))
126  {
127  return id2string(
128  to_java_generic_parameter(pointer_type).get_name());
129  }
130  else
131  return type2java(pointer_type, ns);
132  });
133  stm << ">, ";
134  stack.pop();
135  }
136  stm << "\n";
137  }
138  return stm;
139 }
140 
141 #endif // CPROVER_JAVA_BYTECODE_GENERIC_PARAMETER_SPECIALIZATION_MAP_H
pointer_typet pointer_type(const typet &subtype)
Definition: c_types.cpp:235
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
std::vector< std::stack< std::vector< reference_typet > > > container_to_specializations
The list of containers and, for each one, the stack of lists of specializations.
std::size_t insert(const std::vector< java_generic_parametert > &parameters, std::vector< reference_typet > types)
Insert a specialization for each type parameters of a container.
std::unordered_map< irep_idt, container_paramt > param_to_container
A map from parameter names to container_paramt instances.
friend ostreamt & operator<<(ostreamt &stm, const printert &map)
Output a generic_parameter_specialization_mapt wrapped in a generic_parameter_specialization_mapt::pr...
void pop(std::size_t container_index)
Pop the top of the specialization stack for a given container.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The reference type.
Definition: pointer_expr.h:121
std::string type2java(const typet &type, const namespacet &ns)
Definition: expr2java.cpp:461
ostreamt & operator<<(ostreamt &stm, const generic_parameter_specialization_mapt::printert &map)
Output a generic_parameter_specialization_mapt wrapped in a generic_parameter_specialization_mapt::pr...
Stream & join_strings(Stream &&os, const It b, const It e, const Delimiter &delimiter, TransformFunc &&transform_func)
Prints items to an stream, separated by a constant delimiter.
Definition: string_utils.h:61
The index of the container and the type parameter inside that container.
A wrapper for a generic_parameter_specialization_mapt and a namespacet that can be output to a stream...
printert(const generic_parameter_specialization_mapt &map, const namespacet &ns)