/* * MRustC - Rust Compiler * - By John Hodge (Mutabah/thePowersGang) * * synexts/lang_item.cpp * - Binds language items to #[lang_item] tagged items */ #include #include "../common.hpp" #include "../ast/ast.hpp" #include "../ast/crate.hpp" void handle_lang_item(const Span& sp, AST::Crate& crate, const AST::Path& path, const ::std::string& name, AST::eItemType type) { if(name == "phantom_fn") { // - Just save path } else if( name == "send" ) { // Don't care, Send is fully library in mrustc // - Needed for `static` } else if( name == "sync" ) { // Don't care, Sync is fully library in mrustc // - Needed for `static` } else if( name == "sized" ) { DEBUG("Bind 'sized' to " << path); } else if( name == "copy" ) { DEBUG("Bind 'copy' to " << path); } // ops traits else if( name == "drop" ) { DEBUG("Bind '"<second; if( path != other_path ) { // HACK: Anon modules get visited twice, so can lead to duplicate annotations ERROR(sp, E0000, "Duplicate definition of language item '" << name << "' - " << other_path << " and " << path); } } } class Decorator_LangItem: public ExpandDecorator { public: AttrStage stage() const override { return AttrStage::Post; } void handle(const Span& sp, const AST::MetaItem& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override { TU_MATCH_DEF(::AST::Item, (i), (e), ( TODO(sp, "Unknown item type " << i.tag_str() << " with #["<second; ERROR(sp, E0000, "Duplicate definition of #[main] - " << other_path << " and " << path); } ) else { ERROR(sp, E0000, "#[main] on non-function " << path); } } }; class Decorator_Start: public ExpandDecorator { public: AttrStage stage() const override { return AttrStage::Post; } void handle(const Span& sp, const AST::MetaItem& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override { TU_IFLET(::AST::Item, i, Function, e, auto rv = crate.m_lang_items.insert(::std::make_pair( ::std::string("mrustc-start"), ::AST::Path(path) )); if( !rv.second ) { const auto& other_path = rv.first->second; ERROR(sp, E0000, "Duplicate definition of #[start] - " << other_path << " and " << path); } ) else { ERROR(sp, E0000, "#[start] on non-function " << path); } } }; STATIC_DECORATOR("lang", Decorator_LangItem) STATIC_DECORATOR("main", Decorator_Main); STATIC_DECORATOR("start", Decorator_Start);