Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[upstream] 2024-04-23 #2965

Open
wants to merge 125 commits into
base: gcc-patch-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
5f9e882
Rust: Make 'tree'-level 'MAIN_NAME_P' work
tschwinge Apr 12, 2023
8319fa7
gccrs: Fix false positive for top-level AltPattern
powerboat9 Feb 18, 2024
a58f7df
gccrs: minor cleanup in langhook.type_for_mode
dkm Feb 19, 2024
473feb0
gccrs: fmt: Start working on format_args!() parser
CohenArthur Nov 9, 2023
6fef4d6
gccrs: libgrust: Add format_parser library
CohenArthur Apr 23, 2024
2340894
gccrs: Add 'gcc/rust/Make-lang.in:LIBFORMAT_PARSER'
tschwinge Feb 28, 2024
7e1d64a
gccrs: libgrust: Vendor Rust dependencies
CohenArthur Apr 9, 2024
96a5c5b
Rust: Don't cache 'libformat_parser.a'
tschwinge Feb 28, 2024
acf10f8
Rust: Move 'libformat_parser' build into the GCC build directory
tschwinge Feb 28, 2024
8e284d0
Rust: Move 'libformat_parser' build into libgrust
tschwinge Feb 29, 2024
8647682
gccrs: libformat_parser: Add FFI safe interface
CohenArthur Jan 29, 2024
6a7d0e5
gccrs: libformat_parser: Start experimenting with cbindgen
CohenArthur Jan 29, 2024
d633214
gccrs: libformat_parser: Update header and remove old interface
CohenArthur Jan 29, 2024
6e04e69
gccrs: libformat_parser: Send boxed values across FFI properly
CohenArthur Jan 30, 2024
d72a8e9
gccrs: format_args: Parse format string properly
CohenArthur Jan 30, 2024
827231a
gccrs: format_args: Parse entire token invocation
CohenArthur Feb 7, 2024
0f96685
gccrs: rust-fmt: Store parsed string in Pieces struct
CohenArthur Feb 13, 2024
f7dafa7
gccrs: libformat_parser: Fix Rust warnings.
CohenArthur Feb 15, 2024
433fbb1
gccrs: format-parser: Add `is_some_and` method for Option<T>
CohenArthur Feb 26, 2024
53ccef0
gccrs: Adjust error checks to match name resolution 2.0
powerboat9 Feb 23, 2024
5d30562
gccrs: Fix small FixMe task in rust macro builtins
badumbatish Feb 23, 2024
3c04d95
gccrs: lang-items: Cleanup parsing and lookups of lang items.
CohenArthur Feb 27, 2024
bf6d216
gccrs: lang-items: Make lang items enum stronger, rename class, clean…
CohenArthur Feb 27, 2024
cac2e97
gccrs: extern-types: Declare external types in name resolver.
CohenArthur Feb 20, 2024
26e7729
gccrs: hir: Add ExternalTypeItem node
CohenArthur Feb 20, 2024
07fc785
gccrs: extern-types: Lower to HIR::ExternalTypeItem properly
CohenArthur Feb 20, 2024
2509160
gccrs: Make DefaultResolver visit more of the AST
powerboat9 Feb 28, 2024
194883f
gccrs: ast: Add base nodes for FormatArgs
CohenArthur Feb 15, 2024
6d8765d
gccrs: macro-builtins: Add newline generic format_args!() handler
CohenArthur Feb 16, 2024
d9fa415
gccrs: parser: Add peek(n) method to parser
CohenArthur Feb 19, 2024
68cb878
gccrs: format-args: Fix Rust interface and add input parsing.
CohenArthur Feb 16, 2024
5151b28
gccrs: lower: Add base for lowering FormatArgs nodes
CohenArthur Feb 22, 2024
3f4374c
gccrs: format-args: Add documentation for future expansion of function
CohenArthur Mar 1, 2024
3996459
gccrs: Add error emitting when we can't resolve id expr
badumbatish Mar 1, 2024
38aa479
gccrs: Add curly brackets, formatted clang
badumbatish Mar 1, 2024
ebbf7be
gccrs: Ensure TupleStructPattern and TuplePattern have items
powerboat9 Feb 27, 2024
8c64261
gccrs: Clean BiMap to use tl::optional for lookups
srj31 Mar 1, 2024
709db9b
gccrs: Add support for external functions
0xn4utilus Feb 25, 2024
c1ccc7c
gccrs: Add get_pattern_kind to Pattern
0xn4utilus Feb 25, 2024
bbc1dfc
gccrs: Unify ASTValidation::visit for ExternalFunctionItem and Function
0xn4utilus Feb 25, 2024
293ac1b
gccrs: Update resolver to use `AST::Function` instead of `AST::Extern…
0xn4utilus Feb 25, 2024
b2a6d97
gccrs: Remove dead code associated with `AST::ExternalFunctionItem`
0xn4utilus Feb 28, 2024
240b7c8
gccrs: Placate clang-format re 'gcc/rust/backend/rust-tree.cc'
tschwinge Mar 12, 2024
68ec9f4
gccrs: Replace reference to unique pointer with reference
P-E-P Feb 21, 2024
e01c9f4
gccrs: Replace unique_ptr references with references
P-E-P Feb 22, 2024
f15d40d
gccrs: macro: Use MacroInvocation's node_id in ExternalItem constructor.
CohenArthur Mar 19, 2024
5ed71ad
gccrs: format-args: Add base for expanding FormatArgs nodes
CohenArthur Feb 29, 2024
9b540c4
gccrs: format-args: Start storing string in Rust memory
CohenArthur Feb 22, 2024
444b41b
gccrs: format-args: Add basic expansion of unnamed Display::fmt argum…
CohenArthur Feb 29, 2024
d0e8bf9
gccrs: format-args: Add basic test case
CohenArthur Feb 29, 2024
302ad5d
gccrs: format-args: Only pass the format string to the parser.
CohenArthur Mar 7, 2024
54d8f97
gccrs: TyTy: add common SubstitutionRef API
jdupak Feb 2, 2024
d8cd08d
gccrs: TyTy: Variance analysis module
jdupak Feb 2, 2024
a7b1a89
gccrs: TyTy: Collect variance info from types
jdupak Feb 2, 2024
8c0b650
gccrs: Store visibility properly in ExternalTypeItem
badumbatish Mar 9, 2024
01c16d7
gccrs: Fix typo
GuillaumeGomez Mar 5, 2024
98e0a66
gccrs: Split up rust-macro-builtins.cc
badumbatish Feb 25, 2024
6e8b125
gccrs: Placate clang-format re 'gcc/rust/lex/rust-lex.cc'
tschwinge Mar 24, 2024
9bf8024
gccrs: nr2.0: Add new ImmutableNameResolutionCtx class.
CohenArthur Aug 24, 2023
c3b40bc
gccrs: sesh: Add late name resolution 2.0
CohenArthur Aug 4, 2023
b45c201
gccrs: session-manager: Dump name resolution pass.
CohenArthur Aug 23, 2023
b6d9d2b
gccrs: session manager: Init Immutable name resolver.
CohenArthur Aug 24, 2023
40d6a51
gccrs: nr2.0: Add lookup of resolved nodes.
CohenArthur Aug 24, 2023
9403b42
gccrs: typecheck: Start using nr2.0 properly
CohenArthur Aug 24, 2023
7e135a1
gccrs: backend: Use new name resolver where necessary
CohenArthur Aug 25, 2023
8de755b
gccrs: nr2.0: Start using newtype pattern for Usage and Declaration
CohenArthur Sep 14, 2023
0374faf
gccrs: late: Setup builtin types properly, change Rib API
CohenArthur Aug 28, 2023
c7d64f6
gccrs: Fix duplicate detection
P-E-P Sep 14, 2023
0215786
gccrs: Emit error on identical use declarations
P-E-P Sep 15, 2023
37bde12
gccrs: Change error message on unresolved import
P-E-P Mar 24, 2024
924df99
gccrs: Prevent error emission on resolver reentry
P-E-P Sep 18, 2023
a39fa56
gccrs: late: Add bool builtin type
CohenArthur Nov 8, 2023
df420c8
gccrs: Add modules to type namespace
P-E-P Jan 8, 2024
77bb474
gccrs: Add name resolution for on globbing use decl
P-E-P Jan 9, 2024
fc0d652
gccrs: Shape up name resolver for normal direct calls
P-E-P Jan 10, 2024
318837c
gccrs: Add call to globbing visitor
P-E-P Jan 15, 2024
f1af602
gccrs: Make globbing definition shadowable by default
P-E-P Jan 15, 2024
6eac53f
gccrs: Add support for ambiguous use declarations
P-E-P Jan 16, 2024
5570a2a
gccrs: Add tuple struct constructor to value namespace
P-E-P Jan 17, 2024
04da068
gccrs: Change error message to match test
P-E-P Jan 17, 2024
6e81ad0
gccrs: Visit function return type in default resolver
P-E-P Jan 24, 2024
97bb632
gccrs: Visit constant item type in default resolver
P-E-P Jan 24, 2024
5f68df1
gccrs: Raw pointer type visitor didn't require overload
P-E-P Jan 24, 2024
44af38c
gccrs: Values shall be inserted in the value namespace
P-E-P Jan 24, 2024
fc9b886
gccrs: Unit struct constructor shall be resolved
P-E-P Jan 24, 2024
e995ddd
gccrs: Add tuple struct to the type namespace
P-E-P Jan 24, 2024
afdeae8
gccrs: Change enum namespace from value to type
P-E-P Jan 24, 2024
9a29958
gccrs: Struct are types, not values
P-E-P Jan 24, 2024
bc85b5c
gccrs: Add constant identifiers to the value namespace
P-E-P Jan 24, 2024
193edd0
gccrs: Remove extern block scoping
P-E-P Feb 6, 2024
46241d3
gccrs: Remove unsafe block empty visit function
P-E-P Feb 6, 2024
d755d39
gccrs: Use new name resolver to compile constant items
P-E-P Feb 6, 2024
259b2b3
gccrs: Reinject Self parameter in new resolver
P-E-P Feb 7, 2024
e98ee34
gccrs: Update assignment operator with cratenum
P-E-P Mar 13, 2024
946e224
gccrs: Prevent getting immutable context with classic nr
P-E-P Mar 13, 2024
51e99bd
gccrs: Fix quoted string format
P-E-P Mar 13, 2024
7a50f68
gccrs: Add mappings for struct base and struct fields
P-E-P Mar 21, 2024
96eb672
gccrs: Fix use rebind name resolution.
P-E-P Mar 21, 2024
8efcba9
gccrs: compile: resolve-path-ref: properly resolve nodeId with nr2.0
CohenArthur Mar 22, 2024
54dcac6
gccrs: nr2.0: Add new test cases.
CohenArthur Aug 23, 2023
48f85f4
gccrs: Add globbing name resolution 2.0 test
P-E-P Mar 26, 2024
e3396e7
gccrs: Change dfs function return type to support gcc 4.8
P-E-P Mar 26, 2024
76bb995
gccrs: Improve parsing of raw byte string literals
powerboat9 Mar 27, 2024
1d1daf1
gccrs: Recognize rustc_deprecated as a builtin attribute
powerboat9 Mar 27, 2024
75b29d4
gccrs: Recognize unstable as a builtin attribute
powerboat9 Mar 26, 2024
e610efb
gccrs: Avoid parsing const unsafe/extern functions as async
powerboat9 Mar 26, 2024
4d206aa
gccrs: Improve parsing of raw string literals
powerboat9 Mar 27, 2024
eb99262
gccrs: raw-strings: Remove dg-excess-error directive
CohenArthur Mar 29, 2024
79528c5
gccrs: unify: Always coerce `!` to the target type.
CohenArthur Mar 6, 2024
c0caad4
gccrs: borrowck: Use rust-system.h
jdupak Mar 22, 2024
3ff2231
gccrs: borrowck: Unify BIR terminilogy (node->statement)
jdupak Nov 4, 2023
34e1f62
gccrs: borrowck: BIR: use callable API
jdupak Feb 2, 2024
bc10c6f
gccrs: borrowck: BIR: Place tree traverse API
jdupak Feb 2, 2024
bdccacc
gccrs: borrowck: BIR: scope handling
jdupak Feb 2, 2024
098077b
gccrs: borrowck: BIR: emit moves
jdupak Feb 2, 2024
ec5e8b2
gccrs: borrowck: BIR: make BIR visitor const
jdupak Feb 27, 2024
33b2b42
gccrs: borrowck: Polonius FFI
jdupak Feb 27, 2024
7f95d6b
gccrs: borrowck: Free region representation
jdupak Feb 27, 2024
8cd3a52
gccrs: borrowck: extract regions from types using VA
jdupak Feb 27, 2024
0698539
gccrs: borrowck: Regions in BIR
jdupak Feb 27, 2024
54d7528
gccrs: borrowck: Fact collector
jdupak Feb 27, 2024
5bf7efe
gccrs: borrowck: Remove block braces to satisfy GNU style
jdupak Apr 1, 2024
fbc9ffd
gccrs: borrowck: Bump copyright notice
jdupak Apr 3, 2024
96df6c2
gccrs: Visit type during resolution of inherent impl
P-E-P Apr 18, 2024
3facddc
gccrs: Add a test for inherent impl type name resolve
P-E-P Apr 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions contrib/gcc_update
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ libgomp/config.h.in: libgomp/configure.ac libgomp/aclocal.m4
libgrust/Makefile.in: libgrust/Makefile.am libgrust/aclocal.m4
libgrust/aclocal.m4: libgrust/configure.ac
libgrust/configure: libgrust/configure.ac libgrust/aclocal.m4
libgrust/libformat_parser/Makefile.in: libgrust/libformat_parser/Makefile.am libgrust/aclocal.m4
libgrust/libproc_macro_internal/Makefile.in: libgrust/libproc_macro_internal/Makefile.am libgrust/aclocal.m4
libitm/aclocal.m4: libitm/configure.ac libitm/acinclude.m4
libitm/Makefile.in: libitm/Makefile.am libitm/aclocal.m4
Expand Down
22 changes: 21 additions & 1 deletion gcc/rust/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ GCCRS_D_OBJS = \
rust/rustspec.o \
$(END)

LIBS += -ldl -lpthread

gccrs$(exeext): $(GCCRS_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS)
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
$(GCCRS_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
Expand Down Expand Up @@ -100,6 +102,16 @@ GRS_OBJS = \
rust/rust-proc-macro-invoc-lexer.o \
rust/rust-macro-substitute-ctx.o \
rust/rust-macro-builtins.o \
rust/rust-macro-builtins-helpers.o \
rust/rust-macro-builtins-asm.o \
rust/rust-macro-builtins-trait.o \
rust/rust-macro-builtins-utility.o \
rust/rust-macro-builtins-log-debug.o \
rust/rust-macro-builtins-test-bench.o \
rust/rust-macro-builtins-format-args.o \
rust/rust-macro-builtins-location.o \
rust/rust-macro-builtins-include.o \
rust/rust-fmt.o \
rust/rust-hir.o \
rust/rust-hir-map.o \
rust/rust-attributes.o \
Expand All @@ -115,12 +127,14 @@ GRS_OBJS = \
rust/rust-ast-lower-expr.o \
rust/rust-ast-lower-type.o \
rust/rust-ast-lower-stmt.o \
rust/rust-ast-lower-format-args.o \
rust/rust-rib.o \
rust/rust-name-resolution-context.o \
rust/rust-default-resolver.o \
rust/rust-toplevel-name-resolver-2.0.o \
rust/rust-early-name-resolver-2.0.o \
rust/rust-late-name-resolver-2.0.o \
rust/rust-immutable-name-resolution-context.o \
rust/rust-early-name-resolver.o \
rust/rust-name-resolver.o \
rust/rust-ast-resolve.o \
Expand All @@ -143,6 +157,7 @@ GRS_OBJS = \
rust/rust-tyty-util.o \
rust/rust-tyty-call.o \
rust/rust-tyty-subst.o \
rust/rust-tyty-variance-analysis.o \
rust/rust-typecheck-context.o \
rust/rust-tyty-bounds.o \
rust/rust-hir-trait-resolve.o \
Expand Down Expand Up @@ -200,6 +215,8 @@ GRS_OBJS = \
rust/rust-dir-owner.o \
rust/rust-unicode.o \
rust/rust-punycode.o \
rust/rust-lang-item.o \
rust/rust-expand-format-args.o \
$(END)
# removed object files from here

Expand All @@ -209,6 +226,9 @@ RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o

LIBPROC_MACRO_INTERNAL = ../libgrust/libproc_macro_internal/libproc_macro_internal.a
LIBFORMAT_PARSER = ../libgrust/libformat_parser/debug/liblibformat_parser.a

RUST_LIBDEPS = $(LIBDEPS) $(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER)


RUST_LIBDEPS = $(LIBDEPS) $(LIBPROC_MACRO_INTERNAL)
Expand All @@ -217,7 +237,7 @@ RUST_LIBDEPS = $(LIBDEPS) $(LIBPROC_MACRO_INTERNAL)
crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(RUST_LIBDEPS) $(rust.prev)
@$(call LINK_PROGRESS,$(INDEX.rust),start)
+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
$(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) $(LIBPROC_MACRO_INTERNAL) $(BACKENDLIBS)
$(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) $(LIBPROC_MACRO_INTERNAL) $(LIBFORMAT_PARSER) $(BACKENDLIBS)
@$(call LINK_PROGRESS,$(INDEX.rust),end)

# Build hooks.
Expand Down
66 changes: 44 additions & 22 deletions gcc/rust/ast/rust-ast-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,73 @@
// <http://www.gnu.org/licenses/>.

#include "rust-ast-builder.h"
#include "rust-ast-full-decls.h"
#include "rust-ast-full.h"
#include "rust-expr.h"
#include "rust-token.h"
#include "rust-make-unique.h"

namespace Rust {
namespace AST {

std::unique_ptr<Expr>
AstBuilder::call (std::unique_ptr<Expr> &&path,
std::vector<std::unique_ptr<Expr>> &&args)
Builder::literal_string (std::string &&content) const
{
return std::unique_ptr<Expr> (
new AST::LiteralExpr (std::move (content), Literal::LitType::STRING,
PrimitiveCoreType::CORETYPE_STR, {}, loc));
}

std::unique_ptr<Expr>
Builder::call (std::unique_ptr<Expr> &&path,
std::vector<std::unique_ptr<Expr>> &&args) const
{
return std::unique_ptr<Expr> (
new CallExpr (std::move (path), std::move (args), {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::identifier (std::string name)
Builder::array (std::vector<std::unique_ptr<Expr>> &&members) const
{
auto elts = Rust::make_unique<ArrayElemsValues> (std::move (members), loc);

return std::unique_ptr<Expr> (new ArrayExpr (std::move (elts), {}, {}, loc));
}

std::unique_ptr<Expr>
Builder::identifier (std::string name) const
{
return std::unique_ptr<Expr> (new IdentifierExpr (name, {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::tuple_idx (std::string receiver, int idx)
Builder::tuple_idx (std::string receiver, int idx) const
{
return std::unique_ptr<Expr> (
new TupleIndexExpr (identifier (receiver), idx, {}, loc));
}

FunctionQualifiers
AstBuilder::fn_qualifiers ()
Builder::fn_qualifiers () const
{
return FunctionQualifiers (loc, Async::No, Const::No, Unsafety::Normal);
}

PathExprSegment
AstBuilder::path_segment (std::string seg)
Builder::path_segment (std::string seg) const
{
return PathExprSegment (PathIdentSegment (seg, loc), loc);
}

std::unique_ptr<TypePathSegment>
AstBuilder::type_path_segment (std::string seg)
Builder::type_path_segment (std::string seg) const
{
return std::unique_ptr<TypePathSegment> (
new TypePathSegment (seg, false, loc));
}

std::unique_ptr<Type>
AstBuilder::single_type_path (std::string type)
Builder::single_type_path (std::string type) const
{
auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
segments.emplace_back (type_path_segment (type));
Expand All @@ -72,7 +92,7 @@ AstBuilder::single_type_path (std::string type)
}

PathInExpression
AstBuilder::path_in_expression (std::vector<std::string> &&segments)
Builder::path_in_expression (std::vector<std::string> &&segments) const
{
auto path_segments = std::vector<PathExprSegment> ();
for (auto &seg : segments)
Expand All @@ -82,69 +102,71 @@ AstBuilder::path_in_expression (std::vector<std::string> &&segments)
}

std::unique_ptr<Expr>
AstBuilder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr)
Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr) const
{
return std::unique_ptr<Expr> (new BlockExpr (std::move (stmts),
std::move (tail_expr), {}, {},
LoopLabel::error (), loc, loc));
}

std::unique_ptr<Stmt>
AstBuilder::let (std::unique_ptr<Pattern> pattern, std::unique_ptr<Type> type,
std::unique_ptr<Expr> init)
Builder::let (std::unique_ptr<Pattern> pattern, std::unique_ptr<Type> type,
std::unique_ptr<Expr> init) const
{
return std::unique_ptr<Stmt> (new LetStmt (std::move (pattern),
std::move (init), std::move (type),
{}, loc));
}

std::unique_ptr<Expr>
AstBuilder::ref (std::unique_ptr<Expr> &&of, bool mut)
Builder::ref (std::unique_ptr<Expr> &&of, bool mut) const
{
return std::unique_ptr<Expr> (
new BorrowExpr (std::move (of), mut, /* is double */ false, {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::deref (std::unique_ptr<Expr> &&of)
Builder::deref (std::unique_ptr<Expr> &&of) const
{
return std::unique_ptr<Expr> (new DereferenceExpr (std::move (of), {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::struct_expr_struct (std::string struct_name)
Builder::struct_expr_struct (std::string struct_name) const
{
return std::unique_ptr<Expr> (
new StructExprStruct (path_in_expression ({struct_name}), {}, {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::struct_expr (std::string struct_name,
std::vector<std::unique_ptr<StructExprField>> &&fields)
Builder::struct_expr (
std::string struct_name,
std::vector<std::unique_ptr<StructExprField>> &&fields) const
{
return std::unique_ptr<Expr> (
new StructExprStructFields (path_in_expression ({struct_name}),
std::move (fields), loc));
}

std::unique_ptr<StructExprField>
AstBuilder::struct_expr_field (std::string field_name,
std::unique_ptr<Expr> &&value)
Builder::struct_expr_field (std::string field_name,
std::unique_ptr<Expr> &&value) const
{
return std::unique_ptr<StructExprField> (
new StructExprFieldIdentifierValue (field_name, std::move (value), loc));
}

std::unique_ptr<Expr>
AstBuilder::field_access (std::unique_ptr<Expr> &&instance, std::string field)
Builder::field_access (std::unique_ptr<Expr> &&instance,
std::string field) const
{
return std::unique_ptr<Expr> (
new FieldAccessExpr (std::move (instance), field, {}, loc));
}

std::unique_ptr<Pattern>
AstBuilder::wildcard ()
Builder::wildcard () const
{
return std::unique_ptr<Pattern> (new WildcardPattern (loc));
}
Expand Down
51 changes: 32 additions & 19 deletions gcc/rust/ast/rust-ast-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,80 +28,93 @@ namespace AST {
/* Builder class with helper methods to create AST nodes. This builder is
* tailored towards generating multiple AST nodes from a single location, and
* may not be suitable to other purposes */
class AstBuilder
class Builder
{
public:
AstBuilder (location_t loc) : loc (loc) {}
Builder (location_t loc) : loc (loc) {}

/* Create a string literal expression ("content") */
std::unique_ptr<Expr> literal_string (std::string &&content) const;

/* Create an identifier expression (`variable`) */
std::unique_ptr<Expr> identifier (std::string name);
std::unique_ptr<Expr> identifier (std::string name) const;

/* Create a tuple index expression (`receiver.0`) */
std::unique_ptr<Expr> tuple_idx (std::string receiver, int idx);
std::unique_ptr<Expr> tuple_idx (std::string receiver, int idx) const;

/* Create a reference to an expression (`&of`) */
std::unique_ptr<Expr> ref (std::unique_ptr<Expr> &&of, bool mut = false);
std::unique_ptr<Expr> ref (std::unique_ptr<Expr> &&of,
bool mut = false) const;

/* Create a dereference of an expression (`*of`) */
std::unique_ptr<Expr> deref (std::unique_ptr<Expr> &&of);
std::unique_ptr<Expr> deref (std::unique_ptr<Expr> &&of) const;

/* Create a block with an optional tail expression */
std::unique_ptr<Expr> block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr = nullptr);
std::unique_ptr<Expr> &&tail_expr
= nullptr) const;

/* Create a let binding with an optional type and initializer (`let <name> :
* <type> = <init>`) */
std::unique_ptr<Stmt> let (std::unique_ptr<Pattern> pattern,
std::unique_ptr<Type> type = nullptr,
std::unique_ptr<Expr> init = nullptr);
std::unique_ptr<Expr> init = nullptr) const;

/**
* Create a call expression to a function, struct or enum variant, given its
* arguments (`path(arg0, arg1, arg2)`)
*/
std::unique_ptr<Expr> call (std::unique_ptr<Expr> &&path,
std::vector<std::unique_ptr<Expr>> &&args);
std::vector<std::unique_ptr<Expr>> &&args) const;

/**
* Create an array expression (`[member0, member1, member2]`)
*/
std::unique_ptr<Expr>
array (std::vector<std::unique_ptr<Expr>> &&members) const;

/* Empty function qualifiers, with no specific qualifiers */
FunctionQualifiers fn_qualifiers ();
FunctionQualifiers fn_qualifiers () const;

/* Create a single path segment from one string */
PathExprSegment path_segment (std::string seg);
PathExprSegment path_segment (std::string seg) const;

/* And similarly for type path segments */
std::unique_ptr<TypePathSegment> type_path_segment (std::string seg);
std::unique_ptr<TypePathSegment> type_path_segment (std::string seg) const;

/* Create a Type from a single string - the most basic kind of type in our AST
*/
std::unique_ptr<Type> single_type_path (std::string type);
std::unique_ptr<Type> single_type_path (std::string type) const;

/**
* Create a path in expression from multiple segments (`Clone::clone`). You
* do not need to separate the segments using `::`, you can simply provide a
* vector of strings to the functions which will get turned into path segments
*/
PathInExpression path_in_expression (std::vector<std::string> &&segments);
PathInExpression
path_in_expression (std::vector<std::string> &&segments) const;

/* Create a struct expression for unit structs (`S`) */
std::unique_ptr<Expr> struct_expr_struct (std::string struct_name);
std::unique_ptr<Expr> struct_expr_struct (std::string struct_name) const;

/**
* Create an expression for struct instantiation with fields (`S { a, b: c }`)
*/
std::unique_ptr<Expr>
struct_expr (std::string struct_name,
std::vector<std::unique_ptr<StructExprField>> &&fields);
std::vector<std::unique_ptr<StructExprField>> &&fields) const;

/* Create a field expression for struct instantiation (`field_name: value`) */
std::unique_ptr<StructExprField>
struct_expr_field (std::string field_name, std::unique_ptr<Expr> &&value);
struct_expr_field (std::string field_name,
std::unique_ptr<Expr> &&value) const;

/* Create a field access expression (`instance.field`) */
std::unique_ptr<Expr> field_access (std::unique_ptr<Expr> &&instance,
std::string field);
std::string field) const;

/* Create a wildcard pattern (`_`) */
std::unique_ptr<Pattern> wildcard ();
std::unique_ptr<Pattern> wildcard () const;

private:
/**
Expand Down
Loading