Skip to content

Added serialization of irept and dstringt #663

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
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
2 changes: 1 addition & 1 deletion src/config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BUILD_ENV = AUTO

# Select optimisation or debug info
#CXXFLAGS += -O2 -DNDEBUG
#CXXFLAGS += -O0 -g
CXXFLAGS += -O0 -g

ifeq ($(shell uname),Linux)
CXXFLAGS += -DUSE_BOOST
Expand Down
30 changes: 30 additions & 0 deletions src/util/dstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,33 @@ Author: Daniel Kroening, [email protected]
\*******************************************************************/

#include "dstring.h"
#include "serializer.h"


/*******************************************************************\

Function: dstring::serialize

Inputs:
serializer: The serializer to read from/write to

Outputs:

Purpose:
Serializes this instance to/from the given serializer.

\*******************************************************************/
void dstringt::serialize(serializert &serializer)
{
if(serializer.is_for_reading())
{
std::string str;
serializer.serialize("dstring", str);
no=string_container[str];
}
else
{
std::string str=as_string();
serializer.serialize("dstring", str);
}
}
5 changes: 5 additions & 0 deletions src/util/dstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Author: Daniel Kroening, [email protected]

#include "string_container.h"

class serializert;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove blank lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you making up new coding standards just to make things less structured/readable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One blank line should be enough to visually separate blocks. Two, three or more blank lines just stretch the code unnecessarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your argument sounds like it could be used to say we only need one type of header in documents. Different things need different levels of separation. I'll implement this because I'm giving up trying to make nice code on this project but I wish I could have made things better here.


class dstringt
{
public:
Expand Down Expand Up @@ -123,6 +126,8 @@ class dstringt
return out << as_string();
}

void serialize(serializert &serializer);

// non-standard

unsigned get_no() const
Expand Down
28 changes: 28 additions & 0 deletions src/util/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,31 @@ std::string fileutl_get_relative_path(
std::string const result = fileutl_join_path_parts(split1);
return result;
}

/*******************************************************************\

Function: make_valid_filename

Inputs:
file_name: The file name to sanitize.

Outputs:

Purpose:
Replaces invalid characters in a file name using a hard-coded list of
replacements.
This is not designed to operate on path names and will replace folder
seperator characters.

\*******************************************************************/
std::string make_valid_filename(std::string file_name)
{
std::replace(file_name.begin(), file_name.end(), '#', '_');
std::replace(file_name.begin(), file_name.end(), '$', '_');
std::replace(file_name.begin(), file_name.end(), ':', '.');
std::replace(file_name.begin(), file_name.end(), '/', '.');
std::replace(file_name.begin(), file_name.end(), '\\', '.');
std::replace(file_name.begin(), file_name.end(), '<', '[');
std::replace(file_name.begin(), file_name.end(), '>', ']');
return file_name;
}
2 changes: 2 additions & 0 deletions src/util/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ std::string fileutl_get_relative_path(
std::string const &pathname,
std::string const &directory);

std::string make_valid_filename(std::string filename);

#endif // CPROVER_UTIL_FILE_UTIL_H
22 changes: 22 additions & 0 deletions src/util/irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
#include "string2int.h"
#include "irep.h"
#include "string_hash.h"
#include "serializer.h"
#include "irep_hash.h"

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

return result;
}

/*******************************************************************\

Function: irept::serialize

Inputs:
serializer: The serializer to read from/write to

Outputs:

Purpose:
Serializes this instance to/from the given serializer.

\*******************************************************************/
void irept::serialize(serializert &serializer)
{
serializer.serialize("id", write().data);
serializer.serialize("subs", get_sub());
serializer.serialize("named_subs", get_named_sub());
serializer.serialize("comments", get_comments());
}
5 changes: 5 additions & 0 deletions src/util/irep.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ typedef std::string irep_namet;
typedef string_hash irep_id_hash;
#endif

class serializert;


inline const std::string &id2string(const irep_idt &d)
{
#ifdef USE_DSTRING
Expand Down Expand Up @@ -257,6 +260,8 @@ class irept

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

void serialize(serializert &serializer);

protected:
static bool is_comment(const irep_namet &name)
{ return !name.empty() && name[0]=='#'; }
Expand Down
Loading