aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <phil@nebuloninc.com>2020-05-16 23:05:35 +0100
committerPhilip Herron <philip.herron@embecosm.com>2020-11-28 21:13:13 +0000
commit1d4a355a01e074604cdbd8b557e043cece8d2167 (patch)
tree1405864ca91fc8553c242d15275449e9ecdaf76e
parent289cbcc7e694ab3ed62011c86f2d43c8ee2e9dd9 (diff)
downloadgcc-1d4a355a01e074604cdbd8b557e043cece8d2167.zip
gcc-1d4a355a01e074604cdbd8b557e043cece8d2167.tar.gz
gcc-1d4a355a01e074604cdbd8b557e043cece8d2167.tar.bz2
Infer types for AssignmentExpr
-rw-r--r--gcc/rust/analysis/rust-resolution.cc27
-rw-r--r--gcc/rust/ast/rust-stmt.h2
2 files changed, 28 insertions, 1 deletions
diff --git a/gcc/rust/analysis/rust-resolution.cc b/gcc/rust/analysis/rust-resolution.cc
index a14b64c..cb96ef0 100644
--- a/gcc/rust/analysis/rust-resolution.cc
+++ b/gcc/rust/analysis/rust-resolution.cc
@@ -263,7 +263,32 @@ TypeResolution::visit (AST::TypeCastExpr &expr)
void
TypeResolution::visit (AST::AssignmentExpr &expr)
{
- printf ("AssignmentExpr: %s\n", expr.as_string ().c_str ());
+ size_t before;
+ before = typeBuffer.size ();
+ expr.visit_lhs (*this);
+ if (typeBuffer.size () <= before)
+ {
+ rust_error_at (expr.locus, "unable to determine lhs type");
+ return;
+ }
+
+ auto lhsType = typeBuffer.back ();
+ typeBuffer.pop_back ();
+
+ before = typeBuffer.size ();
+ expr.visit_rhs (*this);
+ if (typeBuffer.size () <= before)
+ {
+ rust_error_at (expr.locus, "unable to determine rhs type");
+ return;
+ }
+
+ auto rhsType = typeBuffer.back ();
+ // not poping because we will be checking they match and the
+ // scope will require knowledge of the type
+
+ // do the lhsType and the rhsType match
+ // TODO
}
void
diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h
index f1b09a7..f19ba2c 100644
--- a/gcc/rust/ast/rust-stmt.h
+++ b/gcc/rust/ast/rust-stmt.h
@@ -63,6 +63,8 @@ public:
Location locus;
+ Type *inferedType;
+
// Returns whether let statement has outer attributes.
inline bool has_outer_attrs () const { return !outer_attrs.empty (); }