aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-ast.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/ast/rust-ast.h')
-rw-r--r--gcc/rust/ast/rust-ast.h485
1 files changed, 269 insertions, 216 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index ad3722f..bdc1f12 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -62,32 +62,6 @@ Location?
};*/
// decided to not have node as a "node" would never need to be stored
-// Attribute body - abstract base class
-class AttrInput
-{
-public:
- virtual ~AttrInput () {}
-
- // Unique pointer custom clone function
- std::unique_ptr<AttrInput> clone_attr_input () const
- {
- return std::unique_ptr<AttrInput> (clone_attr_input_impl ());
- }
-
- 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 nullptr; }
-
-protected:
- // pure virtual clone implementation
- virtual AttrInput *clone_attr_input_impl () const = 0;
-};
-
// forward decl for use in token tree method
class Token;
@@ -109,7 +83,7 @@ public:
/* 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
@@ -219,7 +193,7 @@ public:
void accept_vis (ASTVisitor &vis) override;
// Return copy of itself but in token stream form.
- 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; }
@@ -279,95 +253,6 @@ public:
bool is_error () const { return value_as_string == ""; }
};
-// A token tree with delimiters
-class DelimTokenTree : public TokenTree, public AttrInput
-{
- DelimType delim_type;
- std::vector<std::unique_ptr<TokenTree>> token_trees;
- Location locus;
-
-protected:
- DelimTokenTree *clone_delim_tok_tree_impl () const
- {
- return new DelimTokenTree (*this);
- }
-
- /* Use covariance to implement clone function as returning a DelimTokenTree
- * object */
- DelimTokenTree *clone_attr_input_impl () const override
- {
- 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>> (),
- Location locus = Location ())
- : delim_type (delim_type), token_trees (std::move (token_trees)),
- locus (locus)
- {}
-
- // Copy constructor with vector clone
- DelimTokenTree (DelimTokenTree const &other)
- : delim_type (other.delim_type), locus (other.locus)
- {
- token_trees.reserve (other.token_trees.size ());
- for (const auto &e : other.token_trees)
- token_trees.push_back (e->clone_token_tree ());
- }
-
- // overloaded assignment operator with vector clone
- DelimTokenTree &operator= (DelimTokenTree const &other)
- {
- delim_type = other.delim_type;
- locus = other.locus;
-
- token_trees.reserve (other.token_trees.size ());
- for (const auto &e : other.token_trees)
- token_trees.push_back (e->clone_token_tree ());
-
- return *this;
- }
-
- // move constructors
- DelimTokenTree (DelimTokenTree &&other) = default;
- DelimTokenTree &operator= (DelimTokenTree &&other) = default;
-
- static DelimTokenTree create_empty () { return DelimTokenTree (PARENS); }
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
- bool
- check_cfg_predicate (const Session &session ATTRIBUTE_UNUSED) const override
- {
- // this should never be called - should be converted first
- return false;
- }
-
- AttrInput *parse_to_meta_item () const override;
-
- 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 */
-class AttrInputLiteral;
-
/* TODO: move applicable stuff into here or just don't include it because
* nothing uses it A segment of a path (maybe) */
class PathSegment
@@ -442,7 +327,7 @@ public:
// 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) const
{
return !has_opening_scope_resolution && segments.size () == 1
&& segments[0].as_string () == rhs;
@@ -460,6 +345,9 @@ public:
}
};
+// forward decl for Attribute
+class AttrInput;
+
// aka Attr
// Attribute AST representation
struct Attribute
@@ -488,15 +376,17 @@ public:
~Attribute () = default;
// Copy constructor must deep copy attr_input as unique pointer
- Attribute (Attribute const &other) : path (other.path), locus (other.locus)
+ /*Attribute (Attribute const &other) : path (other.path), locus (other.locus)
{
// guard to protect from null pointer dereference
if (other.attr_input != nullptr)
attr_input = other.attr_input->clone_attr_input ();
- }
+ }*/
+ // no point in being defined inline as requires virtual call anyway
+ Attribute (const Attribute &other);
// overload assignment operator to use custom clone method
- Attribute &operator= (Attribute const &other)
+ /*Attribute &operator= (Attribute const &other)
{
path = other.path;
locus = other.locus;
@@ -505,7 +395,9 @@ public:
attr_input = other.attr_input->clone_attr_input ();
return *this;
- }
+ }*/
+ // no point in being defined inline as requires virtual call anyway
+ Attribute &operator= (const Attribute &other);
// default move semantics
Attribute (Attribute &&other) = default;
@@ -581,29 +473,18 @@ public:
std::string as_string () const;
// TODO: does this require visitor pattern as not polymorphic?
-
- // Maybe change to const-reference in future
- SimplePath get_path () const { return path; }
+
+ const SimplePath &get_path () const { return path; }
+ SimplePath &get_path () { return path; }
// 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. */
- bool check_cfg_predicate (const Session &session)
- {
- /* assume that cfg predicate actually can exist, i.e. attribute has cfg or
- * cfg_attr path */
-
- if (!has_attr_input ())
- return false;
+ bool check_cfg_predicate (const Session &session);
- // TODO: maybe replace with storing a "has been parsed" variable?
- parse_attr_to_meta_item ();
- // can't be const because of this anyway
-
- return attr_input->check_cfg_predicate (session);
- }
+ std::vector<Attribute> separate_cfg_attrs ();
protected:
// not virtual as currently no subclasses of Attribute, but could be in future
@@ -613,6 +494,122 @@ protected:
}
};
+// Attribute body - abstract base class
+class AttrInput
+{
+public:
+ virtual ~AttrInput () {}
+
+ // Unique pointer custom clone function
+ std::unique_ptr<AttrInput> clone_attr_input () const
+ {
+ return std::unique_ptr<AttrInput> (clone_attr_input_impl ());
+ }
+
+ 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 nullptr; }
+
+ virtual std::vector<Attribute> separate_cfg_attrs () const { return {}; }
+
+protected:
+ // pure virtual clone implementation
+ virtual AttrInput *clone_attr_input_impl () const = 0;
+};
+
+// A token tree with delimiters
+class DelimTokenTree : public TokenTree, public AttrInput
+{
+ DelimType delim_type;
+ std::vector<std::unique_ptr<TokenTree> > token_trees;
+ Location locus;
+
+protected:
+ DelimTokenTree *clone_delim_tok_tree_impl () const
+ {
+ return new DelimTokenTree (*this);
+ }
+
+ /* Use covariance to implement clone function as returning a DelimTokenTree
+ * object */
+ DelimTokenTree *clone_attr_input_impl () const override
+ {
+ 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> > (),
+ Location locus = Location ())
+ : delim_type (delim_type), token_trees (std::move (token_trees)),
+ locus (locus)
+ {}
+
+ // Copy constructor with vector clone
+ DelimTokenTree (DelimTokenTree const &other)
+ : delim_type (other.delim_type), locus (other.locus)
+ {
+ token_trees.reserve (other.token_trees.size ());
+ for (const auto &e : other.token_trees)
+ token_trees.push_back (e->clone_token_tree ());
+ }
+
+ // overloaded assignment operator with vector clone
+ DelimTokenTree &operator= (DelimTokenTree const &other)
+ {
+ delim_type = other.delim_type;
+ locus = other.locus;
+
+ token_trees.reserve (other.token_trees.size ());
+ for (const auto &e : other.token_trees)
+ token_trees.push_back (e->clone_token_tree ());
+
+ return *this;
+ }
+
+ // move constructors
+ DelimTokenTree (DelimTokenTree &&other) = default;
+ DelimTokenTree &operator= (DelimTokenTree &&other) = default;
+
+ static DelimTokenTree create_empty () { return DelimTokenTree (PARENS); }
+
+ std::string as_string () const override;
+
+ void accept_vis (ASTVisitor &vis) override;
+
+ bool check_cfg_predicate (const Session &) const override
+ {
+ // this should never be called - should be converted first
+ return false;
+ }
+
+ AttrInput *parse_to_meta_item () const override;
+
+ 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 */
+class AttrInputLiteral;
+
// Forward decl - defined in rust-macro.h
class MetaNameValueStr;
@@ -638,7 +635,10 @@ public:
/* HACK: used to simplify parsing - creates a copy of that type, or returns
* null */
- virtual std::unique_ptr<MetaNameValueStr> to_meta_name_value_str () const { return nullptr; }
+ virtual std::unique_ptr<MetaNameValueStr> to_meta_name_value_str () const
+ {
+ return nullptr;
+ }
// HACK: used to simplify parsing - same thing
virtual SimplePath to_path_item () const
@@ -646,7 +646,7 @@ public:
return SimplePath::create_empty ();
}
- virtual Attribute to_attribute() const { return Attribute::create_empty (); }
+ virtual Attribute to_attribute () const { return Attribute::create_empty (); }
virtual bool check_cfg_predicate (const Session &session) const = 0;
};
@@ -654,11 +654,11 @@ 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)
+ std::vector<std::unique_ptr<MetaItemInner> > items)
: items (std::move (items))
{}
@@ -683,6 +683,8 @@ public:
clone_attr_input_meta_item_container_impl ());
}
+ std::vector<Attribute> separate_cfg_attrs () const override;
+
protected:
// Use covariance to implement clone function as returning this type
AttrInputMetaItemContainer *clone_attr_input_impl () const override
@@ -764,6 +766,9 @@ public:
* methods. */
virtual Location get_locus_slow () const { return Location (); }
+ virtual void mark_for_strip () = 0;
+ virtual bool is_marked_for_strip () const = 0;
+
protected:
// Clone function implementation as pure virtual method
virtual Stmt *clone_stmt_impl () const = 0;
@@ -772,10 +777,6 @@ protected:
// Rust "item" AST node (declaration of top-level/module-level allowed stuff)
class Item : public Stmt
{
- 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
@@ -783,29 +784,22 @@ public:
return std::unique_ptr<Item> (clone_item_impl ());
}
- std::string as_string () const;
+ std::string as_string () const = 0;
/* Adds crate names to the vector passed by reference, if it can
- * (polymorphism). */
+ * (polymorphism). TODO: remove, unused. */
virtual void
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))
- {}
-
// Clone function implementation as pure virtual method
virtual Item *clone_item_impl () const = 0;
/* Save having to specify two clone methods in derived classes by making
* statement clone return item clone. Hopefully won't affect performance too
* much. */
- Item *clone_stmt_impl () const override { return clone_item_impl (); }
+ Item *clone_stmt_impl () const final override { return clone_item_impl (); }
};
// forward decl of ExprWithoutBlock
@@ -818,7 +812,9 @@ class Expr
std::vector<Attribute> outer_attrs;
public:
+ // TODO: this mutable getter seems really dodgy. Think up better way.
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
// Unique pointer custom clone function
std::unique_ptr<Expr> clone_expr () const
@@ -849,6 +845,9 @@ public:
virtual void accept_vis (ASTVisitor &vis) = 0;
+ virtual void mark_for_strip () = 0;
+ virtual bool is_marked_for_strip () const = 0;
+
protected:
// Constructor
Expr (std::vector<Attribute> outer_attribs = std::vector<Attribute> ())
@@ -882,7 +881,7 @@ protected:
/* Save having to specify two clone methods in derived classes by making expr
* clone return exprwithoutblock clone. Hopefully won't affect performance too
* much. */
- ExprWithoutBlock *clone_expr_impl () const override
+ ExprWithoutBlock *clone_expr_impl () const final override
{
return clone_expr_without_block_impl ();
}
@@ -910,11 +909,10 @@ public:
*/
class IdentifierExpr : public ExprWithoutBlock
{
-public:
Identifier ident;
-
Location locus;
+public:
IdentifierExpr (Identifier ident, Location locus = Location (),
std::vector<Attribute> outer_attrs
= std::vector<Attribute> ())
@@ -927,6 +925,8 @@ public:
Location get_locus () const { return locus; }
Location get_locus_slow () const override { return get_locus (); }
+ Identifier get_ident () const { return ident; }
+
void accept_vis (ASTVisitor &vis) override;
// Clones this object.
@@ -935,6 +935,10 @@ public:
return std::unique_ptr<IdentifierExpr> (clone_identifier_expr_impl ());
}
+ // "Error state" if ident is empty, so base stripping on this.
+ void mark_for_strip () override { ident = {}; }
+ bool is_marked_for_strip () const override { return ident.empty (); }
+
protected:
// Clone method implementation
IdentifierExpr *clone_expr_without_block_impl () const override
@@ -946,9 +950,6 @@ protected:
{
return new IdentifierExpr (*this);
}
-
- IdentifierExpr (IdentifierExpr const &other) = default;
- IdentifierExpr &operator= (IdentifierExpr const &other) = default;
};
// Pattern base AST node
@@ -969,6 +970,14 @@ public:
virtual void accept_vis (ASTVisitor &vis) = 0;
+ // as only one kind of pattern can be stripped, have default of nothing
+ virtual void mark_for_strip () {}
+ virtual bool is_marked_for_strip () const { return false; }
+
+ /* HACK: slow way of getting location from base expression through virtual
+ * methods. */
+ virtual Location get_locus_slow () const = 0;
+
protected:
// Clone pattern implementation as pure virtual method
virtual Pattern *clone_pattern_impl () const = 0;
@@ -994,15 +1003,18 @@ public:
/* 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 nullptr;
- }
+ virtual TraitBound *to_trait_bound (bool) const { return nullptr; }
/* as pointer, shouldn't require definition beforehand, only forward
* declaration. */
virtual void accept_vis (ASTVisitor &vis) = 0;
+ // as only two kinds of types can be stripped, have default of nothing
+ virtual void mark_for_strip () {}
+ virtual bool is_marked_for_strip () const { return false; }
+
+ virtual Location get_locus_slow () const = 0;
+
protected:
// Clone function implementation as pure virtual method
virtual Type *clone_type_impl () const = 0;
@@ -1025,7 +1037,7 @@ 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. */
- TypeNoBounds *clone_type_impl () const override
+ TypeNoBounds *clone_type_impl () const final override
{
return clone_type_no_bounds_impl ();
}
@@ -1082,7 +1094,7 @@ public:
{}
// Creates an "error" lifetime.
- static Lifetime error () { return Lifetime (NAMED, std::string ("")); }
+ static Lifetime error () { return Lifetime (NAMED, ""); }
// Returns true if the lifetime is in an error state.
bool is_error () const
@@ -1207,10 +1219,12 @@ class MacroItem : public Item
{
/*public:
std::string as_string() const;*/
+ // std::vector<Attribute> outer_attrs;
+
protected:
- MacroItem (std::vector<Attribute> outer_attribs)
- : Item (std::move (outer_attribs))
- {}
+ /*MacroItem (std::vector<Attribute> outer_attribs)
+ : outer_attrs (std::move (outer_attribs))
+ {}*/
};
// Item used in trait declarations - abstract base class
@@ -1223,21 +1237,12 @@ class TraitItem
// NOTE: all children should have outer attributes
protected:
- // Constructor
- /*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;
public:
virtual ~TraitItem () {}
- // Returns whether TraitItem has outer attributes.
- /*bool has_outer_attrs() const {
- return !outer_attrs.empty();
- }*/
-
// Unique pointer custom clone function
std::unique_ptr<TraitItem> clone_trait_item () const
{
@@ -1247,6 +1252,9 @@ public:
virtual std::string as_string () const = 0;
virtual void accept_vis (ASTVisitor &vis) = 0;
+
+ virtual void mark_for_strip () = 0;
+ virtual bool is_marked_for_strip () const = 0;
};
/* Abstract base class for items used within an inherent impl block (the impl
@@ -1269,6 +1277,9 @@ public:
virtual std::string as_string () const = 0;
virtual void accept_vis (ASTVisitor &vis) = 0;
+
+ virtual void mark_for_strip () = 0;
+ virtual bool is_marked_for_strip () const = 0;
};
// Abstract base class for items used in a trait impl
@@ -1289,6 +1300,33 @@ public:
virtual std::string as_string () const = 0;
virtual void accept_vis (ASTVisitor &vis) = 0;
+
+ virtual void mark_for_strip () = 0;
+ virtual bool is_marked_for_strip () const = 0;
+};
+
+// Abstract base class for an item used inside an extern block
+class ExternalItem
+{
+public:
+ virtual ~ExternalItem () {}
+
+ // Unique pointer custom clone function
+ std::unique_ptr<ExternalItem> clone_external_item () const
+ {
+ return std::unique_ptr<ExternalItem> (clone_external_item_impl ());
+ }
+
+ virtual std::string as_string () const = 0;
+
+ virtual void accept_vis (ASTVisitor &vis) = 0;
+
+ virtual void mark_for_strip () = 0;
+ virtual bool is_marked_for_strip () const = 0;
+
+protected:
+ // Clone function implementation as pure virtual method
+ virtual ExternalItem *clone_external_item_impl () const = 0;
};
/* A macro invocation item (or statement) AST node (i.e. semi-coloned macro
@@ -1296,51 +1334,32 @@ public:
class MacroInvocationSemi : public MacroItem,
public TraitItem,
public InherentImplItem,
- public TraitImplItem
+ public TraitImplItem,
+ public ExternalItem
{
+ std::vector<Attribute> outer_attrs;
SimplePath path;
// all delim types except curly must have invocation end with a semicolon
DelimType delim_type;
- std::vector<std::unique_ptr<TokenTree>> token_trees;
+ std::vector<std::unique_ptr<TokenTree> > token_trees;
Location locus;
public:
std::string as_string () const override;
MacroInvocationSemi (SimplePath macro_path, DelimType delim_type,
- std::vector<std::unique_ptr<TokenTree>> token_trees,
+ 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)),
+ : outer_attrs (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
- * attributes
- * - storage inefficiency at least.
- * Best current idea is to make Item preferred and have TraitItem get virtual
- * functions for attributes or something. Or just redo the "composition"
- * 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)
+ TraitImplItem (other), outer_attrs (other.outer_attrs), path (other.path),
+ delim_type (other.delim_type), locus (other.locus)
{
token_trees.reserve (other.token_trees.size ());
for (const auto &e : other.token_trees)
@@ -1354,6 +1373,7 @@ protected:
TraitItem::operator= (other);
InherentImplItem::operator= (other);
TraitImplItem::operator= (other);
+ outer_attrs = other.outer_attrs;
path = other.path;
delim_type = other.delim_type;
locus = other.locus;
@@ -1365,6 +1385,28 @@ protected:
return *this;
}
+ // 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 ());
+ }
+
+ // Invalid if path is empty, so base stripping on that.
+ void mark_for_strip () override { path = SimplePath::create_empty (); }
+ bool is_marked_for_strip () const override { return path.is_empty (); }
+
+ // TODO: this mutable getter seems really dodgy. Think up better way.
+ const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+ std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
+
+protected:
MacroInvocationSemi *clone_macro_invocation_semi_impl () const
{
return new MacroInvocationSemi (*this);
@@ -1391,19 +1433,19 @@ protected:
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
- /*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 */
MacroInvocationSemi *clone_trait_item_impl () const override
{
return clone_macro_invocation_semi_impl ();
}
+
+ /* Use covariance to implement clone function as returning this object rather
+ * than base */
+ MacroInvocationSemi *clone_external_item_impl () const override
+ {
+ return clone_macro_invocation_semi_impl ();
+ }
};
// A crate AST object - holds all the data for a single compilation unit
@@ -1416,11 +1458,11 @@ struct Crate
// 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;
+ std::vector<std::unique_ptr<Item> > items;
public:
// Constructor
- Crate (std::vector<std::unique_ptr<Item>> items,
+ 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),
@@ -1459,6 +1501,17 @@ public:
// Get crate representation as string (e.g. for debugging).
std::string as_string () const;
+
+ // Delete all crate information, e.g. if fails cfg.
+ void strip_crate ()
+ {
+ inner_attrs.clear ();
+ inner_attrs.shrink_to_fit ();
+
+ items.clear ();
+ items.shrink_to_fit ();
+ // TODO: is this the best way to do this?
+ }
};
// Base path expression AST node - abstract