Skip to content

Commit fc4c0fe

Browse files
author
Daniel Kroening
authored
Merge pull request #880 from NathanJPhillips/feature/enable-goto-model-move-assignment
Enable goto_modelt move assignment
2 parents 7e1ba16 + 389fbcd commit fc4c0fe

File tree

6 files changed

+115
-29
lines changed

6 files changed

+115
-29
lines changed

src/goto-instrument/wmm/goto2graph.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1532,13 +1532,12 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet &cyc)
15321532
}
15331533

15341534
/* now test whether this part of the code can exist */
1535+
goto_functionst::function_mapt map;
15351536
goto_function_templatet<goto_programt> one_interleaving;
15361537
one_interleaving.body.copy_from(interleaving);
1537-
1538-
std::pair<irep_idt, goto_function_templatet<goto_programt> > p(
1539-
goto_functionst::entry_point(), one_interleaving);
1540-
goto_functionst::function_mapt map;
1541-
map.insert(p);
1538+
map.insert(std::make_pair(
1539+
goto_functionst::entry_point(),
1540+
std::move(one_interleaving)));
15421541

15431542
goto_functionst this_interleaving;
15441543
this_interleaving.function_map=std::move(map);

src/goto-programs/goto_functions.h

+23
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ Date: June 2003
1717
class goto_functionst:public goto_functions_templatet<goto_programt>
1818
{
1919
public:
20+
goto_functionst()=default;
21+
22+
// Copying is unavailable as base class copy is deleted
23+
// MSVC is unable to automatically determine this
24+
goto_functionst(const goto_functionst &)=delete;
25+
goto_functionst &operator=(const goto_functionst &)=delete;
26+
27+
// Move operations need to be explicitly enabled as they are deleted with the
28+
// copy operations
29+
// default for move operations isn't available on Windows yet, so define
30+
// explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx
31+
// under "Defaulted and Deleted Functions")
32+
33+
goto_functionst(goto_functionst &&other):
34+
goto_functions_templatet(std::move(other))
35+
{
36+
}
37+
38+
goto_functionst &operator=(goto_functionst &&other)
39+
{
40+
goto_functions_templatet::operator=(std::move(other));
41+
return *this;
42+
}
2043
};
2144

2245
#define Forall_goto_functions(it, functions) \

src/goto-programs/goto_functions_template.h

+27-8
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,29 @@ class goto_function_templatet
6666
parameter_identifiers.swap(other.parameter_identifiers);
6767
}
6868

69-
void copy_from(const goto_function_templatet<bodyT> &other)
69+
void copy_from(const goto_function_templatet &other)
7070
{
7171
body.copy_from(other.body);
7272
type=other.type;
7373
parameter_identifiers=other.parameter_identifiers;
7474
}
7575

76-
goto_function_templatet(const goto_function_templatet<bodyT> &src):
77-
type(src.type),
78-
parameter_identifiers(src.parameter_identifiers)
76+
goto_function_templatet(const goto_function_templatet &)=delete;
77+
goto_function_templatet &operator=(const goto_function_templatet &)=delete;
78+
79+
goto_function_templatet(goto_function_templatet &&other):
80+
body(std::move(other.body)),
81+
type(std::move(other.type)),
82+
parameter_identifiers(std::move(other.parameter_identifiers))
83+
{
84+
}
85+
86+
goto_function_templatet &operator=(goto_function_templatet &&other)
7987
{
80-
body.copy_from(src.body);
88+
body=std::move(other.body);
89+
type=std::move(other.type);
90+
parameter_identifiers=std::move(other.parameter_identifiers);
91+
return *this;
8192
}
8293
};
8394

@@ -93,10 +104,18 @@ class goto_functions_templatet
93104
{
94105
}
95106

96-
// copy constructor, don't use me!
97-
goto_functions_templatet(const goto_functions_templatet<bodyT> &src)
107+
goto_functions_templatet(const goto_functions_templatet &)=delete;
108+
goto_functions_templatet &operator=(const goto_functions_templatet &)=delete;
109+
110+
goto_functions_templatet(goto_functions_templatet &&other):
111+
function_map(std::move(other.function_map))
112+
{
113+
}
114+
115+
goto_functions_templatet &operator=(goto_functions_templatet &&other)
98116
{
99-
assert(src.function_map.empty());
117+
function_map=std::move(other.function_map);
118+
return *this;
100119
}
101120

