aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-06-30 15:52:01 +0000
committerGitHub <noreply@github.com>2022-06-30 15:52:01 +0000
commit33912c1a08d3892d3c72506aed38771754b9cf54 (patch)
treede1e4342203a3567c8a719c8d689a3a097abc71a /gcc/rust/ast
parent81abc8623cb75fa18315c65e94c5965ec36fdb54 (diff)
parent93f63a94d4389f31d5b225ad220ebea5f7288fb7 (diff)
downloadgcc-33912c1a08d3892d3c72506aed38771754b9cf54.zip
gcc-33912c1a08d3892d3c72506aed38771754b9cf54.tar.gz
gcc-33912c1a08d3892d3c72506aed38771754b9cf54.tar.bz2
Merge #1336
1336: Resolve const generic parameters r=CohenArthur a=CohenArthur Fixes #1319. This can only resolve the simpler test cases: Anything that is ambiguous is ignored and does not get resolved. This will be fixed very soon :) Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-ast-full-test.cc4
-rw-r--r--gcc/rust/ast/rust-ast.h69
-rw-r--r--gcc/rust/ast/rust-path.h77
3 files changed, 78 insertions, 72 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index 8179113..d98a7cf 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -2365,8 +2365,8 @@ ConstGenericParam::as_string () const
std::string str ("ConstGenericParam: ");
str += "const " + name + ": " + type->as_string ();
- if (default_value)
- str += " = " + default_value->as_string ();
+ if (has_default_value ())
+ str += " = " + get_default_value ().as_string ();
return str;
}
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 51fe3c4..461a246 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -1344,75 +1344,6 @@ protected:
}
};
-/**
- * Representation of const generic parameters
- */
-class ConstGenericParam : public GenericParam
-{
- /* Name of the parameter */
- Identifier name;
-
- /* Mandatory type of the const parameter - a null pointer is an error */
- std::unique_ptr<AST::Type> type;
-
- /**
- * Default value for the const generic parameter - nullptr indicates a lack
- * of default value, not an error, as these errors are reported during
- * parsing.
- */
- std::unique_ptr<AST::Expr> default_value;
-
- Attribute outer_attr;
- Location locus;
-
-public:
- ConstGenericParam (Identifier name, std::unique_ptr<AST::Type> type,
- std::unique_ptr<AST::Expr> default_value,
- Attribute outer_attr, Location locus)
- : name (name), type (std::move (type)),
- default_value (std::move (default_value)), outer_attr (outer_attr),
- locus (locus)
- {}
-
- ConstGenericParam (const ConstGenericParam &other)
- : GenericParam (), name (other.name), type (other.type->clone_type ()),
- outer_attr (other.outer_attr), locus (other.locus)
- {
- if (other.default_value)
- default_value = other.default_value->clone_expr ();
- }
-
- bool has_type () { return type != nullptr; }
- bool has_default_value () { return default_value != nullptr; }
-
- const Identifier &get_name () const { return name; }
-
- std::unique_ptr<AST::Type> &get_type ()
- {
- rust_assert (has_type ());
-
- return type;
- }
-
- std::unique_ptr<AST::Expr> &get_default_value () { return default_value; }
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
- Location get_locus () const override final { return locus; }
-
- Kind get_kind () const override final { return Kind::Const; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- ConstGenericParam *clone_generic_param_impl () const override
- {
- return new ConstGenericParam (*this);
- }
-};
-
// A macro item AST node - abstract base class
class MacroItem : public Item
{
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index d2d925a..36f1c04 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -191,7 +191,12 @@ public:
Kind get_kind () const { return kind; }
- std::unique_ptr<AST::Expr> &get_expression () { return expression; }
+ const std::unique_ptr<AST::Expr> &get_expression () const
+ {
+ rust_assert (kind == Kind::Clear);
+
+ return expression;
+ }
std::string as_string () const
{
@@ -241,6 +246,76 @@ private:
Location locus;
};
+/**
+ * Representation of const generic parameters
+ */
+class ConstGenericParam : public GenericParam
+{
+ /* Name of the parameter */
+ Identifier name;
+
+ /* Mandatory type of the const parameter - a null pointer is an error */
+ std::unique_ptr<AST::Type> type;
+
+ /**
+ * Default value for the const generic parameter
+ */
+ ConstGenericArg default_value;
+
+ Attribute outer_attr;
+ Location locus;
+
+public:
+ ConstGenericParam (Identifier name, std::unique_ptr<AST::Type> type,
+ ConstGenericArg default_value, Attribute outer_attr,
+ Location locus)
+ : name (name), type (std::move (type)),
+ default_value (std::move (default_value)), outer_attr (outer_attr),
+ locus (locus)
+ {}
+
+ ConstGenericParam (const ConstGenericParam &other)
+ : GenericParam (), name (other.name), type (other.type->clone_type ()),
+ default_value (other.default_value), outer_attr (other.outer_attr),
+ locus (other.locus)
+ {}
+
+ bool has_type () const { return type != nullptr; }
+ bool has_default_value () const { return !default_value.is_error (); }
+
+ const Identifier &get_name () const { return name; }
+
+ std::unique_ptr<AST::Type> &get_type ()
+ {
+ rust_assert (has_type ());
+
+ return type;
+ }
+
+ const ConstGenericArg &get_default_value () const
+ {
+ rust_assert (has_default_value ());
+
+ return default_value;
+ }
+
+ std::string as_string () const override;
+
+ void accept_vis (ASTVisitor &vis) override;
+
+ Location get_locus () const override final { return locus; }
+
+ Kind get_kind () const override final { return Kind::Const; }
+
+protected:
+ /* Use covariance to implement clone function as returning this object rather
+ * than base */
+ ConstGenericParam *clone_generic_param_impl () const override
+ {
+ return new ConstGenericParam (*this);
+ }
+};
+
// Generic arguments allowed in each path expression segment - inline?
struct GenericArgs
{