diff options
-rw-r--r-- | src/hir/from_ast.cpp | 66 | ||||
-rw-r--r-- | src/hir/path.cpp | 16 | ||||
-rw-r--r-- | src/hir/path.hpp | 3 |
3 files changed, 84 insertions, 1 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index 92ac3dc6..28fa490c 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -62,12 +62,76 @@ } } +::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() ); + for( const auto& node : e.nodes ) + { + if( node.args().size() > 0 ) + { + if( allow_final_generic && &node == &e.nodes.back() ) { + // Let it pass + } + else { + throw "BUG: Encountered path with parameters when creating ::HIR::GenericPath"; + } + } + + rv.m_components.push_back( node.name() ); + } + return rv; + ) + else { + throw "BUG: Encountered non-Absolute path when creating ::HIR::GenericPath"; + } +} ::HIR::GenericPath LowerHIR_GenericPath(const ::AST::Path& path) { - throw ::std::runtime_error("TODO: LowerHIR_GenericPath"); + TU_IFLET(::AST::Path::Class, path.m_class, Absolute, e, + auto sp = LowerHIR_SimplePath(path, true); + ::HIR::PathParams params; + for(const auto& param : e.nodes.back().args()) { + params.m_types.push_back( LowerHIR_Type(param) ); + } + return ::HIR::GenericPath(mv$(sp), mv$(params)); + ) + else { + throw "BUG: Encountered non-Absolute path when creating ::HIR::GenericPath"; + } } ::HIR::Path LowerHIR_Path(const ::AST::Path& path) { + TU_MATCH(::AST::Path::Class, (path.m_class), (e), + (Invalid, + throw "BUG: Encountered Invalid path in LowerHIR_Path"; + ), + (Local, + throw "TODO: What to do wth Path::Class::Local in LowerHIR_Path"; + ), + (Relative, + throw "BUG: Encountered `Relative` path in LowerHIR_Path"; + ), + (Self, + throw "BUG: Encountered `Self` path in LowerHIR_Path"; + ), + (Super, + throw "BUG: Encountered `Super` path in LowerHIR_Path"; + ), + (Absolute, + return ::HIR::Path( LowerHIR_GenericPath(path) ); + ), + (UFCS, + if( e.nodes.size() != 1 ) + throw "TODO: Handle UFCS with multiple nodes"; + return ::HIR::Path( + LowerHIR_Type(*e.type), + LowerHIR_GenericPath(*e.trait), + e.nodes[0].name(), + {} + ); + ) + ) throw ::std::runtime_error("TODO: LowerHIR_Path"); } diff --git a/src/hir/path.cpp b/src/hir/path.cpp index 3ea90b9f..3c955f6a 100644 --- a/src/hir/path.cpp +++ b/src/hir/path.cpp @@ -42,7 +42,23 @@ namespace HIR { m_path( mv$(sp) ) { } +::HIR::GenericPath::GenericPath(::HIR::SimplePath sp, ::HIR::PathParams params): + m_path( mv$(sp) ), + m_params( mv$(params) ) +{ +} + +::HIR::Path::Path(::HIR::GenericPath gp): + m_data( ::HIR::Path::Data::make_Generic( mv$(gp) ) ) +{ +} +::HIR::Path::Path(::HIR::TypeRefPtr type, ::HIR::GenericPath trait, ::std::string item, ::HIR::PathParams params): + m_data( ::HIR::Path::Data::make_UFCS({ + mv$(type), mv$(trait), mv$(item), mv$(params) + }) ) +{ +} ::HIR::Path::Path(::HIR::SimplePath sp): m_data( ::HIR::Path::Data::make_Generic(::HIR::GenericPath(mv$(sp))) ) { diff --git a/src/hir/path.hpp b/src/hir/path.hpp index 70d48cc0..a003b4ea 100644 --- a/src/hir/path.hpp +++ b/src/hir/path.hpp @@ -46,6 +46,7 @@ public: GenericPath(); GenericPath(::HIR::SimplePath sp); + GenericPath(::HIR::SimplePath sp, ::HIR::PathParams params); }; class Path @@ -60,6 +61,7 @@ public: TypeRefPtr type; GenericPath trait; ::std::string item; + PathParams params; }) ); @@ -68,6 +70,7 @@ private: public: Path(GenericPath _); + Path(TypeRefPtr type, GenericPath trait, ::std::string item, PathParams params); Path(SimplePath _); }; |