From 1d4a355a01e074604cdbd8b557e043cece8d2167 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Sat, 16 May 2020 23:05:35 +0100 Subject: Infer types for AssignmentExpr --- gcc/rust/analysis/rust-resolution.cc | 27 ++++++++++++++++++++++++++- gcc/rust/ast/rust-stmt.h | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'gcc/rust') 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 (); } -- cgit v1.1