aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/rust-ast-lower.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/hir/rust-ast-lower.cc')
-rw-r--r--gcc/rust/hir/rust-ast-lower.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index aac6ee5..45081af 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -609,5 +609,84 @@ ASTLoweringBase::lower_qualifiers (const AST::FunctionQualifiers &qualifiers)
has_extern, extern_abi);
}
+void
+ASTLoweringBase::handle_outer_attributes (const HIR::Item &item)
+{
+ for (const auto &attr : item.get_outer_attrs ())
+ {
+ const auto &str_path = attr.get_path ().as_string ();
+ if (!is_known_attribute (str_path))
+ {
+ rust_error_at (attr.get_locus (), "unknown attribute");
+ continue;
+ }
+
+ bool is_lang_item = str_path.compare ("lang") == 0
+ && attr.has_attr_input ()
+ && attr.get_attr_input ().get_attr_input_type ()
+ == AST::AttrInput::AttrInputType::LITERAL;
+
+ if (is_lang_item)
+ handle_lang_item_attribute (item, attr);
+ else if (!attribute_handled_in_another_pass (str_path))
+ {
+ rust_error_at (attr.get_locus (), "unhandled attribute: [%s]",
+ attr.get_path ().as_string ().c_str ());
+ }
+ }
+}
+
+void
+ASTLoweringBase::handle_lang_item_attribute (const HIR::Item &item,
+ const AST::Attribute &attr)
+{
+ auto &literal = static_cast<AST::AttrInputLiteral &> (attr.get_attr_input ());
+ const auto &lang_item_type_str = literal.get_literal ().as_string ();
+ auto lang_item_type = Analysis::RustLangItem::Parse (lang_item_type_str);
+ if (lang_item_type == Analysis::RustLangItem::ItemType::UNKNOWN)
+ {
+ rust_error_at (attr.get_locus (), "unknown lang item");
+ return;
+ }
+ mappings->insert_lang_item (lang_item_type,
+ item.get_mappings ().get_defid ());
+}
+
+bool
+ASTLoweringBase::is_known_attribute (const std::string &attribute_path)
+{
+ if (attribute_path.compare ("inline") == 0)
+ return true;
+ else if (attribute_path.compare ("cfg") == 0)
+ return true;
+ else if (attribute_path.compare ("cfg_attr") == 0)
+ return true;
+ else if (attribute_path.compare ("allow") == 0)
+ return true;
+ else if (attribute_path.compare ("lang") == 0)
+ return true;
+
+ return false;
+}
+
+bool
+ASTLoweringBase::attribute_handled_in_another_pass (
+ const std::string &attribute_path)
+{
+ // handled during code-generation
+ if (attribute_path.compare ("inline") == 0)
+ return true;
+
+ // handled during previous expansion pass
+ else if (attribute_path.compare ("cfg") == 0)
+ return true;
+ else if (attribute_path.compare ("cfg_attr") == 0)
+ return true;
+ else if (attribute_path.compare ("allow") == 0)
+ return true;
+
+ return false;
+}
+
} // namespace HIR
} // namespace Rust