Skip to content

Commit ef04e12

Browse files
Merge pull request #663 from NathanJPhillips/feature/serialization
Added serialization of irept and dstringt
2 parents a39da77 + 0764707 commit ef04e12

File tree

8 files changed

+972
-1
lines changed

8 files changed

+972
-1
lines changed

src/config.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ BUILD_ENV = AUTO
99

1010
# Select optimisation or debug info
1111
#CXXFLAGS += -O2 -DNDEBUG
12-
#CXXFLAGS += -O0 -g
12+
CXXFLAGS += -O0 -g
1313

1414
ifeq ($(shell uname),Linux)
1515
CXXFLAGS += -DUSE_BOOST

src/util/dstring.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,33 @@ Author: Daniel Kroening, [email protected]
77
\*******************************************************************/
88

99
#include "dstring.h"
10+
#include "serializer.h"
11+
12+
13+
/*******************************************************************\
14+
15+
Function: dstring::serialize
16+
17+
Inputs:
18+
serializer: The serializer to read from/write to
19+
20+
Outputs:
21+
22+
Purpose:
23+
Serializes this instance to/from the given serializer.
24+
25+
\*******************************************************************/
26+
void dstringt::serialize(serializert &serializer)
27+
{
28+
if(serializer.is_for_reading())
29+
{
30+
std::string str;
31+
serializer.serialize("dstring", str);
32+
no=string_container[str];
33+
}
34+
else
35+
{
36+
std::string str=as_string();
37+
serializer.serialize("dstring", str);
38+
}
39+
}

src/util/dstring.h

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include "string_container.h"
1515

16+
class serializert;
17+
18+
1619
class dstringt
1720
{
1821
public:
@@ -123,6 +126,8 @@ class dstringt
123126
return out << as_string();
124127
}
125128

129+
void serialize(serializert &serializer);
130+
126131
// non-standard
127132

128133
unsigned get_no() const

src/util/file_util.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,31 @@ std::string fileutl_get_relative_path(
371371
std::string const result = fileutl_join_path_parts(split1);
372372
return result;
373373
}
374+
375+
/*******************************************************************\
376+
377+
Function: make_valid_filename
378+
379+
Inputs:
380+
file_name: The file name to sanitize.
381+
382+
Outputs:
383+
384+
Purpose:
385+
Replaces invalid characters in a file name using a hard-coded list of
386+
replacements.
387+
This is not designed to operate on path names and will replace folder
388+
seperator characters.
389+
390+
\*******************************************************************/
391+
std::string make_valid_filename(std::string file_name)
392+
{
393+
std::replace(file_name.begin(), file_name.end(), '#', '_');
394+
std::replace(file_name.begin(), file_name.end(), '$', '_');
395+
std::replace(file_name.begin(), file_name.end(), ':', '.');
396+
std::replace(file_name.begin(), file_name.end(), '/', '.');
397+
std::replace(file_name.begin(), file_name.end(), '\\', '.');
398+
std::replace(file_name.begin(), file_name.end(), '<', '[');
399+
std::replace(file_name.begin(), file_name.end(), '>', ']');
400+
return file_name;
401+
}

src/util/file_util.h

+2
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,6 @@ std::string fileutl_get_relative_path(
6262
std::string const &pathname,
6363
std::string const &directory);
6464

65+
std::string make_valid_filename(std::string filename);
66+
6567
#endif // CPROVER_UTIL_FILE_UTIL_H

src/util/irep.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include "string2int.h"
1313
#include "irep.h"
1414
#include "string_hash.h"
15+
#include "serializer.h"
1516
#include "irep_hash.h"
1617

1718
#ifdef SUB_IS_LIST
@@ -1003,3 +1004,24 @@ std::string irept::pretty(unsigned indent, unsigned max_indent) const
10031004

10041005
return result;
10051006
}
1007+
1008+
/*******************************************************************\
1009+
1010+
Function: irept::serialize
1011+
1012+
Inputs:
1013+
serializer: The serializer to read from/write to
1014+
1015+
Outputs:
1016+
1017+
Purpose:
1018+
Serializes this instance to/from the given serializer.
1019+
1020+
\*******************************************************************/
1021+
void irept::serialize(serializert &serializer)
1022+
{
1023+
serializer.serialize("id", write().data);
1024+
serializer.serialize("subs", get_sub());
1025+
serializer.serialize("named_subs", get_named_sub());
1026+
serializer.serialize("comments", get_comments());
1027+
}

src/util/irep.h

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ typedef std::string irep_namet;
4545
typedef string_hash irep_id_hash;
4646
#endif
4747

48+
class serializert;
49+
50+
4851
inline const std::string &id2string(const irep_idt &d)
4952
{
5053
#ifdef USE_DSTRING
@@ -257,6 +260,8 @@ class irept
257260

258261
std::string pretty(unsigned indent=0, unsigned max_indent=0) const;
259262

263+
void serialize(serializert &serializer);
264+
260265
protected:
261266
static bool is_comment(const irep_namet &name)
262267
{ return !name.empty() && name[0]=='#'; }

0 commit comments

Comments
 (0)