aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2023-04-30 02:54:22 -0400
committerPhilip Herron <philip.herron@embecosm.com>2023-05-17 16:12:25 +0000
commit9cbcb74d71d402bfa20d1a7def6a0eea5e57d525 (patch)
tree42e2af1b19f89bc7f4eaba43185474877d759110 /gcc
parentd98e5aaa62bb1dfdc3ce73d05d03eaa6c875164a (diff)
downloadgcc-9cbcb74d71d402bfa20d1a7def6a0eea5e57d525.zip
gcc-9cbcb74d71d402bfa20d1a7def6a0eea5e57d525.tar.gz
gcc-9cbcb74d71d402bfa20d1a7def6a0eea5e57d525.tar.bz2
Add AST::AttrInputMacro
gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add AttrInputMacro visitor. * ast/rust-ast-dump.h: (Dump::visit): Likewise. * ast/rust-ast-full-decls.h (class AttrInputMacro): New. * ast/rust-ast-collector.cc (TokenCollector::visit): Add and call out to AttrInputMacro visitor. * ast/rust-ast-collector.h: (TokenCollector::visit): Add AttrInputMacro visitor. * ast/rust-ast-visitor.h: (ASTVisitor::visit): Likewise. * ast/rust-ast.cc (AttrInputMacro::accept_vis): New. (AttrInputMacro::as_string): New. (AttrInputMacro::AttrInputMacro): New. (AttrInputMacro::operator=): New. * ast/rust-ast.h: (AttrInput::AttrInputType::MACRO): New. * ast/rust-expr.h (class AttrInputMacro): New. * checks/errors/rust-feature-gate.h: (FeatureGate::visit): Add AttrInputMacro visitor. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-cfg-strip.h: (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h: (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: (ASTLoweringBase::visit): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: (ResolverBase::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * resolve/rust-early-name-resolver.h: (EarlyNameResolver::visit): Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. (check_doc_attribute): Handle AttrInputType::MACRO. * util/rust-attributes.h: (AttributeChecker::visit): Add AttrInputMacro visitor. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-collector.cc11
-rw-r--r--gcc/rust/ast/rust-ast-collector.h1
-rw-r--r--gcc/rust/ast/rust-ast-dump.cc4
-rw-r--r--gcc/rust/ast/rust-ast-dump.h1
-rw-r--r--gcc/rust/ast/rust-ast-full-decls.h1
-rw-r--r--gcc/rust/ast/rust-ast-visitor.h1
-rw-r--r--gcc/rust/ast/rust-ast.cc24
-rw-r--r--gcc/rust/ast/rust-ast.h1
-rw-r--r--gcc/rust/ast/rust-expr.h42
-rw-r--r--gcc/rust/checks/errors/rust-feature-gate.h1
-rw-r--r--gcc/rust/expand/rust-cfg-strip.cc5
-rw-r--r--gcc/rust/expand/rust-cfg-strip.h1
-rw-r--r--gcc/rust/expand/rust-expand-visitor.cc6
-rw-r--r--gcc/rust/expand/rust-expand-visitor.h1
-rw-r--r--gcc/rust/hir/rust-ast-lower-base.cc3
-rw-r--r--gcc/rust/hir/rust-ast-lower-base.h1
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-base.cc4
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-base.h1
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver.cc4
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver.h1
-rw-r--r--gcc/rust/util/rust-attributes.cc5
-rw-r--r--gcc/rust/util/rust-attributes.h1
22 files changed, 120 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index afc1695..45a7609 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -170,6 +170,10 @@ TokenCollector::visit (Attribute &attrib)
visit (static_cast<AttrInputLiteral &> (attrib.get_attr_input ()));
break;
}
+ case AST::AttrInput::AttrInputType::MACRO: {
+ visit (static_cast<AttrInputMacro &> (attrib.get_attr_input ()));
+ break;
+ }
case AST::AttrInput::AttrInputType::META_ITEM: {
visit (static_cast<AttrInputMetaItemContainer &> (
attrib.get_attr_input ()));
@@ -840,6 +844,13 @@ TokenCollector::visit (AttrInputLiteral &literal)
}
void
+TokenCollector::visit (AttrInputMacro &macro)
+{
+ tokens.push_back (Rust::Token::make (EQUAL, Location ()));
+ visit (macro.get_macro ());
+}
+
+void
TokenCollector::visit (MetaItemLitExpr &item)
{
auto lit = item.get_literal ();
diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h
index d4712c2..e185797 100644
--- a/gcc/rust/ast/rust-ast-collector.h
+++ b/gcc/rust/ast/rust-ast-collector.h
@@ -149,6 +149,7 @@ private:
// rust-expr.h
void visit (LiteralExpr &expr);
void visit (AttrInputLiteral &attr_input);
+ void visit (AttrInputMacro &attr_input);
void visit (MetaItemLitExpr &meta_item);
void visit (MetaItemPathLit &meta_item);
void visit (BorrowExpr &expr);
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 0695b76..c00ed65 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -515,6 +515,10 @@ Dump::visit (AttrInputLiteral &)
{}
void
+Dump::visit (AttrInputMacro &)
+{}
+
+void
Dump::visit (MetaItemLitExpr &)
{}
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index f014ad1..a3deced 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -137,6 +137,7 @@ private:
// rust-expr.h
void visit (LiteralExpr &expr);
void visit (AttrInputLiteral &attr_input);
+ void visit (AttrInputMacro &attr_input);
void visit (MetaItemLitExpr &meta_item);
void visit (MetaItemPathLit &meta_item);
void visit (BorrowExpr &expr);
diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h
index 28bee14..64b9b3d 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -77,6 +77,7 @@ class QualifiedPathInType;
class ExprWithBlock;
class LiteralExpr;
class AttrInputLiteral;
+class AttrInputMacro;
class MetaItemLitExpr;
class MetaItemPathLit;
class OperatorExpr;
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index ccc8196..7b41863 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -66,6 +66,7 @@ public:
// rust-expr.h
virtual void visit (LiteralExpr &expr) = 0;
virtual void visit (AttrInputLiteral &attr_input) = 0;
+ virtual void visit (AttrInputMacro &attr_input) = 0;
virtual void visit (MetaItemLitExpr &meta_item) = 0;
virtual void visit (MetaItemPathLit &meta_item) = 0;
virtual void visit (BorrowExpr &expr) = 0;
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index ea267f4..9a53359 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -3266,6 +3266,12 @@ AttrInputMetaItemContainer::as_string () const
return str + ")";
}
+std::string
+AttrInputMacro::as_string () const
+{
+ return " = " + macro->as_string ();
+}
+
/* Override that calls the function recursively on all items contained within
* the module. */
void
@@ -4220,6 +4226,18 @@ BlockExpr::strip_tail_expr ()
}
}
+// needed here because "rust-expr.h" doesn't include "rust-macro.h"
+AttrInputMacro::AttrInputMacro (const AttrInputMacro &oth)
+ : macro (oth.macro->clone_macro_invocation_impl ())
+{}
+
+void
+AttrInputMacro::operator= (const AttrInputMacro &oth)
+{
+ macro = std::unique_ptr<MacroInvocation> (
+ oth.macro->clone_macro_invocation_impl ());
+}
+
/* Visitor implementations - these are short but inlining can't happen anyway
* due to virtual functions and I didn't want to make the ast header includes
* any longer than they already are. */
@@ -4267,6 +4285,12 @@ AttrInputLiteral::accept_vis (ASTVisitor &vis)
}
void
+AttrInputMacro::accept_vis (ASTVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
MetaItemLitExpr::accept_vis (ASTVisitor &vis)
{
vis.visit (*this);
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index ccc0925..56207bd 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -597,6 +597,7 @@ public:
enum AttrInputType
{
LITERAL,
+ MACRO,
META_ITEM,
TOKEN_TREE,
};
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 8f30965..2b23c24 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -139,6 +139,48 @@ protected:
}
};
+// Like an AttrInputLiteral, but stores a MacroInvocation
+class AttrInputMacro : public AttrInput
+{
+ std::unique_ptr<MacroInvocation> macro;
+
+public:
+ AttrInputMacro (std::unique_ptr<MacroInvocation> macro)
+ : macro (std::move (macro))
+ {}
+
+ AttrInputMacro (const AttrInputMacro &oth);
+
+ AttrInputMacro (AttrInputMacro &&oth) : macro (std::move (oth.macro)) {}
+
+ void operator= (const AttrInputMacro &oth);
+
+ void operator= (AttrInputMacro &&oth) { macro = std::move (oth.macro); }
+
+ std::string as_string () const override;
+
+ void accept_vis (ASTVisitor &vis) override;
+
+ // assuming this can't be a cfg predicate
+ bool check_cfg_predicate (const Session &) const override { return false; }
+
+ // assuming this is like AttrInputLiteral
+ bool is_meta_item () const override { return false; }
+
+ std::unique_ptr<MacroInvocation> &get_macro () { return macro; }
+
+ AttrInputType get_attr_input_type () const final override
+ {
+ return AttrInput::AttrInputType::MACRO;
+ }
+
+protected:
+ AttrInputMacro *clone_attr_input_impl () const override
+ {
+ return new AttrInputMacro (*this);
+ }
+};
+
/* literal expr only meta item inner - TODO possibly replace with inheritance of
* LiteralExpr itself? */
class MetaItemLitExpr : public MetaItemInner
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h
index 4bae8c0..5ce0571 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -48,6 +48,7 @@ public:
void visit (AST::QualifiedPathInType &path) override {}
void visit (AST::LiteralExpr &expr) override {}
void visit (AST::AttrInputLiteral &attr_input) override {}
+ void visit (AST::AttrInputMacro &attr_input) override {}
void visit (AST::MetaItemLitExpr &meta_item) override {}
void visit (AST::MetaItemPathLit &meta_item) override {}
void visit (AST::BorrowExpr &expr) override {}
diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc
index ae06785..f9d98c0 100644
--- a/gcc/rust/expand/rust-cfg-strip.cc
+++ b/gcc/rust/expand/rust-cfg-strip.cc
@@ -604,6 +604,11 @@ CfgStrip::visit (AST::AttrInputLiteral &)
// shouldn't require?
}
void
+CfgStrip::visit (AST::AttrInputMacro &)
+{
+ // shouldn't require?
+}
+void
CfgStrip::visit (AST::MetaItemLitExpr &)
{
// shouldn't require?
diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h
index 03b47b2..7235bfa 100644
--- a/gcc/rust/expand/rust-cfg-strip.h
+++ b/gcc/rust/expand/rust-cfg-strip.h
@@ -81,6 +81,7 @@ public:
void visit (AST::LiteralExpr &expr) override;
void visit (AST::AttrInputLiteral &) override;
+ void visit (AST::AttrInputMacro &) override;
void visit (AST::MetaItemLitExpr &) override;
void visit (AST::MetaItemPathLit &) override;
void visit (AST::BorrowExpr &expr) override;
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index a0cfd00..be1a7a4 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -324,6 +324,12 @@ ExpandVisitor::visit (AST::AttrInputLiteral &)
{}
void
+ExpandVisitor::visit (AST::AttrInputMacro &macro)
+{
+ rust_sorry_at (Location (), "macros in attributes not supported");
+}
+
+void
ExpandVisitor::visit (AST::MetaItemLitExpr &)
{}
diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h
index 7b24518..21677ec 100644
--- a/gcc/rust/expand/rust-expand-visitor.h
+++ b/gcc/rust/expand/rust-expand-visitor.h
@@ -166,6 +166,7 @@ public:
void visit (AST::LiteralExpr &expr) override;
void visit (AST::AttrInputLiteral &) override;
+ void visit (AST::AttrInputMacro &) override;
void visit (AST::MetaItemLitExpr &) override;
void visit (AST::MetaItemPathLit &) override;
void visit (AST::BorrowExpr &expr) override;
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc
index 38f0c3e..d7c6a3c 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -87,6 +87,9 @@ void
ASTLoweringBase::visit (AST::AttrInputLiteral &)
{}
void
+ASTLoweringBase::visit (AST::AttrInputMacro &)
+{}
+void
ASTLoweringBase::visit (AST::MetaItemLitExpr &)
{}
void
diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h
index 6bfbcfa..c8d2c27 100644
--- a/gcc/rust/hir/rust-ast-lower-base.h
+++ b/gcc/rust/hir/rust-ast-lower-base.h
@@ -94,6 +94,7 @@ public:
// rust-expr.h
virtual void visit (AST::LiteralExpr &expr);
virtual void visit (AST::AttrInputLiteral &attr_input);
+ virtual void visit (AST::AttrInputMacro &attr_input);
virtual void visit (AST::MetaItemLitExpr &meta_item);
virtual void visit (AST::MetaItemPathLit &meta_item);
virtual void visit (AST::BorrowExpr &expr);
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc
index 6caa9e3..3bd7e4a 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-base.cc
@@ -107,6 +107,10 @@ ResolverBase::visit (AST::AttrInputLiteral &)
{}
void
+ResolverBase::visit (AST::AttrInputMacro &)
+{}
+
+void
ResolverBase::visit (AST::MetaItemLitExpr &)
{}
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h
index 327ee70..bef7f3d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.h
+++ b/gcc/rust/resolve/rust-ast-resolve-base.h
@@ -48,6 +48,7 @@ public:
void visit (AST::QualifiedPathInType &);
void visit (AST::LiteralExpr &);
void visit (AST::AttrInputLiteral &);
+ void visit (AST::AttrInputMacro &);
void visit (AST::MetaItemLitExpr &);
void visit (AST::MetaItemPathLit &);
void visit (AST::BorrowExpr &);
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc
index 3c628d0..00f661f 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -222,6 +222,10 @@ EarlyNameResolver::visit (AST::AttrInputLiteral &)
{}
void
+EarlyNameResolver::visit (AST::AttrInputMacro &)
+{}
+
+void
EarlyNameResolver::visit (AST::MetaItemLitExpr &)
{}
diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h
index 9f1fc0d..44d1a18 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.h
+++ b/gcc/rust/resolve/rust-early-name-resolver.h
@@ -142,6 +142,7 @@ private:
virtual void visit (AST::QualifiedPathInType &path);
virtual void visit (AST::LiteralExpr &expr);
virtual void visit (AST::AttrInputLiteral &attr_input);
+ virtual void visit (AST::AttrInputMacro &attr_input);
virtual void visit (AST::MetaItemLitExpr &meta_item);
virtual void visit (AST::MetaItemPathLit &meta_item);
virtual void visit (AST::BorrowExpr &expr);
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 64f82c1..19fab50 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -163,6 +163,7 @@ check_doc_attribute (const AST::Attribute &attribute)
switch (attribute.get_attr_input ().get_attr_input_type ())
{
case AST::AttrInput::LITERAL:
+ case AST::AttrInput::MACRO:
case AST::AttrInput::META_ITEM:
break;
// FIXME: Handle them as well
@@ -281,6 +282,10 @@ AttributeChecker::visit (AST::AttrInputLiteral &)
{}
void
+AttributeChecker::visit (AST::AttrInputMacro &)
+{}
+
+void
AttributeChecker::visit (AST::MetaItemLitExpr &)
{}
diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h
index bd635f2..806ea78 100644
--- a/gcc/rust/util/rust-attributes.h
+++ b/gcc/rust/util/rust-attributes.h
@@ -113,6 +113,7 @@ private:
// rust-expr.h
void visit (AST::LiteralExpr &expr);
void visit (AST::AttrInputLiteral &attr_input);
+ void visit (AST::AttrInputMacro &attr_input);
void visit (AST::MetaItemLitExpr &meta_item);
void visit (AST::MetaItemPathLit &meta_item);
void visit (AST::BorrowExpr &expr);