cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
cpp_typecheck_fargs.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: C++ Language Type Checking
4
5
Author: Daniel Kroening, kroening@cs.cmu.edu
6
7
\*******************************************************************/
8
11
12
#include "
cpp_typecheck_fargs.h
"
13
14
#include <
util/std_types.h
>
15
16
#include "
cpp_typecheck.h
"
17
18
bool
cpp_typecheck_fargst::has_class_type
()
const
19
{
20
for
(
const
auto
&op :
operands
)
21
{
22
if
(op.type().id() == ID_struct)
23
return
true
;
24
}
25
26
return
false
;
27
}
28
29
void
cpp_typecheck_fargst::build
(
30
const
side_effect_expr_function_callt
&function_call)
31
{
32
in_use
=
true
;
33
operands
= function_call.
arguments
();
34
}
35
36
bool
cpp_typecheck_fargst::match
(
37
const
code_typet
&code_type,
38
unsigned
&distance,
39
cpp_typecheckt
&
cpp_typecheck
)
const
40
{
41
distance=0;
42
43
exprt::operandst
ops=
operands
;
44
const
code_typet::parameterst
¶meters=code_type.
parameters
();
45
46
if
(parameters.size()>ops.size())
47
{
48
// Check for default values.
49
ops.reserve(parameters.size());
50
51
for
(std::size_t i=ops.size(); i<parameters.size(); i++)
52
{
53
const
exprt
&default_value=
54
parameters[i].default_value();
55
56
if
(default_value.
is_nil
())
57
return
false
;
58
59
ops.push_back(default_value);
60
}
61
}
62
else
if
(parameters.size()<ops.size())
63
{
64
// check for ellipsis
65
if
(!code_type.
has_ellipsis
())
66
return
false
;
67
}
68
69
exprt::operandst::iterator it=ops.begin();
70
for
(
const
auto
¶meter : parameters)
71
{
72
// read
73
// http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/topic/
74
// com.ibm.xlcpp8a.doc/language/ref/implicit_conversion_sequences.htm
75
//
76
// The following are the three categories of conversion sequences
77
// in order from best to worst:
78
// * Standard conversion sequences
79
// * User-defined conversion sequences
80
// * Ellipsis conversion sequences
81
82
DATA_INVARIANT
(it != ops.end(),
"arguments and parameters must match"
);
83
const
exprt
&operand=*it;
84
typet
type=parameter.type();
85
86
#if 0
87
// unclear, todo
88
if
(
is_reference
(operand.
type
()))
89
std::cout <<
"O: "
<< operand.
pretty
() <<
'\n'
;
90
91
assert(!
is_reference
(operand.
type
()));
92
#endif
93
94
// "this" is a special case -- we turn the pointer type
95
// into a reference type to do the type matching
96
if
(it == ops.begin() && parameter.get_this())
97
{
98
type.
set
(ID_C_reference,
true
);
99
type.
set
(ID_C_this,
true
);
100
}
101
102
unsigned
rank=0;
103
exprt
new_expr;
104
105
#if 0
106
std::cout <<
"C: "
<<
cpp_typecheck
.to_string(operand.
type
())
107
<<
" -> "
<<
cpp_typecheck
.to_string(parameter.type())
108
<<
'\n'
;
109
#endif
110
111
// can we do the standard conversion sequence?
112
if
(
cpp_typecheck
.implicit_conversion_sequence(
113
operand, type, new_expr, rank))
114
{
115
// ok
116
distance+=rank;
117
#if 0
118
std::cout <<
"OK "
<< rank <<
'\n'
;
119
#endif
120
}
121
else
if
(
122
operand.
id
() == ID_initializer_list &&
cpp_typecheck
.cpp_is_pod(type) &&
123
operand.
operands
().size() == 1 &&
124
cpp_typecheck
.implicit_conversion_sequence(
125
to_unary_expr
(operand).op(), type, new_expr, rank))
126
{
127
distance += rank;
128
}
129
else
130
{
131
#if 0
132
std::cout <<
"NOT OK\n"
;
133
#endif
134
return
false
;
// no conversion possible
135
}
136
137
++it;
138
}
139
140
// we may not have used all operands
141
for
( ; it!=ops.end(); ++it)
142
// Ellipsis is the 'worst' of the conversion sequences
143
distance+=1000;
144
145
return
true
;
146
}
code_typet
Base type of functions.
Definition
std_types.h:583
code_typet::parameterst
std::vector< parametert > parameterst
Definition
std_types.h:586
code_typet::parameters
const parameterst & parameters() const
Definition
std_types.h:699
code_typet::has_ellipsis
bool has_ellipsis() const
Definition
std_types.h:655
cpp_typecheck_fargst::operands
exprt::operandst operands
Definition
cpp_typecheck_fargs.h:25
cpp_typecheck_fargst::in_use
bool in_use
Definition
cpp_typecheck_fargs.h:24
cpp_typecheck_fargst::match
bool match(const code_typet &code_type, unsigned &distance, cpp_typecheckt &cpp_typecheck) const
Definition
cpp_typecheck_fargs.cpp:36
cpp_typecheck_fargst::has_class_type
bool has_class_type() const
Definition
cpp_typecheck_fargs.cpp:18
cpp_typecheck_fargst::build
void build(const side_effect_expr_function_callt &function_call)
Definition
cpp_typecheck_fargs.cpp:29
cpp_typecheckt
Definition
cpp_typecheck.h:43
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::operandst
std::vector< exprt > operandst
Definition
expr.h:59
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
exprt::operands
operandst & operands()
Definition
expr.h:95
irept::pretty
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition
irep.cpp:482
irept::set
void set(const irep_idt &name, const irep_idt &value)
Definition
irep.h:412
irept::id
const irep_idt & id() const
Definition
irep.h:388
irept::is_nil
bool is_nil() const
Definition
irep.h:368
side_effect_expr_function_callt
A side_effect_exprt representation of a function call side effect.
Definition
std_code.h:1692
side_effect_expr_function_callt::arguments
exprt::operandst & arguments()
Definition
std_code.h:1718
typet
The type of an expression, extends irept.
Definition
type.h:29
cpp_typecheck
bool cpp_typecheck(cpp_parse_treet &cpp_parse_tree, symbol_table_baset &symbol_table, const std::string &module, message_handlert &message_handler)
Definition
cpp_typecheck.cpp:137
cpp_typecheck.h
C++ Language Type Checking.
cpp_typecheck_fargs.h
C++ Language Type Checking.
is_reference
bool is_reference(const typet &type)
Returns true if the type is a reference.
Definition
std_types.cpp:145
DATA_INVARIANT
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition
invariant.h:534
to_unary_expr
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
Definition
std_expr.h:414
std_types.h
Pre-defined types.
cpp
cpp_typecheck_fargs.cpp
Generated by
1.17.0