From 1c50e757b45f64ead016d6cd2bf27585ba5dce04 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 20 May 2018 15:02:17 +0800 Subject: AST - Rename MetaItem and MetaItems to Attribute and AttributeList --- src/parse/token.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/parse/token.cpp') diff --git a/src/parse/token.cpp b/src/parse/token.cpp index 768a96bc..6f3bafd9 100644 --- a/src/parse/token.cpp +++ b/src/parse/token.cpp @@ -33,7 +33,7 @@ Token::~Token() delete reinterpret_cast(m_data.as_Fragment()); break; case TOK_INTERPOLATED_META: - delete reinterpret_cast(m_data.as_Fragment()); + delete reinterpret_cast(m_data.as_Fragment()); break; default: break; @@ -92,7 +92,7 @@ Token::Token(const InterpolatedFragment& frag) break; case InterpolatedFragment::META: m_type = TOK_INTERPOLATED_META; - m_data = new AST::MetaItem( reinterpret_cast(frag.m_ptr)->clone() ); + m_data = new AST::Attribute( reinterpret_cast(frag.m_ptr)->clone() ); break; case InterpolatedFragment::ITEM: { m_type = TOK_INTERPOLATED_ITEM; @@ -197,11 +197,11 @@ Token Token::clone() const rv.m_data = reinterpret_cast(e)->clone().release(); break; case TOK_INTERPOLATED_META: - rv.m_data = new AST::MetaItem( reinterpret_cast(e)->clone() ); + rv.m_data = new AST::Attribute( reinterpret_cast(e)->clone() ); break; case TOK_INTERPOLATED_ITEM: TODO(m_pos, "clone interpolated item"); - //rv.m_data = new AST::Named( AST::Item( reinterpret_cast(e)->clone() ) ); + //rv.m_data = new AST::Named( AST::Item( reinterpret_cast(e)->clone() ) ); break; default: BUG(m_pos, "Fragment with invalid token type (" << *this << ")"); @@ -553,7 +553,7 @@ SERIALISE_TYPE(Token::, "Token", { os << ":" << *reinterpret_cast(tok.m_data.as_Fragment()); break; case TOK_INTERPOLATED_META: - os << ":" << *reinterpret_cast(tok.m_data.as_Fragment()); + os << ":" << *reinterpret_cast(tok.m_data.as_Fragment()); break; case TOK_INTERPOLATED_ITEM: { const auto& named_item = *reinterpret_cast*>(tok.m_data.as_Fragment()); -- cgit v1.2.3 From 508fe45737e08a6749ddc5f903523dc7b3aaba1a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 20 May 2018 16:16:20 +0800 Subject: Parse - Cleanup TODOs --- src/macro_rules/eval.cpp | 3 ++- src/parse/expr.cpp | 21 +++++++++++---------- src/parse/root.cpp | 31 ++++++++++--------------------- src/parse/token.cpp | 18 +++++++++++++++--- src/parse/tokenstream.cpp | 2 +- 5 files changed, 39 insertions(+), 36 deletions(-) (limited to 'src/parse/token.cpp') diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp index b2f5e409..a393ba46 100644 --- a/src/macro_rules/eval.cpp +++ b/src/macro_rules/eval.cpp @@ -715,12 +715,13 @@ InterpolatedFragment Macro_HandlePatternCap(TokenStream& lex, MacroPatEnt::Type return InterpolatedFragment( Parse_Mod_Item_S(lex, cur_mod.m_file_info, cur_mod.path(), AST::AttributeList{}) ); } break; case MacroPatEnt::PAT_IDENT: - // TODO: Any reserved word is also valid as an ident + // NOTE: Any reserved word is also valid as an ident GET_TOK(tok, lex); if( tok.type() == TOK_IDENT || is_reserved_word(tok.type()) ) ; else CHECK_TOK(tok, TOK_IDENT); + // TODO: TOK_INTERPOLATED_IDENT return InterpolatedFragment( TokenTree(lex.getHygiene(), tok) ); } throw ""; diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 22bf9afc..5194e1d8 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -20,7 +20,7 @@ using AST::ExprNode; using AST::ExprNodeP; -// TODO: Use a ProtoSpan +// TODO: Use a ProtoSpan instead of a point span? static inline ExprNodeP mk_exprnodep(const TokenStream& lex, AST::ExprNode* en){en->set_span(lex.point_span()); return ExprNodeP(en); } #define NEWNODE(type, ...) mk_exprnodep(lex, new type(__VA_ARGS__)) @@ -66,9 +66,10 @@ ExprNodeP Parse_ExprBlockNode(TokenStream& lex, bool is_unsafe/*=false*/) DEBUG("tok = " << tok); // NOTE: Doc comments can appear within a function and apply to the function - ::AST::AttributeList node_attrs; - Parse_ParentAttrs(lex, node_attrs); - (void)node_attrs; // TODO: Use these attributes + if( lex.parse_state().parent_attrs ) + { + Parse_ParentAttrs(lex, *lex.parse_state().parent_attrs); + } if( LOOK_AHEAD(lex) == TOK_BRACE_CLOSE ) break; @@ -162,6 +163,7 @@ ExprNodeP Parse_ExprBlockLine_WithItems(TokenStream& lex, ::std::shared_ptr 0 ) { // TODO: Is this an error? - Attributes on a expression that didn't yeild a node. + // - They should have applied to the item that was parsed? } else { } @@ -740,7 +742,6 @@ ExprNodeP Parse_Expr1_1(TokenStream& lex) return NEWNODE( AST::ExprNode_BinOp, AST::ExprNode_BinOp::RANGE, ::std::move(left), ::std::move(right) ); } -// TODO: Is this left associative? LEFTASSOC(Parse_Expr1_2, Parse_Expr1_5, case TOK_TRIPLE_DOT: rv = NEWNODE( AST::ExprNode_BinOp, AST::ExprNode_BinOp::RANGE_INC, mv$(rv), next(lex) ); @@ -915,8 +916,7 @@ ExprNodeP Parse_ExprFC(TokenStream& lex) GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE); break; case TOK_DOT: - // Field access / method call - // TODO: What about tuple indexing? + // Field access / method call / tuple index switch(GET_TOK(tok, lex)) { case TOK_IDENT: { @@ -1097,7 +1097,7 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) return tok.take_frag_node(); - // TODO: Return/break/continue/... here? + // Return/break/continue/... also parsed here (but recurses back up to actually handle them) case TOK_RWORD_RETURN: case TOK_RWORD_CONTINUE: case TOK_RWORD_BREAK: @@ -1177,7 +1177,6 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) return NEWNODE( AST::ExprNode_NamedValue, ::std::move(path) ); } case TOK_RWORD_MOVE: - // TODO: Annotate closure as move GET_TOK(tok, lex); if(tok.type() == TOK_PIPE) return Parse_ExprVal_Closure(lex, true); @@ -1271,7 +1270,9 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) } ExprNodeP Parse_ExprMacro(TokenStream& lex, AST::Path path) { - ASSERT_BUG(lex.point_span(), path.is_trivial(), "TODO: Support path macros - " << path); + if( !path.is_trivial() ) { + TODO(lex.point_span(), "Support path macros - " << path); + } Token tok; ::std::string name = path.m_class.is_Local() ? path.m_class.as_Local().name : path.nodes()[0].name(); diff --git a/src/parse/root.cpp b/src/parse/root.cpp index a57d6844..35da3a76 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -346,9 +346,9 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, bool allow_ if( tok.type() == TOK_AMP ) { // By-reference method? - // TODO: If a lifetime is seen (and not a prototype), it is definitely a self binding unsigned int ofs = 0; + // Handle a lifetime parameter name if( lex.lookahead(0) == TOK_LIFETIME ) ofs ++; @@ -362,22 +362,16 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, bool allow_ } auto ty_sp = lex.end_span(ps); + bool is_mut = false; if( tok.type() == TOK_RWORD_MUT ) { - GET_CHECK_TOK(tok, lex, TOK_RWORD_SELF); - args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), ty_sp, true, TypeRef(ty_sp, "Self", 0xFFFF))) ); - } - else - { - args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), ty_sp, false, TypeRef(ty_sp, "Self", 0xFFFF))) ); + is_mut = true; + GET_TOK(tok, lex); } - DEBUG("TODO: UFCS / self lifetimes"); + CHECK_TOK(tok, TOK_RWORD_SELF); + args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), ty_sp, is_mut, TypeRef(ty_sp, "Self", 0xFFFF))) ); if( allow_self == false ) throw ParseError::Generic(lex, "Self binding not expected"); - //args.push_back( ::std::make_pair( - // AST::Pattern(), - // TypeRef(TypeRef::TagReference(), lifetime, (fcn_class == AST::Function::CLASS_MUTMETHOD), ) - //) ); // Prime tok for next step GET_TOK(tok, lex); @@ -486,7 +480,7 @@ AST::Function Parse_FunctionDefWithCode(TokenStream& lex, ::std::string abi, boo Token tok; auto ret = Parse_FunctionDef(lex, abi, allow_self, false, is_unsafe, is_const); GET_CHECK_TOK(tok, lex, TOK_BRACE_OPEN); - // Enter a new hygine scope (TODO: Should this be in Parse_ExprBlock?) + // Enter a new hygine scope for the function (TODO: Should this be in Parse_ExprBlock?) lex.push_hygine(); PUTBACK(tok, lex); ret.set_code( Parse_ExprBlock(lex) ); @@ -645,7 +639,6 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items } while( GET_TOK(tok, lex) == TOK_PLUS ); } - // TODO: Support "for Sized?" if(tok.type() == TOK_RWORD_WHERE) { //if( params.ty_params().size() == 0 ) @@ -747,7 +740,6 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items break; } // Functions (possibly unsafe) - // TODO: Const? case TOK_RWORD_UNSAFE: fn_is_unsafe = true; if( GET_TOK(tok, lex) == TOK_RWORD_EXTERN ) @@ -770,8 +762,7 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items if( GET_TOK(tok, lex) == TOK_BRACE_OPEN ) { PUTBACK(tok, lex); - // Enter a new hygine scope for the function body. - // - TODO: Should this just happen in Parse_ExprBlock? + // Enter a new hygine scope for the function body. (TODO: Should this be in Parse_ExprBlock?) lex.push_hygine(); fcn.set_code( Parse_ExprBlock(lex) ); lex.pop_hygine(); @@ -784,7 +775,6 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items { throw ParseError::Unexpected(lex, tok); } - // TODO: Store `item_attrs` trait.add_function( ::std::move(name), mv$(item_attrs), ::std::move(fcn) ); break; } default: @@ -842,7 +832,7 @@ AST::Enum Parse_EnumDef(TokenStream& lex, const AST::AttributeList& meta_items) } auto field_attrs = Parse_ItemAttrs(lex); - (void)field_attrs; // TODO^ + (void)field_attrs; // TODO: Store field_attrs types.push_back( Parse_Type(lex) ); } while( GET_TOK(tok, lex) == TOK_COMMA ); @@ -1176,8 +1166,7 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); auto i = ::AST::Static(AST::Static::CONST, mv$(ty), mv$(val)); - // TODO: Attributes on associated constants - impl.add_static( is_public, is_specialisable, mv$(name), mv$(i) /*, mv$(item_attrs)*/ ); + impl.add_static( is_public, is_specialisable, mv$(name), mv$(i) ); break ; } else if( tok.type() == TOK_RWORD_UNSAFE ) diff --git a/src/parse/token.cpp b/src/parse/token.cpp index 6f3bafd9..eb5830a2 100644 --- a/src/parse/token.cpp +++ b/src/parse/token.cpp @@ -297,7 +297,7 @@ struct EscapedString { reinterpret_cast(m_data.as_Fragment())->print_pretty(ss, true); return ss.str(); case TOK_INTERPOLATED_PATTERN: - // TODO: Use a configurable print + // TODO: Use a pretty printer too? return FMT( *reinterpret_cast(m_data.as_Fragment()) ); case TOK_INTERPOLATED_STMT: case TOK_INTERPOLATED_BLOCK: @@ -312,9 +312,21 @@ struct EscapedString { // Value tokens case TOK_IDENT: return m_data.as_String(); case TOK_LIFETIME: return "'" + m_data.as_String(); - case TOK_INTEGER: return FMT(m_data.as_Integer().m_intval); // TODO: suffix for type + case TOK_INTEGER: + if( m_data.as_Integer().m_datatype == CORETYPE_ANY ) { + return FMT(m_data.as_Integer().m_intval); + } + else { + return FMT(m_data.as_Integer().m_intval << "_" << m_data.as_Integer().m_datatype); + } case TOK_CHAR: return FMT("'\\u{"<< ::std::hex << m_data.as_Integer().m_intval << "}"); - case TOK_FLOAT: return FMT(m_data.as_Float().m_floatval); + case TOK_FLOAT: + if( m_data.as_Float().m_datatype == CORETYPE_ANY ) { + return FMT(m_data.as_Float().m_floatval); + } + else { + return FMT(m_data.as_Float().m_floatval << "_" << m_data.as_Float().m_datatype); + } case TOK_STRING: return FMT("\"" << EscapedString(m_data.as_String()) << "\""); case TOK_BYTESTRING:return FMT("b\"" << m_data.as_String() << "\""); case TOK_HASH: return "#"; diff --git a/src/parse/tokenstream.cpp b/src/parse/tokenstream.cpp index 901312a3..625f12db 100644 --- a/src/parse/tokenstream.cpp +++ b/src/parse/tokenstream.cpp @@ -141,7 +141,7 @@ Ident TokenStream::get_ident(Token tok) const return Ident(getHygiene(), tok.str()); } else if( tok.type() == TOK_INTERPOLATED_IDENT ) { - TODO(getPosition(), ""); + TODO(getPosition(), "get_ident from TOK_INTERPOLATED_IDENT"); } else { throw ParseError::Unexpected(*this, tok); -- 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/parse/token.cpp') 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 = '"<