aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSimplyTheOther <simplytheother@gmail.com>2021-02-02 13:19:26 +0800
committerSimplyTheOther <simplytheother@gmail.com>2021-02-02 15:55:58 +0800
commit3a0c8ca2156038b726e2689e9b46be4d8c40c55f (patch)
tree3c5e0391cd9ba3a2336a0692f0bc7980469dc165 /gcc
parentb3a39d99c1d6f45890dbac33a9d17c8dd464654e (diff)
downloadgcc-3a0c8ca2156038b726e2689e9b46be4d8c40c55f.zip
gcc-3a0c8ca2156038b726e2689e9b46be4d8c40c55f.tar.gz
gcc-3a0c8ca2156038b726e2689e9b46be4d8c40c55f.tar.bz2
Cleanup of AST - moved outer_attrs to child classes
Fixed compile errors Fixed more compile errors
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-full-test.cc566
-rw-r--r--gcc/rust/ast/rust-ast.h55
-rw-r--r--gcc/rust/ast/rust-expr.h339
-rw-r--r--gcc/rust/ast/rust-macro.h8
-rw-r--r--gcc/rust/ast/rust-path.h35
-rw-r--r--gcc/rust/expand/rust-macro-expand.cc69
-rw-r--r--gcc/rust/parse/rust-parse-impl.h79
7 files changed, 570 insertions, 581 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index 092ab00..53007e7 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -109,6 +109,47 @@ frag_spec_to_str (MacroFragSpec frag_spec)
}
}
+enum AttrMode
+{
+ OUTER,
+ INNER
+};
+
+std::string get_mode_dump_desc (AttrMode mode) {
+ switch (mode) {
+ case OUTER:
+ return "outer attributes";
+ case INNER:
+ return "inner attributes";
+ default:
+ gcc_unreachable ();
+ return "";
+ }
+}
+
+// Adds lines below adding attributes
+std::string append_attributes (std::vector<Attribute> attrs, AttrMode mode) {
+ indent_spaces (enter);
+
+ std::string str = "\n" + indent_spaces (stay) + get_mode_dump_desc (mode) + ": ";
+ //str += "\n" + indent_spaces (stay) + "inner attributes: ";
+ if (attrs.empty ())
+ {
+ str += "none";
+ }
+ else
+ {
+ /* note that this does not print them with outer or "inner attribute"
+ * syntax - just prints the body */
+ for (const auto &attr : attrs)
+ str += "\n" + indent_spaces (stay) + attr.as_string ();
+ }
+
+ indent_spaces (out);
+
+ return str;
+}
+
std::string
Crate::as_string () const
{
@@ -156,7 +197,7 @@ Crate::as_string () const
{
fprintf (stderr, "something really terrible has gone wrong - "
"null pointer item in crate.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + item->as_string ();
@@ -236,7 +277,7 @@ DelimTokenTree::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"token tree in delim token tree.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += tree->as_string ();
@@ -405,7 +446,7 @@ ModuleBodied::as_string () const
{
fprintf (stderr, "something really terrible has gone wrong - "
"null pointer item in crate.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + item->as_string ();
@@ -444,7 +485,7 @@ StaticItem::as_string () const
{
fprintf (stderr, "something really terrible has gone wrong - null "
"pointer type in static item.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n" + indent_spaces (stay) + "Type: " + type->as_string ();
@@ -453,7 +494,7 @@ StaticItem::as_string () const
{
fprintf (stderr, "something really terrible has gone wrong - null "
"pointer expr in static item.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n" + indent_spaces (stay) + "Expression: " + expr->as_string ();
@@ -499,7 +540,7 @@ TupleStruct::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in enum.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -545,7 +586,7 @@ ConstantItem::as_string () const
{
fprintf (stderr, "something really terrible has gone wrong - null "
"pointer type in const item.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n Type: " + type->as_string ();
@@ -554,7 +595,7 @@ ConstantItem::as_string () const
{
fprintf (stderr, "something really terrible has gone wrong - null "
"pointer expr in const item.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n Expression: " + const_expr->as_string ();
@@ -585,7 +626,7 @@ InherentImpl::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in inherent impl.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -663,7 +704,7 @@ Method::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in method.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -725,7 +766,7 @@ StructStruct::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in enum.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -775,7 +816,7 @@ UseDeclaration::as_string () const
stderr,
"something really terrible has gone wrong - null pointer use tree in "
"use declaration.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "use " + use_tree->as_string ();
@@ -835,7 +876,7 @@ UseTreeList::as_string () const
fprintf (stderr,
"something really terrible has gone wrong - null pointer "
"tree in use tree list.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
for (; i != e; i++)
@@ -900,7 +941,7 @@ Enum::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in enum.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -934,7 +975,7 @@ Enum::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"enum item in enum.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + item->as_string ();
@@ -950,9 +991,7 @@ Trait::as_string () const
std::string str = VisItem::as_string ();
if (has_unsafe)
- {
str += "unsafe ";
- }
str += "trait " + name;
@@ -973,7 +1012,7 @@ Trait::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in trait.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -996,7 +1035,7 @@ Trait::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"type param bound in trait.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + bound->as_string ();
@@ -1005,13 +1044,9 @@ Trait::as_string () const
str += "\n Where clause: ";
if (!has_where_clause ())
- {
str += "none";
- }
else
- {
str += where_clause.as_string ();
- }
str += "\n Trait items: ";
if (!has_trait_items ())
@@ -1029,7 +1064,7 @@ Trait::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"trait item in trait.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + item->as_string ();
@@ -1063,7 +1098,7 @@ Union::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in union.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -1072,13 +1107,9 @@ Union::as_string () const
str += "\n Where clause: ";
if (has_where_clause ())
- {
str += where_clause.as_string ();
- }
else
- {
str += "none";
- }
// struct fields
str += "\n Struct fields (variants): ";
@@ -1089,9 +1120,7 @@ Union::as_string () const
else
{
for (const auto &field : variants)
- {
str += "\n " + field.as_string ();
- }
}
return str;
@@ -1114,7 +1143,7 @@ Function::as_string () const
stderr,
"something really terrible has gone wrong - null pointer return "
"type in function.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += return_type->as_string () + " ";
@@ -1139,7 +1168,7 @@ Function::as_string () const
fprintf (stderr,
"something really terrible has gone wrong - null pointer "
"generic param in function item.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
for (; i != e; i++)
@@ -1181,7 +1210,7 @@ Function::as_string () const
stderr,
"something really terrible has gone wrong - null pointer function "
"body in function.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += function_body->as_string () + "\n";
@@ -1212,8 +1241,20 @@ BlockExpr::as_string () const
{
std::string istr = indent_spaces (enter);
std::string str = istr + "BlockExpr:\n" + istr;
+
// get outer attributes
- str += "{\n" + indent_spaces (stay) + Expr::as_string ();
+ str += "{\n" + indent_spaces (stay) + "outer attributes: ";
+ if (outer_attrs.empty ())
+ {
+ str += "none";
+ }
+ else
+ {
+ /* note that this does not print them with "outer attribute" syntax -
+ * just the body */
+ for (const auto &attr : outer_attrs)
+ str += "\n" + indent_spaces (stay) + attr.as_string ();
+ }
// inner attributes
str += "\n" + indent_spaces (stay) + "inner attributes: ";
@@ -1246,7 +1287,7 @@ BlockExpr::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"stmt in block expr.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n" + indent_spaces (stay) + stmt->as_string ();
@@ -1400,7 +1441,7 @@ MacroInvocationSemi::as_string () const
fprintf (stderr,
"something really terrible has gone wrong - null pointer "
"token tree in macro invocation semi.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
std::string s;
@@ -1425,9 +1466,7 @@ ExternBlock::as_string () const
str += "extern ";
if (has_abi ())
- {
str += "\"" + abi + "\" ";
- }
// inner attributes
str += "\n inner attributes: ";
@@ -1576,7 +1615,27 @@ ClosureParam::as_string () const
std::string
ClosureExpr::as_string () const
{
- std::string str ("ClosureExpr:\n Has move: ");
+ std::string str = "ClosureExpr:";
+
+ str += append_attributes (outer_attrs, OUTER);
+
+#if 0
+ // outer attributes
+ str += "\n outer attributes: ";
+ if (outer_attrs.empty ())
+ {
+ str += "none";
+ }
+ else
+ {
+ /* note that this does not print them with "outer attribute" syntax -
+ * just the body */
+ for (const auto &attr : outer_attrs)
+ str += "\n " + attr.as_string ();
+ }
+#endif
+
+ str += "\n Has move: ";
if (has_move)
str += "true";
else
@@ -1643,6 +1702,9 @@ QualifiedPathInExpression::as_string () const
std::string
BorrowExpr::as_string () const
{
+ /* TODO: find way to incorporate outer attrs - may have to represent in
+ * different style (i.e. something more like BorrowExpr: \n outer attrs) */
+
std::string str ("&");
if (double_borrow)
@@ -1659,6 +1721,9 @@ BorrowExpr::as_string () const
std::string
ReturnExpr::as_string () const
{
+ /* TODO: find way to incorporate outer attrs - may have to represent in
+ * different style (i.e. something more like BorrowExpr: \n outer attrs) */
+
std::string str ("return ");
if (has_returned_expr ())
@@ -1672,7 +1737,11 @@ GroupedExpr::as_string () const
{
std::string str ("Grouped expr:");
+ // outer attrs
+ str += append_attributes (outer_attrs, OUTER);
+
// inner attributes
+#if 0
str += "\n inner attributes: ";
if (inner_attrs.empty ())
{
@@ -1685,6 +1754,8 @@ GroupedExpr::as_string () const
for (const auto &attr : inner_attrs)
str += "\n " + attr.as_string ();
}
+#endif
+ str += append_attributes (inner_attrs, INNER);
str += "\n Expr in parens: " + expr_in_parens->as_string ();
@@ -1700,6 +1771,7 @@ RangeToExpr::as_string () const
std::string
ContinueExpr::as_string () const
{
+ // TODO: rewrite format to allow outer attributes
std::string str ("continue ");
if (has_label ())
@@ -1711,6 +1783,7 @@ ContinueExpr::as_string () const
std::string
NegationExpr::as_string () const
{
+ // TODO: rewrite formula to allow outer attributes
std::string str;
switch (negation_type)
@@ -1745,6 +1818,7 @@ RangeFullExpr::as_string () const
std::string
ArrayIndexExpr::as_string () const
{
+ // TODO: rewrite formula to allow outer attributes
return array_expr->as_string () + "[" + index_expr->as_string () + "]";
}
@@ -1775,7 +1849,8 @@ AsyncBlockExpr::as_string () const
std::string str = "AsyncBlockExpr: ";
// get outer attributes
- str += "\n " + Expr::as_string ();
+ //str += "\n " + Expr::as_string ();
+ str += append_attributes (outer_attrs, OUTER);
str += "\n Has move: ";
str += has_move ? "true" : "false";
@@ -1786,6 +1861,7 @@ AsyncBlockExpr::as_string () const
std::string
ComparisonExpr::as_string () const
{
+ // TODO: rewrite to better reflect non-literal expressions
std::string str (main_or_left_expr->as_string ());
switch (expr_type)
@@ -1820,12 +1896,14 @@ ComparisonExpr::as_string () const
std::string
MethodCallExpr::as_string () const
{
- std::string str ("MethodCallExpr: \n Object (receiver) expr: ");
+ std::string str = "MethodCallExpr: ";
+ str += append_attributes (outer_attrs, OUTER);
+
+ str += "\n Object (receiver) expr: \n";
str += receiver->as_string ();
str += "\n Method path segment: \n";
-
str += method_name.as_string ();
str += "\n Call params:";
@@ -1850,24 +1928,28 @@ MethodCallExpr::as_string () const
std::string
TupleIndexExpr::as_string () const
{
+ // TODO: rewrite dump to better reflect non-literal exprs
return tuple_expr->as_string () + "." + std::to_string (tuple_index);
}
std::string
DereferenceExpr::as_string () const
{
+ // TODO: rewrite dump to better reflect non-literal exprs
return "*" + main_or_left_expr->as_string ();
}
std::string
FieldAccessExpr::as_string () const
{
+ // TODO: rewrite dump to better reflect non-literal exprs
return receiver->as_string () + "." + field;
}
std::string
LazyBooleanExpr::as_string () const
{
+ // TODO: rewrite dump to better reflect non-literal exprs
std::string str (main_or_left_expr->as_string ());
switch (expr_type)
@@ -1890,12 +1972,14 @@ LazyBooleanExpr::as_string () const
std::string
RangeFromToExpr::as_string () const
{
+ // TODO: rewrite dump to better reflect non-literal exprs
return from->as_string () + ".." + to->as_string ();
}
std::string
RangeToInclExpr::as_string () const
{
+ // TODO: rewrite dump to better reflect non-literal exprs
return "..=" + to->as_string ();
}
@@ -1907,7 +1991,8 @@ UnsafeBlockExpr::as_string () const
str += istr + "{";
// get outer attributes
- str += "\n" + indent_spaces (stay) + Expr::as_string ();
+ //str += "\n" + indent_spaces (stay) + Expr::as_string ();
+ str += append_attributes (outer_attrs, OUTER);
return str + "\n" + indent_spaces (out) + "}\n" + expr->as_string ();
}
@@ -1925,6 +2010,8 @@ ClosureExprInner::as_string () const
std::string
IfExpr::as_string () const
{
+ /* TODO: can if exprs have outer attributes? i thought no, but can't find it
+ * in docs */
std::string str ("IfExpr: ");
str += "\n Condition expr: " + condition->as_string ();
@@ -1967,6 +2054,8 @@ IfExprConseqIfLet::as_string () const
std::string
IfLetExpr::as_string () const
{
+ /* TODO: can if let exprs have outer attributes? i thought no, but can't find
+ * it in docs */
std::string str ("IfLetExpr: ");
str += "\n Condition match arm patterns: ";
@@ -2020,12 +2109,14 @@ IfLetExprConseqIfLet::as_string () const
std::string
RangeFromToInclExpr::as_string () const
{
+ // TODO: rewrite to allow dumps with non-literal exprs
return from->as_string () + "..=" + to->as_string ();
}
std::string
ErrorPropagationExpr::as_string () const
{
+ // TODO: rewrite to allow dumps with non-literal exprs
return main_or_left_expr->as_string () + "?";
}
@@ -2152,8 +2243,11 @@ ArithmeticOrLogicalExpr::as_string () const
std::string
CallExpr::as_string () const
{
- std::string str ("CallExpr: \n Function expr: ");
+ std::string str = "CallExpr: ";
+ str += append_attributes (outer_attrs, OUTER);
+
+ str += "\n Function expr: ";
str += function->as_string ();
str += "\n Call params:";
@@ -2178,7 +2272,9 @@ CallExpr::as_string () const
std::string
WhileLoopExpr::as_string () const
{
- std::string str ("WhileLoopExpr: ");
+ std::string str = "WhileLoopExpr: ";
+
+ str += append_attributes (outer_attrs, OUTER);
str += "\n Label: ";
if (!has_loop_label ())
@@ -2196,7 +2292,9 @@ WhileLoopExpr::as_string () const
std::string
WhileLetLoopExpr::as_string () const
{
- std::string str ("WhileLetLoopExpr: ");
+ std::string str = "WhileLetLoopExpr: ";
+
+ str += append_attributes (outer_attrs, OUTER);
str += "\n Label: ";
if (!has_loop_label ())
@@ -2225,7 +2323,9 @@ WhileLetLoopExpr::as_string () const
std::string
LoopExpr::as_string () const
{
- std::string str ("LoopExpr: (infinite loop)");
+ std::string str = "LoopExpr: (infinite loop)";
+
+ str += append_attributes (outer_attrs, OUTER);
str += "\n Label: ";
if (!has_loop_label ())
@@ -2241,9 +2341,13 @@ LoopExpr::as_string () const
std::string
ArrayExpr::as_string () const
{
- std::string str ("ArrayExpr:");
+ std::string str = "ArrayExpr:";
+
+ str += append_attributes (outer_attrs, OUTER);
// inner attributes
+ str += append_attributes (inner_attrs, INNER);
+ #if 0
str += "\n inner attributes: ";
if (inner_attrs.empty ())
{
@@ -2256,6 +2360,7 @@ ArrayExpr::as_string () const
for (const auto &attr : inner_attrs)
str += "\n " + attr.as_string ();
}
+ #endif
str += "\n Array elems: ";
if (!has_array_elems ())
@@ -2269,12 +2374,14 @@ ArrayExpr::as_string () const
std::string
AwaitExpr::as_string () const
{
+ // TODO: rewrite dump to allow non-literal exprs
return awaited_expr->as_string () + ".await";
}
std::string
BreakExpr::as_string () const
{
+ // TODO: rewrite dump to allow outer attrs, non-literal exprs
std::string str ("break ");
if (has_label ())
@@ -2296,6 +2403,8 @@ std::string
MatchArm::as_string () const
{
// outer attributes
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "Outer attributes: ";
if (outer_attrs.empty ())
{
@@ -2308,6 +2417,7 @@ MatchArm::as_string () const
for (const auto &attr : outer_attrs)
str += "\n " + attr.as_string ();
}
+#endif
str += "\nPatterns: ";
if (match_arm_patterns.empty ())
@@ -2365,9 +2475,13 @@ MatchExpr::as_string () const
{
std::string str ("MatchExpr:");
+ str += append_attributes (outer_attrs, OUTER);
+
str += "\n Scrutinee expr: " + branch_value->as_string ();
// inner attributes
+ str += append_attributes (inner_attrs, INNER);
+#if 0
str += "\n inner attributes: ";
if (inner_attrs.empty ())
{
@@ -2378,10 +2492,9 @@ MatchExpr::as_string () const
/* note that this does not print them with "inner attribute" syntax -
* just the body */
for (const auto &attr : inner_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
// match arms
str += "\n Match arms: ";
@@ -2403,7 +2516,11 @@ TupleExpr::as_string () const
{
std::string str ("TupleExpr:");
+ str += append_attributes (outer_attrs, OUTER);
+
// inner attributes
+ str += append_attributes (inner_attrs, INNER);
+#if 0
str += "\n inner attributes: ";
if (inner_attrs.empty ())
{
@@ -2414,10 +2531,9 @@ TupleExpr::as_string () const
/* note that this does not print them with "inner attribute" syntax -
* just the body */
for (const auto &attr : inner_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
str += "\n Tuple elements: ";
if (tuple_elems.empty ())
@@ -2427,9 +2543,7 @@ TupleExpr::as_string () const
else
{
for (const auto &elem : tuple_elems)
- {
str += "\n " + elem->as_string ();
- }
}
return str;
@@ -2443,13 +2557,9 @@ ExprStmtWithoutBlock::as_string () const
str += indent_spaces (stay);
if (expr == nullptr)
- {
str += "none (this shouldn't happen and is probably an error)";
- }
else
- {
str += expr->as_string ();
- }
indent_spaces (out);
return str;
@@ -2458,6 +2568,7 @@ ExprStmtWithoutBlock::as_string () const
std::string
FunctionParam::as_string () const
{
+ // TODO: rewrite dump to allow non-literal types
return param_name->as_string () + " : " + type->as_string ();
}
@@ -2482,17 +2593,13 @@ FunctionQualifiers::as_string () const
}
if (has_unsafe)
- {
str += "unsafe ";
- }
if (has_extern)
{
str += "extern";
if (extern_abi != "")
- {
- str += " \"" + extern_abi + "\"";
- }
+ str += " \"" + extern_abi + "\"";
}
return str;
@@ -2505,13 +2612,9 @@ TraitBound::as_string () const
str += "\n Has opening question mark: ";
if (opening_question_mark)
- {
str += "true";
- }
else
- {
str += "false";
- }
str += "\n For lifetimes: ";
if (!has_for_lifetimes ())
@@ -2521,9 +2624,7 @@ TraitBound::as_string () const
else
{
for (const auto &lifetime : for_lifetimes)
- {
str += "\n " + lifetime.as_string ();
- }
}
str += "\n Type path: " + type_path.as_string ();
@@ -2562,9 +2663,7 @@ MacroMatcher::as_string () const
else
{
for (const auto &match : matches)
- {
- str += "\n " + match->as_string ();
- }
+ str += "\n " + match->as_string ();
}
return str;
@@ -2577,13 +2676,9 @@ LifetimeParam::as_string () const
str += "\n Outer attribute: ";
if (!has_outer_attribute ())
- {
str += "none";
- }
else
- {
str += outer_attr.as_string ();
- }
str += "\n Lifetime: " + lifetime.as_string ();
@@ -2595,9 +2690,7 @@ LifetimeParam::as_string () const
else
{
for (const auto &bound : lifetime_bounds)
- {
- str += "\n " + bound.as_string ();
- }
+ str += "\n " + bound.as_string ();
}
return str;
@@ -2612,12 +2705,12 @@ MacroMatchFragment::as_string () const
std::string
QualifiedPathInType::as_string () const
{
+ /* TODO: this may need adjusting if segments (e.g. with functions) can't be
+ * literalised */
std::string str = path_type.as_string ();
for (const auto &segment : segments)
- {
str += "::" + segment->as_string ();
- }
return str;
}
@@ -2635,20 +2728,14 @@ MacroMatchRepetition::as_string () const
else
{
for (const auto &match : matches)
- {
str += "\n " + match->as_string ();
- }
}
str += "\n Sep: ";
if (!has_sep ())
- {
str += "none";
- }
else
- {
str += sep->as_string ();
- }
str += "\n Op: ";
switch (op)
@@ -2676,9 +2763,7 @@ std::string
Lifetime::as_string () const
{
if (is_error ())
- {
return "error lifetime";
- }
switch (lifetime_type)
{
@@ -2696,17 +2781,15 @@ Lifetime::as_string () const
std::string
TypePath::as_string () const
{
+ /* TODO: this may need to be rewritten if a segment (e.g. function) can't be
+ * literalised */
std::string str;
if (has_opening_scope_resolution)
- {
str = "::";
- }
for (const auto &segment : segments)
- {
str += segment->as_string () + "::";
- }
// kinda hack - remove last 2 '::' characters
str.erase (str.length () - 2);
@@ -2721,13 +2804,9 @@ TypeParam::as_string () const
str += "\n Outer attribute: ";
if (!has_outer_attribute ())
- {
str += "none";
- }
else
- {
str += outer_attr.as_string ();
- }
str += "\n Identifier: " + type_representation;
@@ -2739,20 +2818,14 @@ TypeParam::as_string () const
else
{
for (const auto &bound : type_param_bounds)
- {
str += "\n " + bound->as_string ();
- }
}
str += "\n Type: ";
if (!has_type ())
- {
str += "none";
- }
else
- {
str += type->as_string ();
- }
return str;
}
@@ -2761,9 +2834,7 @@ SimplePath
PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
{
if (!has_segments ())
- {
return SimplePath::create_empty ();
- }
// create vector of reserved size (to minimise reallocations)
std::vector<SimplePathSegment> simple_segments;
@@ -2774,9 +2845,7 @@ PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
// return empty path if doesn't meet simple path segment requirements
if (segment.is_error () || segment.has_generic_args ()
|| segment.as_string () == "Self")
- {
return SimplePath::create_empty ();
- }
// create segment and add to vector
std::string segment_str = segment.as_string ();
@@ -2787,13 +2856,10 @@ PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
// kind of a HACK to get locus depending on opening scope resolution
Location locus = Linemap::unknown_location ();
if (with_opening_scope_resolution)
- {
locus = simple_segments[0].get_locus () - 2; // minus 2 chars for ::
- }
else
- {
locus = simple_segments[0].get_locus ();
- }
+ // FIXME: this hack probably doesn't actually work
return SimplePath (std::move (simple_segments), with_opening_scope_resolution,
locus);
@@ -2803,9 +2869,7 @@ SimplePath
TypePath::as_simple_path () const
{
if (segments.empty ())
- {
return SimplePath::create_empty ();
- }
// create vector of reserved size (to minimise reallocations)
std::vector<SimplePathSegment> simple_segments;
@@ -2816,9 +2880,7 @@ TypePath::as_simple_path () const
// return empty path if doesn't meet simple path segment requirements
if (segment == nullptr || segment->is_error ()
|| !segment->is_ident_only () || segment->as_string () == "Self")
- {
return SimplePath::create_empty ();
- }
// create segment and add to vector
std::string segment_str = segment->as_string ();
@@ -2833,11 +2895,10 @@ TypePath::as_simple_path () const
std::string
PathExprSegment::as_string () const
{
+ // TODO: rewrite dump to work with non-literalisable types
std::string ident_str = segment_name.as_string ();
if (has_generic_args ())
- {
ident_str += "::<" + generic_args.as_string () + ">";
- }
return ident_str;
}
@@ -2895,23 +2956,22 @@ GenericArgs::as_string () const
std::string
GenericArgsBinding::as_string () const
{
+ // TODO: rewrite to work with non-literalisable types
return identifier + " = " + type->as_string ();
}
std::string
ForLoopExpr::as_string () const
{
- std::string str ("ForLoopExpr: ");
+ std::string str = "ForLoopExpr: ";
+
+ str += append_attributes (outer_attrs, OUTER);
str += "\n Label: ";
if (!has_loop_label ())
- {
str += "none";
- }
else
- {
str += loop_label.as_string ();
- }
str += "\n Pattern: " + pattern->as_string ();
@@ -2925,14 +2985,11 @@ ForLoopExpr::as_string () const
std::string
RangePattern::as_string () const
{
+ // TODO: maybe rewrite to work with non-linearisable bounds
if (has_ellipsis_syntax)
- {
return lower->as_string () + "..." + upper->as_string ();
- }
else
- {
return lower->as_string () + "..=" + upper->as_string ();
- }
}
std::string
@@ -2941,9 +2998,7 @@ RangePatternBoundLiteral::as_string () const
std::string str;
if (has_minus)
- {
str += "-";
- }
str += literal.as_string ();
@@ -2956,9 +3011,7 @@ SlicePattern::as_string () const
std::string str ("SlicePattern: ");
for (const auto &pattern : items)
- {
str += "\n " + pattern->as_string ();
- }
return str;
}
@@ -2969,9 +3022,7 @@ TuplePatternItemsMultiple::as_string () const
std::string str;
for (const auto &pattern : patterns)
- {
str += "\n " + pattern->as_string ();
- }
return str;
}
@@ -2989,9 +3040,7 @@ TuplePatternItemsRanged::as_string () const
else
{
for (const auto &lower : lower_patterns)
- {
str += "\n " + lower->as_string ();
- }
}
str += "\n Upper patterns: ";
@@ -3002,9 +3051,7 @@ TuplePatternItemsRanged::as_string () const
else
{
for (const auto &upper : upper_patterns)
- {
str += "\n " + upper->as_string ();
- }
}
return str;
@@ -3020,6 +3067,8 @@ std::string
StructPatternField::as_string () const
{
// outer attributes
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str ("Outer attributes: ");
if (outer_attrs.empty ())
{
@@ -3030,10 +3079,9 @@ StructPatternField::as_string () const
/* note that this does not print them with "outer attribute" syntax -
* just the body */
for (const auto &attr : outer_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
return str;
}
@@ -3046,14 +3094,10 @@ StructPatternFieldIdent::as_string () const
str += "\n";
if (has_ref)
- {
str += "ref ";
- }
if (has_mut)
- {
str += "mut ";
- }
str += ident;
@@ -3063,6 +3107,7 @@ StructPatternFieldIdent::as_string () const
std::string
StructPatternFieldTuplePat::as_string () const
{
+ // TODO: maybe rewrite to work with non-linearisable patterns
std::string str = StructPatternField::as_string ();
str += "\n";
@@ -3075,6 +3120,7 @@ StructPatternFieldTuplePat::as_string () const
std::string
StructPatternFieldIdentPat::as_string () const
{
+ // TODO: maybe rewrite to work with non-linearisable patterns
std::string str = StructPatternField::as_string ();
str += "\n";
@@ -3096,20 +3142,14 @@ StructPatternElements::as_string () const
else
{
for (const auto &field : fields)
- {
str += "\n " + field->as_string ();
- }
}
str += "\n Etc: ";
if (has_struct_pattern_etc)
- {
str += "true";
- }
else
- {
str += "false";
- }
return str;
}
@@ -3123,13 +3163,9 @@ StructPattern::as_string () const
str += "\n Struct pattern elems: ";
if (!has_struct_pattern_elems ())
- {
str += "none";
- }
else
- {
str += elems.as_string ();
- }
return str;
}
@@ -3140,9 +3176,7 @@ LiteralPattern::as_string () const
std::string str;
if (has_minus)
- {
str += "-";
- }
return str + lit.as_string ();
}
@@ -3150,17 +3184,14 @@ LiteralPattern::as_string () const
std::string
ReferencePattern::as_string () const
{
+ // TODO: maybe rewrite to work with non-linearisable patterns
std::string str ("&");
if (has_two_amps)
- {
str += "&";
- }
if (is_mut)
- {
str += "mut ";
- }
str += pattern->as_string ();
@@ -3170,24 +3201,19 @@ ReferencePattern::as_string () const
std::string
IdentifierPattern::as_string () const
{
+ // TODO: maybe rewrite to work with non-linearisable patterns
std::string str;
if (is_ref)
- {
str += "ref ";
- }
if (is_mut)
- {
str += "mut ";
- }
str += variable_ident;
if (has_pattern_to_bind ())
- {
str += " @ " + to_bind->as_string ();
- }
return str;
}
@@ -3198,9 +3224,7 @@ TupleStructItemsNoRange::as_string () const
std::string str;
for (const auto &pattern : patterns)
- {
str += "\n " + pattern->as_string ();
- }
return str;
}
@@ -3217,9 +3241,7 @@ TupleStructItemsRange::as_string () const
else
{
for (const auto &lower : lower_patterns)
- {
str += "\n " + lower->as_string ();
- }
}
str += "\n Upper patterns: ";
@@ -3230,9 +3252,7 @@ TupleStructItemsRange::as_string () const
else
{
for (const auto &upper : upper_patterns)
- {
str += "\n " + upper->as_string ();
- }
}
return str;
@@ -3253,39 +3273,21 @@ TupleStructPattern::as_string () const
std::string
LetStmt::as_string () const
{
- // outer attributes
- std::string str = "Outer attributes: ";
- if (outer_attrs.empty ())
- {
- str += "none";
- }
- else
- {
- /* note that this does not print them with "outer attribute" syntax -
- * just the body */
- indent_spaces (enter);
- for (const auto &attr : outer_attrs)
- {
- str += "\n" + indent_spaces (stay) + attr.as_string ();
- }
- indent_spaces (out);
- }
+ // TODO: rewrite to work with non-linearisable types and exprs
+ std::string str = append_attributes (outer_attrs, OUTER);
str += "\n" + indent_spaces (stay) + "let " + variables_pattern->as_string ();
if (has_type ())
- {
str += " : " + type->as_string ();
- }
if (has_init_expr ())
- {
str += " = " + init_expr->as_string ();
- }
return str;
}
+#if 0
// Used to get outer attributes for expressions.
std::string
Expr::as_string () const
@@ -3301,22 +3303,18 @@ Expr::as_string () const
/* note that this does not print them with "outer attribute" syntax -
* just the body */
for (const auto &attr : outer_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
return str;
}
+#endif
// hopefully definition here will prevent circular dependency issue
TraitBound *
TypePath::to_trait_bound (bool in_parens) const
{
- // create clone FIXME is this required? or is copy constructor automatically
- // called?
- TypePath copy (*this);
- return new TraitBound (std::move (copy), copy.get_locus (), in_parens);
+ return new TraitBound (TypePath (*this), get_locus (), in_parens);
}
std::string
@@ -3328,6 +3326,7 @@ InferredType::as_string () const
std::string
TypeCastExpr::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs and types
return main_or_left_expr->as_string () + " as "
+ type_to_convert_to->as_string ();
}
@@ -3344,9 +3343,7 @@ ImplTraitType::as_string () const
else
{
for (const auto &bound : type_param_bounds)
- {
str += "\n " + bound->as_string ();
- }
}
return str;
@@ -3355,17 +3352,14 @@ ImplTraitType::as_string () const
std::string
ReferenceType::as_string () const
{
+ // TODO: rewrite to work with non-linearisable types
std::string str ("&");
if (has_lifetime ())
- {
str += lifetime.as_string () + " ";
- }
if (has_mut)
- {
str += "mut ";
- }
str += type->as_string ();
@@ -3375,6 +3369,7 @@ ReferenceType::as_string () const
std::string
RawPointerType::as_string () const
{
+ // TODO: rewrite to work with non-linearisable types
std::string str ("*");
switch (pointer_type)
@@ -3400,13 +3395,9 @@ TraitObjectType::as_string () const
std::string str ("TraitObjectType: \n Has dyn dispatch: ");
if (has_dyn)
- {
str += "true";
- }
else
- {
str += "false";
- }
str += "\n TypeParamBounds: ";
if (type_param_bounds.empty ())
@@ -3416,9 +3407,7 @@ TraitObjectType::as_string () const
else
{
for (const auto &bound : type_param_bounds)
- {
str += "\n " + bound->as_string ();
- }
}
return str;
@@ -3436,9 +3425,7 @@ BareFunctionType::as_string () const
else
{
for (const auto &for_lifetime : for_lifetimes)
- {
str += "\n " + for_lifetime.as_string ();
- }
}
str += "\n Qualifiers: " + function_qualifiers.as_string ();
@@ -3451,30 +3438,20 @@ BareFunctionType::as_string () const
else
{
for (const auto &param : params)
- {
str += "\n " + param.as_string ();
- }
}
str += "\n Is variadic: ";
if (is_variadic)
- {
str += "true";
- }
else
- {
str += "false";
- }
str += "\n Return type: ";
if (!has_return_type ())
- {
str += "none (void)";
- }
else
- {
str += return_type->as_string ();
- }
return str;
}
@@ -3490,6 +3467,7 @@ ImplTraitTypeOneBound::as_string () const
std::string
TypePathSegmentGeneric::as_string () const
{
+ // TODO: rewrite to work with non-linearisable types
return TypePathSegment::as_string () + "<" + generic_args.as_string () + ">";
}
@@ -3499,13 +3477,9 @@ TraitObjectTypeOneBound::as_string () const
std::string str ("TraitObjectTypeOneBound: \n Has dyn dispatch: ");
if (has_dyn)
- {
str += "true";
- }
else
- {
str += "false";
- }
str += "\n TraitBound: " + trait_bound.as_string ();
@@ -3515,6 +3489,7 @@ TraitObjectTypeOneBound::as_string () const
std::string
TypePathFunction::as_string () const
{
+ // TODO: rewrite to work with non-linearisable types
std::string str ("(");
if (has_inputs ())
@@ -3533,9 +3508,7 @@ TypePathFunction::as_string () const
str += ")";
if (has_return_type ())
- {
str += " -> " + return_type->as_string ();
- }
return str;
}
@@ -3543,24 +3516,28 @@ TypePathFunction::as_string () const
std::string
TypePathSegmentFunction::as_string () const
{
+ // TODO: rewrite to work with non-linearisable types
return TypePathSegment::as_string () + function_path.as_string ();
}
std::string
ArrayType::as_string () const
{
+ // TODO: rewrite to work with non-linearisable types and exprs
return "[" + elem_type->as_string () + "; " + size->as_string () + "]";
}
std::string
SliceType::as_string () const
{
+ // TODO: rewrite to work with non-linearisable types
return "[" + elem_type->as_string () + "]";
}
std::string
TupleType::as_string () const
{
+ // TODO: rewrite to work with non-linearisable types
std::string str ("(");
if (!is_unit_type ())
@@ -3584,7 +3561,7 @@ TupleType::as_string () const
std::string
StructExpr::as_string () const
{
- std::string str = ExprWithoutBlock::as_string ();
+ std::string str = append_attributes (outer_attrs, OUTER);
indent_spaces (enter);
str += "\n" + indent_spaces (stay) + "StructExpr:";
indent_spaces (enter);
@@ -3611,9 +3588,7 @@ StructExprTuple::as_string () const
// debug - null pointer check
if (*i == nullptr)
- {
return "ERROR_MARK_STRING - nullptr struct expr tuple field";
- }
str += '(';
for (; i != e; i++)
@@ -3649,11 +3624,14 @@ StructExprTuple::as_string () const
std::string
StructExprStruct::as_string () const
{
+ // TODO: doesn't this require data from StructExpr?
std::string str ("StructExprStruct (or subclass): ");
str += "\n Path: " + get_struct_name ().as_string ();
// inner attributes
+ str += append_attributes (inner_attrs, INNER);
+#if 0
str += "\n inner attributes: ";
if (inner_attrs.empty ())
{
@@ -3666,6 +3644,7 @@ StructExprStruct::as_string () const
for (const auto &attr : inner_attrs)
str += "\n " + attr.as_string ();
}
+#endif
return str;
}
@@ -3689,12 +3668,14 @@ StructExprFieldWithVal::as_string () const
std::string
StructExprFieldIdentifierValue::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs
return field_name + " : " + StructExprFieldWithVal::as_string ();
}
std::string
StructExprFieldIndexValue::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs
return std::to_string (index) + " : " + StructExprFieldWithVal::as_string ();
}
@@ -3726,7 +3707,7 @@ StructExprStructFields::as_string () const
std::string
EnumExprStruct::as_string () const
{
- std::string str ("StructExprStruct (or subclass): ");
+ std::string str ("EnumExprStruct (or subclass): ");
str += "\n Path: " + get_enum_variant_path ().as_string ();
@@ -3754,12 +3735,14 @@ EnumExprFieldWithVal::as_string () const
std::string
EnumExprFieldIdentifierValue::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs
return field_name + " : " + EnumExprFieldWithVal::as_string ();
}
std::string
EnumExprFieldIndexValue::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs
return std::to_string (index) + " : " + EnumExprFieldWithVal::as_string ();
}
@@ -3767,6 +3750,8 @@ std::string
EnumItem::as_string () const
{
// outer attributes
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -3779,6 +3764,7 @@ EnumItem::as_string () const
for (const auto &attr : outer_attrs)
str += "\n " + attr.as_string ();
}
+#endif
str += "\n" + variant_name;
@@ -3816,7 +3802,11 @@ EnumItemTuple::as_string () const
std::string
TupleField::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs
+
// outer attributes
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -3827,15 +3817,12 @@ TupleField::as_string () const
/* note that this does not print them with "outer attribute" syntax -
* just the body */
for (const auto &attr : outer_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
if (has_visibility ())
- {
str += "\n" + visibility.as_string ();
- }
str += " " + field_type->as_string ();
@@ -3873,7 +3860,10 @@ EnumItemStruct::as_string () const
std::string
StructField::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs
// outer attributes
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -3884,15 +3874,12 @@ StructField::as_string () const
/* note that this does not print them with "outer attribute" syntax -
* just the body */
for (const auto &attr : outer_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
if (has_visibility ())
- {
str += "\n" + visibility.as_string ();
- }
str += " " + field_name + " : " + field_type->as_string ();
@@ -3902,6 +3889,7 @@ StructField::as_string () const
std::string
EnumItemDiscriminant::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs
std::string str = EnumItem::as_string ();
// add equal and expression
@@ -3939,6 +3927,8 @@ std::string
ExternalStaticItem::as_string () const
{
// outer attributes
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -3951,6 +3941,7 @@ ExternalStaticItem::as_string () const
for (const auto &attr : outer_attrs)
str += "\n " + attr.as_string ();
}
+#endif
// start visibility on new line and with a space
str += "\n" + visibility.as_string () + " ";
@@ -3973,6 +3964,8 @@ std::string
ExternalFunctionItem::as_string () const
{
// outer attributes
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -3985,6 +3978,7 @@ ExternalFunctionItem::as_string () const
for (const auto &attr : outer_attrs)
str += "\n " + attr.as_string ();
}
+#endif
// start visibility on new line and with a space
str += "\n" + visibility.as_string () + " ";
@@ -4011,7 +4005,7 @@ ExternalFunctionItem::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in external function item.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -4061,6 +4055,8 @@ ExternalFunctionItem::as_string () const
std::string
NamedFunctionParam::as_string () const
{
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (!has_outer_attrs ())
@@ -4072,6 +4068,7 @@ NamedFunctionParam::as_string () const
for (const auto &attr : outer_attrs)
str += "\n " + attr.as_string ();
}
+#endif
str += "\n" + name;
@@ -4098,6 +4095,8 @@ attr.as_string();
std::string
TraitItemFunc::as_string () const
{
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -4108,22 +4107,17 @@ TraitItemFunc::as_string () const
/* note that this does not print them with "outer attribute" syntax -
* just the body */
for (const auto &attr : outer_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
str += "\n" + decl.as_string ();
str += "\n Definition (block expr): ";
if (has_definition ())
- {
str += block_expr->as_string ();
- }
else
- {
str += "none";
- }
return str;
}
@@ -4150,7 +4144,7 @@ TraitFunctionDecl::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in trait function decl.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -4161,9 +4155,7 @@ TraitFunctionDecl::as_string () const
if (has_params ())
{
for (const auto &param : function_params)
- {
str += "\n " + param.as_string ();
- }
}
else
{
@@ -4172,23 +4164,15 @@ TraitFunctionDecl::as_string () const
str += "\n Return type: ";
if (has_return_type ())
- {
str += return_type->as_string ();
- }
else
- {
str += "none (void)";
- }
str += "\n Where clause: ";
if (has_where_clause ())
- {
str += where_clause.as_string ();
- }
else
- {
str += "none";
- }
return str;
}
@@ -4196,6 +4180,8 @@ TraitFunctionDecl::as_string () const
std::string
TraitItemMethod::as_string () const
{
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -4206,22 +4192,17 @@ TraitItemMethod::as_string () const
/* note that this does not print them with "outer attribute" syntax -
* just the body */
for (const auto &attr : outer_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
str += "\n" + decl.as_string ();
str += "\n Definition (block expr): ";
if (has_definition ())
- {
str += block_expr->as_string ();
- }
else
- {
str += "none";
- }
return str;
}
@@ -4248,7 +4229,7 @@ TraitMethodDecl::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"generic param in trait function decl.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + param->as_string ();
@@ -4261,9 +4242,7 @@ TraitMethodDecl::as_string () const
if (has_params ())
{
for (const auto &param : function_params)
- {
str += "\n " + param.as_string ();
- }
}
else
{
@@ -4272,23 +4251,15 @@ TraitMethodDecl::as_string () const
str += "\n Return type: ";
if (has_return_type ())
- {
str += return_type->as_string ();
- }
else
- {
str += "none (void)";
- }
str += "\n Where clause: ";
if (has_where_clause ())
- {
str += where_clause.as_string ();
- }
else
- {
str += "none";
- }
return str;
}
@@ -4296,6 +4267,9 @@ TraitMethodDecl::as_string () const
std::string
TraitItemConst::as_string () const
{
+ // TODO: rewrite to work with non-linearisable exprs
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -4306,17 +4280,14 @@ TraitItemConst::as_string () const
/* note that this does not print them with "outer attribute" syntax -
* just the body */
for (const auto &attr : outer_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
str += "\nconst " + name + " : " + type->as_string ();
if (has_expression ())
- {
str += " = " + expr->as_string ();
- }
return str;
}
@@ -4324,6 +4295,8 @@ TraitItemConst::as_string () const
std::string
TraitItemType::as_string () const
{
+ std::string str = append_attributes (outer_attrs, OUTER);
+#if 0
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
@@ -4334,10 +4307,9 @@ TraitItemType::as_string () const
/* note that this does not print them with "outer attribute" syntax -
* just the body */
for (const auto &attr : outer_attrs)
- {
str += "\n " + attr.as_string ();
- }
}
+#endif
str += "\ntype " + name;
@@ -4357,7 +4329,7 @@ TraitItemType::as_string () const
stderr,
"something really terrible has gone wrong - null pointer "
"type param bound in trait item type.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + bound->as_string ();
@@ -4370,6 +4342,7 @@ TraitItemType::as_string () const
std::string
SelfParam::as_string () const
{
+ // TODO: rewrite to allow non-linearisable types
if (is_error ())
{
return "error";
@@ -4382,9 +4355,7 @@ SelfParam::as_string () const
std::string str;
if (is_mut)
- {
str += "mut ";
- }
str += "self : ";
@@ -4398,9 +4369,7 @@ SelfParam::as_string () const
std::string str = "&" + lifetime.as_string () + " ";
if (is_mut)
- {
str += "mut ";
- }
str += "self";
@@ -4412,9 +4381,7 @@ SelfParam::as_string () const
std::string str = "&";
if (is_mut)
- {
str += " mut ";
- }
str += "self";
@@ -4426,9 +4393,7 @@ SelfParam::as_string () const
std::string str;
if (is_mut)
- {
str += "mut ";
- }
str += "self";
@@ -4440,6 +4405,7 @@ SelfParam::as_string () const
std::string
ArrayElemsCopied::as_string () const
{
+ // TODO: rewrite to allow non-linearisable exprs
return elem_to_copy->as_string () + "; " + num_copies->as_string ();
}
@@ -4453,9 +4419,7 @@ LifetimeWhereClauseItem::as_string () const
str += "\nLifetime bounds: ";
for (const auto &bound : lifetime_bounds)
- {
str += "\n " + bound.as_string ();
- }
return str;
}
@@ -4472,9 +4436,7 @@ TypeBoundWhereClauseItem::as_string () const
else
{
for (const auto &for_lifetime : for_lifetimes)
- {
str += "\n " + for_lifetime.as_string ();
- }
}
str += "\nType: " + bound_type->as_string ();
@@ -4485,9 +4447,7 @@ TypeBoundWhereClauseItem::as_string () const
{
// debug null pointer check
if (bound == nullptr)
- {
- return "nullptr_POINTER_MARK - type param bounds";
- }
+ return "NULL_POINTER_MARK - type param bounds";
str += "\n " + bound->as_string ();
}
@@ -4508,7 +4468,7 @@ ArrayElemsValues::as_string () const
fprintf (stderr,
"something really terrible has gone wrong - null pointer "
"expr in array elems values.");
- return "nullptr_POINTER_MARK";
+ return "NULL_POINTER_MARK";
}
str += "\n " + expr->as_string ();
@@ -4520,6 +4480,7 @@ ArrayElemsValues::as_string () const
std::string
MaybeNamedParam::as_string () const
{
+ // TODO: rewrite to allow using non-linearisable types in dump
std::string str;
switch (param_kind)
@@ -4838,7 +4799,7 @@ MacroParser::parse_path_meta_item ()
"failed to parse literal in attribute");
return nullptr;
}
- LiteralExpr expr (std::move (lit), locus);
+ LiteralExpr expr (std::move (lit), {}, locus);
// stream_pos++;
/* shouldn't be required anymore due to parsing literal actually
* skipping the token */
@@ -4893,9 +4854,8 @@ MacroParser::parse_meta_item_seq ()
meta_items.push_back (std::move (inner));
if (peek_token ()->get_id () != COMMA)
- {
break;
- }
+
skip_token ();
}
@@ -5056,7 +5016,7 @@ std::unique_ptr<MetaItemLitExpr>
MacroParser::parse_meta_item_lit ()
{
Location locus = peek_token ()->get_locus ();
- LiteralExpr lit_expr (parse_literal (), locus);
+ LiteralExpr lit_expr (parse_literal (), {}, locus);
return std::unique_ptr<MetaItemLitExpr> (
new MetaItemLitExpr (std::move (lit_expr)));
}
@@ -5294,7 +5254,7 @@ Attribute
MetaNameValueStr::to_attribute () const
{
LiteralExpr lit_expr (str, Literal::LitType::STRING,
- PrimitiveCoreType::CORETYPE_UNKNOWN, Location ());
+ PrimitiveCoreType::CORETYPE_UNKNOWN, {}, Location ());
return Attribute (SimplePath::from_str (ident),
std::unique_ptr<AttrInputLiteral> (
new AttrInputLiteral (std::move (lit_expr))));
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index b7baab4..9c7c567 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -846,14 +846,7 @@ class ExprWithoutBlock;
// Base expression AST node - abstract
class Expr
{
- // TODO: move outer attribute data to derived classes?
- std::vector<Attribute> outer_attrs;
-
public:
- // TODO: this mutable getter seems really dodgy. Think up better way.
- const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
- std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
-
// Unique pointer custom clone function
std::unique_ptr<Expr> clone_expr () const
{
@@ -869,8 +862,7 @@ public:
* overrided in subclasses of ExprWithoutBlock */
virtual ExprWithoutBlock *as_expr_without_block () const { return nullptr; }
- // TODO: make pure virtual if move out outer attributes to derived classes
- virtual std::string as_string () const;
+ virtual std::string as_string () const = 0;
virtual ~Expr () {}
@@ -890,9 +882,7 @@ public:
protected:
// Constructor
- Expr (std::vector<Attribute> outer_attribs = std::vector<Attribute> ())
- : outer_attrs (std::move (outer_attribs)),
- node_id (Analysis::Mappings::get ()->get_next_node_id ())
+ Expr () : node_id (Analysis::Mappings::get ()->get_next_node_id ())
{}
// Clone function implementation as pure virtual method
@@ -900,10 +890,7 @@ protected:
// TODO: think of less hacky way to implement this kind of thing
// Sets outer attributes.
- void set_outer_attrs (std::vector<Attribute> outer_attrs_to_set)
- {
- outer_attrs = std::move (outer_attrs_to_set);
- }
+ virtual void set_outer_attrs (std::vector<Attribute>) = 0;
NodeId node_id;
};
@@ -912,12 +899,6 @@ protected:
class ExprWithoutBlock : public Expr
{
protected:
- // Constructor
- ExprWithoutBlock (std::vector<Attribute> outer_attribs
- = std::vector<Attribute> ())
- : Expr (std::move (outer_attribs))
- {}
-
// pure virtual clone implementation
virtual ExprWithoutBlock *clone_expr_without_block_impl () const = 0;
@@ -952,15 +933,13 @@ public:
*/
class IdentifierExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
Identifier ident;
Location locus;
public:
- IdentifierExpr (Identifier ident, Location locus = Location (),
- std::vector<Attribute> outer_attrs
- = std::vector<Attribute> ())
- : ExprWithoutBlock (std::move (outer_attrs)), ident (std::move (ident)),
- locus (locus)
+ IdentifierExpr (Identifier ident, std::vector<Attribute> outer_attrs, Location locus)
+ : outer_attrs (std::move (outer_attrs)), ident (std::move (ident)), locus (locus)
{}
std::string as_string () const override { return ident; }
@@ -982,6 +961,11 @@ public:
void mark_for_strip () override { ident = {}; }
bool is_marked_for_strip () const override { return ident.empty (); }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
// Clone method implementation
IdentifierExpr *clone_expr_without_block_impl () const final override
@@ -1677,22 +1661,7 @@ public:
// Base path expression AST node - abstract
class PathExpr : public ExprWithoutBlock
-{
-protected:
- PathExpr (std::vector<Attribute> outer_attribs)
- : ExprWithoutBlock (std::move (outer_attribs))
- {}
-
-public:
- // TODO: think of a better and less hacky way to allow this
-
- /* Replaces the outer attributes of this path expression with the given outer
- * attributes. */
- void replace_outer_attrs (std::vector<Attribute> outer_attrs)
- {
- set_outer_attrs (std::move (outer_attrs));
- }
-};
+{};
} // namespace AST
} // namespace Rust
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index cfb4228..5177785 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -13,12 +13,7 @@ namespace AST {
// AST node for an expression with an accompanying block - abstract
class ExprWithBlock : public Expr
{
- // TODO: should this mean that a BlockExpr should be a member variable?
protected:
- ExprWithBlock (std::vector<Attribute> outer_attrs = std::vector<Attribute> ())
- : Expr (std::move (outer_attrs))
- {}
-
// pure virtual clone implementation
virtual ExprWithBlock *clone_expr_with_block_impl () const = 0;
@@ -41,6 +36,7 @@ public:
// Literals? Or literal base?
class LiteralExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
Literal literal;
Location locus;
@@ -50,15 +46,15 @@ public:
Literal::LitType get_lit_type () const { return literal.get_lit_type (); }
LiteralExpr (std::string value_as_string, Literal::LitType type,
- PrimitiveCoreType type_hint, Location locus,
- std::vector<Attribute> outer_attrs = std::vector<Attribute> ())
- : ExprWithoutBlock (std::move (outer_attrs)),
+ PrimitiveCoreType type_hint,
+ std::vector<Attribute> outer_attrs, Location locus)
+ : outer_attrs (std::move (outer_attrs)),
literal (std::move (value_as_string), type, type_hint), locus (locus)
{}
- LiteralExpr (Literal literal, Location locus,
- std::vector<Attribute> outer_attrs = std::vector<Attribute> ())
- : ExprWithoutBlock (std::move (outer_attrs)), literal (std::move (literal)),
+ LiteralExpr (Literal literal,
+ std::vector<Attribute> outer_attrs, Location locus)
+ : outer_attrs (std::move (outer_attrs)), literal (std::move (literal)),
locus (locus)
{}
@@ -79,6 +75,11 @@ public:
void mark_for_strip () override { literal = Literal::create_error (); }
bool is_marked_for_strip () const override { return literal.is_error (); }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -196,20 +197,21 @@ public:
Location locus;
protected:
- /* Variable must be protected to allow derived classes to use it as a first
- * class citizen */
+ /* Variables must be protected to allow derived classes to use them as first
+ * class citizens */
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> main_or_left_expr;
// Constructor (only for initialisation of expr purposes)
OperatorExpr (std::unique_ptr<Expr> main_or_left_expr,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)), locus (locus),
+ : locus (locus), outer_attrs (std::move (outer_attribs)),
main_or_left_expr (std::move (main_or_left_expr))
{}
// Copy constructor (only for initialisation of expr purposes)
OperatorExpr (OperatorExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus)
+ : locus (other.locus), outer_attrs (other.outer_attrs)
{
// guard to prevent null dereference (only required if error state)
if (other.main_or_left_expr != nullptr)
@@ -221,7 +223,7 @@ protected:
{
ExprWithoutBlock::operator= (other);
locus = other.locus;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to prevent null dereference (only required if error state)
if (other.main_or_left_expr != nullptr)
@@ -246,6 +248,11 @@ public:
{
return main_or_left_expr == nullptr;
}
+
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
};
/* Unary prefix & or &mut (or && and &&mut) borrow operator. Cannot be
@@ -859,6 +866,7 @@ protected:
// Expression in parentheses (i.e. like literally just any 3 + (2 * 6))
class GroupedExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::vector<Attribute> inner_attrs;
std::unique_ptr<Expr> expr_in_parens;
Location locus;
@@ -869,17 +877,22 @@ public:
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
GroupedExpr (std::unique_ptr<Expr> parenthesised_expr,
std::vector<Attribute> inner_attribs,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
inner_attrs (std::move (inner_attribs)),
expr_in_parens (std::move (parenthesised_expr)), locus (locus)
{}
// Copy constructor includes clone for expr_in_parens
GroupedExpr (GroupedExpr const &other)
- : ExprWithoutBlock (other), inner_attrs (other.inner_attrs),
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), inner_attrs (other.inner_attrs),
locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
@@ -893,7 +906,7 @@ public:
ExprWithoutBlock::operator= (other);
inner_attrs = other.inner_attrs;
locus = other.locus;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to prevent null dereference (only required if error state)
if (other.expr_in_parens != nullptr)
@@ -1090,9 +1103,9 @@ protected:
// Array definition-ish expression
class ArrayExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::vector<Attribute> inner_attrs;
std::unique_ptr<ArrayElems> internal_elements;
-
Location locus;
// TODO: find another way to store this to save memory?
@@ -1104,6 +1117,11 @@ public:
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
// Returns whether array expr has array elems or if it is just empty.
bool has_array_elems () const { return internal_elements != nullptr; }
@@ -1111,14 +1129,14 @@ public:
ArrayExpr (std::unique_ptr<ArrayElems> array_elems,
std::vector<Attribute> inner_attribs,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
inner_attrs (std::move (inner_attribs)),
internal_elements (std::move (array_elems)), locus (locus)
{}
// Copy constructor requires cloning ArrayElems for polymorphism to hold
ArrayExpr (ArrayExpr const &other)
- : ExprWithoutBlock (other), inner_attrs (other.inner_attrs),
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), inner_attrs (other.inner_attrs),
locus (other.locus), marked_for_strip (other.marked_for_strip)
{
if (other.has_array_elems ())
@@ -1132,7 +1150,7 @@ public:
inner_attrs = other.inner_attrs;
locus = other.locus;
marked_for_strip = other.marked_for_strip;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
if (other.has_array_elems ())
internal_elements = other.internal_elements->clone_array_elems ();
@@ -1178,9 +1196,9 @@ protected:
* implementation */
class ArrayIndexExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> array_expr;
std::unique_ptr<Expr> index_expr;
-
Location locus;
public:
@@ -1189,14 +1207,14 @@ public:
ArrayIndexExpr (std::unique_ptr<Expr> array_expr,
std::unique_ptr<Expr> array_index_expr,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
array_expr (std::move (array_expr)),
index_expr (std::move (array_index_expr)), locus (locus)
{}
// Copy constructor requires special cloning due to unique_ptr
ArrayIndexExpr (ArrayIndexExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus)
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
if (other.array_expr != nullptr)
@@ -1209,7 +1227,7 @@ public:
ArrayIndexExpr &operator= (ArrayIndexExpr const &other)
{
ExprWithoutBlock::operator= (other);
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
locus = other.locus;
// guard to prevent null dereference (only required if error state)
@@ -1259,6 +1277,11 @@ public:
return index_expr;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1271,11 +1294,9 @@ protected:
// AST representation of a tuple
class TupleExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::vector<Attribute> inner_attrs;
-
std::vector<std::unique_ptr<Expr> > tuple_elems;
- // replaces (inlined version of) TupleElements
-
Location locus;
// TODO: find another way to store this to save memory?
@@ -1287,17 +1308,22 @@ public:
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
TupleExpr (std::vector<std::unique_ptr<Expr> > tuple_elements,
std::vector<Attribute> inner_attribs,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
inner_attrs (std::move (inner_attribs)),
tuple_elems (std::move (tuple_elements)), locus (locus)
{}
// copy constructor with vector clone
TupleExpr (TupleExpr const &other)
- : ExprWithoutBlock (other), inner_attrs (other.inner_attrs),
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), inner_attrs (other.inner_attrs),
locus (other.locus), marked_for_strip (other.marked_for_strip)
{
tuple_elems.reserve (other.tuple_elems.size ());
@@ -1309,6 +1335,7 @@ public:
TupleExpr &operator= (TupleExpr const &other)
{
ExprWithoutBlock::operator= (other);
+ outer_attrs = other.outer_attrs;
inner_attrs = other.inner_attrs;
locus = other.locus;
marked_for_strip = other.marked_for_strip;
@@ -1359,6 +1386,7 @@ protected:
// AST representation of a tuple indexing expression
class TupleIndexExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> tuple_expr;
// TupleIndex is a decimal int literal with no underscores or suffix
TupleIndex tuple_index;
@@ -1374,13 +1402,13 @@ public:
TupleIndexExpr (std::unique_ptr<Expr> tuple_expr, TupleIndex index,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
{}
// Copy constructor requires a clone for tuple_expr
TupleIndexExpr (TupleIndexExpr const &other)
- : ExprWithoutBlock (other), tuple_index (other.tuple_index),
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), tuple_index (other.tuple_index),
locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
@@ -1394,7 +1422,7 @@ public:
ExprWithoutBlock::operator= (other);
tuple_index = other.tuple_index;
locus = other.locus;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to prevent null dereference (only required if error state)
if (other.tuple_expr != nullptr)
@@ -1425,6 +1453,11 @@ public:
return tuple_expr;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -1437,13 +1470,14 @@ protected:
// Base struct/tuple/union value creator AST node (abstract)
class StructExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
PathInExpression struct_name;
protected:
// Protected constructor to allow initialising struct_name
StructExpr (PathInExpression struct_path,
std::vector<Attribute> outer_attribs)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
struct_name (std::move (struct_path))
{}
@@ -1459,6 +1493,11 @@ public:
struct_name = PathInExpression::create_error ();
}
bool is_marked_for_strip () const override { return struct_name.is_error (); }
+
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
};
// Actual AST node of the struct creator (with no fields). Not abstract!
@@ -1936,13 +1975,14 @@ protected:
// Base AST node representing creation of an enum variant instance - abstract
class EnumVariantExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
PathInExpression enum_variant_path;
protected:
// Protected constructor for initialising enum_variant_path
EnumVariantExpr (PathInExpression path_to_enum_variant,
std::vector<Attribute> outer_attribs)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
enum_variant_path (std::move (path_to_enum_variant))
{}
@@ -1962,6 +2002,11 @@ public:
{
return enum_variant_path.is_error ();
}
+
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
};
/* Base AST node for a single enum expression field (in enum instance creation)
@@ -2183,7 +2228,6 @@ protected:
class EnumExprTuple : public EnumVariantExpr
{
std::vector<std::unique_ptr<Expr> > values;
-
Location locus;
public:
@@ -2282,10 +2326,9 @@ class Function;
// Function call expression AST node
class CallExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> function;
- // inlined form of CallParams
std::vector<std::unique_ptr<Expr> > params;
-
Location locus;
public:
@@ -2296,14 +2339,14 @@ public:
CallExpr (std::unique_ptr<Expr> function_expr,
std::vector<std::unique_ptr<Expr> > function_params,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
function (std::move (function_expr)),
params (std::move (function_params)), locus (locus)
{}
// copy constructor requires clone
CallExpr (CallExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus)
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
if (other.function != nullptr)
@@ -2319,7 +2362,7 @@ public:
{
ExprWithoutBlock::operator= (other);
locus = other.locus;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to prevent null dereference (only required if error state)
if (other.function != nullptr)
@@ -2373,6 +2416,11 @@ public:
return function;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2385,11 +2433,10 @@ protected:
// Method call expression AST node
class MethodCallExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> receiver;
PathExprSegment method_name;
- // inlined form of CallParams
std::vector<std::unique_ptr<Expr> > params;
-
Location locus;
public:
@@ -2399,7 +2446,7 @@ public:
PathExprSegment method_path,
std::vector<std::unique_ptr<Expr> > method_params,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
receiver (std::move (call_receiver)),
method_name (std::move (method_path)), params (std::move (method_params)),
locus (locus)
@@ -2407,7 +2454,7 @@ public:
// copy constructor required due to cloning
MethodCallExpr (MethodCallExpr const &other)
- : ExprWithoutBlock (other), method_name (other.method_name),
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), method_name (other.method_name),
locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
@@ -2425,7 +2472,7 @@ public:
ExprWithoutBlock::operator= (other);
method_name = other.method_name;
locus = other.locus;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to prevent null dereference (only required if error state)
if (other.receiver != nullptr)
@@ -2470,6 +2517,11 @@ public:
const PathExprSegment &get_method_name () const { return method_name; }
PathExprSegment &get_method_name () { return method_name; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2483,9 +2535,9 @@ protected:
// Struct or union field access expression AST node
class FieldAccessExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> receiver;
Identifier field;
-
Location locus;
public:
@@ -2494,14 +2546,14 @@ public:
FieldAccessExpr (std::unique_ptr<Expr> field_access_receiver,
Identifier field_name, std::vector<Attribute> outer_attribs,
Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
receiver (std::move (field_access_receiver)),
field (std::move (field_name)), locus (locus)
{}
// Copy constructor required due to unique_ptr cloning
FieldAccessExpr (FieldAccessExpr const &other)
- : ExprWithoutBlock (other), field (other.field), locus (other.locus)
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), field (other.field), locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
if (other.receiver != nullptr)
@@ -2514,7 +2566,7 @@ public:
ExprWithoutBlock::operator= (other);
field = other.field;
locus = other.locus;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to prevent null dereference (only required if error state)
if (other.receiver != nullptr)
@@ -2547,6 +2599,11 @@ public:
Identifier get_field_name () const { return field; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2645,17 +2702,15 @@ public:
// Base closure definition expression AST node - abstract
class ClosureExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
bool has_move;
std::vector<ClosureParam> params; // may be empty
- /* also note a double pipe "||" can be used for empty params - does not need a
- * space */
-
Location locus;
protected:
ClosureExpr (std::vector<ClosureParam> closure_params, bool has_move,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithoutBlock (std::move (outer_attribs)), has_move (has_move),
+ : outer_attrs (std::move (outer_attribs)), has_move (has_move),
params (std::move (closure_params)), locus (locus)
{}
@@ -2668,6 +2723,11 @@ public:
// TODO: this mutable getter seems really dodgy. Think up better way.
const std::vector<ClosureParam> &get_params () const { return params; }
std::vector<ClosureParam> &get_params () { return params; }
+
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
};
// Represents a non-type-specified closure expression AST node
@@ -2746,13 +2806,10 @@ protected:
// A block AST node
class BlockExpr : public ExprWithBlock
{
+ std::vector<Attribute> outer_attrs;
std::vector<Attribute> inner_attrs;
-
- // bool has_statements;
std::vector<std::unique_ptr<Stmt> > statements;
- // bool has_expr;
- std::unique_ptr<ExprWithoutBlock> expr; // inlined from Statements
-
+ std::unique_ptr<ExprWithoutBlock> expr;
Location locus;
bool marked_for_strip = false;
@@ -2769,7 +2826,7 @@ public:
std::unique_ptr<ExprWithoutBlock> block_expr,
std::vector<Attribute> inner_attribs,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
inner_attrs (std::move (inner_attribs)),
statements (std::move (block_statements)), expr (std::move (block_expr)),
locus (locus)
@@ -2777,7 +2834,7 @@ public:
// Copy constructor with clone
BlockExpr (BlockExpr const &other)
- : ExprWithBlock (other), inner_attrs (other.inner_attrs),
+ : ExprWithBlock (other), outer_attrs (other.outer_attrs), inner_attrs (other.inner_attrs),
locus (other.locus), marked_for_strip (other.marked_for_strip)
{
// guard to protect from null pointer dereference
@@ -2796,7 +2853,7 @@ public:
inner_attrs = other.inner_attrs;
locus = other.locus;
marked_for_strip = other.marked_for_strip;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to protect from null pointer dereference
if (other.expr != nullptr)
@@ -2861,6 +2918,11 @@ public:
// Removes the tail expression from the block.
void strip_tail_expr () { expr = nullptr; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -2970,7 +3032,7 @@ protected:
// AST node representing continue expression within loops
class ContinueExpr : public ExprWithoutBlock
{
- // bool has_label;
+ std::vector<Attribute> outer_attrs;
Lifetime label;
Location locus;
@@ -2984,10 +3046,9 @@ public:
bool has_label () const { return !label.is_error (); }
// Constructor for a ContinueExpr with a label.
- ContinueExpr (Location locus, Lifetime label = Lifetime::error (),
- std::vector<Attribute> outer_attribs
- = std::vector<Attribute> ())
- : ExprWithoutBlock (std::move (outer_attribs)), label (std::move (label)),
+ ContinueExpr (Lifetime label,
+ std::vector<Attribute> outer_attribs, Location locus)
+ : outer_attrs (std::move (outer_attribs)), label (std::move (label)),
locus (locus)
{}
@@ -3000,6 +3061,11 @@ public:
void mark_for_strip () override { marked_for_strip = true; }
bool is_marked_for_strip () const override { return marked_for_strip; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3013,12 +3079,9 @@ protected:
// AST node representing break expression within loops
class BreakExpr : public ExprWithoutBlock
{
- // bool has_label;
+ std::vector<Attribute> outer_attrs;
Lifetime label;
-
- // bool has_break_expr;
std::unique_ptr<Expr> break_expr;
-
Location locus;
// TODO: find another way to store this to save memory?
@@ -3035,17 +3098,17 @@ public:
bool has_break_expr () const { return break_expr != nullptr; }
// Constructor for a break expression
- BreakExpr (Location locus, Lifetime break_label = Lifetime::error (),
- std::unique_ptr<Expr> expr_in_break = nullptr,
- std::vector<Attribute> outer_attribs = std::vector<Attribute> ())
- : ExprWithoutBlock (std::move (outer_attribs)),
+ BreakExpr (Lifetime break_label,
+ std::unique_ptr<Expr> expr_in_break,
+ std::vector<Attribute> outer_attribs, Location locus)
+ : outer_attrs (std::move (outer_attribs)),
label (std::move (break_label)), break_expr (std::move (expr_in_break)),
locus (locus)
{}
// Copy constructor defined to use clone for unique pointer
BreakExpr (BreakExpr const &other)
- : ExprWithoutBlock (other), label (other.label), locus (other.locus),
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), label (other.label), locus (other.locus),
marked_for_strip (other.marked_for_strip)
{
// guard to protect from null pointer dereference
@@ -3060,7 +3123,7 @@ public:
label = other.label;
locus = other.locus;
marked_for_strip = other.marked_for_strip;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to protect from null pointer dereference
if (other.break_expr != nullptr)
@@ -3091,6 +3154,11 @@ public:
return break_expr;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3107,13 +3175,14 @@ class RangeExpr : public ExprWithoutBlock
protected:
// outer attributes not allowed before range expressions
- RangeExpr (Location locus)
- : ExprWithoutBlock (std::vector<Attribute> ()), locus (locus)
- {}
+ RangeExpr (Location locus) : locus (locus) {}
public:
Location get_locus () const { return locus; }
Location get_locus_slow () const final override { return get_locus (); }
+
+ // should never be called - error if called
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { rust_assert (false); }
};
// Range from (inclusive) and to (exclusive) expression AST node object
@@ -3501,8 +3570,8 @@ protected:
// Return expression AST node representation
class ReturnExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> return_expr;
-
Location locus;
// TODO: find another way to store this to save memory?
@@ -3516,15 +3585,15 @@ public:
bool has_returned_expr () const { return return_expr != nullptr; }
// Constructor for ReturnExpr.
- ReturnExpr (Location locus, std::unique_ptr<Expr> returned_expr = nullptr,
- std::vector<Attribute> outer_attribs = std::vector<Attribute> ())
- : ExprWithoutBlock (std::move (outer_attribs)),
+ ReturnExpr (std::unique_ptr<Expr> returned_expr,
+ std::vector<Attribute> outer_attribs, Location locus)
+ : outer_attrs (std::move (outer_attribs)),
return_expr (std::move (returned_expr)), locus (locus)
{}
// Copy constructor with clone
ReturnExpr (ReturnExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus),
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), locus (other.locus),
marked_for_strip (other.marked_for_strip)
{
// guard to protect from null pointer dereference
@@ -3538,7 +3607,7 @@ public:
ExprWithoutBlock::operator= (other);
locus = other.locus;
marked_for_strip = other.marked_for_strip;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to protect from null pointer dereference
if (other.return_expr != nullptr)
@@ -3569,6 +3638,11 @@ public:
return return_expr;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3584,6 +3658,7 @@ class MacroInvocation;
// An unsafe block AST node
class UnsafeBlockExpr : public ExprWithBlock
{
+ std::vector<Attribute> outer_attrs;
// Or just have it extend BlockExpr
std::unique_ptr<BlockExpr> expr;
Location locus;
@@ -3593,13 +3668,13 @@ public:
UnsafeBlockExpr (std::unique_ptr<BlockExpr> block_expr,
std::vector<Attribute> outer_attribs, Location locus)
- : ExprWithBlock (std::move (outer_attribs)), expr (std::move (block_expr)),
+ : outer_attrs (std::move (outer_attribs)), expr (std::move (block_expr)),
locus (locus)
{}
// Copy constructor with clone
UnsafeBlockExpr (UnsafeBlockExpr const &other)
- : ExprWithBlock (other), locus (other.locus)
+ : ExprWithBlock (other), outer_attrs (other.outer_attrs), locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
if (other.expr != nullptr)
@@ -3611,7 +3686,7 @@ public:
{
ExprWithBlock::operator= (other);
locus = other.locus;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to prevent null dereference (only required if error state)
if (other.expr != nullptr)
@@ -3642,6 +3717,11 @@ public:
return expr;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3679,9 +3759,8 @@ class BaseLoopExpr : public ExprWithBlock
{
protected:
// protected to allow subclasses better use of them
- // bool has_loop_label;
+ std::vector<Attribute> outer_attrs;
LoopLabel loop_label;
-
std::unique_ptr<BlockExpr> loop_block;
private:
@@ -3693,14 +3772,14 @@ protected:
LoopLabel loop_label = LoopLabel::error (),
std::vector<Attribute> outer_attribs
= std::vector<Attribute> ())
- : ExprWithBlock (std::move (outer_attribs)),
+ : outer_attrs (std::move (outer_attribs)),
loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
locus (locus)
{}
// Copy constructor for BaseLoopExpr with clone
BaseLoopExpr (BaseLoopExpr const &other)
- : ExprWithBlock (other), loop_label (other.loop_label), locus (other.locus)
+ : ExprWithBlock (other), outer_attrs (other.outer_attrs), loop_label (other.loop_label), locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
if (other.loop_block != nullptr)
@@ -3713,7 +3792,7 @@ protected:
ExprWithBlock::operator= (other);
loop_label = other.loop_label;
locus = other.locus;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
// guard to prevent null dereference (only required if error state)
if (other.loop_block != nullptr)
@@ -3744,6 +3823,11 @@ public:
rust_assert (loop_block != nullptr);
return loop_block;
}
+
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
};
// 'Loop' expression (i.e. the infinite loop) AST node
@@ -3989,7 +4073,6 @@ class IfExpr : public ExprWithBlock
{
std::unique_ptr<Expr> condition;
std::unique_ptr<BlockExpr> if_block;
-
Location locus;
public:
@@ -3997,8 +4080,7 @@ public:
IfExpr (std::unique_ptr<Expr> condition, std::unique_ptr<BlockExpr> if_block,
Location locus)
- : ExprWithBlock (std::vector<Attribute> ()),
- condition (std::move (condition)), if_block (std::move (if_block)),
+ : condition (std::move (condition)), if_block (std::move (if_block)),
locus (locus)
{}
// outer attributes are never allowed on IfExprs
@@ -4079,6 +4161,9 @@ public:
return if_block == nullptr && condition == nullptr;
}
+ // this should never be called
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { rust_assert (false); }
+
protected:
// Base clone function but still concrete as concrete base class
virtual IfExpr *clone_if_expr_impl () const { return new IfExpr (*this); }
@@ -4209,7 +4294,6 @@ protected:
// Basic "if let" expression AST node with no else
class IfLetExpr : public ExprWithBlock
{
- // MatchArmPatterns patterns;
std::vector<std::unique_ptr<Pattern> > match_arm_patterns; // inlined
std::unique_ptr<Expr> value;
std::unique_ptr<BlockExpr> if_block;
@@ -4221,8 +4305,7 @@ public:
IfLetExpr (std::vector<std::unique_ptr<Pattern> > match_arm_patterns,
std::unique_ptr<Expr> value, std::unique_ptr<BlockExpr> if_block,
Location locus)
- : ExprWithBlock (std::vector<Attribute> ()),
- match_arm_patterns (std::move (match_arm_patterns)),
+ : match_arm_patterns (std::move (match_arm_patterns)),
value (std::move (value)), if_block (std::move (if_block)), locus (locus)
{}
// outer attributes not allowed on if let exprs either
@@ -4315,6 +4398,9 @@ public:
return match_arm_patterns;
}
+ // this should never be called
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { rust_assert (false); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base (or rather this or any derived object) */
@@ -4826,15 +4912,10 @@ protected:
// Match expression AST node
class MatchExpr : public ExprWithBlock
{
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> branch_value;
std::vector<Attribute> inner_attrs;
-
- // bool has_match_arms;
- // MatchArms match_arms;
- // std::vector<std::unique_ptr<MatchCase> > match_arms; // inlined from
- // MatchArms
std::vector<MatchCase> match_arms;
-
Location locus;
public:
@@ -4844,11 +4925,10 @@ public:
bool has_match_arms () const { return !match_arms.empty (); }
MatchExpr (std::unique_ptr<Expr> branch_value,
- // std::vector<std::unique_ptr<MatchCase> > match_arms,
std::vector<MatchCase> match_arms,
std::vector<Attribute> inner_attrs,
std::vector<Attribute> outer_attrs, Location locus)
- : ExprWithBlock (std::move (outer_attrs)),
+ : outer_attrs (std::move (outer_attrs)),
branch_value (std::move (branch_value)),
inner_attrs (std::move (inner_attrs)),
match_arms (std::move (match_arms)), locus (locus)
@@ -4856,16 +4936,12 @@ public:
// Copy constructor requires clone due to unique_ptr
MatchExpr (MatchExpr const &other)
- : ExprWithBlock (other), inner_attrs (other.inner_attrs),
+ : ExprWithBlock (other), outer_attrs (other.outer_attrs), inner_attrs (other.inner_attrs),
match_arms (other.match_arms), locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
if (other.branch_value != nullptr)
branch_value = other.branch_value->clone_expr ();
-
- /*match_arms.reserve (other.match_arms.size ());
- for (const auto &e : other.match_arms)
- match_arms.push_back (e->clone_match_case ());*/
}
// Overloaded assignment operator to clone due to unique_ptr
@@ -4874,7 +4950,7 @@ public:
ExprWithBlock::operator= (other);
inner_attrs = other.inner_attrs;
match_arms = other.match_arms;
- // outer_attrs = other.outer_attrs;
+ outer_attrs = other.outer_attrs;
locus = other.locus;
// guard to prevent null dereference (only required if error state)
@@ -4883,10 +4959,6 @@ public:
else
branch_value = nullptr;
- /*match_arms.reserve (other.match_arms.size ());
- for (const auto &e : other.match_arms)
- match_arms.push_back (e->clone_match_case ());*/
-
return *this;
}
@@ -4907,6 +4979,11 @@ public:
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
// TODO: is this better? Or is a "vis_block" better?
std::unique_ptr<Expr> &get_scrutinee_expr ()
{
@@ -4929,6 +5006,7 @@ protected:
// Await expression AST node (pseudo-member variable access)
class AwaitExpr : public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
std::unique_ptr<Expr> awaited_expr;
Location locus;
@@ -4936,13 +5014,13 @@ public:
// TODO: ensure outer attributes are actually allowed
AwaitExpr (std::unique_ptr<Expr> awaited_expr,
std::vector<Attribute> outer_attrs, Location locus)
- : ExprWithoutBlock (std::move (outer_attrs)),
+ : outer_attrs (std::move (outer_attrs)),
awaited_expr (std::move (awaited_expr)), locus (locus)
{}
// copy constructor with clone
AwaitExpr (AwaitExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus)
+ : ExprWithoutBlock (other), outer_attrs (other.outer_attrs), locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
if (other.awaited_expr != nullptr)
@@ -4953,6 +5031,7 @@ public:
AwaitExpr &operator= (AwaitExpr const &other)
{
ExprWithoutBlock::operator= (other);
+ outer_attrs = other.outer_attrs;
locus = other.locus;
// guard to prevent null dereference (only required if error state)
@@ -4986,6 +5065,11 @@ public:
return awaited_expr;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -4999,6 +5083,7 @@ protected:
class AsyncBlockExpr : public ExprWithBlock
{
// TODO: should this extend BlockExpr rather than be a composite of it?
+ std::vector<Attribute> outer_attrs;
bool has_move;
std::unique_ptr<BlockExpr> block_expr;
Location locus;
@@ -5006,13 +5091,13 @@ class AsyncBlockExpr : public ExprWithBlock
public:
AsyncBlockExpr (std::unique_ptr<BlockExpr> block_expr, bool has_move,
std::vector<Attribute> outer_attrs, Location locus)
- : ExprWithBlock (std::move (outer_attrs)), has_move (has_move),
+ : outer_attrs (std::move (outer_attrs)), has_move (has_move),
block_expr (std::move (block_expr)), locus (locus)
{}
// copy constructor with clone
AsyncBlockExpr (AsyncBlockExpr const &other)
- : ExprWithBlock (other), has_move (other.has_move), locus (other.locus)
+ : ExprWithBlock (other), outer_attrs (other.outer_attrs), has_move (other.has_move), locus (other.locus)
{
// guard to prevent null dereference (only required if error state)
if (other.block_expr != nullptr)
@@ -5023,6 +5108,7 @@ public:
AsyncBlockExpr &operator= (AsyncBlockExpr const &other)
{
ExprWithBlock::operator= (other);
+ outer_attrs = other.outer_attrs;
has_move = other.has_move;
locus = other.locus;
@@ -5057,6 +5143,11 @@ public:
return block_expr;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index b5fb858..79d513f 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -360,6 +360,7 @@ class MacroInvocation : public TypeNoBounds,
public Pattern,
public ExprWithoutBlock
{
+ std::vector<Attribute> outer_attrs;
/*SimplePath path;
DelimTokenTree token_tree;*/
MacroInvocData invoc_data;
@@ -375,7 +376,7 @@ public:
{}*/
MacroInvocation (MacroInvocData invoc_data,
std::vector<Attribute> outer_attrs, Location locus)
- : ExprWithoutBlock (std::move (outer_attrs)),
+ : outer_attrs (std::move (outer_attrs)),
invoc_data (std::move (invoc_data)), locus (locus)
{}
@@ -391,6 +392,11 @@ public:
return invoc_data.is_marked_for_strip ();
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 2b7c973..b30dffc 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -311,9 +311,9 @@ public:
* arguments) */
class PathInExpression : public PathPattern, public PathExpr
{
+ std::vector<Attribute> outer_attrs;
bool has_opening_scope_resolution;
Location locus;
-
NodeId _node_id;
public:
@@ -321,12 +321,10 @@ public:
// Constructor
PathInExpression (std::vector<PathExprSegment> path_segments,
- Location locus = Location (),
- bool has_opening_scope_resolution = false,
- std::vector<Attribute> outer_attrs
- = std::vector<Attribute> ())
+ std::vector<Attribute> outer_attrs, Location locus,
+ bool has_opening_scope_resolution = false)
: PathPattern (std::move (path_segments)),
- PathExpr (std::move (outer_attrs)),
+ outer_attrs (std::move (outer_attrs)),
has_opening_scope_resolution (has_opening_scope_resolution),
locus (locus), _node_id (Analysis::Mappings::get ()->get_next_node_id ())
{}
@@ -334,7 +332,7 @@ public:
// Creates an error state path in expression.
static PathInExpression create_error ()
{
- return PathInExpression (std::vector<PathExprSegment> ());
+ return PathInExpression ({}, {}, Location ());
}
// Returns whether path in expression is in an error state.
@@ -360,10 +358,16 @@ public:
// Invalid if path is empty (error state), so base stripping on that.
void mark_for_strip () override { remove_all_segments (); }
bool is_marked_for_strip () const override { return is_error (); }
- bool opening_scope_resolution () { return has_opening_scope_resolution; }
+
+ bool opening_scope_resolution () const { return has_opening_scope_resolution; }
NodeId get_node_id () const override { return _node_id; }
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -835,6 +839,7 @@ public:
* allows specifying trait functions) */
class QualifiedPathInExpression : public PathPattern, public PathExpr
{
+ std::vector<Attribute> outer_attrs;
QualifiedPathType path_type;
Location locus;
@@ -843,11 +848,10 @@ public:
QualifiedPathInExpression (QualifiedPathType qual_path_type,
std::vector<PathExprSegment> path_segments,
- Location locus = Location (),
- std::vector<Attribute> outer_attrs
- = std::vector<Attribute> ())
+ std::vector<Attribute> outer_attrs,
+ Location locus)
: PathPattern (std::move (path_segments)),
- PathExpr (std::move (outer_attrs)),
+ outer_attrs (std::move (outer_attrs)),
path_type (std::move (qual_path_type)), locus (locus)
{}
@@ -861,7 +865,7 @@ public:
static QualifiedPathInExpression create_error ()
{
return QualifiedPathInExpression (QualifiedPathType::create_error (),
- std::vector<PathExprSegment> ());
+ {}, {}, Location ());
}
Location get_locus () const { return locus; }
@@ -883,6 +887,11 @@ public:
return path_type;
}
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void set_outer_attrs (std::vector<Attribute> new_attrs) override { outer_attrs = std::move (new_attrs); }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 39bba4f..2f4c010 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -1529,13 +1529,12 @@ public:
}
void visit (AST::IfExpr &expr) override
{
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
- {
- expr.mark_for_strip ();
- return;
- }
+ // TODO: for if expressions, are attributes allowed if it is part of an expression statement?
+ // if so, probably have to add a "does_expr_allow_attrs()" method to Expr and then don't move attrs.
+ // otherwise, that may be useful anyway for better error messages.
+
+ // NOTE: IfExpr literally doesn't support outer attrs, so no strip code
+ // TODO: is this still true? can't find info on page
// can't strip condition expr itself, but can strip sub-expressions
auto &condition_expr = expr.get_condition_expr ();
@@ -1555,13 +1554,7 @@ public:
}
void visit (AST::IfExprConseqElse &expr) override
{
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
- {
- expr.mark_for_strip ();
- return;
- }
+ // NOTE: IfExpr literally doesn't support outer attrs, so no strip code
// can't strip condition expr itself, but can strip sub-expressions
auto &condition_expr = expr.get_condition_expr ();
@@ -1589,13 +1582,7 @@ public:
}
void visit (AST::IfExprConseqIf &expr) override
{
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
- {
- expr.mark_for_strip ();
- return;
- }
+ // NOTE: IfExpr literally doesn't support outer attrs, so no strip code
// can't strip condition expr itself, but can strip sub-expressions
auto &condition_expr = expr.get_condition_expr ();
@@ -1623,13 +1610,7 @@ public:
}
void visit (AST::IfExprConseqIfLet &expr) override
{
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
- {
- expr.mark_for_strip ();
- return;
- }
+ // NOTE: IfExpr literally doesn't support outer attrs, so no strip code
// can't strip condition expr itself, but can strip sub-expressions
auto &condition_expr = expr.get_condition_expr ();
@@ -1658,13 +1639,7 @@ public:
}
void visit (AST::IfLetExpr &expr) override
{
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
- {
- expr.mark_for_strip ();
- return;
- }
+ // NOTE: IfLetExpr literally doesn't support outer attrs, so no strip code
for (auto &pattern : expr.get_patterns ())
{
@@ -1692,13 +1667,7 @@ public:
}
void visit (AST::IfLetExprConseqElse &expr) override
{
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
- {
- expr.mark_for_strip ();
- return;
- }
+ // NOTE: IfLetExpr literally doesn't support outer attrs, so no strip code
for (auto &pattern : expr.get_patterns ())
{
@@ -1734,13 +1703,7 @@ public:
}
void visit (AST::IfLetExprConseqIf &expr) override
{
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
- {
- expr.mark_for_strip ();
- return;
- }
+ // NOTE: IfLetExpr literally doesn't support outer attrs, so no strip code
for (auto &pattern : expr.get_patterns ())
{
@@ -1776,13 +1739,7 @@ public:
}
void visit (AST::IfLetExprConseqIfLet &expr) override
{
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (expr.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (expr.get_outer_attrs ()))
- {
- expr.mark_for_strip ();
- return;
- }
+ // NOTE: IfLetExpr literally doesn't support outer attrs, so no strip code
for (auto &pattern : expr.get_patterns ())
{
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 87e02dd..a0d2af9 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -791,7 +791,7 @@ Parser<ManagedTokenSource>::parse_attr_input ()
}
// create actual LiteralExpr
- AST::LiteralExpr lit_expr (t->get_str (), lit_type, t->get_type_hint (),
+ AST::LiteralExpr lit_expr (t->get_str (), lit_type, t->get_type_hint (), {},
t->get_locus ());
std::unique_ptr<AST::AttrInputLiteral> attr_input_lit (
@@ -6361,9 +6361,8 @@ Parser<ManagedTokenSource>::parse_path_in_expression ()
segments.shrink_to_fit ();
- return AST::PathInExpression (std::move (segments), locus,
- has_opening_scope_resolution,
- std::vector<AST::Attribute> ());
+ return AST::PathInExpression (std::move (segments), {}, locus,
+ has_opening_scope_resolution);
}
/* Parses a single path in expression path segment (including generic
@@ -6476,8 +6475,7 @@ Parser<ManagedTokenSource>::parse_qualified_path_in_expression (
// FIXME: outer attr parsing
return AST::QualifiedPathInExpression (std::move (qual_path_type),
- std::move (segments), locus,
- std::vector<AST::Attribute> ());
+ std::move (segments), {}, locus);
}
// Parses the type syntactical construction at the start of a qualified path.
@@ -7377,8 +7375,7 @@ Parser<ManagedTokenSource>::parse_literal_expr (
// create literal based on stuff in switch
return std::unique_ptr<AST::LiteralExpr> (
new AST::LiteralExpr (std::move (literal_value), std::move (type),
- t->get_type_hint (), t->get_locus (),
- std::move (outer_attrs)));
+ t->get_type_hint (), std::move (outer_attrs), t->get_locus ()));
}
// Parses a return expression (including any expression to return).
@@ -7406,8 +7403,8 @@ Parser<ManagedTokenSource>::parse_return_expr (
// FIXME: ensure this doesn't ruin the middle of any expressions or anything
return std::unique_ptr<AST::ReturnExpr> (
- new AST::ReturnExpr (locus, std::move (returned_expr),
- std::move (outer_attrs)));
+ new AST::ReturnExpr (std::move (returned_expr),
+ std::move (outer_attrs), locus));
}
/* Parses a break expression (including any label to break to AND any return
@@ -7442,8 +7439,8 @@ Parser<ManagedTokenSource>::parse_break_expr (
std::unique_ptr<AST::Expr> return_expr = parse_expr ();
return std::unique_ptr<AST::BreakExpr> (
- new AST::BreakExpr (locus, std::move (label), std::move (return_expr),
- std::move (outer_attrs)));
+ new AST::BreakExpr (std::move (label), std::move (return_expr),
+ std::move (outer_attrs), locus));
}
// Parses a continue expression (including any label to continue from).
@@ -7474,7 +7471,7 @@ Parser<ManagedTokenSource>::parse_continue_expr (
}
return std::unique_ptr<AST::ContinueExpr> (
- new AST::ContinueExpr (locus, std::move (label), std::move (outer_attrs)));
+ new AST::ContinueExpr (std::move (label), std::move (outer_attrs), locus));
}
// Parses a loop label used in loop expressions.
@@ -11488,7 +11485,7 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr (
// lexer.skip_token();
// HACK: add outer attrs to path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
expr = std::unique_ptr<AST::PathInExpression> (
new AST::PathInExpression (std::move (path)));
}
@@ -11539,7 +11536,7 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr (
// lexer.skip_token();
// HACK: replace outer attributes in path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
std::unique_ptr<AST::PathInExpression> expr (
new AST::PathInExpression (std::move (path)));
@@ -12047,11 +12044,11 @@ Parser<ManagedTokenSource>::null_denotation (
/* HACK: may have to become permanent, but this is my
* current identifier expression */
return std::unique_ptr<AST::IdentifierExpr> (
- new AST::IdentifierExpr (tok->get_str (),
+ new AST::IdentifierExpr (tok->get_str (), {},
tok->get_locus ()));
}
// HACK: add outer attrs to path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
return std::unique_ptr<AST::PathInExpression> (
new AST::PathInExpression (std::move (path)));
}
@@ -12069,11 +12066,11 @@ Parser<ManagedTokenSource>::null_denotation (
/* HACK: may have to become permanent, but this is my
* current identifier expression */
return std::unique_ptr<AST::IdentifierExpr> (
- new AST::IdentifierExpr (tok->get_str (),
+ new AST::IdentifierExpr (tok->get_str (), {},
tok->get_locus ()));
}
// HACK: add outer attrs to path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
return std::unique_ptr<AST::PathInExpression> (
new AST::PathInExpression (std::move (path)));
}
@@ -12087,10 +12084,10 @@ Parser<ManagedTokenSource>::null_denotation (
/* HACK: may have to become permanent, but this is my current
* identifier expression */
return std::unique_ptr<AST::IdentifierExpr> (
- new AST::IdentifierExpr (tok->get_str (), tok->get_locus ()));
+ new AST::IdentifierExpr (tok->get_str (), {}, tok->get_locus ()));
}
// HACK: add outer attrs to path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
return std::unique_ptr<AST::PathInExpression> (
new AST::PathInExpression (std::move (path)));
}
@@ -12105,33 +12102,34 @@ Parser<ManagedTokenSource>::null_denotation (
// HACK: add outer attrs to path
AST::QualifiedPathInExpression path
= parse_qualified_path_in_expression (true);
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
return std::unique_ptr<AST::QualifiedPathInExpression> (
new AST::QualifiedPathInExpression (std::move (path)));
}
+ // FIXME: for literal exprs, should outer attrs be passed in or just ignored?
case INT_LITERAL:
// we should check the range, but ignore for now
// encode as int?
return std::unique_ptr<AST::LiteralExpr> (
new AST::LiteralExpr (tok->get_str (), AST::Literal::INT,
- tok->get_type_hint (), tok->get_locus ()));
+ tok->get_type_hint (), {}, tok->get_locus ()));
case FLOAT_LITERAL:
// encode as float?
return std::unique_ptr<AST::LiteralExpr> (
new AST::LiteralExpr (tok->get_str (), AST::Literal::FLOAT,
- tok->get_type_hint (), tok->get_locus ()));
+ tok->get_type_hint (), {}, tok->get_locus ()));
case STRING_LITERAL:
return std::unique_ptr<AST::LiteralExpr> (
new AST::LiteralExpr (tok->get_str (), AST::Literal::STRING,
- tok->get_type_hint (), tok->get_locus ()));
+ tok->get_type_hint (), {}, tok->get_locus ()));
case TRUE_LITERAL:
return std::unique_ptr<AST::LiteralExpr> (
new AST::LiteralExpr ("true", AST::Literal::BOOL, tok->get_type_hint (),
- tok->get_locus ()));
+ {}, tok->get_locus ()));
case FALSE_LITERAL:
return std::unique_ptr<AST::LiteralExpr> (
new AST::LiteralExpr ("false", AST::Literal::BOOL,
- tok->get_type_hint (), tok->get_locus ()));
+ tok->get_type_hint (), {}, tok->get_locus ()));
case LEFT_PAREN: { // have to parse whole expression if inside brackets
/* recursively invoke parse_expression with lowest priority possible as
* it it were a top-level expression. */
@@ -12170,7 +12168,7 @@ Parser<ManagedTokenSource>::null_denotation (
ParseRestrictions entered_from_unary;
entered_from_unary.entered_from_unary = true;
std::unique_ptr<AST::Expr> expr
- = parse_expr (LBP_UNARY_MINUS, std::vector<AST::Attribute> (),
+ = parse_expr (LBP_UNARY_MINUS, {},
entered_from_unary);
if (expr == nullptr)
@@ -12195,7 +12193,7 @@ Parser<ManagedTokenSource>::null_denotation (
ParseRestrictions entered_from_unary;
entered_from_unary.entered_from_unary = true;
std::unique_ptr<AST::Expr> expr
- = parse_expr (LBP_UNARY_EXCLAM, std::vector<AST::Attribute> (),
+ = parse_expr (LBP_UNARY_EXCLAM, {},
entered_from_unary);
if (expr == nullptr)
@@ -12222,7 +12220,7 @@ Parser<ManagedTokenSource>::null_denotation (
entered_from_unary.entered_from_unary = true;
entered_from_unary.can_be_struct_expr = false;
std::unique_ptr<AST::Expr> expr
- = parse_expr (LBP_UNARY_ASTERISK, std::vector<AST::Attribute> (),
+ = parse_expr (LBP_UNARY_ASTERISK, {},
entered_from_unary);
// FIXME: allow outer attributes on expression
return std::unique_ptr<AST::DereferenceExpr> (
@@ -12245,13 +12243,13 @@ Parser<ManagedTokenSource>::null_denotation (
{
lexer.skip_token ();
expr
- = parse_expr (LBP_UNARY_AMP_MUT, std::vector<AST::Attribute> (),
+ = parse_expr (LBP_UNARY_AMP_MUT, {},
entered_from_unary);
is_mut_borrow = true;
}
else
{
- expr = parse_expr (LBP_UNARY_AMP, std::vector<AST::Attribute> (),
+ expr = parse_expr (LBP_UNARY_AMP, {},
entered_from_unary);
}
@@ -12272,13 +12270,13 @@ Parser<ManagedTokenSource>::null_denotation (
{
lexer.skip_token ();
expr
- = parse_expr (LBP_UNARY_AMP_MUT, std::vector<AST::Attribute> (),
+ = parse_expr (LBP_UNARY_AMP_MUT, {},
entered_from_unary);
is_mut_borrow = true;
}
else
{
- expr = parse_expr (LBP_UNARY_AMP, std::vector<AST::Attribute> (),
+ expr = parse_expr (LBP_UNARY_AMP, {},
entered_from_unary);
}
@@ -12317,7 +12315,7 @@ Parser<ManagedTokenSource>::null_denotation (
if (tok->get_id () == SELF && path.is_single_segment ())
{
// HACK: add outer attrs to path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
return std::unique_ptr<AST::PathInExpression> (
new AST::PathInExpression (std::move (path)));
}
@@ -12347,7 +12345,7 @@ Parser<ManagedTokenSource>::null_denotation (
{
// assume path is returned
// HACK: add outer attributes to path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
return std::unique_ptr<AST::PathInExpression> (
new AST::PathInExpression (std::move (path)));
}
@@ -12360,7 +12358,7 @@ Parser<ManagedTokenSource>::null_denotation (
{
// assume path is returned
// HACK: add outer attributes to path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
return std::unique_ptr<AST::PathInExpression> (
new AST::PathInExpression (std::move (path)));
}
@@ -12369,7 +12367,7 @@ Parser<ManagedTokenSource>::null_denotation (
default:
// assume path is returned
// HACK: add outer attributes to path
- path.replace_outer_attrs (std::move (outer_attrs));
+ path.set_outer_attrs (std::move (outer_attrs));
return std::unique_ptr<AST::PathInExpression> (
new AST::PathInExpression (std::move (path)));
}
@@ -14115,9 +14113,8 @@ Parser<ManagedTokenSource>::parse_struct_expr_tuple_partial (
exprs.push_back (std::move (expr));
if (lexer.peek_token ()->get_id () != COMMA)
- {
break;
- }
+
lexer.skip_token ();
t = lexer.peek_token ();
@@ -14243,7 +14240,7 @@ Parser<ManagedTokenSource>::parse_path_in_expression_pratt (const_TokenPtr tok)
"current token (just about to return path to null denotation): '%s'\n",
lexer.peek_token ()->get_token_description ());
- return AST::PathInExpression (std::move (segments), tok->get_locus (), false);
+ return AST::PathInExpression (std::move (segments), {}, tok->get_locus (), false);
}
// Parses a closure expression with pratt parsing (from null denotation).