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/ast/ast.cpp | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) (limited to 'src/ast/ast.cpp') diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index a4825a89..641bd633 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -14,8 +14,8 @@ namespace AST { namespace { - ::std::vector clone_mivec(const ::std::vector& v) { - ::std::vector ri; + ::std::vector clone_mivec(const ::std::vector& v) { + ::std::vector ri; ri.reserve(v.size()); for(const auto& i : v) ri.push_back( i.clone() ); @@ -23,19 +23,16 @@ namespace { } } -MetaItems::~MetaItems() +AttributeList AttributeList::clone() const { -} -MetaItems MetaItems::clone() const -{ - return MetaItems( m_span, clone_mivec(m_items) ); + return AttributeList( clone_mivec(m_items) ); } -void MetaItems::push_back(MetaItem i) +void AttributeList::push_back(Attribute i) { m_items.push_back( ::std::move(i) ); } -const MetaItem* MetaItems::get(const char *name) const +const Attribute* AttributeList::get(const char *name) const { for( auto& i : m_items ) { if(i.name() == name) { @@ -46,23 +43,20 @@ const MetaItem* MetaItems::get(const char *name) const return 0; } -MetaItem::~MetaItem() +Attribute Attribute::clone() const { -} -MetaItem MetaItem::clone() const -{ - TU_MATCH(MetaItemData, (m_data), (e), + TU_MATCHA( (m_data), (e), (None, - return MetaItem(m_name); + return Attribute(m_span, m_name); ), (String, - return MetaItem(m_name, e.val); + return Attribute(m_span, m_name, e.val); ), (List, - return MetaItem(m_name, clone_mivec(e.sub_items)); + return Attribute(m_span, m_name, clone_mivec(e.sub_items)); ) ) - throw ::std::runtime_error("MetaItem::clone - Fell off end"); + throw ::std::runtime_error("Attribute::clone - Fell off end"); } StructItem StructItem::clone() const @@ -109,16 +103,16 @@ Function Function::clone() const return rv; } -void Trait::add_type(::std::string name, MetaItems attrs, TypeRef type) { +void Trait::add_type(::std::string name, AttributeList attrs, TypeRef type) { m_items.push_back( Named(mv$(name), Item::make_Type({TypeAlias(GenericParams(), mv$(type))}), true) ); m_items.back().data.attrs = mv$(attrs); } -void Trait::add_function(::std::string name, MetaItems attrs, Function fcn) { +void Trait::add_function(::std::string name, AttributeList attrs, Function fcn) { DEBUG("trait fn " << name); m_items.push_back( Named(mv$(name), Item::make_Function({mv$(fcn)}), true) ); m_items.back().data.attrs = mv$(attrs); } -void Trait::add_static(::std::string name, MetaItems attrs, Static v) { +void Trait::add_static(::std::string name, AttributeList attrs, Static v) { m_items.push_back( Named(mv$(name), Item::make_Static({mv$(v)}), true) ); m_items.back().data.attrs = mv$(attrs); } @@ -301,18 +295,18 @@ void Module::add_item( Named named_item ) { DEBUG(m_my_path << "::" << i.name << " = " << i.data.tag_str() << ", attrs = " << i.data.attrs); } } -void Module::add_item(bool is_pub, ::std::string name, Item it, MetaItems attrs) { +void Module::add_item(bool is_pub, ::std::string name, Item it, AttributeList attrs) { it.attrs = mv$(attrs); add_item( Named( mv$(name), mv$(it), is_pub ) ); } -void Module::add_ext_crate(bool is_public, ::std::string ext_name, ::std::string imp_name, MetaItems attrs) { +void Module::add_ext_crate(bool is_public, ::std::string ext_name, ::std::string imp_name, AttributeList attrs) { this->add_item( is_public, imp_name, Item::make_Crate({mv$(ext_name)}), mv$(attrs) ); } -void Module::add_alias(bool is_public, UseStmt us, ::std::string name, MetaItems attrs) { +void Module::add_alias(bool is_public, UseStmt us, ::std::string name, AttributeList attrs) { this->add_item( is_public, mv$(name), Item(mv$(us)), mv$(attrs) ); } void Module::add_macro_invocation(MacroInvocation item) { - this->add_item( false, "", Item( mv$(item) ), ::AST::MetaItems {} ); + this->add_item( false, "", Item( mv$(item) ), ::AST::AttributeList {} ); } void Module::add_macro(bool is_exported, ::std::string name, MacroRulesPtr macro) { m_macros.push_back( Named( mv$(name), mv$(macro), is_exported ) ); -- cgit v1.2.3 From de9ecd7a2d70359b34e77ded57e5aa9284345ac5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 20 May 2018 22:01:59 +0800 Subject: AST - Refactor lifetime/HRB handling --- src/ast/ast.cpp | 30 +++++++++++++----- src/ast/attrs.hpp | 21 +++++++++++-- src/ast/dump.cpp | 8 ++--- src/ast/generics.hpp | 74 ++++++++++++++++++++++++++++++++++----------- src/ast/path.hpp | 5 +-- src/ast/types.cpp | 33 ++++++++++++++++++-- src/ast/types.hpp | 77 +++++++++++++++++++++++++++++++++++++++++++---- src/expand/derive.cpp | 25 +++++++-------- src/expand/mod.cpp | 8 +++-- src/expand/proc_macro.cpp | 48 ++++++++++++++--------------- src/hir/from_ast.cpp | 57 +++++++++++++++++++++++------------ src/parse/common.hpp | 2 +- src/parse/paths.cpp | 4 +-- src/parse/root.cpp | 52 ++++++++++++++++++-------------- src/parse/tokenstream.cpp | 4 +++ src/parse/types.cpp | 77 ++++++++++++++++++++++++++++++----------------- src/resolve/absolute.cpp | 16 +++++----- 17 files changed, 376 insertions(+), 165 deletions(-) (limited to 'src/ast/ast.cpp') diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 641bd633..1a19a10f 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -379,10 +379,31 @@ Item Item::clone() const //os << ")"; return os; } +::std::ostream& operator<<(::std::ostream& os, const LifetimeParam& p) +{ + os << "'" << p.m_name; + return os; +} + +::std::ostream& operator<<(::std::ostream& os, const HigherRankedBounds& x) +{ + if( x.m_lifetimes.empty() ) { + return os; + } + os << "for<"; + for(const auto& l : x.m_lifetimes) + os << "'" << l << ","; + os << "> "; + return os; +} + ::std::ostream& operator<<(::std::ostream& os, const GenericBound& x) { TU_MATCH(GenericBound, (x), (ent), + (None, + os << "/*-*/"; + ), (Lifetime, os << "'" << ent.test << ": '" << ent.bound; ), @@ -390,14 +411,7 @@ Item Item::clone() const os << ent.type << ": '" << ent.bound; ), (IsTrait, - if( ! ent.hrls.empty() ) - { - os << "for<"; - for(const auto& l : ent.hrls) - os << "'" << l; - os << ">"; - } - os << ent.type << ": " << ent.trait; + os << ent.outer_hrbs << ent.type << ": " << ent.inner_hrbs << ent.trait; ), (MaybeTrait, os << ent.type << ": ?" << ent.trait; diff --git a/src/ast/attrs.hpp b/src/ast/attrs.hpp index 4afbdbc1..1926e96a 100644 --- a/src/ast/attrs.hpp +++ b/src/ast/attrs.hpp @@ -30,8 +30,8 @@ public: // Move present AttributeList(AttributeList&&) = default; AttributeList& operator=(AttributeList&&) = default; - // No copy - AttributeList(const AttributeList&) = delete; + // No copy assign, but explicit copy + explicit AttributeList(const AttributeList&) = default; AttributeList& operator=(const AttributeList&) = delete; // Explicit clone AttributeList clone() const; @@ -97,7 +97,22 @@ public: { } - Attribute(const Attribute& ) = delete; + explicit Attribute(const Attribute& x): + m_span(x.m_span), + m_name(x.m_name), + m_is_used(x.m_is_used) + { + TU_MATCHA( (x.m_data), (e), + (None, + ), + (String, + m_data = AttributeData::make_String({ e.val }); + ), + (List, + m_data = AttributeData::make_List({ ::std::vector(e.sub_items) }); + ) + ) + } Attribute& operator=(const Attribute&& ) = delete; Attribute(Attribute&& ) = default; Attribute& operator=(Attribute&& ) = default; diff --git a/src/ast/dump.cpp b/src/ast/dump.cpp index b6336a02..73b332c0 100644 --- a/src/ast/dump.cpp +++ b/src/ast/dump.cpp @@ -829,6 +829,9 @@ void RustPrinter::print_bounds(const AST::GenericParams& params) m_os << indent(); TU_MATCH(AST::GenericBound, (b), (ent), + (None, + m_os << "/*-*/"; + ), (Lifetime, m_os << "'" << ent.test << ": '" << ent.bound; ), @@ -836,10 +839,7 @@ void RustPrinter::print_bounds(const AST::GenericParams& params) m_os << ent.type << ": '" << ent.bound; ), (IsTrait, - if( ent.hrls.size() > 0 ) { - m_os << "for<'" << ::join(", '", ent.hrls) << "> "; - } - m_os << ent.type << ": " << ent.trait; + m_os << ent.outer_hrbs << ent.type << ": " << ent.inner_hrbs << ent.trait; ), (MaybeTrait, m_os << ent.type << ": ?" << ent.trait; diff --git a/src/ast/generics.hpp b/src/ast/generics.hpp index bc14202e..c222044c 100644 --- a/src/ast/generics.hpp +++ b/src/ast/generics.hpp @@ -14,49 +14,86 @@ namespace AST { class TypeParam { + ::AST::AttributeList m_attrs; + Span m_span; + // TODO: use an Ident? ::std::string m_name; ::TypeRef m_default; public: TypeParam(TypeParam&& x) = default; TypeParam& operator=(TypeParam&& x) = default; - TypeParam(const TypeParam& x): - m_name(x.m_name), - m_default(x.m_default.clone()) - {} - //TypeParam(): m_name("") {} - TypeParam(::std::string name): + explicit TypeParam(const TypeParam& x): + m_attrs( x.m_attrs ), + m_span( x.m_span ), + m_name( x.m_name ), + m_default( x.m_default.clone() ) + { + } + + TypeParam(Span sp, ::AST::AttributeList attrs, ::std::string name): + m_attrs( ::std::move(attrs) ), + m_span( ::std::move(sp) ), m_name( ::std::move(name) ), - m_default( Span() ) + m_default(m_span) {} + void setDefault(TypeRef type) { assert(m_default.is_wildcard()); m_default = ::std::move(type); } - const ::std::string& name() const { return m_name; } + const ::AST::AttributeList& attrs() const { return m_attrs; } + const Span& span() const { return m_span; } + const ::std::string& name() const { return m_name; } const TypeRef& get_default() const { return m_default; } TypeRef& get_default() { return m_default; } friend ::std::ostream& operator<<(::std::ostream& os, const TypeParam& tp); }; +class LifetimeParam +{ + ::AST::AttributeList m_attrs; + Span m_span; + Ident m_name; +public: + LifetimeParam(Span sp, ::AST::AttributeList attrs, Ident name): + m_attrs( ::std::move(attrs) ), + m_span( ::std::move(sp) ), + m_name( ::std::move(name) ) + { + } + LifetimeParam(LifetimeParam&&) = default; + LifetimeParam& operator=(LifetimeParam&&) = default; + explicit LifetimeParam(const LifetimeParam&) = default; + + const ::AST::AttributeList& attrs() const { return m_attrs; } + const Span& span() const { return m_span; } + const Ident& name() const { return m_name; } + + friend ::std::ostream& operator<<(::std::ostream& os, const LifetimeParam& p); +}; + +// HigherRankedBounds is defined in `types.hpp` -TAGGED_UNION_EX( GenericBound, (), Lifetime, +TAGGED_UNION_EX( GenericBound, (), None, ( + (None, struct{}), // Lifetime bound: 'test must be valid for 'bound (Lifetime, struct { - ::std::string test; - ::std::string bound; + LifetimeRef test; + LifetimeRef bound; }), // Type lifetime bound (TypeLifetime, struct { TypeRef type; - ::std::string bound; + LifetimeRef bound; }), // Standard trait bound: "Type: [for<'a>] Trait" (IsTrait, struct { + HigherRankedBounds outer_hrbs; TypeRef type; - ::std::vector< ::std::string> hrls; // Higher-ranked lifetimes + HigherRankedBounds inner_hrbs; AST::Path trait; }), // Removed trait bound: "Type: ?Trait" @@ -84,9 +121,10 @@ TAGGED_UNION_EX( GenericBound, (), Lifetime, GenericBound clone() const { TU_MATCH(GenericBound, ( (*this) ), (ent), + (None, return make_None({}); ), (Lifetime, return make_Lifetime({ent.test, ent.bound}); ), (TypeLifetime, return make_TypeLifetime({ent.type.clone(), ent.bound}); ), - (IsTrait, return make_IsTrait({ent.type.clone(), ent.hrls, ent.trait}); ), + (IsTrait, return make_IsTrait({ent.outer_hrbs, ent.type.clone(), ent.inner_hrbs, ent.trait}); ), (MaybeTrait, return make_MaybeTrait({ent.type.clone(), ent.trait}); ), (NotTrait, return make_NotTrait({ent.type.clone(), ent.trait}); ), (Equality, return make_Equality({ent.type.clone(), ent.replacement.clone()}); ) @@ -101,7 +139,7 @@ TAGGED_UNION_EX( GenericBound, (), Lifetime, class GenericParams { ::std::vector m_type_params; - ::std::vector< ::std::string > m_lifetime_params; + ::std::vector m_lifetime_params; ::std::vector m_bounds; public: GenericParams() {} @@ -112,7 +150,7 @@ public: GenericParams clone() const { GenericParams rv; rv.m_type_params = ::std::vector( m_type_params ); // Copy-constructable - rv.m_lifetime_params = m_lifetime_params; + rv.m_lifetime_params = ::std::vector(m_lifetime_params); rv.m_bounds.reserve( m_bounds.size() ); for(auto& e: m_bounds) rv.m_bounds.push_back( e.clone() ); @@ -121,12 +159,12 @@ public: const ::std::vector& ty_params() const { return m_type_params; } ::std::vector& ty_params() { return m_type_params; } - const ::std::vector< ::std::string>& lft_params() const { return m_lifetime_params; } + const ::std::vector& lft_params() const { return m_lifetime_params; } const ::std::vector& bounds() const { return m_bounds; } ::std::vector& bounds() { return m_bounds; } void add_ty_param(TypeParam param) { m_type_params.push_back( ::std::move(param) ); } - void add_lft_param(::std::string name) { m_lifetime_params.push_back( ::std::move(name) ); } + void add_lft_param(LifetimeParam lft) { m_lifetime_params.push_back( ::std::move(lft) ); } void add_bound(GenericBound bound) { m_bounds.push_back( ::std::move(bound) ); } diff --git a/src/ast/path.hpp b/src/ast/path.hpp index 2126e3b2..0470084b 100644 --- a/src/ast/path.hpp +++ b/src/ast/path.hpp @@ -28,6 +28,7 @@ class Static; namespace AST { +class LifetimeRef; class GenericParams; class Crate; class Module; @@ -109,14 +110,14 @@ extern ::std::ostream& operator<<(::std::ostream& os, const PathBinding& x); struct PathParams { - ::std::vector< ::std::string > m_lifetimes; + ::std::vector< LifetimeRef > m_lifetimes; ::std::vector< TypeRef > m_types; ::std::vector< ::std::pair< ::std::string, TypeRef> > m_assoc; PathParams(PathParams&& x) = default; PathParams(const PathParams& x); PathParams() {} - PathParams(::std::vector<::std::string> lfts, ::std::vector tys, ::std::vector<::std::pair<::std::string,TypeRef>> a): + PathParams(::std::vector lfts, ::std::vector tys, ::std::vector<::std::pair<::std::string,TypeRef>> a): m_lifetimes(mv$(lfts)), m_types(mv$(tys)), m_assoc(mv$(a)) diff --git a/src/ast/types.cpp b/src/ast/types.cpp index af99f3d7..8065a3ba 100644 --- a/src/ast/types.cpp +++ b/src/ast/types.cpp @@ -141,6 +141,15 @@ TypeRef TypeRef::clone() const throw ""; } +Ordering Type_TraitPath::ord(const Type_TraitPath& x) const +{ + Ordering rv; + + rv = ::ord( this->path, x.path ); + if(rv != OrdEqual) return rv; + + return rv; +} Ordering TypeRef::ord(const TypeRef& x) const { Ordering rv; @@ -277,7 +286,8 @@ void TypeRef::print(::std::ostream& os, bool is_debug/*=false*/) const for( const auto& it : ent.traits ) { if( &it != &ent.traits.front() ) os << "+"; - it.print_pretty(os, true, is_debug); + os << it.hrbs; + it.path.print_pretty(os, true, is_debug); } os << ")"; ) @@ -286,7 +296,8 @@ void TypeRef::print(::std::ostream& os, bool is_debug/*=false*/) const for( const auto& it : ent.traits ) { if( &it != &ent.traits.front() ) os << "+"; - it.print_pretty(os, true, is_debug); + os << it.hrbs; + it.path.print_pretty(os, true, is_debug); } os << ""; ) @@ -303,3 +314,21 @@ void TypeRef::print(::std::ostream& os, bool is_debug/*=false*/) const return os; } +namespace AST { + ::std::ostream& operator<<(::std::ostream& os, const LifetimeRef& x) { + if( x.m_binding == LifetimeRef::BINDING_STATIC ) { + os << "'static"; + } + else if( x.m_binding == LifetimeRef::BINDING_INFER ) { + os << "'_"; + } + else { + os << "'" << x.m_name; + if( x.m_binding != LifetimeRef::BINDING_UNBOUND ) { + os << "/*" << x.m_binding << "*/"; + } + } + return os; + } +} + diff --git a/src/ast/types.hpp b/src/ast/types.hpp index 820bcf27..49cae373 100644 --- a/src/ast/types.hpp +++ b/src/ast/types.hpp @@ -13,6 +13,63 @@ namespace AST { class ExprNode; class Expr; +class LifetimeParam; +} + +namespace AST { + + // Defined here for dependency reasons + class HigherRankedBounds + { + public: + ::std::vector m_lifetimes; + //::std::vector m_types; + //::std::vector m_bounds; + + bool empty() const { + return m_lifetimes.empty(); + } + + friend ::std::ostream& operator<<(::std::ostream& os, const HigherRankedBounds& x); + }; + + class LifetimeRef + { + static const uint16_t BINDING_STATIC = 0xFFFF; + static const uint16_t BINDING_UNBOUND = 0xFFFE; + static const uint16_t BINDING_INFER = 0xFFFD; + + Ident m_name; + uint16_t m_binding; + + LifetimeRef(Ident name, uint32_t binding): + m_name( ::std::move(name) ), + m_binding( binding ) + { + } + public: + LifetimeRef(): + LifetimeRef("", BINDING_INFER) + { + } + LifetimeRef(Ident name): + LifetimeRef(::std::move(name), BINDING_UNBOUND) + { + } + static LifetimeRef new_static() { + return LifetimeRef("static", BINDING_STATIC); + } + + void set_binding(uint16_t b) { assert(m_binding == BINDING_UNBOUND); m_binding = b; } + + const Ident& name() const { return m_name; } + Ordering ord(const LifetimeRef& x) const { return ::ord(m_name.name, x.m_name.name); } + bool operator==(const LifetimeRef& x) const { return ord(x) == OrdEqual; } + bool operator!=(const LifetimeRef& x) const { return ord(x) != OrdEqual; } + bool operator<(const LifetimeRef& x) const { return ord(x) == OrdLess; }; + + friend ::std::ostream& operator<<(::std::ostream& os, const LifetimeRef& x); + }; } class PrettyPrintType @@ -57,6 +114,14 @@ struct Type_Function Ordering ord(const Type_Function& x) const; }; +struct Type_TraitPath +{ + AST::HigherRankedBounds hrbs; + AST::Path path; + + Ordering ord(const Type_TraitPath& x) const; +}; + TAGGED_UNION(TypeData, None, (None, struct { }), (Any, struct { }), @@ -94,12 +159,12 @@ TAGGED_UNION(TypeData, None, AST::Path path; }), (TraitObject, struct { - ::std::vector<::std::string> hrls; - ::std::vector traits; + ::std::vector traits; + ::std::vector lifetimes; }), (ErasedType, struct { - ::std::vector<::std::string> hrls; - ::std::vector traits; + ::std::vector traits; + ::std::vector lifetimes; }) ); @@ -215,9 +280,9 @@ public: TypeRef(TagPath(), mv$(sp), mv$(path)) {} - TypeRef( Span sp, ::std::vector<::std::string> hrls, ::std::vector traits ): + TypeRef( Span sp, ::std::vector traits, ::std::vector lifetimes ): m_span(mv$(sp)), - m_data(TypeData::make_TraitObject({ mv$(hrls), ::std::move(traits) })) + m_data(TypeData::make_TraitObject({ ::std::move(traits), mv$(lifetimes) })) {} diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp index 077c4b70..0e28b6da 100644 --- a/src/expand/derive.cpp +++ b/src/expand/derive.cpp @@ -86,7 +86,7 @@ struct Deriver for(const auto& arg : params.ty_params()) { params.add_bound( ::AST::GenericBound::make_IsTrait({ - TypeRef(sp, arg.name(), i), {}, trait_path + {}, TypeRef(sp, arg.name(), i), {}, trait_path }) ); i ++; } @@ -96,7 +96,7 @@ struct Deriver for(auto& ty : additional_bounded_types) { params.add_bound( ::AST::GenericBound::make_IsTrait({ - mv$(ty), {}, trait_path + {}, mv$(ty), {}, trait_path }) ); } @@ -1563,11 +1563,10 @@ class Deriver_Hash: ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "state"), TypeRef(TypeRef::TagReference(), sp, true, TypeRef(sp, "H", 0x100|0)) ) ) ); - fcn.params().add_ty_param( AST::TypeParam("H") ); + fcn.params().add_ty_param( AST::TypeParam(sp, {}, "H") ); fcn.params().add_bound( AST::GenericBound::make_IsTrait({ - TypeRef(sp, "H", 0x100|0), - {}, - this->get_trait_path_Hasher(core_name) + {}, TypeRef(sp, "H", 0x100|0), + {}, this->get_trait_path_Hasher(core_name) }) ); fcn.set_code( NEWNODE(Block, vec$(mv$(node))) ); @@ -1717,11 +1716,10 @@ class Deriver_RustcEncodable: ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "s"), TypeRef(TypeRef::TagReference(), sp, true, TypeRef(sp, "S", 0x100|0)) ) ) ); - fcn.params().add_ty_param( AST::TypeParam("S") ); + fcn.params().add_ty_param( AST::TypeParam(sp, {}, "S") ); fcn.params().add_bound( AST::GenericBound::make_IsTrait({ - TypeRef(sp, "S", 0x100|0), - {}, - this->get_trait_path_Encoder() + {}, TypeRef(sp, "S", 0x100|0), + {}, this->get_trait_path_Encoder() }) ); fcn.set_code( NEWNODE(Block, vec$(mv$(node))) ); @@ -1951,11 +1949,10 @@ class Deriver_RustcDecodable: ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "d"), TypeRef(TypeRef::TagReference(), sp, true, TypeRef(sp, "D", 0x100|0)) ) ) ); - fcn.params().add_ty_param( AST::TypeParam("D") ); + fcn.params().add_ty_param( AST::TypeParam(sp, {}, "D") ); fcn.params().add_bound( AST::GenericBound::make_IsTrait({ - TypeRef(sp, "D", 0x100|0), - {}, - this->get_trait_path_Decoder() + {}, TypeRef(sp, "D", 0x100|0), + {}, this->get_trait_path_Decoder() }) ); fcn.set_code( NEWNODE(Block, vec$(mv$(node))) ); diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index aa7655e3..4470b2bb 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -272,13 +272,15 @@ void Expand_Type(::AST::Crate& crate, LList modstack, ::AST: (TraitObject, for(auto& p : e.traits) { - Expand_Path(crate, modstack, mod, p); + // TODO: p.hrbs? Not needed until types are in those + Expand_Path(crate, modstack, mod, p.path); } ), (ErasedType, for(auto& p : e.traits) { - Expand_Path(crate, modstack, mod, p); + // TODO: p.hrbs? + Expand_Path(crate, modstack, mod, p.path); } ) ) @@ -859,6 +861,8 @@ void Expand_GenericParams(::AST::Crate& crate, LList modstac for(auto& bound : params.bounds()) { TU_MATCHA( (bound), (be), + (None, + ), (Lifetime, ), (TypeLifetime, diff --git a/src/expand/proc_macro.cpp b/src/expand/proc_macro.cpp index cdd13a42..28d9f613 100644 --- a/src/expand/proc_macro.cpp +++ b/src/expand/proc_macro.cpp @@ -345,45 +345,41 @@ namespace { ), (TraitObject, m_pmi.send_symbol("("); - if( te.hrls.size() > 0 ) - { - m_pmi.send_ident("for"); - m_pmi.send_symbol("<"); - for(const auto& v : te.hrls) - { - m_pmi.send_lifetime(v.c_str()); - m_pmi.send_symbol(","); - } - m_pmi.send_symbol(">"); - } for(const auto& t : te.traits) { - this->visit_path(t); + this->visit_hrbs(t.hrbs); + this->visit_path(t.path); m_pmi.send_symbol("+"); } + // TODO: Lifetimes m_pmi.send_symbol(")"); ), (ErasedType, m_pmi.send_ident("impl"); - if( te.hrls.size() > 0 ) - { - m_pmi.send_ident("for"); - m_pmi.send_symbol("<"); - for(const auto& v : te.hrls) - { - m_pmi.send_lifetime(v.c_str()); - m_pmi.send_symbol(","); - } - m_pmi.send_symbol(">"); - } for(const auto& t : te.traits) { - this->visit_path(t); + this->visit_hrbs(t.hrbs); + this->visit_path(t.path); m_pmi.send_symbol("+"); } + // TODO: Lifetimes ) ) } + void visit_hrbs(const AST::HigherRankedBounds& hrbs) + { + if( !hrbs.empty() ) + { + m_pmi.send_ident("for"); + m_pmi.send_symbol("<"); + for(const auto& v : hrbs.m_lifetimes) + { + m_pmi.send_lifetime(v.name().name.c_str()); + m_pmi.send_symbol(","); + } + m_pmi.send_symbol(">"); + } + } void visit_path(const AST::Path& path, bool is_expr=false) { @@ -445,7 +441,7 @@ namespace { m_pmi.send_symbol("<"); for(const auto& l : e.args().m_lifetimes) { - m_pmi.send_lifetime(l.c_str()); + m_pmi.send_lifetime(l.name().name.c_str()); m_pmi.send_symbol(","); } for(const auto& t : e.args().m_types) @@ -475,7 +471,7 @@ namespace { { if( !is_first ) m_pmi.send_symbol(","); - m_pmi.send_lifetime(p.c_str()); + m_pmi.send_lifetime(p.name().name.c_str()); is_first = false; } // Types diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index 1dbfdad2..6353a0ea 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -28,6 +28,11 @@ ::HIR::Crate* g_crate_ptr = nullptr; // -------------------------------------------------------------------- +::std::string LowerHIR_LifetimeRef(const ::AST::LifetimeRef& r) +{ + return r.name().name; +} + ::HIR::GenericParams LowerHIR_GenericParams(const ::AST::GenericParams& gp, bool* self_is_sized) { ::HIR::GenericParams rv; @@ -41,24 +46,26 @@ } if( gp.lft_params().size() > 0 ) { - for(const auto& lft_name : gp.lft_params()) - rv.m_lifetimes.push_back( lft_name ); + for(const auto& lft_def : gp.lft_params()) + rv.m_lifetimes.push_back( lft_def.name().name ); } if( gp.bounds().size() > 0 ) { for(const auto& bound : gp.bounds()) { TU_MATCH(::AST::GenericBound, (bound), (e), + (None, + ), (Lifetime, rv.m_bounds.push_back(::HIR::GenericBound::make_Lifetime({ - e.test, - e.bound + LowerHIR_LifetimeRef(e.test), + LowerHIR_LifetimeRef(e.bound) })); ), (TypeLifetime, rv.m_bounds.push_back(::HIR::GenericBound::make_TypeLifetime({ LowerHIR_Type(e.type), - e.bound + LowerHIR_LifetimeRef(e.bound) })); ), (IsTrait, @@ -66,8 +73,8 @@ // TODO: Check if this trait is `Sized` and ignore if it is - rv.m_bounds.push_back(::HIR::GenericBound::make_TraitBound({ mv$(type), LowerHIR_TraitPath(bound.span, e.trait) })); - rv.m_bounds.back().as_TraitBound().trait.m_hrls = e.hrls; + rv.m_bounds.push_back(::HIR::GenericBound::make_TraitBound({ /*LowerHIR_HigherRankedBounds(e.outer_hrbs),*/ mv$(type), LowerHIR_TraitPath(bound.span, e.trait) })); + //rv.m_bounds.back().as_TraitBound().trait.m_hrls = LowerHIR_HigherRankedBounds(e.inner_hrbs); ), (MaybeTrait, auto type = LowerHIR_Type(e.type); @@ -755,47 +762,59 @@ } ), (TraitObject, - //if( e.hrls.size() > 0 ) - // TODO(ty.span(), "TraitObjects with HRLS - " << ty); ::HIR::TypeRef::Data::Data_TraitObject v; // TODO: Lifetime for(const auto& t : e.traits) { - DEBUG("t = " << t); - const auto& tb = t.binding().as_Trait(); + DEBUG("t = " << t.path); + const auto& tb = t.path.binding().as_Trait(); assert( tb.trait_ || tb.hir ); - if( (tb.trait_ ? tb.trait_->is_marker() : tb.hir->m_is_marker) ) { + if( (tb.trait_ ? tb.trait_->is_marker() : tb.hir->m_is_marker) ) + { if( tb.hir ) { DEBUG(tb.hir->m_values.size()); } - v.m_markers.push_back( LowerHIR_GenericPath(ty.span(), t) ); + // TODO: If this has HRBs, what? + v.m_markers.push_back( LowerHIR_GenericPath(ty.span(), t.path) ); } else { // TraitPath -> GenericPath -> SimplePath if( v.m_trait.m_path.m_path.m_components.size() > 0 ) { ERROR(ty.span(), E0000, "Multiple data traits in trait object - " << ty); } - v.m_trait = LowerHIR_TraitPath(ty.span(), t); + // TODO: Handle HRBs + v.m_trait = LowerHIR_TraitPath(ty.span(), t.path); } } return ::HIR::TypeRef( ::HIR::TypeRef::Data::make_TraitObject( mv$(v) ) ); ), (ErasedType, - //if( e.hrls.size() > 0 ) - // TODO(ty.span(), "ErasedType with HRLS - " << ty); ASSERT_BUG(ty.span(), e.traits.size() > 0, "ErasedType with no traits"); ::std::vector< ::HIR::TraitPath> traits; for(const auto& t : e.traits) { - DEBUG("t = " << t); - traits.push_back( LowerHIR_TraitPath(ty.span(), t) ); + DEBUG("t = " << t.path); + // TODO: Pass the HRBs down + traits.push_back( LowerHIR_TraitPath(ty.span(), t.path) ); + } + ::HIR::LifetimeRef lft; + if( e.lifetimes.size() == 0 ) + { + } + else if( e.lifetimes.size() == 1 ) + { + // TODO: Convert the lifetime reference + } + else + { + TODO(ty.span(), "Handle multiple lifetime parameters - " << ty); } // Leave `m_origin` until the bind pass return ::HIR::TypeRef( ::HIR::TypeRef::Data::make_ErasedType(::HIR::TypeRef::Data::Data_ErasedType { ::HIR::Path(::HIR::SimplePath()), 0, mv$(traits), - ::HIR::LifetimeRef() // TODO: Lifetime ref + lft } ) ); ), (Function, diff --git a/src/parse/common.hpp b/src/parse/common.hpp index 1ca86128..49499c86 100644 --- a/src/parse/common.hpp +++ b/src/parse/common.hpp @@ -40,7 +40,7 @@ extern ::std::vector Parse_PathNodes(TokenStream& lex, eParsePath extern AST::PathParams Parse_Path_GenericList(TokenStream& lex); -extern ::std::vector< ::std::string> Parse_HRB(TokenStream& lex); +extern AST::HigherRankedBounds Parse_HRB(TokenStream& lex); extern AST::AttributeList Parse_ItemAttrs(TokenStream& lex); extern void Parse_ParentAttrs(TokenStream& lex, AST::AttributeList& out); extern AST::Attribute Parse_MetaItem(TokenStream& lex); diff --git a/src/parse/paths.cpp b/src/parse/paths.cpp index 59b6b939..d103840e 100644 --- a/src/parse/paths.cpp +++ b/src/parse/paths.cpp @@ -203,7 +203,7 @@ AST::Path Parse_Path(TokenStream& lex, bool is_abs, eParsePathGenericMode generi Token tok; ::std::vector types; - ::std::vector< ::std::string> lifetimes; + ::std::vector lifetimes; ::std::vector< ::std::pair< ::std::string, TypeRef > > assoc_bounds; do { @@ -214,7 +214,7 @@ AST::Path Parse_Path(TokenStream& lex, bool is_abs, eParsePathGenericMode generi switch(GET_TOK(tok, lex)) { case TOK_LIFETIME: - lifetimes.push_back( tok.str() ); + lifetimes.push_back(AST::LifetimeRef(/*lex.point_span(),*/ lex.get_ident(mv$(tok)) )); break; case TOK_IDENT: if( LOOK_AHEAD(lex) == TOK_EQUAL ) diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 35da3a76..2b027bf9 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -119,12 +119,12 @@ bool Parse_Publicity(TokenStream& lex, bool allow_restricted=true) } } -::std::vector< ::std::string> Parse_HRB(TokenStream& lex) +::AST::HigherRankedBounds Parse_HRB(TokenStream& lex) { TRACE_FUNCTION; Token tok; - ::std::vector< ::std::string> lifetimes; + ::AST::HigherRankedBounds rv; GET_CHECK_TOK(tok, lex, TOK_LT); do { auto attrs = Parse_ItemAttrs(lex); @@ -133,17 +133,25 @@ bool Parse_Publicity(TokenStream& lex, bool allow_restricted=true) switch(GET_TOK(tok, lex)) { case TOK_LIFETIME: - lifetimes.push_back(tok.str()); + rv.m_lifetimes.push_back(::AST::LifetimeParam(lex.point_span(), ::std::move(attrs), Ident(lex.getHygiene(), tok.str()))); break; default: throw ParseError::Unexpected(lex, tok, Token(TOK_LIFETIME)); } } while( GET_TOK(tok, lex) == TOK_COMMA ); CHECK_TOK(tok, TOK_GT); - return lifetimes; + return rv; +} + +namespace { + AST::LifetimeRef get_LifetimeRef(TokenStream& lex, Token tok) + { + CHECK_TOK(tok, TOK_LIFETIME); + return AST::LifetimeRef(/*lex.point_span(), */Ident(lex.getHygiene(), mv$(tok.str()))); + } } /// Parse type parameters in a definition -void Parse_TypeBound(TokenStream& lex, AST::GenericParams& ret, TypeRef checked_type, ::std::vector< ::std::string> lifetimes = {}) +void Parse_TypeBound(TokenStream& lex, AST::GenericParams& ret, TypeRef checked_type, AST::HigherRankedBounds outer_hrbs = {}) { TRACE_FUNCTION; Token tok; @@ -156,10 +164,9 @@ void Parse_TypeBound(TokenStream& lex, AST::GenericParams& ret, TypeRef checked_ // return; //} - ::std::vector< ::std::string> hrls; if(GET_TOK(tok, lex) == TOK_LIFETIME) { ret.add_bound(AST::GenericBound::make_TypeLifetime( { - checked_type.clone(), tok.str() + checked_type.clone(), get_LifetimeRef(lex, mv$(tok)) } )); } else if( tok.type() == TOK_QMARK ) { @@ -168,17 +175,17 @@ void Parse_TypeBound(TokenStream& lex, AST::GenericParams& ret, TypeRef checked_ } )); } else { + ::AST::HigherRankedBounds inner_hrls; if( tok.type() == TOK_RWORD_FOR ) { - hrls = Parse_HRB(lex); + inner_hrls = Parse_HRB(lex); } else { PUTBACK(tok, lex); } - (void)hrls; // TODO: HRLs ret.add_bound( AST::GenericBound::make_IsTrait({ - checked_type.clone(), mv$(lifetimes), Parse_Path(lex, PATH_GENERIC_TYPE) + mv$(outer_hrbs), checked_type.clone(), mv$(inner_hrls), Parse_Path(lex, PATH_GENERIC_TYPE) }) ); } } while( GET_TOK(tok, lex) == TOK_PLUS ); @@ -199,14 +206,12 @@ AST::GenericParams Parse_GenericParams(TokenStream& lex) PUTBACK(tok, lex); auto attrs = Parse_ItemAttrs(lex); - (void)attrs; // TODO: Attributes on generic params GET_TOK(tok, lex); if( tok.type() == TOK_IDENT ) { - // TODO: Hygine ::std::string param_name = mv$(tok.str()); - ret.add_ty_param( AST::TypeParam( param_name ) ); + ret.add_ty_param( AST::TypeParam( lex.point_span(), ::std::move(attrs), param_name ) ); auto param_ty = TypeRef(lex.point_span(), param_name); if( GET_TOK(tok, lex) == TOK_COLON ) @@ -223,14 +228,14 @@ AST::GenericParams Parse_GenericParams(TokenStream& lex) } else if( tok.type() == TOK_LIFETIME ) { - // TODO: Should lifetimes have hygine? - ::std::string param_name = tok.str(); - ret.add_lft_param( param_name ); + auto param_name = tok.str(); + auto ref = get_LifetimeRef(lex, mv$(tok)); + ret.add_lft_param(::AST::LifetimeParam(lex.point_span(), ::std::move(attrs), Ident(lex.getHygiene(), param_name) )); if( GET_TOK(tok, lex) == TOK_COLON ) { do { GET_CHECK_TOK(tok, lex, TOK_LIFETIME); - ret.add_bound(AST::GenericBound::make_Lifetime( {param_name, tok.str()} )); + ret.add_bound(AST::GenericBound::make_Lifetime({ AST::LifetimeRef(ref), get_LifetimeRef(lex, mv$(tok)) })); } while( GET_TOK(tok, lex) == TOK_PLUS ); } } @@ -258,11 +263,11 @@ void Parse_WhereClause(TokenStream& lex, AST::GenericParams& params) if( tok.type() == TOK_LIFETIME ) { - auto lhs = mv$(tok.str()); + auto lhs = get_LifetimeRef(lex, mv$(tok)); GET_CHECK_TOK(tok, lex, TOK_COLON); do { GET_CHECK_TOK(tok, lex, TOK_LIFETIME); - auto rhs = mv$(tok.str()); + auto rhs = get_LifetimeRef(lex, mv$(tok)); params.add_bound( AST::GenericBound::make_Lifetime({lhs, rhs}) ); } while( GET_TOK(tok, lex) == TOK_PLUS ); PUTBACK(tok, lex); @@ -270,11 +275,11 @@ void Parse_WhereClause(TokenStream& lex, AST::GenericParams& params) // Higher-ranked types/lifetimes else if( tok.type() == TOK_RWORD_FOR ) { - ::std::vector< ::std::string> lifetimes = Parse_HRB(lex); + auto hrbs = Parse_HRB(lex); TypeRef type = Parse_Type(lex); GET_CHECK_TOK(tok, lex, TOK_COLON); - Parse_TypeBound(lex,params, mv$(type), mv$(lifetimes)); + Parse_TypeBound(lex,params, mv$(type), mv$(hrbs)); } else { @@ -355,9 +360,9 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, bool allow_ if( lex.lookahead(ofs) == TOK_RWORD_SELF || (lex.lookahead(ofs) == TOK_RWORD_MUT && lex.lookahead(ofs+1) == TOK_RWORD_SELF) ) { auto ps = lex.start_span(); - ::std::string lifetime; + AST::LifetimeRef lifetime; if( GET_TOK(tok, lex) == TOK_LIFETIME ) { - lifetime = tok.str(); + lifetime = get_LifetimeRef(lex, mv$(tok)); GET_TOK(tok, lex); } auto ty_sp = lex.end_span(ps); @@ -622,6 +627,7 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items do { if( GET_TOK(tok, lex) == TOK_LIFETIME ) { // TODO: Need a better way of indiciating 'static than just an invalid path + // TODO: Ensure that it's 'static supertraits.push_back( make_spanned( Span(tok.get_pos()), AST::Path() ) ); } else if( tok.type() == TOK_BRACE_OPEN ) { diff --git a/src/parse/tokenstream.cpp b/src/parse/tokenstream.cpp index 625f12db..611df2ff 100644 --- a/src/parse/tokenstream.cpp +++ b/src/parse/tokenstream.cpp @@ -140,6 +140,10 @@ Ident TokenStream::get_ident(Token tok) const if(tok.type() == TOK_IDENT) { return Ident(getHygiene(), tok.str()); } + else if(tok.type() == TOK_LIFETIME) { + // TODO: Maybe only when it's explicitly asked for? + return Ident(getHygiene(), tok.str()); + } else if( tok.type() == TOK_INTERPOLATED_IDENT ) { TODO(getPosition(), "get_ident from TOK_INTERPOLATED_IDENT"); } diff --git a/src/parse/types.cpp b/src/parse/types.cpp index 26785cf7..b0b43426 100644 --- a/src/parse/types.cpp +++ b/src/parse/types.cpp @@ -13,8 +13,8 @@ // === PROTOTYPES === //TypeRef Parse_Type(TokenStream& lex, bool allow_trait_list); TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list); -TypeRef Parse_Type_Fn(TokenStream& lex, ::std::vector<::std::string> hrls = {}); -TypeRef Parse_Type_Path(TokenStream& lex, ::std::vector<::std::string> hrls, bool allow_trait_list); +TypeRef Parse_Type_Fn(TokenStream& lex, AST::HigherRankedBounds hrbs = {}); +TypeRef Parse_Type_Path(TokenStream& lex, AST::HigherRankedBounds hrbs, bool allow_trait_list); TypeRef Parse_Type_ErasedType(TokenStream& lex, bool allow_trait_list); // === CODE === @@ -196,7 +196,7 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) throw ParseError::BugCheck("Reached end of Parse_Type"); } -TypeRef Parse_Type_Fn(TokenStream& lex, ::std::vector<::std::string> hrls) +TypeRef Parse_Type_Fn(TokenStream& lex, ::AST::HigherRankedBounds hrbs) { auto ps = lex.start_span(); // TODO: HRLs @@ -262,36 +262,52 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::std::vector<::std::string> hrls) return TypeRef(TypeRef::TagFunction(), lex.end_span(ps), is_unsafe, mv$(abi), mv$(args), is_variadic, mv$(ret_type)); } -TypeRef Parse_Type_Path(TokenStream& lex, ::std::vector<::std::string> hrls, bool allow_trait_list) +TypeRef Parse_Type_Path(TokenStream& lex, ::AST::HigherRankedBounds hrbs, bool allow_trait_list) { Token tok; auto ps = lex.start_span(); - if( ! allow_trait_list ) + if( hrbs.empty() && !allow_trait_list ) { return TypeRef(TypeRef::TagPath(), lex.end_span(ps), Parse_Path(lex, PATH_GENERIC_TYPE)); } else { - ::std::vector traits; - ::std::vector< ::std::string> lifetimes; - do { - if( LOOK_AHEAD(lex) == TOK_LIFETIME ) { - GET_TOK(tok, lex); - lifetimes.push_back( tok.str() ); + ::std::vector traits; + ::std::vector lifetimes; + + traits.push_back(Type_TraitPath { mv$(hrbs), Parse_Path(lex, PATH_GENERIC_TYPE) }); + + if( allow_trait_list ) + { + while( GET_TOK(tok, lex) == TOK_PLUS ) + { + if( LOOK_AHEAD(lex) == TOK_LIFETIME ) { + GET_TOK(tok, lex); + lifetimes.push_back(AST::LifetimeRef( /*lex.point_span(),*/ lex.get_ident(mv$(tok)) )); + } + else + { + if( lex.lookahead(0) == TOK_RWORD_FOR ) + { + hrbs = Parse_HRB(lex); + } + traits.push_back({ mv$(hrbs), Parse_Path(lex, PATH_GENERIC_TYPE) }); + } } - else - traits.push_back( Parse_Path(lex, PATH_GENERIC_TYPE) ); - } while( GET_TOK(tok, lex) == TOK_PLUS ); - PUTBACK(tok, lex); - if( hrls.size() > 0 || traits.size() > 1 || lifetimes.size() > 0 ) { - if( lifetimes.size() ) - DEBUG("TODO: Lifetime bounds on trait objects"); - return TypeRef(lex.end_span(ps), mv$(hrls), ::std::move(traits)); + PUTBACK(tok, lex); } - else { - return TypeRef(TypeRef::TagPath(), lex.end_span(ps), mv$(traits.at(0))); + + if( !traits[0].hrbs.empty() || traits.size() > 1 || lifetimes.size() > 0 ) + { + if( lifetimes.empty()) + lifetimes.push_back(AST::LifetimeRef()); + return TypeRef(lex.end_span(ps), mv$(traits), mv$(lifetimes)); + } + else + { + return TypeRef(TypeRef::TagPath(), lex.end_span(ps), mv$(traits.at(0).path)); } } } @@ -300,20 +316,25 @@ TypeRef Parse_Type_ErasedType(TokenStream& lex, bool allow_trait_list) Token tok; auto ps = lex.start_span(); - ::std::vector traits; - ::std::vector< ::std::string> lifetimes; + ::std::vector traits; + ::std::vector lifetimes; do { if( LOOK_AHEAD(lex) == TOK_LIFETIME ) { GET_TOK(tok, lex); - lifetimes.push_back( tok.str() ); + lifetimes.push_back(AST::LifetimeRef( /*lex.point_span(),*/ lex.get_ident(mv$(tok)) )); } else - traits.push_back( Parse_Path(lex, PATH_GENERIC_TYPE) ); + { + AST::HigherRankedBounds hrbs; + if( lex.lookahead(0) == TOK_RWORD_FOR ) + { + hrbs = Parse_HRB(lex); + } + traits.push_back({ mv$(hrbs), Parse_Path(lex, PATH_GENERIC_TYPE) }); + } } while( GET_TOK(tok, lex) == TOK_PLUS ); PUTBACK(tok, lex); - if( lifetimes.size() ) - DEBUG("TODO: Lifetime bounds on erased types"); - return TypeRef(lex.end_span(ps), TypeData::make_ErasedType({ {}, mv$(traits) })); + return TypeRef(lex.end_span(ps), TypeData::make_ErasedType({ mv$(traits), mv$(lifetimes) })); } diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index 2c17592c..d05e3bc6 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -1500,24 +1500,24 @@ void Resolve_Absolute_Type(Context& context, TypeRef& type) ) TU_IFLET(::AST::PathBinding, e.path.binding(), Trait, be, - auto ty = ::TypeRef( type.span(), {}, ::make_vec1(mv$(e.path)) ); + auto ty = ::TypeRef( type.span(), ::make_vec1(Type_TraitPath { {}, mv$(e.path)}), {} ); type = mv$(ty); return ; ) ), (TraitObject, - //context.push_lifetimes( e.hrls ); for(auto& trait : e.traits) { - Resolve_Absolute_Path(context, type.span(), Context::LookupMode::Type, trait); + //context.push_lifetimes( trait.hrbs.m_lifetimes ); + Resolve_Absolute_Path(context, type.span(), Context::LookupMode::Type, trait.path); + //context.pop_lifetimes(); } - //context.pop_lifetimes(); ), (ErasedType, - //context.push_lifetimes( e.hrls ); for(auto& trait : e.traits) { - Resolve_Absolute_Path(context, type.span(), Context::LookupMode::Type, trait); + //context.push_lifetimes( trait.hrbs.m_lifetimes ); + Resolve_Absolute_Path(context, type.span(), Context::LookupMode::Type, trait.path); + //context.pop_lifetimes(); } - //context.pop_lifetimes(); ) ) } @@ -1683,6 +1683,8 @@ void Resolve_Absolute_Generic(Context& context, ::AST::GenericParams& params) for( auto& bound : params.bounds() ) { TU_MATCH(::AST::GenericBound, (bound), (e), + (None, + ), (Lifetime, // TODO: Link lifetime names to params ), -- 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/ast.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 = '"<