summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ast/ast.cpp1
-rw-r--r--src/ast/ast.hpp1
-rw-r--r--src/ast/expr.hpp2
-rw-r--r--src/ast/item.hpp6
-rw-r--r--src/ast/pattern.cpp20
-rw-r--r--src/ast/pattern.hpp10
-rw-r--r--src/ast/types.hpp1
-rw-r--r--src/hir/deserialise.cpp1
-rw-r--r--src/hir/serialise.cpp1
-rw-r--r--src/include/serialise.hpp222
-rw-r--r--src/include/serialiser_texttree.hpp67
-rw-r--r--src/macro_rules/macro_rules.hpp24
-rw-r--r--src/macro_rules/mod.cpp67
-rw-r--r--src/main.cpp1
-rw-r--r--src/parse/token.cpp72
-rw-r--r--src/parse/token.hpp7
-rw-r--r--src/serialise.cpp264
17 files changed, 9 insertions, 758 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp
index 1a19a10f..4fdf8f9d 100644
--- a/src/ast/ast.cpp
+++ b/src/ast/ast.cpp
@@ -8,7 +8,6 @@
#include <iostream>
#include "../parse/parseerror.hpp"
#include <algorithm>
-#include <serialiser_texttree.hpp>
namespace AST {
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index 5d0201d0..241b51d7 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -19,7 +19,6 @@
#include "../parse/tokentree.hpp"
#include "types.hpp"
-#include <serialise.hpp>
#include <ast/pattern.hpp>
#include <ast/attrs.hpp>
diff --git a/src/ast/expr.hpp b/src/ast/expr.hpp
index 7572b92f..f3981db5 100644
--- a/src/ast/expr.hpp
+++ b/src/ast/expr.hpp
@@ -41,8 +41,6 @@ public:
m_attrs = mv$(mi);
}
AttributeList& attrs() { return m_attrs; }
-
- static ::std::unique_ptr<ExprNode> from_deserialiser(Deserialiser& d);
};
typedef ::std::unique_ptr<ExprNode> ExprNodeP;
diff --git a/src/ast/item.hpp b/src/ast/item.hpp
index cc88f3e2..2137090d 100644
--- a/src/ast/item.hpp
+++ b/src/ast/item.hpp
@@ -2,7 +2,7 @@
#pragma once
#include <string>
-#include <serialise.hpp>
+#include <vector>
namespace AST {
@@ -25,10 +25,6 @@ struct NamedNS
is_pub( is_pub )
{
}
-
- //friend ::std::ostream& operator<<(::std::ostream& os, const Named& i) {
- // return os << (i.is_pub ? "pub " : " ") << i.name << ": " << i.data;
- //}
};
template <typename T>
diff --git a/src/ast/pattern.cpp b/src/ast/pattern.cpp
index 2a5ce0e5..72087d95 100644
--- a/src/ast/pattern.cpp
+++ b/src/ast/pattern.cpp
@@ -155,19 +155,6 @@ namespace AST {
)
return os;
}
-void operator%(Serialiser& s, Pattern::Value::Tag c) {
-}
-void operator%(::Deserialiser& s, Pattern::Value::Tag& c) {
-}
-void operator%(::Serialiser& s, const Pattern::Value& v) {
-}
-void operator%(::Deserialiser& s, Pattern::Value& v) {
-}
-
-void operator%(Serialiser& s, Pattern::Data::Tag c) {
-}
-void operator%(::Deserialiser& s, Pattern::Data::Tag& c) {
-}
Pattern::~Pattern()
{
@@ -252,10 +239,5 @@ AST::Pattern AST::Pattern::clone() const
return rv;
}
-#define _D(VAR, ...) case Pattern::Data::TAG_##VAR: { m_data = Pattern::Data::make_##VAR({}); auto& ent = m_data.as_##VAR(); (void)&ent; __VA_ARGS__ } break;
-SERIALISE_TYPE(Pattern::, "Pattern", {
-},{
-});
-
-}
+} // namespace AST
diff --git a/src/ast/pattern.hpp b/src/ast/pattern.hpp
index a5e97c40..40cfa927 100644
--- a/src/ast/pattern.hpp
+++ b/src/ast/pattern.hpp
@@ -55,8 +55,7 @@ public:
bool is_valid() const { return m_name.name != ""; }
};
-class Pattern:
- public Serialisable
+class Pattern
{
public:
TAGGED_UNION(Value, Invalid,
@@ -196,13 +195,6 @@ public:
const Path& path() const { return m_data.as_StructTuple().path; }
friend ::std::ostream& operator<<(::std::ostream& os, const Pattern& pat);
-
- SERIALISABLE_PROTOTYPES();
- static ::std::unique_ptr<Pattern> from_deserialiser(Deserialiser& s) {
- ::std::unique_ptr<Pattern> ret(new Pattern);
- s.item(*ret);
- return ret;
- }
};
extern ::std::ostream& operator<<(::std::ostream& os, const Pattern::Value& val);
diff --git a/src/ast/types.hpp b/src/ast/types.hpp
index 22465593..b6d9d6f5 100644
--- a/src/ast/types.hpp
+++ b/src/ast/types.hpp
@@ -7,7 +7,6 @@
#include "coretypes.hpp"
#include "ast/path.hpp"
#include "ast/macro.hpp"
-#include <serialise.hpp>
#include <tagged_union.hpp>
namespace AST {
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp
index 2b9b3512..17a93730 100644
--- a/src/hir/deserialise.cpp
+++ b/src/hir/deserialise.cpp
@@ -8,7 +8,6 @@
//#define DISABLE_DEBUG // Disable debug for this function - too hot
#include "hir.hpp"
#include "main_bindings.hpp"
-#include <serialiser_texttree.hpp>
#include <mir/mir.hpp>
#include <macro_rules/macro_rules.hpp>
#include "serialise_lowlevel.hpp"
diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp
index 00e7aa28..55cd579f 100644
--- a/src/hir/serialise.cpp
+++ b/src/hir/serialise.cpp
@@ -7,7 +7,6 @@
*/
#include "hir.hpp"
#include "main_bindings.hpp"
-#include <serialiser_texttree.hpp>
#include <macro_rules/macro_rules.hpp>
#include <mir/mir.hpp>
#include "serialise_lowlevel.hpp"
diff --git a/src/include/serialise.hpp b/src/include/serialise.hpp
deleted file mode 100644
index 0d6d781a..00000000
--- a/src/include/serialise.hpp
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- */
-#ifndef _SERIALSE_HPP_INCLUDED_
-#define _SERIALSE_HPP_INCLUDED_
-
-#include <vector>
-#include <string>
-#include <map>
-#include <memory>
-#include <stdexcept>
-
-class Serialiser;
-class Deserialiser;
-
-#define SERIALISABLE_PROTOTYPES()\
- const char* serialise_tag() const override; \
- void serialise(::Serialiser& s) const override; \
- void deserialise(::Deserialiser& s) override
-#define SERIALISE_TYPE(method_prefix, tag_str, body, des_body) \
- const char* method_prefix serialise_tag() const { return tag_str; } \
- void method_prefix serialise(::Serialiser& s) const { body } \
- void method_prefix deserialise(::Deserialiser& s) { des_body }
-#define SERIALISE_TYPE_A(method_prefix, tag_str, body) SERIALISE_TYPE(method_prefix, tag_str, body, body)
-#define SERIALISE_TYPE_S(class_, body) SERIALISE_TYPE(class_::, #class_, body, body)
-#define SERIALISE_TU(class_, tag_str, val_name, ...) SERIALISE_TYPE(class_::, tag_str,\
- {\
- s << class_::tag_to_str(this->tag());\
- TU_MATCH(class_, (*this), (val_name), __VA_ARGS__)\
- },/*
-*/ {\
- ::std::string STU_tag_str;\
- s.item(STU_tag_str);\
- auto tag = class_::tag_from_str(STU_tag_str);\
- switch(tag) { \
- case class_::TAGDEAD: break;\
- SERIALISE_TU_MATCH_ARMS(class_, val_name, __VA_ARGS__)\
- }\
- })
-#define SERIALISE_TU_MATCH_ARM(CLASS, VAL_NAME, TAG, ...) case CLASS::TAG_##TAG: {/*
-*/ *this = CLASS::make_##TAG({});/*
-*/ auto& VAL_NAME = this->as_##TAG(); /*
-*/ __VA_ARGS__/*
-*/} break;
-#define SERIALISE_TU_MATCH_ARMS(CLASS, NAME, ...) TU_EXP1( TU_GMA(__VA_ARGS__)(SERIALISE_TU_MATCH_ARM, (CLASS, NAME), __VA_ARGS__) )
-
-class DeserialiseFailure:
- public ::std::runtime_error
-{
- //const char *m_fcn;
- //const char *m_message;
-public:
- DeserialiseFailure(const char *fcn, const char *message):
- ::std::runtime_error("Deserialise failure")//,
- //m_fcn(fcn),
- //m_message(message)
- {}
-};
-
-class Serialisable
-{
-public:
- virtual const char* serialise_tag() const = 0;
- virtual void serialise(Serialiser& s) const = 0;
- virtual void deserialise(Deserialiser& s) = 0;
-};
-
-class Serialiser
-{
-protected:
- virtual void start_object(const char *tag) = 0;
- virtual void end_object(const char *tag) = 0;
- virtual void start_array(unsigned int size) = 0;
- virtual void end_array() = 0;
-public:
- template<typename T>
- inline void item(T& v) { *this << v; }
-
- virtual Serialiser& operator<<(bool val) = 0;
- virtual Serialiser& operator<<(uint64_t val) = 0;
- virtual Serialiser& operator<<(int64_t val) = 0;
- virtual Serialiser& operator<<(double val) = 0;
- Serialiser& operator<<(unsigned int val) { return *this << (uint64_t)val; };
- virtual Serialiser& operator<<(const char* s) = 0;
- Serialiser& operator<<(const ::std::string& s) {
- return *this << s.c_str();
- }
- Serialiser& operator<<(const Serialisable& subobj);
-
- template<typename T>
- Serialiser& operator<<(const ::std::vector<T>& v)
- {
- start_array(v.size());
- for(const auto& ent : v)
- *this << ent;
- end_array();
- return *this;
- }
- template<typename T>
- Serialiser& operator<<(const ::std::shared_ptr<T>& v)
- {
- *this << v.get();
- if(v.get())
- *this << *v;
- return *this;
- }
- template<typename T>
- Serialiser& operator<<(const ::std::unique_ptr<T>& v)
- {
- *this << v.get();
- if(v.get())
- *this << *v;
- return *this;
- }
- template<typename T1, typename T2>
- Serialiser& operator<<(const ::std::pair<T1,T2>& v)
- {
- start_array(2);
- *this << v.first;
- *this << v.second;
- end_array();
- return *this;
- }
- template<typename T1, typename T2>
- Serialiser& operator<<(const ::std::map<T1,T2>& v)
- {
- start_array(v.size());
- for(const auto& ent : v)
- *this << ent;
- end_array();
- return *this;
- }
-};
-
-class Deserialiser
-{
-protected:
- virtual size_t start_array() = 0;
- virtual void end_array() = 0;
-
- virtual ::std::string read_tag() = 0;
-public:
- virtual void item(bool& b) = 0;
- virtual void item(uint64_t& v) = 0;
- void item(unsigned int& v) { uint64_t v1; this->item(v1); v = static_cast<unsigned int>(v1); }
- virtual void item(int64_t& val) = 0;
- virtual void item(double& v) = 0;
- virtual void item(::std::string& s) = 0;
-
- virtual void start_object(const char *tag) = 0;
- virtual void end_object(const char *tag) = 0;
- ::std::string start_object();
-
- void item(Serialisable& v);
- Deserialiser& operator>>(Serialisable& v) {
- this->item(v);
- return *this;
- }
-
- template<typename T>
- void item(::std::vector<T>& v) {
- size_t size = start_array();
- v.reserve(size);
- for(size_t i = 0; i < size; i ++) {
- T item;
- this->item(item);
- v.emplace_back( ::std::move(item) );
- }
- end_array();
- }
- template<typename T>
- void item(::std::shared_ptr<T>& v)
- {
- bool present;
-
- item(present);
-
- if(present) {
- v.reset(new T);
- item(*v);
- }
- else {
- v.reset();
- }
- }
- template<typename T>
- void item(::std::unique_ptr<T>& v)
- {
- bool present;
-
- item(present);
-
- if(present) {
- v.reset( T::from_deserialiser(*this).release() );
- }
- else {
- v.reset();
- }
- }
- template<typename T1, typename T2>
- void item(::std::pair<T1,T2>& v)
- {
- if(2 != start_array())
- throw ::std::runtime_error("Invalid array size for pair");
- item(v.first);
- item(v.second);
- end_array();
- }
- template<typename T1, typename T2>
- void item(::std::map<T1,T2>& v)
- {
- size_t count = start_array();
- while(count--) {
- ::std::pair<T1,T2> e;
- item(e);
- v.insert( ::std::move(e) );
- }
- end_array();
- }
-};
-
-#endif
-
diff --git a/src/include/serialiser_texttree.hpp b/src/include/serialiser_texttree.hpp
deleted file mode 100644
index 7c86d326..00000000
--- a/src/include/serialiser_texttree.hpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- */
-
-#ifndef _SERIALISER_TEXTTREE_HPP_INCLUDED_
-#define _SERIALISER_TEXTTREE_HPP_INCLUDED_
-
-#include <ostream>
-#include <istream>
-#include "serialise.hpp"
-
-class Serialiser_TextTree:
- public Serialiser
-{
- ::std::ostream& m_os;
- int m_indent_level;
- bool m_array_was_empty;
-public:
- Serialiser_TextTree(::std::ostream& os);
-
- virtual Serialiser& operator<<(bool val) override;
- virtual Serialiser& operator<<(uint64_t val) override;
- virtual Serialiser& operator<<(int64_t val) override;
- virtual Serialiser& operator<<(double val) override;
- virtual Serialiser& operator<<(const char* s) override;
-
-protected:
- virtual void start_object(const char *tag) override;
- virtual void end_object(const char* tag) override;
- virtual void start_array(unsigned int size) override;
- virtual void end_array() override;
-private:
- void indent();
- void unindent();
- void print_indent();
-};
-
-
-class Deserialiser_TextTree:
- public Deserialiser
-{
- ::std::istream& m_is;
-
- static bool is_ws(char c);
- char getc();
- char peekc();
- void eat_ws();
-public:
- Deserialiser_TextTree(::std::istream& is);
-
-protected:
- virtual size_t start_array() override;
- virtual void end_array() override;
- virtual ::std::string read_tag() override;
-
-public:
- virtual void item(bool& b) override;
- virtual void item(uint64_t& v) override;
- virtual void item(int64_t& v) override;
- virtual void item(double& v) override;
- virtual void item(::std::string& s) override;
-
- virtual void start_object(const char *tag) override;
- virtual void end_object(const char *tag) override;
-};
-
-#endif
-
diff --git a/src/macro_rules/macro_rules.hpp b/src/macro_rules/macro_rules.hpp
index 2a588a78..c04e3548 100644
--- a/src/macro_rules/macro_rules.hpp
+++ b/src/macro_rules/macro_rules.hpp
@@ -19,7 +19,7 @@
class MacroExpander;
-TAGGED_UNION_EX(MacroExpansionEnt, (: public Serialisable), Token, (
+TAGGED_UNION(MacroExpansionEnt, Token,
// TODO: have a "raw" stream instead of just tokens
(Token, Token),
// TODO: Have a flag on `NamedValue` that indicates that it is the only/last usage of this particular value (at this level)
@@ -34,19 +34,11 @@ TAGGED_UNION_EX(MacroExpansionEnt, (: public Serialisable), Token, (
/// Boolean is true if the variable will be unconditionally expanded
::std::map< unsigned int, bool> variables;
})
- ),
- (),
- (),
- (
- public:
- SERIALISABLE_PROTOTYPES();
- )
);
extern ::std::ostream& operator<<(::std::ostream& os, const MacroExpansionEnt& x);
/// Matching pattern entry
-struct MacroPatEnt:
- public Serialisable
+struct MacroPatEnt
{
::std::string name;
unsigned int name_index = 0;
@@ -99,13 +91,10 @@ struct MacroPatEnt:
friend ::std::ostream& operator<<(::std::ostream& os, const MacroPatEnt& x);
friend ::std::ostream& operator<<(::std::ostream& os, const MacroPatEnt::Type& x);
-
- SERIALISABLE_PROTOTYPES();
};
/// An expansion arm within a macro_rules! blcok
-struct MacroRulesArm:
- public Serialisable
+struct MacroRulesArm
{
/// Names for the parameters
::std::vector< ::std::string> m_param_names;
@@ -126,13 +115,10 @@ struct MacroRulesArm:
MacroRulesArm& operator=(const MacroRulesArm&) = delete;
MacroRulesArm(MacroRulesArm&&) = default;
MacroRulesArm& operator=(MacroRulesArm&&) = default;
-
- SERIALISABLE_PROTOTYPES();
};
/// A sigle 'macro_rules!' block
-class MacroRules:
- public Serialisable
+class MacroRules
{
public:
/// Marks if this macro should be exported from the defining crate
@@ -152,8 +138,6 @@ public:
}
virtual ~MacroRules();
MacroRules(MacroRules&&) = default;
-
- SERIALISABLE_PROTOTYPES();
};
extern ::std::unique_ptr<TokenStream> Macro_InvokeRules(const char *name, const MacroRules& rules, const Span& sp, TokenTree input, AST::Module& mod);
diff --git a/src/macro_rules/mod.cpp b/src/macro_rules/mod.cpp
index 0f16a377..2613a0b4 100644
--- a/src/macro_rules/mod.cpp
+++ b/src/macro_rules/mod.cpp
@@ -161,55 +161,6 @@ MacroRulesPtr::~MacroRulesPtr()
}
}
-SERIALISE_TYPE_S(MacroRulesArm, {
-})
-
-void operator%(Serialiser& s, MacroPatEnt::Type c) {
- switch(c) {
- #define _(v) case MacroPatEnt::v: s << #v; return
- _(PAT_TOKEN);
- _(PAT_TT);
- _(PAT_PAT);
- _(PAT_TYPE);
- _(PAT_EXPR);
- _(PAT_LOOP);
- _(PAT_STMT);
- _(PAT_PATH);
- _(PAT_BLOCK);
- _(PAT_META);
- _(PAT_ITEM);
- _(PAT_IDENT);
- #undef _
- }
-}
-void operator%(::Deserialiser& s, MacroPatEnt::Type& c) {
- ::std::string n;
- s.item(n);
- #define _(v) else if(n == #v) c = MacroPatEnt::v
- if(0) ;
- _(PAT_TOKEN);
- _(PAT_TT);
- _(PAT_PAT);
- _(PAT_TYPE);
- _(PAT_EXPR);
- _(PAT_LOOP);
- //_(PAT_OPTLOOP);
- _(PAT_STMT);
- _(PAT_PATH);
- _(PAT_BLOCK);
- _(PAT_META);
- _(PAT_IDENT);
- _(PAT_ITEM);
- else
- throw ::std::runtime_error( FMT("No conversion for '" << n << "'") );
- #undef _
-}
-SERIALISE_TYPE_S(MacroPatEnt, {
- s % type;
- s.item(name);
- s.item(tok);
- s.item(subpats);
-});
::std::ostream& operator<<(::std::ostream& os, const MacroPatEnt& x)
{
switch(x.type)
@@ -257,20 +208,6 @@ SERIALISE_TYPE_S(MacroPatEnt, {
return os;
}
-SERIALISE_TU(MacroExpansionEnt, "MacroExpansionEnt", e,
-(Token,
- s.item(e);
- ),
-(NamedValue,
- s.item(e);
- ),
-(Loop,
- s.item(e.entries);
- s.item(e.joiner);
- //s.item(e.variables);
- )
-);
-
::std::ostream& operator<<(::std::ostream& os, const MacroExpansionEnt& x)
{
TU_MATCH( MacroExpansionEnt, (x), (e),
@@ -295,8 +232,4 @@ SERIALISE_TU(MacroExpansionEnt, "MacroExpansionEnt", e,
MacroRules::~MacroRules()
{
}
-SERIALISE_TYPE_S(MacroRules, {
- s.item( m_exported );
- s.item( m_rules );
-});
diff --git a/src/main.cpp b/src/main.cpp
index 3ce041c4..ca55d6ba 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,7 +14,6 @@
#include "parse/parseerror.hpp"
#include "ast/ast.hpp"
#include "ast/crate.hpp"
-#include <serialiser_texttree.hpp>
#include <cstring>
#include <main_bindings.hpp>
#include "resolve/main_bindings.hpp"
diff --git a/src/parse/token.cpp b/src/parse/token.cpp
index eb5830a2..115df135 100644
--- a/src/parse/token.cpp
+++ b/src/parse/token.cpp
@@ -457,78 +457,6 @@ struct EscapedString {
throw ParseError::BugCheck("Reached end of Token::to_str");
}
-void operator%(::Serialiser& s, enum eTokenType c) {
- s << Token::typestr(c);
-}
-void operator%(::Deserialiser& s, enum eTokenType& c) {
- ::std::string n;
- s.item(n);
- c = Token::typefromstr(n);
-}
-void operator%(::Serialiser& s, enum eCoreType t) {
- s << coretype_name(t);
-}
-void operator%(::Deserialiser& s, enum eCoreType& t) {
- ::std::string n;
- s.item(n);
- t = coretype_fromstring(n);
- ASSERT_BUG(Span(), t != CORETYPE_INVAL, "Invalid coretype '" << n << "'");
-}
-SERIALISE_TYPE(Token::, "Token", {
- s % m_type;
- s << Token::Data::tag_to_str(m_data.tag());
- TU_MATCH(Token::Data, (m_data), (e),
- (None, ),
- (String,
- s << e;
- ),
- (Integer,
- s % e.m_datatype;
- s.item( e.m_intval );
- ),
- (Float,
- s % e.m_datatype;
- s.item( e.m_floatval );
- ),
- (Fragment,
- assert(!"Serialising interpolated macro fragment");
- )
- )
-},{
- s % m_type;
- Token::Data::Tag tag;
- {
- ::std::string tag_str;
- s.item( tag_str );
- tag = Token::Data::tag_from_str(tag_str);
- }
- switch(tag)
- {
- case Token::Data::TAGDEAD: break;
- case Token::Data::TAG_None: break;
- case Token::Data::TAG_String: {
- ::std::string str;
- s.item( str );
- m_data = Token::Data::make_String(str);
- break; }
- case Token::Data::TAG_Integer: {
- enum eCoreType dt;
- uint64_t v;
- s % dt;
- s.item( v );
- m_data = Token::Data::make_Integer({dt, v});
- break; }
- case Token::Data::TAG_Float: {
- enum eCoreType dt;
- double v;
- s % dt;
- s.item( v );
- m_data = Token::Data::make_Float({dt, v});
- break; }
- case Token::Data::TAG_Fragment:
- assert(!"Serialising interpolated macro fragment");
- }
-});
::std::ostream& operator<<(::std::ostream& os, const Token& tok)
{
diff --git a/src/parse/token.hpp b/src/parse/token.hpp
index 2da64bca..3605679b 100644
--- a/src/parse/token.hpp
+++ b/src/parse/token.hpp
@@ -9,9 +9,9 @@
#include <rc_string.hpp>
#include <tagged_union.hpp>
-#include <serialise.hpp>
#include "../coretypes.hpp"
#include <ident.hpp>
+#include <memory>
enum eTokenType
{
@@ -56,8 +56,7 @@ namespace AST {
class InterpolatedFragment;
-class Token:
- public Serialisable
+class Token
{
friend class HirSerialiser;
friend class HirDeserialiser;
@@ -150,8 +149,6 @@ public:
static const char* typestr(enum eTokenType type);
static eTokenType typefromstr(const ::std::string& s);
- SERIALISABLE_PROTOTYPES();
-
friend ::std::ostream& operator<<(::std::ostream& os, const Token& tok);
};
extern ::std::ostream& operator<<(::std::ostream& os, const Token& tok);
diff --git a/src/serialise.cpp b/src/serialise.cpp
deleted file mode 100644
index e79d4025..00000000
--- a/src/serialise.cpp
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- */
-#define DISABLE_DEBUG
-#include <serialise.hpp>
-#include <serialiser_texttree.hpp>
-#include "common.hpp"
-
-Serialiser& Serialiser::operator<<(const Serialisable& subobj)
-{
- start_object(subobj.serialise_tag());
- subobj.serialise(*this);
- end_object(subobj.serialise_tag());
- return *this;
-}
-
-void Deserialiser::item(Serialisable& s)
-{
- DEBUG("Deserialise - '"<<s.serialise_tag()<<"'");
- start_object(s.serialise_tag());
- s.deserialise(*this);
- end_object(s.serialise_tag());
-}
-::std::string Deserialiser::start_object()
-{
- ::std::string s = read_tag();
- DEBUG("tag = '" << s << "'");
- start_object(nullptr);
- return s;
-}
-
-
-// --------------------------------------------------------------------
-Serialiser_TextTree::Serialiser_TextTree(::std::ostream& os):
- m_os(os),
- m_indent_level(0),
- m_array_was_empty(false)
-{
-}
-
-void Serialiser_TextTree::start_object(const char *tag) {
- print_indent();
- m_os << tag << " {\n";
- indent();
-}
-void Serialiser_TextTree::end_object(const char * /*tag*/) {
- unindent();
- print_indent();
- m_os << "}\n";
-}
-void Serialiser_TextTree::start_array(unsigned int size) {
- print_indent();
- if( size == 0 ) {
- m_os << "[]\n";
- m_array_was_empty = true;
- }
- else {
- m_os << "[" << size << "\n";
- indent();
- }
-}
-void Serialiser_TextTree::end_array() {
- if( m_array_was_empty ) {
- m_array_was_empty = false;
- }
- else {
- unindent();
- print_indent();
- m_os << "]\n";
- }
-}
-Serialiser& Serialiser_TextTree::operator<<(bool val)
-{
- print_indent();
- m_os << (val ? "T" : "F") << "\n";
- return *this;
-}
-Serialiser& Serialiser_TextTree::operator<<(uint64_t val)
-{
- print_indent();
- m_os << val << "\n";
- return *this;
-}
-Serialiser& Serialiser_TextTree::operator<<(int64_t val)
-{
- print_indent();
- m_os << val << "\n";
- return *this;
-}
-Serialiser& Serialiser_TextTree::operator<<(double val)
-{
- print_indent();
- m_os << val << "\n";
- return *this;
-}
-
-Serialiser& Serialiser_TextTree::operator<<(const char* s)
-{
- print_indent();
- m_os << "\"" << s << "\"\n";
- return *this;
-}
-void Serialiser_TextTree::indent()
-{
- m_indent_level ++;
-}
-void Serialiser_TextTree::unindent()
-{
- m_indent_level --;
-}
-void Serialiser_TextTree::print_indent()
-{
- for(int i = 0; i < m_indent_level; i ++)
- m_os << " ";
-}
-
-// --------------------------------------------------------------------
-Deserialiser_TextTree::Deserialiser_TextTree(::std::istream& is):
- m_is(is)
-{
-}
-bool Deserialiser_TextTree::is_ws(char c)
-{
- return c == ' ' || c == '\t' || c == '\n' || c == '\r';
-}
-char Deserialiser_TextTree::getc()
-{
- char c;
- m_is.get(c);
- return c;
-}
-char Deserialiser_TextTree::peekc()
-{
- return m_is.peek();
-}
-void Deserialiser_TextTree::eat_ws()
-{
- char c;
- do {
- m_is.get(c);
- } while( is_ws(c) );
- m_is.putback(c);
-}
-size_t Deserialiser_TextTree::start_array()
-{
- eat_ws();
- char c = getc();
- if( c != '[' )
- throw DeserialiseFailure("start_array", "no [");
-
- eat_ws();
- if( peekc() == ']' ) {
- DEBUG("len = 0");
- return 0;
- }
-
- size_t len;
- m_is >> len;
- if( !m_is.good() )
- throw DeserialiseFailure("start_array", "length missing");
- DEBUG("len = "<<len);
- return len;
-}
-void Deserialiser_TextTree::end_array()
-{
- eat_ws();
- char c = getc();
- DEBUG("c = '"<<c<<"'");
- if( c != ']' )
- throw DeserialiseFailure("end_array", "no ]");
-}
-::std::string Deserialiser_TextTree::read_tag()
-{
- ::std::string tag;
- eat_ws();
- char c;
- do {
- m_is.get(c);
- tag.push_back(c);
- } while( !is_ws(c) );
- tag.pop_back();
- if( tag.size() == 0 )
- throw DeserialiseFailure("read_tag", "tag empty");
- return tag;
-}
-
-void Deserialiser_TextTree::item(bool& b)
-{
- eat_ws();
- switch( getc() )
- {
- case 'T': DEBUG("true"); b = true; break;
- case 'F': DEBUG("false"); b = false; break;
- default:
- throw DeserialiseFailure("item(bool)", "bad value");
- }
-}
-void Deserialiser_TextTree::item(uint64_t& v)
-{
- eat_ws();
- m_is >> v;
- if( !m_is.good() )
- throw DeserialiseFailure("item(uint64_t)", "bad value");
-}
-void Deserialiser_TextTree::item(int64_t& v)
-{
- eat_ws();
- m_is >> v;
- if( !m_is.good() )
- throw DeserialiseFailure("item(int64_t)", "bad value");
-}
-void Deserialiser_TextTree::item(double& v)
-{
- eat_ws();
- m_is >> v;
- if( !m_is.good() )
- throw DeserialiseFailure("item(double)", "bad value");
-}
-void Deserialiser_TextTree::item(::std::string& s)
-{
- eat_ws();
-
- ::std::string rv;
- char c = getc();
- DEBUG("c = '"<<c<<"'");
- if( c != '"' )
- throw DeserialiseFailure("item(::std::string)", "no open \"");
-
- while(peekc() != '"')
- {
- char c = getc();
- if( c == '\\' )
- c = getc();
- rv.push_back(c);
- }
- getc(); // eat "
-
- DEBUG("rv = '"<<rv<<"'");
- s = rv;
-}
-
-void Deserialiser_TextTree::start_object(const char *tag)
-{
- eat_ws();
- if( tag != nullptr ) {
- ::std::string s = read_tag();
- DEBUG("s == " << s);
- if( s != tag )
- throw DeserialiseFailure("start_object", "tag mismatch");
- }
- eat_ws();
- char c = getc();
- DEBUG("c = '" << c << "' (tag = " << (tag ? tag : "-NUL-"));
- if( c != '{' )
- throw DeserialiseFailure("start_object", "no {");
-}
-void Deserialiser_TextTree::end_object(const char * /*tag*/)
-{
- eat_ws();
- char c = getc();
- DEBUG("c = '"<<c<<"'");
- if( c != '}' ) {
- throw DeserialiseFailure("end_object", "no }");
- }
-}