102121
void clear()

src/goto-programs/goto_model.h

+19-5
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,28 @@ class goto_modelt
3838
{
3939
}
4040

41-
goto_modelt(goto_modelt &&other)
41+
// Copying is normally too expensive
42+
goto_modelt(const goto_modelt &)=delete;
43+
goto_modelt &operator=(const goto_modelt &)=delete;
44+
45+
// Move operations need to be explicitly enabled as they are deleted with the
46+
// copy operations
47+
// default for move operations isn't available on Windows yet, so define
48+
// explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx
49+
// under "Defaulted and Deleted Functions")
50+
51+
goto_modelt(goto_modelt &&other):
52+
symbol_table(std::move(other.symbol_table)),
53+
goto_functions(std::move(other.goto_functions))
4254
{
43-
symbol_table.swap(other.symbol_table);
44-
goto_functions.swap(other.goto_functions);
4555
}
4656

47-
// copying is likely too expensive
48-
goto_modelt(const goto_modelt &) = delete;
57+
goto_modelt &operator=(goto_modelt &&other)
58+
{
59+
symbol_table=std::move(other.symbol_table);
60+
goto_functions=std::move(other.goto_functions);
61+
return *this;
62+
}
4963
};
5064

5165
#endif // CPROVER_GOTO_PROGRAMS_GOTO_MODEL_H

src/goto-programs/goto_program.h

+23-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Author: Daniel Kroening, [email protected]
1515

1616
#include "goto_program_template.h"
1717

18-
/*! \brief A specialization of goto_program_templatet do
18+
/*! \brief A specialization of goto_program_templatet over
1919
goto programs in which instructions have codet type.
2020
\ingroup gr_goto_programs
2121
*/
@@ -36,6 +36,28 @@ class goto_programt:public goto_program_templatet<codet, exprt>
3636

3737
goto_programt() { }
3838

39+
// Copying is unavailable as base class copy is deleted
40+
// MSVC is unable to automatically determine this
41+
goto_programt(const goto_programt &)=delete;
42+
goto_programt &operator=(const goto_programt &)=delete;
43+
44+
// Move operations need to be explicitly enabled as they are deleted with the
45+
// copy operations
46+
// default for move operations isn't available on Windows yet, so define
47+
// explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx
48+
// under "Defaulted and Deleted Functions")
49+
50+
goto_programt(goto_programt &&other):
51+
goto_program_templatet(std::move(other))
52+
{
53+
}
54+
55+
goto_programt &operator=(goto_programt &&other)
56+
{
57+
goto_program_templatet::operator=(std::move(other));
58+
return *this;
59+
}
60+
3961
// get the variables in decl statements
4062
typedef std::set<irep_idt> decl_identifierst;
4163
void get_decl_identifiers(decl_identifierst &decl_identifiers) const;

src/goto-programs/goto_program_template.h

+19-10
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,26 @@ template <class codeT, class guardT>
5656
class goto_program_templatet
5757
{
5858
public:
59-
/*! \brief copy constructor
60-
\param[in] src an empty goto program
61-
\remark Use copy_from to copy non-empty goto-programs
62-
*/
63-
goto_program_templatet(const goto_program_templatet &src)=delete;
59+
// Copying is deleted as this class contains pointers that cannot be copied
60+
goto_program_templatet(const goto_program_templatet &)=delete;
61+
goto_program_templatet &operator=(const goto_program_templatet &)=delete;
6462

65-
/*! \brief assignment operator
66-
\param[in] src an empty goto program
67-
\remark Use copy_from to copy non-empty goto-programs
68-
*/
69-
goto_program_templatet &operator=(const goto_program_templatet &src)=delete;
63+
// Move operations need to be explicitly enabled as they are deleted with the
64+
// copy operations
65+
// default for move operations isn't available on Windows yet, so define
66+
// explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx
67+
// under "Defaulted and Deleted Functions")
68+
69+
goto_program_templatet(goto_program_templatet &&other):
70+
instructions(std::move(other.instructions))
71+
{
72+
}
73+
74+
goto_program_templatet &operator=(goto_program_templatet &&other)
75+
{
76+
instructions=std::move(other.instructions);
77+
return *this;
78+
}
7079

7180
/*! \brief Container for an instruction of the goto-program
7281
*/

0 commit comments

Comments
 (0)