aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/typecheck/rust-tyty-call.h
blob: 9d795524ba5c6d51331c82137089dcb13bf835b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (C) 2020-2024 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_TYTY_CALL
#define RUST_TYTY_CALL

#include "rust-diagnostics.h"
#include "rust-hir-full.h"
#include "rust-tyty-visitor.h"
#include "rust-tyty.h"
#include "rust-hir-type-check.h"

namespace Rust {
namespace TyTy {

class TypeCheckCallExpr : private TyVisitor
{
public:
  static BaseType *go (BaseType *ref, HIR::CallExpr &call,
		       TyTy::VariantDef &variant,
		       Resolver::TypeCheckContext *context)
  {
    TypeCheckCallExpr checker (call, variant, context);
    ref->accept_vis (checker);
    return checker.resolved;
  }

  void visit (InferType &) override { rust_unreachable (); }
  void visit (TupleType &) override { rust_unreachable (); }
  void visit (ArrayType &) override { rust_unreachable (); }
  void visit (SliceType &) override { rust_unreachable (); }
  void visit (BoolType &) override { rust_unreachable (); }
  void visit (IntType &) override { rust_unreachable (); }
  void visit (UintType &) override { rust_unreachable (); }
  void visit (FloatType &) override { rust_unreachable (); }
  void visit (USizeType &) override { rust_unreachable (); }
  void visit (ISizeType &) override { rust_unreachable (); }
  void visit (ErrorType &) override { rust_unreachable (); }
  void visit (CharType &) override { rust_unreachable (); }
  void visit (ReferenceType &) override { rust_unreachable (); }
  void visit (PointerType &) override { rust_unreachable (); }
  void visit (ParamType &) override { rust_unreachable (); }
  void visit (StrType &) override { rust_unreachable (); }
  void visit (NeverType &) override { rust_unreachable (); }
  void visit (PlaceholderType &) override { rust_unreachable (); }
  void visit (ProjectionType &) override { rust_unreachable (); }
  void visit (DynamicObjectType &) override { rust_unreachable (); }
  void visit (ClosureType &type) override { rust_unreachable (); }

  // tuple-structs
  void visit (ADTType &type) override;

  // call fns
  void visit (FnType &type) override;
  void visit (FnPtr &type) override;

private:
  TypeCheckCallExpr (HIR::CallExpr &c, TyTy::VariantDef &variant,
		     Resolver::TypeCheckContext *context)
    : resolved (new TyTy::ErrorType (c.get_mappings ().get_hirid ())), call (c),
      variant (variant), context (context),
      mappings (Analysis::Mappings::get ())
  {}

  BaseType *resolved;
  HIR::CallExpr &call;
  TyTy::VariantDef &variant;
  Resolver::TypeCheckContext *context;
  Analysis::Mappings &mappings;
};

class Argument
{
public:
  Argument (Analysis::NodeMapping mapping, BaseType *argument_type,
	    location_t locus)
    : mapping (mapping), argument_type (argument_type), locus (locus)
  {}

  location_t get_locus () const { return locus; }

  BaseType *get_argument_type () { return argument_type; }

  Analysis::NodeMapping get_mappings () const { return mapping; }

private:
  Analysis::NodeMapping mapping;
  BaseType *argument_type;
  location_t locus;
};

class TypeCheckMethodCallExpr
{
public:
  static BaseType *go (FnType *ref, HIR::MethodCallExpr &call,
		       TyTy::BaseType *adjusted_self,
		       Resolver::TypeCheckContext *context);

  static BaseType *go (FnType *ref, Analysis::NodeMapping call_mappings,
		       std::vector<Argument> &args, location_t call_locus,
		       location_t receiver_locus, TyTy::BaseType *adjusted_self,
		       Resolver::TypeCheckContext *context);

protected:
  BaseType *check (FnType &type);

  TypeCheckMethodCallExpr (Analysis::NodeMapping call_mappings,
			   std::vector<Argument> &args, location_t call_locus,
			   location_t receiver_locus,
			   TyTy::BaseType *adjusted_self,
			   Resolver::TypeCheckContext *context);

  Analysis::NodeMapping call_mappings;
  std::vector<Argument> &arguments;
  location_t call_locus;
  location_t receiver_locus;
  TyTy::BaseType *adjusted_self;
  Resolver::TypeCheckContext *context;
  Analysis::Mappings &mappings;
};

} // namespace TyTy
} // namespace Rust

#endif // RUST_TYTY_CALL