summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-05-20 11:55:31 +0800
committerJohn Hodge <tpg@mutabah.net>2016-05-20 11:55:31 +0800
commita0c013a290f88e4ade34c08ff618d8f1ed3f63f6 (patch)
treeae0d233b2189ab58d00beeeadebeda07ac792bea /src
parent19b8d4012bf6d81c47f7eab66a7e38d05d7af718 (diff)
downloadmrust-a0c013a290f88e4ade34c08ff618d8f1ed3f63f6.tar.gz
AST/Path - Move crate name to Absolute form
Diffstat (limited to 'src')
-rw-r--r--src/ast/path.cpp32
-rw-r--r--src/ast/path.hpp23
-rw-r--r--src/hir/from_ast.cpp2
-rw-r--r--src/parse/root.cpp2
-rw-r--r--src/resolve/absolute.cpp23
-rw-r--r--src/resolve/use.cpp6
6 files changed, 46 insertions, 42 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;
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 8a611d33..d8e21496 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -335,7 +335,7 @@
::HIR::SimplePath LowerHIR_SimplePath(const ::AST::Path& path, bool allow_final_generic = false)
{
TU_IFLET(::AST::Path::Class, path.m_class, Absolute, e,
- ::HIR::SimplePath rv( path.crate() );
+ ::HIR::SimplePath rv( e.crate );
for( const auto& node : e.nodes )
{
if( node.args().size() > 0 )
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index df149a5b..dd3d8904 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -1168,7 +1168,7 @@ void Parse_Use(TokenStream& lex, ::std::function<void(AST::UseStmt, ::std::strin
if( LOOK_AHEAD(lex) == TOK_STRING )
{
GET_CHECK_TOK(tok, lex, TOK_STRING);
- path.set_crate(tok.str());
+ path = ::AST::Path(tok.str(), {});
GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON);
}
else {
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index da27261f..5685ae82 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -218,7 +218,7 @@ struct Context
break;
case LookupMode::Type:
- //if( name == "SizeHint" ) {
+ //if( name == "IntoIterator" ) {
// DEBUG("lookup_in_mod(mod="<<mod.path()<<")");
// for(const auto& v : mod.m_type_items) {
// DEBUG("- " << v.first << " = " << (v.second.is_pub ? "pub " : "") << v.second.path);
@@ -465,6 +465,7 @@ void Resolve_Absolute_Path(/*const*/ Context& context, const Span& sp, Context::
(Absolute,
DEBUG("- Absolute");
// Nothing to do (TODO: Bind?)
+ Resolve_Absolute_PathNodes(context, Span(), e.nodes);
),
(UFCS,
DEBUG("- UFCS");
@@ -476,6 +477,26 @@ void Resolve_Absolute_Path(/*const*/ Context& context, const Span& sp, Context::
Resolve_Absolute_PathNodes(context, Span(), e.nodes);
)
)
+
+ #if 0
+ TU_MATCH_DEF(::AST::Path::Class, (path.m_class), (e),
+ (
+ BUG(sp, "Path wasn't absolutised correctly");
+ ),
+ (Local,
+ // TODO: Ensure that local paths are bound to the variable/type index
+ ),
+ (Absolute,
+ if( e.crate != "" ) {
+ // TODO: Handle items from other crates (back-converting HIR paths)
+ }
+ TODO(sp, "Bind absolute paths to relevant items (and expand)");
+ ),
+ (UFCS,
+ // TODO: Resolve UFCS to item class (if possible)
+ )
+ )
+ #endif
}
void Resolve_Absolute_Type(Context& context, TypeRef& type)
diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp
index 9931eefa..2d86be13 100644
--- a/src/resolve/use.cpp
+++ b/src/resolve/use.cpp
@@ -39,7 +39,7 @@ void Resolve_Use(::AST::Crate& crate)
),
(Super,
assert(e.count >= 1);
- AST::Path np(base_path.crate(), {});
+ AST::Path np("", {});
if( e.count > base_path.nodes().size() ) {
ERROR(span, E0000, "Too many `super` components");
}
@@ -67,8 +67,8 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path
BUG(span, "Use path is not absolute after absolutisation");
// TODO: Is this a valid assertion?
- if( use_stmt.data.path.crate() != "" )
- BUG(span, "Use path crate was set before resolve");
+ //if( use_stmt.data.path.crate() != "" )
+ // BUG(span, "Use path crate was set before resolve");
use_stmt.data.path.bind( Resolve_Use_GetBinding(span, crate, use_stmt.data.path, parent_modules) );