diff options
Diffstat (limited to 'gcc/rust/ast/rust-path.h')
-rw-r--r-- | gcc/rust/ast/rust-path.h | 473 |
1 files changed, 200 insertions, 273 deletions
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 |