namespace Rust {
namespace AST {
+std::unique_ptr<Stmt>
+Builder::statementify (std::unique_ptr<Expr> &&value,
+ bool semicolon_followed) const
+{
+ return std::make_unique<ExprStmt> (std::move (value), loc,
+ semicolon_followed);
+}
+
std::unique_ptr<Expr>
Builder::literal_string (std::string &&content) const
{
std::vector<std::unique_ptr<Param>> params,
std::unique_ptr<Type> return_type,
std::unique_ptr<BlockExpr> block,
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
FunctionQualifiers qualifiers, WhereClause where_clause,
Visibility visibility) const
{
return std::unique_ptr<Function> (
- new Function (function_name, qualifiers, {}, std::move (params),
- std::move (return_type), where_clause, std::move (block),
- visibility, {}, loc));
+ new Function (function_name, qualifiers, std::move (generic_params),
+ std::move (params), std::move (return_type), where_clause,
+ std::move (block), visibility, {}, loc));
}
PathExprSegment
}
PathInExpression
-Builder::path_in_expression (std::vector<std::string> &&segments) const
+Builder::path_in_expression (std::vector<std::string> &&segments,
+ bool opening_scope) const
{
auto path_segments = std::vector<PathExprSegment> ();
for (auto &seg : segments)
path_segments.emplace_back (path_segment (seg));
- return PathInExpression (std::move (path_segments), {}, loc);
+ return PathInExpression (std::move (path_segments), {}, loc, opening_scope);
}
PathInExpression
return block (std::move (stmts), std::move (tail_expr));
}
+std::unique_ptr<BlockExpr>
+Builder::block () const
+{
+ auto stmts = std::vector<std::unique_ptr<Stmt>> ();
+
+ return block (std::move (stmts));
+}
+
std::unique_ptr<BlockExpr>
Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr) const
visibility, {}, {}, loc));
}
+std::unique_ptr<GenericParam>
+Builder::generic_type_param (
+ std::string type_representation,
+ std::vector<std::unique_ptr<TypeParamBound>> &&bounds,
+ std::unique_ptr<Type> &&type)
+{
+ return std::make_unique<TypeParam> (type_representation, loc,
+ std::move (bounds), std::move (type),
+ std::vector<Attribute> ());
+}
+
std::unique_ptr<Type>
Builder::new_type (Type &type)
{
return v;
}
+/* Pointer-ify something */
+template <typename T>
+static std::unique_ptr<T>
+ptrify (T value)
+{
+ return std::unique_ptr<T> (new T (value));
+}
+
// TODO: Use this builder when expanding regular macros
/* Builder class with helper methods to create AST nodes. This builder is
* tailored towards generating multiple AST nodes from a single location, and
public:
Builder (location_t loc) : loc (loc) {}
+ /* Create an expression statement from an expression */
+ std::unique_ptr<Stmt> statementify (std::unique_ptr<Expr> &&value,
+ bool semicolon_followed = true) const;
+
/* Create a string literal expression ("content") */
std::unique_ptr<Expr> literal_string (std::string &&content) const;
std::unique_ptr<BlockExpr> block (tl::optional<std::unique_ptr<Stmt>> &&stmt,
std::unique_ptr<Expr> &&tail_expr
= nullptr) const;
+ /* Create an empty block */
+ std::unique_ptr<BlockExpr> block () const;
/* Create an early return expression with an optional expression */
std::unique_ptr<Expr> return_expr (std::unique_ptr<Expr> &&to_return
function (std::string function_name,
std::vector<std::unique_ptr<Param>> params,
std::unique_ptr<Type> return_type, std::unique_ptr<BlockExpr> block,
+ std::vector<std::unique_ptr<GenericParam>> generic_params = {},
FunctionQualifiers qualifiers
= FunctionQualifiers (UNKNOWN_LOCATION, Async::No, Const::No,
Unsafety::Normal),
* 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) const;
+ PathInExpression path_in_expression (std::vector<std::string> &&segments,
+ bool opening_scope = false) const;
/**
* Create a path in expression from a lang item.
WhereClause where_clause = WhereClause::create_empty (),
Visibility visibility = Visibility::create_private ()) const;
+ std::unique_ptr<GenericParam>
+ generic_type_param (std::string type_representation,
+ std::vector<std::unique_ptr<TypeParamBound>> &&bounds,
+ std::unique_ptr<Type> &&type = nullptr);
+
static std::unique_ptr<Type> new_type (Type &type);
static std::unique_ptr<GenericParam>