summaryrefslogtreecommitdiff
path: root/src/ast
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2015-09-06 18:08:38 +0800
committerJohn Hodge <tpg@mutabah.net>2015-09-06 18:08:38 +0800
commit03e211d6eeb3f8f3c6f0b22f77c2074e81443952 (patch)
tree5e07ee69f9020e829e79fb700fa2f35e602b0bcb /src/ast
parent0b6d7c51056ed7b8eb25af6041c4feb5e6e23051 (diff)
downloadmrust-03e211d6eeb3f8f3c6f0b22f77c2074e81443952.tar.gz
Rough span support
Diffstat (limited to 'src/ast')
-rw-r--r--src/ast/path.cpp8
-rw-r--r--src/ast/path.hpp47
-rw-r--r--src/ast/provided_module.cpp4
3 files changed, 34 insertions, 25 deletions
diff --git a/src/ast/path.cpp b/src/ast/path.cpp
index 971cc657..247a6b2b 100644
--- a/src/ast/path.cpp
+++ b/src/ast/path.cpp
@@ -83,13 +83,14 @@ typename ::std::vector<Item<T> >::const_iterator find_named(const ::std::vector<
}
// --- AST::Path
-AST::Path::Path(TagUfcs, TypeRef type, TypeRef trait):
- m_class( AST::Path::Class::make_UFCS({box$(type), box$(trait), {}}) )
+AST::Path::Path(TagUfcs, TypeRef type, TypeRef trait, ::std::vector<AST::PathNode> nodes):
+ m_class( AST::Path::Class::make_UFCS({box$(type), box$(trait), nodes}) )
{
}
AST::Path::Path(const Path& x):
m_crate(x.m_crate),
- m_class()
+ m_class(),
+ m_span(x.m_span)
//m_binding(x.m_binding)
{
TU_MATCH(Class, (x.m_class), (ent),
@@ -850,6 +851,7 @@ void Path::print_pretty(::std::ostream& os) const
os << "::" << n;
)
)
+ os << "/*[" << path.span().filename << ":" << path.span().start_line << "]*/";
#else
switch(path.m_class)
{
diff --git a/src/ast/path.hpp b/src/ast/path.hpp
index 0fa4ff04..9e190453 100644
--- a/src/ast/path.hpp
+++ b/src/ast/path.hpp
@@ -12,6 +12,7 @@
#include <serialise.hpp>
#include <tagged_union.hpp>
#include <string>
+#include "../include/span.hpp"
class TypeRef;
@@ -130,6 +131,7 @@ private:
public:
Class m_class;
+ Span m_span;
private:
PathBinding m_binding;
@@ -139,18 +141,17 @@ public:
m_class()
{}
Path(Path&&) noexcept = default;
- Path& operator=(AST::Path&&) = default;
+ Path& operator=(AST::Path&& x) {
+ m_crate = mv$(x.m_crate);
+ m_class = mv$(x.m_class);
+ //m_span = mv$(x.m_span);
+ x.m_binding = mv$(x.m_binding);
+ return *this;
+ }
Path(const Path& x);
// ABSOLUTE
- struct TagAbsolute {};
- Path(TagAbsolute):
- m_class( Class::make_Absolute({}) )
- {}
- Path(::std::initializer_list<PathNode> l):
- Path("", l)
- {}
Path(::std::string crate, ::std::vector<PathNode> nodes):
m_crate( ::std::move(crate) ),
m_class( Class::make_Absolute({nodes: mv$(nodes)}) )
@@ -158,7 +159,7 @@ public:
// UFCS
struct TagUfcs {};
- Path(TagUfcs, TypeRef type, TypeRef trait);
+ Path(TagUfcs, TypeRef type, TypeRef trait, ::std::vector<PathNode> nodes={});
// VARIABLE
struct TagLocal {};
@@ -171,18 +172,18 @@ public:
// RELATIVE
struct TagRelative {};
- Path(TagRelative):
- m_class( Class::make_Relative({}) )
+ Path(TagRelative, ::std::vector<PathNode> nodes):
+ m_class( Class::make_Relative({nodes: mv$(nodes)}) )
{}
// SELF
struct TagSelf {};
- Path(TagSelf):
- m_class( Class::make_Self({}) )
+ Path(TagSelf, ::std::vector<PathNode> nodes):
+ m_class( Class::make_Self({nodes: nodes}) )
{}
// SUPER
struct TagSuper {};
- Path(TagSuper):
- m_class( Class::make_Super({}) )
+ Path(TagSuper, ::std::vector<PathNode> nodes):
+ m_class( Class::make_Super({nodes: nodes}) )
{}
void set_crate(::std::string crate) {
@@ -191,6 +192,12 @@ public:
DEBUG("crate set to " << m_crate);
}
}
+ void set_span(Span sp) {
+ this->m_span = sp;
+ }
+ const Span& span() const {
+ return this->m_span;
+ }
Class::Tag class_tag() const {
@@ -222,14 +229,14 @@ public:
m_binding = PathBinding();
}
Path operator+(PathNode&& pn) const {
- Path tmp = Path(TagRelative());
- tmp.append( ::std::move(pn) );
- return Path(*this) += tmp;
+ Path tmp = Path(*this);
+ tmp.nodes().push_back( pn );
+ return tmp;
}
Path operator+(const ::std::string& s) const {
- Path tmp = Path(TagRelative());
+ Path tmp = Path(*this);
tmp.append(PathNode(s, {}));
- return Path(*this) += tmp;
+ return tmp;
}
Path operator+(const Path& x) const {
return Path(*this) += x;
diff --git a/src/ast/provided_module.cpp b/src/ast/provided_module.cpp
index 460b7494..fc006020 100644
--- a/src/ast/provided_module.cpp
+++ b/src/ast/provided_module.cpp
@@ -23,11 +23,11 @@ void AST_InitProvidedModule()
void AST_InitProvidedModule_Impls()
{
if( !g_copy_marker_path.is_valid() ) {
- g_copy_marker_path = AST::Path( {AST::PathNode("marker"),AST::PathNode("Copy")} );
+ g_copy_marker_path = AST::Path( "", {AST::PathNode("marker"),AST::PathNode("Copy")} );
}
if( !g_sized_marker_path.is_valid() ) {
- g_sized_marker_path = AST::Path( {AST::PathNode("marker"),AST::PathNode("Sized")} );
+ g_sized_marker_path = AST::Path( "", {AST::PathNode("marker"),AST::PathNode("Sized")} );
}
#define impl(trait, type) \