diff options
author | John Hodge <tpg@mutabah.net> | 2016-05-20 11:55:31 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-05-20 11:55:31 +0800 |
commit | a0c013a290f88e4ade34c08ff618d8f1ed3f63f6 (patch) | |
tree | ae0d233b2189ab58d00beeeadebeda07ac792bea /src/ast | |
parent | 19b8d4012bf6d81c47f7eab66a7e38d05d7af718 (diff) | |
download | mrust-a0c013a290f88e4ade34c08ff618d8f1ed3f63f6.tar.gz |
AST/Path - Move crate name to Absolute form
Diffstat (limited to 'src/ast')
-rw-r--r-- | src/ast/path.cpp | 32 | ||||
-rw-r--r-- | src/ast/path.hpp | 23 |
2 files changed, 19 insertions, 36 deletions
diff --git a/src/ast/path.cpp b/src/ast/path.cpp index 9ff9fe0d..b8ebb234 100644 --- a/src/ast/path.cpp +++ b/src/ast/path.cpp @@ -110,7 +110,6 @@ AST::Path::Path(TagUfcs, TypeRef type, Path trait, ::std::vector<AST::PathNode> { } AST::Path::Path(const Path& x): - m_crate(x.m_crate), m_class() //m_binding(x.m_binding) { @@ -129,7 +128,7 @@ AST::Path::Path(const Path& x): m_class = Class::make_Super({count: ent.count, nodes: ent.nodes}); ), (Absolute, - m_class = Class::make_Absolute({nodes: ent.nodes}); + m_class = Class::make_Absolute({crate: ent.crate, nodes: ent.nodes}); ), (UFCS, if( ent.trait ) @@ -359,15 +358,17 @@ int Path::equal_no_generic(const Path& x) const DEBUG("equal_no_generic(this = " << *this << ", x = " << x << ")"); if( m_class.tag() != x.m_class.tag() ) return -1; - if( m_crate != x.m_crate ) - return -1; TU_MATCH(Path::Class, (m_class, x.m_class), (ent, x_ent), (Invalid, return 0; ), (Local, return (ent.name == x_ent.name ? 0 : 1); ), (Relative, return Path::node_lists_equal_no_generic(ent.nodes, x_ent.nodes); ), - (Absolute, return Path::node_lists_equal_no_generic(ent.nodes, x_ent.nodes); ), + (Absolute, + if( ent.crate != x_ent.crate ) + return -1; + return Path::node_lists_equal_no_generic(ent.nodes, x_ent.nodes); + ), (Self , return Path::node_lists_equal_no_generic(ent.nodes, x_ent.nodes); ), (Super , return Path::node_lists_equal_no_generic(ent.nodes, x_ent.nodes); ), (UFCS, @@ -418,9 +419,6 @@ Ordering Path::ord(const Path& x) const rv = ::ord( (unsigned)m_class.tag(), (unsigned)x.m_class.tag() ); if( rv != OrdEqual ) return rv; - rv = ::ord( m_crate, x.m_crate ); - if( rv != OrdEqual ) return rv; - TU_MATCH(Path::Class, (m_class, x.m_class), (ent, x_ent), (Invalid, return OrdEqual; @@ -438,6 +436,8 @@ Ordering Path::ord(const Path& x) const return ::ord(ent.nodes, x_ent.nodes); ), (Absolute, + rv = ::ord( ent.crate, x_ent.crate ); + if( rv != OrdEqual ) return rv; return ::ord(ent.nodes, x_ent.nodes); ), (UFCS, @@ -494,8 +494,8 @@ void Path::print_pretty(::std::ostream& os, bool is_type_context) const } ), (Absolute, - if( m_crate != "" ) - os << "::\"" << m_crate << "\""; + if( ent.crate != "" ) + os << "::\"" << ent.crate << "\""; for(const auto& n : ent.nodes) { os << "::"; @@ -528,19 +528,7 @@ void Path::print_pretty(::std::ostream& os, bool is_type_context) const ::std::ostream& operator<<(::std::ostream& os, const Path& path) { - #if PRETTY_PATH_PRINT path.print_pretty(os, false); - #else - switch(path.m_class) - { - case Path::RELATIVE: - os << "Path({" << path.m_nodes << "})"; - break; - case Path::ABSOLUTE: - os << "Path(TagAbsolute, \""<<path.m_crate<<"\", {" << path.m_nodes << "})"; - break; - } - #endif return os; } void operator%(Serialiser& s, Path::Class::Tag c) { diff --git a/src/ast/path.hpp b/src/ast/path.hpp index 65d65159..9a2f3579 100644 --- a/src/ast/path.hpp +++ b/src/ast/path.hpp @@ -124,6 +124,7 @@ public: ::std::vector<PathNode> nodes; } ), (Absolute, struct { // Absolute + ::std::string crate; ::std::vector<PathNode> nodes; } ), (UFCS, struct { // Type-relative @@ -132,10 +133,6 @@ public: ::std::vector<PathNode> nodes; } ) ); - -private: - /// The crate defining the root of this path (used for path resolution) - ::std::string m_crate; public: Class m_class; @@ -149,7 +146,6 @@ public: {} Path(Path&&) noexcept = default; Path& operator=(AST::Path&& x) { - m_crate = mv$(x.m_crate); m_class = mv$(x.m_class); m_binding = mv$(x.m_binding); //DEBUG("Path, " << x); @@ -160,8 +156,7 @@ public: // ABSOLUTE Path(::std::string crate, ::std::vector<PathNode> nodes): - m_crate( ::std::move(crate) ), - m_class( Class::make_Absolute({nodes: mv$(nodes)}) ) + m_class( Class::make_Absolute({crate: mv$(crate), nodes: mv$(nodes)}) ) {} // UFCS @@ -194,12 +189,12 @@ public: m_class( Class::make_Super({count: count, nodes: mv$(nodes)}) ) {} - void set_crate(::std::string crate) { - if( m_crate == "" ) { - m_crate = crate; - DEBUG("crate set to " << m_crate); - } - } + //void set_crate(::std::string crate) { + // if( m_crate == "" ) { + // m_crate = crate; + // DEBUG("crate set to " << m_crate); + // } + //} Class::Tag class_tag() const { @@ -288,7 +283,7 @@ public: ) throw ::std::runtime_error("Path::nodes() fell off"); } - const ::std::string& crate() const { return m_crate; } + //const ::std::string& crate() const { return m_crate; } bool is_concrete() const; |