diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-02-23 16:50:39 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:13:36 +0100 |
commit | a8a27b074f40cbac16af37db4c03a1128ce8f201 (patch) | |
tree | d072187d0bf5823cf013570946f0b33391a162b8 /gcc/rust/ast | |
parent | 8b8701243c280559fa8d2426bf8fb0b13d1f563a (diff) | |
download | gcc-a8a27b074f40cbac16af37db4c03a1128ce8f201.zip gcc-a8a27b074f40cbac16af37db4c03a1128ce8f201.tar.gz gcc-a8a27b074f40cbac16af37db4c03a1128ce8f201.tar.bz2 |
gccrs: ast: Add ExternalTypeItem node
gcc/rust/ChangeLog:
* ast/rust-item.h (class ExternalTypeItem): New class.
* ast/rust-ast.cc (ExternalTypeItem::as_string): New function.
(ExternalTypeItem::accept_vis): Likewise.
* ast/rust-ast-full-decls.h (class ExternalTypeItem): Declare class.
* ast/rust-ast-dump.cc (Dump::visit): Add base visitor for ExternalTypeItem.
* ast/rust-ast-dump.h: Likewise.
* ast/rust-ast-visitor.h: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Likewise.
* expand/rust-attribute-visitor.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* util/rust-attributes.h: Likewise.
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.cc | 4 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.h | 1 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-full-decls.h | 1 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-visitor.h | 1 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.cc | 16 | ||||
-rw-r--r-- | gcc/rust/ast/rust-item.h | 75 |
6 files changed, 98 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index a581c02..a5fce67 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1433,6 +1433,10 @@ Dump::visit (TraitImpl &impl) } void +Dump::visit (ExternalTypeItem &type) +{} + +void Dump::visit (ExternalStaticItem &) {} diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index ea3e6f3..a6adab9 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -251,6 +251,7 @@ private: void visit (Trait &trait); void visit (InherentImpl &impl); void visit (TraitImpl &impl); + void visit (ExternalTypeItem &item); void visit (ExternalStaticItem &item); void visit (ExternalFunctionItem &item); void visit (ExternBlock &block); diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 96a6f22..352c1b9 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -203,6 +203,7 @@ class Impl; class InherentImpl; class TraitImpl; class ExternalItem; +class ExternalTypeItem; class ExternalStaticItem; struct NamedFunctionParam; class ExternalFunctionItem; diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index 9cde911..776e1e2 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -161,6 +161,7 @@ public: virtual void visit (InherentImpl &impl) = 0; virtual void visit (TraitImpl &impl) = 0; // virtual void visit(ExternalItem& item) = 0; + virtual void visit (ExternalTypeItem &type) = 0; virtual void visit (ExternalStaticItem &item) = 0; virtual void visit (ExternalFunctionItem &item) = 0; virtual void visit (ExternBlock &block) = 0; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 6692505..13d31cf 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -3407,6 +3407,16 @@ EnumItemDiscriminant::as_string () const } std::string +ExternalTypeItem::as_string () const +{ + auto str = append_attributes (outer_attrs, OUTER); + + str += "type " + item_name + ";"; + + return str; +} + +std::string ExternalStaticItem::as_string () const { // outer attributes @@ -5493,6 +5503,12 @@ TraitImpl::accept_vis (ASTVisitor &vis) } void +ExternalTypeItem::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void ExternalStaticItem::accept_vis (ASTVisitor &vis) { vis.visit (*this); diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 4385323..2abf781 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -3907,6 +3907,81 @@ protected: }; #endif +// A foreign type defined outside the current crate. +// https://rust-lang.github.io/rfcs/1861-extern-types.html +class ExternalTypeItem : public ExternalItem +{ + std::vector<Attribute> outer_attrs; + + Visibility visibility; + Identifier item_name; + Location locus; + + bool marked_for_strip; + +public: + ExternalTypeItem (Identifier item_name, Visibility vis, + std::vector<Attribute> outer_attrs, Location locus) + : ExternalItem (), outer_attrs (std::move (outer_attrs)), visibility (vis), + item_name (std::move (item_name)), locus (locus), marked_for_strip (false) + {} + + ExternalTypeItem (ExternalTypeItem const &other) + : outer_attrs (other.outer_attrs), visibility (other.visibility), + item_name (other.item_name), locus (other.locus), + marked_for_strip (other.marked_for_strip) + { + node_id = other.node_id; + } + + ExternalTypeItem &operator= (ExternalTypeItem const &other) + { + node_id = other.node_id; + outer_attrs = other.outer_attrs; + visibility = other.visibility; + item_name = other.item_name; + locus = other.locus; + marked_for_strip = other.marked_for_strip; + + return *this; + } + + // move constructors + ExternalTypeItem (ExternalTypeItem &&other) = default; + ExternalTypeItem &operator= (ExternalTypeItem &&other) = default; + + std::string as_string () const override; + + void accept_vis (ASTVisitor &vis) override; + + // Returns whether item has outer attributes. + bool has_outer_attrs () const { return !outer_attrs.empty (); } + + // Returns whether item has non-default visibility. + bool has_visibility () const { return !visibility.is_error (); } + + Location get_locus () const { return locus; } + + void mark_for_strip () override { marked_for_strip = true; }; + bool is_marked_for_strip () const override { return marked_for_strip; }; + + // TODO: this mutable getter seems really dodgy. Think up better way. + std::vector<Attribute> &get_outer_attrs () { return outer_attrs; } + const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; } + + Identifier get_identifier () const { return item_name; } + + const Visibility &get_visibility () const { return visibility; } + +protected: + /* Use covariance to implement clone function as returning this object + * rather than base */ + ExternalTypeItem *clone_external_item_impl () const override + { + return new ExternalTypeItem (*this); + } +}; + // A static item used in an extern block class ExternalStaticItem : public ExternalItem { |