// Copyright (C) 2020-2023 Free Software Foundation, Inc.
// This file is part of GCC.
// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING3. If not see
// .
#include "rust-ast-builder.h"
#include "rust-ast-full.h"
namespace Rust {
namespace AST {
std::unique_ptr
AstBuilder::call (std::unique_ptr &&path,
std::vector> &&args)
{
return std::unique_ptr (
new CallExpr (std::move (path), std::move (args), {}, loc));
}
std::unique_ptr
AstBuilder::identifier (std::string name)
{
return std::unique_ptr (new IdentifierExpr (name, {}, loc));
}
std::unique_ptr
AstBuilder::tuple_idx (std::string receiver, int idx)
{
return std::unique_ptr (
new TupleIndexExpr (identifier (receiver), idx, {}, loc));
}
FunctionQualifiers
AstBuilder::fn_qualifiers ()
{
return FunctionQualifiers (loc, AsyncConstStatus::NONE, false);
}
PathExprSegment
AstBuilder::path_segment (std::string seg)
{
return PathExprSegment (PathIdentSegment (seg, loc), loc);
}
std::unique_ptr
AstBuilder::type_path_segment (std::string seg)
{
return std::unique_ptr (
new TypePathSegment (seg, false, loc));
}
std::unique_ptr
AstBuilder::single_type_path (std::string type)
{
auto segments = std::vector> ();
segments.emplace_back (type_path_segment (type));
return std::unique_ptr (new TypePath (std::move (segments), loc));
}
PathInExpression
AstBuilder::path_in_expression (std::vector &&segments)
{
auto path_segments = std::vector ();
for (auto &seg : segments)
path_segments.emplace_back (path_segment (seg));
return PathInExpression (std::move (path_segments), {}, loc);
}
std::unique_ptr
AstBuilder::block (std::vector> &&stmts,
std::unique_ptr &&tail_expr)
{
return std::unique_ptr (
new BlockExpr (std::move (stmts), std::move (tail_expr), {}, {}, loc, loc));
}
std::unique_ptr
AstBuilder::let (std::unique_ptr pattern, std::unique_ptr type,
std::unique_ptr init)
{
return std::unique_ptr (new LetStmt (std::move (pattern),
std::move (init), std::move (type),
{}, loc));
}
std::unique_ptr
AstBuilder::ref (std::unique_ptr &&of, bool mut)
{
return std::unique_ptr (
new BorrowExpr (std::move (of), mut, /* is double */ false, {}, loc));
}
std::unique_ptr
AstBuilder::deref (std::unique_ptr &&of)
{
return std::unique_ptr (new DereferenceExpr (std::move (of), {}, loc));
}
std::unique_ptr
AstBuilder::struct_expr_struct (std::string struct_name)
{
return std::unique_ptr (
new StructExprStruct (path_in_expression ({struct_name}), {}, {}, loc));
}
std::unique_ptr
AstBuilder::struct_expr (std::string struct_name,
std::vector> &&fields)
{
return std::unique_ptr (
new StructExprStructFields (path_in_expression ({struct_name}),
std::move (fields), loc));
}
std::unique_ptr
AstBuilder::struct_expr_field (std::string field_name,
std::unique_ptr &&value)
{
return std::unique_ptr (
new StructExprFieldIdentifierValue (field_name, std::move (value), loc));
}
std::unique_ptr
AstBuilder::field_access (std::unique_ptr &&instance, std::string field)
{
return std::unique_ptr (
new FieldAccessExpr (std::move (instance), field, {}, loc));
}
std::unique_ptr
AstBuilder::wildcard ()
{
return std::unique_ptr (new WildcardPattern (loc));
}
} // namespace AST
} // namespace Rust