summaryrefslogtreecommitdiff
path: root/src/hir/hir.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-06-09 09:54:57 +0800
committerJohn Hodge <tpg@mutabah.net>2016-06-09 09:54:57 +0800
commit502cc9c8dc1941877b35e45d742a3e36264671ca (patch)
tree5ff1f49577673035d7e4d9ff951884e6e979c3f1 /src/hir/hir.cpp
parent7685ecc25ad47d369ea250d36c71bae4cec2d9a1 (diff)
downloadmrust-502cc9c8dc1941877b35e45d742a3e36264671ca.tar.gz
HIR - Save and use paths to #[lang] items
Diffstat (limited to 'src/hir/hir.cpp')
-rw-r--r--src/hir/hir.cpp31
1 files changed, 5 insertions, 26 deletions
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