Skip to content

Pointer cleanup #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/ansi-c/ansi_c_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,13 @@ bool ansi_c_entry_point(
zero_string.type().set(ID_size, "infinity");
exprt index(ID_index, char_type());
index.copy_to_operands(zero_string, from_integer(0, uint_type()));
exprt address_of("address_of", pointer_typet());
address_of.type().subtype()=char_type();
address_of.copy_to_operands(index);
exprt address_of=address_of_exprt(index, pointer_type(char_type()));

if(argv_symbol.type.subtype()!=address_of.type())
address_of.make_typecast(argv_symbol.type.subtype());

// assign argv[*] to the address of a string-object
exprt array_of("array_of", argv_symbol.type);
array_of.copy_to_operands(address_of);
array_of_exprt array_of(address_of, argv_symbol.type);

init_code.copy_to_operands(
code_assignt(argv_symbol.symbol_expr(), array_of));
Expand Down Expand Up @@ -400,17 +397,18 @@ bool ansi_c_entry_point(

{
const exprt &arg1=parameters[1];
const pointer_typet &pointer_type=
to_pointer_type(arg1.type());

exprt index_expr(ID_index, arg1.type().subtype());
index_expr.copy_to_operands(
index_exprt index_expr(
argv_symbol.symbol_expr(),
from_integer(0, index_type()));
from_integer(0, index_type()),
pointer_type.subtype());

// disable bounds check on that one
index_expr.set("bounds_check", false);

op1=exprt(ID_address_of, arg1.type());
op1.move_to_operands(index_expr);
op1=address_of_exprt(index_expr, pointer_type);
}

// do we need envp?
Expand All @@ -420,13 +418,15 @@ bool ansi_c_entry_point(
exprt &op2=operands[2];

const exprt &arg2=parameters[2];
const pointer_typet &pointer_type=
to_pointer_type(arg2.type());

exprt index_expr(ID_index, arg2.type().subtype());
index_expr.copy_to_operands(
envp_symbol.symbol_expr(), from_integer(0, index_type()));
index_exprt index_expr(
envp_symbol.symbol_expr(),
from_integer(0, index_type()),
pointer_type.subtype());

op2=exprt(ID_address_of, arg2.type());
op2.move_to_operands(index_expr);
op2=address_of_exprt(index_expr, pointer_type);
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,10 @@ void c_typecheck_baset::typecheck_expr_symbol(exprt &expr)

if(expr.type().id()==ID_code) // function designator
{ // special case: this is sugar for &f
exprt tmp(ID_address_of, pointer_type(expr.type()));
address_of_exprt tmp(expr, pointer_type(expr.type()));
tmp.set("#implicit", true);
tmp.add_source_location()=expr.source_location();
tmp.move_to_operands(expr);
expr.swap(tmp);
expr=tmp;
}
}
}
Expand Down Expand Up @@ -1778,11 +1777,10 @@ void c_typecheck_baset::typecheck_expr_function_identifier(exprt &expr)
{
if(expr.type().id()==ID_code)
{
exprt tmp(ID_address_of, pointer_type(expr.type()));
address_of_exprt tmp(expr, pointer_type(expr.type()));
tmp.set(ID_C_implicit, true);
tmp.add_source_location()=expr.source_location();
tmp.move_to_operands(expr);
expr.swap(tmp);
expr=tmp;
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,9 +1498,7 @@ void c_typecheck_baset::adjust_function_parameter(typet &type) const
{
// see ISO/IEC 9899:1999 page 199 clause 8,
// may be hidden in typedef
pointer_typet tmp;
tmp.subtype()=type;
type.swap(tmp);
type=pointer_type(type);
}
else if(type.id()==ID_KnR)
{
Expand Down
5 changes: 1 addition & 4 deletions src/cpp/cpp_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,7 @@ codet cpp_typecheckt::cpp_constructor(
assert(tmp_this.id()==ID_address_of
&& tmp_this.op0().id()=="new_object");

exprt address_of(ID_address_of, typet(ID_pointer));
address_of.type().subtype()=object_tc.type();
address_of.copy_to_operands(object_tc);
tmp_this.swap(address_of);
tmp_this=address_of_exprt(object_tc);

if(block.operands().empty())
return to_code(initializer);
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/cpp_convert_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ void cpp_convert_typet::read_function_type(const typet &type)
// see if it's an array type
if(final_type.id()==ID_array)
{
final_type.id(ID_pointer);
final_type.remove(ID_size);
// turn into pointer type
final_type=pointer_type(final_type.subtype());
}

code_typet::parametert new_parameter(final_type);
Expand Down
5 changes: 1 addition & 4 deletions src/cpp/cpp_destructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ codet cpp_typecheckt::cpp_destructor(
assert(tmp_this.id()==ID_address_of
&& tmp_this.op0().id()=="new_object");

exprt address_of(ID_address_of, typet(ID_pointer));
address_of.type().subtype()=object.type();
address_of.copy_to_operands(object);
tmp_this.swap(address_of);
tmp_this=address_of_exprt(object, pointer_type(object.type()));

new_code.swap(initializer);
}
Expand Down
7 changes: 4 additions & 3 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
#include <util/arith_tools.h>
#include <util/simplify_expr.h>
#include <util/std_types.h>
#include <util/c_types.h>

#include <ansi-c/c_qualifiers.h>

Expand Down Expand Up @@ -545,7 +546,7 @@ void cpp_typecheckt::typecheck_compound_declarator(

// add a virtual-table pointer
struct_typet::componentt compo;
compo.type()=pointer_typet(symbol_typet(vt_name));
compo.type()=pointer_type(symbol_typet(vt_name));
compo.set_name(id2string(symbol.name) +"::@vtable_pointer");
compo.set(ID_base_name, "@vtable_pointer");
compo.set(
Expand All @@ -567,7 +568,7 @@ void cpp_typecheckt::typecheck_compound_declarator(

// add an entry to the virtual table
struct_typet::componentt vt_entry;
vt_entry.type()=pointer_typet(component.type());
vt_entry.type()=pointer_type(component.type());
vt_entry.set_name(id2string(vtit->first)+"::"+virtual_name);
vt_entry.set(ID_base_name, virtual_name);
vt_entry.set(ID_pretty_name, virtual_name);
Expand Down Expand Up @@ -1353,7 +1354,7 @@ void cpp_typecheckt::add_this_to_method_type(
if(has_volatile(method_qualifier))
subtype.set(ID_C_volatile, true);

parameter.type()=pointer_typet(subtype);
parameter.type()=pointer_type(subtype);
}

void cpp_typecheckt::add_anonymous_members_to_scope(
Expand Down
Loading