diff options
author | Philip Herron <phil@nebuloninc.com> | 2020-05-16 21:05:45 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2020-11-28 19:13:04 +0000 |
commit | b3c690081ff60998abcbfaa9cfc6bf1b0f9c949f (patch) | |
tree | 0efd47f62c138976a848c328140b876c0516648a /gcc | |
parent | 70f49c655b0fe99c744cd9cc4ab2b84ccc14c7f0 (diff) | |
download | gcc-b3c690081ff60998abcbfaa9cfc6bf1b0f9c949f.zip gcc-b3c690081ff60998abcbfaa9cfc6bf1b0f9c949f.tar.gz gcc-b3c690081ff60998abcbfaa9cfc6bf1b0f9c949f.tar.bz2 |
Do inferencing on Expressions needs type match checking
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/analysis/rust-resolution.cc | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/gcc/rust/analysis/rust-resolution.cc b/gcc/rust/analysis/rust-resolution.cc index 24e1989..1c0fad1 100644 --- a/gcc/rust/analysis/rust-resolution.cc +++ b/gcc/rust/analysis/rust-resolution.cc @@ -67,15 +67,11 @@ TypeResolution::go () void TypeResolution::visit (AST::Token &tok) -{ - printf ("TOKEN: %s\n", tok.as_string ().c_str ()); -} +{} void TypeResolution::visit (AST::DelimTokenTree &delim_tok_tree) -{ - printf ("DelimTokenTree: %s\n", delim_tok_tree.as_string ().c_str ()); -} +{} void TypeResolution::visit (AST::AttrInputMetaItemContainer &input) @@ -84,7 +80,15 @@ TypeResolution::visit (AST::AttrInputMetaItemContainer &input) void TypeResolution::visit (AST::IdentifierExpr &ident_expr) { - printf ("IdentifierExpr %s\n", ident_expr.as_string ().c_str ()); + AST::Type *type = NULL; + bool ok = scope.Lookup (ident_expr.ident, &type); + if (!ok) + { + rust_error_at (ident_expr.locus, "unknown identifier"); + return; + } + + typeBuffer.push_back (type); } void @@ -216,9 +220,32 @@ TypeResolution::visit (AST::NegationExpr &expr) void TypeResolution::visit (AST::ArithmeticOrLogicalExpr &expr) { - printf ("ArithmeticOrLogicalExpr: %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 |