From f6cdae89d1bcef7610471a6181c7cf2b41cae9af Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Thu, 26 Dec 2024 22:09:46 +0000 Subject: [PATCH] gccrs: ast-builder: Add new methods around type paths. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc: New functions. * ast/rust-ast-builder.h: Declare them. --- gcc/rust/ast/rust-ast-builder.cc | 57 ++++++++++++++++++++++++++++++-- gcc/rust/ast/rust-ast-builder.h | 13 +++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc index 55d59c94b52..fe80924fece 100644 --- a/gcc/rust/ast/rust-ast-builder.cc +++ b/gcc/rust/ast/rust-ast-builder.cc @@ -23,6 +23,7 @@ #include "rust-expr.h" #include "rust-path.h" #include "rust-item.h" +#include "rust-path.h" #include "rust-token.h" namespace Rust { @@ -101,12 +102,27 @@ Builder::type_path_segment (std::string seg) const } std::unique_ptr -Builder::generic_type_path_segment (std::string seg, GenericArgs args) const +Builder::type_path_segment (LangItem::Kind lang_item) const +{ + return std::unique_ptr ( + new TypePathSegment (lang_item, loc)); +} + +std::unique_ptr +Builder::type_path_segment_generic (std::string seg, GenericArgs args) const { return std::unique_ptr ( new TypePathSegmentGeneric (PathIdentSegment (seg, loc), false, args, loc)); } +std::unique_ptr +Builder::type_path_segment_generic (LangItem::Kind lang_item, + GenericArgs args) const +{ + return std::unique_ptr ( + new TypePathSegmentGeneric (lang_item, args, loc)); +} + std::unique_ptr Builder::single_type_path (std::string type) const { @@ -116,15 +132,52 @@ Builder::single_type_path (std::string type) const return std::unique_ptr (new TypePath (std::move (segments), loc)); } +std::unique_ptr +Builder::single_type_path (LangItem::Kind lang_item) const +{ + return std::unique_ptr (new TypePath (lang_item, {}, loc)); +} + std::unique_ptr Builder::single_generic_type_path (std::string type, GenericArgs args) const { auto segments = std::vector> (); - segments.emplace_back (generic_type_path_segment (type, args)); + segments.emplace_back (type_path_segment_generic (type, args)); return std::unique_ptr (new TypePath (std::move (segments), loc)); } +std::unique_ptr +Builder::single_generic_type_path (LangItem::Kind lang_item, + GenericArgs args) const +{ + auto segments = std::vector> (); + segments.emplace_back (type_path_segment_generic (lang_item, args)); + + return std::unique_ptr (new TypePath (std::move (segments), loc)); +} + +TypePath +Builder::type_path (std::unique_ptr &&segment) const +{ + auto segments = std::vector> (); + segments.emplace_back (std::move (segment)); + + return TypePath (std::move (segments), loc); +} + +TypePath +Builder::type_path (std::string type) const +{ + return type_path (type_path_segment (type)); +} + +TypePath +Builder::type_path (LangItem::Kind lang_item) const +{ + return type_path (type_path_segment (lang_item)); +} + PathInExpression Builder::path_in_expression (std::vector &&segments) const { diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h index 36c0da2cff2..624cd715181 100644 --- a/gcc/rust/ast/rust-ast-builder.h +++ b/gcc/rust/ast/rust-ast-builder.h @@ -114,16 +114,27 @@ public: /* And similarly for type path segments */ std::unique_ptr type_path_segment (std::string seg) const; + std::unique_ptr + type_path_segment (LangItem::Kind lang_item) const; std::unique_ptr - generic_type_path_segment (std::string seg, GenericArgs args) const; + type_path_segment_generic (std::string seg, GenericArgs args) const; + std::unique_ptr + type_path_segment_generic (LangItem::Kind lang_item, GenericArgs args) const; /* Create a Type from a single string - the most basic kind of type in our AST */ std::unique_ptr single_type_path (std::string type) const; + std::unique_ptr single_type_path (LangItem::Kind lang_item) const; std::unique_ptr single_generic_type_path (std::string type, GenericArgs args) const; + std::unique_ptr single_generic_type_path (LangItem::Kind lang_item, + GenericArgs args) const; + + TypePath type_path (std::unique_ptr &&segment) const; + TypePath type_path (std::string type) const; + TypePath type_path (LangItem::Kind lang_item) const; /** * Create a path in expression from multiple segments (`Clone::clone`). You -- 2.47.2