From 092a639c36b8c64ba5401ffa6c4f1cd4065a0135 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 2 Jun 2018 12:27:16 +0800 Subject: AST - Annotate all patterns with spans --- src/ast/pattern.hpp | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src/ast/pattern.hpp') diff --git a/src/ast/pattern.hpp b/src/ast/pattern.hpp index 583ce351..a5e97c40 100644 --- a/src/ast/pattern.hpp +++ b/src/ast/pattern.hpp @@ -106,40 +106,45 @@ public: Pattern(Pattern&&) = default; Pattern& operator=(Pattern&&) = default; - Pattern(Data dat): - m_binding(), + Pattern(Span sp, Data dat): + m_span( mv$(sp) ), m_data( mv$(dat) ) {}; struct TagMaybeBind {}; - Pattern(TagMaybeBind, Ident name): - m_binding(), + Pattern(TagMaybeBind, Span sp, Ident name): + m_span( mv$(sp) ), m_data( Data::make_MaybeBind({ mv$(name) }) ) {} struct TagMacro {}; - Pattern(TagMacro, unique_ptr<::AST::MacroInvocation> inv): + Pattern(TagMacro, Span sp, unique_ptr<::AST::MacroInvocation> inv): + m_span( mv$(sp) ), m_data( Data::make_Macro({ mv$(inv) }) ) {} struct TagBind {}; - Pattern(TagBind, Ident name, PatternBinding::Type ty = PatternBinding::Type::MOVE, bool is_mut=false): + Pattern(TagBind, Span sp, Ident name, PatternBinding::Type ty = PatternBinding::Type::MOVE, bool is_mut=false): + m_span( mv$(sp) ), m_binding( PatternBinding(mv$(name), ty, is_mut) ) {} struct TagBox {}; - Pattern(TagBox, Pattern sub): + Pattern(TagBox, Span sp, Pattern sub): + m_span( mv$(sp) ), m_data( Data::make_Box({ unique_ptr(new Pattern(mv$(sub))) }) ) {} struct TagValue {}; - Pattern(TagValue, Value val, Value end = Value()): + Pattern(TagValue, Span sp, Value val, Value end = Value()): + m_span( mv$(sp) ), m_data( Data::make_Value({ ::std::move(val), ::std::move(end) }) ) {} struct TagReference {}; - Pattern(TagReference, bool is_mutable, Pattern sub_pattern): + Pattern(TagReference, Span sp, bool is_mutable, Pattern sub_pattern): + m_span( mv$(sp) ), m_data( Data::make_Ref( /*Data::Data_Ref */ { is_mutable, unique_ptr(new Pattern(::std::move(sub_pattern))) }) ) @@ -147,23 +152,28 @@ public: } struct TagTuple {}; - Pattern(TagTuple, ::std::vector pats): + Pattern(TagTuple, Span sp, ::std::vector pats): + m_span( mv$(sp) ), m_data( Data::make_Tuple( TuplePat { mv$(pats), false, {} } ) ) {} - Pattern(TagTuple, TuplePat pat): + Pattern(TagTuple, Span sp, TuplePat pat): + m_span( mv$(sp) ), m_data( Data::make_Tuple( mv$(pat) ) ) {} struct TagNamedTuple {}; - Pattern(TagNamedTuple, Path path, ::std::vector pats): + Pattern(TagNamedTuple, Span sp, Path path, ::std::vector pats): + m_span( mv$(sp) ), m_data( Data::make_StructTuple( { mv$(path), TuplePat { mv$(pats), false, {} } } ) ) {} - Pattern(TagNamedTuple, Path path, TuplePat pat = TuplePat { {}, false, {} }): + Pattern(TagNamedTuple, Span sp, Path path, TuplePat pat = TuplePat { {}, false, {} }): + m_span( mv$(sp) ), m_data( Data::make_StructTuple( { ::std::move(path), ::std::move(pat) } ) ) {} struct TagStruct {}; - Pattern(TagStruct, Path path, ::std::vector< ::std::pair< ::std::string,Pattern> > sub_patterns, bool is_exhaustive): + Pattern(TagStruct, Span sp, Path path, ::std::vector< ::std::pair< ::std::string,Pattern> > sub_patterns, bool is_exhaustive): + m_span( mv$(sp) ), m_data( Data::make_Struct( { ::std::move(path), ::std::move(sub_patterns), is_exhaustive } ) ) {} @@ -174,7 +184,6 @@ public: const Span& span() const { return m_span; } - void set_span(Span sp) { m_span = mv$(sp); } Pattern clone() const; -- cgit v1.2.3 From 44ea3bbb2313f718b220ec24b525bd28248a3d94 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 2 Jun 2018 17:43:28 +0800 Subject: AST - Remove old serialisation code (now all done on HIR) --- src/ast/ast.cpp | 1 - src/ast/ast.hpp | 1 - src/ast/expr.hpp | 2 - src/ast/item.hpp | 6 +- src/ast/pattern.cpp | 20 +-- src/ast/pattern.hpp | 10 +- src/ast/types.hpp | 1 - src/hir/deserialise.cpp | 1 - src/hir/serialise.cpp | 1 - src/include/serialise.hpp | 222 ------------------------------ src/include/serialiser_texttree.hpp | 67 --------- src/macro_rules/macro_rules.hpp | 24 +--- src/macro_rules/mod.cpp | 67 --------- src/main.cpp | 1 - src/parse/token.cpp | 72 ---------- src/parse/token.hpp | 7 +- src/serialise.cpp | 264 ------------------------------------ 17 files changed, 9 insertions(+), 758 deletions(-) delete mode 100644 src/include/serialise.hpp delete mode 100644 src/include/serialiser_texttree.hpp delete mode 100644 src/serialise.cpp (limited to 'src/ast/pattern.hpp') 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 #include "../parse/parseerror.hpp" #include -#include 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 #include #include 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 from_deserialiser(Deserialiser& d); }; typedef ::std::unique_ptr 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 -#include +#include 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 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 from_deserialiser(Deserialiser& s) { - ::std::unique_ptr 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 #include 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 #include #include #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 #include #include #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 -#include -#include -#include -#include - -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 - 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 - Serialiser& operator<<(const ::std::vector& v) - { - start_array(v.size()); - for(const auto& ent : v) - *this << ent; - end_array(); - return *this; - } - template - Serialiser& operator<<(const ::std::shared_ptr& v) - { - *this << v.get(); - if(v.get()) - *this << *v; - return *this; - } - template - Serialiser& operator<<(const ::std::unique_ptr& v) - { - *this << v.get(); - if(v.get()) - *this << *v; - return *this; - } - template - Serialiser& operator<<(const ::std::pair& v) - { - start_array(2); - *this << v.first; - *this << v.second; - end_array(); - return *this; - } - template - Serialiser& operator<<(const ::std::map& 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(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 - void item(::std::vector& 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 - void item(::std::shared_ptr& v) - { - bool present; - - item(present); - - if(present) { - v.reset(new T); - item(*v); - } - else { - v.reset(); - } - } - template - void item(::std::unique_ptr& v) - { - bool present; - - item(present); - - if(present) { - v.reset( T::from_deserialiser(*this).release() ); - } - else { - v.reset(); - } - } - template - void item(::std::pair& v) - { - if(2 != start_array()) - throw ::std::runtime_error("Invalid array size for pair"); - item(v.first); - item(v.second); - end_array(); - } - template - void item(::std::map& v) - { - size_t count = start_array(); - while(count--) { - ::std::pair 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 -#include -#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 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 #include #include #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 #include -#include #include "../coretypes.hpp" #include +#include 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 -#include -#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 - '"<> len; - if( !m_is.good() ) - throw DeserialiseFailure("start_array", "length missing"); - DEBUG("len = "<> 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 = '"<