diff options
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.cc | 12 | ||||
-rw-r--r-- | gcc/rust/hir/rust-hir-dump.cc | 11 | ||||
-rw-r--r-- | gcc/rust/hir/rust-hir-dump.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr-abstract.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.cc | 36 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 36 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-full-decls.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-visitor.cc | 6 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-visitor.h | 5 |
9 files changed, 107 insertions, 2 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index 31126a8..e9c9acc 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -1059,8 +1059,16 @@ ASTLoweringExpr::visit (AST::FormatArgs &fmt) void ASTLoweringExpr::visit (AST::OffsetOf &offset_of) { - // FIXME: Implement HIR::OffsetOf node and const evaluation - rust_unreachable (); + auto type = std::unique_ptr<Type> ( + ASTLoweringType::translate (offset_of.get_type ())); + + auto crate_num = mappings.get_current_crate (); + Analysis::NodeMapping mapping (crate_num, offset_of.get_node_id (), + mappings.get_next_hir_id (crate_num), + mappings.get_next_localdef_id (crate_num)); + + translated = new HIR::OffsetOf (std::move (type), offset_of.get_field (), + mapping, offset_of.get_locus ()); } } // namespace HIR diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 3d61de9..afee7b4 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -1603,6 +1603,17 @@ Dump::visit (LlvmInlineAsm &e) {} void +Dump::visit (OffsetOf &e) +{ + begin ("OffsetOf"); + + put_field ("type", e.get_type ().as_string ()); + put_field ("field", e.get_field ()); + + end ("OffsetOf"); +} + +void Dump::visit (TypeParam &e) { begin ("TypeParam"); diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h index 8c39f48..3e6ae30 100644 --- a/gcc/rust/hir/rust-hir-dump.h +++ b/gcc/rust/hir/rust-hir-dump.h @@ -169,6 +169,7 @@ private: virtual void visit (AsyncBlockExpr &) override; virtual void visit (InlineAsm &) override; virtual void visit (LlvmInlineAsm &) override; + virtual void visit (OffsetOf &) override; virtual void visit (TypeParam &) override; virtual void visit (ConstGenericParam &) override; diff --git a/gcc/rust/hir/tree/rust-hir-expr-abstract.h b/gcc/rust/hir/tree/rust-hir-expr-abstract.h index 8272a828..371daa8 100644 --- a/gcc/rust/hir/tree/rust-hir-expr-abstract.h +++ b/gcc/rust/hir/tree/rust-hir-expr-abstract.h @@ -74,6 +74,7 @@ public: Path, InlineAsm, LlvmInlineAsm, + OffsetOf, }; BaseKind get_hir_kind () override final { return Node::BaseKind::EXPR; } diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc index 8544ed67..14786ad 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.cc +++ b/gcc/rust/hir/tree/rust-hir-expr.cc @@ -1526,5 +1526,41 @@ InlineAsm::InlineAsm (location_t locus, bool is_global_asm, clobber_abi (std::move (clobber_abi)), options (std::move (options)) {} +OffsetOf & +OffsetOf::operator= (const OffsetOf &other) +{ + ExprWithoutBlock::operator= (other); + + type = other.type->clone_type (); + field = other.field; + loc = other.loc; + + return *this; +} + +ExprWithoutBlock * +OffsetOf::clone_expr_without_block_impl () const +{ + return new OffsetOf (*this); +} + +std::string +OffsetOf::as_string () const +{ + return "OffsetOf(" + type->as_string () + ", " + field.as_string () + ")"; +} + +void +OffsetOf::accept_vis (HIRExpressionVisitor &vis) +{ + vis.visit (*this); +} + +void +OffsetOf::accept_vis (HIRFullVisitor &vis) +{ + vis.visit (*this); +} + } // namespace HIR } // namespace Rust diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 64d01ee..61e3590 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -3236,6 +3236,42 @@ public: AST::AttrVec outer_attribs = AST::AttrVec ()); }; +class OffsetOf : public ExprWithoutBlock +{ +public: + OffsetOf (std::unique_ptr<Type> &&type, Identifier field, + Analysis::NodeMapping mappings, location_t loc) + : ExprWithoutBlock (mappings), type (std::move (type)), field (field), + loc (loc) + {} + + OffsetOf (const OffsetOf &other) + : ExprWithoutBlock (other), type (other.type->clone_type ()), + field (other.field), loc (other.loc) + {} + + OffsetOf &operator= (const OffsetOf &other); + + ExprWithoutBlock *clone_expr_without_block_impl () const override; + std::string as_string () const override; + + void accept_vis (HIRExpressionVisitor &vis) override; + void accept_vis (HIRFullVisitor &vis) override; + + ExprType get_expression_type () const override { return ExprType::OffsetOf; } + + location_t get_locus () const override { return loc; } + + Type &get_type () { return *type; } + const Type &get_type () const { return *type; } + const Identifier &get_field () const { return field; } + +private: + std::unique_ptr<Type> type; + Identifier field; + location_t loc; +}; + struct LlvmOperand { std::string constraint; diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 2905117..57b3a4d 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -128,6 +128,7 @@ class InlineAsmRegClass; class InlineAsmOperand; class InlineAsm; class LlvmInlineAsm; +class OffsetOf; // rust-stmt.h class EmptyStmt; diff --git a/gcc/rust/hir/tree/rust-hir-visitor.cc b/gcc/rust/hir/tree/rust-hir-visitor.cc index 77b96e5..c77300a 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.cc +++ b/gcc/rust/hir/tree/rust-hir-visitor.cc @@ -604,6 +604,12 @@ DefaultHIRVisitor::walk (LlvmInlineAsm &expr) } void +DefaultHIRVisitor::walk (OffsetOf &expr) +{ + expr.get_type ().accept_vis (*this); +} + +void DefaultHIRVisitor::walk (TypeParam ¶m) { visit_outer_attrs (param); diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h index 544cf51..7996260 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.h +++ b/gcc/rust/hir/tree/rust-hir-visitor.h @@ -88,6 +88,7 @@ public: virtual void visit (AsyncBlockExpr &expr) = 0; virtual void visit (InlineAsm &expr) = 0; virtual void visit (LlvmInlineAsm &expr) = 0; + virtual void visit (OffsetOf &expr) = 0; virtual void visit (TypeParam ¶m) = 0; virtual void visit (ConstGenericParam ¶m) = 0; virtual void visit (LifetimeWhereClauseItem &item) = 0; @@ -254,6 +255,7 @@ public: virtual void visit (AsyncBlockExpr &node) override { walk (node); } virtual void visit (InlineAsm &node) override { walk (node); } virtual void visit (LlvmInlineAsm &node) override { walk (node); } + virtual void visit (OffsetOf &node) override { walk (node); } virtual void visit (TypeParam &node) override { walk (node); } virtual void visit (ConstGenericParam &node) override { walk (node); } virtual void visit (LifetimeWhereClauseItem &node) override { walk (node); } @@ -392,6 +394,7 @@ protected: virtual void walk (AsyncBlockExpr &) final; virtual void walk (InlineAsm &) final; virtual void walk (LlvmInlineAsm &) final; + virtual void walk (OffsetOf &) final; virtual void walk (TypeParam &) final; virtual void walk (ConstGenericParam &) final; virtual void walk (LifetimeWhereClauseItem &) final; @@ -531,6 +534,7 @@ public: virtual void visit (AsyncBlockExpr &) override {} virtual void visit (InlineAsm &) override {} virtual void visit (LlvmInlineAsm &) override {} + virtual void visit (OffsetOf &) override {} virtual void visit (TypeParam &) override {} virtual void visit (ConstGenericParam &) override {} @@ -754,6 +758,7 @@ public: virtual void visit (IfExpr &expr) = 0; virtual void visit (IfExprConseqElse &expr) = 0; virtual void visit (InlineAsm &expr) = 0; + virtual void visit (OffsetOf &expr) = 0; virtual void visit (LlvmInlineAsm &expr) = 0; virtual void visit (MatchExpr &expr) = 0; virtual void visit (AwaitExpr &expr) = 0; |