aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-dump.cc122
-rw-r--r--gcc/rust/ast/rust-ast-dump.h9
-rw-r--r--gcc/rust/ast/rust-item.h2
-rw-r--r--gcc/rust/hir/rust-ast-lower.cc2
-rw-r--r--gcc/testsuite/rust/compile/const9.rs18
5 files changed, 144 insertions, 9 deletions
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 8ad00b5..bc4f7a3 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -108,6 +108,31 @@ Dump::emit_attrib (const Attribute &attrib)
stream << "]";
}
+void
+Dump::emit_visibility (const Visibility &vis)
+{
+ switch (vis.get_vis_type ())
+ {
+ case Visibility::PUB:
+ stream << "pub ";
+ break;
+ case Visibility::PUB_CRATE:
+ stream << "pub(crate) ";
+ break;
+ case Visibility::PUB_SELF:
+ stream << "pub(self) ";
+ break;
+ case Visibility::PUB_SUPER:
+ stream << "pub(super) ";
+ break;
+ case Visibility::PUB_IN_PATH:
+ stream << "pub(in " << vis.get_path ().as_string () << ") ";
+ break;
+ case Visibility::PRIV:
+ break;
+ }
+}
+
std::ostream &
Dump::emit_indented_string (const std::string &value,
const std::string &comment)
@@ -281,11 +306,63 @@ Dump::visit (TypeCastExpr &expr)
void
Dump::visit (AssignmentExpr &expr)
-{}
+{
+ expr.visit_lhs (*this);
+ stream << " = ";
+ expr.visit_rhs (*this);
+}
void
Dump::visit (CompoundAssignmentExpr &expr)
-{}
+{
+ auto op = "";
+ switch (expr.get_expr_type ())
+ {
+ case CompoundAssignmentOperator::ADD:
+ op = "+";
+ break;
+
+ case CompoundAssignmentOperator::SUBTRACT:
+ op = "-";
+ break;
+
+ case CompoundAssignmentOperator::MULTIPLY:
+ op = "*";
+ break;
+
+ case CompoundAssignmentOperator::DIVIDE:
+ op = "/";
+ break;
+
+ case CompoundAssignmentOperator::MODULUS:
+ op = "%";
+ break;
+
+ case CompoundAssignmentOperator::BITWISE_AND:
+ op = "&";
+ break;
+
+ case CompoundAssignmentOperator::BITWISE_OR:
+ op = "|";
+ break;
+
+ case CompoundAssignmentOperator::BITWISE_XOR:
+ op = "^";
+ break;
+
+ case CompoundAssignmentOperator::LEFT_SHIFT:
+ op = "<<";
+ break;
+
+ case CompoundAssignmentOperator::RIGHT_SHIFT:
+ op = ">>";
+ break;
+ }
+
+ expr.get_left_expr ()->accept_vis (*this);
+ stream << " " << op << "= ";
+ expr.get_right_expr ()->accept_vis (*this);
+}
void
Dump::visit (GroupedExpr &expr)
@@ -457,15 +534,31 @@ Dump::visit (ForLoopExpr &expr)
void
Dump::visit (IfExpr &expr)
-{}
+{
+ stream << "if ";
+ expr.vis_if_condition (*this);
+ expr.vis_if_block (*this);
+}
void
Dump::visit (IfExprConseqElse &expr)
-{}
+{
+ stream << "if ";
+ expr.vis_if_condition (*this);
+ expr.vis_if_block (*this);
+ stream << indentation << "else ";
+ expr.vis_else_block (*this);
+}
void
Dump::visit (IfExprConseqIf &expr)
-{}
+{
+ stream << "if ";
+ expr.vis_if_condition (*this);
+ expr.vis_if_block (*this);
+ stream << indentation << "else if ";
+ expr.vis_conseq_if_expr (*this);
+}
void
Dump::visit (IfExprConseqIfLet &expr)
@@ -522,7 +615,10 @@ Dump::visit (TypeBoundWhereClauseItem &item)
void
Dump::visit (Method &method)
{
- stream << indentation << "fn " << method.get_method_name () << '(';
+ // FIXME: Do we really need to dump the indentation here?
+ stream << indentation;
+ emit_visibility (method.get_visibility ());
+ stream << "fn " << method.get_method_name () << '(';
auto &self = method.get_self_param ();
stream << self.as_string ();
@@ -579,6 +675,7 @@ Dump::visit (UseDeclaration &use_decl)
void
Dump::visit (Function &function)
{
+ emit_visibility (function.get_visibility ());
stream << "fn " << function.get_function_name ();
if (function.has_generics ())
@@ -674,6 +771,7 @@ void
Dump::format_function_common (std::unique_ptr<Type> &return_type,
std::unique_ptr<BlockExpr> &block)
{
+ // FIXME: This should format the `<vis> fn <name> ( [args] )` as well
if (return_type)
{
stream << "-> ";
@@ -714,7 +812,13 @@ void
Dump::visit (TraitItemMethod &item)
{
auto method = item.get_trait_method_decl ();
- stream << indentation << "fn " << method.get_identifier () << '(';
+
+ // FIXME: Do we really need to dump the indentation here?
+ stream << indentation;
+
+ // FIXME: Can we have visibility here?
+ // emit_visibility (method.get_visibility ());
+ stream << "fn " << method.get_identifier () << '(';
auto &self = method.get_self_param ();
stream << self.as_string ();
@@ -754,6 +858,8 @@ Dump::visit (Trait &trait)
stream << "\n" << indentation;
}
+ emit_visibility (trait.get_visibility ());
+
stream << "trait " << trait.get_identifier ();
// Traits actually have an implicit Self thrown at the start so we must expect
@@ -834,6 +940,8 @@ Dump::visit (ExternalStaticItem &item)
void
Dump::visit (ExternalFunctionItem &function)
{
+ emit_visibility (function.get_visibility ());
+
stream << "fn " << function.get_identifier () << '(';
for (size_t i = 0; i < function.get_function_params ().size (); i++)
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index a72bd4d..a5a99f2 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -80,9 +80,18 @@ private:
* Format a function's definition parameter
*/
void format_function_param (FunctionParam &param);
+
+ /**
+ * Emit an attribute
+ */
void emit_attrib (const Attribute &attrib);
/**
+ * Emit an item's visibility
+ */
+ void emit_visibility (const Visibility &vis);
+
+ /**
* Emit an indented string with an optional extra comment
*/
std::ostream &emit_indented_string (const std::string &value,
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 4987674..20f1b93 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -634,7 +634,7 @@ public:
: vis_type (vis_type), in_path (std::move (in_path))
{}
- VisType get_public_vis_type () const { return vis_type; }
+ VisType get_vis_type () const { return vis_type; }
// Returns whether visibility is in an error state.
bool is_error () const
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index 0bec8b0..fa3a83d 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -36,7 +36,7 @@ translate_visibility (const AST::Visibility &vis)
if (vis.is_error ())
return Visibility::create_error ();
- switch (vis.get_public_vis_type ())
+ switch (vis.get_vis_type ())
{
case AST::Visibility::PUB:
return Visibility (Visibility::VisType::PUBLIC);
diff --git a/gcc/testsuite/rust/compile/const9.rs b/gcc/testsuite/rust/compile/const9.rs
new file mode 100644
index 0000000..e71a62a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/const9.rs
@@ -0,0 +1,18 @@
+// { dg-options "-w -O0 -fdump-tree-gimple" }
+const fn test(mut x: i32) -> i32 {
+ loop {
+ if x == 10 {
+ break;
+ }
+
+ x = x + 1;
+ }
+ return x;
+}
+
+const X: i32 = test(0);
+
+fn main() {
+ // { dg-final { scan-tree-dump-times {x = 10} 1 gimple } }
+ let x = X;
+}