/*******************************************************************\ Module: C++ Language Type Checking Author: Daniel Kroening, kroening@cs.cmu.edu \*******************************************************************/ /// \file /// C++ Language Type Checking #include "template_map.h" #include #include #include #include "cpp_template_parameter.h" #include "cpp_template_type.h" #include void template_mapt::apply(typet &type) const { if(type.id()==ID_array) { apply(to_array_type(type).element_type()); apply(to_array_type(type).size()); } else if(type.id()==ID_pointer) { apply(to_pointer_type(type).base_type()); } else if(type.id()==ID_struct || type.id()==ID_union) { for(auto &c : to_struct_union_type(type).components()) { typet &subtype = c.type(); apply(subtype); } } else if(type.id() == ID_template_parameter_symbol_type) { type_mapt::const_iterator m_it = type_map.find(to_template_parameter_symbol_type(type).get_identifier()); if(m_it!=type_map.end()) { type=m_it->second; return; } } else if(type.id()==ID_code) { apply(to_code_type(type).return_type()); irept::subt ¶meters=type.add(ID_parameters).get_sub(); for(auto ¶meter : parameters) { if(parameter.id() == ID_parameter) apply(static_cast(parameter.add(ID_type))); } } else if(type.id()==ID_merged_type) { for(typet &subtype : to_type_with_subtypes(type).subtypes()) apply(subtype); } } void template_mapt::apply(exprt &expr) const { apply(expr.type()); if(expr.id()==ID_symbol) { expr_mapt::const_iterator m_it = expr_map.find(to_symbol_expr(expr).get_identifier()); if(m_it!=expr_map.end()) { expr=m_it->second; return; } } Forall_operands(it, expr) apply(*it); } exprt template_mapt::lookup(const irep_idt &identifier) const { type_mapt::const_iterator t_it= type_map.find(identifier); if(t_it!=type_map.end()) { exprt e(ID_type); e.type()=t_it->second; return e; } expr_mapt::const_iterator e_it= expr_map.find(identifier); if(e_it!=expr_map.end()) return e_it->second; return static_cast(get_nil_irep()); } typet template_mapt::lookup_type(const irep_idt &identifier) const { type_mapt::const_iterator t_it= type_map.find(identifier); if(t_it!=type_map.end()) return t_it->second; return static_cast(get_nil_irep()); } exprt template_mapt::lookup_expr(const irep_idt &identifier) const { expr_mapt::const_iterator e_it= expr_map.find(identifier); if(e_it!=expr_map.end()) return e_it->second; return static_cast(get_nil_irep()); } void template_mapt::print(std::ostream &out) const { for(const auto &mapping : type_map) out << mapping.first << " = " << mapping.second.pretty() << '\n'; for(const auto &mapping : expr_map) out << mapping.first << " = " << mapping.second.pretty() << '\n'; } void template_mapt::build( const template_typet &template_type, const cpp_template_args_tct &template_args) { const template_typet::template_parameterst &template_parameters= template_type.template_parameters(); cpp_template_args_tct::argumentst instance= template_args.arguments(); template_typet::template_parameterst::const_iterator t_it= template_parameters.begin(); if(instance.size()