summaryrefslogtreecommitdiff
path: root/src/hir
diff options
context:
space:
mode:
Diffstat (limited to 'src/hir')
-rw-r--r--src/hir/from_ast.cpp6
-rw-r--r--src/hir/hir.cpp31
-rw-r--r--src/hir/hir.hpp3
3 files changed, 14 insertions, 26 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 3f297e89..6c873e1e 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -1028,6 +1028,12 @@ public:
LowerHIR_Module_Impls(crate.m_root_module, rv);
+ auto sp = Span();
+ for( const auto& lang_item_path : crate.m_lang_items )
+ {
+ rv.m_lang_items.insert( ::std::make_pair(lang_item_path.first, LowerHIR_SimplePath(sp, lang_item_path.second)) );
+ }
+
// Set all pointers in the HIR to the correct (now fixed) locations
IndexVisitor(rv).visit_crate( rv );
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp
index 1dce63f8..d9f85a53 100644
--- a/src/hir/hir.cpp
+++ b/src/hir/hir.cpp
@@ -153,33 +153,12 @@ bool ::HIR::MarkerImpl::matches_type(const ::HIR::TypeRef& type, ::HIR::t_cb_res
const ::HIR::SimplePath& ::HIR::Crate::get_lang_item_path(const Span& sp, const char* name) const
{
- if( ::std::strcmp(name, "index") == 0 ) {
- static ::HIR::SimplePath lang_index { "", {"ops", "Index"} };
- return lang_index;
- }
- else if( ::std::strcmp(name, "unsize") == 0 ) {
- static ::HIR::SimplePath lang_unsize { "", {"marker", "Unsize"} };
- return lang_unsize;
- }
- else if( ::std::strcmp(name, "add") == 0 ) {
- static ::HIR::SimplePath lang_path { "", {"ops", "Add"} };
- return lang_path;
- }
- else if( ::std::strcmp(name, "ord") == 0 ) {
- static ::HIR::SimplePath lang_path { "", {"cmp", "PartialOrd"} };
- return lang_path;
- }
- else if( ::std::strcmp(name, "eq") == 0 ) {
- static ::HIR::SimplePath lang_path { "", {"cmp", "PartialEq"} };
- return lang_path;
- }
- else if( ::std::strcmp(name, "fn_once") == 0 ) {
- static ::HIR::SimplePath lang_path { "", {"ops", "FnOnce"} };
- return lang_path;
- }
- else {
- ERROR(sp, E0000, "Unknown language item '" << name << "' encountered");
+ // TODO: have map stored in crate populated by (or from) the #[lang] attribute handler
+ auto it = this->m_lang_items.find( name );
+ if( it == this->m_lang_items.end() ) {
+ ERROR(sp, E0000, "Undefined language item '" << name << "' required");
}
+ return it->second;
}
const ::HIR::TypeItem& ::HIR::Crate::get_typeitem_by_path(const Span& sp, const ::HIR::SimplePath& path) const
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index 3447aaa0..a938579a 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -263,6 +263,9 @@ public:
/// Macros exported by this crate
::std::unordered_map< ::std::string, ::MacroRules > m_exported_macros;
+ /// Language items avaliable through this crate (includes ones from loaded externs)
+ ::std::unordered_map< ::std::string, ::HIR::SimplePath> m_lang_items;
+
const ::HIR::SimplePath& get_lang_item_path(const Span& sp, const char* name) const;
const ::HIR::TypeItem& get_typeitem_by_path(const Span& sp, const ::HIR::SimplePath& path) const;