diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2020-09-02 14:05:31 +0800 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2020-11-28 21:13:20 +0000 |
commit | 8a633e3ca4d151d6bbee849a1ef2d265d95bc2a7 (patch) | |
tree | a4ad4b385fa736a030c11940d6a197386ea7e733 /gcc | |
parent | 318a91e6baec6dfb406bc069866789c0a11b01e0 (diff) | |
download | gcc-8a633e3ca4d151d6bbee849a1ef2d265d95bc2a7.zip gcc-8a633e3ca4d151d6bbee849a1ef2d265d95bc2a7.tar.gz gcc-8a633e3ca4d151d6bbee849a1ef2d265d95bc2a7.tar.bz2 |
Attempt to modify buffered_queue to take ownership of a source rather than reference, other cleanup
Attempt to fix compile errors caused by make_shared with private constructor
Attempt to fix compile errors
Attempt to fix appearance of no characters in lexer
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast-full-test.cc | 1159 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-visitor.h | 4 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 772 | ||||
-rw-r--r-- | gcc/rust/ast/rust-cond-compilation.h | 86 | ||||
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 3194 | ||||
-rw-r--r-- | gcc/rust/ast/rust-item.h | 2046 | ||||
-rw-r--r-- | gcc/rust/ast/rust-macro.h | 294 | ||||
-rw-r--r-- | gcc/rust/ast/rust-path.h | 473 | ||||
-rw-r--r-- | gcc/rust/ast/rust-pattern.h | 649 | ||||
-rw-r--r-- | gcc/rust/ast/rust-stmt.h | 145 | ||||
-rw-r--r-- | gcc/rust/ast/rust-type.h | 438 | ||||
-rw-r--r-- | gcc/rust/lex/rust-lex.cc | 29 | ||||
-rw-r--r-- | gcc/rust/lex/rust-lex.h | 49 | ||||
-rw-r--r-- | gcc/rust/lex/rust-token.cc | 8 | ||||
-rw-r--r-- | gcc/rust/lex/rust-token.h | 113 | ||||
-rw-r--r-- | gcc/rust/rust-buffered-queue.h | 76 | ||||
-rw-r--r-- | gcc/rust/rust-session-manager.cc | 57 |
17 files changed, 3934 insertions, 5658 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 3eb2f5d..75ea74d 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -1,4 +1,4 @@ -/* +/* General AST-related method implementations for Rust frontend. Copyright (C) 2009-2020 Free Software Foundation, Inc. This file is part of GCC. @@ -37,11 +37,11 @@ enum indent_mode stay }; -::std::string +std::string indent_spaces (enum indent_mode mode) { static int indent = 0; - ::std::string str = ""; + std::string str = ""; if (out == mode) indent--; for (int i = 0; i < indent; i++) @@ -53,8 +53,8 @@ indent_spaces (enum indent_mode mode) } // Gets a string in a certain delim type. -::std::string -get_string_in_delims (::std::string str_input, DelimType delim_type) +std::string +get_string_in_delims (std::string str_input, DelimType delim_type) { switch (delim_type) { @@ -71,7 +71,7 @@ get_string_in_delims (::std::string str_input, DelimType delim_type) } // Converts a frag spec enum item to a string form. -::std::string +std::string frag_spec_to_str (MacroFragSpec frag_spec) { switch (frag_spec) @@ -109,12 +109,12 @@ frag_spec_to_str (MacroFragSpec frag_spec) } } -::std::string +std::string Crate::as_string () const { fprintf (stderr, "beginning crate recursive as-string\n"); - ::std::string str ("Crate: "); + std::string str ("Crate: "); // add utf8bom and shebang if (has_utf8bom) { @@ -133,8 +133,8 @@ Crate::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -152,11 +152,11 @@ Crate::as_string () const for (const auto &item : items) { // DEBUG: null pointer check - if (item == NULL) + if (item == nullptr) { fprintf (stderr, "something really terrible has gone wrong - " "null pointer item in crate."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + item->as_string (); @@ -166,11 +166,11 @@ Crate::as_string () const return str + "\n"; } -::std::string +std::string Attribute::as_string () const { - ::std::string path_str = path.as_string (); - if (attr_input == NULL) + std::string path_str = path.as_string (); + if (attr_input == nullptr) { return path_str; } @@ -180,11 +180,11 @@ Attribute::as_string () const } } -::std::string +std::string DelimTokenTree::as_string () const { - ::std::string start_delim; - ::std::string end_delim; + std::string start_delim; + std::string end_delim; switch (delim_type) { case PARENS: @@ -204,19 +204,19 @@ DelimTokenTree::as_string () const "Should be PARENS, SQUARE, or CURLY."); return "Invalid delimiter type"; } - ::std::string str = start_delim; + std::string str = start_delim; if (!token_trees.empty ()) { for (const auto &tree : token_trees) { // DEBUG: null pointer check - if (tree == NULL) + if (tree == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "token tree in delim token tree."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += tree->as_string (); @@ -227,7 +227,7 @@ DelimTokenTree::as_string () const return str; } -::std::string +std::string Token::as_string () const { /* FIXME: only works when not identifier or literal or whatever, i.e. when @@ -235,20 +235,20 @@ Token::as_string () const // return get_token_description(token_id); // maybe fixed - stores everything as string though, so storage-inefficient - ::std::string quote = is_string_lit () ? "\"" : ""; + std::string quote = is_string_lit () ? "\"" : ""; return quote + str + quote; } -::std::string +std::string SimplePathSegment::as_string () const { return segment_name; } -::std::string +std::string SimplePath::as_string () const { - ::std::string path; + std::string path; if (has_opening_scope_resolution) { path = "::"; @@ -282,33 +282,32 @@ SimplePath::as_string () const return path; } -::std::string +std::string Visibility::as_string () const { switch (public_vis_type) { case NONE: - return ::std::string ("pub"); + return std::string ("pub"); case CRATE: - return ::std::string ("ub(crate)"); + return std::string ("ub(crate)"); case SELF: - return ::std::string ("pub(self)"); + return std::string ("pub(self)"); case SUPER: - return ::std::string ("pub(super)"); + return std::string ("pub(super)"); case IN_PATH: - return ::std::string ("pub(in ") + in_path.as_string () - + ::std::string (")"); + return std::string ("pub(in ") + in_path.as_string () + std::string (")"); default: gcc_unreachable (); } } // Creates a string that reflects the visibility stored. -::std::string +std::string VisItem::as_string () const { // FIXME: can't do formatting on string to make identation occur. - ::std::string str = Item::as_string (); + std::string str = Item::as_string (); if (has_visibility ()) { @@ -319,10 +318,10 @@ VisItem::as_string () const } // Creates a string that reflects the outer attributes stored. -::std::string +std::string Item::as_string () const { - ::std::string str; + std::string str; if (!outer_attrs.empty ()) { @@ -335,19 +334,19 @@ Item::as_string () const return str; } -::std::string +std::string Module::as_string () const { - ::std::string vis_item = VisItem::as_string (); + std::string vis_item = VisItem::as_string (); return vis_item + "mod " + module_name; } -::std::string +std::string ModuleBodied::as_string () const { // get module string for "[vis] mod [name]" - ::std::string str = Module::as_string (); + std::string str = Module::as_string (); // inner attributes str += "\n inner attributes: "; @@ -357,8 +356,8 @@ ModuleBodied::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -376,11 +375,11 @@ ModuleBodied::as_string () const for (const auto &item : items) { // DEBUG: null pointer check - if (item == NULL) + if (item == nullptr) { fprintf (stderr, "something really terrible has gone wrong - " "null pointer item in crate."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + item->as_string (); @@ -390,20 +389,20 @@ ModuleBodied::as_string () const return str + "\n"; } -::std::string +std::string ModuleNoBody::as_string () const { - ::std::string str = Module::as_string (); + std::string str = Module::as_string (); str += "\n no body (reference to external file)"; return str + "\n"; } -::std::string +std::string StaticItem::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += indent_spaces (stay) + "static"; @@ -415,30 +414,30 @@ StaticItem::as_string () const str += name; // DEBUG: null pointer check - if (type == NULL) + if (type == nullptr) { fprintf (stderr, "something really terrible has gone wrong - null " "pointer type in static item."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n" + indent_spaces (stay) + "Type: " + type->as_string (); // DEBUG: null pointer check - if (expr == NULL) + if (expr == nullptr) { fprintf (stderr, "something really terrible has gone wrong - null " "pointer expr in static item."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n" + indent_spaces (stay) + "Expression: " + expr->as_string (); return str + "\n"; } -::std::string +std::string ExternCrate::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += "extern crate " + referenced_crate; @@ -450,10 +449,10 @@ ExternCrate::as_string () const return str; } -::std::string +std::string TupleStruct::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += "struct " + struct_name; @@ -468,13 +467,13 @@ TupleStruct::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in enum."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -508,38 +507,38 @@ TupleStruct::as_string () const return str; } -::std::string +std::string ConstantItem::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += "const " + identifier; // DEBUG: null pointer check - if (type == NULL) + if (type == nullptr) { fprintf (stderr, "something really terrible has gone wrong - null " "pointer type in const item."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n Type: " + type->as_string (); // DEBUG: null pointer check - if (const_expr == NULL) + if (const_expr == nullptr) { fprintf (stderr, "something really terrible has gone wrong - null " "pointer expr in const item."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n Expression: " + const_expr->as_string (); return str + "\n"; } -::std::string +std::string InherentImpl::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += "impl "; @@ -554,13 +553,13 @@ InherentImpl::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in inherent impl."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -587,8 +586,8 @@ InherentImpl::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -612,10 +611,10 @@ InherentImpl::as_string () const return str; } -::std::string +std::string Method::as_string () const { - ::std::string str ("Method: \n "); + std::string str ("Method: \n "); str += vis.as_string () + " " + qualifiers.as_string (); @@ -632,13 +631,13 @@ Method::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in method."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -686,10 +685,10 @@ Method::as_string () const return str; } -::std::string +std::string StructStruct::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += "struct " + struct_name; @@ -704,13 +703,13 @@ StructStruct::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in enum."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -748,19 +747,19 @@ StructStruct::as_string () const return str; } -::std::string +std::string UseDeclaration::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); // DEBUG: null pointer check - if (use_tree == NULL) + if (use_tree == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer use tree in " "use declaration."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "use " + use_tree->as_string (); @@ -768,7 +767,7 @@ UseDeclaration::as_string () const return str; } -::std::string +std::string UseTreeGlob::as_string () const { switch (glob_type) @@ -778,7 +777,7 @@ UseTreeGlob::as_string () const case GLOBAL: return "::*"; case PATH_PREFIXED: { - ::std::string path_str = path.as_string (); + std::string path_str = path.as_string (); return path_str + "::*"; } default: @@ -788,10 +787,10 @@ UseTreeGlob::as_string () const gcc_unreachable (); } -::std::string +std::string UseTreeList::as_string () const { - ::std::string path_str; + std::string path_str; switch (path_type) { case NO_PATH: @@ -815,12 +814,12 @@ UseTreeList::as_string () const auto e = trees.end (); // DEBUG: null pointer check - if (*i == NULL) + if (*i == nullptr) { fprintf (stderr, "something really terrible has gone wrong - null pointer " "tree in use tree list."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } for (; i != e; i++) @@ -838,10 +837,10 @@ UseTreeList::as_string () const return path_str + "}"; } -::std::string +std::string UseTreeRebind::as_string () const { - ::std::string path_str = path.as_string (); + std::string path_str = path.as_string (); switch (bind_type) { @@ -862,10 +861,10 @@ UseTreeRebind::as_string () const return path_str; } -::std::string +std::string Enum::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += enum_name; // generic params @@ -879,13 +878,13 @@ Enum::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in enum."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -913,13 +912,13 @@ Enum::as_string () const for (const auto &item : items) { // DEBUG: null pointer check - if (item == NULL) + if (item == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "enum item in enum."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + item->as_string (); @@ -929,10 +928,10 @@ Enum::as_string () const return str; } -::std::string +std::string Trait::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); if (has_unsafe) { @@ -952,13 +951,13 @@ Trait::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in trait."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -975,13 +974,13 @@ Trait::as_string () const for (const auto &bound : type_param_bounds) { // DEBUG: null pointer check - if (bound == NULL) + if (bound == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "type param bound in trait."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + bound->as_string (); @@ -1008,13 +1007,13 @@ Trait::as_string () const for (const auto &item : trait_items) { // DEBUG: null pointer check - if (item == NULL) + if (item == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "trait item in trait."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + item->as_string (); @@ -1024,10 +1023,10 @@ Trait::as_string () const return str; } -::std::string +std::string Union::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += "union " + union_name; @@ -1042,13 +1041,13 @@ Union::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in union."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -1082,24 +1081,24 @@ Union::as_string () const return str; } -::std::string +std::string Function::as_string () const { - ::std::string str = VisItem::as_string () + "\n"; - ::std::string qstr = qualifiers.as_string (); + std::string str = VisItem::as_string () + "\n"; + std::string qstr = qualifiers.as_string (); if ("" != qstr) str += qstr + " "; if (has_function_return_type ()) { // DEBUG: null pointer check - if (return_type == NULL) + if (return_type == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer return " "type in function."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += return_type->as_string () + " "; @@ -1124,7 +1123,7 @@ Function::as_string () const fprintf (stderr, "something really terrible has gone wrong - null pointer " "generic param in function item."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } for (; i != e; i++) @@ -1162,24 +1161,24 @@ Function::as_string () const str += "\n"; // DEBUG: null pointer check - if (function_body == NULL) + if (function_body == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer function " "body in function."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += function_body->as_string () + "\n"; return str; } -::std::string +std::string WhereClause::as_string () const { // just print where clause items, don't mention "where" or "where clause" - ::std::string str; + std::string str; if (where_clause_items.empty ()) { @@ -1196,11 +1195,11 @@ WhereClause::as_string () const return str; } -::std::string +std::string BlockExpr::as_string () const { - ::std::string istr = indent_spaces (enter); - ::std::string str = istr + "BlockExpr:\n" + istr; + std::string istr = indent_spaces (enter); + std::string str = istr + "BlockExpr:\n" + istr; // get outer attributes str += "{\n" + indent_spaces (stay) + Expr::as_string (); @@ -1212,8 +1211,8 @@ BlockExpr::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* note that this does not print them with "inner attribute" syntax - + * just the body */ for (const auto &attr : inner_attrs) { str += "\n" + indent_spaces (stay) + attr.as_string (); @@ -1231,13 +1230,13 @@ BlockExpr::as_string () const for (const auto &stmt : statements) { // DEBUG: null pointer check - if (stmt == NULL) + if (stmt == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "stmt in block expr."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n" + indent_spaces (stay) + stmt->as_string (); @@ -1246,7 +1245,7 @@ BlockExpr::as_string () const // final expression str += "\n" + indent_spaces (stay) + "final expression: "; - if (expr == NULL) + if (expr == nullptr) { str += "none"; } @@ -1259,10 +1258,10 @@ BlockExpr::as_string () const return str; } -::std::string +std::string TraitImpl::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); if (has_unsafe) { @@ -1317,8 +1316,8 @@ TraitImpl::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -1341,10 +1340,10 @@ TraitImpl::as_string () const return str; } -::std::string +std::string TypeAlias::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += " " + new_type_name; @@ -1382,15 +1381,15 @@ TypeAlias::as_string () const return str; } -::std::string +std::string MacroInvocationSemi::as_string () const { // get outer attrs - ::std::string str = MacroItem::as_string (); + std::string str = MacroItem::as_string (); str += "\n" + path.as_string () + "!"; - ::std::string tok_trees; + std::string tok_trees; if (token_trees.empty ()) { tok_trees = "none"; @@ -1406,10 +1405,10 @@ MacroInvocationSemi::as_string () const fprintf (stderr, "something really terrible has gone wrong - null pointer " "token tree in macro invocation semi."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } - ::std::string s; + std::string s; for (; i != e; i++) { s += (*i)->as_string (); @@ -1423,10 +1422,10 @@ MacroInvocationSemi::as_string () const return str; } -::std::string +std::string ExternBlock::as_string () const { - ::std::string str = VisItem::as_string (); + std::string str = VisItem::as_string (); str += "extern "; if (has_abi ()) @@ -1442,8 +1441,8 @@ ExternBlock::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -1466,10 +1465,10 @@ ExternBlock::as_string () const return str; } -::std::string +std::string MacroRule::as_string () const { - ::std::string str ("Macro rule: "); + std::string str ("Macro rule: "); str += "\n Matcher: \n "; str += matcher.as_string (); @@ -1480,10 +1479,10 @@ MacroRule::as_string () const return str; } -::std::string +std::string MacroRulesDefinition::as_string () const { - ::std::string str ("macro_rules!"); + std::string str ("macro_rules!"); str += rule_name; @@ -1519,17 +1518,17 @@ MacroRulesDefinition::as_string () const return str; } -::std::string +std::string MacroInvocation::as_string () const { return "MacroInvocation: " + path.as_string () + "!" + token_tree.as_string (); } -::std::string +std::string PathInExpression::as_string () const { - ::std::string str; + std::string str; if (has_opening_scope_resolution) { @@ -1539,12 +1538,12 @@ PathInExpression::as_string () const return str + PathPattern::as_string (); } -::std::string +std::string ExprStmtWithBlock::as_string () const { - ::std::string str = indent_spaces (enter) + "ExprStmtWithBlock: \n"; + std::string str = indent_spaces (enter) + "ExprStmtWithBlock: \n"; - if (expr == NULL) + if (expr == nullptr) { str += "none (this should not happen and is an error)"; } @@ -1559,10 +1558,10 @@ ExprStmtWithBlock::as_string () const return str; } -::std::string +std::string ClosureParam::as_string () const { - ::std::string str (pattern->as_string ()); + std::string str (pattern->as_string ()); if (has_type_given ()) { @@ -1572,10 +1571,10 @@ ClosureParam::as_string () const return str; } -::std::string +std::string ClosureExpr::as_string () const { - ::std::string str ("ClosureExpr:\n Has move: "); + std::string str ("ClosureExpr:\n Has move: "); if (has_move) { str += "true"; @@ -1601,10 +1600,10 @@ ClosureExpr::as_string () const return str; } -::std::string +std::string ClosureExprInnerTyped::as_string () const { - ::std::string str = ClosureExpr::as_string (); + std::string str = ClosureExpr::as_string (); str += "\n Return type: " + return_type->as_string (); @@ -1613,10 +1612,10 @@ ClosureExprInnerTyped::as_string () const return str; } -::std::string +std::string PathPattern::as_string () const { - ::std::string str; + std::string str; for (const auto &segment : segments) { @@ -1629,10 +1628,10 @@ PathPattern::as_string () const return str; } -::std::string +std::string QualifiedPathType::as_string () const { - ::std::string str ("<"); + std::string str ("<"); str += type_to_invoke_on->as_string (); if (has_as_clause ()) @@ -1643,16 +1642,16 @@ QualifiedPathType::as_string () const return str + ">"; } -::std::string +std::string QualifiedPathInExpression::as_string () const { return path_type.as_string () + "::" + PathPattern::as_string (); } -::std::string +std::string BorrowExpr::as_string () const { - ::std::string str ("&"); + std::string str ("&"); if (double_borrow) { @@ -1669,10 +1668,10 @@ BorrowExpr::as_string () const return str; } -::std::string +std::string ReturnExpr::as_string () const { - ::std::string str ("return "); + std::string str ("return "); if (has_return_expr ()) { @@ -1682,10 +1681,10 @@ ReturnExpr::as_string () const return str; } -::std::string +std::string GroupedExpr::as_string () const { - ::std::string str ("Grouped expr:"); + std::string str ("Grouped expr:"); // inner attributes str += "\n inner attributes: "; @@ -1695,8 +1694,8 @@ GroupedExpr::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -1708,16 +1707,16 @@ GroupedExpr::as_string () const return str; } -::std::string +std::string RangeToExpr::as_string () const { return ".." + to->as_string (); } -::std::string +std::string ContinueExpr::as_string () const { - ::std::string str ("continue "); + std::string str ("continue "); if (has_label ()) { @@ -1727,10 +1726,10 @@ ContinueExpr::as_string () const return str; } -::std::string +std::string NegationExpr::as_string () const { - ::std::string str; + std::string str; switch (negation_type) { @@ -1749,30 +1748,30 @@ NegationExpr::as_string () const return str; } -::std::string +std::string RangeFromExpr::as_string () const { return from->as_string () + ".."; } -::std::string +std::string RangeFullExpr::as_string () const { return ".."; } -::std::string +std::string ArrayIndexExpr::as_string () const { return array_expr->as_string () + "[" + index_expr->as_string () + "]"; } -::std::string +std::string AssignmentExpr::as_string () const { - ::std::string str ("AssignmentExpr: "); + std::string str ("AssignmentExpr: "); - if (main_or_left_expr == NULL || right_expr == NULL) + if (main_or_left_expr == nullptr || right_expr == nullptr) { str += "error (either or both expressions are null)"; } @@ -1788,10 +1787,10 @@ AssignmentExpr::as_string () const return str; } -::std::string +std::string AsyncBlockExpr::as_string () const { - ::std::string str = "AsyncBlockExpr: "; + std::string str = "AsyncBlockExpr: "; // get outer attributes str += "\n " + Expr::as_string (); @@ -1802,10 +1801,10 @@ AsyncBlockExpr::as_string () const return str + "\n" + block_expr->as_string (); } -::std::string +std::string ComparisonExpr::as_string () const { - ::std::string str (main_or_left_expr->as_string ()); + std::string str (main_or_left_expr->as_string ()); switch (expr_type) { @@ -1836,10 +1835,10 @@ ComparisonExpr::as_string () const return str; } -::std::string +std::string MethodCallExpr::as_string () const { - ::std::string str ("MethodCallExpr: \n Object (receiver) expr: "); + std::string str ("MethodCallExpr: \n Object (receiver) expr: "); str += receiver->as_string (); @@ -1856,7 +1855,7 @@ MethodCallExpr::as_string () const { for (const auto ¶m : params) { - if (param == NULL) + if (param == nullptr) { return "ERROR_MARK_STRING - method call expr param is null"; } @@ -1868,28 +1867,28 @@ MethodCallExpr::as_string () const return str; } -::std::string +std::string TupleIndexExpr::as_string () const { - return tuple_expr->as_string () + "." + ::std::to_string (tuple_index); + return tuple_expr->as_string () + "." + std::to_string (tuple_index); } -::std::string +std::string DereferenceExpr::as_string () const { return "*" + main_or_left_expr->as_string (); } -::std::string +std::string FieldAccessExpr::as_string () const { return receiver->as_string () + "." + field; } -::std::string +std::string LazyBooleanExpr::as_string () const { - ::std::string str (main_or_left_expr->as_string ()); + std::string str (main_or_left_expr->as_string ()); switch (expr_type) { @@ -1908,23 +1907,23 @@ LazyBooleanExpr::as_string () const return str; } -::std::string +std::string RangeFromToExpr::as_string () const { return from->as_string () + ".." + to->as_string (); } -::std::string +std::string RangeToInclExpr::as_string () const { return "..=" + to->as_string (); } -::std::string +std::string UnsafeBlockExpr::as_string () const { - ::std::string istr = indent_spaces (enter); - ::std::string str = istr + "UnsafeBlockExpr:"; + std::string istr = indent_spaces (enter); + std::string str = istr + "UnsafeBlockExpr:"; str += istr + "{"; // get outer attributes @@ -1933,20 +1932,20 @@ UnsafeBlockExpr::as_string () const return str + "\n" + indent_spaces (out) + "}\n" + expr->as_string (); } -::std::string +std::string ClosureExprInner::as_string () const { - ::std::string str = ClosureExpr::as_string (); + std::string str = ClosureExpr::as_string (); str += "\n Expression: " + closure_inner->as_string (); return str; } -::std::string +std::string IfExpr::as_string () const { - ::std::string str ("IfExpr: "); + std::string str ("IfExpr: "); str += "\n Condition expr: " + condition->as_string (); @@ -1955,40 +1954,40 @@ IfExpr::as_string () const return str; } -::std::string +std::string IfExprConseqElse::as_string () const { - ::std::string str = IfExpr::as_string (); + std::string str = IfExpr::as_string (); str += "\n Else block expr: " + else_block->as_string (); return str; } -::std::string +std::string IfExprConseqIf::as_string () const { - ::std::string str = IfExpr::as_string (); + std::string str = IfExpr::as_string (); str += "\n Else if expr: \n " + conseq_if_expr->as_string (); return str; } -::std::string +std::string IfExprConseqIfLet::as_string () const { - ::std::string str = IfExpr::as_string (); + std::string str = IfExpr::as_string (); str += "\n Else if let expr: \n " + if_let_expr->as_string (); return str; } -::std::string +std::string IfLetExpr::as_string () const { - ::std::string str ("IfLetExpr: "); + std::string str ("IfLetExpr: "); str += "\n Condition match arm patterns: "; if (match_arm_patterns.empty ()) @@ -2010,52 +2009,52 @@ IfLetExpr::as_string () const return str; } -::std::string +std::string IfLetExprConseqElse::as_string () const { - ::std::string str = IfLetExpr::as_string (); + std::string str = IfLetExpr::as_string (); str += "\n Else block expr: " + else_block->as_string (); return str; } -::std::string +std::string IfLetExprConseqIf::as_string () const { - ::std::string str = IfLetExpr::as_string (); + std::string str = IfLetExpr::as_string (); str += "\n Else if expr: \n " + if_expr->as_string (); return str; } -::std::string +std::string IfLetExprConseqIfLet::as_string () const { - ::std::string str = IfLetExpr::as_string (); + std::string str = IfLetExpr::as_string (); str += "\n Else if let expr: \n " + if_let_expr->as_string (); return str; } -::std::string +std::string RangeFromToInclExpr::as_string () const { return from->as_string () + "..=" + to->as_string (); } -::std::string +std::string ErrorPropagationExpr::as_string () const { return main_or_left_expr->as_string () + "?"; } -::std::string +std::string CompoundAssignmentExpr::as_string () const { - ::std::string operator_str; + std::string operator_str; operator_str.reserve (1); // get operator string @@ -2098,8 +2097,8 @@ CompoundAssignmentExpr::as_string () const operator_str += "="; - ::std::string str ("CompoundAssignmentExpr: "); - if (main_or_left_expr == NULL || right_expr == NULL) + std::string str ("CompoundAssignmentExpr: "); + if (main_or_left_expr == nullptr || right_expr == nullptr) { str += "error. this is probably a parsing failure."; } @@ -2113,10 +2112,10 @@ CompoundAssignmentExpr::as_string () const return str; } -::std::string +std::string ArithmeticOrLogicalExpr::as_string () const { - ::std::string operator_str; + std::string operator_str; operator_str.reserve (1); // get operator string @@ -2157,8 +2156,8 @@ ArithmeticOrLogicalExpr::as_string () const break; } - ::std::string str ("ArithmeticOrLogicalExpr: "); - if (main_or_left_expr == NULL || right_expr == NULL) + std::string str ("ArithmeticOrLogicalExpr: "); + if (main_or_left_expr == nullptr || right_expr == nullptr) { str += "error. this is probably a parsing failure."; } @@ -2172,10 +2171,10 @@ ArithmeticOrLogicalExpr::as_string () const return str; } -::std::string +std::string CallExpr::as_string () const { - ::std::string str ("CallExpr: \n Function expr: "); + std::string str ("CallExpr: \n Function expr: "); str += function->as_string (); @@ -2188,7 +2187,7 @@ CallExpr::as_string () const { for (const auto ¶m : params) { - if (param == NULL) + if (param == nullptr) { return "ERROR_MARK_STRING - call expr param is null"; } @@ -2200,10 +2199,10 @@ CallExpr::as_string () const return str; } -::std::string +std::string WhileLoopExpr::as_string () const { - ::std::string str ("WhileLoopExpr: "); + std::string str ("WhileLoopExpr: "); str += "\n Label: "; if (!has_loop_label ()) @@ -2222,10 +2221,10 @@ WhileLoopExpr::as_string () const return str; } -::std::string +std::string WhileLetLoopExpr::as_string () const { - ::std::string str ("WhileLetLoopExpr: "); + std::string str ("WhileLetLoopExpr: "); str += "\n Label: "; if (!has_loop_label ()) @@ -2257,10 +2256,10 @@ WhileLetLoopExpr::as_string () const return str; } -::std::string +std::string LoopExpr::as_string () const { - ::std::string str ("LoopExpr: (infinite loop)"); + std::string str ("LoopExpr: (infinite loop)"); str += "\n Label: "; if (!has_loop_label ()) @@ -2277,10 +2276,10 @@ LoopExpr::as_string () const return str; } -::std::string +std::string ArrayExpr::as_string () const { - ::std::string str ("ArrayExpr:"); + std::string str ("ArrayExpr:"); // inner attributes str += "\n inner attributes: "; @@ -2290,8 +2289,8 @@ ArrayExpr::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -2311,16 +2310,16 @@ ArrayExpr::as_string () const return str; } -::std::string +std::string AwaitExpr::as_string () const { return awaited_expr->as_string () + ".await"; } -::std::string +std::string BreakExpr::as_string () const { - ::std::string str ("break "); + std::string str ("break "); if (has_label ()) { @@ -2335,25 +2334,25 @@ BreakExpr::as_string () const return str; } -::std::string +std::string LoopLabel::as_string () const { return label.as_string () + ": (label) "; } -::std::string +std::string MatchArm::as_string () const { // outer attributes - ::std::string str = "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 + /* 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 (); @@ -2386,40 +2385,40 @@ MatchArm::as_string () const return str; } -::std::string +std::string MatchCase::as_string () const { - ::std::string str ("MatchCase: (match arm) "); + std::string str ("MatchCase: (match arm) "); str += "\n Match arm matcher: \n" + arm.as_string (); return str; } -::std::string +std::string MatchCaseBlockExpr::as_string () const { - ::std::string str = MatchCase::as_string (); + std::string str = MatchCase::as_string (); str += "\n Block expr: " + block_expr->as_string (); return str; } -::std::string +std::string MatchCaseExpr::as_string () const { - ::std::string str = MatchCase::as_string (); + std::string str = MatchCase::as_string (); str += "\n Expr: " + expr->as_string (); return str; } -::std::string +std::string MatchExpr::as_string () const { - ::std::string str ("MatchExpr:"); + std::string str ("MatchExpr:"); str += "\n Scrutinee expr: " + branch_value->as_string (); @@ -2431,8 +2430,8 @@ MatchExpr::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -2456,10 +2455,10 @@ MatchExpr::as_string () const return str; } -::std::string +std::string TupleExpr::as_string () const { - ::std::string str ("TupleExpr:"); + std::string str ("TupleExpr:"); // inner attributes str += "\n inner attributes: "; @@ -2469,8 +2468,8 @@ TupleExpr::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -2493,14 +2492,14 @@ TupleExpr::as_string () const return str; } -::std::string +std::string ExprStmtWithoutBlock::as_string () const { - ::std::string str ("ExprStmtWithoutBlock:\n"); + std::string str ("ExprStmtWithoutBlock:\n"); indent_spaces (enter); str += indent_spaces (stay); - if (expr == NULL) + if (expr == nullptr) { str += "none (this shouldn't happen and is probably an error)"; } @@ -2513,16 +2512,16 @@ ExprStmtWithoutBlock::as_string () const return str; } -::std::string +std::string FunctionParam::as_string () const { return param_name->as_string () + " : " + type->as_string (); } -::std::string +std::string FunctionQualifiers::as_string () const { - ::std::string str; + std::string str; switch (const_status) { @@ -2556,10 +2555,10 @@ FunctionQualifiers::as_string () const return str; } -::std::string +std::string TraitBound::as_string () const { - ::std::string str ("TraitBound:"); + std::string str ("TraitBound:"); str += "\n Has opening question mark: "; if (opening_question_mark) @@ -2589,10 +2588,10 @@ TraitBound::as_string () const return str; } -::std::string +std::string MacroMatcher::as_string () const { - ::std::string str ("Macro matcher: "); + std::string str ("Macro matcher: "); str += "\n Delim type: "; @@ -2628,10 +2627,10 @@ MacroMatcher::as_string () const return str; } -::std::string +std::string LifetimeParam::as_string () const { - ::std::string str ("LifetimeParam: "); + std::string str ("LifetimeParam: "); str += "\n Outer attribute: "; if (!has_outer_attribute ()) @@ -2661,16 +2660,16 @@ LifetimeParam::as_string () const return str; } -::std::string +std::string MacroMatchFragment::as_string () const { return "$" + ident + ": " + frag_spec_to_str (frag_spec); } -::std::string +std::string QualifiedPathInType::as_string () const { - ::std::string str = path_type.as_string (); + std::string str = path_type.as_string (); for (const auto &segment : segments) { @@ -2680,10 +2679,10 @@ QualifiedPathInType::as_string () const return str; } -::std::string +std::string MacroMatchRepetition::as_string () const { - ::std::string str ("Macro match repetition: "); + std::string str ("Macro match repetition: "); str += "\n Matches: "; if (matches.empty ()) @@ -2730,7 +2729,7 @@ MacroMatchRepetition::as_string () const return str; } -::std::string +std::string Lifetime::as_string () const { if (is_error ()) @@ -2751,10 +2750,10 @@ Lifetime::as_string () const } } -::std::string +std::string TypePath::as_string () const { - ::std::string str; + std::string str; if (has_opening_scope_resolution) { @@ -2772,10 +2771,10 @@ TypePath::as_string () const return str; } -::std::string +std::string TypeParam::as_string () const { - ::std::string str ("TypeParam: "); + std::string str ("TypeParam: "); str += "\n Outer attribute: "; if (!has_outer_attribute ()) @@ -2824,7 +2823,7 @@ PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const } // create vector of reserved size (to minimise reallocations) - ::std::vector<SimplePathSegment> simple_segments; + std::vector<SimplePathSegment> simple_segments; simple_segments.reserve (segments.size ()); for (const auto &segment : segments) @@ -2837,9 +2836,9 @@ PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const } // create segment and add to vector - ::std::string segment_str = segment.as_string (); + std::string segment_str = segment.as_string (); simple_segments.push_back ( - SimplePathSegment (::std::move (segment_str), segment.get_locus ())); + SimplePathSegment (std::move (segment_str), segment.get_locus ())); } // kind of a HACK to get locus depending on opening scope resolution @@ -2853,8 +2852,8 @@ PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const locus = simple_segments[0].get_locus (); } - return SimplePath (::std::move (simple_segments), - with_opening_scope_resolution, locus); + return SimplePath (std::move (simple_segments), with_opening_scope_resolution, + locus); } SimplePath @@ -2866,32 +2865,32 @@ TypePath::as_simple_path () const } // create vector of reserved size (to minimise reallocations) - ::std::vector<SimplePathSegment> simple_segments; + std::vector<SimplePathSegment> simple_segments; simple_segments.reserve (segments.size ()); for (const auto &segment : segments) { // return empty path if doesn't meet simple path segment requirements - if (segment == NULL || segment->is_error () || !segment->is_ident_only () - || segment->as_string () == "Self") + 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 (); + std::string segment_str = segment->as_string (); simple_segments.push_back ( - SimplePathSegment (::std::move (segment_str), segment->get_locus ())); + SimplePathSegment (std::move (segment_str), segment->get_locus ())); } - return SimplePath (::std::move (simple_segments), - has_opening_scope_resolution, locus); + return SimplePath (std::move (simple_segments), has_opening_scope_resolution, + locus); } -::std::string +std::string PathExprSegment::as_string () const { - ::std::string ident_str = segment_name.as_string (); + std::string ident_str = segment_name.as_string (); if (has_generic_args ()) { ident_str += "::<" + generic_args.as_string () + ">"; @@ -2900,10 +2899,10 @@ PathExprSegment::as_string () const return ident_str; } -::std::string +std::string GenericArgs::as_string () const { - ::std::string args; + std::string args; // lifetime args if (!lifetime_args.empty ()) @@ -2950,16 +2949,16 @@ GenericArgs::as_string () const return args; } -::std::string +std::string GenericArgsBinding::as_string () const { return identifier + " = " + type->as_string (); } -::std::string +std::string ForLoopExpr::as_string () const { - ::std::string str ("ForLoopExpr: "); + std::string str ("ForLoopExpr: "); str += "\n Label: "; if (!has_loop_label ()) @@ -2980,7 +2979,7 @@ ForLoopExpr::as_string () const return str; } -::std::string +std::string RangePattern::as_string () const { if (has_ellipsis_syntax) @@ -2993,10 +2992,10 @@ RangePattern::as_string () const } } -::std::string +std::string RangePatternBoundLiteral::as_string () const { - ::std::string str; + std::string str; if (has_minus) { @@ -3008,10 +3007,10 @@ RangePatternBoundLiteral::as_string () const return str; } -::std::string +std::string SlicePattern::as_string () const { - ::std::string str ("SlicePattern: "); + std::string str ("SlicePattern: "); for (const auto &pattern : items) { @@ -3021,10 +3020,10 @@ SlicePattern::as_string () const return str; } -::std::string +std::string TuplePatternItemsMultiple::as_string () const { - ::std::string str; + std::string str; for (const auto &pattern : patterns) { @@ -3034,10 +3033,10 @@ TuplePatternItemsMultiple::as_string () const return str; } -::std::string +std::string TuplePatternItemsRanged::as_string () const { - ::std::string str; + std::string str; str += "\n Lower patterns: "; if (lower_patterns.empty ()) @@ -3068,25 +3067,25 @@ TuplePatternItemsRanged::as_string () const return str; } -::std::string +std::string TuplePattern::as_string () const { return "TuplePattern: " + items->as_string (); } -::std::string +std::string StructPatternField::as_string () const { // outer attributes - ::std::string str ("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 + /* 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 (); @@ -3096,10 +3095,10 @@ StructPatternField::as_string () const return str; } -::std::string +std::string StructPatternFieldIdent::as_string () const { - ::std::string str = StructPatternField::as_string (); + std::string str = StructPatternField::as_string (); str += "\n"; @@ -3118,22 +3117,22 @@ StructPatternFieldIdent::as_string () const return str; } -::std::string +std::string StructPatternFieldTuplePat::as_string () const { - ::std::string str = StructPatternField::as_string (); + std::string str = StructPatternField::as_string (); str += "\n"; - str += ::std::to_string (index) + " : " + tuple_pattern->as_string (); + str += std::to_string (index) + " : " + tuple_pattern->as_string (); return str; } -::std::string +std::string StructPatternFieldIdentPat::as_string () const { - ::std::string str = StructPatternField::as_string (); + std::string str = StructPatternField::as_string (); str += "\n"; @@ -3142,10 +3141,10 @@ StructPatternFieldIdentPat::as_string () const return str; } -::std::string +std::string StructPatternElements::as_string () const { - ::std::string str ("\n Fields: "); + std::string str ("\n Fields: "); if (!has_struct_pattern_fields ()) { @@ -3172,10 +3171,10 @@ StructPatternElements::as_string () const return str; } -::std::string +std::string StructPattern::as_string () const { - ::std::string str ("StructPattern: \n Path: "); + std::string str ("StructPattern: \n Path: "); str += path.as_string (); @@ -3192,10 +3191,10 @@ StructPattern::as_string () const return str; } -::std::string +std::string LiteralPattern::as_string () const { - ::std::string str; + std::string str; if (has_minus) { @@ -3205,10 +3204,10 @@ LiteralPattern::as_string () const return str + lit.as_string (); } -::std::string +std::string ReferencePattern::as_string () const { - ::std::string str ("&"); + std::string str ("&"); if (has_two_amps) { @@ -3225,10 +3224,10 @@ ReferencePattern::as_string () const return str; } -::std::string +std::string IdentifierPattern::as_string () const { - ::std::string str; + std::string str; if (is_ref) { @@ -3250,10 +3249,10 @@ IdentifierPattern::as_string () const return str; } -::std::string +std::string TupleStructItemsNoRange::as_string () const { - ::std::string str; + std::string str; for (const auto &pattern : patterns) { @@ -3263,10 +3262,10 @@ TupleStructItemsNoRange::as_string () const return str; } -::std::string +std::string TupleStructItemsRange::as_string () const { - ::std::string str ("\n Lower patterns: "); + std::string str ("\n Lower patterns: "); if (lower_patterns.empty ()) { @@ -3296,10 +3295,10 @@ TupleStructItemsRange::as_string () const return str; } -::std::string +std::string TupleStructPattern::as_string () const { - ::std::string str ("TupleStructPattern: \n Path: "); + std::string str ("TupleStructPattern: \n Path: "); str += path.as_string (); @@ -3308,19 +3307,19 @@ TupleStructPattern::as_string () const return str; } -::std::string +std::string LetStmt::as_string () const { // outer attributes - ::std::string str = "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 + /* note that this does not print them with "outer attribute" syntax - + * just the body */ indent_spaces (enter); for (const auto &attr : outer_attrs) { @@ -3345,19 +3344,19 @@ LetStmt::as_string () const } // Used to get outer attributes for expressions. -::std::string +std::string Expr::as_string () const { // outer attributes - ::std::string str = "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 + /* 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 (); @@ -3374,26 +3373,26 @@ 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 (std::move (copy), copy.get_locus (), in_parens); } -::std::string +std::string InferredType::as_string () const { return "_ (inferred)"; } -::std::string +std::string TypeCastExpr::as_string () const { return main_or_left_expr->as_string () + " as " + type_to_convert_to->as_string (); } -::std::string +std::string ImplTraitType::as_string () const { - ::std::string str ("ImplTraitType: \n TypeParamBounds: "); + std::string str ("ImplTraitType: \n TypeParamBounds: "); if (type_param_bounds.empty ()) { @@ -3410,10 +3409,10 @@ ImplTraitType::as_string () const return str; } -::std::string +std::string ReferenceType::as_string () const { - ::std::string str ("&"); + std::string str ("&"); if (has_lifetime ()) { @@ -3430,10 +3429,10 @@ ReferenceType::as_string () const return str; } -::std::string +std::string RawPointerType::as_string () const { - ::std::string str ("*"); + std::string str ("*"); switch (pointer_type) { @@ -3452,10 +3451,10 @@ RawPointerType::as_string () const return str; } -::std::string +std::string TraitObjectType::as_string () const { - ::std::string str ("TraitObjectType: \n Has dyn dispatch: "); + std::string str ("TraitObjectType: \n Has dyn dispatch: "); if (has_dyn) { @@ -3482,10 +3481,10 @@ TraitObjectType::as_string () const return str; } -::std::string +std::string BareFunctionType::as_string () const { - ::std::string str ("BareFunctionType: \n For lifetimes: "); + std::string str ("BareFunctionType: \n For lifetimes: "); if (!has_for_lifetimes ()) { @@ -3537,24 +3536,24 @@ BareFunctionType::as_string () const return str; } -::std::string +std::string ImplTraitTypeOneBound::as_string () const { - ::std::string str ("ImplTraitTypeOneBound: \n TraitBound: "); + std::string str ("ImplTraitTypeOneBound: \n TraitBound: "); return str + trait_bound.as_string (); } -::std::string +std::string TypePathSegmentGeneric::as_string () const { return TypePathSegment::as_string () + "<" + generic_args.as_string () + ">"; } -::std::string +std::string TraitObjectTypeOneBound::as_string () const { - ::std::string str ("TraitObjectTypeOneBound: \n Has dyn dispatch: "); + std::string str ("TraitObjectTypeOneBound: \n Has dyn dispatch: "); if (has_dyn) { @@ -3570,10 +3569,10 @@ TraitObjectTypeOneBound::as_string () const return str; } -::std::string +std::string TypePathFunction::as_string () const { - ::std::string str ("("); + std::string str ("("); if (has_inputs ()) { @@ -3598,28 +3597,28 @@ TypePathFunction::as_string () const return str; } -::std::string +std::string TypePathSegmentFunction::as_string () const { return TypePathSegment::as_string () + function_path.as_string (); } -::std::string +std::string ArrayType::as_string () const { return "[" + elem_type->as_string () + "; " + size->as_string () + "]"; } -::std::string +std::string SliceType::as_string () const { return "[" + elem_type->as_string () + "]"; } -::std::string +std::string TupleType::as_string () const { - ::std::string str ("("); + std::string str ("("); if (!is_unit_type ()) { @@ -3639,10 +3638,10 @@ TupleType::as_string () const return str; } -::std::string +std::string StructExpr::as_string () const { - ::std::string str = ExprWithoutBlock::as_string (); + std::string str = ExprWithoutBlock::as_string (); indent_spaces (enter); str += "\n" + indent_spaces (stay) + "StructExpr:"; indent_spaces (enter); @@ -3653,10 +3652,10 @@ StructExpr::as_string () const return str; } -::std::string +std::string StructExprTuple::as_string () const { - ::std::string str = StructExpr::as_string (); + std::string str = StructExpr::as_string (); if (exprs.empty ()) { @@ -3668,7 +3667,7 @@ StructExprTuple::as_string () const auto e = exprs.end (); // debug - null pointer check - if (*i == NULL) + if (*i == nullptr) { return "ERROR_MARK_STRING - nullptr struct expr tuple field"; } @@ -3693,8 +3692,8 @@ StructExprTuple::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* note that this does not print them with "inner attribute" syntax - + * just the body */ for (const auto &attr : inner_attrs) { str += "\n" + indent_spaces (stay) + attr.as_string (); @@ -3706,10 +3705,10 @@ StructExprTuple::as_string () const return str; } -::std::string +std::string StructExprStruct::as_string () const { - ::std::string str ("StructExprStruct (or subclass): "); + std::string str ("StructExprStruct (or subclass): "); str += "\n Path: " + get_struct_name ().as_string (); @@ -3721,8 +3720,8 @@ StructExprStruct::as_string () const } else { - // note that this does not print them with "inner attribute" syntax - - // just the body + /* 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 (); @@ -3732,10 +3731,10 @@ StructExprStruct::as_string () const return str; } -::std::string +std::string StructBase::as_string () const { - if (base_struct != NULL) + if (base_struct != nullptr) { return base_struct->as_string (); } @@ -3745,30 +3744,29 @@ StructBase::as_string () const } } -::std::string +std::string StructExprFieldWithVal::as_string () const { // used to get value string return value->as_string (); } -::std::string +std::string StructExprFieldIdentifierValue::as_string () const { return field_name + " : " + StructExprFieldWithVal::as_string (); } -::std::string +std::string StructExprFieldIndexValue::as_string () const { - return ::std::to_string (index) + " : " - + StructExprFieldWithVal::as_string (); + return std::to_string (index) + " : " + StructExprFieldWithVal::as_string (); } -::std::string +std::string StructExprStructFields::as_string () const { - ::std::string str = StructExprStruct::as_string (); + std::string str = StructExprStruct::as_string (); str += "\n Fields: "; if (fields.empty ()) @@ -3796,19 +3794,19 @@ StructExprStructFields::as_string () const return str; } -::std::string +std::string EnumItem::as_string () const { // outer attributes - ::std::string str = "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 + /* 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 (); @@ -3820,10 +3818,10 @@ EnumItem::as_string () const return str; } -::std::string +std::string EnumItemTuple::as_string () const { - ::std::string str = EnumItem::as_string (); + std::string str = EnumItem::as_string (); // add tuple opening parens str += "("; @@ -3848,19 +3846,19 @@ EnumItemTuple::as_string () const return str; } -::std::string +std::string TupleField::as_string () const { // outer attributes - ::std::string str = "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 + /* 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 (); @@ -3877,10 +3875,10 @@ TupleField::as_string () const return str; } -::std::string +std::string EnumItemStruct::as_string () const { - ::std::string str = EnumItem::as_string (); + std::string str = EnumItem::as_string (); // add struct opening parens str += "{"; @@ -3905,19 +3903,19 @@ EnumItemStruct::as_string () const return str; } -::std::string +std::string StructField::as_string () const { // outer attributes - ::std::string str = "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 + /* 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 (); @@ -3934,10 +3932,10 @@ StructField::as_string () const return str; } -::std::string +std::string EnumItemDiscriminant::as_string () const { - ::std::string str = EnumItem::as_string (); + std::string str = EnumItem::as_string (); // add equal and expression str += " = " + expression->as_string (); @@ -3945,19 +3943,19 @@ EnumItemDiscriminant::as_string () const return str; } -::std::string +std::string ExternalItem::as_string () const { // outer attributes - ::std::string str = "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 + /* 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 (); @@ -3970,10 +3968,10 @@ ExternalItem::as_string () const return str; } -::std::string +std::string ExternalStaticItem::as_string () const { - ::std::string str = ExternalItem::as_string (); + std::string str = ExternalItem::as_string (); str += "static "; @@ -3991,10 +3989,10 @@ ExternalStaticItem::as_string () const return str; } -::std::string +std::string ExternalFunctionItem::as_string () const { - ::std::string str = ExternalItem::as_string (); + std::string str = ExternalItem::as_string (); str += "fn "; @@ -4012,13 +4010,13 @@ ExternalFunctionItem::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in external function item."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -4060,19 +4058,19 @@ ExternalFunctionItem::as_string () const return str; } -::std::string +std::string NamedFunctionParam::as_string () const { - ::std::string str = name; + std::string str = name; str += "\n Type: " + param_type->as_string (); return str; } -/*::std::string TraitItem::as_string() const { +/*std::string TraitItem::as_string() const { // outer attributes - ::std::string str = "outer attributes: "; + std::string str = "outer attributes: "; if (outer_attrs.empty()) { str += "none"; } else { @@ -4085,18 +4083,18 @@ attr.as_string(); return str; }*/ -::std::string +std::string TraitItemFunc::as_string () const { - ::std::string str = "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 + /* 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 (); @@ -4118,10 +4116,10 @@ TraitItemFunc::as_string () const return str; } -::std::string +std::string TraitFunctionDecl::as_string () const { - ::std::string str = qualifiers.as_string () + "fn " + function_name; + std::string str = qualifiers.as_string () + "fn " + function_name; // generic params str += "\n Generic params: "; @@ -4134,13 +4132,13 @@ TraitFunctionDecl::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in trait function decl."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -4183,18 +4181,18 @@ TraitFunctionDecl::as_string () const return str; } -::std::string +std::string TraitItemMethod::as_string () const { - ::std::string str = "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 + /* 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 (); @@ -4216,10 +4214,10 @@ TraitItemMethod::as_string () const return str; } -::std::string +std::string TraitMethodDecl::as_string () const { - ::std::string str = qualifiers.as_string () + "fn " + function_name; + std::string str = qualifiers.as_string () + "fn " + function_name; // generic params str += "\n Generic params: "; @@ -4232,13 +4230,13 @@ TraitMethodDecl::as_string () const for (const auto ¶m : generic_params) { // DEBUG: null pointer check - if (param == NULL) + if (param == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "generic param in trait function decl."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + param->as_string (); @@ -4283,18 +4281,18 @@ TraitMethodDecl::as_string () const return str; } -::std::string +std::string TraitItemConst::as_string () const { - ::std::string str = "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 + /* 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 (); @@ -4311,18 +4309,18 @@ TraitItemConst::as_string () const return str; } -::std::string +std::string TraitItemType::as_string () const { - ::std::string str = "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 + /* 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 (); @@ -4341,13 +4339,13 @@ TraitItemType::as_string () const for (const auto &bound : type_param_bounds) { // DEBUG: null pointer check - if (bound == NULL) + if (bound == nullptr) { fprintf ( stderr, "something really terrible has gone wrong - null pointer " "type param bound in trait item type."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + bound->as_string (); @@ -4357,7 +4355,7 @@ TraitItemType::as_string () const return str; } -::std::string +std::string SelfParam::as_string () const { if (is_error ()) @@ -4369,7 +4367,7 @@ SelfParam::as_string () const if (has_type ()) { // type (i.e. not ref, no lifetime) - ::std::string str; + std::string str; if (is_mut) { @@ -4385,7 +4383,7 @@ SelfParam::as_string () const else if (has_lifetime ()) { // ref and lifetime - ::std::string str = "&" + lifetime.as_string () + " "; + std::string str = "&" + lifetime.as_string () + " "; if (is_mut) { @@ -4399,7 +4397,7 @@ SelfParam::as_string () const else if (has_ref) { // ref with no lifetime - ::std::string str = "&"; + std::string str = "&"; if (is_mut) { @@ -4413,7 +4411,7 @@ SelfParam::as_string () const else { // no ref, no type - ::std::string str; + std::string str; if (is_mut) { @@ -4427,16 +4425,16 @@ SelfParam::as_string () const } } -::std::string +std::string ArrayElemsCopied::as_string () const { return elem_to_copy->as_string () + "; " + num_copies->as_string (); } -::std::string +std::string LifetimeWhereClauseItem::as_string () const { - ::std::string str ("Lifetime: "); + std::string str ("Lifetime: "); str += lifetime.as_string (); @@ -4450,10 +4448,10 @@ LifetimeWhereClauseItem::as_string () const return str; } -::std::string +std::string TypeBoundWhereClauseItem::as_string () const { - ::std::string str ("For lifetimes: "); + std::string str ("For lifetimes: "); if (!has_for_lifetimes ()) { @@ -4474,9 +4472,9 @@ TypeBoundWhereClauseItem::as_string () const for (const auto &bound : type_param_bounds) { // debug null pointer check - if (bound == NULL) + if (bound == nullptr) { - return "NULL_POINTER_MARK - type param bounds"; + return "nullptr_POINTER_MARK - type param bounds"; } str += "\n " + bound->as_string (); @@ -4485,20 +4483,20 @@ TypeBoundWhereClauseItem::as_string () const return str; } -::std::string +std::string ArrayElemsValues::as_string () const { - ::std::string str; + std::string str; for (const auto &expr : values) { // DEBUG: null pointer check - if (expr == NULL) + if (expr == nullptr) { fprintf (stderr, "something really terrible has gone wrong - null pointer " "expr in array elems values."); - return "NULL_POINTER_MARK"; + return "nullptr_POINTER_MARK"; } str += "\n " + expr->as_string (); @@ -4507,10 +4505,10 @@ ArrayElemsValues::as_string () const return str; } -::std::string +std::string MaybeNamedParam::as_string () const { - ::std::string str; + std::string str; switch (param_kind) { @@ -4531,10 +4529,10 @@ MaybeNamedParam::as_string () const return str; } -::std::string +std::string MetaItemSeq::as_string () const { - ::std::string path_str = path.as_string () + "("; + std::string path_str = path.as_string () + "("; auto i = seq.begin (); auto e = seq.end (); @@ -4549,10 +4547,10 @@ MetaItemSeq::as_string () const return path_str + ")"; } -::std::string +std::string MetaListPaths::as_string () const { - ::std::string str = ident + "("; + std::string str = ident + "("; auto i = paths.begin (); auto e = paths.end (); @@ -4567,10 +4565,10 @@ MetaListPaths::as_string () const return str + ")"; } -::std::string +std::string MetaListNameValueStr::as_string () const { - ::std::string str = ident + "("; + std::string str = ident + "("; auto i = strs.begin (); auto e = strs.end (); @@ -4585,10 +4583,10 @@ MetaListNameValueStr::as_string () const return str + ")"; } -::std::string +std::string AttrInputMetaItemContainer::as_string () const { - ::std::string str = "("; + std::string str = "("; auto i = items.begin (); auto e = items.end (); @@ -4603,18 +4601,16 @@ AttrInputMetaItemContainer::as_string () const return str + ")"; } -// Override that calls the function recursively on all items contained within -// the module. +/* Override that calls the function recursively on all items contained within + * the module. */ void -ModuleBodied::add_crate_name (::std::vector< ::std::string> &names) const +ModuleBodied::add_crate_name (std::vector<std::string> &names) const { /* TODO: test whether module has been 'cfg'-ed out to determine whether to * exclude it from search */ for (const auto &item : items) - { - item->add_crate_name (names); - } + item->add_crate_name (names); } void @@ -4622,17 +4618,13 @@ Attribute::parse_attr_to_meta_item () { // only parse if has attribute input if (!has_attr_input ()) - { - return; - } + return; - ::std::unique_ptr<AttrInput> converted_input ( + std::unique_ptr<AttrInput> converted_input ( attr_input->parse_to_meta_item ()); - if (converted_input != NULL) - { - attr_input = ::std::move (converted_input); - } + if (converted_input != nullptr) + attr_input = std::move (converted_input); } AttrInput * @@ -4640,28 +4632,26 @@ DelimTokenTree::parse_to_meta_item () const { // must have token trees if (token_trees.empty ()) - { - return NULL; - } + return nullptr; - // assume top-level delim token tree in attribute - convert all nested ones - // to token stream - ::std::vector< ::std::unique_ptr<Token> > token_stream = to_token_stream (); + /* assume top-level delim token tree in attribute - convert all nested ones + * to token stream */ + std::vector<std::unique_ptr<Token>> token_stream = to_token_stream (); // TODO: replace this with a specialised converter that the token stream is // moved into /*int i = 0; - ::std::vector< ::std::unique_ptr<MetaItemInner> > meta_items( + std::vector<std::unique_ptr<MetaItemInner>> meta_items( parse_meta_item_seq(token_stream, i));*/ // something like: - MacroParser parser (::std::move (token_stream)); - ::std::vector< ::std::unique_ptr<MetaItemInner> > meta_items ( + MacroParser parser (std::move (token_stream)); + std::vector<std::unique_ptr<MetaItemInner>> meta_items ( parser.parse_meta_item_seq ()); - return new AttrInputMetaItemContainer (::std::move (meta_items)); + return new AttrInputMetaItemContainer (std::move (meta_items)); } -::std::unique_ptr<MetaItemInner> +std::unique_ptr<MetaItemInner> MacroParser::parse_meta_item_inner () { // if first tok not identifier, not a "special" case one @@ -4690,7 +4680,7 @@ MacroParser::parse_meta_item_inner () rust_error_at (peek_token ()->get_locus (), "unrecognised token '%s' in meta item", get_token_description (peek_token ()->get_id ())); - return NULL; + return nullptr; } } @@ -4706,7 +4696,7 @@ MacroParser::parse_meta_item_inner () { // meta word syntax skip_token (); - return ::std::unique_ptr<MetaWord> (new MetaWord (::std::move (ident))); + return std::unique_ptr<MetaWord> (new MetaWord (std::move (ident))); } if (peek_token (1)->get_id () == EQUAL) @@ -4716,12 +4706,12 @@ MacroParser::parse_meta_item_inner () && is_end_meta_item_tok (peek_token (3)->get_id ())) { // meta name value str syntax - ::std::string value = peek_token (2)->as_string (); + std::string value = peek_token (2)->as_string (); skip_token (2); - return ::std::unique_ptr<MetaNameValueStr> ( - new MetaNameValueStr (::std::move (ident), ::std::move (value))); + return std::unique_ptr<MetaNameValueStr> ( + new MetaNameValueStr (std::move (ident), std::move (value))); } else { @@ -4735,55 +4725,55 @@ MacroParser::parse_meta_item_inner () rust_error_at (peek_token (1)->get_locus (), "unexpected token '%s' after identifier in attribute", get_token_description (peek_token (1)->get_id ())); - return NULL; + return nullptr; } - // HACK: parse parenthesised sequence, and then try conversions to other - // stuff - ::std::vector< ::std::unique_ptr<MetaItemInner> > meta_items + /* HACK: parse parenthesised sequence, and then try conversions to other + * stuff */ + std::vector<std::unique_ptr<MetaItemInner>> meta_items = parse_meta_item_seq (); // pass for meta name value str - ::std::vector<MetaNameValueStr> meta_name_value_str_items; + std::vector<MetaNameValueStr> meta_name_value_str_items; for (const auto &item : meta_items) { - ::std::unique_ptr<MetaNameValueStr> converted_item ( + std::unique_ptr<MetaNameValueStr> converted_item ( item->to_meta_name_value_str ()); - if (converted_item == NULL) + if (converted_item == nullptr) { meta_name_value_str_items.clear (); break; } - meta_name_value_str_items.push_back (::std::move (*converted_item)); + meta_name_value_str_items.push_back (std::move (*converted_item)); } // if valid, return this if (!meta_name_value_str_items.empty ()) { - return ::std::unique_ptr<MetaListNameValueStr> ( - new MetaListNameValueStr (::std::move (ident), - ::std::move (meta_name_value_str_items))); + return std::unique_ptr<MetaListNameValueStr> ( + new MetaListNameValueStr (std::move (ident), + std::move (meta_name_value_str_items))); } // pass for meta list idents - /*::std::vector<Identifier> ident_items; + /*std::vector<Identifier> ident_items; for (const auto& item : meta_items) { - ::std::unique_ptr<Identifier> converted_ident(item->to_ident_item()); - if (converted_ident == NULL) { + std::unique_ptr<Identifier> converted_ident(item->to_ident_item()); + if (converted_ident == nullptr) { ident_items.clear(); break; } - ident_items.push_back(::std::move(*converted_ident)); + ident_items.push_back(std::move(*converted_ident)); } // if valid return this if (!ident_items.empty()) { - return ::std::unique_ptr<MetaListIdents>(new - MetaListIdents(::std::move(ident), - ::std::move(ident_items))); + return std::unique_ptr<MetaListIdents>(new + MetaListIdents(std::move(ident), + std::move(ident_items))); }*/ // as currently no meta list ident, currently no path. may change in future // pass for meta list paths - ::std::vector<SimplePath> path_items; + std::vector<SimplePath> path_items; for (const auto &item : meta_items) { SimplePath converted_path (item->to_path_item ()); @@ -4792,17 +4782,17 @@ MacroParser::parse_meta_item_inner () path_items.clear (); break; } - path_items.push_back (::std::move (converted_path)); + path_items.push_back (std::move (converted_path)); } if (!path_items.empty ()) { - return ::std::unique_ptr<MetaListPaths> ( - new MetaListPaths (::std::move (ident), ::std::move (path_items))); + return std::unique_ptr<MetaListPaths> ( + new MetaListPaths (std::move (ident), std::move (path_items))); } rust_error_at (Linemap::unknown_location (), "failed to parse any meta item inner"); - return NULL; + return nullptr; } bool @@ -4811,7 +4801,7 @@ MacroParser::is_end_meta_item_tok (TokenId id) const return id == COMMA || id == RIGHT_PAREN; } -::std::unique_ptr<MetaItem> +std::unique_ptr<MetaItem> MacroParser::parse_path_meta_item () { SimplePath path = parse_simple_path (); @@ -4819,17 +4809,17 @@ MacroParser::parse_path_meta_item () { rust_error_at (peek_token ()->get_locus (), "failed to parse simple path in attribute"); - return NULL; + return nullptr; } switch (peek_token ()->get_id ()) { case LEFT_PAREN: { - ::std::vector< ::std::unique_ptr<MetaItemInner> > meta_items + std::vector<std::unique_ptr<MetaItemInner>> meta_items = parse_meta_item_seq (); - return ::std::unique_ptr<MetaItemSeq> ( - new MetaItemSeq (::std::move (path), ::std::move (meta_items))); + return std::unique_ptr<MetaItemSeq> ( + new MetaItemSeq (std::move (path), std::move (meta_items))); } case EQUAL: { skip_token (); @@ -4840,30 +4830,30 @@ MacroParser::parse_path_meta_item () { rust_error_at (peek_token ()->get_locus (), "failed to parse literal in attribute"); - return NULL; + 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 - return ::std::unique_ptr<MetaItemPathLit> ( - new MetaItemPathLit (::std::move (path), ::std::move (expr))); + /* shouldn't be required anymore due to parsing literal actually + * skipping the token */ + return std::unique_ptr<MetaItemPathLit> ( + new MetaItemPathLit (std::move (path), std::move (expr))); } case COMMA: // just simple path - return ::std::unique_ptr<MetaItemPath> ( - new MetaItemPath (::std::move (path))); + return std::unique_ptr<MetaItemPath> ( + new MetaItemPath (std::move (path))); default: rust_error_at (peek_token ()->get_locus (), "unrecognised token '%s' in meta item", get_token_description (peek_token ()->get_id ())); - return NULL; + return nullptr; } } -// Parses a parenthesised sequence of meta item inners. Parentheses are -// required here. -::std::vector< ::std::unique_ptr<MetaItemInner> > +/* Parses a parenthesised sequence of meta item inners. Parentheses are + * required here. */ +std::vector<std::unique_ptr<MetaItemInner>> MacroParser::parse_meta_item_seq () { if (stream_pos != 0) @@ -4875,7 +4865,7 @@ MacroParser::parse_meta_item_seq () // int i = 0; int vec_length = token_stream.size (); - ::std::vector< ::std::unique_ptr<MetaItemInner> > meta_items; + std::vector<std::unique_ptr<MetaItemInner>> meta_items; if (peek_token ()->get_id () != LEFT_PAREN) { @@ -4887,14 +4877,14 @@ MacroParser::parse_meta_item_seq () while (stream_pos < vec_length && peek_token ()->get_id () != RIGHT_PAREN) { - ::std::unique_ptr<MetaItemInner> inner = parse_meta_item_inner (); - if (inner == NULL) + std::unique_ptr<MetaItemInner> inner = parse_meta_item_inner (); + if (inner == nullptr) { rust_error_at (peek_token ()->get_locus (), "failed to parse inner meta item in attribute"); return {}; } - meta_items.push_back (::std::move (inner)); + meta_items.push_back (std::move (inner)); if (peek_token ()->get_id () != COMMA) { @@ -4914,28 +4904,27 @@ MacroParser::parse_meta_item_seq () return meta_items; } -// Collects any nested token trees into a flat token stream, suitable for -// parsing. -::std::vector< ::std::unique_ptr<Token> > +/* Collects any nested token trees into a flat token stream, suitable for + * parsing. */ +std::vector<std::unique_ptr<Token>> DelimTokenTree::to_token_stream () const { - ::std::vector< ::std::unique_ptr<Token> > tokens; + std::vector<std::unique_ptr<Token>> tokens; // simulate presence of delimiters - tokens.push_back (::std::unique_ptr<Token> ( - new Token (LEFT_PAREN, Linemap::unknown_location (), "", - CORETYPE_UNKNOWN))); + tokens.push_back ( + std::unique_ptr<Token> (new Token (LEFT_PAREN, Linemap::unknown_location (), + "", CORETYPE_UNKNOWN))); for (const auto &tree : token_trees) { - ::std::vector< ::std::unique_ptr<Token> > stream - = tree->to_token_stream (); + std::vector<std::unique_ptr<Token>> stream = tree->to_token_stream (); - tokens.insert (tokens.end (), ::std::make_move_iterator (stream.begin ()), - ::std::make_move_iterator (stream.end ())); + tokens.insert (tokens.end (), std::make_move_iterator (stream.begin ()), + std::make_move_iterator (stream.end ())); } - tokens.push_back (::std::unique_ptr<Token> ( + tokens.push_back (std::unique_ptr<Token> ( new Token (RIGHT_PAREN, Linemap::unknown_location (), "", CORETYPE_UNKNOWN))); @@ -4947,7 +4936,7 @@ DelimTokenTree::to_token_stream () const Literal MacroParser::parse_literal () { - const ::std::unique_ptr<Token> &tok = peek_token (); + const std::unique_ptr<Token> &tok = peek_token (); switch (tok->get_id ()) { case CHAR_LITERAL: @@ -4991,7 +4980,7 @@ MacroParser::parse_simple_path () skip_token (); } - ::std::vector<SimplePathSegment> segments; + std::vector<SimplePathSegment> segments; SimplePathSegment segment = parse_simple_path_segment (); if (segment.is_error ()) @@ -5001,7 +4990,7 @@ MacroParser::parse_simple_path () "failed to parse simple path segment in attribute simple path"); return SimplePath::create_empty (); } - segments.push_back (::std::move (segment)); + segments.push_back (std::move (segment)); while (peek_token ()->get_id () == SCOPE_RESOLUTION) { @@ -5015,17 +5004,17 @@ MacroParser::parse_simple_path () "failed to parse simple path segment in attribute simple path"); return SimplePath::create_empty (); } - segments.push_back (::std::move (segment)); + segments.push_back (std::move (segment)); } segments.shrink_to_fit (); - return SimplePath (::std::move (segments), has_opening_scope_res); + return SimplePath (std::move (segments), has_opening_scope_res); } SimplePathSegment MacroParser::parse_simple_path_segment () { - const ::std::unique_ptr<Token> &tok = peek_token (); + const std::unique_ptr<Token> &tok = peek_token (); switch (tok->get_id ()) { case IDENTIFIER: @@ -5055,20 +5044,20 @@ MacroParser::parse_simple_path_segment () } } -::std::unique_ptr<MetaItemLitExpr> +std::unique_ptr<MetaItemLitExpr> MacroParser::parse_meta_item_lit () { Location locus = peek_token ()->get_locus (); LiteralExpr lit_expr (parse_literal (), locus); - return ::std::unique_ptr<MetaItemLitExpr> ( - new MetaItemLitExpr (::std::move (lit_expr))); + return std::unique_ptr<MetaItemLitExpr> ( + new MetaItemLitExpr (std::move (lit_expr))); } bool AttrInputMetaItemContainer::check_cfg_predicate (const Session &session) const { - // cfg value of container is purely based on cfg of each inner item - all - // must be true + /* cfg value of container is purely based on cfg of each inner item - all + * must be true */ for (const auto &inner_item : items) { if (!inner_item->check_cfg_predicate (session)) @@ -5087,8 +5076,8 @@ bool MetaItemLitExpr::check_cfg_predicate ( const Session &session ATTRIBUTE_UNUSED) const { - // as far as I can tell, a literal expr can never be a valid cfg body, so - // false + /* as far as I can tell, a literal expr can never be a valid cfg body, so + * false */ return false; } @@ -5121,13 +5110,13 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const { if (strs.size () != 1) { - // HACK: convert vector platform-dependent size_type to string to - // use in printf + /* HACK: convert vector platform-dependent size_type to string to + * use in printf */ rust_error_at (Linemap::unknown_location (), "cfg predicate could not be checked for " "MetaListNameValueStr with ident of " "'not' because there are '%s' elements, not '1'", - ::std::to_string (strs.size ()).c_str ()); + std::to_string (strs.size ()).c_str ()); return false; } @@ -5179,7 +5168,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const "cfg predicate could not be checked for MetaListPaths " "with ident of 'not' " "because there are '%s' elements, not '1'", - ::std::to_string (paths.size ()).c_str ()); + std::to_string (paths.size ()).c_str ()); return false; } @@ -5243,7 +5232,7 @@ MetaItemSeq::check_cfg_predicate (const Session &session) const "cfg predicate could not be checked for MetaItemSeq " "with ident of 'not' " "because there are '%s' elements, not '1'", - ::std::to_string (seq.size ()).c_str ()); + std::to_string (seq.size ()).c_str ()); return false; } @@ -5299,14 +5288,14 @@ MetaItemPathLit::check_cfg_predicate (const Session &session) const lit.as_string ()); } -::std::vector< ::std::unique_ptr<Token> > +std::vector<std::unique_ptr<Token>> Token::to_token_stream () const { // initialisation list doesn't work as it needs copy constructor, so have to // do this - ::std::vector< ::std::unique_ptr<Token> > dummy_vector; + std::vector<std::unique_ptr<Token>> dummy_vector; dummy_vector.reserve (1); - dummy_vector.push_back (::std::unique_ptr<Token> (clone_token_impl ())); + dummy_vector.push_back (std::unique_ptr<Token> (clone_token_impl ())); return dummy_vector; } diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index eb680b8..0d89d51 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -7,8 +7,8 @@ namespace Rust { namespace AST { -// Pure abstract class that provides an interface for accessing different -// classes of the AST. +/* Pure abstract class that provides an interface for accessing different + * classes of the AST. */ class ASTVisitor { public: diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 9ad2c4c..4c115b2 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -4,15 +4,12 @@ // GCC imports #include "config.h" -//#define INCLUDE_UNIQUE_PTR -// should allow including the gcc emulation of std::unique_ptr #include "system.h" -#include "coretypes.h" // order: config, INCLUDE, system, coretypes +#include "coretypes.h" // order: config, system, coretypes #include "rust-system.h" // STL imports -// with C++11, now can use actual std::unique_ptr #include <memory> #include <string> #include <vector> @@ -25,9 +22,7 @@ namespace Rust { // TODO: remove typedefs and make actual types for these -// typedef int Location; -// typedef ::std::string SimplePath; -typedef ::std::string Identifier; +typedef std::string Identifier; typedef int TupleIndex; struct Session; @@ -59,7 +54,7 @@ enum DelimType } // Get node output as a string. Pure virtual. - virtual ::std::string as_string() const = 0; + virtual std::string as_string() const = 0; virtual ~Node() {} @@ -79,19 +74,19 @@ public: virtual ~AttrInput () {} // Unique pointer custom clone function - ::std::unique_ptr<AttrInput> clone_attr_input () const + std::unique_ptr<AttrInput> clone_attr_input () const { - return ::std::unique_ptr<AttrInput> (clone_attr_input_impl ()); + return std::unique_ptr<AttrInput> (clone_attr_input_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; virtual bool check_cfg_predicate (const Session &session) const = 0; // Parse attribute input to meta item, if possible - virtual AttrInput *parse_to_meta_item () const { return NULL; } + virtual AttrInput *parse_to_meta_item () const { return nullptr; } protected: // pure virtual clone implementation @@ -108,19 +103,18 @@ public: virtual ~TokenTree () {} // Unique pointer custom clone function - ::std::unique_ptr<TokenTree> clone_token_tree () const + std::unique_ptr<TokenTree> clone_token_tree () const { - return ::std::unique_ptr<TokenTree> (clone_token_tree_impl ()); + return std::unique_ptr<TokenTree> (clone_token_tree_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; /* Converts token tree to a flat token stream. Tokens must be pointer to avoid * mutual dependency with Token. */ - virtual ::std::vector< ::std::unique_ptr<Token> > - to_token_stream () const = 0; + virtual std::vector<std::unique_ptr<Token>> to_token_stream () const = 0; protected: // pure virtual clone implementation @@ -133,12 +127,12 @@ class MacroMatch public: virtual ~MacroMatch () {} - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; // Unique pointer custom clone function - ::std::unique_ptr<MacroMatch> clone_macro_match () const + std::unique_ptr<MacroMatch> clone_macro_match () const { - return ::std::unique_ptr<MacroMatch> (clone_macro_match_impl ()); + return std::unique_ptr<MacroMatch> (clone_macro_match_impl ()); } virtual void accept_vis (ASTVisitor &vis) = 0; @@ -165,23 +159,23 @@ class Token : public TokenTree, public MacroMatch public: // Unique pointer custom clone function - ::std::unique_ptr<Token> clone_token () const + std::unique_ptr<Token> clone_token () const { - return ::std::unique_ptr<Token> (clone_token_impl ()); + return std::unique_ptr<Token> (clone_token_impl ()); } - // constructor from general text - avoid using if lexer const_TokenPtr is - // available - Token (TokenId token_id, Location locus, ::std::string str, + /* constructor from general text - avoid using if lexer const_TokenPtr is + * available */ + Token (TokenId token_id, Location locus, std::string str, PrimitiveCoreType type_hint) - : token_id (token_id), locus (locus), str (::std::move (str)), + : token_id (token_id), locus (locus), str (std::move (str)), type_hint (type_hint) {} // Constructor from lexer const_TokenPtr - /* TODO: find workaround for std::string being NULL - probably have to + /* TODO: find workaround for std::string being nullptr - probably have to * introduce new method in lexer Token, or maybe make conversion method - * there*/ + * there */ Token (const_TokenPtr lexer_token_ptr) : token_id (lexer_token_ptr->get_id ()), locus (lexer_token_ptr->get_locus ()), str (""), @@ -213,7 +207,7 @@ public: } } - inline bool is_string_lit () const + bool is_string_lit () const { switch (token_id) { @@ -225,13 +219,12 @@ public: } } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; // Return copy of itself but in token stream form. - virtual ::std::vector< ::std::unique_ptr<Token> > - to_token_stream () const OVERRIDE; + std::vector<std::unique_ptr<Token>> to_token_stream () const override; TokenId get_id () const { return token_id; } @@ -241,18 +234,15 @@ protected: // No virtual for now as not polymorphic but can be in future /*virtual*/ Token *clone_token_impl () const { return new Token (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual Token *clone_token_tree_impl () const OVERRIDE - { - return new Token (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + Token *clone_token_tree_impl () const override { return clone_token_impl (); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual Token *clone_macro_match_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + Token *clone_macro_match_impl () const override { - return new Token (*this); + return clone_token_impl (); } }; @@ -274,18 +264,18 @@ public: }; private: - // TODO: maybe make subclasses of each type of literal with their typed values - // (or generics) - ::std::string value_as_string; + /* TODO: maybe make subclasses of each type of literal with their typed values + * (or generics) */ + std::string value_as_string; LitType type; public: - ::std::string as_string () const { return value_as_string; } + std::string as_string () const { return value_as_string; } - inline LitType get_lit_type () const { return type; } + LitType get_lit_type () const { return type; } - Literal (::std::string value_as_string, LitType type) - : value_as_string (::std::move (value_as_string)), type (type) + Literal (std::string value_as_string, LitType type) + : value_as_string (std::move (value_as_string)), type (type) {} static Literal create_error () { return Literal ("", CHAR); } @@ -298,50 +288,35 @@ public: class DelimTokenTree : public TokenTree, public AttrInput { DelimType delim_type; - ::std::vector< ::std::unique_ptr<TokenTree> > token_trees; - + std::vector<std::unique_ptr<TokenTree>> token_trees; Location locus; - // TODO: move all the "parse" functions into a separate class that has the - // token stream reference - will be cleaner Parse a meta item inner. - //::std::unique_ptr<MetaItemInner> parse_meta_item_inner(const ::std::vector< - //::std::unique_ptr<Token> >& token_stream, int& i) const; SimplePath - // parse_simple_path(const ::std::vector< ::std::unique_ptr<Token> >& - // token_stream, int& i) const; SimplePathSegment - // parse_simple_path_segment(const ::std::vector< - // ::std::unique_ptr<Token> >& token_stream, int& i) const; - //::std::unique_ptr<MetaItemLitExpr> parse_meta_item_lit(const - //::std::unique_ptr<Token>& - // tok) const; - //::std::vector< ::std::unique_ptr<MetaItemInner> > parse_meta_item_seq(const - //::std::vector< ::std::unique_ptr<Token> >& token_stream, int& i) const; - // Literal - // parse_literal(const ::std::unique_ptr<Token>& tok) const; - //::std::unique_ptr<MetaItem> parse_path_meta_item(const ::std::vector< - //::std::unique_ptr<Token> >& token_stream, int& i) const; bool - // is_end_meta_item_tok(TokenId tok) const; - protected: - // Use covariance to implement clone function as returning a DelimTokenTree - // object - virtual DelimTokenTree *clone_attr_input_impl () const OVERRIDE + DelimTokenTree *clone_delim_tok_tree_impl () const { return new DelimTokenTree (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual DelimTokenTree *clone_token_tree_impl () const OVERRIDE + /* Use covariance to implement clone function as returning a DelimTokenTree + * object */ + DelimTokenTree *clone_attr_input_impl () const override { - return new DelimTokenTree (*this); + return clone_delim_tok_tree_impl (); + } + + /* Use covariance to implement clone function as returning a DelimTokenTree + * object */ + DelimTokenTree *clone_token_tree_impl () const override + { + return clone_delim_tok_tree_impl (); } public: DelimTokenTree (DelimType delim_type, - ::std::vector< ::std::unique_ptr<TokenTree> > token_trees - = ::std::vector< ::std::unique_ptr<TokenTree> > (), + std::vector<std::unique_ptr<TokenTree>> token_trees + = std::vector<std::unique_ptr<TokenTree>> (), Location locus = Location ()) - : delim_type (delim_type), token_trees (::std::move (token_trees)), + : delim_type (delim_type), token_trees (std::move (token_trees)), locus (locus) {} @@ -349,14 +324,9 @@ public: DelimTokenTree (DelimTokenTree const &other) : delim_type (other.delim_type), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? token_trees.reserve (other.token_trees.size ()); - for (const auto &e : other.token_trees) - { - token_trees.push_back (e->clone_token_tree ()); - } + token_trees.push_back (e->clone_token_tree ()); } // overloaded assignment operator with vector clone @@ -365,14 +335,9 @@ public: delim_type = other.delim_type; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? token_trees.reserve (other.token_trees.size ()); - for (const auto &e : other.token_trees) - { - token_trees.push_back (e->clone_token_tree ()); - } + token_trees.push_back (e->clone_token_tree ()); return *this; } @@ -383,35 +348,39 @@ public: static DelimTokenTree create_empty () { return DelimTokenTree (PARENS); } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - virtual bool - check_cfg_predicate (const Session &session ATTRIBUTE_UNUSED) const OVERRIDE + bool + check_cfg_predicate (const Session &session ATTRIBUTE_UNUSED) const override { // this should never be called - should be converted first return false; } - virtual AttrInput *parse_to_meta_item () const OVERRIDE; + AttrInput *parse_to_meta_item () const override; + + std::vector<std::unique_ptr<Token>> to_token_stream () const override; - virtual ::std::vector< ::std::unique_ptr<Token> > - to_token_stream () const OVERRIDE; + std::unique_ptr<DelimTokenTree> clone_delim_token_tree () const + { + return std::unique_ptr<DelimTokenTree> (clone_delim_tok_tree_impl ()); + } }; -// Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to -// be defined +/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to + * be defined */ class AttrInputLiteral; -// TODO: move applicable stuff into here or just don't include it because -// nothing uses it A segment of a path (maybe) +/* TODO: move applicable stuff into here or just don't include it because + * nothing uses it A segment of a path (maybe) */ class PathSegment { public: virtual ~PathSegment () {} - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; // TODO: add visitor here? }; @@ -419,29 +388,29 @@ public: // A segment of a simple path without generic or type arguments class SimplePathSegment : public PathSegment { - ::std::string segment_name; + std::string segment_name; Location locus; // only allow identifiers, "super", "self", "crate", or "$crate" public: // TODO: put checks in constructor to enforce this rule? - SimplePathSegment (::std::string segment_name, Location locus = Location ()) - : segment_name (::std::move (segment_name)), locus (locus) + SimplePathSegment (std::string segment_name, Location locus = Location ()) + : segment_name (std::move (segment_name)), locus (locus) {} - // Returns whether simple path segment is in an invalid state (currently, if - // empty). - inline bool is_error () const { return segment_name.empty (); } + /* Returns whether simple path segment is in an invalid state (currently, if + * empty). */ + bool is_error () const { return segment_name.empty (); } // Creates an error SimplePathSegment static SimplePathSegment create_error () { - return SimplePathSegment (::std::string ("")); + return SimplePathSegment (std::string ("")); } - ::std::string as_string () const; + std::string as_string () const override; - inline Location get_locus () const { return locus; } + Location get_locus () const { return locus; } // TODO: visitor pattern? }; @@ -450,35 +419,35 @@ public: class SimplePath { bool has_opening_scope_resolution; - ::std::vector<SimplePathSegment> segments; + std::vector<SimplePathSegment> segments; Location locus; public: // Constructor - SimplePath (::std::vector<SimplePathSegment> path_segments, + SimplePath (std::vector<SimplePathSegment> path_segments, bool has_opening_scope_resolution = false, Location locus = Location ()) : has_opening_scope_resolution (has_opening_scope_resolution), - segments (::std::move (path_segments)), locus (locus) + segments (std::move (path_segments)), locus (locus) {} // Creates an empty SimplePath. static SimplePath create_empty () { - return SimplePath (::std::vector<SimplePathSegment> ()); + return SimplePath (std::vector<SimplePathSegment> ()); } // Returns whether the SimplePath is empty, i.e. has path segments. - inline bool is_empty () const { return segments.empty (); } + bool is_empty () const { return segments.empty (); } - ::std::string as_string () const; + std::string as_string () const; Location get_locus () const { return locus; } // does this need visitor if not polymorphic? probably not // path-to-string comparison operator - bool operator== (const ::std::string &rhs) + bool operator== (const std::string &rhs) { return !has_opening_scope_resolution && segments.size () == 1 && segments[0].as_string () == rhs; @@ -488,11 +457,11 @@ public: * ensure that this is a valid identifier in path, so be careful. Also, this * will have no location data. * TODO have checks? */ - static SimplePath from_str (::std::string str) + static SimplePath from_str (std::string str) { - ::std::vector<AST::SimplePathSegment> single_segments - = {AST::SimplePathSegment (::std::move (str))}; - return SimplePath (::std::move (single_segments)); + std::vector<AST::SimplePathSegment> single_segments + = {AST::SimplePathSegment (std::move (str))}; + return SimplePath (std::move (single_segments)); } }; @@ -504,8 +473,7 @@ private: SimplePath path; // bool has_attr_input; - // AttrInput* attr_input; - ::std::unique_ptr<AttrInput> attr_input; + std::unique_ptr<AttrInput> attr_input; Location locus; @@ -513,37 +481,33 @@ private: public: // Returns whether Attribute has AttrInput - inline bool has_attr_input () const { return attr_input != NULL; } + bool has_attr_input () const { return attr_input != nullptr; } // Constructor has pointer AttrInput for polymorphism reasons - Attribute (SimplePath path, ::std::unique_ptr<AttrInput> input, + Attribute (SimplePath path, std::unique_ptr<AttrInput> input, Location locus = Location ()) - : path (::std::move (path)), attr_input (::std::move (input)), locus (locus) + : path (std::move (path)), attr_input (std::move (input)), locus (locus) {} + // default destructor + ~Attribute () = default; + // Copy constructor must deep copy attr_input as unique pointer Attribute (Attribute const &other) : path (other.path), locus (other.locus) { // guard to protect from null pointer dereference - if (other.attr_input != NULL) - { - attr_input = other.attr_input->clone_attr_input (); - } + if (other.attr_input != nullptr) + attr_input = other.attr_input->clone_attr_input (); } - // default destructor - ~Attribute () = default; - // overload assignment operator to use custom clone method Attribute &operator= (Attribute const &other) { path = other.path; locus = other.locus; // guard to protect from null pointer dereference - if (other.attr_input != NULL) - { - attr_input = other.attr_input->clone_attr_input (); - } + if (other.attr_input != nullptr) + attr_input = other.attr_input->clone_attr_input (); return *this; } @@ -553,26 +517,19 @@ public: Attribute &operator= (Attribute &&other) = default; // Unique pointer custom clone function - ::std::unique_ptr<Attribute> clone_attribute () const + std::unique_ptr<Attribute> clone_attribute () const { - return ::std::unique_ptr<Attribute> (clone_attribute_impl ()); + return std::unique_ptr<Attribute> (clone_attribute_impl ()); } - /*~Attribute() { - delete attr_input; - }*/ - // Creates an empty attribute (which is invalid) static Attribute create_empty () { - return Attribute (SimplePath::create_empty (), NULL); + return Attribute (SimplePath::create_empty (), nullptr); } // Returns whether the attribute is considered an "empty" attribute. - inline bool is_empty () const - { - return attr_input == NULL && path.is_empty (); - } + bool is_empty () const { return attr_input == nullptr && path.is_empty (); } /* e.g.: #![crate_type = "lib"] @@ -626,7 +583,7 @@ public: * windows_subsystem * feature */ - ::std::string as_string () const; + std::string as_string () const; // TODO: does this require visitor pattern as not polymorphic? @@ -636,17 +593,15 @@ public: // Call to parse attribute body to meta item syntax. void parse_attr_to_meta_item (); - // Determines whether cfg predicate is true and item with attribute should not - // be stripped. + /* Determines whether cfg predicate is true and item with attribute should not + * be stripped. */ bool check_cfg_predicate (const Session &session) { - // assume that cfg predicate actually can exist, i.e. attribute has cfg or - // cfg_attr path + /* assume that cfg predicate actually can exist, i.e. attribute has cfg or + * cfg_attr path */ if (!has_attr_input ()) - { - return false; - } + return false; // TODO: maybe replace with storing a "has been parsed" variable? parse_attr_to_meta_item (); @@ -675,20 +630,20 @@ protected: public: // Unique pointer custom clone function - ::std::unique_ptr<MetaItemInner> clone_meta_item_inner () const + std::unique_ptr<MetaItemInner> clone_meta_item_inner () const { - return ::std::unique_ptr<MetaItemInner> (clone_meta_item_inner_impl ()); + return std::unique_ptr<MetaItemInner> (clone_meta_item_inner_impl ()); } virtual ~MetaItemInner () {} - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; - // HACK: used to simplify parsing - creates a copy of that type, or returns - // null - virtual MetaNameValueStr *to_meta_name_value_str () const { return NULL; } + /* HACK: used to simplify parsing - creates a copy of that type, or returns + * null */ + virtual MetaNameValueStr *to_meta_name_value_str () const { return nullptr; } // HACK: used to simplify parsing - same thing virtual SimplePath to_path_item () const @@ -702,63 +657,67 @@ public: // Container used to store MetaItems as AttrInput (bridge-ish kinda thing) class AttrInputMetaItemContainer : public AttrInput { - ::std::vector< ::std::unique_ptr<MetaItemInner> > items; + std::vector<std::unique_ptr<MetaItemInner>> items; public: AttrInputMetaItemContainer ( - ::std::vector< ::std::unique_ptr<MetaItemInner> > items) - : items (::std::move (items)) + std::vector<std::unique_ptr<MetaItemInner>> items) + : items (std::move (items)) {} + // no destructor definition required + + // default move constructors + AttrInputMetaItemContainer (AttrInputMetaItemContainer &&other) = default; + AttrInputMetaItemContainer &operator= (AttrInputMetaItemContainer &&other) + = default; + + std::string as_string () const override; + + void accept_vis (ASTVisitor &vis) override; + + bool check_cfg_predicate (const Session &session) const override; + + // Clones this object. + std::unique_ptr<AttrInputMetaItemContainer> + clone_attr_input_meta_item_container () const + { + return std::unique_ptr<AttrInputMetaItemContainer> ( + clone_attr_input_meta_item_container_impl ()); + } + +protected: + // Use covariance to implement clone function as returning this type + AttrInputMetaItemContainer *clone_attr_input_impl () const override + { + return clone_attr_input_meta_item_container_impl (); + } + + AttrInputMetaItemContainer *clone_attr_input_meta_item_container_impl () const + { + return new AttrInputMetaItemContainer (*this); + } + // copy constructor with vector clone AttrInputMetaItemContainer (const AttrInputMetaItemContainer &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? items.reserve (other.items.size ()); - for (const auto &e : other.items) - { - items.push_back (e->clone_meta_item_inner ()); - } + items.push_back (e->clone_meta_item_inner ()); } - // no destructor definition required - // copy assignment operator with vector clone AttrInputMetaItemContainer & operator= (const AttrInputMetaItemContainer &other) { AttrInput::operator= (other); - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? - items.reserve (other.items.size ()); + items.reserve (other.items.size ()); for (const auto &e : other.items) - { - items.push_back (e->clone_meta_item_inner ()); - } + items.push_back (e->clone_meta_item_inner ()); return *this; } - - // default move constructors - AttrInputMetaItemContainer (AttrInputMetaItemContainer &&other) = default; - AttrInputMetaItemContainer &operator= (AttrInputMetaItemContainer &&other) - = default; - - ::std::string as_string () const OVERRIDE; - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; - - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; - -protected: - // Use covariance to implement clone function as returning this type - virtual AttrInputMetaItemContainer *clone_attr_input_impl () const OVERRIDE - { - return new AttrInputMetaItemContainer (*this); - } }; // abstract base meta item class @@ -793,19 +752,19 @@ class Stmt { public: // Unique pointer custom clone function - ::std::unique_ptr<Stmt> clone_stmt () const + std::unique_ptr<Stmt> clone_stmt () const { - return ::std::unique_ptr<Stmt> (clone_stmt_impl ()); + return std::unique_ptr<Stmt> (clone_stmt_impl ()); } virtual ~Stmt () {} - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; - // HACK: slow way of getting location from base expression through virtual - // methods. + /* HACK: slow way of getting location from base expression through virtual + * methods. */ virtual Location get_locus_slow () const { return Location (); } protected: @@ -816,31 +775,31 @@ protected: // Rust "item" AST node (declaration of top-level/module-level allowed stuff) class Item : public Stmt { - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; // TODO: should outer attrs be defined here or in each derived class? public: // Unique pointer custom clone function - ::std::unique_ptr<Item> clone_item () const + std::unique_ptr<Item> clone_item () const { - return ::std::unique_ptr<Item> (clone_item_impl ()); + return std::unique_ptr<Item> (clone_item_impl ()); } - ::std::string as_string () const; + std::string as_string () const; - // Adds crate names to the vector passed by reference, if it can - // (polymorphism). + /* Adds crate names to the vector passed by reference, if it can + * (polymorphism). */ virtual void - add_crate_name (::std::vector< ::std::string> &names ATTRIBUTE_UNUSED) const + add_crate_name (std::vector<std::string> &names ATTRIBUTE_UNUSED) const {} virtual void accept_vis (ASTVisitor &vis ATTRIBUTE_UNUSED) {} protected: // Constructor - Item (::std::vector<Attribute> outer_attribs = ::std::vector<Attribute> ()) - : outer_attrs (::std::move (outer_attribs)) + Item (std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) + : outer_attrs (std::move (outer_attribs)) {} // Clone function implementation as pure virtual method @@ -849,7 +808,7 @@ protected: /* Save having to specify two clone methods in derived classes by making * statement clone return item clone. Hopefully won't affect performance too * much. */ - virtual Item *clone_stmt_impl () const OVERRIDE { return clone_item_impl (); } + Item *clone_stmt_impl () const override { return clone_item_impl (); } }; // forward decl of ExprWithoutBlock @@ -859,18 +818,15 @@ class ExprWithoutBlock; class Expr { // TODO: move outer attribute data to derived classes? - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; public: - inline const ::std::vector<Attribute> &get_outer_attrs () const - { - return outer_attrs; - } + const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; } // Unique pointer custom clone function - ::std::unique_ptr<Expr> clone_expr () const + std::unique_ptr<Expr> clone_expr () const { - return ::std::unique_ptr<Expr> (clone_expr_impl ()); + return std::unique_ptr<Expr> (clone_expr_impl ()); } /* TODO: public methods that could be useful: @@ -878,33 +834,25 @@ public: * for some? * - evaluate() - evaluates expression if constant? can_evaluate()? */ - // HACK: downcasting without dynamic_cast (if possible) via polymorphism - - // overrided in subclasses of ExprWithoutBlock - virtual ExprWithoutBlock *as_expr_without_block () const - { - // DEBUG - fprintf ( - stderr, - "clone expr without block returns null and has not been overriden\n"); - - return NULL; - } + /* HACK: downcasting without dynamic_cast (if possible) via polymorphism - + * 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; virtual ~Expr () {} - // HACK: slow way of getting location from base expression through virtual - // methods. + /* HACK: slow way of getting location from base expression through virtual + * methods. */ virtual Location get_locus_slow () const { return Location (); } virtual void accept_vis (ASTVisitor &vis) = 0; protected: // Constructor - Expr (::std::vector<Attribute> outer_attribs = ::std::vector<Attribute> ()) - : outer_attrs (::std::move (outer_attribs)) + Expr (std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) + : outer_attrs (std::move (outer_attribs)) {} // Clone function implementation as pure virtual method @@ -912,9 +860,9 @@ 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) + void set_outer_attrs (std::vector<Attribute> outer_attrs_to_set) { - outer_attrs = ::std::move (outer_attrs_to_set); + outer_attrs = std::move (outer_attrs_to_set); } }; @@ -923,45 +871,41 @@ class ExprWithoutBlock : public Expr { protected: // Constructor - ExprWithoutBlock (::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : Expr (::std::move (outer_attribs)) + 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; /* Save having to specify two clone methods in derived classes by making expr - * clone - * return exprwithoutblock clone. Hopefully won't affect performance too much. - */ - virtual ExprWithoutBlock *clone_expr_impl () const OVERRIDE + * clone return exprwithoutblock clone. Hopefully won't affect performance too + * much. */ + ExprWithoutBlock *clone_expr_impl () const override { return clone_expr_without_block_impl (); } public: // Unique pointer custom clone function - ::std::unique_ptr<ExprWithoutBlock> clone_expr_without_block () const + std::unique_ptr<ExprWithoutBlock> clone_expr_without_block () const { - return ::std::unique_ptr<ExprWithoutBlock> ( - clone_expr_without_block_impl ()); + return std::unique_ptr<ExprWithoutBlock> (clone_expr_without_block_impl ()); } - // downcasting hack from expr to use pratt parsing with - // parse_expr_without_block - virtual ExprWithoutBlock *as_expr_without_block () const OVERRIDE + /* downcasting hack from expr to use pratt parsing with + * parse_expr_without_block */ + ExprWithoutBlock *as_expr_without_block () const override { - // DEBUG - fprintf (stderr, "about to call the impl for clone expr without block\n"); - return clone_expr_without_block_impl (); } }; -// HACK: IdentifierExpr, delete when figure out identifier vs expr problem in -// Pratt parser Alternatively, identifiers could just be represented as -// single-segment paths +/* HACK: IdentifierExpr, delete when figure out identifier vs expr problem in + * Pratt parser */ +/* Alternatively, identifiers could just be represented as single-segment paths + */ class IdentifierExpr : public ExprWithoutBlock { public: @@ -970,26 +914,39 @@ public: Location locus; IdentifierExpr (Identifier ident, Location locus = Location (), - ::std::vector<Attribute> outer_attrs - = ::std::vector<Attribute> ()) - : ExprWithoutBlock (::std::move (outer_attrs)), ident (::std::move (ident)), + std::vector<Attribute> outer_attrs + = std::vector<Attribute> ()) + : ExprWithoutBlock (std::move (outer_attrs)), ident (std::move (ident)), locus (locus) {} - ::std::string as_string () const OVERRIDE { return ident; } + std::string as_string () const override { return ident; } Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } + void accept_vis (ASTVisitor &vis) override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + // Clones this object. + std::unique_ptr<IdentifierExpr> clone_identifier_expr () const + { + return std::unique_ptr<IdentifierExpr> (clone_identifier_expr_impl ()); + } protected: // Clone method implementation - virtual IdentifierExpr *clone_expr_without_block_impl () const OVERRIDE + IdentifierExpr *clone_expr_without_block_impl () const override + { + return clone_identifier_expr_impl (); + } + + IdentifierExpr *clone_identifier_expr_impl () const { return new IdentifierExpr (*this); } + + IdentifierExpr (IdentifierExpr const &other) = default; + IdentifierExpr &operator= (IdentifierExpr const &other) = default; }; // Pattern base AST node @@ -997,16 +954,16 @@ class Pattern { public: // Unique pointer custom clone function - ::std::unique_ptr<Pattern> clone_pattern () const + std::unique_ptr<Pattern> clone_pattern () const { - return ::std::unique_ptr<Pattern> (clone_pattern_impl ()); + return std::unique_ptr<Pattern> (clone_pattern_impl ()); } // possible virtual methods: is_refutable() virtual ~Pattern () {} - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -1023,24 +980,24 @@ class Type { public: // Unique pointer custom clone function - ::std::unique_ptr<Type> clone_type () const + std::unique_ptr<Type> clone_type () const { - return ::std::unique_ptr<Type> (clone_type_impl ()); + return std::unique_ptr<Type> (clone_type_impl ()); } // virtual destructor virtual ~Type () {} - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; - // HACK: convert to trait bound. Virtual method overriden by classes that - // enable this. + /* HACK: convert to trait bound. Virtual method overriden by classes that + * enable this. */ virtual TraitBound *to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const { - return NULL; + return nullptr; } - // as pointer, shouldn't require definition beforehand, only forward - // declaration. + /* as pointer, shouldn't require definition beforehand, only forward + * declaration. */ virtual void accept_vis (ASTVisitor &vis) = 0; @@ -1054,9 +1011,9 @@ class TypeNoBounds : public Type { public: // Unique pointer custom clone function - ::std::unique_ptr<TypeNoBounds> clone_type_no_bounds () const + std::unique_ptr<TypeNoBounds> clone_type_no_bounds () const { - return ::std::unique_ptr<TypeNoBounds> (clone_type_no_bounds_impl ()); + return std::unique_ptr<TypeNoBounds> (clone_type_no_bounds_impl ()); } protected: @@ -1066,26 +1023,26 @@ protected: /* Save having to specify two clone methods in derived classes by making type * clone return typenobounds clone. Hopefully won't affect performance too * much. */ - virtual TypeNoBounds *clone_type_impl () const OVERRIDE + TypeNoBounds *clone_type_impl () const override { return clone_type_no_bounds_impl (); } }; -// Abstract base class representing a type param bound - Lifetime and TraitBound -// extends it +/* Abstract base class representing a type param bound - Lifetime and TraitBound + * extends it */ class TypeParamBound { public: virtual ~TypeParamBound () {} // Unique pointer custom clone function - ::std::unique_ptr<TypeParamBound> clone_type_param_bound () const + std::unique_ptr<TypeParamBound> clone_type_param_bound () const { - return ::std::unique_ptr<TypeParamBound> (clone_type_param_bound_impl ()); + return std::unique_ptr<TypeParamBound> (clone_type_param_bound_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -1110,54 +1067,54 @@ private: // TODO: LIFETIME_OR_LABEL (aka lifetime token) is only field // find way of enclosing token or something - ::std::string lifetime_name; + std::string lifetime_name; // only applies for NAMED lifetime_type Location locus; public: // Constructor - Lifetime (LifetimeType type, ::std::string name = ::std::string (), + Lifetime (LifetimeType type, std::string name = std::string (), Location locus = Location ()) - : lifetime_type (type), lifetime_name (::std::move (name)), locus (locus) + : lifetime_type (type), lifetime_name (std::move (name)), locus (locus) {} // Creates an "error" lifetime. - static Lifetime error () { return Lifetime (NAMED, ::std::string ("")); } + static Lifetime error () { return Lifetime (NAMED, std::string ("")); } // Returns true if the lifetime is in an error state. - inline bool is_error () const + bool is_error () const { return lifetime_type == NAMED && lifetime_name.empty (); } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual Lifetime *clone_type_param_bound_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + Lifetime *clone_type_param_bound_impl () const override { return new Lifetime (*this); } }; -// Base generic parameter in AST. Abstract - can be represented by a Lifetime or -// Type param +/* Base generic parameter in AST. Abstract - can be represented by a Lifetime or + * Type param */ class GenericParam { public: virtual ~GenericParam () {} // Unique pointer custom clone function - ::std::unique_ptr<GenericParam> clone_generic_param () const + std::unique_ptr<GenericParam> clone_generic_param () const { - return ::std::unique_ptr<GenericParam> (clone_generic_param_impl ()); + return std::unique_ptr<GenericParam> (clone_generic_param_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -1173,20 +1130,20 @@ class LifetimeParam : public GenericParam // bool has_lifetime_bounds; // LifetimeBounds lifetime_bounds; - ::std::vector<Lifetime> lifetime_bounds; // inlined LifetimeBounds + std::vector<Lifetime> lifetime_bounds; // inlined LifetimeBounds // bool has_outer_attribute; - //::std::unique_ptr<Attribute> outer_attr; + // std::unique_ptr<Attribute> outer_attr; Attribute outer_attr; Location locus; public: // Returns whether the lifetime param has any lifetime bounds. - inline bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); } + bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); } // Returns whether the lifetime param has an outer attribute. - inline bool has_outer_attribute () const { return !outer_attr.is_empty (); } + bool has_outer_attribute () const { return !outer_attr.is_empty (); } // Creates an error state lifetime param. static LifetimeParam create_error () @@ -1195,16 +1152,16 @@ public: } // Returns whether the lifetime param is in an error state. - inline bool is_error () const { return lifetime.is_error (); } + bool is_error () const { return lifetime.is_error (); } // Constructor LifetimeParam (Lifetime lifetime, Location locus = Location (), - ::std::vector<Lifetime> lifetime_bounds - = ::std::vector<Lifetime> (), + std::vector<Lifetime> lifetime_bounds + = std::vector<Lifetime> (), Attribute outer_attr = Attribute::create_empty ()) - : lifetime (::std::move (lifetime)), - lifetime_bounds (::std::move (lifetime_bounds)), - outer_attr (::std::move (outer_attr)), locus (locus) + : lifetime (std::move (lifetime)), + lifetime_bounds (std::move (lifetime_bounds)), + outer_attr (std::move (outer_attr)), locus (locus) {} // TODO: remove copy and assignment operator definitions - not required @@ -1215,8 +1172,6 @@ public: outer_attr (other.outer_attr), locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone attribute LifetimeParam &operator= (LifetimeParam const &other) { @@ -1232,14 +1187,14 @@ public: LifetimeParam (LifetimeParam &&other) = default; LifetimeParam &operator= (LifetimeParam &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual LifetimeParam *clone_generic_param_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + LifetimeParam *clone_generic_param_impl () const override { return new LifetimeParam (*this); } @@ -1249,10 +1204,10 @@ protected: class MacroItem : public Item { /*public: - ::std::string as_string() const;*/ + std::string as_string() const;*/ protected: - MacroItem (::std::vector<Attribute> outer_attribs) - : Item (::std::move (outer_attribs)) + MacroItem (std::vector<Attribute> outer_attribs) + : Item (std::move (outer_attribs)) {} }; @@ -1261,14 +1216,14 @@ class TraitItem { // bool has_outer_attrs; // TODO: remove and rely on virtual functions and VisItem-derived attributes? - //::std::vector<Attribute> outer_attrs; + // std::vector<Attribute> outer_attrs; // NOTE: all children should have outer attributes protected: // Constructor - /*TraitItem(::std::vector<Attribute> outer_attrs = ::std::vector<Attribute>()) - : outer_attrs(::std::move(outer_attrs)) {}*/ + /*TraitItem(std::vector<Attribute> outer_attrs = std::vector<Attribute>()) + : outer_attrs(std::move(outer_attrs)) {}*/ // Clone function implementation as pure virtual method virtual TraitItem *clone_trait_item_impl () const = 0; @@ -1277,23 +1232,23 @@ public: virtual ~TraitItem () {} // Returns whether TraitItem has outer attributes. - /*inline bool has_outer_attrs() const { + /*bool has_outer_attrs() const { return !outer_attrs.empty(); }*/ // Unique pointer custom clone function - ::std::unique_ptr<TraitItem> clone_trait_item () const + std::unique_ptr<TraitItem> clone_trait_item () const { - return ::std::unique_ptr<TraitItem> (clone_trait_item_impl ()); + return std::unique_ptr<TraitItem> (clone_trait_item_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; }; -// Abstract base class for items used within an inherent impl block (the impl -// name {} one) +/* Abstract base class for items used within an inherent impl block (the impl + * name {} one) */ class InherentImplItem { protected: @@ -1304,13 +1259,12 @@ public: virtual ~InherentImplItem () {} // Unique pointer custom clone function - ::std::unique_ptr<InherentImplItem> clone_inherent_impl_item () const + std::unique_ptr<InherentImplItem> clone_inherent_impl_item () const { - return ::std::unique_ptr<InherentImplItem> ( - clone_inherent_impl_item_impl ()); + return std::unique_ptr<InherentImplItem> (clone_inherent_impl_item_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; }; @@ -1325,42 +1279,37 @@ public: virtual ~TraitImplItem (){}; // Unique pointer custom clone function - ::std::unique_ptr<TraitImplItem> clone_trait_impl_item () const + std::unique_ptr<TraitImplItem> clone_trait_impl_item () const { - return ::std::unique_ptr<TraitImplItem> (clone_trait_impl_item_impl ()); + return std::unique_ptr<TraitImplItem> (clone_trait_impl_item_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; }; -// A macro invocation item (or statement) AST node (i.e. semi-coloned macro -// invocation) +/* A macro invocation item (or statement) AST node (i.e. semi-coloned macro + * invocation) */ class MacroInvocationSemi : public MacroItem, public TraitItem, public InherentImplItem, public TraitImplItem -/*, public Statement*/ { - // already inherits from statement indirectly via item as item is a subclass - // of statement +{ SimplePath path; // all delim types except curly must have invocation end with a semicolon DelimType delim_type; - //::std::vector<TokenTree> token_trees; - ::std::vector< ::std::unique_ptr<TokenTree> > token_trees; - + std::vector<std::unique_ptr<TokenTree>> token_trees; Location locus; public: - ::std::string as_string () const; - - MacroInvocationSemi ( - SimplePath macro_path, DelimType delim_type, - ::std::vector< ::std::unique_ptr<TokenTree> > token_trees, - ::std::vector<Attribute> outer_attribs, Location locus) - : MacroItem (::std::move (outer_attribs)), path (::std::move (macro_path)), - delim_type (delim_type), token_trees (::std::move (token_trees)), + std::string as_string () const override; + + MacroInvocationSemi (SimplePath macro_path, DelimType delim_type, + std::vector<std::unique_ptr<TokenTree>> token_trees, + std::vector<Attribute> outer_attribs, Location locus) + : MacroItem (std::move (outer_attribs)), path (std::move (macro_path)), + delim_type (delim_type), token_trees (std::move (token_trees)), locus (locus) {} /* TODO: possible issue with Item and TraitItem hierarchies both having outer @@ -1371,20 +1320,29 @@ public: * approach, but then this prevents polymorphism and would entail redoing * quite a bit of the parser. */ + // Move constructors + MacroInvocationSemi (MacroInvocationSemi &&other) = default; + MacroInvocationSemi &operator= (MacroInvocationSemi &&other) = default; + + void accept_vis (ASTVisitor &vis) override; + + // Clones this macro invocation semi. + std::unique_ptr<MacroInvocationSemi> clone_macro_invocation_semi () const + { + return std::unique_ptr<MacroInvocationSemi> ( + clone_macro_invocation_semi_impl ()); + } + +protected: // Copy constructor with vector clone MacroInvocationSemi (MacroInvocationSemi const &other) : MacroItem (other), TraitItem (other), InherentImplItem (other), TraitImplItem (other), path (other.path), delim_type (other.delim_type), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? token_trees.reserve (other.token_trees.size ()); - for (const auto &e : other.token_trees) - { - token_trees.push_back (e->clone_token_tree ()); - } + token_trees.push_back (e->clone_token_tree ()); } // Overloaded assignment operator to vector clone @@ -1398,58 +1356,51 @@ public: delim_type = other.delim_type; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? token_trees.reserve (other.token_trees.size ()); - for (const auto &e : other.token_trees) - { - token_trees.push_back (e->clone_token_tree ()); - } + token_trees.push_back (e->clone_token_tree ()); return *this; } - // Move constructors - MacroInvocationSemi (MacroInvocationSemi &&other) = default; - MacroInvocationSemi &operator= (MacroInvocationSemi &&other) = default; - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; - -protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocationSemi *clone_item_impl () const OVERRIDE + MacroInvocationSemi *clone_macro_invocation_semi_impl () const { return new MacroInvocationSemi (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocationSemi *clone_inherent_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocationSemi *clone_item_impl () const override { - return new MacroInvocationSemi (*this); + return clone_macro_invocation_semi_impl (); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocationSemi *clone_trait_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocationSemi *clone_inherent_impl_item_impl () const override { - return new MacroInvocationSemi (*this); + return clone_macro_invocation_semi_impl (); + } + + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocationSemi *clone_trait_impl_item_impl () const override + { + return clone_macro_invocation_semi_impl (); } // FIXME: remove if item impl virtual override works properly // Use covariance to implement clone function as returning this object rather // than base - /*virtual MacroInvocationSemi* clone_statement_impl() const OVERRIDE { - return new MacroInvocationSemi(*this); + /*MacroInvocationSemi* clone_statement_impl() const override { + return clone_macro_invocation_semi_impl (); }*/ - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocationSemi *clone_trait_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocationSemi *clone_trait_item_impl () const override { - return new MacroInvocationSemi (*this); + return clone_macro_invocation_semi_impl (); } }; @@ -1459,20 +1410,19 @@ struct Crate bool has_utf8bom; bool has_shebang; - ::std::vector<Attribute> inner_attrs; - //::std::vector<Item> items; + std::vector<Attribute> inner_attrs; // dodgy spacing required here - // TODO: is it better to have a vector of items here or a module (implicit - // top-level one)? - ::std::vector< ::std::unique_ptr<Item> > items; + /* TODO: is it better to have a vector of items here or a module (implicit + * top-level one)? */ + std::vector<std::unique_ptr<Item>> items; public: // Constructor - Crate (::std::vector< ::std::unique_ptr<Item> > items, - ::std::vector<Attribute> inner_attrs, bool has_utf8bom = false, + Crate (std::vector<std::unique_ptr<Item>> items, + std::vector<Attribute> inner_attrs, bool has_utf8bom = false, bool has_shebang = false) : has_utf8bom (has_utf8bom), has_shebang (has_shebang), - inner_attrs (::std::move (inner_attrs)), items (::std::move (items)) + inner_attrs (std::move (inner_attrs)), items (std::move (items)) {} // Copy constructor with vector clone @@ -1480,14 +1430,9 @@ public: : has_utf8bom (other.has_utf8bom), has_shebang (other.has_shebang), inner_attrs (other.inner_attrs) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? items.reserve (other.items.size ()); - for (const auto &e : other.items) - { - items.push_back (e->clone_item ()); - } + items.push_back (e->clone_item ()); } ~Crate () = default; @@ -1499,14 +1444,9 @@ public: has_shebang = other.has_shebang; has_utf8bom = other.has_utf8bom; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? items.reserve (other.items.size ()); - for (const auto &e : other.items) - { - items.push_back (e->clone_item ()); - } + items.push_back (e->clone_item ()); return *this; } @@ -1516,25 +1456,25 @@ public: Crate &operator= (Crate &&other) = default; // Get crate representation as string (e.g. for debugging). - ::std::string as_string () const; + std::string as_string () const; }; // Base path expression AST node - abstract class PathExpr : public ExprWithoutBlock { protected: - PathExpr (::std::vector<Attribute> outer_attribs) - : ExprWithoutBlock (::std::move (outer_attribs)) + 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) + /* 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)); + set_outer_attrs (std::move (outer_attrs)); } }; } // namespace AST diff --git a/gcc/rust/ast/rust-cond-compilation.h b/gcc/rust/ast/rust-cond-compilation.h index ae6eb0a..cef8ebb 100644 --- a/gcc/rust/ast/rust-cond-compilation.h +++ b/gcc/rust/ast/rust-cond-compilation.h @@ -13,10 +13,9 @@ public: virtual ~ConfigurationPredicate () {} // Unique pointer custom clone function - ::std::unique_ptr<ConfigurationPredicate> - clone_configuration_predicate () const + std::unique_ptr<ConfigurationPredicate> clone_configuration_predicate () const { - return ::std::unique_ptr<ConfigurationPredicate> ( + return std::unique_ptr<ConfigurationPredicate> ( clone_configuration_predicate_impl ()); } @@ -35,28 +34,27 @@ class ConfigurationOption : public ConfigurationPredicate Identifier option_name; // bool has_string_literal_option_body; - ::std::string option_value; // technically a string or raw string literal + std::string option_value; // technically a string or raw string literal public: - // Returns whether the configuration option has a "value" part of the - // key-value pair. - inline bool has_option_value () const { return !option_value.empty (); } + /* Returns whether the configuration option has a "value" part of the + * key-value pair. */ + bool has_option_value () const { return !option_value.empty (); } // Key-value pair constructor - ConfigurationOption (Identifier option_name, ::std::string option_value) + ConfigurationOption (Identifier option_name, std::string option_value) : option_name (option_name), option_value (option_value) {} // Name-only constructor ConfigurationOption (Identifier option_name) : option_name (option_name) {} - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ConfigurationOption * - clone_configuration_predicate_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ConfigurationOption *clone_configuration_predicate_impl () const override { return new ConfigurationOption (*this); } @@ -65,27 +63,27 @@ protected: // TODO: inline struct ConfigurationPredicateList { - ::std::vector< ::std::unique_ptr<ConfigurationPredicate> > predicate_list; + std::vector<std::unique_ptr<ConfigurationPredicate>> predicate_list; }; // Predicate that returns true if all of the supplied predicates return true. class ConfigurationAll : public ConfigurationPredicate { - ::std::vector< ::std::unique_ptr<ConfigurationPredicate> > + std::vector<std::unique_ptr<ConfigurationPredicate>> predicate_list; // inlined form public: ConfigurationAll ( - ::std::vector< ::std::unique_ptr<ConfigurationPredicate> > predicate_list) + std::vector<std::unique_ptr<ConfigurationPredicate>> predicate_list) : predicate_list (predicate_list) {} - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ConfigurationAll *clone_configuration_predicate_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ConfigurationAll *clone_configuration_predicate_impl () const override { return new ConfigurationAll (*this); } @@ -94,31 +92,31 @@ protected: // Predicate that returns true if any of the supplied predicates are true. class ConfigurationAny : public ConfigurationPredicate { - ::std::vector< ::std::unique_ptr<ConfigurationPredicate> > + std::vector<std::unique_ptr<ConfigurationPredicate>> predicate_list; // inlined form public: ConfigurationAny ( - ::std::vector< ::std::unique_ptr<ConfigurationPredicate> > predicate_list) + std::vector<std::unique_ptr<ConfigurationPredicate>> predicate_list) : predicate_list (predicate_list) {} - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ConfigurationAny *clone_configuration_predicate_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ConfigurationAny *clone_configuration_predicate_impl () const override { return new ConfigurationAny (*this); } }; -// Predicate that produces the negation of a supplied other configuration -// predicate. +/* Predicate that produces the negation of a supplied other configuration + * predicate. */ class ConfigurationNot : public ConfigurationPredicate { - ::std::unique_ptr<ConfigurationPredicate> config_to_negate; + std::unique_ptr<ConfigurationPredicate> config_to_negate; public: ConfigurationNot (ConfigurationPredicate *config_to_negate) @@ -128,11 +126,9 @@ public: // Copy constructor with clone ConfigurationNot (ConfigurationNot const &other) : config_to_negate ( - other.config_to_negate->clone_configuration_predicate ()) + other.config_to_negate->clone_configuration_predicate ()) {} - // Destructor - define here if required - // Overloaded assignment operator to clone ConfigurationNot &operator= (ConfigurationNot const &other) { @@ -145,12 +141,12 @@ public: ConfigurationNot (ConfigurationNot &&other) = default; ConfigurationNot &operator= (ConfigurationNot &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ConfigurationNot *clone_configuration_predicate_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ConfigurationNot *clone_configuration_predicate_impl () const override { return new ConfigurationNot (*this); } @@ -159,7 +155,7 @@ protected: // TODO: relationship to other attributes? class CfgAttribute { - ::std::unique_ptr<ConfigurationPredicate> config_to_include; + std::unique_ptr<ConfigurationPredicate> config_to_include; public: CfgAttribute (ConfigurationPredicate *config_to_include) @@ -169,11 +165,9 @@ public: // Copy constructor with clone CfgAttribute (CfgAttribute const &other) : config_to_include ( - other.config_to_include->clone_configuration_predicate ()) + other.config_to_include->clone_configuration_predicate ()) {} - // Destructor - define here if required - // Overloaded assignment operator to clone CfgAttribute &operator= (CfgAttribute const &other) { @@ -195,30 +189,28 @@ public: // TODO: inline struct CfgAttrs { - ::std::vector<Attribute> cfg_attrs; + std::vector<Attribute> cfg_attrs; }; // TODO: relationship to other attributes? class CfgAttrAttribute { - ::std::unique_ptr<ConfigurationPredicate> config_to_include; - ::std::vector<Attribute> cfg_attrs; + std::unique_ptr<ConfigurationPredicate> config_to_include; + std::vector<Attribute> cfg_attrs; public: CfgAttrAttribute (ConfigurationPredicate *config_to_include, - ::std::vector<Attribute> cfg_attrs) + std::vector<Attribute> cfg_attrs) : config_to_include (config_to_include), cfg_attrs (cfg_attrs) {} // Copy constructor with clone CfgAttrAttribute (CfgAttrAttribute const &other) : config_to_include ( - other.config_to_include->clone_configuration_predicate ()), + other.config_to_include->clone_configuration_predicate ()), cfg_attrs (cfg_attrs) {} - // Destructor - define here if required - // Overloaded assignment operator to clone CfgAttrAttribute &operator= (CfgAttrAttribute const &other) { diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 91e176f..727cf3c 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -10,128 +10,84 @@ namespace AST { * "has_whatever" pairs with * optional types (std::optional or boost::optional)? */ -// forward decls: defined in rust-path.h, rust-type.h, rust-pattern.h, and -// rust-stmt.h -/*class PathInExpression; -class QualifiedPathInExpression; -class PathExprSegment;*/ // decls no longer required as "rust-path.h" is included -/*class Type; -class TypeNoBounds; -class Lifetime; -class Pattern; -class Statement;*/ // decls no longer required as definitions moved to rust-ast.h - -// Decl as definition moved to rust-ast.h -class ExprWithoutBlock; -class Function; - // 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)) + 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; // prevent having to define multiple clone expressions - virtual ExprWithBlock *clone_expr_impl () const OVERRIDE + ExprWithBlock *clone_expr_impl () const override { return clone_expr_with_block_impl (); } public: // Unique pointer custom clone function - ::std::unique_ptr<ExprWithBlock> clone_expr_with_block () const + std::unique_ptr<ExprWithBlock> clone_expr_with_block () const { - return ::std::unique_ptr<ExprWithBlock> (clone_expr_with_block_impl ()); + return std::unique_ptr<ExprWithBlock> (clone_expr_with_block_impl ()); } }; // Literals? Or literal base? class LiteralExpr : public ExprWithoutBlock { - /*public: - enum LitType { - CHAR, - STRING, - RAW_STRING, - BYTE, - BYTE_STRING, - RAW_BYTE_STRING, - INT, - FLOAT, - BOOL - }; - - private: - // TODO: maybe make subclasses of each type of literal with their typed - values (or - // generics) - ::std::string value_as_string; - LitType type;*/ - // moved to Literal - public: Literal literal; - Location locus; - ::std::string as_string () const { return literal.as_string (); } + std::string as_string () const override { return literal.as_string (); } - inline Literal::LitType get_lit_type () const - { - return literal.get_lit_type (); - } + Literal::LitType get_lit_type () const { return literal.get_lit_type (); } - LiteralExpr (::std::string value_as_string, Literal::LitType type, + LiteralExpr (std::string value_as_string, Literal::LitType type, Location locus, - ::std::vector<Attribute> outer_attrs - = ::std::vector<Attribute> ()) - : ExprWithoutBlock (::std::move (outer_attrs)), - literal (::std::move (value_as_string), type), locus (locus) + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : ExprWithoutBlock (std::move (outer_attrs)), + literal (std::move (value_as_string), type), locus (locus) {} LiteralExpr (Literal literal, Location locus, - ::std::vector<Attribute> outer_attrs - = ::std::vector<Attribute> ()) - : ExprWithoutBlock (::std::move (outer_attrs)), - literal (::std::move (literal)), locus (locus) + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : ExprWithoutBlock (std::move (outer_attrs)), literal (std::move (literal)), + locus (locus) {} // Unique pointer custom clone function - ::std::unique_ptr<LiteralExpr> clone_literal_expr () const + std::unique_ptr<LiteralExpr> clone_literal_expr () const { - return ::std::unique_ptr<LiteralExpr> (clone_literal_expr_impl ()); + return std::unique_ptr<LiteralExpr> (clone_literal_expr_impl ()); } Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual LiteralExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + LiteralExpr *clone_expr_impl () const override { return new LiteralExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual LiteralExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + LiteralExpr *clone_expr_without_block_impl () const override { return new LiteralExpr (*this); } - // not virtual as currently no subclasses of LiteralExpr, but could be in - // future + /* not virtual as currently no subclasses of LiteralExpr, but could be in + * future */ /*virtual*/ LiteralExpr *clone_literal_expr_impl () const { return new LiteralExpr (*this); @@ -142,8 +98,7 @@ protected: class AttrInputLiteral : public AttrInput { // Literal expression WITHOUT SUFFIX - // LiteralExpr* literal_expr; - //::std::unique_ptr<LiteralExpr> literal_expr; + // std::unique_ptr<LiteralExpr> literal_expr; LiteralExpr literal_expr; // as not using polymorphic behaviour, doesn't require pointer // TODO: will require pointer if LiteralExpr is changed to have subclassing @@ -151,57 +106,51 @@ class AttrInputLiteral : public AttrInput // TODO: should this store location data? public: - AttrInputLiteral (LiteralExpr lit_expr) - : literal_expr (::std::move (lit_expr)) + AttrInputLiteral (LiteralExpr lit_expr) : literal_expr (std::move (lit_expr)) {} - /*~AttrInputLiteral() { - delete literal_expr; - }*/ - ::std::string as_string () const { return " = " + literal_expr.as_string (); } + std::string as_string () const override + { + return " = " + literal_expr.as_string (); + } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - // this can never be a cfg predicate - cfg and cfg_attr require a token-tree - // cfg - virtual bool - check_cfg_predicate (const Session &session ATTRIBUTE_UNUSED) const OVERRIDE + /* this can never be a cfg predicate - cfg and cfg_attr require a token-tree + * cfg */ + bool + check_cfg_predicate (const Session &session ATTRIBUTE_UNUSED) const override { - // TODO: ensure this is true - // DEBUG - fprintf (stderr, "check_cfg_predicate call went to AttrInputLiteral - " - "should not happen?\n"); - return false; } protected: - // Use covariance to implement clone function as returning an AttrInputLiteral - // object - virtual AttrInputLiteral *clone_attr_input_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + AttrInputLiteral *clone_attr_input_impl () const override { return new AttrInputLiteral (*this); } }; -// literal expr only meta item inner - TODO possibly replace with inheritance of -// LiteralExpr itself? +/* literal expr only meta item inner - TODO possibly replace with inheritance of + * LiteralExpr itself? */ class MetaItemLitExpr : public MetaItemInner { LiteralExpr lit_expr; public: - MetaItemLitExpr (LiteralExpr lit_expr) : lit_expr (::std::move (lit_expr)) {} + MetaItemLitExpr (LiteralExpr lit_expr) : lit_expr (std::move (lit_expr)) {} - ::std::string as_string () const OVERRIDE { return lit_expr.as_string (); } + std::string as_string () const override { return lit_expr.as_string (); } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; + bool check_cfg_predicate (const Session &session) const override; protected: // Use covariance to implement clone function as returning this type - virtual MetaItemLitExpr *clone_meta_item_inner_impl () const OVERRIDE + MetaItemLitExpr *clone_meta_item_inner_impl () const override { return new MetaItemLitExpr (*this); } @@ -215,84 +164,30 @@ class MetaItemPathLit : public MetaItem public: MetaItemPathLit (SimplePath path, LiteralExpr lit_expr) - : path (::std::move (path)), lit (::std::move (lit_expr)) + : path (std::move (path)), lit (std::move (lit_expr)) {} - ::std::string as_string () const OVERRIDE + std::string as_string () const override { return path.as_string () + " = " + lit.as_string (); } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; - // TODO: return true if "ident" is defined and value of it is "lit", return - // false otherwise + bool check_cfg_predicate (const Session &session) const override; + /* TODO: return true if "ident" is defined and value of it is "lit", return + * false otherwise */ protected: // Use covariance to implement clone function as returning this type - virtual MetaItemPathLit *clone_meta_item_inner_impl () const OVERRIDE + MetaItemPathLit *clone_meta_item_inner_impl () const override { return new MetaItemPathLit (*this); } }; -// AST node for a non-qualified path expression - FIXME: should this be -// inheritance instead? -/*class PathExprNonQual : public PathExpr { - PathInExpression path; - - public: - ::std::string as_string() const { - return path.as_string(); - } - - PathExprNonQual(PathInExpression path, ::std::vector<Attribute> -outer_attribs) : PathExpr(::std::move(outer_attribs)), path(::std::move(path)) -{} - - protected: - // Use covariance to implement clone function as returning this object -rather than base virtual PathExprNonQual* clone_expr_impl() const OVERRIDE { - return new PathExprNonQual(*this); - } - - // Use covariance to implement clone function as returning this object -rather than base virtual PathExprNonQual* clone_expr_without_block_impl() const -OVERRIDE { return new PathExprNonQual(*this); - } -};*/ -// converted to inheritance - -// AST node for a qualified path expression - FIXME: should this be inheritance -// instead? -/*class PathExprQual : public PathExpr { - QualifiedPathInExpression path; - - public: - ::std::string as_string() const { - return path.as_string(); - } - - PathExprQual(QualifiedPathInExpression path, ::std::vector<Attribute> -outer_attribs) : PathExpr(::std::move(outer_attribs)), path(::std::move(path)) -{} - - protected: - // Use covariance to implement clone function as returning this object -rather than base virtual PathExprQual* clone_expr_impl() const OVERRIDE { return -new PathExprQual(*this); - } - - // Use covariance to implement clone function as returning this object -rather than base virtual PathExprQual* clone_expr_without_block_impl() const -OVERRIDE { return new PathExprQual(*this); - } -};*/ -// replaced with inheritance - -// Represents an expression using unary or binary operators as AST node. Can be -// overloaded. +/* Represents an expression using unary or binary operators as AST node. Can be + * overloaded. */ class OperatorExpr : public ExprWithoutBlock { // TODO: create binary and unary operator subclasses? @@ -300,37 +195,22 @@ public: Location locus; protected: - // Variable must be protected to allow derived classes to use it as a first - // class citizen Expr* main_or_left_expr; - ::std::unique_ptr<Expr> main_or_left_expr; + /* Variable must be protected to allow derived classes to use it as a first + * class citizen */ + 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), - main_or_left_expr (::std::move (main_or_left_expr)) + OperatorExpr (std::unique_ptr<Expr> main_or_left_expr, + std::vector<Attribute> outer_attribs, Location locus) + : ExprWithoutBlock (std::move (outer_attribs)), locus (locus), + 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) /*, main_or_left_expr(other.main_or_left_expr->clone_expr())*/ - { - // DEBUG: moved main_or_left_expr into body - move back later - - if (other.main_or_left_expr == NULL) - { - fprintf (stderr, "other operator expr's main_or_left_expr is null!\n"); - } - - fprintf (stderr, "called operator expr copy constructor - about to clone " - "main_or_left_expr\n"); - main_or_left_expr = other.main_or_left_expr->clone_expr (); - fprintf (stderr, "successfully cloned main_or_left_expr\n"); - // this occurred successfully, so something else must be the issue - } + : ExprWithoutBlock (other), locus (other.locus), + main_or_left_expr (other.main_or_left_expr->clone_expr ()) + {} // Overload assignment operator to deep copy expr OperatorExpr &operator= (OperatorExpr const &other) @@ -348,58 +228,42 @@ protected: OperatorExpr &operator= (OperatorExpr &&other) = default; public: - /*virtual ~OperatorExpr() { - delete main_or_left_expr; - }*/ - Location get_locus () const { return locus; } - - Location get_locus_slow () const OVERRIDE { return get_locus (); } + Location get_locus_slow () const override { return get_locus (); } }; -// Unary prefix & or &mut (or && and &&mut) borrow operator. Cannot be -// overloaded. +/* Unary prefix & or &mut (or && and &&mut) borrow operator. Cannot be + * overloaded. */ class BorrowExpr : public OperatorExpr { bool is_mut; bool double_borrow; public: - ::std::string as_string () const; + std::string as_string () const override; - BorrowExpr (::std::unique_ptr<Expr> borrow_lvalue, bool is_mut_borrow, - bool is_double_borrow, ::std::vector<Attribute> outer_attribs, + BorrowExpr (std::unique_ptr<Expr> borrow_lvalue, bool is_mut_borrow, + bool is_double_borrow, std::vector<Attribute> outer_attribs, Location locus) - : OperatorExpr (::std::move (borrow_lvalue), ::std::move (outer_attribs), + : OperatorExpr (std::move (borrow_lvalue), std::move (outer_attribs), locus), is_mut (is_mut_borrow), double_borrow (is_double_borrow) {} - // Copy constructor - define here if required - - // Destructor - define here if required - - // Overload assignment operator here if required - - // Move semantics here if required - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual BorrowExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + BorrowExpr *clone_expr_impl () const override { return new BorrowExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual BorrowExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + BorrowExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf (stderr, "called clone_expr_without_block_impl() on borrowexpr\n"); - return new BorrowExpr (*this); } }; @@ -408,41 +272,28 @@ protected: class DereferenceExpr : public OperatorExpr { public: - ::std::string as_string () const; + std::string as_string () const override; // Constructor calls OperatorExpr's protected constructor - DereferenceExpr (::std::unique_ptr<Expr> deref_lvalue, - ::std::vector<Attribute> outer_attribs, Location locus) - : OperatorExpr (::std::move (deref_lvalue), ::std::move (outer_attribs), - locus) + DereferenceExpr (std::unique_ptr<Expr> deref_lvalue, + std::vector<Attribute> outer_attribs, Location locus) + : OperatorExpr (std::move (deref_lvalue), std::move (outer_attribs), locus) {} - // Copy constructor - define here if required - - // Destructor - define here if required - - // Overload assignment operator here if required - - // Move semantics here if required - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual DereferenceExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + DereferenceExpr *clone_expr_impl () const override { return new DereferenceExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual DereferenceExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + DereferenceExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf (stderr, - "called clone_expr_without_block_impl() on dereferenceexpr\n"); - return new DereferenceExpr (*this); } }; @@ -451,42 +302,29 @@ protected: class ErrorPropagationExpr : public OperatorExpr { public: - ::std::string as_string () const; + std::string as_string () const override; // Constructor calls OperatorExpr's protected constructor - ErrorPropagationExpr (::std::unique_ptr<Expr> potential_error_value, - ::std::vector<Attribute> outer_attribs, Location locus) - : OperatorExpr (::std::move (potential_error_value), - ::std::move (outer_attribs), locus) + ErrorPropagationExpr (std::unique_ptr<Expr> potential_error_value, + std::vector<Attribute> outer_attribs, Location locus) + : OperatorExpr (std::move (potential_error_value), + std::move (outer_attribs), locus) {} - // Copy constructor - define here if required - - // Destructor - define here if required - - // Overload assignment operator here if required - - // Move semantics here if required - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ErrorPropagationExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ErrorPropagationExpr *clone_expr_impl () const override { return new ErrorPropagationExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ErrorPropagationExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ErrorPropagationExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf ( - stderr, - "called clone_expr_without_block_impl() on errorpropagationexpr\n"); - return new ErrorPropagationExpr (*this); } }; @@ -501,53 +339,40 @@ public: NOT }; - // Note: overload negation via std::ops::Neg and not via std::ops::Not - // Negation only works for signed integer and floating-point types, NOT only - // works for boolean and integer types (via bitwise NOT) + /* Note: overload negation via std::ops::Neg and not via std::ops::Not + * Negation only works for signed integer and floating-point types, NOT only + * works for boolean and integer types (via bitwise NOT) */ NegationType negation_type; public: - ::std::string as_string () const; + std::string as_string () const override; - inline NegationType get_negation_type () const { return negation_type; } + NegationType get_negation_type () const { return negation_type; } // Constructor calls OperatorExpr's protected constructor - NegationExpr (::std::unique_ptr<Expr> negated_value, - NegationType negation_kind, - ::std::vector<Attribute> outer_attribs, Location locus) - : OperatorExpr (::std::move (negated_value), ::std::move (outer_attribs), + NegationExpr (std::unique_ptr<Expr> negated_value, NegationType negation_kind, + std::vector<Attribute> outer_attribs, Location locus) + : OperatorExpr (std::move (negated_value), std::move (outer_attribs), locus), negation_type (negation_kind) {} - // Copy constructor - define here if required - - // Destructor - define here if required - - // Overload assignment operator here if required - - // Move semantics here if required - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; Expr *get_expr () { return main_or_left_expr.get (); } protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual NegationExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + NegationExpr *clone_expr_impl () const override { return new NegationExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual NegationExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + NegationExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf (stderr, - "called clone_expr_without_block_impl() on negationexpr\n"); - return new NegationExpr (*this); } }; @@ -573,25 +398,19 @@ public: // Note: overloading trait specified in comments ExprType expr_type; - // Expr* right_expr; - ::std::unique_ptr<Expr> right_expr; + std::unique_ptr<Expr> right_expr; public: - /*~ArithmeticOrLogicalExpr() { - delete right_expr; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - inline ExprType get_expr_type () const { return expr_type; } + ExprType get_expr_type () const { return expr_type; } // Constructor calls OperatorExpr's protected constructor - ArithmeticOrLogicalExpr (::std::unique_ptr<Expr> left_value, - ::std::unique_ptr<Expr> right_value, + ArithmeticOrLogicalExpr (std::unique_ptr<Expr> left_value, + std::unique_ptr<Expr> right_value, ExprType expr_kind, Location locus) - : OperatorExpr (::std::move (left_value), ::std::vector<Attribute> (), - locus), - expr_type (expr_kind), right_expr (::std::move (right_value)) + : OperatorExpr (std::move (left_value), std::vector<Attribute> (), locus), + expr_type (expr_kind), right_expr (std::move (right_value)) {} // outer attributes not allowed @@ -601,8 +420,6 @@ public: right_expr (other.right_expr->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator ArithmeticOrLogicalExpr &operator= (ArithmeticOrLogicalExpr const &other) { @@ -619,32 +436,25 @@ public: ArithmeticOrLogicalExpr &operator= (ArithmeticOrLogicalExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; Expr *get_lhs () { return main_or_left_expr.get (); } void visit_lhs (ASTVisitor &vis) { main_or_left_expr->accept_vis (vis); } - void visit_rhs (ASTVisitor &vis) { right_expr->accept_vis (vis); } protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ArithmeticOrLogicalExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ArithmeticOrLogicalExpr *clone_expr_impl () const override { return new ArithmeticOrLogicalExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ArithmeticOrLogicalExpr * - clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ArithmeticOrLogicalExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf ( - stderr, - "called clone_expr_without_block_impl() on arithmeticorlogicalexpr\n"); - return new ArithmeticOrLogicalExpr (*this); } }; @@ -666,25 +476,19 @@ public: // Note: overloading trait specified in comments ExprType expr_type; - // Expr* right_expr; - ::std::unique_ptr<Expr> right_expr; + std::unique_ptr<Expr> right_expr; public: - /*~ComparisonExpr() { - delete right_expr; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - inline ExprType get_expr_type () const { return expr_type; } + ExprType get_expr_type () const { return expr_type; } // Constructor requires pointers for polymorphism - ComparisonExpr (::std::unique_ptr<Expr> left_value, - ::std::unique_ptr<Expr> right_value, ExprType comparison_kind, + ComparisonExpr (std::unique_ptr<Expr> left_value, + std::unique_ptr<Expr> right_value, ExprType comparison_kind, Location locus) - : OperatorExpr (::std::move (left_value), ::std::vector<Attribute> (), - locus), - expr_type (comparison_kind), right_expr (::std::move (right_value)) + : OperatorExpr (std::move (left_value), std::vector<Attribute> (), locus), + expr_type (comparison_kind), right_expr (std::move (right_value)) {} // outer attributes not allowed @@ -694,8 +498,6 @@ public: right_expr (other.right_expr->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to deep copy ComparisonExpr &operator= (ComparisonExpr const &other) { @@ -712,28 +514,24 @@ public: ComparisonExpr (ComparisonExpr &&other) = default; ComparisonExpr &operator= (ComparisonExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; Expr *get_lhs () { return main_or_left_expr.get (); } - // TODO: implement via a function call to std::cmp::PartialEq::eq(&op1, &op2) - // maybe? + /* TODO: implement via a function call to std::cmp::PartialEq::eq(&op1, &op2) + * maybe? */ protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ComparisonExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ComparisonExpr *clone_expr_impl () const override { return new ComparisonExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ComparisonExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ComparisonExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf (stderr, - "called clone_expr_without_block_impl() on comparisonexpr\n"); - return new ComparisonExpr (*this); } }; @@ -750,21 +548,16 @@ public: ExprType expr_type; - // Expr* right_expr; - ::std::unique_ptr<Expr> right_expr; + std::unique_ptr<Expr> right_expr; public: - /*~LazyBooleanExpr() { - delete right_expr; - }*/ - // Constructor calls OperatorExpr's protected constructor - LazyBooleanExpr (::std::unique_ptr<Expr> left_bool_expr, - ::std::unique_ptr<Expr> right_bool_expr, ExprType expr_kind, + LazyBooleanExpr (std::unique_ptr<Expr> left_bool_expr, + std::unique_ptr<Expr> right_bool_expr, ExprType expr_kind, Location locus) - : OperatorExpr (::std::move (left_bool_expr), ::std::vector<Attribute> (), + : OperatorExpr (std::move (left_bool_expr), std::vector<Attribute> (), locus), - expr_type (expr_kind), right_expr (::std::move (right_bool_expr)) + expr_type (expr_kind), right_expr (std::move (right_bool_expr)) {} // outer attributes not allowed @@ -774,8 +567,6 @@ public: right_expr (other.right_expr->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to deep copy LazyBooleanExpr &operator= (LazyBooleanExpr const &other) { @@ -791,30 +582,26 @@ public: LazyBooleanExpr (LazyBooleanExpr &&other) = default; LazyBooleanExpr &operator= (LazyBooleanExpr &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - inline ExprType get_expr_type () const { return expr_type; } + ExprType get_expr_type () const { return expr_type; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; Expr *get_lhs () { return main_or_left_expr.get (); } protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual LazyBooleanExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + LazyBooleanExpr *clone_expr_impl () const override { return new LazyBooleanExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual LazyBooleanExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + LazyBooleanExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf (stderr, - "called clone_expr_without_block_impl() on lazybooleanexpr\n"); - return new LazyBooleanExpr (*this); } }; @@ -822,19 +609,17 @@ protected: // Binary infix "as" cast expression. class TypeCastExpr : public OperatorExpr { - // TypeNoBounds type_to_convert_to; - ::std::unique_ptr<TypeNoBounds> type_to_convert_to; + std::unique_ptr<TypeNoBounds> type_to_convert_to; // Note: only certain type casts allowed, outlined in reference public: - ::std::string as_string () const; + std::string as_string () const override; // Constructor requires calling protected constructor of OperatorExpr - TypeCastExpr (::std::unique_ptr<Expr> expr_to_cast, - ::std::unique_ptr<TypeNoBounds> type_to_cast_to, Location locus) - : OperatorExpr (::std::move (expr_to_cast), ::std::vector<Attribute> (), - locus), - type_to_convert_to (::std::move (type_to_cast_to)) + TypeCastExpr (std::unique_ptr<Expr> expr_to_cast, + std::unique_ptr<TypeNoBounds> type_to_cast_to, Location locus) + : OperatorExpr (std::move (expr_to_cast), std::vector<Attribute> (), locus), + type_to_convert_to (std::move (type_to_cast_to)) {} // outer attributes not allowed @@ -844,8 +629,6 @@ public: type_to_convert_to (other.type_to_convert_to->clone_type_no_bounds ()) {} - // Destructor - define here if required - // Overload assignment operator to deep copy TypeCastExpr &operator= (TypeCastExpr const &other) { @@ -860,24 +643,20 @@ public: TypeCastExpr (TypeCastExpr &&other) = default; TypeCastExpr &operator= (TypeCastExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TypeCastExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TypeCastExpr *clone_expr_impl () const override { return new TypeCastExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual TypeCastExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TypeCastExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf (stderr, - "called clone_expr_without_block_impl() on typecastexpr\n"); - return new TypeCastExpr (*this); } }; @@ -886,48 +665,23 @@ protected: class AssignmentExpr : public OperatorExpr { public: - // Expr* right_expr; - ::std::unique_ptr<Expr> right_expr; + std::unique_ptr<Expr> right_expr; - /*~AssignmentExpr() { - delete right_expr; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // Call OperatorExpr constructor to initialise left_expr - AssignmentExpr (::std::unique_ptr<Expr> value_to_assign_to, - ::std::unique_ptr<Expr> value_to_assign, Location locus) - : OperatorExpr (::std::move (value_to_assign_to), - ::std::vector<Attribute> (), locus), - right_expr (::std::move (value_to_assign)) + AssignmentExpr (std::unique_ptr<Expr> value_to_assign_to, + std::unique_ptr<Expr> value_to_assign, Location locus) + : OperatorExpr (std::move (value_to_assign_to), std::vector<Attribute> (), + locus), + right_expr (std::move (value_to_assign)) {} // outer attributes not allowed // Call OperatorExpr constructor in copy constructor, as well as clone AssignmentExpr (AssignmentExpr const &other) - : OperatorExpr (other) /*, right_expr(other.right_expr->clone_expr())*/ - { - // DEBUG: moved cloning right expr into body - fprintf (stderr, "assignment expr copy constructor successfully cloned " - "base operator expr\n"); - if (other.right_expr == NULL) - { - fprintf (stderr, "other expr's right expr (in assignment) is null!!!"); - } - fprintf (stderr, "test other's right expr as string: %s\n", - other.right_expr->as_string ().c_str ()); - // apparently, despite not being null, cloning still fails - right_expr = other.right_expr->clone_expr (); - fprintf ( - stderr, - "assignment expr copy constructor successfully cloned right expr\n"); - - // DEBUG - fprintf (stderr, "assignment expr copy constructor called successfully\n"); - } - - // Destructor - define here if required + : OperatorExpr (other), right_expr (other.right_expr->clone_expr ()) + {} // Overload assignment operator to clone unique_ptr right_expr AssignmentExpr &operator= (AssignmentExpr const &other) @@ -944,36 +698,31 @@ public: AssignmentExpr (AssignmentExpr &&other) = default; AssignmentExpr &operator= (AssignmentExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; void visit_lhs (ASTVisitor &vis) { main_or_left_expr->accept_vis (vis); } - void visit_rhs (ASTVisitor &vis) { right_expr->accept_vis (vis); } Expr *get_lhs () { return main_or_left_expr.get (); } protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual AssignmentExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + AssignmentExpr *clone_expr_impl () const override { return new AssignmentExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual AssignmentExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + AssignmentExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf (stderr, - "called clone_expr_without_block_impl() on assignmentexpr\n"); - return new AssignmentExpr (*this); } }; -// Binary infix compound assignment (arithmetic or logic then assignment) -// expressions. +/* Binary infix compound assignment (arithmetic or logic then assignment) + * expressions. */ class CompoundAssignmentExpr : public OperatorExpr { public: @@ -994,26 +743,20 @@ public: private: // Note: overloading trait specified in comments ExprType expr_type; - - // Expr* right_expr; - ::std::unique_ptr<Expr> right_expr; + std::unique_ptr<Expr> right_expr; public: - /*~CompoundAssignmentExpr() { - delete right_expr; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - inline ExprType get_expr_type () const { return expr_type; } + ExprType get_expr_type () const { return expr_type; } // Use pointers in constructor to enable polymorphism - CompoundAssignmentExpr (::std::unique_ptr<Expr> value_to_assign_to, - ::std::unique_ptr<Expr> value_to_assign, + CompoundAssignmentExpr (std::unique_ptr<Expr> value_to_assign_to, + std::unique_ptr<Expr> value_to_assign, ExprType expr_kind, Location locus) - : OperatorExpr (::std::move (value_to_assign_to), - ::std::vector<Attribute> (), locus), - expr_type (expr_kind), right_expr (::std::move (value_to_assign)) + : OperatorExpr (std::move (value_to_assign_to), std::vector<Attribute> (), + locus), + expr_type (expr_kind), right_expr (std::move (value_to_assign)) {} // outer attributes not allowed @@ -1023,8 +766,6 @@ public: right_expr (other.right_expr->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to clone CompoundAssignmentExpr &operator= (CompoundAssignmentExpr const &other) { @@ -1041,26 +782,20 @@ public: CompoundAssignmentExpr (CompoundAssignmentExpr &&other) = default; CompoundAssignmentExpr &operator= (CompoundAssignmentExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual CompoundAssignmentExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + CompoundAssignmentExpr *clone_expr_impl () const override { return new CompoundAssignmentExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual CompoundAssignmentExpr * - clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + CompoundAssignmentExpr *clone_expr_without_block_impl () const override { - // DEBUG - fprintf ( - stderr, - "called clone_expr_without_block_impl() on compoundassignmentexpr\n"); - return new CompoundAssignmentExpr (*this); } }; @@ -1068,30 +803,22 @@ protected: // Expression in parentheses (i.e. like literally just any 3 + (2 * 6)) class GroupedExpr : public ExprWithoutBlock { - ::std::vector<Attribute> inner_attrs; - // Expr* expr_in_parens; - ::std::unique_ptr<Expr> expr_in_parens; + std::vector<Attribute> inner_attrs; + std::unique_ptr<Expr> expr_in_parens; Location locus; public: - /*~GroupedExpr() { - delete expr_in_parens; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - inline ::std::vector<Attribute> get_inner_attrs () const - { - return inner_attrs; - } + std::vector<Attribute> get_inner_attrs () const { return inner_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)), - inner_attrs (::std::move (inner_attribs)), - expr_in_parens (::std::move (parenthesised_expr)), locus (locus) + GroupedExpr (std::unique_ptr<Expr> parenthesised_expr, + std::vector<Attribute> inner_attribs, + std::vector<Attribute> outer_attribs, Location locus) + : ExprWithoutBlock (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 @@ -1100,8 +827,6 @@ public: expr_in_parens (other.expr_in_parens->clone_expr ()), locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone expr_in_parens GroupedExpr &operator= (GroupedExpr const &other) { @@ -1119,22 +844,21 @@ public: GroupedExpr &operator= (GroupedExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual GroupedExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + GroupedExpr *clone_expr_impl () const override { return new GroupedExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual GroupedExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + GroupedExpr *clone_expr_without_block_impl () const override { return new GroupedExpr (*this); } @@ -1148,12 +872,12 @@ public: virtual ~ArrayElems () {} // Unique pointer custom clone ArrayElems function - ::std::unique_ptr<ArrayElems> clone_array_elems () const + std::unique_ptr<ArrayElems> clone_array_elems () const { - return ::std::unique_ptr<ArrayElems> (clone_array_elems_impl ()); + return std::unique_ptr<ArrayElems> (clone_array_elems_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -1165,44 +889,29 @@ protected: // Value array elements class ArrayElemsValues : public ArrayElems { - //::std::vector<Expr> values; - ::std::vector< ::std::unique_ptr<Expr> > values; + std::vector<std::unique_ptr<Expr>> values; // TODO: should this store location data? public: - /*inline ::std::vector< ::std::unique_ptr<Expr> > get_values() const { - return values; - }*/ - - ArrayElemsValues (::std::vector< ::std::unique_ptr<Expr> > elems) - : values (::std::move (elems)) + ArrayElemsValues (std::vector<std::unique_ptr<Expr>> elems) + : values (std::move (elems)) {} // copy constructor with vector clone ArrayElemsValues (ArrayElemsValues const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? values.reserve (other.values.size ()); - for (const auto &e : other.values) - { - values.push_back (e->clone_expr ()); - } + values.push_back (e->clone_expr ()); } // overloaded assignment operator with vector clone ArrayElemsValues &operator= (ArrayElemsValues const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? values.reserve (other.values.size ()); - for (const auto &e : other.values) - { - values.push_back (e->clone_expr ()); - } + values.push_back (e->clone_expr ()); return *this; } @@ -1211,12 +920,12 @@ public: ArrayElemsValues (ArrayElemsValues &&other) = default; ArrayElemsValues &operator= (ArrayElemsValues &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - virtual ArrayElemsValues *clone_array_elems_impl () const OVERRIDE + ArrayElemsValues *clone_array_elems_impl () const override { return new ArrayElemsValues (*this); } @@ -1225,24 +934,17 @@ protected: // Copied array element and number of copies class ArrayElemsCopied : public ArrayElems { - // Expr* elem_to_copy; - ::std::unique_ptr<Expr> elem_to_copy; - // Expr* num_copies; - ::std::unique_ptr<Expr> num_copies; + std::unique_ptr<Expr> elem_to_copy; + std::unique_ptr<Expr> num_copies; // TODO: should this store location data? public: - /*~ArrayElemsCopied() { - delete num_copies; - delete elem_to_copy; - }*/ - // Constructor requires pointers for polymorphism - ArrayElemsCopied (::std::unique_ptr<Expr> copied_elem, - ::std::unique_ptr<Expr> copy_amount) - : elem_to_copy (::std::move (copied_elem)), - num_copies (::std::move (copy_amount)) + ArrayElemsCopied (std::unique_ptr<Expr> copied_elem, + std::unique_ptr<Expr> copy_amount) + : elem_to_copy (std::move (copied_elem)), + num_copies (std::move (copy_amount)) {} // Copy constructor required due to unique_ptr - uses custom clone @@ -1251,8 +953,6 @@ public: num_copies (other.num_copies->clone_expr ()) {} - // Destructor - define here if required - // Overloaded assignment operator for deep copying ArrayElemsCopied &operator= (ArrayElemsCopied const &other) { @@ -1266,12 +966,12 @@ public: ArrayElemsCopied (ArrayElemsCopied &&other) = default; ArrayElemsCopied &operator= (ArrayElemsCopied &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - virtual ArrayElemsCopied *clone_array_elems_impl () const OVERRIDE + ArrayElemsCopied *clone_array_elems_impl () const override { return new ArrayElemsCopied (*this); } @@ -1280,30 +980,26 @@ protected: // Array definition-ish expression class ArrayExpr : public ExprWithoutBlock { - ::std::vector<Attribute> inner_attrs; - // ArrayElems internal_elements; - ::std::unique_ptr<ArrayElems> internal_elements; + std::vector<Attribute> inner_attrs; + std::unique_ptr<ArrayElems> internal_elements; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; - inline ::std::vector<Attribute> get_inner_attrs () const - { - return inner_attrs; - } + std::vector<Attribute> get_inner_attrs () const { return inner_attrs; } // Returns whether array expr has array elems or if it is just empty. - inline bool has_array_elems () const { return internal_elements != NULL; } + bool has_array_elems () const { return internal_elements != nullptr; } // Constructor requires ArrayElems pointer - ArrayExpr (::std::unique_ptr<ArrayElems> array_elems, - ::std::vector<Attribute> inner_attribs, - ::std::vector<Attribute> outer_attribs, Location locus) - : ExprWithoutBlock (::std::move (outer_attribs)), - inner_attrs (::std::move (inner_attribs)), - internal_elements (::std::move (array_elems)), locus (locus) + ArrayExpr (std::unique_ptr<ArrayElems> array_elems, + std::vector<Attribute> inner_attribs, + std::vector<Attribute> outer_attribs, Location locus) + : ExprWithoutBlock (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 @@ -1312,22 +1008,16 @@ public: locus (other.locus) { if (other.has_array_elems ()) - { - internal_elements = other.internal_elements->clone_array_elems (); - } + internal_elements = other.internal_elements->clone_array_elems (); } - // Destructor - define here if required - // Overload assignment operator to clone internal_elements ArrayExpr &operator= (ArrayExpr const &other) { ExprWithoutBlock::operator= (other); inner_attrs = other.inner_attrs; if (other.has_array_elems ()) - { - internal_elements = other.internal_elements->clone_array_elems (); - } + internal_elements = other.internal_elements->clone_array_elems (); locus = other.locus; // outer_attrs = other.outer_attrs; @@ -1339,55 +1029,44 @@ public: ArrayExpr &operator= (ArrayExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ArrayExpr *clone_expr_impl () const OVERRIDE - { - return new ArrayExpr (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + ArrayExpr *clone_expr_impl () const override { return new ArrayExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ArrayExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ArrayExpr *clone_expr_without_block_impl () const override { return new ArrayExpr (*this); } }; // Aka IndexExpr (also applies to slices) -// Apparently a[b] is equivalent to *std::ops::Index::index(&a, b) or -// *std::ops::Index::index_mut(&mut a, b) -// Also apparently deref operations on a will be repeatedly applied to find an -// implementation +/* Apparently a[b] is equivalent to *std::ops::Index::index(&a, b) or + * *std::ops::Index::index_mut(&mut a, b) */ +/* Also apparently deref operations on a will be repeatedly applied to find an + * implementation */ class ArrayIndexExpr : public ExprWithoutBlock { - /*Expr* array_expr; - Expr* index_expr;*/ - ::std::unique_ptr<Expr> array_expr; - ::std::unique_ptr<Expr> index_expr; + std::unique_ptr<Expr> array_expr; + std::unique_ptr<Expr> index_expr; Location locus; public: - /*~ArrayIndexExpr() { - delete index_expr; - delete array_expr; - }*/ - - ::std::string as_string () const; - - 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)), - array_expr (::std::move (array_expr)), - index_expr (::std::move (array_index_expr)), locus (locus) + std::string as_string () const override; + + 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)), + array_expr (std::move (array_expr)), + index_expr (std::move (array_index_expr)), locus (locus) {} // Copy constructor requires special cloning due to unique_ptr @@ -1396,8 +1075,6 @@ public: index_expr (other.index_expr->clone_expr ()), locus (other.locus) {} - // Destructor - define here if required - // Overload assignment operator to clone unique_ptrs ArrayIndexExpr &operator= (ArrayIndexExpr const &other) { @@ -1415,22 +1092,21 @@ public: ArrayIndexExpr &operator= (ArrayIndexExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ArrayIndexExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ArrayIndexExpr *clone_expr_impl () const override { return new ArrayIndexExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ArrayIndexExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ArrayIndexExpr *clone_expr_without_block_impl () const override { return new ArrayIndexExpr (*this); } @@ -1439,28 +1115,24 @@ protected: // AST representation of a tuple class TupleExpr : public ExprWithoutBlock { - ::std::vector<Attribute> inner_attrs; + std::vector<Attribute> inner_attrs; - //::std::vector<Expr> tuple_elems; - ::std::vector< ::std::unique_ptr<Expr> > tuple_elems; + std::vector<std::unique_ptr<Expr>> tuple_elems; // replaces (inlined version of) TupleElements Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; - inline ::std::vector<Attribute> get_inner_attrs () const - { - return inner_attrs; - } + std::vector<Attribute> get_inner_attrs () const { return inner_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)), - inner_attrs (::std::move (inner_attribs)), - tuple_elems (::std::move (tuple_elements)), locus (locus) + 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)), + inner_attrs (std::move (inner_attribs)), + tuple_elems (std::move (tuple_elements)), locus (locus) {} // copy constructor with vector clone @@ -1468,14 +1140,9 @@ public: : ExprWithoutBlock (other), inner_attrs (other.inner_attrs), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? tuple_elems.reserve (other.tuple_elems.size ()); - for (const auto &e : other.tuple_elems) - { - tuple_elems.push_back (e->clone_expr ()); - } + tuple_elems.push_back (e->clone_expr ()); } // overloaded assignment operator to vector clone @@ -1485,14 +1152,9 @@ public: inner_attrs = other.inner_attrs; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? tuple_elems.reserve (other.tuple_elems.size ()); - for (const auto &e : other.tuple_elems) - { - tuple_elems.push_back (e->clone_expr ()); - } + tuple_elems.push_back (e->clone_expr ()); return *this; } @@ -1501,26 +1163,22 @@ public: TupleExpr (TupleExpr &&other) = default; TupleExpr &operator= (TupleExpr &&other) = default; - // Note: syntactically, can disambiguate single-element tuple from parens with - // comma, i.e. (0,) rather than (0) + /* Note: syntactically, can disambiguate single-element tuple from parens with + * comma, i.e. (0,) rather than (0) */ Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleExpr *clone_expr_impl () const OVERRIDE - { - return new TupleExpr (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleExpr *clone_expr_impl () const override { return new TupleExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleExpr *clone_expr_without_block_impl () const override { return new TupleExpr (*this); } @@ -1530,8 +1188,7 @@ protected: // AST representation of a tuple indexing expression class TupleIndexExpr : public ExprWithoutBlock { - // Expr* tuple_expr; - ::std::unique_ptr<Expr> tuple_expr; + std::unique_ptr<Expr> tuple_expr; // TupleIndex is a decimal int literal with no underscores or suffix TupleIndex tuple_index; @@ -1540,18 +1197,14 @@ class TupleIndexExpr : public ExprWithoutBlock // i.e. pair.0 public: - /*~TupleIndexExpr() { - delete tuple_expr; - }*/ + std::string as_string () const override; - ::std::string as_string () const; + TupleIndex get_tuple_index () const { return tuple_index; } - inline TupleIndex get_tuple_index () const { return tuple_index; } - - TupleIndexExpr (::std::unique_ptr<Expr> tuple_expr, TupleIndex index, - ::std::vector<Attribute> outer_attribs, Location locus) - : ExprWithoutBlock (::std::move (outer_attribs)), - tuple_expr (::std::move (tuple_expr)), tuple_index (index), locus (locus) + TupleIndexExpr (std::unique_ptr<Expr> tuple_expr, TupleIndex index, + std::vector<Attribute> outer_attribs, Location locus) + : ExprWithoutBlock (std::move (outer_attribs)), + tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus) {} // Copy constructor requires a clone for tuple_expr @@ -1560,8 +1213,6 @@ public: tuple_index (other.tuple_index), locus (other.locus) {} - // Destructor - define here if required - // Overload assignment operator in order to clone TupleIndexExpr &operator= (TupleIndexExpr const &other) { @@ -1579,22 +1230,21 @@ public: TupleIndexExpr &operator= (TupleIndexExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleIndexExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleIndexExpr *clone_expr_impl () const override { return new TupleIndexExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleIndexExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleIndexExpr *clone_expr_without_block_impl () const override { return new TupleIndexExpr (*this); } @@ -1608,90 +1258,77 @@ class StructExpr : public ExprWithoutBlock protected: // Protected constructor to allow initialising struct_name StructExpr (PathInExpression struct_path, - ::std::vector<Attribute> outer_attribs) - : ExprWithoutBlock (::std::move (outer_attribs)), - struct_name (::std::move (struct_path)) + std::vector<Attribute> outer_attribs) + : ExprWithoutBlock (std::move (outer_attribs)), + struct_name (std::move (struct_path)) {} public: - inline const PathInExpression &get_struct_name () const - { - return struct_name; - } + const PathInExpression &get_struct_name () const { return struct_name; } - virtual ::std::string as_string () const; + std::string as_string () const override; }; // Actual AST node of the struct creator (with no fields). Not abstract! class StructExprStruct : public StructExpr { - ::std::vector<Attribute> inner_attrs; + std::vector<Attribute> inner_attrs; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; - inline ::std::vector<Attribute> get_inner_attrs () const - { - return inner_attrs; - } + std::vector<Attribute> get_inner_attrs () const { return inner_attrs; } // Constructor has to call protected constructor of base class StructExprStruct (PathInExpression struct_path, - ::std::vector<Attribute> inner_attribs, - ::std::vector<Attribute> outer_attribs, Location locus) - : StructExpr (::std::move (struct_path), ::std::move (outer_attribs)), - inner_attrs (::std::move (inner_attribs)), locus (locus) + std::vector<Attribute> inner_attribs, + std::vector<Attribute> outer_attribs, Location locus) + : StructExpr (std::move (struct_path), std::move (outer_attribs)), + inner_attrs (std::move (inner_attribs)), locus (locus) {} Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprStruct *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprStruct *clone_expr_impl () const override { return new StructExprStruct (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprStruct *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprStruct *clone_expr_without_block_impl () const override { return new StructExprStruct (*this); } }; -// AST node representing expression used to fill a struct's fields from another -// struct +/* AST node representing expression used to fill a struct's fields from another + * struct */ struct StructBase { public: - // Expr* base_struct; - ::std::unique_ptr<Expr> base_struct; + std::unique_ptr<Expr> base_struct; // TODO: should this store location data? - StructBase (::std::unique_ptr<Expr> base_struct_ptr) - : base_struct (::std::move (base_struct_ptr)) + StructBase (std::unique_ptr<Expr> base_struct_ptr) + : base_struct (std::move (base_struct_ptr)) {} // Copy constructor requires clone StructBase (StructBase const &other) { - // HACK: gets around base_struct pointer being null (e.g. if no struct base - // exists) - if (other.base_struct != NULL) - { - other.base_struct->clone_expr (); - } - - // DEBUG: - fprintf (stderr, "struct base copy constructor called successfully\n"); + /* HACK: gets around base_struct pointer being null (e.g. if no struct base + * exists) */ + if (other.base_struct != nullptr) + other.base_struct->clone_expr (); } // Destructor @@ -1709,33 +1346,29 @@ public: StructBase (StructBase &&other) = default; StructBase &operator= (StructBase &&other) = default; - /*~StructBase() { - delete base_struct; - }*/ - // Returns a null expr-ed StructBase - error state - static StructBase error () { return StructBase (NULL); } + static StructBase error () { return StructBase (nullptr); } // Returns whether StructBase is in error state - inline bool is_invalid () const { return base_struct == NULL; } + bool is_invalid () const { return base_struct == nullptr; } - ::std::string as_string () const; + std::string as_string () const; }; -// Base AST node for a single struct expression field (in struct instance -// creation) - abstract +/* Base AST node for a single struct expression field (in struct instance + * creation) - abstract */ class StructExprField { public: virtual ~StructExprField () {} // Unique pointer custom clone function - ::std::unique_ptr<StructExprField> clone_struct_expr_field () const + std::unique_ptr<StructExprField> clone_struct_expr_field () const { - return ::std::unique_ptr<StructExprField> (clone_struct_expr_field_impl ()); + return std::unique_ptr<StructExprField> (clone_struct_expr_field_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -1753,34 +1386,32 @@ public: // TODO: should this store location data? StructExprFieldIdentifier (Identifier field_identifier) - : field_name (::std::move (field_identifier)) + : field_name (std::move (field_identifier)) {} - ::std::string as_string () const { return field_name; } + std::string as_string () const override { return field_name; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this rather than - // base - virtual StructExprFieldIdentifier * - clone_struct_expr_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprFieldIdentifier *clone_struct_expr_field_impl () const override { return new StructExprFieldIdentifier (*this); } }; -// Base AST node for a single struct expression field with an assigned value - -// abstract +/* Base AST node for a single struct expression field with an assigned value - + * abstract */ class StructExprFieldWithVal : public StructExprField { public: - // Expr* value; - ::std::unique_ptr<Expr> value; + std::unique_ptr<Expr> value; protected: - StructExprFieldWithVal (::std::unique_ptr<Expr> field_value) - : value (::std::move (field_value)) + StructExprFieldWithVal (std::unique_ptr<Expr> field_value) + : value (std::move (field_value)) {} // Copy constructor requires clone @@ -1788,8 +1419,6 @@ protected: : value (other.value->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to clone unique_ptr StructExprFieldWithVal &operator= (StructExprFieldWithVal const &other) { @@ -1803,11 +1432,7 @@ protected: StructExprFieldWithVal &operator= (StructExprFieldWithVal &&other) = default; public: - /*~StructExprFieldWithVal() { - delete value; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; }; // Identifier and value variant of StructExprField AST node @@ -1819,23 +1444,19 @@ public: // TODO: should this store location data? StructExprFieldIdentifierValue (Identifier field_identifier, - ::std::unique_ptr<Expr> field_value) - : StructExprFieldWithVal (::std::move (field_value)), - field_name (::std::move (field_identifier)) + std::unique_ptr<Expr> field_value) + : StructExprFieldWithVal (std::move (field_value)), + field_name (std::move (field_identifier)) {} - // copy constructor, destructor, and overloaded assignment operator should - // carry through - - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this rather than - // base - virtual StructExprFieldIdentifierValue * - clone_struct_expr_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprFieldIdentifierValue *clone_struct_expr_field_impl () const override { return new StructExprFieldIdentifierValue (*this); } @@ -1850,22 +1471,18 @@ public: // TODO: should this store location data? StructExprFieldIndexValue (TupleIndex tuple_index, - ::std::unique_ptr<Expr> field_value) - : StructExprFieldWithVal (::std::move (field_value)), index (tuple_index) + std::unique_ptr<Expr> field_value) + : StructExprFieldWithVal (std::move (field_value)), index (tuple_index) {} - // copy constructor, destructor, and overloaded assignment operator should - // carry through + std::string as_string () const override; - ::std::string as_string () const; - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this rather than - // base - virtual StructExprFieldIndexValue * - clone_struct_expr_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprFieldIndexValue *clone_struct_expr_field_impl () const override { return new StructExprFieldIndexValue (*this); } @@ -1875,17 +1492,17 @@ protected: class StructExprStructFields : public StructExprStruct { public: - //::std::vector<StructExprField> fields; - ::std::vector< ::std::unique_ptr<StructExprField> > fields; + // std::vector<StructExprField> fields; + std::vector<std::unique_ptr<StructExprField>> fields; // bool has_struct_base; StructBase struct_base; - ::std::string as_string () const; + std::string as_string () const override; - inline bool has_struct_base () const { return !struct_base.is_invalid (); } + bool has_struct_base () const { return !struct_base.is_invalid (); } - /*inline ::std::vector< ::std::unique_ptr<StructExprField> > get_fields() + /*inline std::vector<std::unique_ptr<StructExprField>> get_fields() const { return fields; }*/ @@ -1896,44 +1513,22 @@ public: // Constructor for StructExprStructFields when no struct base is used StructExprStructFields ( PathInExpression struct_path, - ::std::vector< ::std::unique_ptr<StructExprField> > expr_fields, - Location locus, StructBase base_struct = StructBase::error (), - ::std::vector<Attribute> inner_attribs = ::std::vector<Attribute> (), - ::std::vector<Attribute> outer_attribs = ::std::vector<Attribute> ()) - : StructExprStruct (::std::move (struct_path), ::std::move (inner_attribs), - ::std::move (outer_attribs), locus), - fields (::std::move (expr_fields)), - struct_base (::std::move (base_struct)) + std::vector<std::unique_ptr<StructExprField>> expr_fields, Location locus, + StructBase base_struct = StructBase::error (), + std::vector<Attribute> inner_attribs = std::vector<Attribute> (), + std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) + : StructExprStruct (std::move (struct_path), std::move (inner_attribs), + std::move (outer_attribs), locus), + fields (std::move (expr_fields)), struct_base (std::move (base_struct)) {} // copy constructor with vector clone StructExprStructFields (StructExprStructFields const &other) : StructExprStruct (other), struct_base (other.struct_base) { - // DEBUG - fprintf (stderr, - "got past the initialisation list part of copy constructor\n"); - - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? fields.reserve (other.fields.size ()); - - // DEBUG - fprintf (stderr, "reserved space in fields\n"); - for (const auto &e : other.fields) - { - // DEBUG - fprintf (stderr, "about to clone a field\n"); - - fields.push_back (e->clone_struct_expr_field ()); - - // DEBUG - fprintf (stderr, "cloned a field successfully\n"); - } - - // DEBUG - fprintf (stderr, "finished cloning fields\n"); + fields.push_back (e->clone_struct_expr_field ()); } // overloaded assignment operator with vector clone @@ -1942,14 +1537,9 @@ public: StructExprStruct::operator= (other); struct_base = other.struct_base; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? fields.reserve (other.fields.size ()); - for (const auto &e : other.fields) - { - fields.push_back (e->clone_struct_expr_field ()); - } + fields.push_back (e->clone_struct_expr_field ()); return *this; } @@ -1958,44 +1548,20 @@ public: StructExprStructFields (StructExprStructFields &&other) = default; StructExprStructFields &operator= (StructExprStructFields &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprStructFields *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprStructFields *clone_expr_impl () const override { return new StructExprStructFields (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprStructFields * - clone_expr_without_block_impl () const OVERRIDE - { - // DEBUG - fprintf ( - stderr, - "called structexprstructfields clone expr without block impl - about " - "to return new structexprstructfields\n"); - - // DEBUG - test creation of a base from this - fprintf (stderr, "about to try to create and allocate structexprstruct \n"); - StructExprStruct *test_DELETE = new StructExprStruct (*this); - delete test_DELETE; - fprintf (stderr, "managed to create and allocate structexprstruct \n"); - // very weird: can create and allocate structexpstruct but not - // structexprstructfields - - // DEBUG - test creation of a non-returned class from this - fprintf (stderr, "about to try to create and allocate " - "structexprstructfields (but not return)\n"); - StructExprStructFields *test_DELETE2 = new StructExprStructFields (*this); - delete test_DELETE2; - fprintf (stderr, "managed to create and allocate structexprstructfields " - "(if not returned) \n"); - // ok this fails. fair enough. - + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprStructFields *clone_expr_without_block_impl () const override + { return new StructExprStructFields (*this); } }; @@ -2006,33 +1572,33 @@ class StructExprStructBase : public StructExprStruct StructBase struct_base; public: - ::std::string as_string () const; + std::string as_string () const override; /*inline StructBase get_struct_base() const { return struct_base; }*/ StructExprStructBase (PathInExpression struct_path, StructBase base_struct, - ::std::vector<Attribute> inner_attribs, - ::std::vector<Attribute> outer_attribs, Location locus) - : StructExprStruct (::std::move (struct_path), ::std::move (inner_attribs), - ::std::move (outer_attribs), locus), - struct_base (::std::move (base_struct)) + std::vector<Attribute> inner_attribs, + std::vector<Attribute> outer_attribs, Location locus) + : StructExprStruct (std::move (struct_path), std::move (inner_attribs), + std::move (outer_attribs), locus), + struct_base (std::move (base_struct)) {} - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprStructBase *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprStructBase *clone_expr_impl () const override { return new StructExprStructBase (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprStructBase *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprStructBase *clone_expr_without_block_impl () const override { return new StructExprStructBase (*this); } @@ -2041,45 +1607,36 @@ protected: // AST node of a tuple struct creator class StructExprTuple : public StructExpr { - ::std::vector<Attribute> inner_attrs; - //::std::vector<Expr> exprs; - ::std::vector< ::std::unique_ptr<Expr> > exprs; + std::vector<Attribute> inner_attrs; + std::vector<std::unique_ptr<Expr>> exprs; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; - inline const ::std::vector<Attribute> &get_inner_attrs () const - { - return inner_attrs; - } + const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; } - /*inline ::std::vector< ::std::unique_ptr<Expr> > get_exprs() const { + /*inline std::vector<std::unique_ptr<Expr>> get_exprs() const { return exprs; }*/ StructExprTuple (PathInExpression struct_path, - ::std::vector< ::std::unique_ptr<Expr> > tuple_exprs, - ::std::vector<Attribute> inner_attribs, - ::std::vector<Attribute> outer_attribs, Location locus) - : StructExpr (::std::move (struct_path), ::std::move (outer_attribs)), - inner_attrs (::std::move (inner_attribs)), - exprs (::std::move (tuple_exprs)), locus (locus) + std::vector<std::unique_ptr<Expr>> tuple_exprs, + std::vector<Attribute> inner_attribs, + std::vector<Attribute> outer_attribs, Location locus) + : StructExpr (std::move (struct_path), std::move (outer_attribs)), + inner_attrs (std::move (inner_attribs)), exprs (std::move (tuple_exprs)), + locus (locus) {} // copy constructor with vector clone StructExprTuple (StructExprTuple const &other) : StructExpr (other), inner_attrs (other.inner_attrs), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? exprs.reserve (other.exprs.size ()); - for (const auto &e : other.exprs) - { - exprs.push_back (e->clone_expr ()); - } + exprs.push_back (e->clone_expr ()); } // overloaded assignment operator with vector clone @@ -2089,14 +1646,9 @@ public: inner_attrs = other.inner_attrs; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? exprs.reserve (other.exprs.size ()); - for (const auto &e : other.exprs) - { - exprs.push_back (e->clone_expr ()); - } + exprs.push_back (e->clone_expr ()); return *this; } @@ -2106,22 +1658,21 @@ public: StructExprTuple &operator= (StructExprTuple &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprTuple *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprTuple *clone_expr_impl () const override { return new StructExprTuple (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprTuple *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprTuple *clone_expr_without_block_impl () const override { return new StructExprTuple (*this); } @@ -2133,35 +1684,34 @@ class StructExprUnit : public StructExpr Location locus; public: - ::std::string as_string () const + std::string as_string () const override { return get_struct_name ().as_string (); // return struct_name.as_string(); } StructExprUnit (PathInExpression struct_path, - ::std::vector<Attribute> outer_attribs, Location locus) - : StructExpr (::std::move (struct_path), ::std::move (outer_attribs)), + std::vector<Attribute> outer_attribs, Location locus) + : StructExpr (std::move (struct_path), std::move (outer_attribs)), locus (locus) {} Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprUnit *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprUnit *clone_expr_impl () const override { return new StructExprUnit (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructExprUnit *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructExprUnit *clone_expr_without_block_impl () const override { return new StructExprUnit (*this); } @@ -2176,30 +1726,27 @@ class EnumVariantExpr : public ExprWithoutBlock protected: // Protected constructor for initialising enum_variant_path EnumVariantExpr (PathInExpression path_to_enum_variant, - ::std::vector<Attribute> outer_attribs) - : ExprWithoutBlock (::std::move (outer_attribs)), - enum_variant_path (::std::move (path_to_enum_variant)) + std::vector<Attribute> outer_attribs) + : ExprWithoutBlock (std::move (outer_attribs)), + enum_variant_path (std::move (path_to_enum_variant)) {} public: // TODO: maybe remove and have string version gotten here directly - inline PathInExpression get_enum_variant_path () const - { - return enum_variant_path; - } + PathInExpression get_enum_variant_path () const { return enum_variant_path; } }; -// Base AST node for a single enum expression field (in enum instance creation) -// - abstract +/* Base AST node for a single enum expression field (in enum instance creation) + * - abstract */ class EnumExprField { public: virtual ~EnumExprField () {} // Unique pointer custom clone function - ::std::unique_ptr<EnumExprField> clone_enum_expr_field () const + std::unique_ptr<EnumExprField> clone_enum_expr_field () const { - return ::std::unique_ptr<EnumExprField> (clone_enum_expr_field_impl ()); + return std::unique_ptr<EnumExprField> (clone_enum_expr_field_impl ()); } virtual void accept_vis (ASTVisitor &vis) = 0; @@ -2218,32 +1765,31 @@ class EnumExprFieldIdentifier : public EnumExprField public: EnumExprFieldIdentifier (Identifier field_identifier) - : field_name (::std::move (field_identifier)) + : field_name (std::move (field_identifier)) {} - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprFieldIdentifier *clone_enum_expr_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprFieldIdentifier *clone_enum_expr_field_impl () const override { return new EnumExprFieldIdentifier (*this); } }; -// Base AST node for a single enum expression field with an assigned value - -// abstract +/* Base AST node for a single enum expression field with an assigned value - + * abstract */ class EnumExprFieldWithVal : public EnumExprField { - // Expr* value; - ::std::unique_ptr<Expr> value; + std::unique_ptr<Expr> value; // TODO: should this store location data? protected: - EnumExprFieldWithVal (::std::unique_ptr<Expr> field_value) - : value (::std::move (field_value)) + EnumExprFieldWithVal (std::unique_ptr<Expr> field_value) + : value (std::move (field_value)) {} // Copy constructor must clone unique_ptr value @@ -2251,8 +1797,6 @@ protected: : value (other.value->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to clone EnumExprFieldWithVal &operator= (EnumExprFieldWithVal const &other) { @@ -2275,21 +1819,20 @@ class EnumExprFieldIdentifierValue : public EnumExprFieldWithVal public: EnumExprFieldIdentifierValue (Identifier field_name, - ::std::unique_ptr<Expr> field_value) - : EnumExprFieldWithVal (::std::move (field_value)), - field_name (::std::move (field_name)) + std::unique_ptr<Expr> field_value) + : EnumExprFieldWithVal (std::move (field_value)), + field_name (std::move (field_name)) {} // copy constructor, destructor, and assignment operator should not need // defining - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprFieldIdentifierValue * - clone_enum_expr_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprFieldIdentifierValue *clone_enum_expr_field_impl () const override { return new EnumExprFieldIdentifierValue (*this); } @@ -2305,19 +1848,16 @@ class EnumExprFieldIndexValue : public EnumExprFieldWithVal public: EnumExprFieldIndexValue (TupleIndex field_index, - ::std::unique_ptr<Expr> field_value) - : EnumExprFieldWithVal (::std::move (field_value)), index (field_index) + std::unique_ptr<Expr> field_value) + : EnumExprFieldWithVal (std::move (field_value)), index (field_index) {} - // copy constructor, destructor, and assignment operator should not need - // defining - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprFieldIndexValue *clone_enum_expr_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprFieldIndexValue *clone_enum_expr_field_impl () const override { return new EnumExprFieldIndexValue (*this); } @@ -2326,39 +1866,33 @@ protected: // Struct-like syntax enum variant instance creation AST node class EnumExprStruct : public EnumVariantExpr { - //::std::vector<EnumExprField> fields; - ::std::vector< ::std::unique_ptr<EnumExprField> > fields; + // std::vector<EnumExprField> fields; + std::vector<std::unique_ptr<EnumExprField>> fields; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; - /*inline ::std::vector< ::std::unique_ptr<EnumExprField> > get_fields() const + /*inline std::vector<std::unique_ptr<EnumExprField>> get_fields() const { return fields; }*/ - EnumExprStruct ( - PathInExpression enum_variant_path, - ::std::vector< ::std::unique_ptr<EnumExprField> > variant_fields, - ::std::vector<Attribute> outer_attribs, Location locus) - : EnumVariantExpr (::std::move (enum_variant_path), - ::std::move (outer_attribs)), - fields (::std::move (variant_fields)), locus (locus) + EnumExprStruct (PathInExpression enum_variant_path, + std::vector<std::unique_ptr<EnumExprField>> variant_fields, + std::vector<Attribute> outer_attribs, Location locus) + : EnumVariantExpr (std::move (enum_variant_path), + std::move (outer_attribs)), + fields (std::move (variant_fields)), locus (locus) {} // copy constructor with vector clone EnumExprStruct (EnumExprStruct const &other) : EnumVariantExpr (other), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? fields.reserve (other.fields.size ()); - for (const auto &e : other.fields) - { - fields.push_back (e->clone_enum_expr_field ()); - } + fields.push_back (e->clone_enum_expr_field ()); } // overloaded assignment operator with vector clone @@ -2367,14 +1901,9 @@ public: EnumVariantExpr::operator= (other); locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? fields.reserve (other.fields.size ()); - for (const auto &e : other.fields) - { - fields.push_back (e->clone_enum_expr_field ()); - } + fields.push_back (e->clone_enum_expr_field ()); return *this; } @@ -2384,22 +1913,21 @@ public: EnumExprStruct &operator= (EnumExprStruct &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprStruct *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprStruct *clone_expr_impl () const override { return new EnumExprStruct (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprStruct *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprStruct *clone_expr_without_block_impl () const override { return new EnumExprStruct (*this); } @@ -2408,38 +1936,32 @@ protected: // Tuple-like syntax enum variant instance creation AST node class EnumExprTuple : public EnumVariantExpr { - //::std::vector<Expr> values; - ::std::vector< ::std::unique_ptr<Expr> > values; + std::vector<std::unique_ptr<Expr>> values; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; - /*inline ::std::vector< ::std::unique_ptr<Expr> > get_values() const { + /*inline std::vector<std::unique_ptr<Expr>> get_values() const { return values; }*/ EnumExprTuple (PathInExpression enum_variant_path, - ::std::vector< ::std::unique_ptr<Expr> > variant_values, - ::std::vector<Attribute> outer_attribs, Location locus) - : EnumVariantExpr (::std::move (enum_variant_path), - ::std::move (outer_attribs)), - values (::std::move (variant_values)), locus (locus) + std::vector<std::unique_ptr<Expr>> variant_values, + std::vector<Attribute> outer_attribs, Location locus) + : EnumVariantExpr (std::move (enum_variant_path), + std::move (outer_attribs)), + values (std::move (variant_values)), locus (locus) {} // copy constructor with vector clone EnumExprTuple (EnumExprTuple const &other) : EnumVariantExpr (other), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? values.reserve (other.values.size ()); - for (const auto &e : other.values) - { - values.push_back (e->clone_expr ()); - } + values.push_back (e->clone_expr ()); } // overloaded assignment operator with vector clone @@ -2448,14 +1970,9 @@ public: EnumVariantExpr::operator= (other); locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? values.reserve (other.values.size ()); - for (const auto &e : other.values) - { - values.push_back (e->clone_expr ()); - } + values.push_back (e->clone_expr ()); return *this; } @@ -2465,22 +1982,21 @@ public: EnumExprTuple &operator= (EnumExprTuple &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprTuple *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprTuple *clone_expr_impl () const override { return new EnumExprTuple (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprTuple *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprTuple *clone_expr_without_block_impl () const override { return new EnumExprTuple (*this); } @@ -2492,73 +2008,67 @@ class EnumExprFieldless : public EnumVariantExpr Location locus; public: - ::std::string as_string () const + std::string as_string () const override { // return enum_variant_path.as_string(); return get_enum_variant_path ().as_string (); } EnumExprFieldless (PathInExpression enum_variant_path, - ::std::vector<Attribute> outer_attribs, Location locus) - : EnumVariantExpr (::std::move (enum_variant_path), - ::std::move (outer_attribs)), + std::vector<Attribute> outer_attribs, Location locus) + : EnumVariantExpr (std::move (enum_variant_path), + std::move (outer_attribs)), locus (locus) {} - // copy constructor, destructor, and assignment operator should not need - // defining - Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprFieldless *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprFieldless *clone_expr_impl () const override { return new EnumExprFieldless (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual EnumExprFieldless *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + EnumExprFieldless *clone_expr_without_block_impl () const override { return new EnumExprFieldless (*this); } }; +// Forward decl for Function - used in CallExpr +class Function; + // Function call expression AST node class CallExpr : public ExprWithoutBlock { public: - // Expr* function; - ::std::unique_ptr<Expr> function; - //::std::vector<Expr> params; // inlined form of CallParams - ::std::vector< ::std::unique_ptr<Expr> > params; + std::unique_ptr<Expr> function; + // inlined form of CallParams + std::vector<std::unique_ptr<Expr>> params; Location locus; Function *fndeclRef; - /*~CallExpr() { - delete function; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - /*inline ::std::vector< ::std::unique_ptr<Expr> > get_params() const { + /*inline std::vector<std::unique_ptr<Expr>> get_params() const { return params; }*/ - 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)), - function (::std::move (function_expr)), - params (::std::move (function_params)), locus (locus) + 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)), + function (std::move (function_expr)), + params (std::move (function_params)), locus (locus) {} // copy constructor requires clone @@ -2566,18 +2076,11 @@ public: : ExprWithoutBlock (other), function (other.function->clone_expr ()), locus (other.locus) /*, params(other.params),*/ { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? params.reserve (other.params.size ()); - for (const auto &e : other.params) - { - params.push_back (e->clone_expr ()); - } + params.push_back (e->clone_expr ()); } - // Destructor - define here if required - // Overload assignment operator to clone CallExpr &operator= (CallExpr const &other) { @@ -2587,14 +2090,9 @@ public: // params = other.params; // outer_attrs = other.outer_attrs; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? params.reserve (other.params.size ()); - for (const auto &e : other.params) - { - params.push_back (e->clone_expr ()); - } + params.push_back (e->clone_expr ()); return *this; } @@ -2604,25 +2102,21 @@ public: CallExpr &operator= (CallExpr &&other) = default; // Returns whether function call has parameters. - inline bool has_params () const { return !params.empty (); } + bool has_params () const { return !params.empty (); } Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual CallExpr *clone_expr_impl () const OVERRIDE - { - return new CallExpr (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + CallExpr *clone_expr_impl () const override { return new CallExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual CallExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + CallExpr *clone_expr_without_block_impl () const override { return new CallExpr (*this); } @@ -2631,33 +2125,28 @@ protected: // Method call expression AST node class MethodCallExpr : public ExprWithoutBlock { - // Expr* receiver; - ::std::unique_ptr<Expr> receiver; + std::unique_ptr<Expr> receiver; PathExprSegment method_name; - //::std::vector<Expr> params; // inlined form of CallParams - ::std::vector< ::std::unique_ptr<Expr> > params; + // inlined form of CallParams + std::vector<std::unique_ptr<Expr>> params; Location locus; public: - /*~MethodCallExpr() { - delete receiver; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - /*inline ::std::vector< ::std::unique_ptr<Expr> > get_params() const { + /*inline std::vector<std::unique_ptr<Expr>> get_params() const { return params; }*/ - MethodCallExpr (::std::unique_ptr<Expr> call_receiver, + MethodCallExpr (std::unique_ptr<Expr> call_receiver, PathExprSegment method_path, - ::std::vector< ::std::unique_ptr<Expr> > method_params, - ::std::vector<Attribute> outer_attribs, Location locus) - : ExprWithoutBlock (::std::move (outer_attribs)), - receiver (::std::move (call_receiver)), - method_name (::std::move (method_path)), - params (::std::move (method_params)), locus (locus) + std::vector<std::unique_ptr<Expr>> method_params, + std::vector<Attribute> outer_attribs, Location locus) + : ExprWithoutBlock (std::move (outer_attribs)), + receiver (std::move (call_receiver)), + method_name (std::move (method_path)), params (std::move (method_params)), + locus (locus) {} // copy constructor required due to cloning @@ -2665,18 +2154,11 @@ public: : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()), method_name (other.method_name), locus (other.locus) /*, params(other.params),*/ { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? params.reserve (other.params.size ()); - for (const auto &e : other.params) - { - params.push_back (e->clone_expr ()); - } + params.push_back (e->clone_expr ()); } - // Destructor - define here if required - // Overload assignment operator to clone receiver object MethodCallExpr &operator= (MethodCallExpr const &other) { @@ -2687,14 +2169,9 @@ public: // params = other.params; // outer_attrs = other.outer_attrs; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? params.reserve (other.params.size ()); - for (const auto &e : other.params) - { - params.push_back (e->clone_expr ()); - } + params.push_back (e->clone_expr ()); return *this; } @@ -2704,22 +2181,21 @@ public: MethodCallExpr &operator= (MethodCallExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MethodCallExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MethodCallExpr *clone_expr_impl () const override { return new MethodCallExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual MethodCallExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MethodCallExpr *clone_expr_without_block_impl () const override { return new MethodCallExpr (*this); } @@ -2729,25 +2205,20 @@ protected: // Struct or union field access expression AST node class FieldAccessExpr : public ExprWithoutBlock { - // Expr* receiver; - ::std::unique_ptr<Expr> receiver; + std::unique_ptr<Expr> receiver; Identifier field; Location locus; public: - /*~FieldAccessExpr() { - delete receiver; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - FieldAccessExpr (::std::unique_ptr<Expr> field_access_receiver, - Identifier field_name, - ::std::vector<Attribute> outer_attribs, Location locus) - : ExprWithoutBlock (::std::move (outer_attribs)), - receiver (::std::move (field_access_receiver)), - field (::std::move (field_name)), locus (locus) + FieldAccessExpr (std::unique_ptr<Expr> field_access_receiver, + Identifier field_name, std::vector<Attribute> outer_attribs, + Location locus) + : ExprWithoutBlock (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 @@ -2756,8 +2227,6 @@ public: field (other.field), locus (other.locus) {} - // Destructor - define here if required - // Overload assignment operator to clone unique_ptr FieldAccessExpr &operator= (FieldAccessExpr const &other) { @@ -2775,22 +2244,21 @@ public: FieldAccessExpr &operator= (FieldAccessExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual FieldAccessExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + FieldAccessExpr *clone_expr_impl () const override { return new FieldAccessExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual FieldAccessExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + FieldAccessExpr *clone_expr_without_block_impl () const override { return new FieldAccessExpr (*this); } @@ -2800,23 +2268,21 @@ protected: struct ClosureParam { private: - // Pattern pattern; - ::std::unique_ptr<Pattern> pattern; + std::unique_ptr<Pattern> pattern; // bool has_type_given; - // Type type; - ::std::unique_ptr<Type> type; + std::unique_ptr<Type> type; // TODO: should this store location data? public: // Returns whether the type of the parameter has been given. - inline bool has_type_given () const { return type != NULL; } + bool has_type_given () const { return type != nullptr; } // Constructor for closure parameter - ClosureParam (::std::unique_ptr<Pattern> param_pattern, - ::std::unique_ptr<Type> param_type = NULL) - : pattern (::std::move (param_pattern)), type (::std::move (param_type)) + ClosureParam (std::unique_ptr<Pattern> param_pattern, + std::unique_ptr<Type> param_type = nullptr) + : pattern (std::move (param_pattern)), type (std::move (param_type)) {} // Copy constructor required due to cloning as a result of unique_ptrs @@ -2824,10 +2290,8 @@ public: : pattern (other.pattern->clone_pattern ()) { // guard to protect from null pointer dereference - if (other.type != NULL) - { - type = other.type->clone_type (); - } + if (other.type != nullptr) + type = other.type->clone_type (); } ~ClosureParam () = default; @@ -2846,72 +2310,61 @@ public: ClosureParam &operator= (ClosureParam &&other) = default; // Returns whether closure parameter is in an error state. - inline bool is_error () const { return pattern == NULL; } + bool is_error () const { return pattern == nullptr; } // Creates an error state closure parameter. - static ClosureParam create_error () { return ClosureParam (NULL); } + static ClosureParam create_error () { return ClosureParam (nullptr); } - ::std::string as_string () const; + std::string as_string () const; }; // Base closure definition expression AST node - abstract class ClosureExpr : public ExprWithoutBlock { 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 + 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), - params (::std::move (closure_params)), locus (locus) + 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), + params (std::move (closure_params)), locus (locus) {} - // Copy constructor, destructor, and assignment operator override should not - // be needed public: - virtual ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - - Location get_locus_slow () const OVERRIDE { return get_locus (); } + Location get_locus_slow () const override { return get_locus (); } }; // Represents a non-type-specified closure expression AST node class ClosureExprInner : public ClosureExpr { - // Expr* closure_inner; - ::std::unique_ptr<Expr> closure_inner; + std::unique_ptr<Expr> closure_inner; public: - /*~ClosureExprInner() { - delete closure_inner; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // Constructor for a ClosureExprInner - ClosureExprInner (::std::unique_ptr<Expr> closure_inner_expr, - ::std::vector<ClosureParam> closure_params, Location locus, + ClosureExprInner (std::unique_ptr<Expr> closure_inner_expr, + std::vector<ClosureParam> closure_params, Location locus, bool is_move = false, - ::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : ClosureExpr (::std::move (closure_params), is_move, - ::std::move (outer_attribs), locus), - closure_inner (::std::move (closure_inner_expr)) + std::vector<Attribute> outer_attribs + = std::vector<Attribute> ()) + : ClosureExpr (std::move (closure_params), is_move, + std::move (outer_attribs), locus), + closure_inner (std::move (closure_inner_expr)) {} // Copy constructor must be defined to allow copying via cloning of unique_ptr ClosureExprInner (ClosureExprInner const &other) : ClosureExpr (other), closure_inner (other.closure_inner->clone_expr ()) {} - // TODO: ensure that this actually constructs properly - - // Destructor - define here if required // Overload assignment operator to clone closure_inner ClosureExprInner &operator= (ClosureExprInner const &other) @@ -2929,59 +2382,53 @@ public: ClosureExprInner (ClosureExprInner &&other) = default; ClosureExprInner &operator= (ClosureExprInner &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ClosureExprInner *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ClosureExprInner *clone_expr_impl () const override { return new ClosureExprInner (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ClosureExprInner *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ClosureExprInner *clone_expr_without_block_impl () const override { return new ClosureExprInner (*this); } }; -// Forward decl BlockExpr for ClosureExprInnerTyped -// class BlockExpr; - // A block AST node class BlockExpr : public ExprWithBlock { public: - ::std::vector<Attribute> inner_attrs; - - /*bool has_statements; - Statements statements;*/ + std::vector<Attribute> inner_attrs; // bool has_statements; - ::std::vector< ::std::unique_ptr<Stmt> > statements; + std::vector<std::unique_ptr<Stmt>> statements; // bool has_expr; - ::std::unique_ptr<ExprWithoutBlock> expr; // inlined from Statements + std::unique_ptr<ExprWithoutBlock> expr; // inlined from Statements Location locus; - ::std::string as_string () const; + std::string as_string () const override; // Returns whether the block contains statements. - inline bool has_statements () const { return !statements.empty (); } + bool has_statements () const { return !statements.empty (); } // Returns whether the block contains an expression - inline bool has_expr () const { return expr != NULL; } - - BlockExpr (::std::vector< ::std::unique_ptr<Stmt> > block_statements, - ::std::unique_ptr<ExprWithoutBlock> block_expr, - ::std::vector<Attribute> inner_attribs, - ::std::vector<Attribute> outer_attribs, Location locus) - : ExprWithBlock (::std::move (outer_attribs)), - inner_attrs (::std::move (inner_attribs)), - statements (::std::move (block_statements)), - expr (::std::move (block_expr)), locus (locus) + bool has_expr () const { return expr != nullptr; } + + BlockExpr (std::vector<std::unique_ptr<Stmt>> block_statements, + std::unique_ptr<ExprWithoutBlock> block_expr, + std::vector<Attribute> inner_attribs, + std::vector<Attribute> outer_attribs, Location locus) + : ExprWithBlock (std::move (outer_attribs)), + inner_attrs (std::move (inner_attribs)), + statements (std::move (block_statements)), expr (std::move (block_expr)), + locus (locus) {} // Copy constructor with clone @@ -2990,23 +2437,14 @@ public: inner_attrs (other.inner_attrs), locus (other.locus) { // guard to protect from null pointer dereference - if (other.expr != NULL) - { - expr = other.expr->clone_expr_without_block (); - } + if (other.expr != nullptr) + expr = other.expr->clone_expr_without_block (); - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? statements.reserve (other.statements.size ()); - for (const auto &e : other.statements) - { - statements.push_back (e->clone_stmt ()); - } + statements.push_back (e->clone_stmt ()); } - // Destructor - define here if required - // Overloaded assignment operator to clone pointer BlockExpr &operator= (BlockExpr const &other) { @@ -3017,14 +2455,9 @@ public: locus = other.locus; // outer_attrs = other.outer_attrs; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? statements.reserve (other.statements.size ()); - for (const auto &e : other.statements) - { - statements.push_back (e->clone_stmt ()); - } + statements.push_back (e->clone_stmt ()); return *this; } @@ -3034,30 +2467,29 @@ public: BlockExpr &operator= (BlockExpr &&other) = default; // Unique pointer custom clone function - ::std::unique_ptr<BlockExpr> clone_block_expr () const + std::unique_ptr<BlockExpr> clone_block_expr () const { - return ::std::unique_ptr<BlockExpr> (clone_block_expr_impl ()); + return std::unique_ptr<BlockExpr> (clone_block_expr_impl ()); } Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual BlockExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + BlockExpr *clone_expr_impl () const override { - return new BlockExpr (*this); + return clone_block_expr_impl (); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual BlockExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + BlockExpr *clone_expr_with_block_impl () const override { - return new BlockExpr (*this); + return clone_block_expr_impl (); } /* This is the base method as not an abstract class - not virtual but could be @@ -3071,30 +2503,24 @@ protected: // Represents a type-specified closure expression AST node class ClosureExprInnerTyped : public ClosureExpr { - // Type return_type; - ::std::unique_ptr<Type> return_type; - // BlockExpr* expr; - ::std::unique_ptr<BlockExpr> + std::unique_ptr<Type> return_type; + std::unique_ptr<BlockExpr> expr; // only used because may be polymorphic in future public: - /*~ClosureExprInnerTyped() { - delete expr; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // Constructor potentially with a move - ClosureExprInnerTyped (::std::unique_ptr<Type> closure_return_type, - ::std::unique_ptr<BlockExpr> closure_expr, - ::std::vector<ClosureParam> closure_params, + ClosureExprInnerTyped (std::unique_ptr<Type> closure_return_type, + std::unique_ptr<BlockExpr> closure_expr, + std::vector<ClosureParam> closure_params, Location locus, bool is_move = false, - ::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : ClosureExpr (::std::move (closure_params), is_move, - ::std::move (outer_attribs), locus), - return_type (::std::move (closure_return_type)), - expr (::std::move (closure_expr)) + std::vector<Attribute> outer_attribs + = std::vector<Attribute> ()) + : ClosureExpr (std::move (closure_params), is_move, + std::move (outer_attribs), locus), + return_type (std::move (closure_return_type)), + expr (std::move (closure_expr)) {} // Copy constructor requires cloning @@ -3103,8 +2529,6 @@ public: expr (other.expr->clone_block_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to clone unique_ptrs ClosureExprInnerTyped &operator= (ClosureExprInnerTyped const &other) { @@ -3122,19 +2546,19 @@ public: ClosureExprInnerTyped (ClosureExprInnerTyped &&other) = default; ClosureExprInnerTyped &operator= (ClosureExprInnerTyped &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ClosureExprInnerTyped *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ClosureExprInnerTyped *clone_expr_impl () const override { return new ClosureExprInnerTyped (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ClosureExprInnerTyped *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ClosureExprInnerTyped *clone_expr_without_block_impl () const override { return new ClosureExprInnerTyped (*this); } @@ -3145,43 +2569,38 @@ class ContinueExpr : public ExprWithoutBlock { // bool has_label; Lifetime label; - Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns true if the continue expr has a label. - inline bool has_label () const { return !label.is_error (); } + 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)), locus (locus) + std::vector<Attribute> outer_attribs + = std::vector<Attribute> ()) + : ExprWithoutBlock (std::move (outer_attribs)), label (std::move (label)), + locus (locus) {} - // copy constructor, destructor, and assignment operator should not need - // defining - Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ContinueExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ContinueExpr *clone_expr_impl () const override { return new ContinueExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ContinueExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ContinueExpr *clone_expr_without_block_impl () const override { return new ContinueExpr (*this); } @@ -3195,35 +2614,27 @@ class BreakExpr : public ExprWithoutBlock Lifetime label; // bool has_break_expr; - // Expr* break_expr; // may be uninitialised - ::std::unique_ptr<Expr> break_expr; + std::unique_ptr<Expr> break_expr; Location locus; public: - /*~BreakExpr() { - if (has_break_expr) { - delete break_expr; - } - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // Returns whether the break expression has a label or not. - inline bool has_label () const { return !label.is_error (); } + bool has_label () const { return !label.is_error (); } - // Returns whether the break expression has an expression used in the break or - // not. - inline bool has_break_expr () const { return break_expr != NULL; } + /* Returns whether the break expression has an expression used in the break or + * not. */ + 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 = NULL, - ::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : ExprWithoutBlock (::std::move (outer_attribs)), - label (::std::move (break_label)), - break_expr (::std::move (expr_in_break)), locus (locus) + std::unique_ptr<Expr> expr_in_break = nullptr, + std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) + : ExprWithoutBlock (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 @@ -3231,14 +2642,10 @@ public: : ExprWithoutBlock (other), label (other.label), locus (other.locus) { // guard to protect from null pointer dereference - if (other.break_expr != NULL) - { - break_expr = other.break_expr->clone_expr (); - } + if (other.break_expr != nullptr) + break_expr = other.break_expr->clone_expr (); } - // Destructor - define here if required - // Overload assignment operator to clone unique pointer BreakExpr &operator= (BreakExpr const &other) { @@ -3256,22 +2663,18 @@ public: BreakExpr &operator= (BreakExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual BreakExpr *clone_expr_impl () const OVERRIDE - { - return new BreakExpr (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + BreakExpr *clone_expr_impl () const override { return new BreakExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual BreakExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + BreakExpr *clone_expr_without_block_impl () const override { return new BreakExpr (*this); } @@ -3285,36 +2688,28 @@ class RangeExpr : public ExprWithoutBlock protected: // outer attributes not allowed before range expressions RangeExpr (Location locus) - : ExprWithoutBlock (::std::vector<Attribute> ()), locus (locus) + : ExprWithoutBlock (std::vector<Attribute> ()), locus (locus) {} public: Location get_locus () const { return locus; } - - Location get_locus_slow () const OVERRIDE { return get_locus (); } + Location get_locus_slow () const override { return get_locus (); } }; // Range from (inclusive) and to (exclusive) expression AST node object // aka RangeExpr; constructs a std::ops::Range object class RangeFromToExpr : public RangeExpr { - /*Expr* from; - Expr* to;*/ - ::std::unique_ptr<Expr> from; - ::std::unique_ptr<Expr> to; + std::unique_ptr<Expr> from; + std::unique_ptr<Expr> to; public: - /*~RangeFromToExpr() { - delete from; - delete to; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - RangeFromToExpr (::std::unique_ptr<Expr> range_from, - ::std::unique_ptr<Expr> range_to, Location locus) - : RangeExpr (locus), from (::std::move (range_from)), - to (::std::move (range_to)) + RangeFromToExpr (std::unique_ptr<Expr> range_from, + std::unique_ptr<Expr> range_to, Location locus) + : RangeExpr (locus), from (std::move (range_from)), + to (std::move (range_to)) {} // Copy constructor with cloning @@ -3323,8 +2718,6 @@ public: to (other.to->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to clone unique pointers RangeFromToExpr &operator= (RangeFromToExpr const &other) { @@ -3339,19 +2732,19 @@ public: RangeFromToExpr (RangeFromToExpr &&other) = default; RangeFromToExpr &operator= (RangeFromToExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeFromToExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeFromToExpr *clone_expr_impl () const override { return new RangeFromToExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeFromToExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeFromToExpr *clone_expr_without_block_impl () const override { return new RangeFromToExpr (*this); } @@ -3361,18 +2754,13 @@ protected: // constructs a std::ops::RangeFrom object class RangeFromExpr : public RangeExpr { - // Expr* from; - ::std::unique_ptr<Expr> from; + std::unique_ptr<Expr> from; public: - /*~RangeFromExpr() { - delete from; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - RangeFromExpr (::std::unique_ptr<Expr> range_from, Location locus) - : RangeExpr (locus), from (::std::move (range_from)) + RangeFromExpr (std::unique_ptr<Expr> range_from, Location locus) + : RangeExpr (locus), from (std::move (range_from)) {} // Copy constructor with clone @@ -3380,8 +2768,6 @@ public: : RangeExpr (other), from (other.from->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to clone unique_ptr RangeFromExpr &operator= (RangeFromExpr const &other) { @@ -3395,19 +2781,19 @@ public: RangeFromExpr (RangeFromExpr &&other) = default; RangeFromExpr &operator= (RangeFromExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeFromExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeFromExpr *clone_expr_impl () const override { return new RangeFromExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeFromExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeFromExpr *clone_expr_without_block_impl () const override { return new RangeFromExpr (*this); } @@ -3417,19 +2803,14 @@ protected: // constructs a std::ops::RangeTo object class RangeToExpr : public RangeExpr { - // Expr* to; - ::std::unique_ptr<Expr> to; + std::unique_ptr<Expr> to; public: - /*~RangeToExpr() { - delete to; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // outer attributes not allowed - RangeToExpr (::std::unique_ptr<Expr> range_to, Location locus) - : RangeExpr (locus), to (::std::move (range_to)) + RangeToExpr (std::unique_ptr<Expr> range_to, Location locus) + : RangeExpr (locus), to (std::move (range_to)) {} // Copy constructor with clone @@ -3437,8 +2818,6 @@ public: : RangeExpr (other), to (other.to->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to clone unique_ptr RangeToExpr &operator= (RangeToExpr const &other) { @@ -3452,19 +2831,19 @@ public: RangeToExpr (RangeToExpr &&other) = default; RangeToExpr &operator= (RangeToExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeToExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeToExpr *clone_expr_impl () const override { return new RangeToExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeToExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeToExpr *clone_expr_without_block_impl () const override { return new RangeToExpr (*this); } @@ -3475,24 +2854,24 @@ protected: class RangeFullExpr : public RangeExpr { public: - ::std::string as_string () const; + std::string as_string () const override; RangeFullExpr (Location locus) : RangeExpr (locus) {} // outer attributes not allowed - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeFullExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeFullExpr *clone_expr_impl () const override { return new RangeFullExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeFullExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeFullExpr *clone_expr_without_block_impl () const override { return new RangeFullExpr (*this); } @@ -3502,23 +2881,16 @@ protected: // aka RangeInclusiveExpr; constructs a std::ops::RangeInclusive object class RangeFromToInclExpr : public RangeExpr { - /*Expr* from; - Expr* to;*/ - ::std::unique_ptr<Expr> from; - ::std::unique_ptr<Expr> to; + std::unique_ptr<Expr> from; + std::unique_ptr<Expr> to; public: - /*~RangeFromToInclExpr() { - delete from; - delete to; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - RangeFromToInclExpr (::std::unique_ptr<Expr> range_from, - ::std::unique_ptr<Expr> range_to, Location locus) - : RangeExpr (locus), from (::std::move (range_from)), - to (::std::move (range_to)) + RangeFromToInclExpr (std::unique_ptr<Expr> range_from, + std::unique_ptr<Expr> range_to, Location locus) + : RangeExpr (locus), from (std::move (range_from)), + to (std::move (range_to)) {} // outer attributes not allowed @@ -3528,8 +2900,6 @@ public: to (other.to->clone_expr ()) {} - // Destructor - define here if required - // Overload assignment operator to use clone RangeFromToInclExpr &operator= (RangeFromToInclExpr const &other) { @@ -3544,19 +2914,19 @@ public: RangeFromToInclExpr (RangeFromToInclExpr &&other) = default; RangeFromToInclExpr &operator= (RangeFromToInclExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeFromToInclExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeFromToInclExpr *clone_expr_impl () const override { return new RangeFromToInclExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeFromToInclExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeFromToInclExpr *clone_expr_without_block_impl () const override { return new RangeFromToInclExpr (*this); } @@ -3566,18 +2936,13 @@ protected: // aka RangeToInclusiveExpr; constructs a std::ops::RangeToInclusive object class RangeToInclExpr : public RangeExpr { - // Expr* to; - ::std::unique_ptr<Expr> to; + std::unique_ptr<Expr> to; public: - /*~RangeToInclExpr() { - delete to; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - RangeToInclExpr (::std::unique_ptr<Expr> range_to, Location locus) - : RangeExpr (locus), to (::std::move (range_to)) + RangeToInclExpr (std::unique_ptr<Expr> range_to, Location locus) + : RangeExpr (locus), to (std::move (range_to)) {} // outer attributes not allowed @@ -3586,8 +2951,6 @@ public: : RangeExpr (other), to (other.to->clone_expr ()) {} - // Define destructor here if required - // Overload assignment operator to clone pointer RangeToInclExpr &operator= (RangeToInclExpr const &other) { @@ -3601,19 +2964,19 @@ public: RangeToInclExpr (RangeToInclExpr &&other) = default; RangeToInclExpr &operator= (RangeToInclExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeToInclExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeToInclExpr *clone_expr_impl () const override { return new RangeToInclExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangeToInclExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangeToInclExpr *clone_expr_without_block_impl () const override { return new RangeToInclExpr (*this); } @@ -3623,30 +2986,21 @@ protected: class ReturnExpr : public ExprWithoutBlock { public: - // bool has_return_expr; - // Expr* return_expr; - ::std::unique_ptr<Expr> return_expr; + std::unique_ptr<Expr> return_expr; Location locus; - /*~ReturnExpr() { - if (has_return_expr) { - delete return_expr; - } - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - // Returns whether the object has an expression returned (i.e. not void return - // type). - inline bool has_return_expr () const { return return_expr != NULL; } + /* Returns whether the object has an expression returned (i.e. not void return + * type). */ + bool has_return_expr () const { return return_expr != nullptr; } // Constructor for ReturnExpr. - ReturnExpr (Location locus, ::std::unique_ptr<Expr> returned_expr = NULL, - ::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : ExprWithoutBlock (::std::move (outer_attribs)), - return_expr (::std::move (returned_expr)), locus (locus) + ReturnExpr (Location locus, std::unique_ptr<Expr> returned_expr = nullptr, + std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) + : ExprWithoutBlock (std::move (outer_attribs)), + return_expr (std::move (returned_expr)), locus (locus) {} // Copy constructor with clone @@ -3654,14 +3008,10 @@ public: : ExprWithoutBlock (other), locus (other.locus) { // guard to protect from null pointer dereference - if (other.return_expr != NULL) - { - return_expr = other.return_expr->clone_expr (); - } + if (other.return_expr != nullptr) + return_expr = other.return_expr->clone_expr (); } - // Destructor - define here if required - // Overloaded assignment operator to clone return_expr pointer ReturnExpr &operator= (ReturnExpr const &other) { @@ -3678,22 +3028,21 @@ public: ReturnExpr &operator= (ReturnExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ReturnExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ReturnExpr *clone_expr_impl () const override { return new ReturnExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ReturnExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ReturnExpr *clone_expr_without_block_impl () const override { return new ReturnExpr (*this); } @@ -3701,31 +3050,22 @@ protected: // Forward decl - defined in rust-macro.h class MacroInvocation; -/*class MacroInvocation : public ExprWithoutBlock { - public: - ::std::string as_string() const; -};*/ // An unsafe block AST node class UnsafeBlockExpr : public ExprWithBlock { // Or just have it extend BlockExpr - // BlockExpr* expr; - ::std::unique_ptr<BlockExpr> expr; + std::unique_ptr<BlockExpr> expr; Location locus; public: - /*~UnsafeBlockExpr() { - delete expr; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - UnsafeBlockExpr (::std::unique_ptr<BlockExpr> block_expr, - ::std::vector<Attribute> outer_attribs, Location locus) - : ExprWithBlock (::std::move (outer_attribs)), - expr (::std::move (block_expr)), locus (locus) + UnsafeBlockExpr (std::unique_ptr<BlockExpr> block_expr, + std::vector<Attribute> outer_attribs, Location locus) + : ExprWithBlock (std::move (outer_attribs)), expr (std::move (block_expr)), + locus (locus) {} // Copy constructor with clone @@ -3734,8 +3074,6 @@ public: locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone UnsafeBlockExpr &operator= (UnsafeBlockExpr const &other) { @@ -3752,22 +3090,21 @@ public: UnsafeBlockExpr &operator= (UnsafeBlockExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual UnsafeBlockExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + UnsafeBlockExpr *clone_expr_impl () const override { return new UnsafeBlockExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual UnsafeBlockExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + UnsafeBlockExpr *clone_expr_with_block_impl () const override { return new UnsafeBlockExpr (*this); } @@ -3782,14 +3119,14 @@ class LoopLabel /*: public Node*/ Location locus; public: - ::std::string as_string () const; + std::string as_string () const; LoopLabel (Lifetime loop_label, Location locus = Location ()) - : label (::std::move (loop_label)), locus (locus) + : label (std::move (loop_label)), locus (locus) {} // Returns whether the LoopLabel is in an error state. - inline bool is_error () const { return label.is_error (); } + bool is_error () const { return label.is_error (); } // Creates an error state LoopLabel. static LoopLabel error () { return LoopLabel (Lifetime::error ()); } @@ -3805,21 +3142,20 @@ protected: // bool has_loop_label; LoopLabel loop_label; - // BlockExpr* loop_block; - ::std::unique_ptr<BlockExpr> loop_block; + std::unique_ptr<BlockExpr> loop_block; private: Location locus; protected: // Constructor for BaseLoopExpr - BaseLoopExpr (::std::unique_ptr<BlockExpr> loop_block, Location locus, + BaseLoopExpr (std::unique_ptr<BlockExpr> loop_block, Location locus, LoopLabel loop_label = LoopLabel::error (), - ::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : ExprWithBlock (::std::move (outer_attribs)), - loop_label (::std::move (loop_label)), - loop_block (::std::move (loop_block)), locus (locus) + std::vector<Attribute> outer_attribs + = std::vector<Attribute> ()) + : ExprWithBlock (std::move (outer_attribs)), + loop_label (std::move (loop_label)), loop_block (std::move (loop_block)), + locus (locus) {} // Copy constructor for BaseLoopExpr with clone @@ -3828,8 +3164,6 @@ protected: loop_block (other.loop_block->clone_block_expr ()), locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone BaseLoopExpr &operator= (BaseLoopExpr const &other) { @@ -3847,48 +3181,36 @@ protected: BaseLoopExpr &operator= (BaseLoopExpr &&other) = default; public: - /*~BaseLoopExpr() { - delete loop_block; - }*/ - - inline bool has_loop_label () const { return !loop_label.is_error (); } + bool has_loop_label () const { return !loop_label.is_error (); } Location get_locus () const { return locus; } - - Location get_locus_slow () const OVERRIDE { return get_locus (); } + Location get_locus_slow () const override { return get_locus (); } }; // 'Loop' expression (i.e. the infinite loop) AST node class LoopExpr : public BaseLoopExpr { public: - ::std::string as_string () const; + std::string as_string () const override; // Constructor for LoopExpr - LoopExpr (::std::unique_ptr<BlockExpr> loop_block, Location locus, + LoopExpr (std::unique_ptr<BlockExpr> loop_block, Location locus, LoopLabel loop_label = LoopLabel::error (), - ::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : BaseLoopExpr (::std::move (loop_block), locus, ::std::move (loop_label), - ::std::move (outer_attribs)) + std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) + : BaseLoopExpr (std::move (loop_block), locus, std::move (loop_label), + std::move (outer_attribs)) {} - // copy constructor, destructor, and assignment operator should not need - // modification - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual LoopExpr *clone_expr_impl () const OVERRIDE - { - return new LoopExpr (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + LoopExpr *clone_expr_impl () const override { return new LoopExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual LoopExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + LoopExpr *clone_expr_with_block_impl () const override { return new LoopExpr (*this); } @@ -3897,25 +3219,20 @@ protected: // While loop expression AST node (predicate loop) class WhileLoopExpr : public BaseLoopExpr { - // Expr* condition; - ::std::unique_ptr<Expr> condition; + std::unique_ptr<Expr> condition; public: - /*~WhileLoopExpr() { - delete condition; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // Constructor for while loop with loop label - WhileLoopExpr (::std::unique_ptr<Expr> loop_condition, - ::std::unique_ptr<BlockExpr> loop_block, Location locus, + WhileLoopExpr (std::unique_ptr<Expr> loop_condition, + std::unique_ptr<BlockExpr> loop_block, Location locus, LoopLabel loop_label = LoopLabel::error (), - ::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : BaseLoopExpr (::std::move (loop_block), locus, ::std::move (loop_label), - ::std::move (outer_attribs)), - condition (::std::move (loop_condition)) + std::vector<Attribute> outer_attribs + = std::vector<Attribute> ()) + : BaseLoopExpr (std::move (loop_block), locus, std::move (loop_label), + std::move (outer_attribs)), + condition (std::move (loop_condition)) {} // Copy constructor with clone @@ -3923,8 +3240,6 @@ public: : BaseLoopExpr (other), condition (other.condition->clone_expr ()) {} - // Destructor - define here if required - // Overloaded assignment operator to clone WhileLoopExpr &operator= (WhileLoopExpr const &other) { @@ -3941,52 +3256,45 @@ public: WhileLoopExpr (WhileLoopExpr &&other) = default; WhileLoopExpr &operator= (WhileLoopExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual WhileLoopExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + WhileLoopExpr *clone_expr_impl () const override { return new WhileLoopExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual WhileLoopExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + WhileLoopExpr *clone_expr_with_block_impl () const override { return new WhileLoopExpr (*this); } }; -// Forward decl MatchArmPatterns -// struct MatchArmPatterns; - // While let loop expression AST node (predicate pattern loop) class WhileLetLoopExpr : public BaseLoopExpr { // MatchArmPatterns patterns; - ::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns; // inlined - // Expr* condition; - ::std::unique_ptr<Expr> condition; + std::vector<std::unique_ptr<Pattern>> match_arm_patterns; // inlined + std::unique_ptr<Expr> condition; public: - /*~WhileLetLoopExpr() { - delete condition; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // Constructor with a loop label - WhileLetLoopExpr ( - ::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns, - ::std::unique_ptr<Expr> condition, ::std::unique_ptr<BlockExpr> loop_block, - Location locus, LoopLabel loop_label = LoopLabel::error (), - ::std::vector<Attribute> outer_attribs = ::std::vector<Attribute> ()) - : BaseLoopExpr (::std::move (loop_block), locus, ::std::move (loop_label), - ::std::move (outer_attribs)), - match_arm_patterns (::std::move (match_arm_patterns)), - condition (::std::move (condition)) + WhileLetLoopExpr (std::vector<std::unique_ptr<Pattern>> match_arm_patterns, + std::unique_ptr<Expr> condition, + std::unique_ptr<BlockExpr> loop_block, Location locus, + LoopLabel loop_label = LoopLabel::error (), + std::vector<Attribute> outer_attribs + = std::vector<Attribute> ()) + : BaseLoopExpr (std::move (loop_block), locus, std::move (loop_label), + std::move (outer_attribs)), + match_arm_patterns (std::move (match_arm_patterns)), + condition (std::move (condition)) {} // Copy constructor with clone @@ -3995,18 +3303,11 @@ public: /*match_arm_patterns(other.match_arm_patterns),*/ condition ( other.condition->clone_expr ()) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? match_arm_patterns.reserve (other.match_arm_patterns.size ()); - for (const auto &e : other.match_arm_patterns) - { - match_arm_patterns.push_back (e->clone_pattern ()); - } + match_arm_patterns.push_back (e->clone_pattern ()); } - // Destructor - define here if required - // Overloaded assignment operator to clone pointers WhileLetLoopExpr &operator= (WhileLetLoopExpr const &other) { @@ -4017,14 +3318,9 @@ public: // loop_label = other.loop_label; // outer_attrs = other.outer_attrs; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? match_arm_patterns.reserve (other.match_arm_patterns.size ()); - for (const auto &e : other.match_arm_patterns) - { - match_arm_patterns.push_back (e->clone_pattern ()); - } + match_arm_patterns.push_back (e->clone_pattern ()); return *this; } @@ -4033,19 +3329,19 @@ public: WhileLetLoopExpr (WhileLetLoopExpr &&other) = default; WhileLetLoopExpr &operator= (WhileLetLoopExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual WhileLetLoopExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + WhileLetLoopExpr *clone_expr_impl () const override { return new WhileLetLoopExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual WhileLetLoopExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + WhileLetLoopExpr *clone_expr_with_block_impl () const override { return new WhileLetLoopExpr (*this); } @@ -4054,29 +3350,22 @@ protected: // For loop expression AST node (iterator loop) class ForLoopExpr : public BaseLoopExpr { - // Pattern pattern; - ::std::unique_ptr<Pattern> pattern; - // Expr* iterator_expr; - ::std::unique_ptr<Expr> iterator_expr; + std::unique_ptr<Pattern> pattern; + std::unique_ptr<Expr> iterator_expr; public: - /*~ForLoopExpr() { - delete iterator_expr; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // Constructor with loop label - ForLoopExpr (::std::unique_ptr<Pattern> loop_pattern, - ::std::unique_ptr<Expr> iterator_expr, - ::std::unique_ptr<BlockExpr> loop_body, Location locus, + ForLoopExpr (std::unique_ptr<Pattern> loop_pattern, + std::unique_ptr<Expr> iterator_expr, + std::unique_ptr<BlockExpr> loop_body, Location locus, LoopLabel loop_label = LoopLabel::error (), - ::std::vector<Attribute> outer_attribs - = ::std::vector<Attribute> ()) - : BaseLoopExpr (::std::move (loop_body), locus, ::std::move (loop_label), - ::std::move (outer_attribs)), - pattern (::std::move (loop_pattern)), - iterator_expr (::std::move (iterator_expr)) + std::vector<Attribute> outer_attribs = std::vector<Attribute> ()) + : BaseLoopExpr (std::move (loop_body), locus, std::move (loop_label), + std::move (outer_attribs)), + pattern (std::move (loop_pattern)), + iterator_expr (std::move (iterator_expr)) {} // Copy constructor with clone @@ -4085,8 +3374,6 @@ public: iterator_expr (other.iterator_expr->clone_expr ()) {} - // Destructor - define here if required - // Overloaded assignment operator to clone ForLoopExpr &operator= (ForLoopExpr const &other) { @@ -4104,19 +3391,19 @@ public: ForLoopExpr (ForLoopExpr &&other) = default; ForLoopExpr &operator= (ForLoopExpr &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ForLoopExpr *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ForLoopExpr *clone_expr_impl () const override { return new ForLoopExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ForLoopExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ForLoopExpr *clone_expr_with_block_impl () const override { return new ForLoopExpr (*this); } @@ -4128,30 +3415,18 @@ class IfLetExpr; // Base if expression with no "else" or "if let" AST node class IfExpr : public ExprWithBlock { - /*Expr* condition; - BlockExpr* if_block;*/ - ::std::unique_ptr<Expr> condition; - ::std::unique_ptr<BlockExpr> if_block; - /*union { - BlockExpr else_block; - IfExpr* if_expr; - IfLetExpr if_let_expr; - } consequent_block;*/ + std::unique_ptr<Expr> condition; + std::unique_ptr<BlockExpr> if_block; Location locus; public: - /*virtual ~IfExpr() { - delete condition; - delete if_block; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - 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)), + 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)), locus (locus) {} // outer attributes are never allowed on IfExprs @@ -4162,8 +3437,6 @@ public: if_block (other.if_block->clone_block_expr ()), locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone expressions IfExpr &operator= (IfExpr const &other) { @@ -4180,9 +3453,9 @@ public: IfExpr &operator= (IfExpr &&other) = default; // Unique pointer custom clone function - ::std::unique_ptr<IfExpr> clone_if_expr () const + std::unique_ptr<IfExpr> clone_if_expr () const { - return ::std::unique_ptr<IfExpr> (clone_if_expr_impl ()); + return std::unique_ptr<IfExpr> (clone_if_expr_impl ()); } /* Note that multiple "else if"s are handled via nested ASTs rather than a @@ -4190,33 +3463,27 @@ public: * better approach? or does it not parse correctly and have downsides? */ Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; void vis_if_condition (ASTVisitor &vis) { condition->accept_vis (vis); } - void vis_if_block (ASTVisitor &vis) { if_block->accept_vis (vis); } Expr *get_if_condition () { return condition.get (); } - BlockExpr *get_if_block () { return if_block.get (); } protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExpr *clone_expr_impl () const OVERRIDE - { - return new IfExpr (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExpr *clone_expr_impl () const override { return new IfExpr (*this); } // Base clone function but still concrete as concrete base class virtual IfExpr *clone_if_expr_impl () const { return new IfExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExpr *clone_expr_with_block_impl () const override { return new IfExpr (*this); } @@ -4225,21 +3492,16 @@ protected: // If expression with an ending "else" expression AST node (trailing) class IfExprConseqElse : public IfExpr { - // BlockExpr* else_block; - ::std::unique_ptr<BlockExpr> else_block; + std::unique_ptr<BlockExpr> else_block; public: - /*~IfExprConseqElse() { - delete else_block; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - IfExprConseqElse (::std::unique_ptr<Expr> condition, - ::std::unique_ptr<BlockExpr> if_block, - ::std::unique_ptr<BlockExpr> else_block, Location locus) - : IfExpr (::std::move (condition), ::std::move (if_block), locus), - else_block (::std::move (else_block)) + IfExprConseqElse (std::unique_ptr<Expr> condition, + std::unique_ptr<BlockExpr> if_block, + std::unique_ptr<BlockExpr> else_block, Location locus) + : IfExpr (std::move (condition), std::move (if_block), locus), + else_block (std::move (else_block)) {} // again, outer attributes not allowed @@ -4248,8 +3510,6 @@ public: : IfExpr (other), else_block (other.else_block->clone_block_expr ()) {} - // Destructor - define here if required - // Overloaded assignment operator with cloning IfExprConseqElse &operator= (IfExprConseqElse const &other) { @@ -4265,28 +3525,28 @@ public: IfExprConseqElse (IfExprConseqElse &&other) = default; IfExprConseqElse &operator= (IfExprConseqElse &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; void vis_else_block (ASTVisitor &vis) { else_block->accept_vis (vis); } protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqElse *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqElse *clone_expr_impl () const override { return new IfExprConseqElse (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqElse *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqElse *clone_expr_with_block_impl () const override { return new IfExprConseqElse (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqElse *clone_if_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqElse *clone_if_expr_impl () const override { return new IfExprConseqElse (*this); } @@ -4295,21 +3555,16 @@ protected: // If expression with an ending "else if" expression AST node class IfExprConseqIf : public IfExpr { - // IfExpr* if_expr; - ::std::unique_ptr<IfExpr> conseq_if_expr; + std::unique_ptr<IfExpr> conseq_if_expr; public: - /*~IfExprConseqIf() { - delete if_expr; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - IfExprConseqIf (::std::unique_ptr<Expr> condition, - ::std::unique_ptr<BlockExpr> if_block, - ::std::unique_ptr<IfExpr> conseq_if_expr, Location locus) - : IfExpr (::std::move (condition), ::std::move (if_block), locus), - conseq_if_expr (::std::move (conseq_if_expr)) + IfExprConseqIf (std::unique_ptr<Expr> condition, + std::unique_ptr<BlockExpr> if_block, + std::unique_ptr<IfExpr> conseq_if_expr, Location locus) + : IfExpr (std::move (condition), std::move (if_block), locus), + conseq_if_expr (std::move (conseq_if_expr)) {} // outer attributes not allowed @@ -4318,8 +3573,6 @@ public: : IfExpr (other), conseq_if_expr (other.conseq_if_expr->clone_if_expr ()) {} - // Destructor - define here if required - // Overloaded assignment operator to use clone IfExprConseqIf &operator= (IfExprConseqIf const &other) { @@ -4335,7 +3588,7 @@ public: IfExprConseqIf (IfExprConseqIf &&other) = default; IfExprConseqIf &operator= (IfExprConseqIf &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; void vis_conseq_if_expr (ASTVisitor &vis) { @@ -4343,23 +3596,23 @@ public: } protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqIf *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqIf *clone_expr_impl () const override { return new IfExprConseqIf (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqIf *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqIf *clone_expr_with_block_impl () const override { return new IfExprConseqIf (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqIf *clone_if_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqIf *clone_if_expr_impl () const override { return new IfExprConseqIf (*this); } @@ -4369,29 +3622,21 @@ protected: class IfLetExpr : public ExprWithBlock { // MatchArmPatterns patterns; - ::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns; // inlined - /*Expr* value; - BlockExpr* if_block;*/ - ::std::unique_ptr<Expr> value; - ::std::unique_ptr<BlockExpr> if_block; - /*union { - BlockExpr else_block; - IfExpr if_expr; - IfLetExpr* if_let_expr; - } consequent_block;*/ + std::vector<std::unique_ptr<Pattern>> match_arm_patterns; // inlined + std::unique_ptr<Expr> value; + std::unique_ptr<BlockExpr> if_block; Location locus; public: - ::std::string as_string () const; - - 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)), - value (::std::move (value)), if_block (::std::move (if_block)), - locus (locus) + std::string as_string () const override; + + 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)), + value (std::move (value)), if_block (std::move (if_block)), locus (locus) {} // outer attributes not allowed on if let exprs either @@ -4402,18 +3647,11 @@ public: other.value->clone_expr ()), if_block (other.if_block->clone_block_expr ()), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? match_arm_patterns.reserve (other.match_arm_patterns.size ()); - for (const auto &e : other.match_arm_patterns) - { - match_arm_patterns.push_back (e->clone_pattern ()); - } + match_arm_patterns.push_back (e->clone_pattern ()); } - // destructor - define here if required - // overload assignment operator to clone IfLetExpr &operator= (IfLetExpr const &other) { @@ -4423,14 +3661,9 @@ public: if_block = other.if_block->clone_block_expr (); locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? match_arm_patterns.reserve (other.match_arm_patterns.size ()); - for (const auto &e : other.match_arm_patterns) - { - match_arm_patterns.push_back (e->clone_pattern ()); - } + match_arm_patterns.push_back (e->clone_pattern ()); return *this; } @@ -4440,28 +3673,24 @@ public: IfLetExpr &operator= (IfLetExpr &&other) = default; // Unique pointer custom clone function - ::std::unique_ptr<IfLetExpr> clone_if_let_expr () const + std::unique_ptr<IfLetExpr> clone_if_let_expr () const { - return ::std::unique_ptr<IfLetExpr> (clone_if_let_expr_impl ()); + return std::unique_ptr<IfLetExpr> (clone_if_let_expr_impl ()); } Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExpr *clone_expr_impl () const OVERRIDE - { - return new IfLetExpr (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExpr *clone_expr_impl () const override { return new IfLetExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExpr *clone_expr_with_block_impl () const override { return new IfLetExpr (*this); } @@ -4476,22 +3705,17 @@ protected: // If expression with an ending "else if let" expression AST node class IfExprConseqIfLet : public IfExpr { - // IfLetExpr* if_let_expr; - ::std::unique_ptr<IfLetExpr> if_let_expr; + std::unique_ptr<IfLetExpr> if_let_expr; public: - /*~IfExprIfConseqIfLet() { - delete if_let_expr; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - IfExprConseqIfLet (::std::unique_ptr<Expr> condition, - ::std::unique_ptr<BlockExpr> if_block, - ::std::unique_ptr<IfLetExpr> conseq_if_let_expr, + IfExprConseqIfLet (std::unique_ptr<Expr> condition, + std::unique_ptr<BlockExpr> if_block, + std::unique_ptr<IfLetExpr> conseq_if_let_expr, Location locus) - : IfExpr (::std::move (condition), ::std::move (if_block), locus), - if_let_expr (::std::move (conseq_if_let_expr)) + : IfExpr (std::move (condition), std::move (if_block), locus), + if_let_expr (std::move (conseq_if_let_expr)) {} // outer attributes not allowed @@ -4500,8 +3724,6 @@ public: : IfExpr (other), if_let_expr (other.if_let_expr->clone_if_let_expr ()) {} - // Destructor - define here if required - // Overloaded assignment operator to use clone IfExprConseqIfLet &operator= (IfExprConseqIfLet const &other) { @@ -4517,52 +3739,47 @@ public: IfExprConseqIfLet (IfExprConseqIfLet &&other) = default; IfExprConseqIfLet &operator= (IfExprConseqIfLet &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqIfLet *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqIfLet *clone_expr_impl () const override { return new IfExprConseqIfLet (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqIfLet *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqIfLet *clone_expr_with_block_impl () const override { return new IfExprConseqIfLet (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfExprConseqIfLet *clone_if_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfExprConseqIfLet *clone_if_expr_impl () const override { return new IfExprConseqIfLet (*this); } }; -// AST node representing "if let" expression with an "else" expression at the -// end +/* AST node representing "if let" expression with an "else" expression at the + * end */ class IfLetExprConseqElse : public IfLetExpr { - // BlockExpr* else_block; - ::std::unique_ptr<BlockExpr> else_block; + std::unique_ptr<BlockExpr> else_block; public: - /*~IfLetExprConseqElse() { - delete else_block; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; IfLetExprConseqElse ( - ::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns, - ::std::unique_ptr<Expr> value, ::std::unique_ptr<BlockExpr> if_block, - ::std::unique_ptr<BlockExpr> else_block, Location locus) - : IfLetExpr (::std::move (match_arm_patterns), ::std::move (value), - ::std::move (if_block), locus), - else_block (::std::move (else_block)) + std::vector<std::unique_ptr<Pattern>> match_arm_patterns, + std::unique_ptr<Expr> value, std::unique_ptr<BlockExpr> if_block, + std::unique_ptr<BlockExpr> else_block, Location locus) + : IfLetExpr (std::move (match_arm_patterns), std::move (value), + std::move (if_block), locus), + else_block (std::move (else_block)) {} // outer attributes not allowed @@ -4571,8 +3788,6 @@ public: : IfLetExpr (other), else_block (other.else_block->clone_block_expr ()) {} - // destructor - define here if required - // overload assignment operator to clone IfLetExprConseqElse &operator= (IfLetExprConseqElse const &other) { @@ -4590,52 +3805,47 @@ public: IfLetExprConseqElse (IfLetExprConseqElse &&other) = default; IfLetExprConseqElse &operator= (IfLetExprConseqElse &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqElse *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqElse *clone_expr_impl () const override { return new IfLetExprConseqElse (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqElse *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqElse *clone_expr_with_block_impl () const override { return new IfLetExprConseqElse (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqElse *clone_if_let_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqElse *clone_if_let_expr_impl () const override { return new IfLetExprConseqElse (*this); } }; -// AST node representing "if let" expression with an "else if" expression at the -// end +/* AST node representing "if let" expression with an "else if" expression at the + * end */ class IfLetExprConseqIf : public IfLetExpr { - // IfExpr* if_expr; - ::std::unique_ptr<IfExpr> if_expr; + std::unique_ptr<IfExpr> if_expr; public: - /*~IfLetExprConseqIf() { - delete if_expr; - }*/ - - ::std::string as_string () const; - - IfLetExprConseqIf ( - ::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns, - ::std::unique_ptr<Expr> value, ::std::unique_ptr<BlockExpr> if_block, - ::std::unique_ptr<IfExpr> if_expr, Location locus) - : IfLetExpr (::std::move (match_arm_patterns), ::std::move (value), - ::std::move (if_block), locus), - if_expr (::std::move (if_expr)) + std::string as_string () const override; + + IfLetExprConseqIf (std::vector<std::unique_ptr<Pattern>> match_arm_patterns, + std::unique_ptr<Expr> value, + std::unique_ptr<BlockExpr> if_block, + std::unique_ptr<IfExpr> if_expr, Location locus) + : IfLetExpr (std::move (match_arm_patterns), std::move (value), + std::move (if_block), locus), + if_expr (std::move (if_expr)) {} // again, outer attributes not allowed @@ -4644,8 +3854,6 @@ public: : IfLetExpr (other), if_expr (other.if_expr->clone_if_expr ()) {} - // destructor - define here if required - // overload assignment operator to clone IfLetExprConseqIf &operator= (IfLetExprConseqIf const &other) { @@ -4662,52 +3870,47 @@ public: IfLetExprConseqIf (IfLetExprConseqIf &&other) = default; IfLetExprConseqIf &operator= (IfLetExprConseqIf &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqIf *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqIf *clone_expr_impl () const override { return new IfLetExprConseqIf (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqIf *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqIf *clone_expr_with_block_impl () const override { return new IfLetExprConseqIf (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqIf *clone_if_let_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqIf *clone_if_let_expr_impl () const override { return new IfLetExprConseqIf (*this); } }; -// AST node representing "if let" expression with an "else if let" expression at -// the end +/* AST node representing "if let" expression with an "else if let" expression at + * the end */ class IfLetExprConseqIfLet : public IfLetExpr { - // IfLetExpr* if_let_expr; - ::std::unique_ptr<IfLetExpr> if_let_expr; + std::unique_ptr<IfLetExpr> if_let_expr; public: - /*~IfLetExprConseqIfLet() { - delete if_let_expr; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; IfLetExprConseqIfLet ( - ::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns, - ::std::unique_ptr<Expr> value, ::std::unique_ptr<BlockExpr> if_block, - ::std::unique_ptr<IfLetExpr> if_let_expr, Location locus) - : IfLetExpr (::std::move (match_arm_patterns), ::std::move (value), - ::std::move (if_block), locus), - if_let_expr (::std::move (if_let_expr)) + std::vector<std::unique_ptr<Pattern>> match_arm_patterns, + std::unique_ptr<Expr> value, std::unique_ptr<BlockExpr> if_block, + std::unique_ptr<IfLetExpr> if_let_expr, Location locus) + : IfLetExpr (std::move (match_arm_patterns), std::move (value), + std::move (if_block), locus), + if_let_expr (std::move (if_let_expr)) {} // outer attributes not allowed @@ -4716,8 +3919,6 @@ public: : IfLetExpr (other), if_let_expr (other.if_let_expr->clone_if_let_expr ()) {} - // destructor - define here if required - // overload assignment operator to clone IfLetExprConseqIfLet &operator= (IfLetExprConseqIfLet const &other) { @@ -4734,26 +3935,26 @@ public: IfLetExprConseqIfLet (IfLetExprConseqIfLet &&other) = default; IfLetExprConseqIfLet &operator= (IfLetExprConseqIfLet &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqIfLet *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqIfLet *clone_expr_impl () const override { return new IfLetExprConseqIfLet (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqIfLet *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqIfLet *clone_expr_with_block_impl () const override { return new IfLetExprConseqIfLet (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual IfLetExprConseqIfLet *clone_if_let_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IfLetExprConseqIfLet *clone_if_let_expr_impl () const override { return new IfLetExprConseqIfLet (*this); } @@ -4763,33 +3964,27 @@ protected: struct MatchArm { private: - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; // MatchArmPatterns patterns; - ::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns; // inlined + std::vector<std::unique_ptr<Pattern>> match_arm_patterns; // inlined // bool has_match_arm_guard; - // Expr* match_arm_guard; // inlined from MatchArmGuard - ::std::unique_ptr<Expr> guard_expr; + // inlined from MatchArmGuard + std::unique_ptr<Expr> guard_expr; // TODO: should this store location data? public: - /*~MatchArm() { - if (has_match_arm_guard) { - delete match_arm_guard; - } - }*/ - // Returns whether the MatchArm has a match arm guard expression - inline bool has_match_arm_guard () const { return guard_expr != NULL; } + bool has_match_arm_guard () const { return guard_expr != nullptr; } // Constructor for match arm with a guard expression - MatchArm (::std::vector< ::std::unique_ptr<Pattern> > match_arm_patterns, - ::std::unique_ptr<Expr> guard_expr = NULL, - ::std::vector<Attribute> outer_attrs = ::std::vector<Attribute> ()) - : outer_attrs (::std::move (outer_attrs)), - match_arm_patterns (::std::move (match_arm_patterns)), - guard_expr (::std::move (guard_expr)) + MatchArm (std::vector<std::unique_ptr<Pattern>> match_arm_patterns, + std::unique_ptr<Expr> guard_expr = nullptr, + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : outer_attrs (std::move (outer_attrs)), + match_arm_patterns (std::move (match_arm_patterns)), + guard_expr (std::move (guard_expr)) {} // Copy constructor with clone @@ -4798,30 +3993,12 @@ public: other.outer_attrs) { // guard to protect from null pointer dereference - if (other.guard_expr != NULL) - { - guard_expr = other.guard_expr->clone_expr (); - } - - // DEBUG - fprintf ( - stderr, - "started copy-constructing match arm (outer attrs, guard expr done)\n"); - - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? - match_arm_patterns.reserve (other.match_arm_patterns.size ()); + if (other.guard_expr != nullptr) + guard_expr = other.guard_expr->clone_expr (); + match_arm_patterns.reserve (other.match_arm_patterns.size ()); for (const auto &e : other.match_arm_patterns) - { - match_arm_patterns.push_back (e->clone_pattern ()); - - // DEBUG - fprintf (stderr, "successfully pushed back a match arm pattern\n"); - } - - // DEBUG - fprintf (stderr, "successfully copy-constructed match arm\n"); + match_arm_patterns.push_back (e->clone_pattern ()); } ~MatchArm () = default; @@ -4833,14 +4010,9 @@ public: outer_attrs = other.outer_attrs; guard_expr = other.guard_expr->clone_expr (); - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? match_arm_patterns.reserve (other.match_arm_patterns.size ()); - for (const auto &e : other.match_arm_patterns) - { - match_arm_patterns.push_back (e->clone_pattern ()); - } + match_arm_patterns.push_back (e->clone_pattern ()); return *this; } @@ -4850,15 +4022,15 @@ public: MatchArm &operator= (MatchArm &&other) = default; // Returns whether match arm is in an error state. - inline bool is_error () const { return match_arm_patterns.empty (); } + bool is_error () const { return match_arm_patterns.empty (); } // Creates a match arm in an error state. static MatchArm create_error () { - return MatchArm (::std::vector< ::std::unique_ptr<Pattern> > ()); + return MatchArm (std::vector<std::unique_ptr<Pattern>> ()); } - ::std::string as_string () const; + std::string as_string () const; }; // Base "match case" for a match expression - abstract @@ -4867,7 +4039,7 @@ class MatchCase MatchArm arm; protected: - MatchCase (MatchArm arm) : arm (::std::move (arm)) {} + MatchCase (MatchArm arm) : arm (std::move (arm)) {} // Should not require copy constructor or assignment operator overloading @@ -4878,15 +4050,12 @@ public: virtual ~MatchCase () {} // Unique pointer custom clone function - ::std::unique_ptr<MatchCase> clone_match_case () const + std::unique_ptr<MatchCase> clone_match_case () const { - // DEBUG - fprintf (stderr, "about to call clone match case impl\n"); - - return ::std::unique_ptr<MatchCase> (clone_match_case_impl ()); + return std::unique_ptr<MatchCase> (clone_match_case_impl ()); } - virtual ::std::string as_string () const; + virtual std::string as_string () const; virtual void accept_vis (ASTVisitor &vis) = 0; }; @@ -4894,29 +4063,19 @@ public: // Block expression match case class MatchCaseBlockExpr : public MatchCase { - // BlockExpr* block_expr; - ::std::unique_ptr<BlockExpr> block_expr; + std::unique_ptr<BlockExpr> block_expr; // TODO: should this store location data? public: - /*~MatchCaseBlockExpr() { - delete block_expr; - }*/ - - MatchCaseBlockExpr (MatchArm arm, ::std::unique_ptr<BlockExpr> block_expr) - : MatchCase (::std::move (arm)), block_expr (::std::move (block_expr)) + MatchCaseBlockExpr (MatchArm arm, std::unique_ptr<BlockExpr> block_expr) + : MatchCase (std::move (arm)), block_expr (std::move (block_expr)) {} // Copy constructor requires clone MatchCaseBlockExpr (MatchCaseBlockExpr const &other) : MatchCase (other), block_expr (other.block_expr->clone_block_expr ()) - { - // DEBUG - fprintf (stderr, "successfully copy constructed match case expr\n"); - } - - // Destructor - define here if required + {} // Overload assignment operator to have clone MatchCaseBlockExpr &operator= (MatchCaseBlockExpr const &other) @@ -4932,18 +4091,15 @@ public: MatchCaseBlockExpr (MatchCaseBlockExpr &&other) = default; MatchCaseBlockExpr &operator= (MatchCaseBlockExpr &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MatchCaseBlockExpr *clone_match_case_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MatchCaseBlockExpr *clone_match_case_impl () const override { - // DEBUG - fprintf (stderr, "about to copy construct match case block expr\n"); - return new MatchCaseBlockExpr (*this); } }; @@ -4951,29 +4107,19 @@ protected: // Expression (except block expression) match case class MatchCaseExpr : public MatchCase { - // Expr* expr; - ::std::unique_ptr<Expr> expr; + std::unique_ptr<Expr> expr; // TODO: should this store location data? public: - /*~MatchCaseExpr() { - delete expr; - }*/ - - MatchCaseExpr (MatchArm arm, ::std::unique_ptr<Expr> expr) - : MatchCase (::std::move (arm)), expr (::std::move (expr)) + MatchCaseExpr (MatchArm arm, std::unique_ptr<Expr> expr) + : MatchCase (std::move (arm)), expr (std::move (expr)) {} // Copy constructor requires clone MatchCaseExpr (MatchCaseExpr const &other) : MatchCase (other), expr (other.expr->clone_expr ()) - { - // DEBUG - fprintf (stderr, "successfully copy constructed match case expr\n"); - } - - // Destructor - define here if required + {} // Overload assignment operator to have clone MatchCaseExpr &operator= (MatchCaseExpr const &other) @@ -4989,24 +4135,15 @@ public: MatchCaseExpr (MatchCaseExpr &&other) = default; MatchCaseExpr &operator= (MatchCaseExpr &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MatchCaseExpr *clone_match_case_impl () const OVERRIDE - { - // DEBUG - fprintf (stderr, "about to copy construct match case expr\n"); - if (expr == NULL) - { - fprintf ( - stderr, - "warning: match case expr to be copy constructed has null expr!\n"); - } - + /* Use covariance to implement clone function as returning this object rather + * than base */ + MatchCaseExpr *clone_match_case_impl () const override + { return new MatchCaseExpr (*this); } }; @@ -5014,35 +4151,29 @@ protected: // Match expression AST node class MatchExpr : public ExprWithBlock { - // Expr* branch_value; - ::std::unique_ptr<Expr> branch_value; - ::std::vector<Attribute> inner_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<std::unique_ptr<MatchCase>> match_arms; // inlined from MatchArms Location locus; public: - /*~MatchExpr() { - delete branch_value; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; // Returns whether the match expression has any match arms. - inline 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<Attribute> inner_attrs, - ::std::vector<Attribute> outer_attrs, Location locus) - : ExprWithBlock (::std::move (outer_attrs)), - branch_value (::std::move (branch_value)), - inner_attrs (::std::move (inner_attrs)), - match_arms (::std::move (match_arms)), locus (locus) + 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<Attribute> inner_attrs, + std::vector<Attribute> outer_attrs, Location locus) + : ExprWithBlock (std::move (outer_attrs)), + branch_value (std::move (branch_value)), + inner_attrs (std::move (inner_attrs)), + match_arms (std::move (match_arms)), locus (locus) {} // Copy constructor requires clone due to unique_ptr @@ -5052,27 +4183,11 @@ public: other.branch_value->clone_expr ()), /*match_arms(other.match_arms),*/ inner_attrs (other.inner_attrs), locus (other.locus) { - fprintf (stderr, - "copy constructor for matchexpr called - only match arm vector " - "copying after this\n"); - - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? match_arms.reserve (other.match_arms.size ()); - - fprintf (stderr, "match expr: successfully reserved size\n"); - for (const auto &e : other.match_arms) - { - match_arms.push_back (e->clone_match_case ()); - fprintf (stderr, "match expr: successfully pushed back a match case\n"); - } - - fprintf (stderr, "match expr: successfully pushed back all match cases\n"); + match_arms.push_back (e->clone_match_case ()); } - // Destructor - define here if required - // Overloaded assignment operator to clone due to unique_ptr MatchExpr &operator= (MatchExpr const &other) { @@ -5083,14 +4198,9 @@ public: // outer_attrs = other.outer_attrs; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? match_arms.reserve (other.match_arms.size ()); - for (const auto &e : other.match_arms) - { - match_arms.push_back (e->clone_match_case ()); - } + match_arms.push_back (e->clone_match_case ()); return *this; } @@ -5100,22 +4210,18 @@ public: MatchExpr &operator= (MatchExpr &&other) = default; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MatchExpr *clone_expr_impl () const OVERRIDE - { - return new MatchExpr (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + MatchExpr *clone_expr_impl () const override { return new MatchExpr (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual MatchExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MatchExpr *clone_expr_with_block_impl () const override { return new MatchExpr (*this); } @@ -5124,16 +4230,16 @@ protected: // Await expression AST node (pseudo-member variable access) class AwaitExpr : public ExprWithoutBlock { - ::std::unique_ptr<Expr> awaited_expr; + std::unique_ptr<Expr> awaited_expr; Location locus; 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)), - awaited_expr (::std::move (awaited_expr)), locus (locus) + AwaitExpr (std::unique_ptr<Expr> awaited_expr, + std::vector<Attribute> outer_attrs, Location locus) + : ExprWithoutBlock (std::move (outer_attrs)), + awaited_expr (std::move (awaited_expr)), locus (locus) {} // copy constructor with clone @@ -5142,8 +4248,6 @@ public: awaited_expr (other.awaited_expr->clone_expr ()), locus (other.locus) {} - // destructor - define here if required - // overloaded assignment operator with clone AwaitExpr &operator= (AwaitExpr const &other) { @@ -5158,18 +4262,17 @@ public: AwaitExpr (AwaitExpr &&other) = default; AwaitExpr &operator= (AwaitExpr &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual AwaitExpr *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + AwaitExpr *clone_expr_without_block_impl () const override { return new AwaitExpr (*this); } @@ -5180,15 +4283,15 @@ class AsyncBlockExpr : public ExprWithBlock { // TODO: should this extend BlockExpr rather than be a composite of it? bool has_move; - ::std::unique_ptr<BlockExpr> block_expr; + std::unique_ptr<BlockExpr> block_expr; Location locus; 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), - block_expr (::std::move (block_expr)), locus (locus) + 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), + block_expr (std::move (block_expr)), locus (locus) {} // copy constructor with clone @@ -5197,8 +4300,6 @@ public: block_expr (other.block_expr->clone_block_expr ()), locus (other.locus) {} - // destructor - define if required - // overloaded assignment operator to clone AsyncBlockExpr &operator= (AsyncBlockExpr const &other) { @@ -5214,18 +4315,17 @@ public: AsyncBlockExpr (AsyncBlockExpr &&other) = default; AsyncBlockExpr &operator= (AsyncBlockExpr &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual AsyncBlockExpr *clone_expr_with_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + AsyncBlockExpr *clone_expr_with_block_impl () const override { return new AsyncBlockExpr (*this); } diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 07d9a6c..b5d9247 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -25,28 +25,22 @@ along with GCC; see the file COPYING3. If not see namespace Rust { namespace AST { // forward decls -// struct Lifetime; -// struct LifetimeBounds; -// struct TypeParamBounds; class BlockExpr; -// class Expr; -// class Type; class TypePath; -// class Pattern; class MacroInvocationSemi; // TODO: inline? /*struct AbiName { - ::std::string abi_name; + std::string abi_name; // Technically is meant to be STRING_LITERAL or RAW_STRING_LITERAL public: // Returns whether abi name is empty, i.e. doesn't exist. - inline bool is_empty() const { + bool is_empty() const { return abi_name.empty(); } - AbiName(::std::string name) : abi_name(::std::move(name)) {} + AbiName(std::string name) : abi_name(std::move(name)) {} // Empty AbiName constructor AbiName() {} @@ -56,67 +50,53 @@ class MacroInvocationSemi; class TypeParam : public GenericParam { // bool has_outer_attribute; - //::std::unique_ptr<Attribute> outer_attr; + // std::unique_ptr<Attribute> outer_attr; Attribute outer_attr; Identifier type_representation; // bool has_type_param_bounds; // TypeParamBounds type_param_bounds; - ::std::vector< ::std::unique_ptr<TypeParamBound> > + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds; // inlined form // bool has_type; - // Type type; - ::std::unique_ptr<Type> type; + std::unique_ptr<Type> type; Location locus; public: // Returns whether the type of the type param has been specified. - inline bool has_type () const { return type != NULL; } + bool has_type () const { return type != nullptr; } // Returns whether the type param has type param bounds. - inline bool has_type_param_bounds () const - { - return !type_param_bounds.empty (); - } + bool has_type_param_bounds () const { return !type_param_bounds.empty (); } // Returns whether the type param has an outer attribute. - inline bool has_outer_attribute () const { return !outer_attr.is_empty (); } - - TypeParam ( - Identifier type_representation, Location locus = Location (), - ::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds - = ::std::vector< ::std::unique_ptr<TypeParamBound> > (), - ::std::unique_ptr<Type> type = NULL, - Attribute outer_attr = Attribute::create_empty ()) - : outer_attr (::std::move (outer_attr)), - type_representation (::std::move (type_representation)), - type_param_bounds (::std::move (type_param_bounds)), - type (::std::move (type)), locus (locus) + bool has_outer_attribute () const { return !outer_attr.is_empty (); } + + TypeParam (Identifier type_representation, Location locus = Location (), + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds + = std::vector<std::unique_ptr<TypeParamBound>> (), + std::unique_ptr<Type> type = nullptr, + Attribute outer_attr = Attribute::create_empty ()) + : outer_attr (std::move (outer_attr)), + type_representation (std::move (type_representation)), + type_param_bounds (std::move (type_param_bounds)), + type (std::move (type)), locus (locus) {} // Copy constructor uses clone TypeParam (TypeParam const &other) : outer_attr (other.outer_attr), type_representation (other.type_representation), - /*type_param_bounds(other.type_param_bounds),*/ type ( - other.type->clone_type ()), - locus (other.locus) + type (other.type->clone_type ()), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); } - // Destructor - define here if required - // Overloaded assignment operator to clone TypeParam &operator= (TypeParam const &other) { @@ -126,14 +106,9 @@ public: outer_attr = other.outer_attr; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); return *this; } @@ -142,34 +117,34 @@ public: TypeParam (TypeParam &&other) = default; TypeParam &operator= (TypeParam &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual TypeParam *clone_generic_param_impl () const + TypeParam *clone_generic_param_impl () const override { return new TypeParam (*this); } }; -// "where" clause item base. Abstract - use LifetimeWhereClauseItem, -// TypeBoundWhereClauseItem +/* "where" clause item base. Abstract - use LifetimeWhereClauseItem, + * TypeBoundWhereClauseItem */ class WhereClauseItem { public: virtual ~WhereClauseItem () {} // Unique pointer custom clone function - ::std::unique_ptr<WhereClauseItem> clone_where_clause_item () const + std::unique_ptr<WhereClauseItem> clone_where_clause_item () const { - return ::std::unique_ptr<WhereClauseItem> (clone_where_clause_item_impl ()); + return std::unique_ptr<WhereClauseItem> (clone_where_clause_item_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -184,24 +159,24 @@ class LifetimeWhereClauseItem : public WhereClauseItem Lifetime lifetime; // LifetimeBounds lifetime_bounds; - ::std::vector<Lifetime> lifetime_bounds; // inlined lifetime bounds + std::vector<Lifetime> lifetime_bounds; // inlined lifetime bounds // should this store location info? public: LifetimeWhereClauseItem (Lifetime lifetime, - ::std::vector<Lifetime> lifetime_bounds) - : lifetime (::std::move (lifetime)), - lifetime_bounds (::std::move (lifetime_bounds)) + std::vector<Lifetime> lifetime_bounds) + : lifetime (std::move (lifetime)), + lifetime_bounds (std::move (lifetime_bounds)) {} - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual LifetimeWhereClauseItem *clone_where_clause_item_impl () const + LifetimeWhereClauseItem *clone_where_clause_item_impl () const override { return new LifetimeWhereClauseItem (*this); } @@ -212,70 +187,51 @@ class TypeBoundWhereClauseItem : public WhereClauseItem { // bool has_for_lifetimes; // LifetimeParams for_lifetimes; - ::std::vector<LifetimeParam> for_lifetimes; // inlined + std::vector<LifetimeParam> for_lifetimes; // inlined - // Type bound_type; - ::std::unique_ptr<Type> bound_type; + std::unique_ptr<Type> bound_type; // bool has_type_param_bounds; // TypeParamBounds type_param_bounds; - ::std::vector< ::std::unique_ptr<TypeParamBound> > + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds; // inlined form // should this store location info? public: // Returns whether the item has ForLifetimes - inline bool has_for_lifetimes () const { return !for_lifetimes.empty (); } + bool has_for_lifetimes () const { return !for_lifetimes.empty (); } // Returns whether the item has type param bounds - inline bool has_type_param_bounds () const - { - return !type_param_bounds.empty (); - } + bool has_type_param_bounds () const { return !type_param_bounds.empty (); } TypeBoundWhereClauseItem ( - ::std::vector<LifetimeParam> for_lifetimes, - ::std::unique_ptr<Type> bound_type, - ::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds) - : for_lifetimes (::std::move (for_lifetimes)), - bound_type (::std::move (bound_type)), - type_param_bounds (::std::move (type_param_bounds)) + std::vector<LifetimeParam> for_lifetimes, std::unique_ptr<Type> bound_type, + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds) + : for_lifetimes (std::move (for_lifetimes)), + bound_type (std::move (bound_type)), + type_param_bounds (std::move (type_param_bounds)) {} // Copy constructor requires clone TypeBoundWhereClauseItem (TypeBoundWhereClauseItem const &other) : for_lifetimes (other.for_lifetimes), - bound_type (other.bound_type->clone_type ()) /*, -type_param_bounds(other.type_param_bounds)*/ + bound_type (other.bound_type->clone_type ()) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); } - // Destructor - define here if required - // Overload assignment operator to clone TypeBoundWhereClauseItem &operator= (TypeBoundWhereClauseItem const &other) { for_lifetimes = other.for_lifetimes; bound_type = other.bound_type->clone_type (); - // type_param_bounds = other.type_param_bounds; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); return *this; } @@ -285,13 +241,13 @@ type_param_bounds(other.type_param_bounds)*/ TypeBoundWhereClauseItem &operator= (TypeBoundWhereClauseItem &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual TypeBoundWhereClauseItem *clone_where_clause_item_impl () const + TypeBoundWhereClauseItem *clone_where_clause_item_impl () const override { return new TypeBoundWhereClauseItem (*this); } @@ -301,41 +257,30 @@ protected: struct WhereClause { private: - //::std::vector<WhereClauseItem> where_clause_items; - ::std::vector< ::std::unique_ptr<WhereClauseItem> > where_clause_items; + std::vector<std::unique_ptr<WhereClauseItem>> where_clause_items; // should this store location info? public: WhereClause ( - ::std::vector< ::std::unique_ptr<WhereClauseItem> > where_clause_items) - : where_clause_items (::std::move (where_clause_items)) + std::vector<std::unique_ptr<WhereClauseItem>> where_clause_items) + : where_clause_items (std::move (where_clause_items)) {} // copy constructor with vector clone WhereClause (WhereClause const &other) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? where_clause_items.reserve (other.where_clause_items.size ()); - for (const auto &e : other.where_clause_items) - { - where_clause_items.push_back (e->clone_where_clause_item ()); - } + where_clause_items.push_back (e->clone_where_clause_item ()); } // overloaded assignment operator with vector clone WhereClause &operator= (WhereClause const &other) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? where_clause_items.reserve (other.where_clause_items.size ()); - for (const auto &e : other.where_clause_items) - { - where_clause_items.push_back (e->clone_where_clause_item ()); - } + where_clause_items.push_back (e->clone_where_clause_item ()); return *this; } @@ -347,13 +292,13 @@ public: // Creates a WhereClause with no items. static WhereClause create_empty () { - return WhereClause (::std::vector< ::std::unique_ptr<WhereClauseItem> > ()); + return WhereClause (std::vector<std::unique_ptr<WhereClauseItem>> ()); } // Returns whether the WhereClause has no items. - inline bool is_empty () const { return where_clause_items.empty (); } + bool is_empty () const { return where_clause_items.empty (); } - ::std::string as_string () const; + std::string as_string () const; }; // A self parameter in a method @@ -366,27 +311,26 @@ private: Lifetime lifetime; // bool has_type; // only possible if not ref - // Type type; - ::std::unique_ptr<Type> type; + std::unique_ptr<Type> type; Location locus; // Unrestricted constructor used for error state SelfParam (Lifetime lifetime, bool has_ref, bool is_mut, Type *type) - : has_ref (has_ref), is_mut (is_mut), lifetime (::std::move (lifetime)), + : has_ref (has_ref), is_mut (is_mut), lifetime (std::move (lifetime)), type (type) {} // this is ok as no outside classes can ever call this public: // Returns whether the self-param has a type field. - inline bool has_type () const { return type != NULL; } + bool has_type () const { return type != nullptr; } // Returns whether the self-param has a valid lifetime. - inline bool has_lifetime () const { return !lifetime.is_error (); } + bool has_lifetime () const { return !lifetime.is_error (); } // Returns whether the self-param is in an error state. - inline bool is_error () const + bool is_error () const { return has_type () && has_lifetime (); // not having either is not an error @@ -400,32 +344,37 @@ public: return SelfParam (Lifetime (Lifetime::STATIC), false, false, new QualifiedPathInType ( QualifiedPathInType::create_error ())); + /* FIXME: is there a reason why I didn't just create a null pointer? Is it + * due to error being having both a type and a lifetime? If it is, wouldn't + * something like "not has_ref and has lifetime" for error be better? */ } // Type-based self parameter (not ref, no lifetime) - SelfParam (::std::unique_ptr<Type> type, bool is_mut, Location locus) + SelfParam (std::unique_ptr<Type> type, bool is_mut, Location locus) : has_ref (false), is_mut (is_mut), lifetime (Lifetime::error ()), - type (::std::move (type)), locus (locus) + type (std::move (type)), locus (locus) {} // Lifetime-based self parameter (is ref, no type) SelfParam (Lifetime lifetime, bool is_mut, Location locus) - : /*type(NULL), */ has_ref (true), is_mut (is_mut), - lifetime (::std::move (lifetime)), locus (locus) + : has_ref (true), is_mut (is_mut), lifetime (std::move (lifetime)), + locus (locus) {} // Copy constructor requires clone SelfParam (SelfParam const &other) : has_ref (other.has_ref), is_mut (other.is_mut), lifetime (other.lifetime), - type (other.type->clone_type ()), locus (other.locus) - {} - - // Destructor - define here if required + locus (other.locus) + { + if (other.type != nullptr) + type = other.type->clone_type (); + } // Overload assignment operator to use clone SelfParam &operator= (SelfParam const &other) { - type = other.type->clone_type (); + if (other.type != nullptr) + type = other.type->clone_type (); is_mut = other.is_mut; has_ref = other.has_ref; lifetime = other.lifetime; @@ -438,7 +387,7 @@ public: SelfParam (SelfParam &&other) = default; SelfParam &operator= (SelfParam &&other) = default; - ::std::string as_string () const; + std::string as_string () const; Location get_locus () const { return locus; } }; @@ -447,8 +396,8 @@ public: struct FunctionQualifiers { public: - // Whether the function is neither const nor async, const only, or async - // only. + /* Whether the function is neither const nor async, const only, or async + * only. */ enum AsyncConstStatus { NONE, @@ -460,53 +409,40 @@ private: AsyncConstStatus const_status; bool has_unsafe; bool has_extern; - ::std::string extern_abi; // e.g. extern "C" fn() -> i32 {} + std::string extern_abi; // e.g. extern "C" fn() -> i32 {} // TODO: maybe ensure that extern_abi only exists if extern exists? // should this store location info? public: - // Constructor with no extern (and hence no extern abi) - FunctionQualifiers (AsyncConstStatus const_status, bool has_unsafe) - : const_status (const_status), has_unsafe (has_unsafe), has_extern (false), - extern_abi (::std::string ("")) - {} - - // Constructor with extern abi (and thus extern) FunctionQualifiers (AsyncConstStatus const_status, bool has_unsafe, - ::std::string extern_abi) - : const_status (const_status), has_unsafe (has_unsafe), has_extern (true), - extern_abi (::std::move (extern_abi)) - {} - - // Constructor with all possible options (DON'T HAVE EXTERN_ABI WITHOUT - // EXTERN!) - FunctionQualifiers (AsyncConstStatus const_status, bool has_unsafe, - bool has_extern, ::std::string extern_abi) + bool has_extern = false, + std::string extern_abi = std::string ()) : const_status (const_status), has_unsafe (has_unsafe), - has_extern (has_extern), extern_abi (::std::move (extern_abi)) - {} + has_extern (has_extern), extern_abi (std::move (extern_abi)) + { + if (!this->extern_abi.empty ()) + { + // having extern is required; not having it is an implementation error + gcc_assert (has_extern); + } + } - ::std::string as_string () const; + std::string as_string () const; }; -// Forward decl FunctionParams -// struct FunctionParams; - // A function parameter struct FunctionParam { public: - // Pattern* param_name; - ::std::unique_ptr<Pattern> param_name; - // Type type; - ::std::unique_ptr<Type> type; + std::unique_ptr<Pattern> param_name; + std::unique_ptr<Type> type; Location locus; - FunctionParam (::std::unique_ptr<Pattern> param_name, - ::std::unique_ptr<Type> param_type, Location locus) - : param_name (::std::move (param_name)), type (::std::move (param_type)), + FunctionParam (std::unique_ptr<Pattern> param_name, + std::unique_ptr<Type> param_type, Location locus) + : param_name (std::move (param_name)), type (std::move (param_type)), locus (locus) {} @@ -516,8 +452,6 @@ public: type (other.type->clone_type ()), locus (other.locus) {} - // Destructor - define here if required - // Overload assignment operator to use clone FunctionParam &operator= (FunctionParam const &other) { @@ -533,15 +467,15 @@ public: FunctionParam &operator= (FunctionParam &&other) = default; // Returns whether FunctionParam is in an invalid state. - inline bool is_error () const { return param_name == NULL || type == NULL; } + bool is_error () const { return param_name == nullptr || type == nullptr; } // Creates an error FunctionParam. static FunctionParam create_error () { - return FunctionParam (NULL, NULL, Location ()); + return FunctionParam (nullptr, nullptr, Location ()); } - ::std::string as_string () const; + std::string as_string () const; Location get_locus () const { return locus; } }; @@ -560,11 +494,8 @@ public: }; private: - // bool is_pub; - // if vis is public, one of these PublicVisType public_vis_type; - // Only assigned if public_vis_type is IN_PATH SimplePath in_path; @@ -573,18 +504,11 @@ private: public: // Creates a Visibility - TODO make constructor protected or private? Visibility (PublicVisType public_vis_type, SimplePath in_path) - : public_vis_type (public_vis_type), in_path (::std::move (in_path)) - { - if (public_vis_type != IN_PATH && !in_path.is_empty ()) - { - // error - invalid state - - // just ignore path if vis type is not that - } - } + : public_vis_type (public_vis_type), in_path (std::move (in_path)) + {} // Returns whether visibility is in an error state. - inline bool is_error () const + bool is_error () const { return public_vis_type == IN_PATH && in_path.is_empty (); } @@ -596,8 +520,8 @@ public: } // Unique pointer custom clone function - /*::std::unique_ptr<Visibility> clone_visibility() const { - return ::std::unique_ptr<Visibility>(clone_visibility_impl()); + /*std::unique_ptr<Visibility> clone_visibility() const { + return std::unique_ptr<Visibility>(clone_visibility_impl()); }*/ /* TODO: think of a way to only allow valid Visibility states - polymorphism @@ -631,10 +555,10 @@ public: // Creates a public visibility with a given path or whatever. static Visibility create_in_path (SimplePath in_path) { - return Visibility (IN_PATH, ::std::move (in_path)); + return Visibility (IN_PATH, std::move (in_path)); } - ::std::string as_string () const; + std::string as_string () const; protected: // Clone function implementation - not currently virtual but may be if @@ -649,7 +573,7 @@ protected: class Method : public InherentImplItem, public TraitImplItem { // moved from impl items for consistency - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; Visibility vis; FunctionQualifiers qualifiers; @@ -657,78 +581,73 @@ class Method : public InherentImplItem, public TraitImplItem // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined SelfParam self_param; // bool has_params; // FunctionParams function_params; - ::std::vector<FunctionParam> function_params; // inlined + std::vector<FunctionParam> function_params; // inlined // bool has_return_type; // FunctionReturnType return_type; - ::std::unique_ptr<Type> return_type; // inlined + std::unique_ptr<Type> return_type; // inlined // bool has_where_clause; WhereClause where_clause; - // BlockExpr* expr; - ::std::unique_ptr<BlockExpr> expr; + std::unique_ptr<BlockExpr> expr; Location locus; public: - /*~Method() { - delete expr; - }*/ - // Returns whether the method is in an error state. - inline bool is_error () const + bool is_error () const { - return expr == NULL || method_name.empty () || self_param.is_error (); + return expr == nullptr || method_name.empty () || self_param.is_error (); } // Creates an error state method. static Method create_error () { return Method ("", FunctionQualifiers (FunctionQualifiers::NONE, true), - ::std::vector< ::std::unique_ptr<GenericParam> > (), - SelfParam::create_error (), ::std::vector<FunctionParam> (), - NULL, WhereClause::create_empty (), NULL, - Visibility::create_error (), ::std::vector<Attribute> ()); + std::vector<std::unique_ptr<GenericParam>> (), + SelfParam::create_error (), std::vector<FunctionParam> (), + nullptr, WhereClause::create_empty (), nullptr, + Visibility::create_error (), std::vector<Attribute> ()); } // Returns whether the method has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether the method has parameters. - inline bool has_params () const { return !function_params.empty (); } + bool has_params () const { return !function_params.empty (); } // Returns whether the method has a return type (void otherwise). - inline bool has_return_type () const { return return_type != NULL; } + bool has_return_type () const { return return_type != nullptr; } // Returns whether the where clause exists (i.e. has items) - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } // Returns whether method has a non-default visibility. - inline bool has_visibility () const { return !vis.is_error (); } + bool has_visibility () const { return !vis.is_error (); } // Mega-constructor with all possible fields Method (Identifier method_name, FunctionQualifiers qualifiers, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - SelfParam self_param, ::std::vector<FunctionParam> function_params, - ::std::unique_ptr<Type> return_type, WhereClause where_clause, - ::std::unique_ptr<BlockExpr> function_body, Visibility vis, - ::std::vector<Attribute> outer_attrs, Location locus = Location ()) - : outer_attrs (::std::move (outer_attrs)), vis (::std::move (vis)), - qualifiers (::std::move (qualifiers)), - method_name (::std::move (method_name)), - generic_params (::std::move (generic_params)), - self_param (::std::move (self_param)), - function_params (::std::move (function_params)), - return_type (::std::move (return_type)), - where_clause (::std::move (where_clause)), - expr (::std::move (function_body)), locus (locus) + std::vector<std::unique_ptr<GenericParam>> generic_params, + SelfParam self_param, std::vector<FunctionParam> function_params, + std::unique_ptr<Type> return_type, WhereClause where_clause, + std::unique_ptr<BlockExpr> function_body, Visibility vis, + std::vector<Attribute> outer_attrs, Location locus = Location ()) + : outer_attrs (std::move (outer_attrs)), vis (std::move (vis)), + qualifiers (std::move (qualifiers)), + method_name (std::move (method_name)), + generic_params (std::move (generic_params)), + self_param (std::move (self_param)), + function_params (std::move (function_params)), + return_type (std::move (return_type)), + where_clause (std::move (where_clause)), expr (std::move (function_body)), + locus (locus) {} // TODO: add constructor with less fields @@ -737,24 +656,16 @@ public: Method (Method const &other) : outer_attrs (other.outer_attrs), vis (other.vis), qualifiers (other.qualifiers), method_name (other.method_name), - /*generic_params(other.generic_params),*/ self_param (other.self_param), - function_params (other.function_params), + self_param (other.self_param), function_params (other.function_params), return_type (other.return_type->clone_type ()), where_clause (other.where_clause), expr (other.expr->clone_block_expr ()), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } - //~Method() = default; - // Overloaded assignment operator to clone Method &operator= (Method const &other) { @@ -762,7 +673,6 @@ public: outer_attrs = other.outer_attrs; vis = other.vis; qualifiers = other.qualifiers; - // generic_params = other.generic_params; self_param = other.self_param; function_params = other.function_params; return_type = other.return_type->clone_type (); @@ -770,14 +680,9 @@ public: expr = other.expr->clone_block_expr (); locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -786,21 +691,21 @@ public: Method (Method &&other) = default; Method &operator= (Method &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual Method *clone_inherent_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + Method *clone_inherent_impl_item_impl () const override { return new Method (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - virtual Method *clone_trait_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + Method *clone_trait_impl_item_impl () const override { return new Method (*this); } @@ -814,16 +719,14 @@ class VisItem : public Item protected: // Visibility constructor VisItem (Visibility visibility, - ::std::vector<Attribute> outer_attrs = ::std::vector<Attribute> ()) - : Item (::std::move (outer_attrs)), visibility (::std::move (visibility)) + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : Item (std::move (outer_attrs)), visibility (std::move (visibility)) {} // Visibility copy constructor VisItem (VisItem const &other) : Item (other), visibility (other.visibility) {} - // Destructor - define here if required - // Overload assignment operator to clone VisItem &operator= (VisItem const &other) { @@ -839,30 +742,29 @@ protected: VisItem &operator= (VisItem &&other) = default; public: - // Does the item have some kind of public visibility (non-default - // visibility)? - inline bool has_visibility () const { return !visibility.is_error (); } + /* Does the item have some kind of public visibility (non-default + * visibility)? */ + bool has_visibility () const { return !visibility.is_error (); } - virtual ::std::string as_string () const; + std::string as_string () const override; }; // Rust module item - abstract base class class Module : public VisItem { Identifier module_name; - Location locus; protected: // Protected constructor Module (Identifier module_name, Visibility visibility, Location locus, - ::std::vector<Attribute> outer_attrs = ::std::vector<Attribute> ()) - : VisItem (::std::move (visibility), ::std::move (outer_attrs)), + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : VisItem (std::move (visibility), std::move (outer_attrs)), module_name (module_name), locus (locus) {} public: - virtual ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } }; @@ -871,46 +773,38 @@ public: class ModuleBodied : public Module { // bool has_inner_attrs; - ::std::vector<Attribute> inner_attrs; + std::vector<Attribute> inner_attrs; // bool has_items; - //::std::vector<Item> items; - ::std::vector< ::std::unique_ptr<Item> > items; + std::vector<std::unique_ptr<Item>> items; public: - virtual ::std::string as_string () const; + std::string as_string () const override; // Returns whether the module has items in its body. - inline bool has_items () const { return !items.empty (); } + bool has_items () const { return !items.empty (); } // Returns whether the module has any inner attributes. - inline bool has_inner_attrs () const { return !inner_attrs.empty (); } + bool has_inner_attrs () const { return !inner_attrs.empty (); } // Full constructor ModuleBodied (Identifier name, Location locus, - ::std::vector< ::std::unique_ptr<Item> > items - = ::std::vector< ::std::unique_ptr<Item> > (), + std::vector<std::unique_ptr<Item>> items + = std::vector<std::unique_ptr<Item>> (), Visibility visibility = Visibility::create_error (), - ::std::vector<Attribute> inner_attrs - = ::std::vector<Attribute> (), - ::std::vector<Attribute> outer_attrs - = ::std::vector<Attribute> ()) - : Module (::std::move (name), ::std::move (visibility), locus, - ::std::move (outer_attrs)), - inner_attrs (::std::move (inner_attrs)), items (::std::move (items)) + std::vector<Attribute> inner_attrs = std::vector<Attribute> (), + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : Module (std::move (name), std::move (visibility), locus, + std::move (outer_attrs)), + inner_attrs (std::move (inner_attrs)), items (std::move (items)) {} // Copy constructor with vector clone ModuleBodied (ModuleBodied const &other) : Module (other), inner_attrs (other.inner_attrs) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? items.reserve (other.items.size ()); - for (const auto &e : other.items) - { - items.push_back (e->clone_item ()); - } + items.push_back (e->clone_item ()); } // Overloaded assignment operator with vector clone @@ -919,14 +813,9 @@ public: Module::operator= (other); inner_attrs = other.inner_attrs; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? items.reserve (other.items.size ()); - for (const auto &e : other.items) - { - items.push_back (e->clone_item ()); - } + items.push_back (e->clone_item ()); return *this; } @@ -935,24 +824,23 @@ public: ModuleBodied (ModuleBodied &&other) = default; ModuleBodied &operator= (ModuleBodied &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - // Override that runs the function recursively on all items contained within - // the module. - virtual void - add_crate_name (::std::vector< ::std::string> &names) const OVERRIDE; + /* Override that runs the function recursively on all items contained within + * the module. */ + void add_crate_name (std::vector<std::string> &names) const override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual ModuleBodied *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ModuleBodied *clone_item_impl () const override { return new ModuleBodied (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual ModuleBodied* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual ModuleBodied* clone_statement_impl() const override { return new ModuleBodied(*this); }*/ }; @@ -961,28 +849,28 @@ protected: class ModuleNoBody : public Module { public: - ::std::string as_string () const; + std::string as_string () const override; // Full constructor ModuleNoBody (Identifier name, Visibility visibility, - ::std::vector<Attribute> outer_attrs, Location locus) - : Module (::std::move (name), ::std::move (visibility), locus, - ::std::move (outer_attrs)) + std::vector<Attribute> outer_attrs, Location locus) + : Module (std::move (name), std::move (visibility), locus, + std::move (outer_attrs)) {} - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual ModuleNoBody *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ModuleNoBody *clone_item_impl () const override { return new ModuleNoBody (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual ModuleNoBody* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual ModuleNoBody* clone_statement_impl() const override { return new ModuleNoBody(*this); }*/ }; @@ -991,11 +879,11 @@ protected: class ExternCrate : public VisItem { // this is either an identifier or "self", with self parsed to string - ::std::string referenced_crate; + std::string referenced_crate; // bool has_as_clause; // AsClause as_clause; // this is either an identifier or "_", with _ parsed to string - ::std::string as_clause_name; + std::string as_clause_name; Location locus; @@ -1004,46 +892,45 @@ class ExternCrate : public VisItem "extern crate foo" "extern crate std as cool_std" */ public: - ::std::string as_string () const; + std::string as_string () const override; // Returns whether extern crate declaration has an as clause. - inline bool has_as_clause () const { return !as_clause_name.empty (); } + bool has_as_clause () const { return !as_clause_name.empty (); } - // Returns whether extern crate declaration references the current crate - // (i.e. self). - inline bool references_self () const { return referenced_crate == "self"; } + /* Returns whether extern crate declaration references the current crate + * (i.e. self). */ + bool references_self () const { return referenced_crate == "self"; } // Constructor - ExternCrate (::std::string referenced_crate, Visibility visibility, - ::std::vector<Attribute> outer_attrs, Location locus, - ::std::string as_clause_name = ::std::string ()) - : VisItem (::std::move (visibility), ::std::move (outer_attrs)), - referenced_crate (::std::move (referenced_crate)), - as_clause_name (::std::move (as_clause_name)), locus (locus) + ExternCrate (std::string referenced_crate, Visibility visibility, + std::vector<Attribute> outer_attrs, Location locus, + std::string as_clause_name = std::string ()) + : VisItem (std::move (visibility), std::move (outer_attrs)), + referenced_crate (std::move (referenced_crate)), + as_clause_name (std::move (as_clause_name)), locus (locus) {} Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; // Override that adds extern crate name in decl to passed list of names. - virtual void - add_crate_name (::std::vector< ::std::string> &names) const OVERRIDE + void add_crate_name (std::vector<std::string> &names) const override { names.push_back (referenced_crate); } protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual ExternCrate *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ExternCrate *clone_item_impl () const override { return new ExternCrate (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual ExternCrate* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual ExternCrate* clone_statement_impl() const override { return new ExternCrate(*this); }*/ }; @@ -1057,12 +944,12 @@ public: virtual ~UseTree () {} // Unique pointer custom clone function - ::std::unique_ptr<UseTree> clone_use_tree () const + std::unique_ptr<UseTree> clone_use_tree () const { - return ::std::unique_ptr<UseTree> (clone_use_tree_impl ()); + return std::unique_ptr<UseTree> (clone_use_tree_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; Location get_locus () const { return locus; } @@ -1092,23 +979,32 @@ private: public: UseTreeGlob (PathType glob_type, SimplePath path, Location locus) - : UseTree (locus), glob_type (glob_type), path (::std::move (path)) - {} + : UseTree (locus), glob_type (glob_type), path (std::move (path)) + { + if (this->glob_type != PATH_PREFIXED) + { + // compiler implementation error if there is a path with a + // non-path-prefixed use tree glob + gcc_assert (!has_path ()); + } + // TODO: do path-prefixed paths also have to have a path? If so, have an + // assert for that too. + } - // Returns whether has path. Should be made redundant by PathType - // PATH_PREFIXED. - inline bool has_path () const { return !path.is_empty (); } + /* Returns whether has path. Should be made redundant by PathType + * PATH_PREFIXED. */ + bool has_path () const { return !path.is_empty (); } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - // TODO: find way to ensure only PATH_PREFIXED glob_type has path - factory - // methods? + /* TODO: find way to ensure only PATH_PREFIXED glob_type has path - factory + * methods? */ protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual UseTreeGlob *clone_use_tree_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + UseTreeGlob *clone_use_tree_impl () const override { return new UseTreeGlob (*this); } @@ -1129,28 +1025,31 @@ private: PathType path_type; SimplePath path; - ::std::vector< ::std::unique_ptr<UseTree> > trees; + std::vector<std::unique_ptr<UseTree>> trees; public: UseTreeList (PathType path_type, SimplePath path, - ::std::vector< ::std::unique_ptr<UseTree> > trees, - Location locus) - : UseTree (locus), path_type (path_type), path (::std::move (path)), - trees (::std::move (trees)) - {} + std::vector<std::unique_ptr<UseTree>> trees, Location locus) + : UseTree (locus), path_type (path_type), path (std::move (path)), + trees (std::move (trees)) + { + if (this->path_type != PATH_PREFIXED) + { + // compiler implementation error if there is a path with a + // non-path-prefixed use tree glob + gcc_assert (!has_path ()); + } + // TODO: do path-prefixed paths also have to have a path? If so, have an + // assert for that too. + } // copy constructor with vector clone UseTreeList (UseTreeList const &other) : UseTree (other), path_type (other.path_type), path (other.path) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? trees.reserve (other.trees.size ()); - for (const auto &e : other.trees) - { - trees.push_back (e->clone_use_tree ()); - } + trees.push_back (e->clone_use_tree ()); } // overloaded assignment operator with vector clone @@ -1160,14 +1059,9 @@ public: path_type = other.path_type; path = other.path; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? trees.reserve (other.trees.size ()); - for (const auto &e : other.trees) - { - trees.push_back (e->clone_use_tree ()); - } + trees.push_back (e->clone_use_tree ()); return *this; } @@ -1177,21 +1071,21 @@ public: UseTreeList &operator= (UseTreeList &&other) = default; // Returns whether has path. Should be made redundant by path_type. - inline bool has_path () const { return !path.is_empty (); } + bool has_path () const { return !path.is_empty (); } // Returns whether has inner tree elements. - inline bool has_trees () const { return !trees.empty (); } + bool has_trees () const { return !trees.empty (); } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; // TODO: find way to ensure only PATH_PREFIXED path_type has path - factory // methods? protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual UseTreeList *clone_use_tree_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + UseTreeList *clone_use_tree_impl () const override { return new UseTreeList (*this); } @@ -1216,27 +1110,27 @@ private: public: UseTreeRebind (NewBindType bind_type, SimplePath path, Location locus, - Identifier identifier = ::std::string ()) - : UseTree (locus), path (::std::move (path)), bind_type (bind_type), - identifier (::std::move (identifier)) + Identifier identifier = std::string ()) + : UseTree (locus), path (std::move (path)), bind_type (bind_type), + identifier (std::move (identifier)) {} // Returns whether has path (this should always be true). - inline bool has_path () const { return !path.is_empty (); } + bool has_path () const { return !path.is_empty (); } // Returns whether has identifier (or, rather, is allowed to). - inline bool has_identifier () const { return bind_type == IDENTIFIER; } + bool has_identifier () const { return bind_type == IDENTIFIER; } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; // TODO: find way to ensure only PATH_PREFIXED path_type has path - factory // methods? protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual UseTreeRebind *clone_use_tree_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + virtual UseTreeRebind *clone_use_tree_impl () const override { return new UseTreeRebind (*this); } @@ -1245,17 +1139,16 @@ protected: // Rust use declaration (i.e. for modules) AST node class UseDeclaration : public VisItem { - ::std::unique_ptr<UseTree> use_tree; - + std::unique_ptr<UseTree> use_tree; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; - UseDeclaration (::std::unique_ptr<UseTree> use_tree, Visibility visibility, - ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (visibility), ::std::move (outer_attrs)), - use_tree (::std::move (use_tree)), locus (locus) + UseDeclaration (std::unique_ptr<UseTree> use_tree, Visibility visibility, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (visibility), std::move (outer_attrs)), + use_tree (std::move (use_tree)), locus (locus) {} // Copy constructor with clone @@ -1264,8 +1157,6 @@ public: locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone UseDeclaration &operator= (UseDeclaration const &other) { @@ -1284,26 +1175,26 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual UseDeclaration *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + UseDeclaration *clone_item_impl () const override { return new UseDeclaration (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual UseDeclaration* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual UseDeclaration* clone_statement_impl() const override { return new UseDeclaration(*this); }*/ }; // Parameters used in a function - TODO inline? /*struct FunctionParams { - ::std::vector<FunctionParam> function_params; + std::vector<FunctionParam> function_params; };*/ class LetStmt; @@ -1313,63 +1204,57 @@ class Function : public VisItem, public InherentImplItem, public TraitImplItem { public: FunctionQualifiers qualifiers; - Identifier function_name; // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined // bool has_function_params; // FunctionParams function_params; - ::std::vector<FunctionParam> function_params; // inlined + std::vector<FunctionParam> function_params; // inlined // bool has_function_return_type; - // Type return_type; - ::std::unique_ptr<Type> return_type; + std::unique_ptr<Type> return_type; // bool has_where_clause; WhereClause where_clause; - // BlockExpr* function_body; - ::std::unique_ptr<BlockExpr> function_body; + std::unique_ptr<BlockExpr> function_body; Location locus; - ::std::vector<LetStmt *> locals; + std::vector<LetStmt *> locals; - /*~Function() { - delete function_body; - }*/ - ::std::string as_string () const; + std::string as_string () const override; // Returns whether function has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether function has regular parameters. - inline bool has_function_params () const { return !function_params.empty (); } + bool has_function_params () const { return !function_params.empty (); } // Returns whether function has return type - if not, it is void. - inline bool has_function_return_type () const { return return_type != NULL; } + bool has_function_return_type () const { return return_type != nullptr; } // Returns whether function has a where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } // Mega-constructor with all possible fields Function (Identifier function_name, FunctionQualifiers qualifiers, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - ::std::vector<FunctionParam> function_params, - ::std::unique_ptr<Type> return_type, WhereClause where_clause, - ::std::unique_ptr<BlockExpr> function_body, Visibility vis, - ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - qualifiers (::std::move (qualifiers)), - function_name (::std::move (function_name)), - generic_params (::std::move (generic_params)), - function_params (::std::move (function_params)), - return_type (::std::move (return_type)), - where_clause (::std::move (where_clause)), - function_body (::std::move (function_body)), locus (locus) + std::vector<std::unique_ptr<GenericParam>> generic_params, + std::vector<FunctionParam> function_params, + std::unique_ptr<Type> return_type, WhereClause where_clause, + std::unique_ptr<BlockExpr> function_body, Visibility vis, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), + qualifiers (std::move (qualifiers)), + function_name (std::move (function_name)), + generic_params (std::move (generic_params)), + function_params (std::move (function_params)), + return_type (std::move (return_type)), + where_clause (std::move (where_clause)), + function_body (std::move (function_body)), locus (locus) {} // TODO: add constructor with less fields @@ -1378,25 +1263,17 @@ public: Function (Function const &other) : VisItem (other), qualifiers (other.qualifiers), function_name (other.function_name), - /*generic_params(other.generic_params),*/ function_params ( - other.function_params), + function_params (other.function_params), return_type (other.return_type->clone_type ()), where_clause (other.where_clause), function_body (other.function_body->clone_block_expr ()), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } - // Destructor - define here if required - // Overloaded assignment operator to clone Function &operator= (Function const &other) { @@ -1412,14 +1289,9 @@ public: // outer_attrs = other.outer_attrs; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -1430,33 +1302,30 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual Function *clone_item_impl () const OVERRIDE - { - return new Function (*this); - } + /* Use covariance to implement clone function as returning this object + * rather than base */ + Function *clone_item_impl () const override { return new Function (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - virtual Function *clone_inherent_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + Function *clone_inherent_impl_item_impl () const override { return new Function (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - virtual Function *clone_trait_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + Function *clone_trait_impl_item_impl () const override { return new Function (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual Function* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual Function* clone_statement_impl() const override { return new Function(*this); }*/ }; @@ -1468,58 +1337,47 @@ class TypeAlias : public VisItem, public TraitImplItem // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined // bool has_where_clause; WhereClause where_clause; - // Type exiting_type; - ::std::unique_ptr<Type> existing_type; + std::unique_ptr<Type> existing_type; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns whether type alias has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether type alias has a where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } // Mega-constructor with all possible fields TypeAlias (Identifier new_type_name, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - WhereClause where_clause, ::std::unique_ptr<Type> existing_type, - Visibility vis, ::std::vector<Attribute> outer_attrs, - Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - new_type_name (::std::move (new_type_name)), - generic_params (::std::move (generic_params)), - where_clause (::std::move (where_clause)), - existing_type (::std::move (existing_type)), locus (locus) + std::vector<std::unique_ptr<GenericParam>> generic_params, + WhereClause where_clause, std::unique_ptr<Type> existing_type, + Visibility vis, std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), + new_type_name (std::move (new_type_name)), + generic_params (std::move (generic_params)), + where_clause (std::move (where_clause)), + existing_type (std::move (existing_type)), locus (locus) {} // Copy constructor TypeAlias (TypeAlias const &other) - : VisItem (other), - new_type_name ( - other.new_type_name), /*generic_params(other.generic_params),*/ + : VisItem (other), new_type_name (other.new_type_name), where_clause (other.where_clause), existing_type (other.existing_type->clone_type ()), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } - // Destructor - define here if required - // Overloaded assignment operator to clone TypeAlias &operator= (TypeAlias const &other) { @@ -1532,14 +1390,9 @@ public: // outer_attrs = other.outer_attrs; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -1550,26 +1403,23 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual TypeAlias *clone_item_impl () const OVERRIDE - { - return new TypeAlias (*this); - } + /* Use covariance to implement clone function as returning this object + * rather than base */ + TypeAlias *clone_item_impl () const override { return new TypeAlias (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - virtual TypeAlias *clone_trait_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + TypeAlias *clone_trait_impl_item_impl () const override { return new TypeAlias (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual TypeAlias* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual TypeAlias* clone_statement_impl() const override { return new TypeAlias(*this); }*/ }; @@ -1583,7 +1433,7 @@ public: // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined // bool has_where_clause; WhereClause where_clause; @@ -1591,22 +1441,22 @@ public: Location locus; // Returns whether struct has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether struct has a where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } Location get_locus () const { return locus; } protected: Struct (Identifier struct_name, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, + std::vector<std::unique_ptr<GenericParam>> generic_params, WhereClause where_clause, Visibility vis, Location locus, - ::std::vector<Attribute> outer_attrs = ::std::vector<Attribute> ()) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - struct_name (::std::move (struct_name)), - generic_params (::std::move (generic_params)), - where_clause (::std::move (where_clause)), locus (locus) + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : VisItem (std::move (vis), std::move (outer_attrs)), + struct_name (std::move (struct_name)), + generic_params (std::move (generic_params)), + where_clause (std::move (where_clause)), locus (locus) {} // Copy constructor with vector clone @@ -1614,14 +1464,9 @@ protected: : VisItem (other), struct_name (other.struct_name), where_clause (other.where_clause), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } // Overloaded assignment operator with vector clone @@ -1632,14 +1477,9 @@ protected: where_clause = other.where_clause; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -1654,30 +1494,27 @@ struct StructField { public: // bool has_outer_attributes; - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; // bool has_visibility; Visibility visibility; Identifier field_name; - // Type field_type; - ::std::unique_ptr<Type> field_type; + std::unique_ptr<Type> field_type; // should this store location info? // Returns whether struct field has any outer attributes. - inline bool has_outer_attributes () const { return !outer_attrs.empty (); } + bool has_outer_attributes () const { return !outer_attrs.empty (); } // Returns whether struct field has a non-private (non-default) visibility. - inline bool has_visibility () const { return !visibility.is_error (); } + bool has_visibility () const { return !visibility.is_error (); } - StructField (Identifier field_name, ::std::unique_ptr<Type> field_type, + StructField (Identifier field_name, std::unique_ptr<Type> field_type, Visibility vis, - ::std::vector<Attribute> outer_attrs - = ::std::vector<Attribute> ()) - : outer_attrs (::std::move (outer_attrs)), visibility (::std::move (vis)), - field_name (::std::move (field_name)), - field_type (::std::move (field_type)) + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)), + field_name (std::move (field_name)), field_type (std::move (field_type)) {} // Copy constructor @@ -1705,72 +1542,71 @@ public: StructField &operator= (StructField &&other) = default; // Returns whether struct field is in an error state. - inline bool is_error () const + bool is_error () const { - return field_name.empty () && field_type == NULL; + return field_name.empty () && field_type == nullptr; // this should really be an or since neither are allowed } // Creates an error state struct field. static StructField create_error () { - return StructField (::std::string (""), NULL, Visibility::create_error ()); + return StructField (std::string (""), nullptr, Visibility::create_error ()); } - ::std::string as_string () const; + std::string as_string () const; }; // Rust struct declaration with true struct type AST node class StructStruct : public Struct { public: - ::std::vector<StructField> fields; + std::vector<StructField> fields; bool is_unit; - ::std::string as_string () const; + std::string as_string () const override; // Mega-constructor with all possible fields - StructStruct (::std::vector<StructField> fields, Identifier struct_name, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, + StructStruct (std::vector<StructField> fields, Identifier struct_name, + std::vector<std::unique_ptr<GenericParam>> generic_params, WhereClause where_clause, bool is_unit, Visibility vis, - ::std::vector<Attribute> outer_attrs, Location locus) - : Struct (::std::move (struct_name), ::std::move (generic_params), - ::std::move (where_clause), ::std::move (vis), locus, - ::std::move (outer_attrs)), - fields (::std::move (fields)), is_unit (is_unit) + std::vector<Attribute> outer_attrs, Location locus) + : Struct (std::move (struct_name), std::move (generic_params), + std::move (where_clause), std::move (vis), locus, + std::move (outer_attrs)), + fields (std::move (fields)), is_unit (is_unit) {} // Unit struct constructor StructStruct (Identifier struct_name, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, + std::vector<std::unique_ptr<GenericParam>> generic_params, WhereClause where_clause, Visibility vis, - ::std::vector<Attribute> outer_attrs, Location locus) - : Struct (::std::move (struct_name), ::std::move (generic_params), - ::std::move (where_clause), ::std::move (vis), locus, - ::std::move (outer_attrs)), + std::vector<Attribute> outer_attrs, Location locus) + : Struct (std::move (struct_name), std::move (generic_params), + std::move (where_clause), std::move (vis), locus, + std::move (outer_attrs)), is_unit (true) {} // TODO: can a unit struct have generic fields? assuming yes for now. /* Returns whether the struct is a unit struct - struct defined without - * fields. This is - * important because it also means an implicit constant of its type is - * defined. */ - inline bool is_unit_struct () const { return is_unit; } + * fields. This is important because it also means an implicit constant of its + * type is defined. */ + bool is_unit_struct () const { return is_unit; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual StructStruct *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + StructStruct *clone_item_impl () const override { return new StructStruct (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual StructStruct* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual StructStruct* clone_statement_impl() const override { return new StructStruct(*this); }*/ }; @@ -1780,30 +1616,28 @@ struct TupleField { private: // bool has_outer_attributes; - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; // bool has_visibility; Visibility visibility; - // Type field_type; - ::std::unique_ptr<Type> field_type; + std::unique_ptr<Type> field_type; // should this store location info? public: // Returns whether tuple field has outer attributes. - inline bool has_outer_attributes () const { return !outer_attrs.empty (); } + bool has_outer_attributes () const { return !outer_attrs.empty (); } - // Returns whether tuple field has a non-default visibility (i.e. a public - // one) - inline bool has_visibility () const { return !visibility.is_error (); } + /* Returns whether tuple field has a non-default visibility (i.e. a public + * one) */ + bool has_visibility () const { return !visibility.is_error (); } // Complete constructor - TupleField (::std::unique_ptr<Type> field_type, Visibility vis, - ::std::vector<Attribute> outer_attrs - = ::std::vector<Attribute> ()) - : outer_attrs (::std::move (outer_attrs)), visibility (::std::move (vis)), - field_type (::std::move (field_type)) + TupleField (std::unique_ptr<Type> field_type, Visibility vis, + std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) + : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)), + field_type (std::move (field_type)) {} // Copy constructor with clone @@ -1829,59 +1663,59 @@ public: TupleField &operator= (TupleField &&other) = default; // Returns whether tuple field is in an error state. - inline bool is_error () const { return field_type == NULL; } + bool is_error () const { return field_type == nullptr; } // Creates an error state tuple field. static TupleField create_error () { - return TupleField (NULL, Visibility::create_error ()); + return TupleField (nullptr, Visibility::create_error ()); } - ::std::string as_string () const; + std::string as_string () const; }; // Rust tuple declared using struct keyword AST node class TupleStruct : public Struct { - ::std::vector<TupleField> fields; + std::vector<TupleField> fields; public: - ::std::string as_string () const; + std::string as_string () const override; // Mega-constructor with all possible fields - TupleStruct (::std::vector<TupleField> fields, Identifier struct_name, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, + TupleStruct (std::vector<TupleField> fields, Identifier struct_name, + std::vector<std::unique_ptr<GenericParam>> generic_params, WhereClause where_clause, Visibility vis, - ::std::vector<Attribute> outer_attrs, Location locus) - : Struct (::std::move (struct_name), ::std::move (generic_params), - ::std::move (where_clause), ::std::move (vis), locus, - ::std::move (outer_attrs)), - fields (::std::move (fields)) + std::vector<Attribute> outer_attrs, Location locus) + : Struct (std::move (struct_name), std::move (generic_params), + std::move (where_clause), std::move (vis), locus, + std::move (outer_attrs)), + fields (std::move (fields)) {} - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual TupleStruct *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + TupleStruct *clone_item_impl () const override { return new TupleStruct (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual TupleStruct* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual TupleStruct* clone_statement_impl() const override { return new TupleStruct(*this); }*/ }; -// An item used in an "enum" tagged union - not abstract: base represents a -// name-only enum +/* An item used in an "enum" tagged union - not abstract: base represents a + * name-only enum */ class EnumItem { // bool has_attrs; - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; Identifier variant_name; @@ -1891,21 +1725,21 @@ public: virtual ~EnumItem () {} // Returns whether enum item has outer attributes. - inline bool has_outer_attrs () const { return !outer_attrs.empty (); } + bool has_outer_attrs () const { return !outer_attrs.empty (); } - EnumItem (Identifier variant_name, ::std::vector<Attribute> outer_attrs, + EnumItem (Identifier variant_name, std::vector<Attribute> outer_attrs, Location locus) - : outer_attrs (::std::move (outer_attrs)), - variant_name (::std::move (variant_name)), locus (locus) + : outer_attrs (std::move (outer_attrs)), + variant_name (std::move (variant_name)), locus (locus) {} // Unique pointer custom clone function - ::std::unique_ptr<EnumItem> clone_enum_item () const + std::unique_ptr<EnumItem> clone_enum_item () const { - return ::std::unique_ptr<EnumItem> (clone_enum_item_impl ()); + return std::unique_ptr<EnumItem> (clone_enum_item_impl ()); } - virtual ::std::string as_string () const; + virtual std::string as_string () const; // not pure virtual as not abstract virtual void accept_vis (ASTVisitor &vis); @@ -1922,26 +1756,25 @@ protected: class EnumItemTuple : public EnumItem { // bool has_tuple_fields; - ::std::vector<TupleField> tuple_fields; + std::vector<TupleField> tuple_fields; public: // Returns whether tuple enum item has tuple fields. - inline bool has_tuple_fields () const { return !tuple_fields.empty (); } + bool has_tuple_fields () const { return !tuple_fields.empty (); } - EnumItemTuple (Identifier variant_name, - ::std::vector<TupleField> tuple_fields, - ::std::vector<Attribute> outer_attrs, Location locus) - : EnumItem (::std::move (variant_name), ::std::move (outer_attrs), locus), - tuple_fields (::std::move (tuple_fields)) + EnumItemTuple (Identifier variant_name, std::vector<TupleField> tuple_fields, + std::vector<Attribute> outer_attrs, Location locus) + : EnumItem (std::move (variant_name), std::move (outer_attrs), locus), + tuple_fields (std::move (tuple_fields)) {} - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual EnumItemTuple *clone_enum_item_impl () const + EnumItemTuple *clone_enum_item_impl () const override { return new EnumItemTuple (*this); } @@ -1951,26 +1784,26 @@ protected: class EnumItemStruct : public EnumItem { // bool has_struct_fields; - ::std::vector<StructField> struct_fields; + std::vector<StructField> struct_fields; public: // Returns whether struct enum item has struct fields. - inline bool has_struct_fields () const { return !struct_fields.empty (); } + bool has_struct_fields () const { return !struct_fields.empty (); } EnumItemStruct (Identifier variant_name, - ::std::vector<StructField> struct_fields, - ::std::vector<Attribute> outer_attrs, Location locus) - : EnumItem (::std::move (variant_name), ::std::move (outer_attrs), locus), - struct_fields (::std::move (struct_fields)) + std::vector<StructField> struct_fields, + std::vector<Attribute> outer_attrs, Location locus) + : EnumItem (std::move (variant_name), std::move (outer_attrs), locus), + struct_fields (std::move (struct_fields)) {} - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual EnumItemStruct *clone_enum_item_impl () const + EnumItemStruct *clone_enum_item_impl () const override { return new EnumItemStruct (*this); } @@ -1979,18 +1812,13 @@ protected: // A discriminant (numbered enum) item used in an "enum" tagged union class EnumItemDiscriminant : public EnumItem { - // Expr* expression; - ::std::unique_ptr<Expr> expression; + std::unique_ptr<Expr> expression; public: - /*~EnumItemDiscriminant() { - delete expression; - }*/ - - EnumItemDiscriminant (Identifier variant_name, ::std::unique_ptr<Expr> expr, - ::std::vector<Attribute> outer_attrs, Location locus) - : EnumItem (::std::move (variant_name), ::std::move (outer_attrs), locus), - expression (::std::move (expr)) + EnumItemDiscriminant (Identifier variant_name, std::unique_ptr<Expr> expr, + std::vector<Attribute> outer_attrs, Location locus) + : EnumItem (std::move (variant_name), std::move (outer_attrs), locus), + expression (std::move (expr)) {} // Copy constructor with clone @@ -1998,8 +1826,6 @@ public: : EnumItem (other), expression (other.expression->clone_expr ()) {} - // Destructor - define here if required - // Overloaded assignment operator to clone EnumItemDiscriminant &operator= (EnumItemDiscriminant const &other) { @@ -2015,13 +1841,13 @@ public: EnumItemDiscriminant (EnumItemDiscriminant &&other) = default; EnumItemDiscriminant &operator= (EnumItemDiscriminant &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual EnumItemDiscriminant *clone_enum_item_impl () const + EnumItemDiscriminant *clone_enum_item_impl () const override { return new EnumItemDiscriminant (*this); } @@ -2034,38 +1860,37 @@ class Enum : public VisItem // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined // bool has_where_clause; WhereClause where_clause; - ::std::vector< ::std::unique_ptr<EnumItem> > items; + std::vector<std::unique_ptr<EnumItem>> items; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns whether "enum" has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether "enum" has a where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } /* Returns whether enum is a "zero-variant" (no possible variant) enum, - * which cannot be instantiated.*/ - inline bool is_zero_variant () const { return items.empty (); } + * which cannot be instantiated. */ + bool is_zero_variant () const { return items.empty (); } // Mega-constructor Enum (Identifier enum_name, Visibility vis, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - WhereClause where_clause, - ::std::vector< ::std::unique_ptr<EnumItem> > items, - ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - enum_name (::std::move (enum_name)), - generic_params (::std::move (generic_params)), - where_clause (::std::move (where_clause)), items (::std::move (items)), + std::vector<std::unique_ptr<GenericParam>> generic_params, + WhereClause where_clause, std::vector<std::unique_ptr<EnumItem>> items, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), + enum_name (std::move (enum_name)), + generic_params (std::move (generic_params)), + where_clause (std::move (where_clause)), items (std::move (items)), locus (locus) {} @@ -2076,23 +1901,13 @@ public: : VisItem (other), enum_name (other.enum_name), where_clause (other.where_clause), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? items.reserve (other.items.size ()); - for (const auto &e : other.items) - { - items.push_back (e->clone_enum_item ()); - } + items.push_back (e->clone_enum_item ()); } // Overloaded assignment operator with vector clone @@ -2103,23 +1918,13 @@ public: where_clause = other.where_clause; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? items.reserve (other.items.size ()); - for (const auto &e : other.items) - { - items.push_back (e->clone_enum_item ()); - } + items.push_back (e->clone_enum_item ()); return *this; } @@ -2130,16 +1935,16 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual Enum *clone_item_impl () const OVERRIDE { return new Enum (*this); } + /* Use covariance to implement clone function as returning this object + * rather than base */ + Enum *clone_item_impl () const override { return new Enum (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual Enum* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual Enum* clone_statement_impl() const override { return new Enum(*this); }*/ }; @@ -2151,33 +1956,33 @@ class Union : public VisItem // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined // bool has_where_clause; WhereClause where_clause; - ::std::vector<StructField> variants; + std::vector<StructField> variants; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns whether union has generic params. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether union has where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } Union (Identifier union_name, Visibility vis, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - WhereClause where_clause, ::std::vector<StructField> variants, - ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - union_name (::std::move (union_name)), - generic_params (::std::move (generic_params)), - where_clause (::std::move (where_clause)), - variants (::std::move (variants)), locus (locus) + std::vector<std::unique_ptr<GenericParam>> generic_params, + WhereClause where_clause, std::vector<StructField> variants, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), + union_name (std::move (union_name)), + generic_params (std::move (generic_params)), + where_clause (std::move (where_clause)), variants (std::move (variants)), + locus (locus) {} // copy constructor with vector clone @@ -2186,14 +1991,9 @@ public: where_clause (other.where_clause), variants (other.variants), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } // overloaded assignment operator with vector clone @@ -2205,14 +2005,9 @@ public: variants = other.variants; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -2223,22 +2018,22 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual Union *clone_item_impl () const OVERRIDE { return new Union (*this); } + /* Use covariance to implement clone function as returning this object + * rather than base */ + Union *clone_item_impl () const override { return new Union (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual Union* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual Union* clone_statement_impl() const override { return new Union(*this); }*/ }; -// "Constant item" AST node - used for constant, compile-time expressions -// within module scope +/* "Constant item" AST node - used for constant, compile-time expressions + * within module scope (like constexpr) */ class ConstantItem : public VisItem, public InherentImplItem, public TraitImplItem @@ -2248,27 +2043,20 @@ class ConstantItem : public VisItem, // if no identifier declared, identifier will be "_" Identifier identifier; - // Type type; - ::std::unique_ptr<Type> type; - - // Expr* const_expr; - ::std::unique_ptr<Expr> const_expr; + std::unique_ptr<Type> type; + std::unique_ptr<Expr> const_expr; Location locus; public: - /*~ConstantItem() { - delete const_expr; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - ConstantItem (Identifier ident, Visibility vis, ::std::unique_ptr<Type> type, - ::std::unique_ptr<Expr> const_expr, - ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - identifier (::std::move (ident)), type (::std::move (type)), - const_expr (::std::move (const_expr)), locus (locus) + ConstantItem (Identifier ident, Visibility vis, std::unique_ptr<Type> type, + std::unique_ptr<Expr> const_expr, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), + identifier (std::move (ident)), type (std::move (type)), + const_expr (std::move (const_expr)), locus (locus) {} ConstantItem (ConstantItem const &other) @@ -2277,8 +2065,6 @@ public: const_expr (other.const_expr->clone_expr ()), locus (other.locus) {} - // Destructor - define here if required - // Overload assignment operator to clone ConstantItem &operator= (ConstantItem const &other) { @@ -2297,70 +2083,60 @@ public: /* Returns whether constant item is an "unnamed" (wildcard underscore used * as identifier) constant. */ - inline bool is_unnamed () const { return identifier == ::std::string ("_"); } + bool is_unnamed () const { return identifier == std::string ("_"); } Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual ConstantItem *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ConstantItem *clone_item_impl () const override { return new ConstantItem (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - virtual ConstantItem *clone_inherent_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ConstantItem *clone_inherent_impl_item_impl () const override { return new ConstantItem (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - virtual ConstantItem *clone_trait_impl_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ConstantItem *clone_trait_impl_item_impl () const override { return new ConstantItem (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual ConstantItem* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual ConstantItem* clone_statement_impl() const override { return new ConstantItem(*this); }*/ }; -// Static item AST node - items within module scope with fixed storage -// duration? +/* Static item AST node - items within module scope with fixed storage + * duration? */ class StaticItem : public VisItem { bool has_mut; - Identifier name; - - // Type type; - ::std::unique_ptr<Type> type; - - // Expr* expr; - ::std::unique_ptr<Expr> expr; - + std::unique_ptr<Type> type; + std::unique_ptr<Expr> expr; Location locus; public: - /*~StaticItem() { - delete expr; - }*/ - - ::std::string as_string () const; + std::string as_string () const override; - StaticItem (Identifier name, bool is_mut, ::std::unique_ptr<Type> type, - ::std::unique_ptr<Expr> expr, Visibility vis, - ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), has_mut (is_mut), - name (::std::move (name)), type (::std::move (type)), - expr (::std::move (expr)), locus (locus) + StaticItem (Identifier name, bool is_mut, std::unique_ptr<Type> type, + std::unique_ptr<Expr> expr, Visibility vis, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), has_mut (is_mut), + name (std::move (name)), type (std::move (type)), expr (std::move (expr)), + locus (locus) {} // Copy constructor with clone @@ -2370,8 +2146,6 @@ public: locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone StaticItem &operator= (StaticItem const &other) { @@ -2391,19 +2165,19 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual StaticItem *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + StaticItem *clone_item_impl () const override { return new StaticItem (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual StaticItem* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual StaticItem* clone_statement_impl() const override { return new StaticItem(*this); }*/ }; @@ -2418,15 +2192,14 @@ private: // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined // bool has_params; // FunctionParams function_params; - ::std::vector<FunctionParam> function_params; // inlined + std::vector<FunctionParam> function_params; // inlined // bool has_return_type; - // Type return_type; - ::std::unique_ptr<Type> return_type; + std::unique_ptr<Type> return_type; // bool has_where_clause; WhereClause where_clause; @@ -2435,47 +2208,41 @@ private: public: // Returns whether function decl has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether function decl has regular parameters. - inline bool has_params () const { return !function_params.empty (); } + bool has_params () const { return !function_params.empty (); } // Returns whether function has return type (otherwise is void). - inline bool has_return_type () const { return return_type != NULL; } + bool has_return_type () const { return return_type != nullptr; } // Returns whether function has a where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } // Mega-constructor - TraitFunctionDecl ( - Identifier function_name, FunctionQualifiers qualifiers, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - ::std::vector<FunctionParam> function_params, - ::std::unique_ptr<Type> return_type, WhereClause where_clause) - : qualifiers (::std::move (qualifiers)), - function_name (::std::move (function_name)), - generic_params (::std::move (generic_params)), - function_params (::std::move (function_params)), - return_type (::std::move (return_type)), - where_clause (::std::move (where_clause)) + TraitFunctionDecl (Identifier function_name, FunctionQualifiers qualifiers, + std::vector<std::unique_ptr<GenericParam>> generic_params, + std::vector<FunctionParam> function_params, + std::unique_ptr<Type> return_type, + WhereClause where_clause) + : qualifiers (std::move (qualifiers)), + function_name (std::move (function_name)), + generic_params (std::move (generic_params)), + function_params (std::move (function_params)), + return_type (std::move (return_type)), + where_clause (std::move (where_clause)) {} // Copy constructor with clone TraitFunctionDecl (TraitFunctionDecl const &other) : qualifiers (other.qualifiers), function_name (other.function_name), - /*generic_params(other.generic_params),*/ function_params ( - other.function_params), + function_params (other.function_params), return_type (other.return_type->clone_type ()), where_clause (other.where_clause) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } ~TraitFunctionDecl () = default; @@ -2485,19 +2252,13 @@ public: { function_name = other.function_name; qualifiers = other.qualifiers; - // generic_params = other.generic_params; function_params = other.function_params; return_type = other.return_type->clone_type (); where_clause = other.where_clause; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -2506,48 +2267,35 @@ public: TraitFunctionDecl (TraitFunctionDecl &&other) = default; TraitFunctionDecl &operator= (TraitFunctionDecl &&other) = default; - ::std::string as_string () const; + std::string as_string () const; }; // Actual trait item function declaration within traits class TraitItemFunc : public TraitItem { - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; TraitFunctionDecl decl; - // BlockExpr* block_expr; - ::std::unique_ptr<BlockExpr> block_expr; - + std::unique_ptr<BlockExpr> block_expr; Location locus; public: - /*~TraitItemFunc() { - delete block_expr; - }*/ - // Returns whether function has a definition or is just a declaration. - inline bool has_definition () const { return block_expr != NULL; } + bool has_definition () const { return block_expr != nullptr; } - TraitItemFunc (TraitFunctionDecl decl, - ::std::unique_ptr<BlockExpr> block_expr, - ::std::vector<Attribute> outer_attrs, Location locus) - : outer_attrs (::std::move (outer_attrs)), decl (::std::move (decl)), - block_expr (::std::move (block_expr)), locus (locus) + TraitItemFunc (TraitFunctionDecl decl, std::unique_ptr<BlockExpr> block_expr, + std::vector<Attribute> outer_attrs, Location locus) + : outer_attrs (std::move (outer_attrs)), decl (std::move (decl)), + block_expr (std::move (block_expr)), locus (locus) {} // Copy constructor with clone TraitItemFunc (TraitItemFunc const &other) - : outer_attrs (other.outer_attrs), - decl (other.decl) /*, block_expr(other.block_expr->clone_block_expr())*/, - locus (other.locus) + : outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus) { - if (other.block_expr != NULL) - { - block_expr = other.block_expr->clone_block_expr (); - } + if (other.block_expr != nullptr) + block_expr = other.block_expr->clone_block_expr (); } - // Destructor - define here if required - // Overloaded assignment operator to clone TraitItemFunc &operator= (TraitItemFunc const &other) { @@ -2555,10 +2303,8 @@ public: outer_attrs = other.outer_attrs; decl = other.decl; locus = other.locus; - if (other.block_expr != NULL) - { - block_expr = other.block_expr->clone_block_expr (); - } + if (other.block_expr != nullptr) + block_expr = other.block_expr->clone_block_expr (); return *this; } @@ -2567,15 +2313,15 @@ public: TraitItemFunc (TraitItemFunc &&other) = default; TraitItemFunc &operator= (TraitItemFunc &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual TraitItemFunc *clone_trait_item_impl () const + TraitItemFunc *clone_trait_item_impl () const override { return new TraitItemFunc (*this); } @@ -2591,17 +2337,16 @@ private: // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined SelfParam self_param; // bool has_params; // FunctionParams function_params; - ::std::vector<FunctionParam> function_params; // inlined + std::vector<FunctionParam> function_params; // inlined // bool has_return_type; - // Type return_type; - ::std::unique_ptr<Type> return_type; + std::unique_ptr<Type> return_type; // bool has_where_clause; WhereClause where_clause; @@ -2610,48 +2355,42 @@ private: public: // Returns whether method decl has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether method decl has regular parameters. - inline bool has_params () const { return !function_params.empty (); } + bool has_params () const { return !function_params.empty (); } // Returns whether method has return type (otherwise is void). - inline bool has_return_type () const { return return_type != NULL; } + bool has_return_type () const { return return_type != nullptr; } // Returns whether method has a where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } // Mega-constructor - TraitMethodDecl ( - Identifier function_name, FunctionQualifiers qualifiers, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - SelfParam self_param, ::std::vector<FunctionParam> function_params, - ::std::unique_ptr<Type> return_type, WhereClause where_clause) - : qualifiers (::std::move (qualifiers)), - function_name (::std::move (function_name)), - generic_params (::std::move (generic_params)), - self_param (::std::move (self_param)), - function_params (::std::move (function_params)), - return_type (::std::move (return_type)), - where_clause (::std::move (where_clause)) + TraitMethodDecl (Identifier function_name, FunctionQualifiers qualifiers, + std::vector<std::unique_ptr<GenericParam>> generic_params, + SelfParam self_param, + std::vector<FunctionParam> function_params, + std::unique_ptr<Type> return_type, WhereClause where_clause) + : qualifiers (std::move (qualifiers)), + function_name (std::move (function_name)), + generic_params (std::move (generic_params)), + self_param (std::move (self_param)), + function_params (std::move (function_params)), + return_type (std::move (return_type)), + where_clause (std::move (where_clause)) {} // Copy constructor with clone TraitMethodDecl (TraitMethodDecl const &other) : qualifiers (other.qualifiers), function_name (other.function_name), - /*generic_params(other.generic_params),*/ self_param (other.self_param), - function_params (other.function_params), + self_param (other.self_param), function_params (other.function_params), return_type (other.return_type->clone_type ()), where_clause (other.where_clause) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } ~TraitMethodDecl () = default; @@ -2661,20 +2400,14 @@ public: { function_name = other.function_name; qualifiers = other.qualifiers; - // generic_params = other.generic_params; self_param = other.self_param; function_params = other.function_params; return_type = other.return_type->clone_type (); where_clause = other.where_clause; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -2683,32 +2416,25 @@ public: TraitMethodDecl (TraitMethodDecl &&other) = default; TraitMethodDecl &operator= (TraitMethodDecl &&other) = default; - ::std::string as_string () const; + std::string as_string () const; }; // Actual trait item method declaration within traits class TraitItemMethod : public TraitItem { - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; TraitMethodDecl decl; - // BlockExpr* block_expr; - ::std::unique_ptr<BlockExpr> block_expr; - + std::unique_ptr<BlockExpr> block_expr; Location locus; public: - /*~TraitItemMethod() { - delete block_expr; - }*/ - // Returns whether method has a definition or is just a declaration. - inline bool has_definition () const { return block_expr != NULL; } + bool has_definition () const { return block_expr != nullptr; } - TraitItemMethod (TraitMethodDecl decl, - ::std::unique_ptr<BlockExpr> block_expr, - ::std::vector<Attribute> outer_attrs, Location locus) - : outer_attrs (::std::move (outer_attrs)), decl (::std::move (decl)), - block_expr (::std::move (block_expr)), locus (locus) + TraitItemMethod (TraitMethodDecl decl, std::unique_ptr<BlockExpr> block_expr, + std::vector<Attribute> outer_attrs, Location locus) + : outer_attrs (std::move (outer_attrs)), decl (std::move (decl)), + block_expr (std::move (block_expr)), locus (locus) {} // Copy constructor with clone @@ -2717,8 +2443,6 @@ public: block_expr (other.block_expr->clone_block_expr ()), locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone TraitItemMethod &operator= (TraitItemMethod const &other) { @@ -2735,15 +2459,15 @@ public: TraitItemMethod (TraitItemMethod &&other) = default; TraitItemMethod &operator= (TraitItemMethod &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual TraitItemMethod *clone_trait_item_impl () const + TraitItemMethod *clone_trait_item_impl () const override { return new TraitItemMethod (*this); } @@ -2752,30 +2476,24 @@ protected: // Constant item within traits class TraitItemConst : public TraitItem { - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; Identifier name; - // Type type; - ::std::unique_ptr<Type> type; + std::unique_ptr<Type> type; // bool has_expression; - // Expr* expr; - ::std::unique_ptr<Expr> expr; + std::unique_ptr<Expr> expr; Location locus; public: - /*~TraitItemConst() { - delete expr; - }*/ - // Whether the constant item has an associated expression. - inline bool has_expression () const { return expr != NULL; } + bool has_expression () const { return expr != nullptr; } - TraitItemConst (Identifier name, ::std::unique_ptr<Type> type, - ::std::unique_ptr<Expr> expr, - ::std::vector<Attribute> outer_attrs, Location locus) - : outer_attrs (::std::move (outer_attrs)), name (::std::move (name)), - type (::std::move (type)), expr (::std::move (expr)), locus (locus) + TraitItemConst (Identifier name, std::unique_ptr<Type> type, + std::unique_ptr<Expr> expr, + std::vector<Attribute> outer_attrs, Location locus) + : outer_attrs (std::move (outer_attrs)), name (std::move (name)), + type (std::move (type)), expr (std::move (expr)), locus (locus) {} // Copy constructor with clones @@ -2785,8 +2503,6 @@ public: locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone TraitItemConst &operator= (TraitItemConst const &other) { @@ -2804,15 +2520,15 @@ public: TraitItemConst (TraitItemConst &&other) = default; TraitItemConst &operator= (TraitItemConst &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual TraitItemConst *clone_trait_item_impl () const + TraitItemConst *clone_trait_item_impl () const override { return new TraitItemConst (*this); } @@ -2821,44 +2537,36 @@ protected: // Type items within traits class TraitItemType : public TraitItem { - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; Identifier name; // bool has_type_param_bounds; // TypeParamBounds type_param_bounds; - ::std::vector< ::std::unique_ptr<TypeParamBound> > + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds; // inlined form Location locus; public: // Returns whether trait item type has type param bounds. - inline bool has_type_param_bounds () const - { - return !type_param_bounds.empty (); - } + bool has_type_param_bounds () const { return !type_param_bounds.empty (); } TraitItemType ( Identifier name, - ::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds, - ::std::vector<Attribute> outer_attrs, Location locus) - : outer_attrs (::std::move (outer_attrs)), name (::std::move (name)), - type_param_bounds (::std::move (type_param_bounds)), locus (locus) + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds, + std::vector<Attribute> outer_attrs, Location locus) + : outer_attrs (std::move (outer_attrs)), name (std::move (name)), + type_param_bounds (std::move (type_param_bounds)), locus (locus) {} // Copy constructor with vector clone TraitItemType (TraitItemType const &other) : outer_attrs (other.outer_attrs), name (other.name), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); } // Overloaded assignment operator with vector clone @@ -2869,14 +2577,9 @@ public: name = other.name; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); return *this; } @@ -2885,34 +2588,20 @@ public: TraitItemType (TraitItemType &&other) = default; TraitItemType &operator= (TraitItemType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Clone function implementation as (not pure) virtual method - virtual TraitItemType *clone_trait_item_impl () const + TraitItemType *clone_trait_item_impl () const override { return new TraitItemType (*this); } }; -// Macro invocation items within traits - TODO is this approach better or is -// making MacroInvocationSemi itself implement TraitItem better? Leaning -// toward latter. -/*class TraitItemMacroInvoc : public TraitItem { - MacroInvocationSemi macro_invoc; - - public: - TraitItemMacroInvoc( - MacroInvocationSemi macro_invoc, ::std::vector<Attribute> outer_attrs) : - macro_invoc(macro_invoc), - TraitItem(outer_attrs) {} -};*/ -// replaced with MacroInvocationSemi implementing TraitItem - // Rust trait item declaration AST node class Trait : public VisItem { @@ -2922,52 +2611,49 @@ class Trait : public VisItem // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined // bool has_type_param_bounds; // TypeParamBounds type_param_bounds; - ::std::vector< ::std::unique_ptr<TypeParamBound> > + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds; // inlined form // bool has_where_clause; WhereClause where_clause; // bool has_trait_items; - ::std::vector< ::std::unique_ptr<TraitItem> > trait_items; + std::vector<std::unique_ptr<TraitItem>> trait_items; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns whether trait has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether trait has type parameter bounds. - inline bool has_type_param_bounds () const - { - return !type_param_bounds.empty (); - } + bool has_type_param_bounds () const { return !type_param_bounds.empty (); } // Returns whether trait has where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } // Returns whether trait has trait items. - inline bool has_trait_items () const { return !trait_items.empty (); } + bool has_trait_items () const { return !trait_items.empty (); } // Mega-constructor Trait (Identifier name, bool is_unsafe, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - ::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds, + std::vector<std::unique_ptr<GenericParam>> generic_params, + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds, WhereClause where_clause, - ::std::vector< ::std::unique_ptr<TraitItem> > trait_items, - Visibility vis, ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - has_unsafe (is_unsafe), name (::std::move (name)), - generic_params (::std::move (generic_params)), - type_param_bounds (::std::move (type_param_bounds)), - where_clause (::std::move (where_clause)), - trait_items (::std::move (trait_items)), locus (locus) + std::vector<std::unique_ptr<TraitItem>> trait_items, Visibility vis, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), + has_unsafe (is_unsafe), name (std::move (name)), + generic_params (std::move (generic_params)), + type_param_bounds (std::move (type_param_bounds)), + where_clause (std::move (where_clause)), + trait_items (std::move (trait_items)), locus (locus) {} // Copy constructor with vector clone @@ -2975,30 +2661,17 @@ public: : VisItem (other), has_unsafe (other.has_unsafe), name (other.name), where_clause (other.where_clause), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); - // again for type param bounds type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); - // again for trait items trait_items.reserve (other.trait_items.size ()); - for (const auto &e : other.trait_items) - { - trait_items.push_back (e->clone_trait_item ()); - } + trait_items.push_back (e->clone_trait_item ()); } // Overloaded assignment operator with vector clone @@ -3010,30 +2683,17 @@ public: where_clause = other.where_clause; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); - // again for type param bounds type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); - // again for trait items trait_items.reserve (other.trait_items.size ()); - for (const auto &e : other.trait_items) - { - trait_items.push_back (e->clone_trait_item ()); - } + trait_items.push_back (e->clone_trait_item ()); return *this; } @@ -3044,16 +2704,16 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual Trait *clone_item_impl () const OVERRIDE { return new Trait (*this); } + /* Use covariance to implement clone function as returning this object + * rather than base */ + Trait *clone_item_impl () const override { return new Trait (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual Trait* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual Trait* clone_statement_impl() const override { return new Trait(*this); }*/ }; @@ -3065,16 +2725,15 @@ class Impl : public VisItem protected: // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined - // Type trait_type; - ::std::unique_ptr<Type> trait_type; + std::unique_ptr<Type> trait_type; // bool has_where_clause; WhereClause where_clause; // bool has_inner_attrs; - ::std::vector<Attribute> inner_attrs; + std::vector<Attribute> inner_attrs; private: // doesn't really need to be protected as write access probably not needed @@ -3082,67 +2741,52 @@ private: public: // Returns whether impl has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether impl has where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } // Returns whether impl has inner attributes. - inline bool has_inner_attrs () const { return !inner_attrs.empty (); } + bool has_inner_attrs () const { return !inner_attrs.empty (); } Location get_locus () const { return locus; } protected: // Mega-constructor - Impl (::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - ::std::unique_ptr<Type> trait_type, WhereClause where_clause, - Visibility vis, ::std::vector<Attribute> inner_attrs, - ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - generic_params (::std::move (generic_params)), - trait_type (::std::move (trait_type)), - where_clause (::std::move (where_clause)), - inner_attrs (::std::move (inner_attrs)), locus (locus) + Impl (std::vector<std::unique_ptr<GenericParam>> generic_params, + std::unique_ptr<Type> trait_type, WhereClause where_clause, + Visibility vis, std::vector<Attribute> inner_attrs, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), + generic_params (std::move (generic_params)), + trait_type (std::move (trait_type)), + where_clause (std::move (where_clause)), + inner_attrs (std::move (inner_attrs)), locus (locus) {} // Copy constructor Impl (Impl const &other) - : VisItem (other), - /*generic_params(other.generic_params),*/ trait_type ( - other.trait_type->clone_type ()), + : VisItem (other), trait_type (other.trait_type->clone_type ()), where_clause (other.where_clause), inner_attrs (other.inner_attrs), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } - // Destructor - define here if required - // Assignment operator overload with cloning Impl &operator= (Impl const &other) { VisItem::operator= (other); - // generic_params = other.generic_params; trait_type = other.trait_type->clone_type (); where_clause = other.where_clause; inner_attrs = other.inner_attrs; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -3156,37 +2800,32 @@ protected: class InherentImpl : public Impl { // bool has_impl_items; - ::std::vector< ::std::unique_ptr<InherentImplItem> > impl_items; + std::vector<std::unique_ptr<InherentImplItem>> impl_items; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns whether inherent impl block has inherent impl items. - inline bool has_impl_items () const { return !impl_items.empty (); } + bool has_impl_items () const { return !impl_items.empty (); } // Mega-constructor - InherentImpl (::std::vector< ::std::unique_ptr<InherentImplItem> > impl_items, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - ::std::unique_ptr<Type> trait_type, WhereClause where_clause, - Visibility vis, ::std::vector<Attribute> inner_attrs, - ::std::vector<Attribute> outer_attrs, Location locus) - : Impl (::std::move (generic_params), ::std::move (trait_type), - ::std::move (where_clause), ::std::move (vis), - ::std::move (inner_attrs), ::std::move (outer_attrs), locus), - impl_items (::std::move (impl_items)) + InherentImpl (std::vector<std::unique_ptr<InherentImplItem>> impl_items, + std::vector<std::unique_ptr<GenericParam>> generic_params, + std::unique_ptr<Type> trait_type, WhereClause where_clause, + Visibility vis, std::vector<Attribute> inner_attrs, + std::vector<Attribute> outer_attrs, Location locus) + : Impl (std::move (generic_params), std::move (trait_type), + std::move (where_clause), std::move (vis), std::move (inner_attrs), + std::move (outer_attrs), locus), + impl_items (std::move (impl_items)) {} // Copy constructor with vector clone InherentImpl (InherentImpl const &other) : Impl (other) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? impl_items.reserve (other.impl_items.size ()); - for (const auto &e : other.impl_items) - { - impl_items.push_back (e->clone_inherent_impl_item ()); - } + impl_items.push_back (e->clone_inherent_impl_item ()); } // Overloaded assignment operator with vector clone @@ -3194,14 +2833,9 @@ public: { Impl::operator= (other); - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? impl_items.reserve (other.impl_items.size ()); - for (const auto &e : other.impl_items) - { - impl_items.push_back (e->clone_inherent_impl_item ()); - } + impl_items.push_back (e->clone_inherent_impl_item ()); return *this; } @@ -3210,19 +2844,19 @@ public: InherentImpl (InherentImpl &&other) = default; InherentImpl &operator= (InherentImpl &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual InherentImpl *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + InherentImpl *clone_item_impl () const override { return new InherentImpl (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual InherentImpl* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual InherentImpl* clone_statement_impl() const override { return new InherentImpl(*this); }*/ }; @@ -3231,33 +2865,30 @@ protected: class TraitImpl : public Impl { bool has_unsafe; - bool has_exclam; - TypePath trait_path; // bool has_impl_items; - ::std::vector< ::std::unique_ptr<TraitImplItem> > impl_items; + std::vector<std::unique_ptr<TraitImplItem>> impl_items; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns whether trait impl has impl items. - inline bool has_impl_items () const { return !impl_items.empty (); } + bool has_impl_items () const { return !impl_items.empty (); } // Mega-constructor TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam, - ::std::vector< ::std::unique_ptr<TraitImplItem> > impl_items, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - ::std::unique_ptr<Type> trait_type, WhereClause where_clause, - Visibility vis, ::std::vector<Attribute> inner_attrs, - ::std::vector<Attribute> outer_attrs, Location locus) - : Impl (::std::move (generic_params), ::std::move (trait_type), - ::std::move (where_clause), ::std::move (vis), - ::std::move (inner_attrs), ::std::move (outer_attrs), locus), + std::vector<std::unique_ptr<TraitImplItem>> impl_items, + std::vector<std::unique_ptr<GenericParam>> generic_params, + std::unique_ptr<Type> trait_type, WhereClause where_clause, + Visibility vis, std::vector<Attribute> inner_attrs, + std::vector<Attribute> outer_attrs, Location locus) + : Impl (std::move (generic_params), std::move (trait_type), + std::move (where_clause), std::move (vis), std::move (inner_attrs), + std::move (outer_attrs), locus), has_unsafe (is_unsafe), has_exclam (has_exclam), - trait_path (::std::move (trait_path)), - impl_items (::std::move (impl_items)) + trait_path (std::move (trait_path)), impl_items (std::move (impl_items)) {} // TODO: constructors with less params @@ -3267,14 +2898,9 @@ public: : Impl (other), has_unsafe (other.has_unsafe), has_exclam (other.has_exclam), trait_path (other.trait_path) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? impl_items.reserve (other.impl_items.size ()); - for (const auto &e : other.impl_items) - { - impl_items.push_back (e->clone_trait_impl_item ()); - } + impl_items.push_back (e->clone_trait_impl_item ()); } // Overloaded assignment operator with vector clone @@ -3285,14 +2911,9 @@ public: has_unsafe = other.has_unsafe; has_exclam = other.has_exclam; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? impl_items.reserve (other.impl_items.size ()); - for (const auto &e : other.impl_items) - { - impl_items.push_back (e->clone_trait_impl_item ()); - } + impl_items.push_back (e->clone_trait_impl_item ()); return *this; } @@ -3301,19 +2922,16 @@ public: TraitImpl (TraitImpl &&other) = default; TraitImpl &operator= (TraitImpl &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual TraitImpl *clone_item_impl () const OVERRIDE - { - return new TraitImpl (*this); - } + /* Use covariance to implement clone function as returning this object + * rather than base */ + TraitImpl *clone_item_impl () const override { return new TraitImpl (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual TraitImpl* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual TraitImpl* clone_statement_impl() const override { return new TraitImpl(*this); }*/ }; @@ -3322,31 +2940,30 @@ protected: class ExternalItem { // bool has_outer_attrs; - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; // bool has_visibility; Visibility visibility; Identifier item_name; - Location locus; public: virtual ~ExternalItem () {} // Returns whether item has outer attributes. - inline bool has_outer_attrs () const { return !outer_attrs.empty (); } + bool has_outer_attrs () const { return !outer_attrs.empty (); } // Returns whether item has non-default visibility. - inline bool has_visibility () const { return !visibility.is_error (); } + bool has_visibility () const { return !visibility.is_error (); } // Unique pointer custom clone function - ::std::unique_ptr<ExternalItem> clone_external_item () const + std::unique_ptr<ExternalItem> clone_external_item () const { - return ::std::unique_ptr<ExternalItem> (clone_external_item_impl ()); + return std::unique_ptr<ExternalItem> (clone_external_item_impl ()); } - virtual ::std::string as_string () const; + virtual std::string as_string () const; Location get_locus () const { return locus; } @@ -3354,9 +2971,9 @@ public: protected: ExternalItem (Identifier item_name, Visibility vis, - ::std::vector<Attribute> outer_attrs, Location locus) - : outer_attrs (::std::move (outer_attrs)), visibility (::std::move (vis)), - item_name (::std::move (item_name)), locus (locus) + std::vector<Attribute> outer_attrs, Location locus) + : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)), + item_name (std::move (item_name)), locus (locus) {} // Copy constructor @@ -3384,24 +3001,22 @@ protected: virtual ExternalItem *clone_external_item_impl () const = 0; // possibly make this public if required - ::std::string get_item_name () const { return item_name; } + std::string get_item_name () const { return item_name; } }; // A static item used in an extern block class ExternalStaticItem : public ExternalItem { bool has_mut; - - // Type item_type; - ::std::unique_ptr<Type> item_type; + std::unique_ptr<Type> item_type; public: - ExternalStaticItem (Identifier item_name, ::std::unique_ptr<Type> item_type, + ExternalStaticItem (Identifier item_name, std::unique_ptr<Type> item_type, bool is_mut, Visibility vis, - ::std::vector<Attribute> outer_attrs, Location locus) - : ExternalItem (::std::move (item_name), ::std::move (vis), - ::std::move (outer_attrs), locus), - has_mut (is_mut), item_type (::std::move (item_type)) + std::vector<Attribute> outer_attrs, Location locus) + : ExternalItem (std::move (item_name), std::move (vis), + std::move (outer_attrs), locus), + has_mut (is_mut), item_type (std::move (item_type)) {} // Copy constructor @@ -3410,8 +3025,6 @@ public: item_type (other.item_type->clone_type ()) {} - // Destructor - define here if required - // Overloaded assignment operator to clone ExternalStaticItem &operator= (ExternalStaticItem const &other) { @@ -3426,14 +3039,14 @@ public: ExternalStaticItem (ExternalStaticItem &&other) = default; ExternalStaticItem &operator= (ExternalStaticItem &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual ExternalStaticItem *clone_external_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ExternalStaticItem *clone_external_item_impl () const override { return new ExternalStaticItem (*this); } @@ -3446,31 +3059,30 @@ private: // bool has_name; // otherwise is _ Identifier name; // TODO: handle wildcard in identifier? - // Type param_type; - ::std::unique_ptr<Type> param_type; + std::unique_ptr<Type> param_type; // TODO: should this store location data? public: // Returns whether the named function parameter has a name (i.e. name is not // '_'). - inline bool has_name () const { return name != "_"; } + bool has_name () const { return name != "_"; } // Returns whether the named function parameter is in an error state. - inline bool is_error () const + bool is_error () const { // also if identifier is "" but that is probably more costly to compute - return param_type == NULL; + return param_type == nullptr; } // Creates an error state named function parameter. static NamedFunctionParam create_error () { - return NamedFunctionParam ("", NULL); + return NamedFunctionParam ("", nullptr); } - NamedFunctionParam (Identifier name, ::std::unique_ptr<Type> param_type) - : name (::std::move (name)), param_type (::std::move (param_type)) + NamedFunctionParam (Identifier name, std::unique_ptr<Type> param_type) + : name (std::move (name)), param_type (std::move (param_type)) {} // Copy constructor @@ -3494,7 +3106,7 @@ public: NamedFunctionParam (NamedFunctionParam &&other) = default; NamedFunctionParam &operator= (NamedFunctionParam &&other) = default; - ::std::string as_string () const; + std::string as_string () const; }; // A function item used in an extern block @@ -3502,83 +3114,67 @@ class ExternalFunctionItem : public ExternalItem { // bool has_generics; // Generics generic_params; - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params; // inlined + std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined // bool has_return_type; // FunctionReturnType return_type; - ::std::unique_ptr<Type> return_type; // inlined + std::unique_ptr<Type> return_type; // inlined // bool has_where_clause; WhereClause where_clause; - ::std::vector<NamedFunctionParam> function_params; - + std::vector<NamedFunctionParam> function_params; bool has_variadics; public: // Returns whether item has generic parameters. - inline bool has_generics () const { return !generic_params.empty (); } + bool has_generics () const { return !generic_params.empty (); } // Returns whether item has a return type (otherwise void). - inline bool has_return_type () const { return return_type != NULL; } + bool has_return_type () const { return return_type != nullptr; } // Returns whether item has a where clause. - inline bool has_where_clause () const { return !where_clause.is_empty (); } + bool has_where_clause () const { return !where_clause.is_empty (); } ExternalFunctionItem ( Identifier item_name, - ::std::vector< ::std::unique_ptr<GenericParam> > generic_params, - ::std::unique_ptr<Type> return_type, WhereClause where_clause, - ::std::vector<NamedFunctionParam> function_params, bool has_variadics, - Visibility vis, ::std::vector<Attribute> outer_attrs, Location locus) - : ExternalItem (::std::move (item_name), ::std::move (vis), - ::std::move (outer_attrs), locus), - generic_params (::std::move (generic_params)), - return_type (::std::move (return_type)), - where_clause (::std::move (where_clause)), - function_params (::std::move (function_params)), + std::vector<std::unique_ptr<GenericParam>> generic_params, + std::unique_ptr<Type> return_type, WhereClause where_clause, + std::vector<NamedFunctionParam> function_params, bool has_variadics, + Visibility vis, std::vector<Attribute> outer_attrs, Location locus) + : ExternalItem (std::move (item_name), std::move (vis), + std::move (outer_attrs), locus), + generic_params (std::move (generic_params)), + return_type (std::move (return_type)), + where_clause (std::move (where_clause)), + function_params (std::move (function_params)), has_variadics (has_variadics) {} // Copy constructor with clone ExternalFunctionItem (ExternalFunctionItem const &other) - : ExternalItem (other), - /*generic_params(other.generic_params),*/ return_type ( - other.return_type->clone_type ()), + : ExternalItem (other), return_type (other.return_type->clone_type ()), where_clause (other.where_clause), function_params (other.function_params), has_variadics (other.has_variadics) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); } - // Destructor - define here if required - // Overloaded assignment operator with clone ExternalFunctionItem &operator= (ExternalFunctionItem const &other) { ExternalItem::operator= (other); - // generic_params = other.generic_params; return_type = other.return_type->clone_type (); where_clause = other.where_clause; function_params = other.function_params; has_variadics = other.has_variadics; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? generic_params.reserve (other.generic_params.size ()); - for (const auto &e : other.generic_params) - { - generic_params.push_back (e->clone_generic_param ()); - } + generic_params.push_back (e->clone_generic_param ()); return *this; } @@ -3587,14 +3183,14 @@ public: ExternalFunctionItem (ExternalFunctionItem &&other) = default; ExternalFunctionItem &operator= (ExternalFunctionItem &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual ExternalFunctionItem *clone_external_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ExternalFunctionItem *clone_external_item_impl () const override { return new ExternalFunctionItem (*this); } @@ -3604,35 +3200,35 @@ protected: class ExternBlock : public VisItem { // bool has_abi; - ::std::string abi; + std::string abi; // bool has_inner_attrs; - ::std::vector<Attribute> inner_attrs; + std::vector<Attribute> inner_attrs; // bool has_extern_items; - ::std::vector< ::std::unique_ptr<ExternalItem> > extern_items; + std::vector<std::unique_ptr<ExternalItem>> extern_items; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns whether extern block has inner attributes. - inline bool has_inner_attrs () const { return !inner_attrs.empty (); } + bool has_inner_attrs () const { return !inner_attrs.empty (); } // Returns whether extern block has extern items. - inline bool has_extern_items () const { return !extern_items.empty (); } + bool has_extern_items () const { return !extern_items.empty (); } // Returns whether extern block has ABI name. - inline bool has_abi () const { return !abi.empty (); } - - ExternBlock (::std::string abi, - ::std::vector< ::std::unique_ptr<ExternalItem> > extern_items, - Visibility vis, ::std::vector<Attribute> inner_attrs, - ::std::vector<Attribute> outer_attrs, Location locus) - : VisItem (::std::move (vis), ::std::move (outer_attrs)), - abi (::std::move (abi)), inner_attrs (::std::move (inner_attrs)), - extern_items (::std::move (extern_items)), locus (locus) + bool has_abi () const { return !abi.empty (); } + + ExternBlock (std::string abi, + std::vector<std::unique_ptr<ExternalItem>> extern_items, + Visibility vis, std::vector<Attribute> inner_attrs, + std::vector<Attribute> outer_attrs, Location locus) + : VisItem (std::move (vis), std::move (outer_attrs)), abi (std::move (abi)), + inner_attrs (std::move (inner_attrs)), + extern_items (std::move (extern_items)), locus (locus) {} // Copy constructor with vector clone @@ -3640,14 +3236,9 @@ public: : VisItem (other), abi (other.abi), inner_attrs (other.inner_attrs), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? extern_items.reserve (other.extern_items.size ()); - for (const auto &e : other.extern_items) - { - extern_items.push_back (e->clone_external_item ()); - } + extern_items.push_back (e->clone_external_item ()); } // Overloaded assignment operator with vector clone @@ -3658,14 +3249,9 @@ public: inner_attrs = other.inner_attrs; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of - // doing this? extern_items.reserve (other.extern_items.size ()); - for (const auto &e : other.extern_items) - { - extern_items.push_back (e->clone_external_item ()); - } + extern_items.push_back (e->clone_external_item ()); return *this; } @@ -3676,19 +3262,19 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object - // rather than base - virtual ExternBlock *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object + * rather than base */ + ExternBlock *clone_item_impl () const override { return new ExternBlock (*this); } - // Use covariance to implement clone function as returning this object - // rather than base - /*virtual ExternBlock* clone_statement_impl() const OVERRIDE { + /* Use covariance to implement clone function as returning this object + * rather than base */ + /*virtual ExternBlock* clone_statement_impl() const override { return new ExternBlock(*this); }*/ }; diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index fe5b5d8..6e34c3e 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -28,7 +28,7 @@ enum MacroFragSpec }; inline MacroFragSpec -get_frag_spec_from_str (::std::string str) +get_frag_spec_from_str (std::string str) { if (str == "block") return BLOCK; @@ -74,26 +74,26 @@ class MacroMatchFragment : public MacroMatch public: MacroMatchFragment (Identifier ident, MacroFragSpec frag_spec) - : ident (::std::move (ident)), frag_spec (frag_spec) + : ident (std::move (ident)), frag_spec (frag_spec) {} // Returns whether macro match fragment is in an error state. - inline bool is_error () const { return frag_spec == INVALID; } + bool is_error () const { return frag_spec == INVALID; } // Creates an error state macro match fragment. static MacroMatchFragment create_error () { - return MacroMatchFragment (::std::string (""), INVALID); + return MacroMatchFragment (std::string (""), INVALID); } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroMatchFragment *clone_macro_match_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroMatchFragment *clone_macro_match_impl () const override { return new MacroMatchFragment (*this); } @@ -112,57 +112,43 @@ public: }; private: - //::std::vector<MacroMatch> matches; - ::std::vector< ::std::unique_ptr<MacroMatch> > matches; + std::vector<std::unique_ptr<MacroMatch>> matches; MacroRepOp op; // bool has_sep; typedef Token MacroRepSep; // any token except delimiters and repetition operators - ::std::unique_ptr<MacroRepSep> sep; + std::unique_ptr<MacroRepSep> sep; // TODO: should store location information? public: // Returns whether macro match repetition has separator token. - inline bool has_sep () const { return sep != NULL; } + bool has_sep () const { return sep != NULL; } - MacroMatchRepetition (::std::vector< ::std::unique_ptr<MacroMatch> > matches, - MacroRepOp op, ::std::unique_ptr<MacroRepSep> sep) - : matches (::std::move (matches)), op (op), sep (::std::move (sep)) + MacroMatchRepetition (std::vector<std::unique_ptr<MacroMatch>> matches, + MacroRepOp op, std::unique_ptr<MacroRepSep> sep) + : matches (std::move (matches)), op (op), sep (std::move (sep)) {} // Copy constructor with clone MacroMatchRepetition (MacroMatchRepetition const &other) - : /*matches(other.matches),*/ op (other.op), sep (other.sep->clone_token ()) + : op (other.op), sep (other.sep->clone_token ()) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? matches.reserve (other.matches.size ()); - for (const auto &e : other.matches) - { - matches.push_back (e->clone_macro_match ()); - } + matches.push_back (e->clone_macro_match ()); } - // Destructor - define here if required - // Overloaded assignment operator to clone MacroMatchRepetition &operator= (MacroMatchRepetition const &other) { - // matches = other.matches; // TODO: this needs to clone somehow? op = other.op; sep = other.sep->clone_token (); - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? matches.reserve (other.matches.size ()); - for (const auto &e : other.matches) - { - matches.push_back (e->clone_macro_match ()); - } + matches.push_back (e->clone_macro_match ()); return *this; } @@ -171,14 +157,14 @@ public: MacroMatchRepetition (MacroMatchRepetition &&other) = default; MacroMatchRepetition &operator= (MacroMatchRepetition &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroMatchRepetition *clone_macro_match_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroMatchRepetition *clone_macro_match_impl () const override { return new MacroMatchRepetition (*this); } @@ -188,8 +174,7 @@ protected: class MacroMatcher : public MacroMatch { DelimType delim_type; - //::std::vector<MacroMatch> matches; - ::std::vector< ::std::unique_ptr<MacroMatch> > matches; + std::vector<std::unique_ptr<MacroMatch>> matches; // TODO: think of way to mark invalid that doesn't take up more space bool is_invalid; @@ -198,22 +183,16 @@ class MacroMatcher : public MacroMatch public: MacroMatcher (DelimType delim_type, - ::std::vector< ::std::unique_ptr<MacroMatch> > matches) - : delim_type (delim_type), matches (::std::move (matches)), - is_invalid (false) + std::vector<std::unique_ptr<MacroMatch>> matches) + : delim_type (delim_type), matches (std::move (matches)), is_invalid (false) {} // copy constructor with vector clone MacroMatcher (MacroMatcher const &other) : delim_type (other.delim_type) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? matches.reserve (other.matches.size ()); - for (const auto &e : other.matches) - { - matches.push_back (e->clone_macro_match ()); - } + matches.push_back (e->clone_macro_match ()); } // overloaded assignment operator with vector clone @@ -221,14 +200,9 @@ public: { delim_type = other.delim_type; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? matches.reserve (other.matches.size ()); - for (const auto &e : other.matches) - { - matches.push_back (e->clone_macro_match ()); - } + matches.push_back (e->clone_macro_match ()); return *this; } @@ -241,16 +215,16 @@ public: static MacroMatcher create_error () { return MacroMatcher (true); } // Returns whether MacroMatcher is in an error state. - inline bool is_error () const { return is_invalid; } + bool is_error () const { return is_invalid; } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroMatcher *clone_macro_match_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroMatcher *clone_macro_match_impl () const override { return new MacroMatcher (*this); } @@ -270,10 +244,10 @@ private: public: MacroTranscriber (DelimTokenTree token_tree) - : token_tree (::std::move (token_tree)) + : token_tree (std::move (token_tree)) {} - ::std::string as_string () const { return token_tree.as_string (); } + std::string as_string () const { return token_tree.as_string (); } }; // A macro rule? Matcher and transcriber pair? @@ -287,11 +261,11 @@ private: public: MacroRule (MacroMatcher matcher, MacroTranscriber transcriber) - : matcher (::std::move (matcher)), transcriber (::std::move (transcriber)) + : matcher (std::move (matcher)), transcriber (std::move (transcriber)) {} // Returns whether macro rule is in error state. - inline bool is_error () const { return matcher.is_error (); } + bool is_error () const { return matcher.is_error (); } // Creates an error state macro rule. static MacroRule create_error () @@ -300,7 +274,7 @@ public: MacroTranscriber (DelimTokenTree::create_empty ())); } - ::std::string as_string () const; + std::string as_string () const; }; // A macro rules definition item AST node @@ -311,90 +285,87 @@ class MacroRulesDefinition : public MacroItem // only curly without required semicolon at end DelimType delim_type; // MacroRules rules; - ::std::vector<MacroRule> rules; // inlined form + std::vector<MacroRule> rules; // inlined form Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; MacroRulesDefinition (Identifier rule_name, DelimType delim_type, - ::std::vector<MacroRule> rules, - ::std::vector<Attribute> outer_attrs, Location locus) - : MacroItem (::std::move (outer_attrs)), - rule_name (::std::move (rule_name)), delim_type (delim_type), - rules (::std::move (rules)), locus (locus) + std::vector<MacroRule> rules, + std::vector<Attribute> outer_attrs, Location locus) + : MacroItem (std::move (outer_attrs)), rule_name (std::move (rule_name)), + delim_type (delim_type), rules (std::move (rules)), locus (locus) {} - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroRulesDefinition *clone_item_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroRulesDefinition *clone_item_impl () const override { return new MacroRulesDefinition (*this); } }; -// AST node of a macro invocation, which is replaced by the macro result at -// compile time +/* AST node of a macro invocation, which is replaced by the macro result at + * compile time */ class MacroInvocation : public TypeNoBounds, public Pattern, public ExprWithoutBlock { SimplePath path; DelimTokenTree token_tree; - Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; MacroInvocation (SimplePath path, DelimTokenTree token_tree, - ::std::vector<Attribute> outer_attrs, Location locus) - : ExprWithoutBlock (::std::move (outer_attrs)), path (::std::move (path)), - token_tree (::std::move (token_tree)), locus (locus) + std::vector<Attribute> outer_attrs, Location locus) + : ExprWithoutBlock (std::move (outer_attrs)), path (std::move (path)), + token_tree (std::move (token_tree)), locus (locus) {} Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocation *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocation *clone_pattern_impl () const override { return new MacroInvocation (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocation *clone_expr_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocation *clone_expr_impl () const override { return new MacroInvocation (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocation *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocation *clone_expr_without_block_impl () const override { return new MacroInvocation (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocation *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocation *clone_type_impl () const override { return new MacroInvocation (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual MacroInvocation *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + MacroInvocation *clone_type_no_bounds_impl () const override { return new MacroInvocation (*this); } @@ -406,24 +377,24 @@ class MetaItemPath : public MetaItem SimplePath path; public: - MetaItemPath (SimplePath path) : path (::std::move (path)) {} + MetaItemPath (SimplePath path) : path (std::move (path)) {} - ::std::string as_string () const OVERRIDE { return path.as_string (); } + std::string as_string () const override { return path.as_string (); } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; // HACK: used to simplify parsing - returns non-empty only in this case - virtual SimplePath to_path_item () const OVERRIDE + SimplePath to_path_item () const override { // this should copy construct - TODO ensure it does return path; } - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; + bool check_cfg_predicate (const Session &session) const override; protected: // Use covariance to implement clone function as returning this type - virtual MetaItemPath *clone_meta_item_inner_impl () const OVERRIDE + MetaItemPath *clone_meta_item_inner_impl () const override { return new MetaItemPath (*this); } @@ -433,42 +404,31 @@ protected: class MetaItemSeq : public MetaItem { SimplePath path; - ::std::vector< ::std::unique_ptr<MetaItemInner> > seq; + std::vector<std::unique_ptr<MetaItemInner>> seq; public: MetaItemSeq (SimplePath path, - ::std::vector< ::std::unique_ptr<MetaItemInner> > seq) - : path (::std::move (path)), seq (::std::move (seq)) + std::vector<std::unique_ptr<MetaItemInner>> seq) + : path (std::move (path)), seq (std::move (seq)) {} // copy constructor with vector clone MetaItemSeq (const MetaItemSeq &other) : path (other.path) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? seq.reserve (other.seq.size ()); - for (const auto &e : other.seq) - { - seq.push_back (e->clone_meta_item_inner ()); - } + seq.push_back (e->clone_meta_item_inner ()); } - // destructor definition not required - // overloaded assignment operator with vector clone MetaItemSeq &operator= (const MetaItemSeq &other) { MetaItem::operator= (other); path = other.path; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? - seq.reserve (other.seq.size ()); + seq.reserve (other.seq.size ()); for (const auto &e : other.seq) - { - seq.push_back (e->clone_meta_item_inner ()); - } + seq.push_back (e->clone_meta_item_inner ()); return *this; } @@ -477,15 +437,15 @@ public: MetaItemSeq (MetaItemSeq &&other) = default; MetaItemSeq &operator= (MetaItemSeq &&other) = default; - ::std::string as_string () const OVERRIDE; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; + bool check_cfg_predicate (const Session &session) const override; protected: // Use covariance to implement clone function as returning this type - virtual MetaItemSeq *clone_meta_item_inner_impl () const OVERRIDE + MetaItemSeq *clone_meta_item_inner_impl () const override { return new MetaItemSeq (*this); } @@ -497,17 +457,17 @@ class MetaWord : public MetaItem Identifier ident; public: - MetaWord (Identifier ident) : ident (::std::move (ident)) {} + MetaWord (Identifier ident) : ident (std::move (ident)) {} - ::std::string as_string () const OVERRIDE { return ident; } + std::string as_string () const override { return ident; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; + bool check_cfg_predicate (const Session &session) const override; protected: // Use covariance to implement clone function as returning this type - virtual MetaWord *clone_meta_item_inner_impl () const OVERRIDE + MetaWord *clone_meta_item_inner_impl () const override { return new MetaWord (*this); } @@ -517,28 +477,28 @@ protected: class MetaNameValueStr : public MetaItem { Identifier ident; - ::std::string str; + std::string str; public: - MetaNameValueStr (Identifier ident, ::std::string str) - : ident (::std::move (ident)), str (::std::move (str)) + MetaNameValueStr (Identifier ident, std::string str) + : ident (std::move (ident)), str (std::move (str)) {} - ::std::string as_string () const OVERRIDE { return ident + " = " + str; } + std::string as_string () const override { return ident + " = " + str; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; // HACK: used to simplify parsing - creates a copy of this - virtual MetaNameValueStr *to_meta_name_value_str () const OVERRIDE + MetaNameValueStr *to_meta_name_value_str () const override { return clone_meta_item_inner_impl (); } - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; + bool check_cfg_predicate (const Session &session) const override; protected: // Use covariance to implement clone function as returning this type - virtual MetaNameValueStr *clone_meta_item_inner_impl () const OVERRIDE + MetaNameValueStr *clone_meta_item_inner_impl () const override { return new MetaNameValueStr (*this); } @@ -549,18 +509,18 @@ protected: class MetaListPaths : public MetaItem { Identifier ident; - ::std::vector<SimplePath> paths; + std::vector<SimplePath> paths; public: - MetaListPaths (Identifier ident, ::std::vector<SimplePath> paths) - : ident (::std::move (ident)), paths (::std::move (paths)) + MetaListPaths (Identifier ident, std::vector<SimplePath> paths) + : ident (std::move (ident)), paths (std::move (paths)) {} - ::std::string as_string () const OVERRIDE; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; + bool check_cfg_predicate (const Session &session) const override; private: bool check_path_exists_in_cfg (const Session &session, @@ -568,7 +528,7 @@ private: protected: // Use covariance to implement clone function as returning this type - virtual MetaListPaths *clone_meta_item_inner_impl () const OVERRIDE + MetaListPaths *clone_meta_item_inner_impl () const override { return new MetaListPaths (*this); } @@ -578,22 +538,22 @@ protected: class MetaListNameValueStr : public MetaItem { Identifier ident; - ::std::vector<MetaNameValueStr> strs; + std::vector<MetaNameValueStr> strs; public: - MetaListNameValueStr (Identifier ident, ::std::vector<MetaNameValueStr> strs) - : ident (::std::move (ident)), strs (::std::move (strs)) + MetaListNameValueStr (Identifier ident, std::vector<MetaNameValueStr> strs) + : ident (std::move (ident)), strs (std::move (strs)) {} - ::std::string as_string () const OVERRIDE; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - virtual bool check_cfg_predicate (const Session &session) const OVERRIDE; + bool check_cfg_predicate (const Session &session) const override; protected: // Use covariance to implement clone function as returning this type - virtual MetaListNameValueStr *clone_meta_item_inner_impl () const OVERRIDE + MetaListNameValueStr *clone_meta_item_inner_impl () const override { return new MetaListNameValueStr (*this); } @@ -603,26 +563,26 @@ protected: struct MacroParser { private: - ::std::vector< ::std::unique_ptr<Token> > token_stream; - // probably have to make this mutable (mutable int stream_pos) otherwise const - // has to be removed up to DelimTokenTree or further ok since this changing - // would have an effect on the results of the methods run (i.e. not logically - // const), the parsing methods shouldn't be const + std::vector<std::unique_ptr<Token>> token_stream; + /* probably have to make this mutable (mutable int stream_pos) otherwise const + * has to be removed up to DelimTokenTree or further ok since this changing + * would have an effect on the results of the methods run (i.e. not logically + * const), the parsing methods shouldn't be const */ int stream_pos; public: - MacroParser (::std::vector< ::std::unique_ptr<Token> > token_stream, + MacroParser (std::vector<std::unique_ptr<Token>> token_stream, int stream_start_pos = 0) - : token_stream (::std::move (token_stream)), stream_pos (stream_start_pos) + : token_stream (std::move (token_stream)), stream_pos (stream_start_pos) {} ~MacroParser () = default; - ::std::vector< ::std::unique_ptr<MetaItemInner> > parse_meta_item_seq (); + std::vector<std::unique_ptr<MetaItemInner>> parse_meta_item_seq (); private: // Parses a MetaItemInner. - ::std::unique_ptr<MetaItemInner> parse_meta_item_inner (); + std::unique_ptr<MetaItemInner> parse_meta_item_inner (); // Returns whether token can end a meta item. bool is_end_meta_item_tok (TokenId id) const; // Parses a simple path. @@ -630,14 +590,14 @@ private: // Parses a segment of a simple path (but not scope resolution operator). SimplePathSegment parse_simple_path_segment (); // Parses a MetaItemLitExpr. - ::std::unique_ptr<MetaItemLitExpr> parse_meta_item_lit (); + std::unique_ptr<MetaItemLitExpr> parse_meta_item_lit (); // Parses a literal. Literal parse_literal (); // Parses a meta item that begins with a simple path. - ::std::unique_ptr<MetaItem> parse_path_meta_item (); + std::unique_ptr<MetaItem> parse_path_meta_item (); // TODO: should this be const? - ::std::unique_ptr<Token> &peek_token (int i = 0) + std::unique_ptr<Token> &peek_token (int i = 0) { return token_stream[stream_pos + i]; } diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index 4c96e65..3006780 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -10,38 +10,33 @@ namespace Rust { namespace AST { -// make intellisense calm -/*typedef ::std::string Symbol; -typedef int Lifetime; -typedef int Type; -typedef int Binding;*/ // The "identifier" (not generic args) aspect of each path expression segment class PathIdentSegment { - ::std::string segment_name; + std::string segment_name; // TODO: should this have location info stored? // only allow identifiers, "super", "self", "Self", "crate", or "$crate" public: - PathIdentSegment (::std::string segment_name) - : segment_name (::std::move (segment_name)) + PathIdentSegment (std::string segment_name) + : segment_name (std::move (segment_name)) {} /* TODO: insert check in constructor for this? Or is this a semantic error * best handled then? */ - // TODO: does this require visitor. pretty sure this isn't polymorphic, but - // not entirely sure + /* TODO: does this require visitor? pretty sure this isn't polymorphic, but + * not entirely sure */ // Creates an error PathIdentSegment. static PathIdentSegment create_error () { return PathIdentSegment (""); } // Returns whether PathIdentSegment is in an error state. - inline bool is_error () const { return segment_name.empty (); } + bool is_error () const { return segment_name.empty (); } - ::std::string as_string () const { return segment_name; } + std::string as_string () const { return segment_name; } }; // A binding of an identifier to a type used in generic arguments in paths @@ -49,30 +44,28 @@ struct GenericArgsBinding { private: Identifier identifier; - // Type type; - ::std::unique_ptr<Type> type; + std::unique_ptr<Type> type; Location locus; public: // Returns whether binding is in an error state. - inline bool is_error () const + bool is_error () const { - return type - == NULL; // and also identifier is empty, but cheaper computation + return type == nullptr; + // and also identifier is empty, but cheaper computation } // Creates an error state generic args binding. static GenericArgsBinding create_error () { - return GenericArgsBinding ("", NULL); + return GenericArgsBinding ("", nullptr); } // Pointer type for type in constructor to enable polymorphism - GenericArgsBinding (Identifier ident, ::std::unique_ptr<Type> type_ptr, + GenericArgsBinding (Identifier ident, std::unique_ptr<Type> type_ptr, Location locus = Location ()) - : identifier (::std::move (ident)), type (::std::move (type_ptr)), - locus (locus) + : identifier (std::move (ident)), type (std::move (type_ptr)), locus (locus) {} // Copy constructor has to deep copy the type as it is a unique pointer @@ -97,34 +90,32 @@ public: GenericArgsBinding (GenericArgsBinding &&other) = default; GenericArgsBinding &operator= (GenericArgsBinding &&other) = default; - ::std::string as_string () const; + std::string as_string () const; }; // Generic arguments allowed in each path expression segment - inline? struct GenericArgs { - ::std::vector<Lifetime> lifetime_args; - //::std::vector<Type> type_args; - ::std::vector< ::std::unique_ptr<Type> > type_args; - ::std::vector<GenericArgsBinding> binding_args; - + std::vector<Lifetime> lifetime_args; + std::vector<std::unique_ptr<Type>> type_args; + std::vector<GenericArgsBinding> binding_args; Location locus; public: // Returns true if there are any generic arguments - inline bool has_generic_args () const + bool has_generic_args () const { return !(lifetime_args.empty () && type_args.empty () && binding_args.empty ()); } - GenericArgs (::std::vector<Lifetime> lifetime_args, - ::std::vector< ::std::unique_ptr<Type> > type_args, - ::std::vector<GenericArgsBinding> binding_args, + GenericArgs (std::vector<Lifetime> lifetime_args, + std::vector<std::unique_ptr<Type>> type_args, + std::vector<GenericArgsBinding> binding_args, Location locus = Location ()) - : lifetime_args (::std::move (lifetime_args)), - type_args (::std::move (type_args)), - binding_args (::std::move (binding_args)), locus (locus) + : lifetime_args (std::move (lifetime_args)), + type_args (std::move (type_args)), + binding_args (std::move (binding_args)), locus (locus) {} // copy constructor with vector clone @@ -132,14 +123,9 @@ public: : lifetime_args (other.lifetime_args), binding_args (other.binding_args), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? type_args.reserve (other.type_args.size ()); - for (const auto &e : other.type_args) - { - type_args.push_back (e->clone_type ()); - } + type_args.push_back (e->clone_type ()); } ~GenericArgs () = default; @@ -151,14 +137,9 @@ public: binding_args = other.binding_args; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? type_args.reserve (other.type_args.size ()); - for (const auto &e : other.type_args) - { - type_args.push_back (e->clone_type ()); - } + type_args.push_back (e->clone_type ()); return *this; } @@ -170,16 +151,16 @@ public: // Creates an empty GenericArgs (no arguments) static GenericArgs create_empty () { - return GenericArgs (::std::vector<Lifetime> (), - ::std::vector< ::std::unique_ptr<Type> > (), - ::std::vector<GenericArgsBinding> ()); + return GenericArgs (std::vector<Lifetime> (), + std::vector<std::unique_ptr<Type>> (), + std::vector<GenericArgsBinding> ()); } - ::std::string as_string () const; + std::string as_string () const; }; -// A segment of a path in expression, including an identifier aspect and maybe -// generic args +/* A segment of a path in expression, including an identifier aspect and maybe + * generic args */ class PathExprSegment { // or should this extend PathIdentSegment? private: @@ -194,36 +175,33 @@ private: public: // Returns true if there are any generic arguments - inline bool has_generic_args () const - { - return generic_args.has_generic_args (); - } + bool has_generic_args () const { return generic_args.has_generic_args (); } // Constructor for segment (from IdentSegment and GenericArgs) PathExprSegment (PathIdentSegment segment_name, Location locus = Location (), GenericArgs generic_args = GenericArgs::create_empty ()) - : segment_name (::std::move (segment_name)), - generic_args (::std::move (generic_args)), locus (locus) + : segment_name (std::move (segment_name)), + generic_args (std::move (generic_args)), locus (locus) {} - // Constructor for segment with generic arguments (from segment name and all - // args) - PathExprSegment (::std::string segment_name, Location locus, - ::std::vector<Lifetime> lifetime_args - = ::std::vector<Lifetime> (), - ::std::vector< ::std::unique_ptr<Type> > type_args - = ::std::vector< ::std::unique_ptr<Type> > (), - ::std::vector<GenericArgsBinding> binding_args - = ::std::vector<GenericArgsBinding> ()) - : segment_name (PathIdentSegment (::std::move (segment_name))), - generic_args (GenericArgs (::std::move (lifetime_args), - ::std::move (type_args), - ::std::move (binding_args))), + /* Constructor for segment with generic arguments (from segment name and all + * args) */ + PathExprSegment (std::string segment_name, Location locus, + std::vector<Lifetime> lifetime_args + = std::vector<Lifetime> (), + std::vector<std::unique_ptr<Type>> type_args + = std::vector<std::unique_ptr<Type>> (), + std::vector<GenericArgsBinding> binding_args + = std::vector<GenericArgsBinding> ()) + : segment_name (PathIdentSegment (std::move (segment_name))), + generic_args (GenericArgs (std::move (lifetime_args), + std::move (type_args), + std::move (binding_args))), locus (locus) {} // Returns whether path expression segment is in an error state. - inline bool is_error () const { return segment_name.is_error (); } + bool is_error () const { return segment_name.is_error (); } // Creates an error-state path expression segment. static PathExprSegment create_error () @@ -231,23 +209,23 @@ public: return PathExprSegment (PathIdentSegment::create_error ()); } - ::std::string as_string () const; + std::string as_string () const; - inline Location get_locus () const { return locus; } + Location get_locus () const { return locus; } }; // AST node representing a pattern that involves a "path" - abstract base class class PathPattern : public Pattern { - ::std::vector<PathExprSegment> segments; + std::vector<PathExprSegment> segments; protected: - PathPattern (::std::vector<PathExprSegment> segments) - : segments (::std::move (segments)) + PathPattern (std::vector<PathExprSegment> segments) + : segments (std::move (segments)) {} // Returns whether path has segments. - inline bool has_segments () const { return !segments.empty (); } + bool has_segments () const { return !segments.empty (); } /* Converts path segments to their equivalent SimplePath segments if possible, * and creates a SimplePath from them. */ @@ -256,45 +234,44 @@ protected: public: /* Returns whether the path is a single segment (excluding qualified path * initial as segment). */ - inline bool is_single_segment () const { return segments.size () == 1; } + bool is_single_segment () const { return segments.size () == 1; } - virtual ::std::string as_string () const; + std::string as_string () const override; }; -// AST node representing a path-in-expression pattern (path that allows generic -// arguments) +/* AST node representing a path-in-expression pattern (path that allows generic + * arguments) */ class PathInExpression : public PathPattern, public PathExpr { bool has_opening_scope_resolution; - Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Constructor - PathInExpression (::std::vector<PathExprSegment> path_segments, + PathInExpression (std::vector<PathExprSegment> path_segments, Location locus = Location (), bool has_opening_scope_resolution = false, - ::std::vector<Attribute> outer_attrs - = ::std::vector<Attribute> ()) - : PathPattern (::std::move (path_segments)), - PathExpr (::std::move (outer_attrs)), + std::vector<Attribute> outer_attrs + = std::vector<Attribute> ()) + : PathPattern (std::move (path_segments)), + PathExpr (std::move (outer_attrs)), has_opening_scope_resolution (has_opening_scope_resolution), locus (locus) {} // Creates an error state path in expression. static PathInExpression create_error () { - return PathInExpression (::std::vector<PathExprSegment> ()); + return PathInExpression (std::vector<PathExprSegment> ()); } // Returns whether path in expression is in an error state. - inline bool is_error () const { return !has_segments (); } + bool is_error () const { return !has_segments (); } /* Converts PathInExpression to SimplePath if possible (i.e. no generic * arguments). Otherwise returns an empty SimplePath. */ - inline SimplePath as_simple_path () const + SimplePath as_simple_path () const { /* delegate to parent class as can't access segments. however, * QualifiedPathInExpression conversion to simple path wouldn't make sense, @@ -305,29 +282,28 @@ public: } Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual PathInExpression *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + PathInExpression *clone_pattern_impl () const override { return new PathInExpression (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual PathInExpression *clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + PathInExpression *clone_expr_without_block_impl () const override { return new PathInExpression (*this); } }; -// Base class for segments used in type paths - not abstract (represents an -// ident-only segment) +/* Base class for segments used in type paths - not abstract (represents an + * ident-only segment) */ class TypePathSegment { /* TODO: may have to unify TypePathSegment and PathExprSegment (which are @@ -340,8 +316,8 @@ class TypePathSegment Location locus; protected: - // This is protected because it is only really used by derived classes, not - // the base. + /* This is protected because it is only really used by derived classes, not + * the base. */ bool has_separating_scope_resolution; // Clone function implementation - not pure virtual as overrided by subclasses @@ -354,38 +330,35 @@ public: virtual ~TypePathSegment () {} // Unique pointer custom clone function - ::std::unique_ptr<TypePathSegment> clone_type_path_segment () const + std::unique_ptr<TypePathSegment> clone_type_path_segment () const { - return ::std::unique_ptr<TypePathSegment> (clone_type_path_segment_impl ()); + return std::unique_ptr<TypePathSegment> (clone_type_path_segment_impl ()); } TypePathSegment (PathIdentSegment ident_segment, bool has_separating_scope_resolution, Location locus) - : ident_segment (::std::move (ident_segment)), locus (locus), + : ident_segment (std::move (ident_segment)), locus (locus), has_separating_scope_resolution (has_separating_scope_resolution) {} - TypePathSegment (::std::string segment_name, + TypePathSegment (std::string segment_name, bool has_separating_scope_resolution, Location locus) - : ident_segment (PathIdentSegment (::std::move (segment_name))), + : ident_segment (PathIdentSegment (std::move (segment_name))), locus (locus), has_separating_scope_resolution (has_separating_scope_resolution) {} - virtual ::std::string as_string () const - { - return ident_segment.as_string (); - } + virtual std::string as_string () const { return ident_segment.as_string (); } - // Returns whether the type path segment is in an error state. May be virtual - // in future. - inline bool is_error () const { return ident_segment.is_error (); } + /* Returns whether the type path segment is in an error state. May be virtual + * in future. */ + bool is_error () const { return ident_segment.is_error (); } /* Returns whether segment is identifier only (as opposed to generic args or - function). Overriden in derived classes with other segments. */ + * function). Overriden in derived classes with other segments. */ virtual bool is_ident_only () const { return true; } - inline Location get_locus () const { return locus; } + Location get_locus () const { return locus; } // not pure virtual as class not abstract virtual void accept_vis (ASTVisitor &vis); @@ -397,43 +370,40 @@ class TypePathSegmentGeneric : public TypePathSegment GenericArgs generic_args; public: - inline bool has_generic_args () const - { - return generic_args.has_generic_args (); - } + bool has_generic_args () const { return generic_args.has_generic_args (); } - bool is_ident_only () const { return false; } + bool is_ident_only () const override { return false; } // Constructor with PathIdentSegment and GenericArgs TypePathSegmentGeneric (PathIdentSegment ident_segment, bool has_separating_scope_resolution, GenericArgs generic_args, Location locus) - : TypePathSegment (::std::move (ident_segment), + : TypePathSegment (std::move (ident_segment), has_separating_scope_resolution, locus), - generic_args (::std::move (generic_args)) + generic_args (std::move (generic_args)) {} // Constructor from segment name and all args - TypePathSegmentGeneric (::std::string segment_name, + TypePathSegmentGeneric (std::string segment_name, bool has_separating_scope_resolution, - ::std::vector<Lifetime> lifetime_args, - ::std::vector< ::std::unique_ptr<Type> > type_args, - ::std::vector<GenericArgsBinding> binding_args, + std::vector<Lifetime> lifetime_args, + std::vector<std::unique_ptr<Type>> type_args, + std::vector<GenericArgsBinding> binding_args, Location locus) - : TypePathSegment (::std::move (segment_name), + : TypePathSegment (std::move (segment_name), has_separating_scope_resolution, locus), - generic_args (GenericArgs (::std::move (lifetime_args), - ::std::move (type_args), - ::std::move (binding_args))) + generic_args (GenericArgs (std::move (lifetime_args), + std::move (type_args), + std::move (binding_args))) {} - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Use covariance to override base class method - virtual TypePathSegmentGeneric *clone_type_path_segment_impl () const OVERRIDE + TypePathSegmentGeneric *clone_type_path_segment_impl () const override { return new TypePathSegmentGeneric (*this); } @@ -446,12 +416,11 @@ private: // TODO: remove /*bool has_inputs; TypePathFnInputs inputs;*/ - //::std::vector<Type> inputs; // inlined from TypePathFnInputs - ::std::vector< ::std::unique_ptr<Type> > inputs; + // inlined from TypePathFnInputs + std::vector<std::unique_ptr<Type>> inputs; // bool has_type; - // Type type; - ::std::unique_ptr<Type> return_type; + std::unique_ptr<Type> return_type; // FIXME: think of better way to mark as invalid than taking up storage bool is_invalid; @@ -464,44 +433,39 @@ protected: public: // Returns whether the return type of the function has been specified. - inline bool has_return_type () const { return return_type != NULL; } + bool has_return_type () const { return return_type != nullptr; } // Returns whether the function has inputs. - inline bool has_inputs () const { return !inputs.empty (); } + bool has_inputs () const { return !inputs.empty (); } // Returns whether function is in an error state. - inline bool is_error () const { return is_invalid; } + bool is_error () const { return is_invalid; } // Creates an error state function. static TypePathFunction create_error () { return TypePathFunction (true); } // Constructor - TypePathFunction (::std::vector< ::std::unique_ptr<Type> > inputs, - Type *type = NULL) - : inputs (::std::move (inputs)), return_type (type), is_invalid (false) + TypePathFunction (std::vector<std::unique_ptr<Type>> inputs, + Type *type = nullptr) + : inputs (std::move (inputs)), return_type (type), is_invalid (false) {} // FIXME: deprecated // Constructor - TypePathFunction (::std::vector< ::std::unique_ptr<Type> > inputs, - ::std::unique_ptr<Type> type = NULL) - : inputs (::std::move (inputs)), return_type (::std::move (type)), + TypePathFunction (std::vector<std::unique_ptr<Type>> inputs, + std::unique_ptr<Type> type = nullptr) + : inputs (std::move (inputs)), return_type (std::move (type)), is_invalid (false) {} // Copy constructor with clone TypePathFunction (TypePathFunction const &other) - : /*inputs(other.inputs),*/ return_type (other.return_type->clone_type ()), + : return_type (other.return_type->clone_type ()), is_invalid (other.is_invalid) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? inputs.reserve (other.inputs.size ()); - for (const auto &e : other.inputs) - { - inputs.push_back (e->clone_type ()); - } + inputs.push_back (e->clone_type ()); } ~TypePathFunction () = default; @@ -509,18 +473,12 @@ public: // Overloaded assignment operator to clone type TypePathFunction &operator= (TypePathFunction const &other) { - // inputs = other.inputs; return_type = other.return_type->clone_type (); is_invalid = other.is_invalid; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? inputs.reserve (other.inputs.size ()); - for (const auto &e : other.inputs) - { - inputs.push_back (e->clone_type ()); - } + inputs.push_back (e->clone_type ()); return *this; } @@ -529,7 +487,7 @@ public: TypePathFunction (TypePathFunction &&other) = default; TypePathFunction &operator= (TypePathFunction &&other) = default; - ::std::string as_string () const; + std::string as_string () const; }; // Segment used in type path with a function argument @@ -542,30 +500,29 @@ public: TypePathSegmentFunction (PathIdentSegment ident_segment, bool has_separating_scope_resolution, TypePathFunction function_path, Location locus) - : TypePathSegment (::std::move (ident_segment), + : TypePathSegment (std::move (ident_segment), has_separating_scope_resolution, locus), - function_path (::std::move (function_path)) + function_path (std::move (function_path)) {} // Constructor with segment name and TypePathFn - TypePathSegmentFunction (::std::string segment_name, + TypePathSegmentFunction (std::string segment_name, bool has_separating_scope_resolution, TypePathFunction function_path, Location locus) - : TypePathSegment (::std::move (segment_name), + : TypePathSegment (std::move (segment_name), has_separating_scope_resolution, locus), - function_path (::std::move (function_path)) + function_path (std::move (function_path)) {} - ::std::string as_string () const; + std::string as_string () const override; - bool is_ident_only () const { return false; } + bool is_ident_only () const override { return false; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: // Use covariance to override base class method - virtual TypePathSegmentFunction * - clone_type_path_segment_impl () const OVERRIDE + TypePathSegmentFunction *clone_type_path_segment_impl () const override { return new TypePathSegmentFunction (*this); } @@ -576,21 +533,17 @@ class TypePath : public TypeNoBounds { public: bool has_opening_scope_resolution; - ::std::vector< ::std::unique_ptr<TypePathSegment> > segments; - + std::vector<std::unique_ptr<TypePathSegment>> segments; Location locus; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TypePath *clone_type_impl () const OVERRIDE - { - return new TypePath (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + TypePath *clone_type_impl () const override { return new TypePath (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual TypePath *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TypePath *clone_type_no_bounds_impl () const override { return new TypePath (*this); } @@ -598,26 +551,26 @@ protected: public: /* Returns whether the TypePath has an opening scope resolution operator (i.e. * is global path or crate-relative path, not module-relative) */ - inline bool has_opening_scope_resolution_op () const + bool has_opening_scope_resolution_op () const { return has_opening_scope_resolution; } // Returns whether the TypePath is in an invalid state. - inline bool is_error () const { return segments.empty (); } + bool is_error () const { return segments.empty (); } // Creates an error state TypePath. static TypePath create_error () { - return TypePath (::std::vector< ::std::unique_ptr<TypePathSegment> > (), + return TypePath (std::vector<std::unique_ptr<TypePathSegment>> (), Location ()); } // Constructor - TypePath (::std::vector< ::std::unique_ptr<TypePathSegment> > segments, + TypePath (std::vector<std::unique_ptr<TypePathSegment>> segments, Location locus, bool has_opening_scope_resolution = false) : has_opening_scope_resolution (has_opening_scope_resolution), - segments (::std::move (segments)), locus (locus) + segments (std::move (segments)), locus (locus) {} // Copy constructor with vector clone @@ -625,14 +578,9 @@ public: : has_opening_scope_resolution (other.has_opening_scope_resolution), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? segments.reserve (other.segments.size ()); - for (const auto &e : other.segments) - { - segments.push_back (e->clone_type_path_segment ()); - } + segments.push_back (e->clone_type_path_segment ()); } // Overloaded assignment operator with clone @@ -641,14 +589,9 @@ public: has_opening_scope_resolution = other.has_opening_scope_resolution; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? segments.reserve (other.segments.size ()); - for (const auto &e : other.segments) - { - segments.push_back (e->clone_type_path_segment ()); - } + segments.push_back (e->clone_type_path_segment ()); return *this; } @@ -657,25 +600,24 @@ public: TypePath (TypePath &&other) = default; TypePath &operator= (TypePath &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; /* Converts TypePath to SimplePath if possible (i.e. no generic or function * arguments). Otherwise returns an empty SimplePath. */ SimplePath as_simple_path () const; // Creates a trait bound with a clone of this type path as its only element. - virtual TraitBound *to_trait_bound (bool in_parens) const OVERRIDE; + TraitBound *to_trait_bound (bool in_parens) const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; struct QualifiedPathType { private: - // Type type_to_invoke_on; - ::std::unique_ptr<Type> type_to_invoke_on; + std::unique_ptr<Type> type_to_invoke_on; // bool has_as_clause; TypePath trait_path; @@ -684,11 +626,11 @@ private: public: // Constructor - QualifiedPathType (::std::unique_ptr<Type> invoke_on_type, + QualifiedPathType (std::unique_ptr<Type> invoke_on_type, Location locus = Location (), TypePath trait_path = TypePath::create_error ()) - : type_to_invoke_on (::std::move (invoke_on_type)), - trait_path (::std::move (trait_path)), locus (locus) + : type_to_invoke_on (std::move (invoke_on_type)), + trait_path (std::move (trait_path)), locus (locus) {} // Copy constructor uses custom deep copy for Type to preserve polymorphism @@ -714,17 +656,20 @@ public: QualifiedPathType &operator= (QualifiedPathType &&other) = default; // Returns whether the qualified path type has a rebind as clause. - inline bool has_as_clause () const { return !trait_path.is_error (); } + bool has_as_clause () const { return !trait_path.is_error (); } // Returns whether the qualified path type is in an error state. - inline bool is_error () const { return type_to_invoke_on == NULL; } + bool is_error () const { return type_to_invoke_on == nullptr; } // Creates an error state qualified path type. - static QualifiedPathType create_error () { return QualifiedPathType (NULL); } + static QualifiedPathType create_error () + { + return QualifiedPathType (nullptr); + } - ::std::string as_string () const; + std::string as_string () const; - inline Location get_locus () const { return locus; } + Location get_locus () const { return locus; } }; /* AST node representing a qualified path-in-expression pattern (path that @@ -732,82 +677,74 @@ public: class QualifiedPathInExpression : public PathPattern, public PathExpr { QualifiedPathType path_type; - Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; QualifiedPathInExpression (QualifiedPathType qual_path_type, - ::std::vector<PathExprSegment> path_segments, + std::vector<PathExprSegment> path_segments, Location locus = Location (), - ::std::vector<Attribute> outer_attrs - = ::std::vector<Attribute> ()) - : PathPattern (::std::move (path_segments)), - PathExpr (::std::move (outer_attrs)), - path_type (::std::move (qual_path_type)), locus (locus) + std::vector<Attribute> outer_attrs + = std::vector<Attribute> ()) + : PathPattern (std::move (path_segments)), + PathExpr (std::move (outer_attrs)), + path_type (std::move (qual_path_type)), locus (locus) {} - // TODO: maybe make a shortcut constructor that has QualifiedPathType elements - // as params - - // Copy constructor, destructor, and assignment operator overload shouldn't be - // required + /* TODO: maybe make a shortcut constructor that has QualifiedPathType elements + * as params */ // Returns whether qualified path in expression is in an error state. - inline bool is_error () const { return path_type.is_error (); } + bool is_error () const { return path_type.is_error (); } // Creates an error qualified path in expression. static QualifiedPathInExpression create_error () { return QualifiedPathInExpression (QualifiedPathType::create_error (), - ::std::vector<PathExprSegment> ()); + std::vector<PathExprSegment> ()); } Location get_locus () const { return locus; } + Location get_locus_slow () const override { return get_locus (); } - Location get_locus_slow () const OVERRIDE { return get_locus (); } - - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual QualifiedPathInExpression *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + QualifiedPathInExpression *clone_pattern_impl () const override { return new QualifiedPathInExpression (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual QualifiedPathInExpression * - clone_expr_without_block_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + QualifiedPathInExpression *clone_expr_without_block_impl () const override { return new QualifiedPathInExpression (*this); } }; -// Represents a qualified path in a type; used for disambiguating trait function -// calls +/* Represents a qualified path in a type; used for disambiguating trait function + * calls */ class QualifiedPathInType : public TypeNoBounds { QualifiedPathType path_type; - // ::std::vector<TypePathSegment> segments; - ::std::vector< ::std::unique_ptr<TypePathSegment> > segments; - + std::vector<std::unique_ptr<TypePathSegment>> segments; Location locus; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual QualifiedPathInType *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + QualifiedPathInType *clone_type_impl () const override { return new QualifiedPathInType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual QualifiedPathInType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + QualifiedPathInType *clone_type_no_bounds_impl () const override { return new QualifiedPathInType (*this); } @@ -815,27 +752,22 @@ protected: public: QualifiedPathInType ( QualifiedPathType qual_path_type, - ::std::vector< ::std::unique_ptr<TypePathSegment> > path_segments, + std::vector<std::unique_ptr<TypePathSegment>> path_segments, Location locus = Location ()) - : path_type (::std::move (qual_path_type)), - segments (::std::move (path_segments)), locus (locus) + : path_type (std::move (qual_path_type)), + segments (std::move (path_segments)), locus (locus) {} - // TODO: maybe make a shortcut constructor that has QualifiedPathType elements - // as params + /* TODO: maybe make a shortcut constructor that has QualifiedPathType elements + * as params */ // Copy constructor with vector clone QualifiedPathInType (QualifiedPathInType const &other) : path_type (other.path_type), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? segments.reserve (other.segments.size ()); - for (const auto &e : other.segments) - { - segments.push_back (e->clone_type_path_segment ()); - } + segments.push_back (e->clone_type_path_segment ()); } // Overloaded assignment operator with vector clone @@ -844,14 +776,9 @@ public: path_type = other.path_type; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? segments.reserve (other.segments.size ()); - for (const auto &e : other.segments) - { - segments.push_back (e->clone_type_path_segment ()); - } + segments.push_back (e->clone_type_path_segment ()); return *this; } @@ -861,19 +788,19 @@ public: QualifiedPathInType &operator= (QualifiedPathInType &&other) = default; // Returns whether qualified path in type is in an error state. - inline bool is_error () const { return path_type.is_error (); } + bool is_error () const { return path_type.is_error (); } // Creates an error state qualified path in type. static QualifiedPathInType create_error () { return QualifiedPathInType ( QualifiedPathType::create_error (), - ::std::vector< ::std::unique_ptr<TypePathSegment> > ()); + std::vector<std::unique_ptr<TypePathSegment>> ()); } - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; } // namespace AST } // namespace Rust diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h index e61d473..4e639a5 100644 --- a/gcc/rust/ast/rust-pattern.h +++ b/gcc/rust/ast/rust-pattern.h @@ -8,10 +8,10 @@ namespace AST { // Literal pattern AST node (comparing to a literal) class LiteralPattern : public Pattern { - Literal lit; // make literal have a type given by enum, etc. rustc uses an - // extended form - // of its literal token implementation - // FIXME: literal representation - use LiteralExpr? or another thing? + Literal lit; + /* make literal have a type given by enum, etc. rustc uses an extended form of + * its literal token implementation */ + // TODO: literal representation - use LiteralExpr? or another thing? // Minus prefixed to literal (if integer or floating-point) bool has_minus; @@ -20,27 +20,27 @@ class LiteralPattern : public Pattern Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Constructor for a literal pattern LiteralPattern (Literal lit, Location locus, bool has_minus = false) - : lit (::std::move (lit)), has_minus (has_minus), locus (locus) + : lit (std::move (lit)), has_minus (has_minus), locus (locus) {} - LiteralPattern (::std::string val, Literal::LitType type, Location locus, + LiteralPattern (std::string val, Literal::LitType type, Location locus, bool has_minus = false) - : lit (Literal (::std::move (val), type)), has_minus (has_minus), + : lit (Literal (std::move (val), type)), has_minus (has_minus), locus (locus) {} Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual LiteralPattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + virtual LiteralPattern *clone_pattern_impl () const override { return new LiteralPattern (*this); } @@ -55,26 +55,21 @@ public: bool is_mut; // bool has_pattern; - // Pattern* to_bind; - ::std::unique_ptr<Pattern> to_bind; + std::unique_ptr<Pattern> to_bind; Location locus; - /*~IdentifierPattern() { - delete to_bind; - }*/ - - ::std::string as_string () const; + std::string as_string () const; // Returns whether the IdentifierPattern has a pattern to bind. - inline bool has_pattern_to_bind () const { return to_bind != NULL; } + bool has_pattern_to_bind () const { return to_bind != nullptr; } // Constructor IdentifierPattern (Identifier ident, Location locus, bool is_ref = false, bool is_mut = false, - ::std::unique_ptr<Pattern> to_bind = NULL) - : variable_ident (::std::move (ident)), is_ref (is_ref), is_mut (is_mut), - to_bind (::std::move (to_bind)), locus (locus) + std::unique_ptr<Pattern> to_bind = nullptr) + : variable_ident (std::move (ident)), is_ref (is_ref), is_mut (is_mut), + to_bind (std::move (to_bind)), locus (locus) {} // Copy constructor with clone @@ -83,14 +78,10 @@ public: is_mut (other.is_mut), locus (other.locus) { // fix to get prevent null pointer dereference - if (other.to_bind != NULL) - { - to_bind = other.to_bind->clone_pattern (); - } + if (other.to_bind != nullptr) + to_bind = other.to_bind->clone_pattern (); } - // Destructor - define here if required - // Overload assignment operator to use clone IdentifierPattern &operator= (IdentifierPattern const &other) { @@ -98,11 +89,10 @@ public: is_ref = other.is_ref; is_mut = other.is_mut; locus = other.locus; + // fix to get prevent null pointer dereference - if (other.to_bind != NULL) - { - to_bind = other.to_bind->clone_pattern (); - } + if (other.to_bind != nullptr) + to_bind = other.to_bind->clone_pattern (); return *this; } @@ -113,12 +103,12 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual IdentifierPattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + IdentifierPattern *clone_pattern_impl () const override { return new IdentifierPattern (*this); } @@ -130,18 +120,18 @@ class WildcardPattern : public Pattern Location locus; public: - ::std::string as_string () const { return ::std::string (1, '_'); } + std::string as_string () const override { return std::string (1, '_'); } WildcardPattern (Location locus) : locus (locus) {} Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual WildcardPattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + WildcardPattern *clone_pattern_impl () const override { return new WildcardPattern (*this); } @@ -150,25 +140,17 @@ protected: // Base range pattern bound (lower or upper limit) - abstract class RangePatternBound { - /*union { - CharLiteral char_lit; - ByteLiteral byte_lit; - IntLiteral int_lit; - FloatLiteral float_lit; - PathInExpression path; - QualifiedPathInExpression qual_path; - } pattern;*/ public: virtual ~RangePatternBound () {} // Unique pointer custom clone function - ::std::unique_ptr<RangePatternBound> clone_range_pattern_bound () const + std::unique_ptr<RangePatternBound> clone_range_pattern_bound () const { - return ::std::unique_ptr<RangePatternBound> ( + return std::unique_ptr<RangePatternBound> ( clone_range_pattern_bound_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -181,8 +163,8 @@ protected: class RangePatternBoundLiteral : public RangePatternBound { Literal literal; - // Can only be a char, byte, int, or float literal - same impl here as - // previously + /* Can only be a char, byte, int, or float literal - same impl here as + * previously */ // Minus prefixed to literal (if integer or floating-point) bool has_minus; @@ -196,17 +178,16 @@ public: : literal (literal), has_minus (has_minus), locus (locus) {} - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangePatternBoundLiteral * - clone_range_pattern_bound_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangePatternBoundLiteral *clone_range_pattern_bound_impl () const override { return new RangePatternBoundLiteral (*this); } @@ -217,23 +198,22 @@ class RangePatternBoundPath : public RangePatternBound { PathInExpression path; - // TODO: should this be refactored so that PathInExpression is a subclass of - // RangePatternBound? + /* TODO: should this be refactored so that PathInExpression is a subclass of + * RangePatternBound? */ public: - RangePatternBoundPath (PathInExpression path) : path (::std::move (path)) {} + RangePatternBoundPath (PathInExpression path) : path (std::move (path)) {} - ::std::string as_string () const { return path.as_string (); } + std::string as_string () const override { return path.as_string (); } Location get_locus () const { return path.get_locus (); } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangePatternBoundPath * - clone_range_pattern_bound_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangePatternBoundPath *clone_range_pattern_bound_impl () const override { return new RangePatternBoundPath (*this); } @@ -249,20 +229,19 @@ class RangePatternBoundQualPath : public RangePatternBound public: RangePatternBoundQualPath (QualifiedPathInExpression path) - : path (::std::move (path)) + : path (std::move (path)) {} - ::std::string as_string () const { return path.as_string (); } + std::string as_string () const override { return path.as_string (); } Location get_locus () const { return path.get_locus (); } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangePatternBoundQualPath * - clone_range_pattern_bound_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangePatternBoundQualPath *clone_range_pattern_bound_impl () const override { return new RangePatternBoundQualPath (*this); } @@ -271,25 +250,23 @@ protected: // AST node for matching within a certain range (range pattern) class RangePattern : public Pattern { - /*RangePatternBound lower; - RangePatternBound upper;*/ - ::std::unique_ptr<RangePatternBound> lower; - ::std::unique_ptr<RangePatternBound> upper; + std::unique_ptr<RangePatternBound> lower; + std::unique_ptr<RangePatternBound> upper; bool has_ellipsis_syntax; - // location only stored to avoid a dereference - lower pattern should give - // correct location so maybe change in future + /* location only stored to avoid a dereference - lower pattern should give + * correct location so maybe change in future */ Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Constructor - RangePattern (::std::unique_ptr<RangePatternBound> lower, - ::std::unique_ptr<RangePatternBound> upper, Location locus, + RangePattern (std::unique_ptr<RangePatternBound> lower, + std::unique_ptr<RangePatternBound> upper, Location locus, bool has_ellipsis_syntax = false) - : lower (::std::move (lower)), upper (::std::move (upper)), + : lower (std::move (lower)), upper (std::move (upper)), has_ellipsis_syntax (has_ellipsis_syntax), locus (locus) {} @@ -300,8 +277,6 @@ public: has_ellipsis_syntax (other.has_ellipsis_syntax), locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone RangePattern &operator= (RangePattern const &other) { @@ -319,12 +294,12 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RangePattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RangePattern *clone_pattern_impl () const override { return new RangePattern (*this); } @@ -335,22 +310,16 @@ class ReferencePattern : public Pattern { bool has_two_amps; bool is_mut; - // Pattern* pattern; - ::std::unique_ptr<Pattern> pattern; - + std::unique_ptr<Pattern> pattern; Location locus; public: - /*~ReferencePattern() { - delete pattern; - }*/ + std::string as_string () const override; - ::std::string as_string () const; - - ReferencePattern (::std::unique_ptr<Pattern> pattern, bool is_mut_reference, + ReferencePattern (std::unique_ptr<Pattern> pattern, bool is_mut_reference, bool ref_has_two_amps, Location locus) : has_two_amps (ref_has_two_amps), is_mut (is_mut_reference), - pattern (::std::move (pattern)), locus (locus) + pattern (std::move (pattern)), locus (locus) {} // Copy constructor requires clone @@ -359,8 +328,6 @@ public: pattern (other.pattern->clone_pattern ()), locus (other.locus) {} - // Destructor - define here if required - // Overload assignment operator to clone ReferencePattern &operator= (ReferencePattern const &other) { @@ -376,12 +343,12 @@ public: ReferencePattern (ReferencePattern &&other) = default; ReferencePattern &operator= (ReferencePattern &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ReferencePattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ReferencePattern *clone_pattern_impl () const override { return new ReferencePattern (*this); } @@ -391,63 +358,47 @@ protected: struct StructPatternEtc { private: - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; // should this store location data? public: - StructPatternEtc (::std::vector<Attribute> outer_attribs) - : outer_attrs (::std::move (outer_attribs)) + StructPatternEtc (std::vector<Attribute> outer_attribs) + : outer_attrs (std::move (outer_attribs)) {} // Creates an empty StructPatternEtc static StructPatternEtc create_empty () { - return StructPatternEtc (::std::vector<Attribute> ()); + return StructPatternEtc (std::vector<Attribute> ()); } }; // Base class for a single field in a struct pattern - abstract class StructPatternField { - ::std::vector<Attribute> outer_attrs; - /*union { - struct { - //TupleIndex index; - Pattern tuple_pattern; - } tuple_pattern; - struct { - //Identifier ident; - Pattern ident_pattern; - } ident_pattern; - struct { - bool has_ref; - bool has_mut; - //Identifier ident; - } ident; - } pattern;*/ - + std::vector<Attribute> outer_attrs; Location locus; public: virtual ~StructPatternField () {} // Unique pointer custom clone function - ::std::unique_ptr<StructPatternField> clone_struct_pattern_field () const + std::unique_ptr<StructPatternField> clone_struct_pattern_field () const { - return ::std::unique_ptr<StructPatternField> ( + return std::unique_ptr<StructPatternField> ( clone_struct_pattern_field_impl ()); } - virtual ::std::string as_string () const; + virtual std::string as_string () const; Location get_locus () const { return locus; } virtual void accept_vis (ASTVisitor &vis) = 0; protected: - StructPatternField (::std::vector<Attribute> outer_attribs, Location locus) - : outer_attrs (::std::move (outer_attribs)), locus (locus) + StructPatternField (std::vector<Attribute> outer_attribs, Location locus) + : outer_attrs (std::move (outer_attribs)), locus (locus) {} // Clone function implementation as pure virtual method @@ -458,20 +409,15 @@ protected: class StructPatternFieldTuplePat : public StructPatternField { TupleIndex index; - // Pattern* tuple_pattern; - ::std::unique_ptr<Pattern> tuple_pattern; + std::unique_ptr<Pattern> tuple_pattern; public: - /*~StructPatternFieldTuplePat() { - delete tuple_pattern; - }*/ - StructPatternFieldTuplePat (TupleIndex index, - ::std::unique_ptr<Pattern> tuple_pattern, - ::std::vector<Attribute> outer_attribs, + std::unique_ptr<Pattern> tuple_pattern, + std::vector<Attribute> outer_attribs, Location locus) - : StructPatternField (::std::move (outer_attribs), locus), index (index), - tuple_pattern (::std::move (tuple_pattern)) + : StructPatternField (std::move (outer_attribs), locus), index (index), + tuple_pattern (std::move (tuple_pattern)) {} // Copy constructor requires clone @@ -480,8 +426,6 @@ public: tuple_pattern (other.tuple_pattern->clone_pattern ()) {} - // Destructor - define here if required - // Overload assignment operator to perform clone StructPatternFieldTuplePat & operator= (StructPatternFieldTuplePat const &other) @@ -499,15 +443,14 @@ public: StructPatternFieldTuplePat &operator= (StructPatternFieldTuplePat &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructPatternFieldTuplePat * - clone_struct_pattern_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructPatternFieldTuplePat *clone_struct_pattern_field_impl () const override { return new StructPatternFieldTuplePat (*this); } @@ -517,20 +460,15 @@ protected: class StructPatternFieldIdentPat : public StructPatternField { Identifier ident; - // Pattern* ident_pattern; - ::std::unique_ptr<Pattern> ident_pattern; + std::unique_ptr<Pattern> ident_pattern; public: - /*~StructPatternFieldIdentPat() { - delete ident_pattern; - }*/ - StructPatternFieldIdentPat (Identifier ident, - ::std::unique_ptr<Pattern> ident_pattern, - ::std::vector<Attribute> outer_attrs, + std::unique_ptr<Pattern> ident_pattern, + std::vector<Attribute> outer_attrs, Location locus) - : StructPatternField (::std::move (outer_attrs), locus), - ident (::std::move (ident)), ident_pattern (::std::move (ident_pattern)) + : StructPatternField (std::move (outer_attrs), locus), + ident (std::move (ident)), ident_pattern (std::move (ident_pattern)) {} // Copy constructor requires clone @@ -539,8 +477,6 @@ public: ident_pattern (other.ident_pattern->clone_pattern ()) {} - // Destructor - define here if required - // Overload assignment operator to clone StructPatternFieldIdentPat & operator= (StructPatternFieldIdentPat const &other) @@ -558,15 +494,14 @@ public: StructPatternFieldIdentPat &operator= (StructPatternFieldIdentPat &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructPatternFieldIdentPat * - clone_struct_pattern_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructPatternFieldIdentPat *clone_struct_pattern_field_impl () const override { return new StructPatternFieldIdentPat (*this); } @@ -577,25 +512,23 @@ class StructPatternFieldIdent : public StructPatternField { bool has_ref; bool has_mut; - Identifier ident; public: StructPatternFieldIdent (Identifier ident, bool is_ref, bool is_mut, - ::std::vector<Attribute> outer_attrs, Location locus) - : StructPatternField (::std::move (outer_attrs), locus), has_ref (is_ref), - has_mut (is_mut), ident (::std::move (ident)) + std::vector<Attribute> outer_attrs, Location locus) + : StructPatternField (std::move (outer_attrs), locus), has_ref (is_ref), + has_mut (is_mut), ident (std::move (ident)) {} - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructPatternFieldIdent * - clone_struct_pattern_field_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructPatternFieldIdent *clone_struct_pattern_field_impl () const override { return new StructPatternFieldIdent (*this); } @@ -606,8 +539,7 @@ struct StructPatternElements { private: // bool has_struct_pattern_fields; - //::std::vector<StructPatternField> fields; - ::std::vector< ::std::unique_ptr<StructPatternField> > fields; + std::vector<std::unique_ptr<StructPatternField>> fields; bool has_struct_pattern_etc; StructPatternEtc etc; @@ -618,27 +550,27 @@ private: public: // Returns whether there are any struct pattern fields - inline bool has_struct_pattern_fields () const { return !fields.empty (); } + bool has_struct_pattern_fields () const { return !fields.empty (); } - // Returns whether the struct pattern elements is entirely empty (no fields, - // no etc). - inline bool is_empty () const + /* Returns whether the struct pattern elements is entirely empty (no fields, + * no etc). */ + bool is_empty () const { return !has_struct_pattern_fields () && !has_struct_pattern_etc; } // Constructor for StructPatternElements with both (potentially) StructPatternElements ( - ::std::vector< ::std::unique_ptr<StructPatternField> > fields, + std::vector<std::unique_ptr<StructPatternField>> fields, StructPatternEtc etc) - : fields (::std::move (fields)), has_struct_pattern_etc (true), - etc (::std::move (etc)) + : fields (std::move (fields)), has_struct_pattern_etc (true), + etc (std::move (etc)) {} // Constructor for StructPatternElements with no StructPatternEtc StructPatternElements ( - ::std::vector< ::std::unique_ptr<StructPatternField> > fields) - : fields (::std::move (fields)), has_struct_pattern_etc (false), + std::vector<std::unique_ptr<StructPatternField>> fields) + : fields (std::move (fields)), has_struct_pattern_etc (false), etc (StructPatternEtc::create_empty ()) {} @@ -646,14 +578,9 @@ public: StructPatternElements (StructPatternElements const &other) : has_struct_pattern_etc (other.has_struct_pattern_etc), etc (other.etc) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? fields.reserve (other.fields.size ()); - for (const auto &e : other.fields) - { - fields.push_back (e->clone_struct_pattern_field ()); - } + fields.push_back (e->clone_struct_pattern_field ()); } // Overloaded assignment operator with vector clone @@ -662,14 +589,9 @@ public: etc = other.etc; has_struct_pattern_etc = other.has_struct_pattern_etc; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? fields.reserve (other.fields.size ()); - for (const auto &e : other.fields) - { - fields.push_back (e->clone_struct_pattern_field ()); - } + fields.push_back (e->clone_struct_pattern_field ()); return *this; } @@ -682,10 +604,10 @@ public: static StructPatternElements create_empty () { return StructPatternElements ( - ::std::vector< ::std::unique_ptr<StructPatternField> > ()); + std::vector<std::unique_ptr<StructPatternField>> ()); } - ::std::string as_string () const; + std::string as_string () const; }; // Struct pattern AST node representation @@ -699,30 +621,30 @@ class StructPattern : public Pattern // TODO: should this store location data? Accessor uses path location data. public: - ::std::string as_string () const; + std::string as_string () const override; // Constructs a struct pattern from specified StructPatternElements StructPattern (PathInExpression struct_path, StructPatternElements elems = StructPatternElements::create_empty ()) - : path (::std::move (struct_path)), elems (::std::move (elems)) + : path (std::move (struct_path)), elems (std::move (elems)) {} - // TODO: constructor to construct via elements included in - // StructPatternElements + /* TODO: constructor to construct via elements included in + * StructPatternElements */ - // Returns whether struct pattern has any struct pattern elements (if not, it - // is empty). - inline bool has_struct_pattern_elems () const { return !elems.is_empty (); } + /* Returns whether struct pattern has any struct pattern elements (if not, it + * is empty). */ + bool has_struct_pattern_elems () const { return !elems.is_empty (); } Location get_locus () const { return path.get_locus (); } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual StructPattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + StructPattern *clone_pattern_impl () const override { return new StructPattern (*this); } @@ -737,13 +659,12 @@ public: // TODO: should this store location data? // Unique pointer custom clone function - ::std::unique_ptr<TupleStructItems> clone_tuple_struct_items () const + std::unique_ptr<TupleStructItems> clone_tuple_struct_items () const { - return ::std::unique_ptr<TupleStructItems> ( - clone_tuple_struct_items_impl ()); + return std::unique_ptr<TupleStructItems> (clone_tuple_struct_items_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -755,38 +676,27 @@ protected: // Class for non-ranged tuple struct pattern patterns class TupleStructItemsNoRange : public TupleStructItems { - //::std::vector<Pattern> patterns; - ::std::vector< ::std::unique_ptr<Pattern> > patterns; + std::vector<std::unique_ptr<Pattern>> patterns; public: - TupleStructItemsNoRange (::std::vector< ::std::unique_ptr<Pattern> > patterns) - : patterns (::std::move (patterns)) + TupleStructItemsNoRange (std::vector<std::unique_ptr<Pattern>> patterns) + : patterns (std::move (patterns)) {} // Copy constructor with vector clone TupleStructItemsNoRange (TupleStructItemsNoRange const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? patterns.reserve (other.patterns.size ()); - for (const auto &e : other.patterns) - { - patterns.push_back (e->clone_pattern ()); - } + patterns.push_back (e->clone_pattern ()); } // Overloaded assignment operator with vector clone TupleStructItemsNoRange &operator= (TupleStructItemsNoRange const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? patterns.reserve (other.patterns.size ()); - for (const auto &e : other.patterns) - { - patterns.push_back (e->clone_pattern ()); - } + patterns.push_back (e->clone_pattern ()); return *this; } @@ -796,15 +706,14 @@ public: TupleStructItemsNoRange &operator= (TupleStructItemsNoRange &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleStructItemsNoRange * - clone_tuple_struct_items_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleStructItemsNoRange *clone_tuple_struct_items_impl () const override { return new TupleStructItemsNoRange (*this); } @@ -813,61 +722,38 @@ protected: // Class for ranged tuple struct pattern patterns class TupleStructItemsRange : public TupleStructItems { - /*::std::vector<Pattern> lower_patterns; - ::std::vector<Pattern> upper_patterns;*/ - ::std::vector< ::std::unique_ptr<Pattern> > lower_patterns; - ::std::vector< ::std::unique_ptr<Pattern> > upper_patterns; + std::vector<std::unique_ptr<Pattern>> lower_patterns; + std::vector<std::unique_ptr<Pattern>> upper_patterns; public: - TupleStructItemsRange ( - ::std::vector< ::std::unique_ptr<Pattern> > lower_patterns, - ::std::vector< ::std::unique_ptr<Pattern> > upper_patterns) - : lower_patterns (::std::move (lower_patterns)), - upper_patterns (::std::move (upper_patterns)) + TupleStructItemsRange (std::vector<std::unique_ptr<Pattern>> lower_patterns, + std::vector<std::unique_ptr<Pattern>> upper_patterns) + : lower_patterns (std::move (lower_patterns)), + upper_patterns (std::move (upper_patterns)) {} // Copy constructor with vector clone TupleStructItemsRange (TupleStructItemsRange const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? lower_patterns.reserve (other.lower_patterns.size ()); - for (const auto &e : other.lower_patterns) - { - lower_patterns.push_back (e->clone_pattern ()); - } + lower_patterns.push_back (e->clone_pattern ()); - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? upper_patterns.reserve (other.upper_patterns.size ()); - for (const auto &e : other.upper_patterns) - { - upper_patterns.push_back (e->clone_pattern ()); - } + upper_patterns.push_back (e->clone_pattern ()); } // Overloaded assignment operator to clone TupleStructItemsRange &operator= (TupleStructItemsRange const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? lower_patterns.reserve (other.lower_patterns.size ()); - for (const auto &e : other.lower_patterns) - { - lower_patterns.push_back (e->clone_pattern ()); - } + lower_patterns.push_back (e->clone_pattern ()); - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? upper_patterns.reserve (other.upper_patterns.size ()); - for (const auto &e : other.upper_patterns) - { - upper_patterns.push_back (e->clone_pattern ()); - } + upper_patterns.push_back (e->clone_pattern ()); return *this; } @@ -876,14 +762,14 @@ public: TupleStructItemsRange (TupleStructItemsRange &&other) = default; TupleStructItemsRange &operator= (TupleStructItemsRange &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleStructItemsRange *clone_tuple_struct_items_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleStructItemsRange *clone_tuple_struct_items_impl () const override { return new TupleStructItemsRange (*this); } @@ -893,18 +779,17 @@ protected: class TupleStructPattern : public Pattern { PathInExpression path; - // TupleStructItems items; - ::std::unique_ptr<TupleStructItems> items; + std::unique_ptr<TupleStructItems> items; - // TOOD: should this store location data? current accessor uses path location - // data + /* TOOD: should this store location data? current accessor uses path location + * data */ public: - ::std::string as_string () const; + std::string as_string () const override; TupleStructPattern (PathInExpression tuple_struct_path, - ::std::unique_ptr<TupleStructItems> items) - : path (::std::move (tuple_struct_path)), items (::std::move (items)) + std::unique_ptr<TupleStructItems> items) + : path (std::move (tuple_struct_path)), items (std::move (items)) {} // Copy constructor required to clone @@ -912,8 +797,6 @@ public: : path (other.path), items (other.items->clone_tuple_struct_items ()) {} - // Destructor - define here if required - // Operator overload assignment operator to clone TupleStructPattern &operator= (TupleStructPattern const &other) { @@ -929,12 +812,12 @@ public: Location get_locus () const { return path.get_locus (); } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleStructPattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleStructPattern *clone_pattern_impl () const override { return new TupleStructPattern (*this); } @@ -949,13 +832,13 @@ public: // TODO: should this store location data? // Unique pointer custom clone function - ::std::unique_ptr<TuplePatternItems> clone_tuple_pattern_items () const + std::unique_ptr<TuplePatternItems> clone_tuple_pattern_items () const { - return ::std::unique_ptr<TuplePatternItems> ( + return std::unique_ptr<TuplePatternItems> ( clone_tuple_pattern_items_impl ()); } - virtual ::std::string as_string () const = 0; + virtual std::string as_string () const = 0; virtual void accept_vis (ASTVisitor &vis) = 0; @@ -967,7 +850,7 @@ protected: // Class representing TuplePattern patterns where there is only a single pattern /*class TuplePatternItemsSingle : public TuplePatternItems { // Pattern pattern; - ::std::unique_ptr<Pattern> pattern; + std::unique_ptr<Pattern> pattern; public: TuplePatternItemsSingle(Pattern* pattern) : pattern(pattern) {} @@ -993,7 +876,7 @@ default; protected: // Use covariance to implement clone function as returning this object rather than base virtual TuplePatternItemsSingle* -clone_tuple_pattern_items_impl() const OVERRIDE { return new +clone_tuple_pattern_items_impl() const override { return new TuplePatternItemsSingle(*this); } };*/ @@ -1002,39 +885,27 @@ TuplePatternItemsSingle(*this); // Class representing TuplePattern patterns where there are multiple patterns class TuplePatternItemsMultiple : public TuplePatternItems { - //::std::vector<Pattern> patterns; - ::std::vector< ::std::unique_ptr<Pattern> > patterns; + std::vector<std::unique_ptr<Pattern>> patterns; public: - TuplePatternItemsMultiple ( - ::std::vector< ::std::unique_ptr<Pattern> > patterns) - : patterns (::std::move (patterns)) + TuplePatternItemsMultiple (std::vector<std::unique_ptr<Pattern>> patterns) + : patterns (std::move (patterns)) {} // Copy constructor with vector clone TuplePatternItemsMultiple (TuplePatternItemsMultiple const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? patterns.reserve (other.patterns.size ()); - for (const auto &e : other.patterns) - { - patterns.push_back (e->clone_pattern ()); - } + patterns.push_back (e->clone_pattern ()); } // Overloaded assignment operator to vector clone TuplePatternItemsMultiple &operator= (TuplePatternItemsMultiple const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? patterns.reserve (other.patterns.size ()); - for (const auto &e : other.patterns) - { - patterns.push_back (e->clone_pattern ()); - } + patterns.push_back (e->clone_pattern ()); return *this; } @@ -1044,15 +915,14 @@ public: TuplePatternItemsMultiple &operator= (TuplePatternItemsMultiple &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TuplePatternItemsMultiple * - clone_tuple_pattern_items_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TuplePatternItemsMultiple *clone_tuple_pattern_items_impl () const override { return new TuplePatternItemsMultiple (*this); } @@ -1061,61 +931,39 @@ protected: // Class representing TuplePattern patterns where there are a range of patterns class TuplePatternItemsRanged : public TuplePatternItems { - /*::std::vector<Pattern> lower_patterns; - ::std::vector<Pattern> upper_patterns;*/ - ::std::vector< ::std::unique_ptr<Pattern> > lower_patterns; - ::std::vector< ::std::unique_ptr<Pattern> > upper_patterns; + std::vector<std::unique_ptr<Pattern>> lower_patterns; + std::vector<std::unique_ptr<Pattern>> upper_patterns; public: TuplePatternItemsRanged ( - ::std::vector< ::std::unique_ptr<Pattern> > lower_patterns, - ::std::vector< ::std::unique_ptr<Pattern> > upper_patterns) - : lower_patterns (::std::move (lower_patterns)), - upper_patterns (::std::move (upper_patterns)) + std::vector<std::unique_ptr<Pattern>> lower_patterns, + std::vector<std::unique_ptr<Pattern>> upper_patterns) + : lower_patterns (std::move (lower_patterns)), + upper_patterns (std::move (upper_patterns)) {} // Copy constructor with vector clone TuplePatternItemsRanged (TuplePatternItemsRanged const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? lower_patterns.reserve (other.lower_patterns.size ()); - for (const auto &e : other.lower_patterns) - { - lower_patterns.push_back (e->clone_pattern ()); - } + lower_patterns.push_back (e->clone_pattern ()); - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? upper_patterns.reserve (other.upper_patterns.size ()); - for (const auto &e : other.upper_patterns) - { - upper_patterns.push_back (e->clone_pattern ()); - } + upper_patterns.push_back (e->clone_pattern ()); } // Overloaded assignment operator to clone TuplePatternItemsRanged &operator= (TuplePatternItemsRanged const &other) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? lower_patterns.reserve (other.lower_patterns.size ()); - for (const auto &e : other.lower_patterns) - { - lower_patterns.push_back (e->clone_pattern ()); - } + lower_patterns.push_back (e->clone_pattern ()); - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? upper_patterns.reserve (other.upper_patterns.size ()); - for (const auto &e : other.upper_patterns) - { - upper_patterns.push_back (e->clone_pattern ()); - } + upper_patterns.push_back (e->clone_pattern ()); return *this; } @@ -1125,15 +973,14 @@ public: TuplePatternItemsRanged &operator= (TuplePatternItemsRanged &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TuplePatternItemsRanged * - clone_tuple_pattern_items_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TuplePatternItemsRanged *clone_tuple_pattern_items_impl () const override { return new TuplePatternItemsRanged (*this); } @@ -1143,19 +990,18 @@ protected: class TuplePattern : public Pattern { // bool has_tuple_pattern_items; - // TuplePatternItems items; - ::std::unique_ptr<TuplePatternItems> items; + std::unique_ptr<TuplePatternItems> items; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; // Returns true if the tuple pattern has items - inline bool has_tuple_pattern_items () const { return items != NULL; } + bool has_tuple_pattern_items () const { return items != nullptr; } - TuplePattern (::std::unique_ptr<TuplePatternItems> items, Location locus) - : items (::std::move (items)), locus (locus) + TuplePattern (std::unique_ptr<TuplePatternItems> items, Location locus) + : items (std::move (items)), locus (locus) {} // Copy constructor requires clone @@ -1163,8 +1009,6 @@ public: : items (other.items->clone_tuple_pattern_items ()), locus (other.locus) {} - // Destructor - define here if required - // Overload assignment operator to clone TuplePattern &operator= (TuplePattern const &other) { @@ -1176,12 +1020,12 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TuplePattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TuplePattern *clone_pattern_impl () const override { return new TuplePattern (*this); } @@ -1190,19 +1034,17 @@ protected: // AST node representing a pattern in parentheses, used to control precedence class GroupedPattern : public Pattern { - // Pattern pattern_in_parens; - ::std::unique_ptr<Pattern> pattern_in_parens; - + std::unique_ptr<Pattern> pattern_in_parens; Location locus; public: - ::std::string as_string () const + std::string as_string () const override { return "(" + pattern_in_parens->as_string () + ")"; } - GroupedPattern (::std::unique_ptr<Pattern> pattern_in_parens, Location locus) - : pattern_in_parens (::std::move (pattern_in_parens)), locus (locus) + GroupedPattern (std::unique_ptr<Pattern> pattern_in_parens, Location locus) + : pattern_in_parens (std::move (pattern_in_parens)), locus (locus) {} // Copy constructor uses clone @@ -1211,8 +1053,6 @@ public: locus (other.locus) {} - // Destructor - define here if required - // Overload assignment operator to clone GroupedPattern &operator= (GroupedPattern const &other) { @@ -1228,12 +1068,12 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual GroupedPattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + GroupedPattern *clone_pattern_impl () const override { return new GroupedPattern (*this); } @@ -1242,44 +1082,32 @@ protected: // AST node representing patterns that can match slices and arrays class SlicePattern : public Pattern { - //::std::vector<Pattern> items; - ::std::vector< ::std::unique_ptr<Pattern> > items; - + std::vector<std::unique_ptr<Pattern>> items; Location locus; public: - ::std::string as_string () const; + std::string as_string () const override; - SlicePattern (::std::vector< ::std::unique_ptr<Pattern> > items, - Location locus) - : items (::std::move (items)), locus (locus) + SlicePattern (std::vector<std::unique_ptr<Pattern>> items, Location locus) + : items (std::move (items)), locus (locus) {} // Copy constructor with vector clone SlicePattern (SlicePattern const &other) : locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? items.reserve (other.items.size ()); - for (const auto &e : other.items) - { - items.push_back (e->clone_pattern ()); - } + items.push_back (e->clone_pattern ()); } // Overloaded assignment operator to vector clone SlicePattern &operator= (SlicePattern const &other) { locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? - items.reserve (other.items.size ()); + items.reserve (other.items.size ()); for (const auto &e : other.items) - { - items.push_back (e->clone_pattern ()); - } + items.push_back (e->clone_pattern ()); return *this; } @@ -1290,20 +1118,17 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual SlicePattern *clone_pattern_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + SlicePattern *clone_pattern_impl () const override { return new SlicePattern (*this); } }; -// forward decl PathExprSegment -// class PathExprSegment; - // Moved definition to rust-path.h class PathPattern; @@ -1313,10 +1138,6 @@ class QualifiedPathInExpression; // Replaced with forward decl - defined in rust-macro.h class MacroInvocation; -/*class MacroInvocation : public Pattern { - public: - ::std::string as_string() const; -};*/ } // namespace AST } // namespace Rust diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h index addb5f9..89b4d87 100644 --- a/gcc/rust/ast/rust-stmt.h +++ b/gcc/rust/ast/rust-stmt.h @@ -13,82 +13,57 @@ class EmptyStmt : public Stmt Location locus; public: - ::std::string as_string () const { return ::std::string (1, ';'); } + std::string as_string () const override { return std::string (1, ';'); } EmptyStmt (Location locus) : locus (locus) {} Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual EmptyStmt *clone_stmt_impl () const OVERRIDE - { - return new EmptyStmt (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + EmptyStmt *clone_stmt_impl () const override { return new EmptyStmt (*this); } }; -/* This is syntactically identical to declaring an item inside a module BUT it - * has block scope. Type of "declaration statement" as it introduces new name - * into scope */ -/*class ItemStatement : public Statement { - // TODO: put in same params as regular item - // maybe even merge data structure with module item? - - public: - ::std::string as_string() const; -};*/ -// removed - just made item inherit from statement - /* Variable assignment let statement - type of "declaration statement" as it * introduces new name into scope */ class LetStmt : public Stmt { public: // bool has_outer_attrs; - ::std::vector<Attribute> outer_attrs; + std::vector<Attribute> outer_attrs; - // Pattern variables_pattern; - ::std::unique_ptr<Pattern> variables_pattern; + std::unique_ptr<Pattern> variables_pattern; // bool has_type; - // Type type; - ::std::unique_ptr<Type> type; + std::unique_ptr<Type> type; // bool has_init_expr; - // Expr* init_expr; - ::std::unique_ptr<Expr> init_expr; + std::unique_ptr<Expr> init_expr; Location locus; Type *inferedType; // Returns whether let statement has outer attributes. - inline bool has_outer_attrs () const { return !outer_attrs.empty (); } + bool has_outer_attrs () const { return !outer_attrs.empty (); } // Returns whether let statement has a given return type. - inline bool has_type () const { return type != NULL; } + bool has_type () const { return type != nullptr; } // Returns whether let statement has an initialisation expression. - inline bool has_init_expr () const { return init_expr != NULL; } - - /*~LetStatement() { - if (has_init_expr) { - delete init_expr; - } - }*/ - - ::std::string as_string () const; - - LetStmt (::std::unique_ptr<Pattern> variables_pattern, - ::std::unique_ptr<Expr> init_expr, ::std::unique_ptr<Type> type, - ::std::vector<Attribute> outer_attrs, Location locus) - : outer_attrs (::std::move (outer_attrs)), - variables_pattern (::std::move (variables_pattern)), - type (::std::move (type)), init_expr (::std::move (init_expr)), - locus (locus) + bool has_init_expr () const { return init_expr != nullptr; } + + std::string as_string () const override; + + LetStmt (std::unique_ptr<Pattern> variables_pattern, + std::unique_ptr<Expr> init_expr, std::unique_ptr<Type> type, + std::vector<Attribute> outer_attrs, Location locus) + : outer_attrs (std::move (outer_attrs)), + variables_pattern (std::move (variables_pattern)), + type (std::move (type)), init_expr (std::move (init_expr)), locus (locus) {} // Copy constructor with clone @@ -99,8 +74,6 @@ public: init_expr (other.init_expr->clone_expr ()), locus (other.locus) {} - // Destructor - define here if required - // Overloaded assignment operator to clone LetStmt &operator= (LetStmt const &other) { @@ -119,19 +92,16 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual LetStmt *clone_stmt_impl () const OVERRIDE - { - return new LetStmt (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + LetStmt *clone_stmt_impl () const override { return new LetStmt (*this); } }; -// Abstract base class for expression statements (statements containing an -// expression) +/* Abstract base class for expression statements (statements containing an + * expression) */ class ExprStmt : public Stmt { // TODO: add any useful virtual functions @@ -154,19 +124,15 @@ public: /* HACK: cannot ensure type safety of ExprWithoutBlock due to Pratt parsing, * so have to store more general type of Expr. FIXME: fix this issue somehow * or redesign AST. */ - //::std::unique_ptr<ExprWithoutBlock> expr; - ::std::unique_ptr<Expr> expr; - - /*~ExpressionStatementWithoutBlock() { - delete expr; - }*/ + // std::unique_ptr<ExprWithoutBlock> expr; + std::unique_ptr<Expr> expr; - ::std::string as_string () const; + std::string as_string () const override; - // ExprStmtWithoutBlock(::std::unique_ptr<ExprWithoutBlock> expr) : - // expr(::std::move(expr)) {} - ExprStmtWithoutBlock (::std::unique_ptr<Expr> expr, Location locus) - : ExprStmt (locus), expr (::std::move (expr)) + // ExprStmtWithoutBlock(std::unique_ptr<ExprWithoutBlock> expr) : + // expr(std::move(expr)) {} + ExprStmtWithoutBlock (std::unique_ptr<Expr> expr, Location locus) + : ExprStmt (locus), expr (std::move (expr)) {} // Copy constructor with clone @@ -174,8 +140,6 @@ public: : ExprStmt (other), expr (other.expr->clone_expr /*_without_block*/ ()) {} - // Destructor - define here if required - // Overloaded assignment operator to clone ExprStmtWithoutBlock &operator= (ExprStmtWithoutBlock const &other) { @@ -189,12 +153,12 @@ public: ExprStmtWithoutBlock (ExprStmtWithoutBlock &&other) = default; ExprStmtWithoutBlock &operator= (ExprStmtWithoutBlock &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ExprStmtWithoutBlock *clone_stmt_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ExprStmtWithoutBlock *clone_stmt_impl () const override { return new ExprStmtWithoutBlock (*this); } @@ -204,19 +168,14 @@ protected: class ExprStmtWithBlock : public ExprStmt { public: - // ExprWithBlock* expr; - ::std::unique_ptr<ExprWithBlock> expr; - - /*~ExpressionStatementWithBlock() { - delete expr; - }*/ + std::unique_ptr<ExprWithBlock> expr; - ::std::string as_string () const; + std::string as_string () const override; - ::std::vector<LetStmt *> locals; + std::vector<LetStmt *> locals; - ExprStmtWithBlock (::std::unique_ptr<ExprWithBlock> expr, Location locus) - : ExprStmt (locus), expr (::std::move (expr)) + ExprStmtWithBlock (std::unique_ptr<ExprWithBlock> expr, Location locus) + : ExprStmt (locus), expr (std::move (expr)) {} // Copy constructor with clone @@ -224,8 +183,6 @@ public: : ExprStmt (other), expr (other.expr->clone_expr_with_block ()) {} - // Destructor - define here if required - // Overloaded assignment operator to clone ExprStmtWithBlock &operator= (ExprStmtWithBlock const &other) { @@ -239,24 +196,20 @@ public: ExprStmtWithBlock (ExprStmtWithBlock &&other) = default; ExprStmtWithBlock &operator= (ExprStmtWithBlock &&other) = default; - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ExprStmtWithBlock *clone_stmt_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ExprStmtWithBlock *clone_stmt_impl () const override { return new ExprStmtWithBlock (*this); } }; -// Replaced definition of MacroInvocationSemi with forward decl - defined in -// rust-macro.h +/* Replaced definition of MacroInvocationSemi with forward decl - defined in + * rust-macro.h */ class MacroInvocationSemi; -/*class MacroInvocationSemi : public Statement { - public: - ::std::string as_string() const; -};*/ } // namespace AST } // namespace Rust diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index cacdd55..b396a44 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -18,7 +18,7 @@ class TraitBound : public TypeParamBound // bool has_for_lifetimes; // LifetimeParams for_lifetimes; - ::std::vector<LifetimeParam> for_lifetimes; // inlined LifetimeParams + std::vector<LifetimeParam> for_lifetimes; // inlined LifetimeParams TypePath type_path; @@ -26,26 +26,27 @@ class TraitBound : public TypeParamBound public: // Returns whether trait bound has "for" lifetimes - inline bool has_for_lifetimes () const { return !for_lifetimes.empty (); } + bool has_for_lifetimes () const { return !for_lifetimes.empty (); } TraitBound (TypePath type_path, Location locus, bool in_parens = false, bool opening_question_mark = false, - ::std::vector<LifetimeParam> for_lifetimes - = ::std::vector<LifetimeParam> ()) + std::vector<LifetimeParam> for_lifetimes + = std::vector<LifetimeParam> ()) : in_parens (in_parens), opening_question_mark (opening_question_mark), - for_lifetimes (::std::move (for_lifetimes)), - type_path (::std::move (type_path)), locus (locus) + for_lifetimes (std::move (for_lifetimes)), + type_path (std::move (type_path)), locus (locus) {} - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Clone function implementation as (not pure) virtual method - virtual TraitBound *clone_type_param_bound_impl () const + /* Use covariance to implement clone function as returning this object rather + * than base */ + TraitBound *clone_type_param_bound_impl () const override { return new TraitBound (*this); } @@ -58,51 +59,42 @@ class TypeNoBounds; class ImplTraitType : public Type { // TypeParamBounds type_param_bounds; - ::std::vector< ::std::unique_ptr<TypeParamBound> > - type_param_bounds; // inlined form + // inlined form + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds; Location locus; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ImplTraitType *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ImplTraitType *clone_type_impl () const override { return new ImplTraitType (*this); } public: ImplTraitType ( - ::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds, + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds, Location locus) - : type_param_bounds (::std::move (type_param_bounds)), locus (locus) + : type_param_bounds (std::move (type_param_bounds)), locus (locus) {} // copy constructor with vector clone ImplTraitType (ImplTraitType const &other) : locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); } // overloaded assignment operator to clone ImplTraitType &operator= (ImplTraitType const &other) { locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? - type_param_bounds.reserve (other.type_param_bounds.size ()); + type_param_bounds.reserve (other.type_param_bounds.size ()); for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); return *this; } @@ -111,11 +103,11 @@ public: ImplTraitType (ImplTraitType &&other) = default; ImplTraitType &operator= (ImplTraitType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; // An opaque value of another type that implements a set of traits @@ -123,39 +115,34 @@ class TraitObjectType : public Type { bool has_dyn; // TypeParamBounds type_param_bounds; - ::std::vector< ::std::unique_ptr<TypeParamBound> > + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds; // inlined form Location locus; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TraitObjectType *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TraitObjectType *clone_type_impl () const override { return new TraitObjectType (*this); } public: TraitObjectType ( - ::std::vector< ::std::unique_ptr<TypeParamBound> > type_param_bounds, + std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds, Location locus, bool is_dyn_dispatch = false) : has_dyn (is_dyn_dispatch), - type_param_bounds (::std::move (type_param_bounds)), locus (locus) + type_param_bounds (std::move (type_param_bounds)), locus (locus) {} // copy constructor with vector clone TraitObjectType (TraitObjectType const &other) : has_dyn (other.has_dyn), locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); } // overloaded assignment operator to clone @@ -163,14 +150,9 @@ public: { has_dyn = other.has_dyn; locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? type_param_bounds.reserve (other.type_param_bounds.size ()); - for (const auto &e : other.type_param_bounds) - { - type_param_bounds.push_back (e->clone_type_param_bound ()); - } + type_param_bounds.push_back (e->clone_type_param_bound ()); return *this; } @@ -179,50 +161,46 @@ public: TraitObjectType (TraitObjectType &&other) = default; TraitObjectType &operator= (TraitObjectType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; // A type with parentheses around it, used to avoid ambiguity. class ParenthesisedType : public TypeNoBounds { - // Type type_in_parens; - ::std::unique_ptr<Type> type_in_parens; - + std::unique_ptr<Type> type_in_parens; Location locus; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ParenthesisedType *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ParenthesisedType *clone_type_impl () const override { return new ParenthesisedType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ParenthesisedType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ParenthesisedType *clone_type_no_bounds_impl () const override { return new ParenthesisedType (*this); } public: // Constructor uses Type pointer for polymorphism - ParenthesisedType (::std::unique_ptr<Type> type_inside_parens, Location locus) - : type_in_parens (::std::move (type_inside_parens)), locus (locus) + ParenthesisedType (std::unique_ptr<Type> type_inside_parens, Location locus) + : type_in_parens (std::move (type_inside_parens)), locus (locus) {} - // Copy constructor uses custom deep copy method for type to preserve - // polymorphism + /* Copy constructor uses custom deep copy method for type to preserve + * polymorphism */ ParenthesisedType (ParenthesisedType const &other) : type_in_parens (other.type_in_parens->clone_type ()), locus (other.locus) {} - // define destructor here if required - // overload assignment operator to use custom clone method ParenthesisedType &operator= (ParenthesisedType const &other) { @@ -235,14 +213,13 @@ public: ParenthesisedType (ParenthesisedType &&other) = default; ParenthesisedType &operator= (ParenthesisedType &&other) = default; - ::std::string as_string () const + std::string as_string () const override { return "(" + type_in_parens->as_string () + ")"; } // Creates a trait bound (clone of this one's trait bound) - HACK - virtual TraitBound * - to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const OVERRIDE + TraitBound *to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const override { /* NOTE: obviously it is unknown whether the internal type is a trait bound * due to polymorphism, so just let the internal type handle it. As @@ -252,7 +229,7 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; // Impl trait with a single bound? Poor reference material here. @@ -263,30 +240,30 @@ class ImplTraitTypeOneBound : public TypeNoBounds Location locus; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ImplTraitTypeOneBound *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ImplTraitTypeOneBound *clone_type_impl () const override { return new ImplTraitTypeOneBound (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ImplTraitTypeOneBound *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ImplTraitTypeOneBound *clone_type_no_bounds_impl () const override { return new ImplTraitTypeOneBound (*this); } public: ImplTraitTypeOneBound (TraitBound trait_bound, Location locus) - : trait_bound (::std::move (trait_bound)), locus (locus) + : trait_bound (std::move (trait_bound)), locus (locus) {} - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; /* A trait object with a single trait bound. The "trait bound" is really just @@ -299,16 +276,16 @@ class TraitObjectTypeOneBound : public TypeNoBounds Location locus; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TraitObjectTypeOneBound *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TraitObjectTypeOneBound *clone_type_impl () const override { return new TraitObjectTypeOneBound (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual TraitObjectTypeOneBound *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TraitObjectTypeOneBound *clone_type_no_bounds_impl () const override { return new TraitObjectTypeOneBound (*this); } @@ -316,15 +293,14 @@ protected: public: TraitObjectTypeOneBound (TraitBound trait_bound, Location locus, bool is_dyn_dispatch = false) - : has_dyn (is_dyn_dispatch), trait_bound (::std::move (trait_bound)), + : has_dyn (is_dyn_dispatch), trait_bound (std::move (trait_bound)), locus (locus) {} - ::std::string as_string () const; + std::string as_string () const override; // Creates a trait bound (clone of this one's trait bound) - HACK - virtual TraitBound * - to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const OVERRIDE + TraitBound *to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const override { /* NOTE: this assumes there is no dynamic dispatch specified- if there was, * this cloning would not be required as parsing is unambiguous. */ @@ -333,53 +309,42 @@ public: Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; class TypePath; // definition moved to "rust-path.h" -// A type consisting of the "product" of others (the tuple's elements) in a -// specific order +/* A type consisting of the "product" of others (the tuple's elements) in a + * specific order */ class TupleType : public TypeNoBounds { - //::std::vector<Type> elems; - ::std::vector< ::std::unique_ptr<Type> > elems; - + std::vector<std::unique_ptr<Type>> elems; Location locus; public: // Returns whether the tuple type is the unit type, i.e. has no elements. - inline bool is_unit_type () const { return elems.empty (); } + bool is_unit_type () const { return elems.empty (); } - TupleType (::std::vector< ::std::unique_ptr<Type> > elems, Location locus) - : elems (::std::move (elems)), locus (locus) + TupleType (std::vector<std::unique_ptr<Type>> elems, Location locus) + : elems (std::move (elems)), locus (locus) {} // copy constructor with vector clone TupleType (TupleType const &other) : locus (other.locus) { - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? elems.reserve (other.elems.size ()); - for (const auto &e : other.elems) - { - elems.push_back (e->clone_type ()); - } + elems.push_back (e->clone_type ()); } // overloaded assignment operator to clone TupleType &operator= (TupleType const &other) { locus = other.locus; - // crappy vector unique pointer clone - TODO is there a better way of doing - // this? - elems.reserve (other.elems.size ()); + elems.reserve (other.elems.size ()); for (const auto &e : other.elems) - { - elems.push_back (e->clone_type ()); - } + elems.push_back (e->clone_type ()); return *this; } @@ -388,23 +353,20 @@ public: TupleType (TupleType &&other) = default; TupleType &operator= (TupleType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleType *clone_type_impl () const OVERRIDE - { - return new TupleType (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleType *clone_type_impl () const override { return new TupleType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual TupleType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + TupleType *clone_type_no_bounds_impl () const override { return new TupleType (*this); } @@ -418,16 +380,13 @@ class NeverType : public TypeNoBounds Location locus; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual NeverType *clone_type_impl () const OVERRIDE - { - return new NeverType (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + NeverType *clone_type_impl () const override { return new NeverType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual NeverType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + NeverType *clone_type_no_bounds_impl () const override { return new NeverType (*this); } @@ -435,11 +394,11 @@ protected: public: NeverType (Location locus) : locus (locus) {} - ::std::string as_string () const { return "! (never type)"; } + std::string as_string () const override { return "! (never type)"; } Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; // A type consisting of a pointer without safety or liveness guarantees @@ -454,21 +413,17 @@ public: private: PointerType pointer_type; - - // TypeNoBounds type; - ::std::unique_ptr<TypeNoBounds> type; - + std::unique_ptr<TypeNoBounds> type; Location locus; public: // Returns whether the pointer is mutable or constant. - inline PointerType get_pointer_type () const { return pointer_type; } + PointerType get_pointer_type () const { return pointer_type; } // Constructor requires pointer for polymorphism reasons RawPointerType (PointerType pointer_type, - ::std::unique_ptr<TypeNoBounds> type_no_bounds, - Location locus) - : pointer_type (pointer_type), type (::std::move (type_no_bounds)), + std::unique_ptr<TypeNoBounds> type_no_bounds, Location locus) + : pointer_type (pointer_type), type (std::move (type_no_bounds)), locus (locus) {} @@ -478,8 +433,6 @@ public: type (other.type->clone_type_no_bounds ()), locus (other.locus) {} - // no destructor required? - // overload assignment operator to use custom clone method RawPointerType &operator= (RawPointerType const &other) { @@ -493,23 +446,23 @@ public: RawPointerType (RawPointerType &&other) = default; RawPointerType &operator= (RawPointerType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual RawPointerType *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RawPointerType *clone_type_impl () const override { return new RawPointerType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual RawPointerType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + RawPointerType *clone_type_no_bounds_impl () const override { return new RawPointerType (*this); } @@ -522,24 +475,21 @@ class ReferenceType : public TypeNoBounds Lifetime lifetime; bool has_mut; - - // TypeNoBounds type; - ::std::unique_ptr<TypeNoBounds> type; - + std::unique_ptr<TypeNoBounds> type; Location locus; public: // Returns whether the reference is mutable or immutable. - inline bool is_mut () const { return has_mut; } + bool is_mut () const { return has_mut; } // Returns whether the reference has a lifetime. - inline bool has_lifetime () const { return !lifetime.is_error (); } + bool has_lifetime () const { return !lifetime.is_error (); } // Constructor - ReferenceType (bool is_mut, ::std::unique_ptr<TypeNoBounds> type_no_bounds, + ReferenceType (bool is_mut, std::unique_ptr<TypeNoBounds> type_no_bounds, Location locus, Lifetime lifetime = Lifetime::error ()) - : lifetime (::std::move (lifetime)), has_mut (is_mut), - type (::std::move (type_no_bounds)), locus (locus) + : lifetime (std::move (lifetime)), has_mut (is_mut), + type (std::move (type_no_bounds)), locus (locus) {} // Copy constructor with custom clone method @@ -548,8 +498,6 @@ public: type (other.type->clone_type_no_bounds ()), locus (other.locus) {} - // Destructor not required? - // Operator overload assignment operator to custom clone the unique pointer ReferenceType &operator= (ReferenceType const &other) { @@ -565,23 +513,23 @@ public: ReferenceType (ReferenceType &&other) = default; ReferenceType &operator= (ReferenceType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ReferenceType *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ReferenceType *clone_type_impl () const override { return new ReferenceType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ReferenceType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ReferenceType *clone_type_no_bounds_impl () const override { return new ReferenceType (*this); } @@ -590,19 +538,15 @@ protected: // A fixed-size sequence of elements of a specified type class ArrayType : public TypeNoBounds { - // Type elem_type; - ::std::unique_ptr<Type> elem_type; - // Expr* size; - ::std::unique_ptr<Expr> size; - + std::unique_ptr<Type> elem_type; + std::unique_ptr<Expr> size; Location locus; public: // Constructor requires pointers for polymorphism - ArrayType (::std::unique_ptr<Type> type, ::std::unique_ptr<Expr> array_size, + ArrayType (std::unique_ptr<Type> type, std::unique_ptr<Expr> array_size, Location locus) - : elem_type (::std::move (type)), size (::std::move (array_size)), - locus (locus) + : elem_type (std::move (type)), size (std::move (array_size)), locus (locus) {} // Copy constructor requires deep copies of both unique pointers @@ -611,8 +555,6 @@ public: size (other.size->clone_expr ()), locus (other.locus) {} - // destructor not required? - // Overload assignment operator to deep copy pointers ArrayType &operator= (ArrayType const &other) { @@ -626,44 +568,36 @@ public: ArrayType (ArrayType &&other) = default; ArrayType &operator= (ArrayType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; - /*~ArrayType() { - delete size; - }*/ protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual ArrayType *clone_type_impl () const OVERRIDE - { - return new ArrayType (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + ArrayType *clone_type_impl () const override { return new ArrayType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual ArrayType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + ArrayType *clone_type_no_bounds_impl () const override { return new ArrayType (*this); } }; -// A dynamically-sized type representing a "view" into a sequence of elements of -// a type +/* A dynamically-sized type representing a "view" into a sequence of elements of + * a type */ class SliceType : public TypeNoBounds { - // Type elem_type; - ::std::unique_ptr<Type> elem_type; - + std::unique_ptr<Type> elem_type; Location locus; public: // Constructor requires pointer for polymorphism - SliceType (::std::unique_ptr<Type> type, Location locus) - : elem_type (::std::move (type)), locus (locus) + SliceType (std::unique_ptr<Type> type, Location locus) + : elem_type (std::move (type)), locus (locus) {} // Copy constructor requires deep copy of Type smart pointer @@ -671,8 +605,6 @@ public: : elem_type (other.elem_type->clone_type ()), locus (other.locus) {} - // destructor not required? - // Overload assignment operator to deep copy SliceType &operator= (SliceType const &other) { @@ -686,46 +618,43 @@ public: SliceType (SliceType &&other) = default; SliceType &operator= (SliceType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual SliceType *clone_type_impl () const OVERRIDE - { - return new SliceType (*this); - } + /* Use covariance to implement clone function as returning this object rather + * than base */ + SliceType *clone_type_impl () const override { return new SliceType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual SliceType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + SliceType *clone_type_no_bounds_impl () const override { return new SliceType (*this); } }; -// Type used in generic arguments to explicitly request type inference (wildcard -// pattern) +/* Type used in generic arguments to explicitly request type inference (wildcard + * pattern) */ class InferredType : public TypeNoBounds { Location locus; // e.g. Vec<_> = whatever protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual InferredType *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + InferredType *clone_type_impl () const override { return new InferredType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual InferredType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + InferredType *clone_type_no_bounds_impl () const override { return new InferredType (*this); } @@ -733,11 +662,11 @@ protected: public: InferredType (Location locus) : locus (locus) {} - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; }; class QualifiedPathInType; // definition moved to "rust-path.h" @@ -754,8 +683,7 @@ public: }; private: - // Type param_type; - ::std::unique_ptr<Type> param_type; + std::unique_ptr<Type> param_type; ParamKind param_kind; Identifier name; // technically, can be an identifier or '_' @@ -764,9 +692,9 @@ private: public: MaybeNamedParam (Identifier name, ParamKind param_kind, - ::std::unique_ptr<Type> param_type, Location locus) - : param_type (::std::move (param_type)), param_kind (param_kind), - name (::std::move (name)), locus (locus) + std::unique_ptr<Type> param_type, Location locus) + : param_type (std::move (param_type)), param_kind (param_kind), + name (std::move (name)), locus (locus) {} // Copy constructor with clone @@ -792,15 +720,15 @@ public: MaybeNamedParam (MaybeNamedParam &&other) = default; MaybeNamedParam &operator= (MaybeNamedParam &&other) = default; - ::std::string as_string () const; + std::string as_string () const; // Returns whether the param is in an error state. - inline bool is_error () const { return param_type == NULL; } + bool is_error () const { return param_type == nullptr; } // Creates an error state param. static MaybeNamedParam create_error () { - return MaybeNamedParam ("", UNNAMED, NULL, Location ()); + return MaybeNamedParam ("", UNNAMED, nullptr, Location ()); } Location get_locus () const { return locus; } @@ -812,34 +740,33 @@ class BareFunctionType : public TypeNoBounds { // bool has_for_lifetimes; // ForLifetimes for_lifetimes; - ::std::vector<LifetimeParam> for_lifetimes; // inlined version + std::vector<LifetimeParam> for_lifetimes; // inlined version FunctionQualifiers function_qualifiers; - ::std::vector<MaybeNamedParam> params; + std::vector<MaybeNamedParam> params; bool is_variadic; // bool has_return_type; // BareFunctionReturnType return_type; - ::std::unique_ptr<TypeNoBounds> return_type; // inlined version + std::unique_ptr<TypeNoBounds> return_type; // inlined version Location locus; public: // Whether a return type is defined with the function. - inline bool has_return_type () const { return return_type != NULL; } + bool has_return_type () const { return return_type != nullptr; } // Whether the function has ForLifetimes. - inline bool has_for_lifetimes () const { return !for_lifetimes.empty (); } + bool has_for_lifetimes () const { return !for_lifetimes.empty (); } - BareFunctionType (::std::vector<LifetimeParam> lifetime_params, + BareFunctionType (std::vector<LifetimeParam> lifetime_params, FunctionQualifiers qualifiers, - ::std::vector<MaybeNamedParam> named_params, - bool is_variadic, ::std::unique_ptr<TypeNoBounds> type, - Location locus) - : for_lifetimes (::std::move (lifetime_params)), - function_qualifiers (::std::move (qualifiers)), - params (::std::move (named_params)), is_variadic (is_variadic), - return_type (::std::move (type)), locus (locus) + std::vector<MaybeNamedParam> named_params, bool is_variadic, + std::unique_ptr<TypeNoBounds> type, Location locus) + : for_lifetimes (std::move (lifetime_params)), + function_qualifiers (std::move (qualifiers)), + params (std::move (named_params)), is_variadic (is_variadic), + return_type (std::move (type)), locus (locus) {} // Copy constructor with clone @@ -851,8 +778,6 @@ public: locus (other.locus) {} - // destructor - define here if required - // Overload assignment operator to deep copy BareFunctionType &operator= (BareFunctionType const &other) { @@ -870,23 +795,23 @@ public: BareFunctionType (BareFunctionType &&other) = default; BareFunctionType &operator= (BareFunctionType &&other) = default; - ::std::string as_string () const; + std::string as_string () const override; Location get_locus () const { return locus; } - virtual void accept_vis (ASTVisitor &vis) OVERRIDE; + void accept_vis (ASTVisitor &vis) override; protected: - // Use covariance to implement clone function as returning this object rather - // than base - virtual BareFunctionType *clone_type_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + BareFunctionType *clone_type_impl () const override { return new BareFunctionType (*this); } - // Use covariance to implement clone function as returning this object rather - // than base - virtual BareFunctionType *clone_type_no_bounds_impl () const OVERRIDE + /* Use covariance to implement clone function as returning this object rather + * than base */ + BareFunctionType *clone_type_no_bounds_impl () const override { return new BareFunctionType (*this); } @@ -895,11 +820,6 @@ protected: // Forward decl - defined in rust-macro.h class MacroInvocation; -/*// AST node of a macro invocation, which is replaced by the macro result at -compile time class MacroInvocation : public TypeNoBounds, public Pattern, public -ExprWithoutBlock { SimplePath path; DelimTokenTree token_tree; -};*/ - /* TODO: possible types * struct type? * "enum" (tagged union) type? diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 1f0f9cb..ac174ad 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -95,10 +95,13 @@ is_whitespace (char character) return ISSPACE (character); } -Lexer::Lexer (const char *filename, FILE *input, Linemap *linemap) - : input (input), current_line (1), current_column (1), line_map (linemap), - input_source (input), input_queue (input_source), token_source (this), - token_queue (token_source) +// this compiles fine, so any intellisense saying otherwise is fake news +Lexer::Lexer (const char *filename, RAIIFile file_input, Linemap *linemap) + : input (std::move (file_input)), current_line (1), current_column (1), line_map (linemap), + /*input_source (input.get_raw ()), */ + input_queue {InputSource (input.get_raw ())}, + /*token_source (this),*/ + token_queue (TokenSource (this)) { // inform line_table that file is being entered and is in line 1 line_map->start_file (filename, current_line); @@ -156,6 +159,8 @@ void Lexer::replace_current_token (TokenPtr replacement) { token_queue.replace_current_value (replacement); + + fprintf(stderr, "called 'replace_current_token' - this is deprecated"); } /* shitty anonymous namespace that can only be accessed inside the compilation @@ -1000,8 +1005,8 @@ Lexer::parse_escape (char opening_char) return std::make_tuple (output_char, additional_length_offset, false); } -// Parses an escape (or string continue) in a string or character. Supports -// unicode escapes. +/* Parses an escape (or string continue) in a string or character. Supports + * unicode escapes. */ std::tuple<Codepoint, int, bool> Lexer::parse_utf8_escape (char opening_char) { @@ -1983,6 +1988,7 @@ Lexer::parse_char_or_lifetime (Location loc) { rust_error_at (get_current_location (), "expected ' after character constant in char literal"); + return nullptr; } } } @@ -2289,4 +2295,15 @@ Lexer::test_peek_codepoint_input (int n) UTF-8 (too long)"); return 0xFFFE; }*/ } + +void +Lexer::split_current_token (TokenId new_left, TokenId new_right) { + // TODO: assert that this TokenId is a "simple token" like punctuation and not like "IDENTIFIER"? + Location current_loc = peek_token ()->get_locus(); + TokenPtr new_left_tok = Token::make (new_left, current_loc); + TokenPtr new_right_tok = Token::make (new_right, current_loc + 1); + + token_queue.replace_current_value (std::move (new_left_tok)); + token_queue.insert (1, std::move (new_right_tok)); +} } // namespace Rust diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h index 8a031ed..5ac3a4b 100644 --- a/gcc/rust/lex/rust-lex.h +++ b/gcc/rust/lex/rust-lex.h @@ -9,6 +9,36 @@ #include <tuple> namespace Rust { +// Simple wrapper for FILE* that simplifies destruction. +struct RAIIFile +{ +private: + FILE *file; + +public: + RAIIFile (const char *filename) : file (fopen (filename, "r")) {} + RAIIFile (const RAIIFile &other) = delete; + RAIIFile &operator= (const RAIIFile &other) = delete; + + // have to specify setting file to nullptr, otherwise unintended fclose occurs + RAIIFile (RAIIFile &&other) : file (other.file) { other.file = nullptr; } + RAIIFile &operator= (RAIIFile &&other) + { + file = other.file; + other.file = nullptr; + + return *this; + } + + ~RAIIFile () + { + if (file != nullptr) + fclose (file); + } + + FILE *get_raw () { return file; } +}; + class Lexer { private: @@ -65,7 +95,7 @@ private: public: // Construct lexer with input file and filename provided - Lexer (const char *filename, FILE *input, Linemap *linemap); + Lexer (const char *filename, RAIIFile input, Linemap *linemap); ~Lexer (); // don't allow copy semantics (for now, at least) @@ -88,12 +118,19 @@ public: // Replaces the current token with a specified token. void replace_current_token (TokenPtr replacement); + // FIXME: don't use anymore + + /* Splits the current token into two. Intended for use with nested generics + * closes (i.e. T<U<X>> where >> is wrongly lexed as one token). Note that + * this will only work with "simple" tokens like punctuation. */ + void split_current_token (TokenId new_left, TokenId new_right); Linemap *get_line_map () { return line_map; } private: // File for use as input. - FILE *input; + RAIIFile input; + // TODO is this actually required? could just have file storage in InputSource // Current line number. int current_line; @@ -104,8 +141,8 @@ private: // Line map. Linemap *line_map; - // Max column number that can be quickly allocated - higher may require - // allocating new linemap + /* Max column number that can be quickly allocated - higher may require + * allocating new linemap */ static const int max_column_hint = 80; // Input source wrapper thing. @@ -122,7 +159,7 @@ private: }; // The input source for the lexer. - InputSource input_source; + // InputSource input_source; // Input file queue. buffered_queue<int, InputSource> input_queue; @@ -140,7 +177,7 @@ private: }; // The token source for the lexer. - TokenSource token_source; + // TokenSource token_source; // Token stream queue. buffered_queue<std::shared_ptr<Token>, TokenSource> token_queue; }; diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc index d8bd661..84462e6 100644 --- a/gcc/rust/lex/rust-token.cc +++ b/gcc/rust/lex/rust-token.cc @@ -21,8 +21,8 @@ get_token_description (TokenId id) } } -// Hackily defined way to get token description as a string for enum value using -// x-macros +/* Hackily defined way to get token description as a string for enum value using + * x-macros */ const char * token_id_to_str (TokenId id) { @@ -93,14 +93,14 @@ Token::get_type_hint_str () const return get_type_hint_string (type_hint); } -const ::std::string & +const std::string & Token::get_str () const { // FIXME: attempt to return null again // gcc_assert(str != NULL); // HACK: allow referencing an empty string - static const ::std::string empty = ""; + static const std::string empty = ""; if (str == NULL) { diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index 9dd5f0b..2193181 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -8,8 +8,6 @@ // order: config, system, coretypes, input #include <string> -//#include <tr1/memory> // as shared_ptr is not available in std memory in c++03 -// replace with proper std::memory in c++11 #include <memory> #include "rust-linemap.h" @@ -51,8 +49,8 @@ enum PrimitiveCoreType // // Keep RS_TOKEN_KEYWORD sorted -// note that abstract, async, become, box, do, final, macro, override, priv, -// try, typeof, unsized, virtual, and yield are unused +/* note that abstract, async, become, box, do, final, macro, override, priv, + * try, typeof, unsized, virtual, and yield are unused */ #define RS_TOKEN_LIST \ RS_TOKEN (FIRST_TOKEN, "<first-token-marker>") \ RS_TOKEN (END_OF_FILE, "end of file") \ @@ -146,7 +144,7 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD (AS, "as") \ RS_TOKEN_KEYWORD (ASYNC, "async") /* unused */ \ RS_TOKEN_KEYWORD (BECOME, "become") /* unused */ \ - RS_TOKEN_KEYWORD (BOX, "box") /* unused */ \ + RS_TOKEN_KEYWORD (BOX, "box") /* unused */ \ RS_TOKEN_KEYWORD (BREAK, "break") \ RS_TOKEN_KEYWORD (CONST, "const") \ RS_TOKEN_KEYWORD (CONTINUE, "continue") \ @@ -171,7 +169,7 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD (MOVE, "move") \ RS_TOKEN_KEYWORD (MUT, "mut") \ RS_TOKEN_KEYWORD (OVERRIDE_TOK, "override") /* unused */ \ - RS_TOKEN_KEYWORD (PRIV, "priv") /* unused */ \ + RS_TOKEN_KEYWORD (PRIV, "priv") /* unused */ \ RS_TOKEN_KEYWORD (PUB, "pub") \ RS_TOKEN_KEYWORD (REF, "ref") \ RS_TOKEN_KEYWORD (RETURN_TOK, "return") \ @@ -209,15 +207,15 @@ enum TokenId // dodgy "TokenPtr" declaration with Token forward declaration class Token; // A smart pointer (shared_ptr) to Token. -typedef ::std::shared_ptr<Token> TokenPtr; +typedef std::shared_ptr<Token> TokenPtr; // A smart pointer (shared_ptr) to a constant Token. -typedef ::std::shared_ptr<const Token> const_TokenPtr; +typedef std::shared_ptr<const Token> const_TokenPtr; // Hackily defined way to get token description for enum value using x-macros const char * get_token_description (TokenId id); -// Hackily defined way to get token description as a string for enum value using -// x-macros +/* Hackily defined way to get token description as a string for enum value using + * x-macros */ const char * token_id_to_str (TokenId id); // Get type hint description as a string. @@ -233,117 +231,136 @@ private: // Token location. Location locus; // Associated text (if any) of token. - ::std::string *str; - // Type hint for token based on lexer data (e.g. type suffix). Does not exist - // for most tokens. + std::string *str; + // TODO: maybe remove issues and just store std::string as value? + /* Type hint for token based on lexer data (e.g. type suffix). Does not exist + * for most tokens. */ PrimitiveCoreType type_hint; // Token constructor from token id and location. Has a null string. Token (TokenId token_id, Location location) - : token_id (token_id), locus (location), str (NULL), + : token_id (token_id), locus (location), str (nullptr), type_hint (CORETYPE_UNKNOWN) {} // Token constructor from token id, location, and a string. - Token (TokenId token_id, Location location, const ::std::string ¶mStr) - : token_id (token_id), locus (location), str (new ::std::string (paramStr)), + Token (TokenId token_id, Location location, const std::string ¶mStr) + : token_id (token_id), locus (location), str (new std::string (paramStr)), type_hint (CORETYPE_UNKNOWN) {} // Token constructor from token id, location, and a char. Token (TokenId token_id, Location location, char paramChar) : token_id (token_id), locus (location), - str (new ::std::string (1, paramChar)), type_hint (CORETYPE_UNKNOWN) + str (new std::string (1, paramChar)), type_hint (CORETYPE_UNKNOWN) {} // Token constructor from token id, location, and a "codepoint". Token (TokenId token_id, Location location, Codepoint paramCodepoint) : token_id (token_id), locus (location), - str (new ::std::string (paramCodepoint.as_string ())), + str (new std::string (paramCodepoint.as_string ())), type_hint (CORETYPE_UNKNOWN) {} // Token constructor from token id, location, a string, and type hint. - Token (TokenId token_id, Location location, const ::std::string ¶mStr, + Token (TokenId token_id, Location location, const std::string ¶mStr, PrimitiveCoreType parType) - : token_id (token_id), locus (location), str (new ::std::string (paramStr)), + : token_id (token_id), locus (location), str (new std::string (paramStr)), type_hint (parType) {} - // No default initialiser. - Token (); +public: + // No default constructor. + Token () = delete; // Do not copy/assign tokens. - Token (const Token &); - Token &operator= (const Token &); + Token (const Token &) = delete; + Token &operator= (const Token &) = delete; + + // Allow moving tokens. + Token (Token &&other) = default; + Token &operator= (Token &&other) = default; -public: ~Token () { delete str; } + /* TODO: make_shared (which saves a heap allocation) does not work with the + * private constructor */ + // Makes and returns a new TokenPtr (with null string). static TokenPtr make (TokenId token_id, Location locus) { + // return std::make_shared<Token> (token_id, locus); return TokenPtr (new Token (token_id, locus)); } // Makes and returns a new TokenPtr of type IDENTIFIER. - static TokenPtr make_identifier (Location locus, const ::std::string &str) + static TokenPtr make_identifier (Location locus, const std::string &str) { + // return std::make_shared<Token> (IDENTIFIER, locus, str); return TokenPtr (new Token (IDENTIFIER, locus, str)); } // Makes and returns a new TokenPtr of type INT_LITERAL. - static TokenPtr make_int (Location locus, const ::std::string &str) + /*static TokenPtr make_int (Location locus, const std::string &str) { - return TokenPtr (new Token (INT_LITERAL, locus, str)); - } + //return TokenPtr (new Token (INT_LITERAL, locus, str)); + return std::make_shared<Token>(INT_LITERAL, locus, str); + }*/ // Makes and returns a new TokenPtr of type INT_LITERAL. - static TokenPtr make_int (Location locus, const ::std::string &str, - PrimitiveCoreType type_hint) + static TokenPtr make_int (Location locus, const std::string &str, + PrimitiveCoreType type_hint = CORETYPE_UNKNOWN) { + // return std::make_shared<Token> (INT_LITERAL, locus, str, type_hint); return TokenPtr (new Token (INT_LITERAL, locus, str, type_hint)); } // Makes and returns a new TokenPtr of type FLOAT_LITERAL. - static TokenPtr make_float (Location locus, const ::std::string &str) + /*static TokenPtr make_float (Location locus, const std::string &str) { return TokenPtr (new Token (FLOAT_LITERAL, locus, str)); - } + return std::make_shared<Token>(FLOAT_LITERAL, locus, str); + }*/ // Makes and returns a new TokenPtr of type FLOAT_LITERAL. - static TokenPtr make_float (Location locus, const ::std::string &str, - PrimitiveCoreType type_hint) + static TokenPtr make_float (Location locus, const std::string &str, + PrimitiveCoreType type_hint = CORETYPE_UNKNOWN) { + // return std::make_shared<Token> (FLOAT_LITERAL, locus, str, type_hint); return TokenPtr (new Token (FLOAT_LITERAL, locus, str, type_hint)); } // Makes and returns a new TokenPtr of type STRING_LITERAL. - static TokenPtr make_string (Location locus, const ::std::string &str) + static TokenPtr make_string (Location locus, const std::string &str) { + // return std::make_shared<Token> (STRING_LITERAL, locus, str, CORETYPE_STR); return TokenPtr (new Token (STRING_LITERAL, locus, str, CORETYPE_STR)); } - // Makes and returns a new TokenPtr of type CHAR_LITERAL (fix). + // Makes and returns a new TokenPtr of type CHAR_LITERAL. static TokenPtr make_char (Location locus, Codepoint char_lit) { + // return std::make_shared<Token> (CHAR_LITERAL, locus, char_lit); return TokenPtr (new Token (CHAR_LITERAL, locus, char_lit)); } - // Makes and returns a new TokenPtr of type BYTE_CHAR_LITERAL (fix). + // Makes and returns a new TokenPtr of type BYTE_CHAR_LITERAL. static TokenPtr make_byte_char (Location locus, char byte_char) { + // return std::make_shared<Token> (BYTE_CHAR_LITERAL, locus, byte_char); return TokenPtr (new Token (BYTE_CHAR_LITERAL, locus, byte_char)); } // Makes and returns a new TokenPtr of type BYTE_STRING_LITERAL (fix). - static TokenPtr make_byte_string (Location locus, const ::std::string &str) + static TokenPtr make_byte_string (Location locus, const std::string &str) { + // return std::make_shared<Token> (BYTE_STRING_LITERAL, locus, str); return TokenPtr (new Token (BYTE_STRING_LITERAL, locus, str)); } // Makes and returns a new TokenPtr of type LIFETIME. - static TokenPtr make_lifetime (Location locus, const ::std::string &str) + static TokenPtr make_lifetime (Location locus, const std::string &str) { + // return std::make_shared<Token> (LIFETIME, locus, str); return TokenPtr (new Token (LIFETIME, locus, str)); } @@ -354,11 +371,11 @@ public: Location get_locus () const { return locus; } // Gets string description of the token. - const ::std::string & + const std::string & get_str () const; /*{ // FIXME: put in header again when fix null problem -//gcc_assert(str != NULL); -if (str == NULL) { +//gcc_assert(str != nullptr); +if (str == nullptr) { error_at(get_locus(), "attempted to get string for '%s', which has no string. returning empty string instead.", get_token_description()); return ""; } @@ -385,7 +402,7 @@ return *str; /* Returns whether the token is a literal of any type (int, float, char, * string, byte char, byte string). */ - inline bool is_literal () const + bool is_literal () const { switch (token_id) { @@ -401,12 +418,12 @@ return *str; } } - // Returns whether the token actually has a string (regardless of whether it - // should or not). - inline bool has_str () const { return str != NULL; } + /* Returns whether the token actually has a string (regardless of whether it + * should or not). */ + bool has_str () const { return str != nullptr; } // Returns whether the token should have a string. - inline bool should_have_str () const + bool should_have_str () const { return is_literal () || token_id == IDENTIFIER || token_id == LIFETIME; } diff --git a/gcc/rust/rust-buffered-queue.h b/gcc/rust/rust-buffered-queue.h index f56aaff..ac9ffa1 100644 --- a/gcc/rust/rust-buffered-queue.h +++ b/gcc/rust/rust-buffered-queue.h @@ -8,13 +8,25 @@ // order: config, system namespace Rust { -// Buffered queue implementation. Items are of type T, queue source is of type -// Source. +/* Buffered queue implementation. Items are of type T, queue source is of type + * Source. Note that this is owning of the source. */ template <typename T, typename Source> class buffered_queue { public: - // Construct empty queue from Source& src. - buffered_queue (Source &src) : source (src), start (0), end (0), buffer () {} + // Construct empty queue from Source src. + buffered_queue (Source src) + : source (std::move (src)), start (0), end (0), buffer () + {} + + /* disable copying (since source is probably non-copyable) + * TODO is this actually a good idea? If source is non-copyable, it would + * just delete the copy constructor anyway.*/ + buffered_queue (const buffered_queue &other) = delete; + buffered_queue &operator= (const buffered_queue &other) = delete; + + // enable moving + buffered_queue (buffered_queue &&other) = default; + buffered_queue &operator= (buffered_queue &&other) = default; // Returns token at position start + n (i.e. n tokens ahead). T peek (int n) @@ -30,8 +42,8 @@ public: { int num_items_to_read = num_items_required - num_queued_items; - // if queue length + extra items is larger than buffer size, expand - // buffer + /* if queue length + extra items is larger than buffer size, expand + * buffer */ if (end + num_items_to_read > (int) buffer.size ()) { // Resize the buffer by 1.5x @@ -44,6 +56,8 @@ public: new_queue.begin ()); start = 0; end = num_queued_items; + // TODO: would move be better here? optimisation for move with + // shared pointer? // swap member buffer and new queue buffer std::swap (buffer, new_queue); @@ -52,12 +66,10 @@ public: gcc_assert (end + num_queued_items < (int) buffer.size ()); } - // iterate through buffer and invoke operator () on source on values - // past original end + /* iterate through buffer and invoke operator () on source on values + * past original end */ for (int i = 0; i < num_items_to_read; i++) - { - buffer[end + i] = source (); - } + buffer[end + i] = source (); // move end based on additional items added end += num_items_to_read; @@ -73,8 +85,8 @@ public: return buffer[start + n]; } - // TODO: add faster peek current token to remove overhead of conditional - // branches? + /* TODO: add faster peek current token to remove overhead of conditional + * branches? */ // Advances start by n + 1. void skip (int n) @@ -82,12 +94,9 @@ public: // Call peek to ensure requested n is actually in queue. peek (n); - // Clear values from start to n (inclusive). + // Clear queue values from start to n (inclusive). for (int i = 0; i < (n + 1); i++) - { - // Clear value at index buffer[start + i] = T (); - } // Move start forward by n + 1. start += (n + 1); @@ -98,9 +107,7 @@ public: // Compact buffer if empty if (start == end) - { - start = end = 0; - } + start = end = 0; } /* Inserts element at front of vector. Really dirty hack with terrible @@ -110,10 +117,29 @@ public: // TODO: test as this may not work properly // Insert actual element in buffer at start. - buffer.insert (buffer.begin (), 1, elem_to_insert); + buffer.insert (buffer.begin (), elem_to_insert); + + /* Increase the end number since added element means all others have shifted + * one along */ + end++; + } + + // Insert at arbitrary position (attempt) + void insert (int index, T elem_to_insert) + { + // TODO: test as this may not work properly + + // n should not be behind + gcc_assert (index >= 0); + + // call peek to ensure that the items behind this (at least) are in queue + if (index >= 1) + peek (index - 1); + else + peek (index); + + buffer.insert (buffer.begin () + start + index, std::move (elem_to_insert)); - // Increase the end number since added element means all others have shifted - // one along end++; } @@ -123,14 +149,14 @@ public: // call peek to ensure value exists peek (0); - buffer[start] = replacement; + buffer[start] = std::move (replacement); // don't move start or end } private: // Source of tokens for queue. - Source &source; + Source source; // Begin of range in buffer, inclusive. int start; diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 29933d5..6ba496d7 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -25,19 +25,10 @@ extern Backend * rust_get_backend (); namespace Rust { -// Simple wrapper for FILE* that simplifies destruction. -struct RAIIFile -{ - FILE *file; - - RAIIFile (const char *filename) : file (fopen (filename, "r")) {} - - ~RAIIFile () { fclose (file); } -}; // Implicitly enable a target_feature (and recursively enable dependencies). void -Session::implicitly_enable_feature (::std::string feature_name) +Session::implicitly_enable_feature (std::string feature_name) { // TODO: is this really required since features added would be complete via // target spec? @@ -91,7 +82,7 @@ Session::implicitly_enable_feature (::std::string feature_name) } options.target_data.insert_key_value_pair ("target_feature", - ::std::move (feature_name)); + std::move (feature_name)); } } @@ -235,7 +226,7 @@ Session::enable_features () } } options.target_data.features.shrink_to_fit(); - ::std::sort(options.target_data.features.begin(), + std::sort(options.target_data.features.begin(), options.target_data.features.end());*/ } @@ -313,7 +304,7 @@ Session::handle_option ( // enable dump and return whether this was successful if (arg != NULL) { - ret = enable_dump (::std::string (arg)); + ret = enable_dump (std::string (arg)); } else { @@ -332,7 +323,7 @@ Session::handle_option ( /* Enables a certain dump depending on the name passed in. Returns true if name * is valid, false otherwise. */ bool -Session::enable_dump (::std::string arg) +Session::enable_dump (std::string arg) { // FIXME: change dumping algorithm when new non-inhibiting dump system is // created @@ -411,7 +402,7 @@ Session::parse_file (const char *filename) { RAIIFile file_wrap (filename); - if (file_wrap.file == NULL) + if (file_wrap.get_raw() == NULL) { fatal_error (UNKNOWN_LOCATION, "cannot open filename %s: %m", filename); } @@ -419,10 +410,10 @@ Session::parse_file (const char *filename) Backend *backend = rust_get_backend (); // parse file here - // create lexer and parser - these are file-specific and so aren't instance - // variables - Rust::Lexer lex (filename, file_wrap.file, rust_get_linemap ()); - Rust::Parser parser (lex); + /* create lexer and parser - these are file-specific and so aren't instance + * variables */ + Rust::Lexer lex (filename, std::move (file_wrap), rust_get_linemap ()); + Rust::Parser parser (/*std::move (*/lex/*)*/); // generate crate from parser auto parsed_crate = parser.parse_crate (); @@ -518,7 +509,7 @@ check_cfg (const AST::Attribute &attr ATTRIBUTE_UNUSED) // Checks whether any 'cfg' attribute on the item prevents compilation of that // item. bool -check_item_cfg (::std::vector<AST::Attribute> attrs) +check_item_cfg (std::vector<AST::Attribute> attrs) { for (const auto &attr : attrs) { @@ -534,7 +525,7 @@ check_item_cfg (::std::vector<AST::Attribute> attrs) // TODO: actually implement method void -load_extern_crate (::std::string crate_name ATTRIBUTE_UNUSED) +load_extern_crate (std::string crate_name ATTRIBUTE_UNUSED) {} // TODO: deprecated - don't use @@ -555,7 +546,7 @@ Session::debug_dump_load_crates (Parser &parser) * enable using Option and Copy without qualifying it or importing it via * 'use' manually) */ - ::std::vector< ::std::string> crate_names; + std::vector<std::string> crate_names; for (const auto &item : crate.items) { // if item is extern crate, add name? to list of stuff ONLY IF config is @@ -656,7 +647,7 @@ Session::injection (AST::Crate &crate) * test should be prioritised since they seem to be used the most. */ // crate injection - ::std::vector< ::std::string> names; + std::vector<std::string> names; if (contains_name (crate.inner_attrs, "no_core")) { // no prelude @@ -689,33 +680,33 @@ Session::injection (AST::Crate &crate) AST::Attribute attr (AST::SimplePath::from_str ("macro_use"), NULL); // create "extern crate" item with the name - ::std::unique_ptr<AST::ExternCrate> extern_crate ( + std::unique_ptr<AST::ExternCrate> extern_crate ( new AST::ExternCrate (*it, AST::Visibility::create_error (), - {::std::move (attr)}, + {std::move (attr)}, Linemap::unknown_location ())); // insert at beginning - crate.items.insert (crate.items.begin (), ::std::move (extern_crate)); + crate.items.insert (crate.items.begin (), std::move (extern_crate)); } // create use tree path // prelude is injected_crate_name - ::std::vector<AST::SimplePathSegment> segments + std::vector<AST::SimplePathSegment> segments = {AST::SimplePathSegment (injected_crate_name), AST::SimplePathSegment ("prelude"), AST::SimplePathSegment ("v1")}; // create use tree and decl - ::std::unique_ptr<AST::UseTreeGlob> use_tree ( + std::unique_ptr<AST::UseTreeGlob> use_tree ( new AST::UseTreeGlob (AST::UseTreeGlob::PATH_PREFIXED, - AST::SimplePath (::std::move (segments)), + AST::SimplePath (std::move (segments)), Location ())); AST::Attribute prelude_attr (AST::SimplePath::from_str ("prelude_import"), NULL); - ::std::unique_ptr<AST::UseDeclaration> use_decl ( - new AST::UseDeclaration (::std::move (use_tree), + std::unique_ptr<AST::UseDeclaration> use_decl ( + new AST::UseDeclaration (std::move (use_tree), AST::Visibility::create_error (), - {::std::move (prelude_attr)}, Location ())); + {std::move (prelude_attr)}, Location ())); - crate.items.insert (crate.items.begin (), ::std::move (use_decl)); + crate.items.insert (crate.items.begin (), std::move (use_decl)); /* TODO: potentially add checking attribute crate type? I can't figure out * what this does currently comment says "Unconditionally collect crate types |