diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-22 20:20:14 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-22 20:20:14 +0800 |
commit | cc4c5fbe0c4980d4a0a7350c82f6f586bbcd38b5 (patch) | |
tree | 09c31f94a5b2ceea907b7528b546db8d5832e1d6 | |
parent | acf27310066894f76399b237ccfe91db3f8d759c (diff) | |
download | mrust-cc4c5fbe0c4980d4a0a7350c82f6f586bbcd38b5.tar.gz |
HIR - Commit missing header (this is why we have CI)
-rw-r--r-- | src/hir/item_path.hpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/hir/item_path.hpp b/src/hir/item_path.hpp new file mode 100644 index 00000000..78056064 --- /dev/null +++ b/src/hir/item_path.hpp @@ -0,0 +1,83 @@ +/* + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * hir/item-path.hpp + * - Printable path to an item in the HIR + */ +#pragma once + +namespace HIR { + +class ItemPath +{ + const ItemPath* parent = nullptr; + const ::HIR::TypeRef* ty = nullptr; + const ::HIR::SimplePath* trait = nullptr; + const ::HIR::PathParams* trait_params = nullptr; + const char* name = nullptr; + +public: + ItemPath() {} + ItemPath(const ItemPath& p, const char* n): + parent(&p), + name(n) + {} + ItemPath(const ::HIR::TypeRef& type): + ty(&type) + {} + ItemPath(const ::HIR::TypeRef& type, const ::HIR::SimplePath& path, const ::HIR::PathParams& params): + ty(&type), + trait(&path), + trait_params(¶ms) + {} + ItemPath(const ::HIR::SimplePath& path): + trait(&path) + {} + + ::HIR::SimplePath get_simple_path() const { + if( parent ) { + assert(name); + return parent->get_simple_path() + name; + } + else { + assert(!name); + return ::HIR::SimplePath(); + } + } + const char* get_name() const { + return name ? name : ""; + } + + ItemPath operator+(const ::std::string& name) const { + return ItemPath(*this, name.c_str()); + } + + friend ::std::ostream& operator<<(::std::ostream& os, const ItemPath& x) { + if( x.parent ) { + os << *x.parent; + } + if( x.name ) { + os << "::" << x.name; + } + else if( x.ty ) { + os << "<" << *x.ty; + if( x.trait ) { + os << " as " << *x.trait; + if( x.trait_params ) { + os << *x.trait_params; + } + } + os << ">"; + } + else if( x.trait ) { + os << "<* as " << *x.trait << ">"; + } + else { + } + return os; + } +}; + +} + |