aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-expr.h35
-rw-r--r--gcc/rust/ast/rust-item.h9
-rw-r--r--gcc/rust/ast/rust-path.h35
-rw-r--r--gcc/rust/ast/rust-pattern.h6
4 files changed, 46 insertions, 39 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 3f3ed5c..7336db2 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -953,12 +953,11 @@ protected:
class ArrayElemsValues : public ArrayElems
{
std::vector<std::unique_ptr<Expr> > values;
-
- // TODO: should this store location data?
+ Location locus;
public:
- ArrayElemsValues (std::vector<std::unique_ptr<Expr> > elems)
- : ArrayElems (), values (std::move (elems))
+ ArrayElemsValues (std::vector<std::unique_ptr<Expr> > elems, Location locus)
+ : ArrayElems (), values (std::move (elems)), locus (locus)
{}
// copy constructor with vector clone
@@ -1008,15 +1007,14 @@ class ArrayElemsCopied : public ArrayElems
{
std::unique_ptr<Expr> elem_to_copy;
std::unique_ptr<Expr> num_copies;
-
- // TODO: should this store location data?
+ Location locus;
public:
// Constructor requires pointers for polymorphism
ArrayElemsCopied (std::unique_ptr<Expr> copied_elem,
- std::unique_ptr<Expr> copy_amount)
+ std::unique_ptr<Expr> copy_amount, Location locus)
: ArrayElems (), elem_to_copy (std::move (copied_elem)),
- num_copies (std::move (copy_amount))
+ num_copies (std::move (copy_amount)), locus (locus)
{}
// Copy constructor required due to unique_ptr - uses custom clone
@@ -1516,11 +1514,11 @@ struct StructBase
{
private:
std::unique_ptr<Expr> base_struct;
+ Location locus;
public:
- // 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, Location locus)
+ : base_struct (std::move (base_struct_ptr)), locus (locus)
{}
// Copy constructor requires clone
@@ -1552,7 +1550,7 @@ public:
StructBase &operator= (StructBase &&other) = default;
// Returns a null expr-ed StructBase - error state
- static StructBase error () { return StructBase (nullptr); }
+ static StructBase error () { return StructBase (nullptr, Location ()); }
// Returns whether StructBase is in error state
bool is_invalid () const { return base_struct == nullptr; }
@@ -2136,8 +2134,7 @@ private:
// bool has_type_given;
std::unique_ptr<Type> type;
-
- // TODO: should this store location data?
+ Location locus;
public:
// Returns whether the type of the parameter has been given.
@@ -2146,11 +2143,12 @@ public:
bool has_outer_attrs () const { return !outer_attrs.empty (); }
// Constructor for closure parameter
- ClosureParam (std::unique_ptr<Pattern> param_pattern,
+ ClosureParam (std::unique_ptr<Pattern> param_pattern, Location locus,
std::unique_ptr<Type> param_type = nullptr,
std::vector<Attribute> outer_attrs = {})
: outer_attrs (std::move (outer_attrs)),
- pattern (std::move (param_pattern)), type (std::move (param_type))
+ pattern (std::move (param_pattern)), type (std::move (param_type)),
+ locus (locus)
{}
// Copy constructor required due to cloning as a result of unique_ptrs
@@ -2191,7 +2189,10 @@ public:
bool is_error () const { return pattern == nullptr; }
// Creates an error state closure parameter.
- static ClosureParam create_error () { return ClosureParam (nullptr); }
+ static ClosureParam create_error ()
+ {
+ return ClosureParam (nullptr, Location ());
+ }
std::string as_string () const;
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index b04aa05..94e5cbd 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3941,12 +3941,11 @@ private:
std::unique_ptr<Type> param_type;
- // TODO: should this store location data?
-
// seemingly new since writing this node
std::vector<Attribute> outer_attrs;
NodeId node_id;
+ Location locus;
public:
/* Returns whether the named function parameter has a name (i.e. name is not
@@ -3967,14 +3966,14 @@ public:
// Creates an error state named function parameter.
static NamedFunctionParam create_error ()
{
- return NamedFunctionParam ("", nullptr, {});
+ return NamedFunctionParam ("", nullptr, {}, Location ());
}
NamedFunctionParam (std::string name, std::unique_ptr<Type> param_type,
- std::vector<Attribute> outer_attrs)
+ std::vector<Attribute> outer_attrs, Location locus)
: name (std::move (name)), param_type (std::move (param_type)),
outer_attrs (std::move (outer_attrs)),
- node_id (Analysis::Mappings::get ()->get_next_node_id ())
+ node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus)
{}
// Copy constructor
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index e062dc6..ed37f40 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -33,13 +33,12 @@ namespace AST {
class PathIdentSegment
{
std::string segment_name;
-
- // TODO: should this have location info stored?
+ Location locus;
// 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, Location locus)
+ : segment_name (std::move (segment_name)), locus (locus)
{}
/* TODO: insert check in constructor for this? Or is this a semantic error
@@ -49,7 +48,10 @@ public:
* not entirely sure */
// Creates an error PathIdentSegment.
- static PathIdentSegment create_error () { return PathIdentSegment (""); }
+ static PathIdentSegment create_error ()
+ {
+ return PathIdentSegment ("", Location ());
+ }
// Returns whether PathIdentSegment is in an error state.
bool is_error () const { return segment_name.empty (); }
@@ -221,7 +223,7 @@ public:
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 (),
+ PathExprSegment (PathIdentSegment segment_name, Location locus,
GenericArgs generic_args = GenericArgs::create_empty ())
: segment_name (std::move (segment_name)),
generic_args (std::move (generic_args)), locus (locus),
@@ -237,7 +239,7 @@ public:
= std::vector<std::unique_ptr<Type> > (),
std::vector<GenericArgsBinding> binding_args
= std::vector<GenericArgsBinding> ())
- : segment_name (PathIdentSegment (std::move (segment_name))),
+ : segment_name (PathIdentSegment (std::move (segment_name), locus)),
generic_args (GenericArgs (std::move (lifetime_args),
std::move (type_args),
std::move (binding_args))),
@@ -250,7 +252,7 @@ public:
// Creates an error-state path expression segment.
static PathExprSegment create_error ()
{
- return PathExprSegment (PathIdentSegment::create_error ());
+ return PathExprSegment (PathIdentSegment::create_error (), Location ());
}
std::string as_string () const;
@@ -440,7 +442,7 @@ public:
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 (locus),
has_separating_scope_resolution (has_separating_scope_resolution),
node_id (Analysis::Mappings::get ()->get_next_node_id ())
@@ -539,11 +541,13 @@ private:
// FIXME: think of better way to mark as invalid than taking up storage
bool is_invalid;
- // TODO: should this have location info?
+ Location locus;
protected:
// Constructor only used to create invalid type path functions.
- TypePathFunction (bool is_invalid) : is_invalid (is_invalid) {}
+ TypePathFunction (bool is_invalid, Location locus)
+ : is_invalid (is_invalid), locus (locus)
+ {}
public:
// Returns whether the return type of the function has been specified.
@@ -556,13 +560,16 @@ public:
bool is_error () const { return is_invalid; }
// Creates an error state function.
- static TypePathFunction create_error () { return TypePathFunction (true); }
+ static TypePathFunction create_error ()
+ {
+ return TypePathFunction (true, Location ());
+ }
// Constructor
- TypePathFunction (std::vector<std::unique_ptr<Type> > inputs,
+ TypePathFunction (std::vector<std::unique_ptr<Type> > inputs, Location locus,
std::unique_ptr<Type> type = nullptr)
: inputs (std::move (inputs)), return_type (std::move (type)),
- is_invalid (false)
+ is_invalid (false), locus (locus)
{}
// Copy constructor with clone
diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index 3b8dbd7..5d937d7 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -848,18 +848,18 @@ class StructPattern : public Pattern
// bool has_struct_pattern_elements;
StructPatternElements elems;
- // TODO: should this store location data? Accessor uses path location data.
NodeId node_id;
+ Location locus;
public:
std::string as_string () const override;
// Constructs a struct pattern from specified StructPatternElements
- StructPattern (PathInExpression struct_path,
+ StructPattern (PathInExpression struct_path, Location locus,
StructPatternElements elems
= StructPatternElements::create_empty ())
: path (std::move (struct_path)), elems (std::move (elems)),
- node_id (Analysis::Mappings::get ()->get_next_node_id ())
+ node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus)
{}
/* TODO: constructor to construct via elements included in