]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/rust/typecheck/rust-tyty-call.h
Update copyright years.
[thirdparty/gcc.git] / gcc / rust / typecheck / rust-tyty-call.h
CommitLineData
a945c346 1// Copyright (C) 2020-2024 Free Software Foundation, Inc.
06688fe4
PH
2
3// This file is part of GCC.
4
5// GCC is free software; you can redistribute it and/or modify it under
6// the terms of the GNU General Public License as published by the Free
7// Software Foundation; either version 3, or (at your option) any later
8// version.
9
10// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11// WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13// for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with GCC; see the file COPYING3. If not see
17// <http://www.gnu.org/licenses/>.
18
19#ifndef RUST_TYTY_CALL
20#define RUST_TYTY_CALL
21
22#include "rust-diagnostics.h"
23#include "rust-hir-full.h"
24#include "rust-tyty-visitor.h"
25#include "rust-tyty.h"
26#include "rust-hir-type-check.h"
27
28namespace Rust {
29namespace TyTy {
30
31class TypeCheckCallExpr : private TyVisitor
32{
33public:
34 static BaseType *go (BaseType *ref, HIR::CallExpr &call,
35 TyTy::VariantDef &variant,
36 Resolver::TypeCheckContext *context)
37 {
38 TypeCheckCallExpr checker (call, variant, context);
39 ref->accept_vis (checker);
40 return checker.resolved;
41 }
42
43 void visit (InferType &) override { gcc_unreachable (); }
44 void visit (TupleType &) override { gcc_unreachable (); }
45 void visit (ArrayType &) override { gcc_unreachable (); }
46 void visit (SliceType &) override { gcc_unreachable (); }
47 void visit (BoolType &) override { gcc_unreachable (); }
48 void visit (IntType &) override { gcc_unreachable (); }
49 void visit (UintType &) override { gcc_unreachable (); }
50 void visit (FloatType &) override { gcc_unreachable (); }
51 void visit (USizeType &) override { gcc_unreachable (); }
52 void visit (ISizeType &) override { gcc_unreachable (); }
53 void visit (ErrorType &) override { gcc_unreachable (); }
54 void visit (CharType &) override { gcc_unreachable (); }
55 void visit (ReferenceType &) override { gcc_unreachable (); }
56 void visit (PointerType &) override { gcc_unreachable (); }
57 void visit (ParamType &) override { gcc_unreachable (); }
58 void visit (StrType &) override { gcc_unreachable (); }
59 void visit (NeverType &) override { gcc_unreachable (); }
60 void visit (PlaceholderType &) override { gcc_unreachable (); }
61 void visit (ProjectionType &) override { gcc_unreachable (); }
62 void visit (DynamicObjectType &) override { gcc_unreachable (); }
63 void visit (ClosureType &type) override { gcc_unreachable (); }
64
65 // tuple-structs
66 void visit (ADTType &type) override;
67
68 // call fns
69 void visit (FnType &type) override;
70 void visit (FnPtr &type) override;
71
72private:
73 TypeCheckCallExpr (HIR::CallExpr &c, TyTy::VariantDef &variant,
74 Resolver::TypeCheckContext *context)
75 : resolved (new TyTy::ErrorType (c.get_mappings ().get_hirid ())), call (c),
76 variant (variant), context (context),
77 mappings (Analysis::Mappings::get ())
78 {}
79
80 BaseType *resolved;
81 HIR::CallExpr &call;
82 TyTy::VariantDef &variant;
83 Resolver::TypeCheckContext *context;
84 Analysis::Mappings *mappings;
85};
86
4d021d9e 87class Argument
06688fe4
PH
88{
89public:
4d021d9e
PH
90 Argument (Analysis::NodeMapping mapping, BaseType *argument_type,
91 Location locus)
92 : mapping (mapping), argument_type (argument_type), locus (locus)
93 {}
06688fe4 94
4d021d9e 95 Location get_locus () const { return locus; }
06688fe4 96
4d021d9e 97 BaseType *get_argument_type () { return argument_type; }
06688fe4 98
4d021d9e 99 Analysis::NodeMapping get_mappings () const { return mapping; }
06688fe4
PH
100
101private:
4d021d9e
PH
102 Analysis::NodeMapping mapping;
103 BaseType *argument_type;
104 Location locus;
105};
106
107class TypeCheckMethodCallExpr
108{
109public:
110 static BaseType *go (FnType *ref, HIR::MethodCallExpr &call,
111 TyTy::BaseType *adjusted_self,
112 Resolver::TypeCheckContext *context);
113
114 static BaseType *go (FnType *ref, Analysis::NodeMapping call_mappings,
115 std::vector<Argument> &args, Location call_locus,
116 Location receiver_locus, TyTy::BaseType *adjusted_self,
117 Resolver::TypeCheckContext *context);
118
119protected:
120 BaseType *check (FnType &type);
121
122 TypeCheckMethodCallExpr (Analysis::NodeMapping call_mappings,
123 std::vector<Argument> &args, Location call_locus,
124 Location receiver_locus,
06688fe4 125 TyTy::BaseType *adjusted_self,
4d021d9e 126 Resolver::TypeCheckContext *context);
06688fe4 127
4d021d9e
PH
128 Analysis::NodeMapping call_mappings;
129 std::vector<Argument> &arguments;
130 Location call_locus;
131 Location receiver_locus;
06688fe4
PH
132 TyTy::BaseType *adjusted_self;
133 Resolver::TypeCheckContext *context;
134 Analysis::Mappings *mappings;
135};
136
137} // namespace TyTy
138} // namespace Rust
139
140#endif // RUST_TYTY_CALL