Skip to content

Commit 7a5a1e0

Browse files
author
Pascal Kesseli
committed
Extended null object CEGIS implementation.
1 parent bf427fe commit 7a5a1e0

File tree

8 files changed

+68
-20
lines changed

8 files changed

+68
-20
lines changed

src/cegis/cegis-util/type_helper.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#include <algorithm>
2+
13
#include <util/std_types.h>
24
#include <util/symbol_table.h>
35
#include <util/type_eq.h>
46
#include <util/namespace.h>
57

8+
#include <cegis/cegis-util/type_helper.h>
9+
610
#define TAG_PREFIX "tag-"
711

812
const typet &replace_struct_by_symbol_type(const symbol_tablet &st,
@@ -42,3 +46,17 @@ bool instanceof(const symbol_tablet &st, const typet &lhs, const typet &rhs)
4246
return type_eq(resolved_lhs, resolved_rhs, ns);
4347
return instanceof(resolved_lhs, resolved_rhs, ns);
4448
}
49+
50+
instanceof_anyt::instanceof_anyt(const symbol_tablet &st,
51+
const std::set<typet> &types) :
52+
st(st), types(types)
53+
{
54+
}
55+
56+
bool instanceof_anyt::operator ()(const typet &type) const
57+
{
58+
return types.end()
59+
!= std::find_if(types.begin(), types.end(),
60+
[this, &type](const typet &rhs)
61+
{ return instanceof(st, type, rhs);});
62+
}

src/cegis/cegis-util/type_helper.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef CEGIS_UTIL_TYPE_HELPER_H_
1111
#define CEGIS_UTIL_TYPE_HELPER_H_
1212

13+
#include <set>
14+
1315
/**
1416
* @brief
1517
*
@@ -33,4 +35,36 @@ const class typet &replace_struct_by_symbol_type(
3335
*/
3436
bool instanceof(const symbol_tablet &st, const typet &lhs, const typet &rhs);
3537

38+
/**
39+
* @brief
40+
*
41+
* @details
42+
*/
43+
class instanceof_anyt
44+
{
45+
const symbol_tablet &st;
46+
const std::set<typet> &types;
47+
public:
48+
/**
49+
* @brief
50+
*
51+
* @details
52+
*
53+
* @param st
54+
* @param types
55+
*/
56+
instanceof_anyt(const symbol_tablet &st, const std::set<typet> &types);
57+
58+
/**
59+
* @brief
60+
*
61+
* @details
62+
*
63+
* @param type
64+
*
65+
* @return
66+
*/
67+
bool operator()(const typet &type) const;
68+
};
69+
3670
#endif /* CEGIS_UTIL_TYPE_HELPER_H_ */

src/cegis/refactor/environment/instrument_state_vars.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
void instrument_state_vars(goto_programt &body,
44
const goto_programt::targett &first, const goto_programt::targett &last,
5-
std::function<bool(const goto_programt::instructiont &)> predicate)
5+
const std::function<bool(const typet &)> predicate)
66
{
77
// TODO: Implement
88
assert(false);
99
}
1010

1111
namespace
1212
{
13-
bool yes(const goto_programt::instructiont &instr)
13+
bool yes(const typet &instr)
1414
{
1515
return true;
1616
}

src/cegis/refactor/environment/instrument_state_vars.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void instrument_state_vars(
2828
goto_programt &body,
2929
const goto_programt::targett &first,
3030
const goto_programt::targett &last,
31-
std::function<bool(const goto_programt::instructiont &)> predicate);
31+
std::function<bool(const typet &)> predicate);
3232

3333
/**
3434
* @brief

src/cegis/refactor/instructionset/create_cegis_processor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ class type_collectort: public const_expr_visitort
1616
};
1717
}
1818

19-
std::set<typet> collect_context_types(goto_programt::const_targett first,
20-
const goto_programt::const_targett &last)
19+
std::set<typet> collect_context_types(const goto_ranget &range)
2120
{
2221
type_collectort collector;
23-
for (; first != last; ++first)
24-
first->code.visit(collector);
22+
for (goto_programt::const_targett it(range.first); it != range.second; ++it)
23+
it->code.visit(collector);
2524
return collector.types;
2625
}
2726

2827
void create_cegis_processor(const std::set<typet> &state_types,
2928
const size_t var_slots_per_state_type, const std::set<typet> &context_types)
3029
{
31-
30+
// TODO: Implement
31+
assert(false);
3232
}

src/cegis/refactor/instructionset/create_cegis_processor.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@
1313
#include <set>
1414

1515
#include <util/type.h>
16-
#include <goto-programs/goto_program.h>
16+
17+
#include <cegis/cegis-util/goto_range.h>
1718

1819
/**
1920
* @brief
2021
*
2122
* @details
2223
*
23-
* @param first
24-
* @param last
24+
* @param range
2525
*
2626
* @return
2727
*/
28-
std::set<typet> collect_context_types(
29-
goto_programt::const_targett first,
30-
const goto_programt::const_targett &last);
28+
std::set<typet> collect_context_types(const goto_ranget &range);
3129

3230
/**
3331
* @brief

src/cegis/refactor/nullobject/range_collector.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ void collect_nullobject_ranges(refactor_programt &prog)
5050
sketch.spec_range=else_range;
5151
sketch.input_range=then_range;
5252
}
53-
sketch.types=collect_context_types(then_range.first, then_range.second);
54-
const std::set<typet> tmp(
55-
collect_context_types(else_range.first, else_range.second));
53+
sketch.types=collect_context_types(then_range);
54+
const std::set<typet> tmp(collect_context_types(else_range));
5655
sketch.types.insert(tmp.begin(), tmp.end());
5756
}
5857
}

src/cegis/refactor/preprocessing/refactor_preprocessing.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <cegis/options/parameters.h>
66
#include <cegis/cegis-util/inline_user_program.h>
77
#include <cegis/cegis-util/program_helper.h>
8+
#include <cegis/cegis-util/type_helper.h>
89
#include <cegis/refactor/environment/instrument_state_vars.h>
910
#include <cegis/refactor/nullobject/range_collector.h>
1011
#include <cegis/refactor/preprocessing/refactor_preprocessing.h>
@@ -27,9 +28,7 @@ void refactor_preprocessingt::operator()()
2728
{
2829
goto_ranget &input_range=sketch.input_range;
2930
goto_programt &body=get_body(gf, input_range.first);
30-
const std::function<bool(const goto_programt::instructiont &)> pred=
31-
[&st, &sketch](const goto_programt::instructiont &instr)
32-
{ return false;};
31+
const instanceof_anyt pred(st, sketch.types);
3332
instrument_state_vars(body, input_range.first, input_range.second, pred);
3433
}
3534
// TODO: collect_

0 commit comments

Comments
 (0)