cprover
select_pointer_typet Class Reference

#include <select_pointer_type.h>

Public Member Functions

virtual ~select_pointer_typet ()=default
 
virtual pointer_typet convert_pointer_type (const pointer_typet &pointer_type, const generic_parameter_specialization_mapt &generic_parameter_specialization_map, const namespacet &ns) const
 Select what type should be used for a given pointer type. More...
 
virtual std::set< struct_tag_typetget_parameter_alternative_types (const irep_idt &function_name, const irep_idt &parameter_name, const namespacet &ns) const
 Get alternative types for a method parameter, e.g., based on the casts in the function body. More...
 
pointer_typet specialize_generics (const pointer_typet &pointer_type, const generic_parameter_specialization_mapt &generic_parameter_specialization_map, generic_parameter_recursion_trackingt &visited_nodes) const
 Specialize generic parameters in a pointer type based on the current map of parameters -> types. More...
 

Private Member Functions

optionalt< pointer_typetget_recursively_instantiated_type (const irep_idt &, const generic_parameter_specialization_mapt &, generic_parameter_recursion_trackingt &, const size_t) const
 See get_recursively instantiated_type, the additional parameters just track the recursion to prevent visiting the same depth again and specify which stack depth is analyzed. More...
 
optionalt< pointer_typetget_recursively_instantiated_type (const irep_idt &parameter_name, const generic_parameter_specialization_mapt &visited) const
 Return the first concrete type instantiation if any such exists. More...
 

Detailed Description

Definition at line 28 of file select_pointer_type.h.

Constructor & Destructor Documentation

◆ ~select_pointer_typet()

virtual select_pointer_typet::~select_pointer_typet ( )
virtualdefault

Member Function Documentation

◆ convert_pointer_type()

pointer_typet select_pointer_typet::convert_pointer_type ( const pointer_typet pointer_type,
const generic_parameter_specialization_mapt generic_parameter_specialization_map,
const namespacet ns 
) const
virtual

Select what type should be used for a given pointer type.

In the base class we just use the supplied type. Derived classes can override this behavior to provide more sophisticated type selection. Generic parameters are replaced with their specialized type.

Parameters
pointer_typeThe pointer type to convert
generic_parameter_specialization_mapMap of types for all generic parameters in the current scope
nsNamespace for type lookups
Returns
A pointer type where the subtype may have been modified

Definition at line 17 of file select_pointer_type.cpp.

◆ get_parameter_alternative_types()

std::set< struct_tag_typet > select_pointer_typet::get_parameter_alternative_types ( const irep_idt function_name,
const irep_idt parameter_name,
const namespacet ns 
) const
virtual

Get alternative types for a method parameter, e.g., based on the casts in the function body.

In the base class we just return an empty set. Derived classes can override this behaviour to provide more sophisticated alternative type identification.

Definition at line 212 of file select_pointer_type.cpp.

◆ get_recursively_instantiated_type() [1/2]

optionalt< pointer_typet > select_pointer_typet::get_recursively_instantiated_type ( const irep_idt parameter_name,
const generic_parameter_specialization_mapt generic_parameter_specialization_map,
generic_parameter_recursion_trackingt visited,
const size_t  depth 
) const
private

See get_recursively instantiated_type, the additional parameters just track the recursion to prevent visiting the same depth again and specify which stack depth is analyzed.

Parameters
parameter_nameThe name of the generic parameter type we want to have instantiated
generic_parameter_specialization_mapMap of type names to specialization stack
visitedTracks the visited parameter names
depthStack depth to analyze
Returns
if this type is not a generic type, it is returned as a valid instantiation, if nothing can be found at the given depth, en empty optional is returned

Definition at line 170 of file select_pointer_type.cpp.

◆ get_recursively_instantiated_type() [2/2]

optionalt< pointer_typet > select_pointer_typet::get_recursively_instantiated_type ( const irep_idt parameter_name,
const generic_parameter_specialization_mapt generic_parameter_specialization_map 
) const
private

Return the first concrete type instantiation if any such exists.

This method is only to be called when select_pointer_typet::specialize_generics cannot find an instantiation due to a loop in its recursion.

Example: class MyGeneric<T,U> { MyGeneric<U,T> gen; T t;} When instantiating MyGeneric<Integer,String> my we need to for example resolve the type of my.gen.t. The map would in this context contain

  • T -> (Integer, U)
  • U -> (String, T)

Note that the top of the stacks for T and U create a recursion T -> U, U-> T. We want to break it and specialize T my.gen.t to String my.gen.t.

Parameters
parameter_nameThe name of the generic parameter type we want to have instantiated
generic_parameter_specialization_mapMap of type names to specialization stack
Returns
The first instantiated type for the generic type or nothing if no such instantiation exists.

Definition at line 128 of file select_pointer_type.cpp.

◆ specialize_generics()

pointer_typet select_pointer_typet::specialize_generics ( const pointer_typet pointer_type,
const generic_parameter_specialization_mapt generic_parameter_specialization_map,
generic_parameter_recursion_trackingt visited_nodes 
) const

Specialize generic parameters in a pointer type based on the current map of parameters -> types.

We specialize generics only if the pointer is a java generic parameter or an array with generic parameters. More general generic types such as MyGeneric<T> are specialized indirectly in java_object_factoryt, their concrete types are already stored in the map and will be retrieved when needed e.g., to initialize fields. Example:

  • generic type: T
  • map: T -> U; U -> String
  • result: String
  • generic type: T[]
  • map: T -> U; U -> String
  • result: String[]
    Parameters
    pointer_typeThe pointer to be specialized
    generic_parameter_specialization_mapMap of types for all generic parameters in the current scope
    visited_nodesSet of parameter names already considered in recursion, used to avoid infinite recursion
    Returns
    Pointer type where generic parameters are replaced with specialized types (if set in the current scope)

Definition at line 40 of file select_pointer_type.cpp.


The documentation for this class was generated from the following files: