aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorSimplyTheOther <simplytheother@gmail.com>2021-01-08 15:09:08 +0800
committerSimplyTheOther <simplytheother@gmail.com>2021-01-08 15:09:08 +0800
commit238a31b33f79cddfaa40c5fd748495a5f2b34630 (patch)
treebc217d37b5e3ee41b0a69265341945389d1f4dfb /gcc/rust/resolve
parentb5f86dca7e6b53ca3701ef01ae36070a760dff78 (diff)
parentaf04ea2222b6407fb3e83759ae332d600495380c (diff)
downloadgcc-238a31b33f79cddfaa40c5fd748495a5f2b34630.zip
gcc-238a31b33f79cddfaa40c5fd748495a5f2b34630.tar.gz
gcc-238a31b33f79cddfaa40c5fd748495a5f2b34630.tar.bz2
Merge branch 'master' of https://github.com/redbrain/gccrs
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-expr.h35
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.h20
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h53
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-toplevel.h24
-rw-r--r--gcc/rust/resolve/rust-ast-resolve.cc26
5 files changed, 148 insertions, 10 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h
index d86866c..2292d16 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.h
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.h
@@ -21,6 +21,7 @@
#include "rust-ast-resolve-base.h"
#include "rust-ast-full.h"
+#include "rust-ast-resolve-struct-expr-field.h"
namespace Rust {
namespace Resolver {
@@ -38,19 +39,22 @@ public:
void visit (AST::PathInExpression &expr)
{
+ // name scope first
if (!resolver->get_name_scope ().lookup (expr.as_string (), &resolved_node))
{
- rust_error_at (expr.get_locus (), "unknown path %s",
- expr.as_string ().c_str ());
- return;
- }
- else
- {
- resolver->insert_resolved_name (expr.get_node_id (), resolved_node);
- resolver->insert_new_definition (expr.get_node_id (),
- Definition{expr.get_node_id (),
- parent});
+ // check the type scope
+ if (!resolver->get_type_scope ().lookup (expr.as_string (),
+ &resolved_node))
+ {
+ rust_error_at (expr.get_locus (), "unknown path %s",
+ expr.as_string ().c_str ());
+ return;
+ }
}
+
+ resolver->insert_resolved_name (expr.get_node_id (), resolved_node);
+ resolver->insert_new_definition (expr.get_node_id (),
+ Definition{expr.get_node_id (), parent});
}
void visit (AST::ReturnExpr &expr)
@@ -154,6 +158,17 @@ public:
ResolveExpr::go (elems.get_elem_to_copy ().get (), elems.get_node_id ());
}
+ void visit (AST::StructExprStructFields &struct_expr)
+ {
+ ResolveExpr::go (&struct_expr.get_struct_name (),
+ struct_expr.get_node_id ());
+ struct_expr.iterate (
+ [&] (AST::StructExprField *struct_field) mutable -> bool {
+ ResolveStructExprField::go (struct_field, struct_expr.get_node_id ());
+ return true;
+ });
+ }
+
private:
ResolveExpr (NodeId parent) : ResolverBase (parent) {}
};
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index 2c21a52..c3b2312 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -39,6 +39,26 @@ public:
~ResolveItem () {}
+ void visit (AST::StructStruct &struct_decl)
+ {
+ struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ ResolveType::go (field.get_field_type ().get (), field.get_node_id ());
+ return true;
+ });
+ }
+
+ void visit (AST::StaticItem &var)
+ {
+ ResolveType::go (var.get_type ().get (), var.get_node_id ());
+ ResolveExpr::go (var.get_expr ().get (), var.get_node_id ());
+ }
+
+ void visit (AST::ConstantItem &constant)
+ {
+ ResolveType::go (constant.get_type ().get (), constant.get_node_id ());
+ ResolveExpr::go (constant.get_expr ().get (), constant.get_node_id ());
+ }
+
void visit (AST::Function &function)
{
if (function.has_return_type ())
diff --git a/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h b/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h
new file mode 100644
index 0000000..c705a03
--- /dev/null
+++ b/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h
@@ -0,0 +1,53 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_AST_RESOLVE_STRUCT_EXPR_FIELD
+#define RUST_AST_RESOLVE_STRUCT_EXPR_FIELD
+
+#include "rust-ast-resolve-base.h"
+#include "rust-ast-full.h"
+
+namespace Rust {
+namespace Resolver {
+
+// this resolves values being assigned not that the field actually exists yet.
+// We cant resolve the field to struct until type resolution since the HIR
+// Mappings don't exist yet.
+class ResolveStructExprField : public ResolverBase
+{
+public:
+ static void go (AST::StructExprField *field, NodeId parent)
+ {
+ ResolveStructExprField resolver (parent);
+ field->accept_vis (resolver);
+ }
+
+ virtual ~ResolveStructExprField () {}
+
+ void visit (AST::StructExprFieldIdentifierValue &field);
+
+ // TODO
+
+private:
+ ResolveStructExprField (NodeId parent) : ResolverBase (parent) {}
+};
+
+} // namespace Resolver
+} // namespace Rust
+
+#endif // RUST_AST_RESOLVE_STRUCT_EXPR_FIELD
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
index fcc9663..6a4395f 100644
--- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h
+++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
@@ -36,6 +36,30 @@ public:
~ResolveTopLevel () {}
+ void visit (AST::StructStruct &struct_decl)
+ {
+ resolver->get_type_scope ().insert (struct_decl.get_identifier (),
+ struct_decl.get_node_id ());
+ }
+
+ void visit (AST::StaticItem &var)
+ {
+ resolver->get_name_scope ().insert (var.get_identifier (),
+ var.get_node_id ());
+ resolver->insert_new_definition (var.get_node_id (),
+ Definition{var.get_node_id (),
+ var.get_node_id ()});
+ }
+
+ void visit (AST::ConstantItem &constant)
+ {
+ resolver->get_name_scope ().insert (constant.get_identifier (),
+ constant.get_node_id ());
+ resolver->insert_new_definition (constant.get_node_id (),
+ Definition{constant.get_node_id (),
+ constant.get_node_id ()});
+ }
+
void visit (AST::Function &function)
{
// function_names are simple std::String identifiers so this can be a
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc
index 8370a5b..fe8d7e0 100644
--- a/gcc/rust/resolve/rust-ast-resolve.cc
+++ b/gcc/rust/resolve/rust-ast-resolve.cc
@@ -126,20 +126,38 @@ Resolver::generate_builtins ()
= new TyTy::UintType (mappings->get_next_hir_id (), TyTy::UintType::U16);
auto u32
= new TyTy::UintType (mappings->get_next_hir_id (), TyTy::UintType::U32);
+ auto u64
+ = new TyTy::UintType (mappings->get_next_hir_id (), TyTy::UintType::U64);
+ auto u128
+ = new TyTy::UintType (mappings->get_next_hir_id (), TyTy::UintType::U128);
auto i8 = new TyTy::IntType (mappings->get_next_hir_id (), TyTy::IntType::I8);
auto i16
= new TyTy::IntType (mappings->get_next_hir_id (), TyTy::IntType::I16);
auto i32
= new TyTy::IntType (mappings->get_next_hir_id (), TyTy::IntType::I32);
+ auto i64
+ = new TyTy::IntType (mappings->get_next_hir_id (), TyTy::IntType::I64);
+ auto i128
+ = new TyTy::IntType (mappings->get_next_hir_id (), TyTy::IntType::I128);
auto rbool = new TyTy::BoolType (mappings->get_next_hir_id ());
+ auto f32
+ = new TyTy::FloatType (mappings->get_next_hir_id (), TyTy::FloatType::F32);
+ auto f64
+ = new TyTy::FloatType (mappings->get_next_hir_id (), TyTy::FloatType::F64);
MKBUILTIN_TYPE ("u8", builtins, u8);
MKBUILTIN_TYPE ("u16", builtins, u16);
MKBUILTIN_TYPE ("u32", builtins, u32);
+ MKBUILTIN_TYPE ("u64", builtins, u64);
+ MKBUILTIN_TYPE ("u128", builtins, u128);
MKBUILTIN_TYPE ("i8", builtins, i8);
MKBUILTIN_TYPE ("i16", builtins, i16);
MKBUILTIN_TYPE ("i32", builtins, i32);
+ MKBUILTIN_TYPE ("i64", builtins, i64);
+ MKBUILTIN_TYPE ("i128", builtins, i128);
MKBUILTIN_TYPE ("bool", builtins, rbool);
+ MKBUILTIN_TYPE ("f32", builtins, f32);
+ MKBUILTIN_TYPE ("f64", builtins, f64);
}
void
@@ -271,5 +289,13 @@ ResolveExpr::visit (AST::BlockExpr &expr)
resolver->get_type_scope ().pop ();
}
+// rust-ast-resolve-struct-expr-field.h
+
+void
+ResolveStructExprField::visit (AST::StructExprFieldIdentifierValue &field)
+{
+ ResolveExpr::go (field.get_value ().get (), field.get_node_id ());
+}
+
} // namespace Resolver
} // namespace Rust