Branch data Line data Source code
1 : : // Copyright (C) 2020-2025 Free Software Foundation, Inc.
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 : :
28 : : namespace Rust {
29 : : namespace TyTy {
30 : :
31 : : class TypeCheckCallExpr : private TyVisitor
32 : : {
33 : : public:
34 : 10924 : static BaseType *go (BaseType *ref, HIR::CallExpr &call,
35 : : TyTy::VariantDef &variant,
36 : : Resolver::TypeCheckContext *context)
37 : : {
38 : 10924 : TypeCheckCallExpr checker (call, variant, context);
39 : 10924 : ref->accept_vis (checker);
40 : 10924 : return checker.resolved;
41 : : }
42 : :
43 : 0 : void visit (InferType &) override { rust_unreachable (); }
44 : 0 : void visit (TupleType &) override { rust_unreachable (); }
45 : 0 : void visit (ArrayType &) override { rust_unreachable (); }
46 : 0 : void visit (SliceType &) override { rust_unreachable (); }
47 : 0 : void visit (BoolType &) override { rust_unreachable (); }
48 : 0 : void visit (IntType &) override { rust_unreachable (); }
49 : 0 : void visit (UintType &) override { rust_unreachable (); }
50 : 0 : void visit (FloatType &) override { rust_unreachable (); }
51 : 0 : void visit (USizeType &) override { rust_unreachable (); }
52 : 0 : void visit (ISizeType &) override { rust_unreachable (); }
53 : 0 : void visit (ErrorType &) override { rust_unreachable (); }
54 : 0 : void visit (CharType &) override { rust_unreachable (); }
55 : 0 : void visit (ReferenceType &) override { rust_unreachable (); }
56 : 0 : void visit (PointerType &) override { rust_unreachable (); }
57 : 0 : void visit (ParamType &) override { rust_unreachable (); }
58 : 0 : void visit (StrType &) override { rust_unreachable (); }
59 : 0 : void visit (NeverType &) override { rust_unreachable (); }
60 : 0 : void visit (PlaceholderType &) override { rust_unreachable (); }
61 : 0 : void visit (ProjectionType &) override { rust_unreachable (); }
62 : 0 : void visit (DynamicObjectType &) override { rust_unreachable (); }
63 : 0 : void visit (ClosureType &) override { rust_unreachable (); }
64 : 0 : void visit (OpaqueType &) override { rust_unreachable (); }
65 : 0 : void visit (ConstParamType &) override { rust_unreachable (); }
66 : 0 : void visit (ConstValueType &) override { rust_unreachable (); }
67 : 0 : void visit (ConstInferType &) override { rust_unreachable (); }
68 : 0 : void visit (ConstErrorType &) override { rust_unreachable (); }
69 : :
70 : : // tuple-structs
71 : : void visit (ADTType &type) override;
72 : :
73 : : // call fns
74 : : void visit (FnType &type) override;
75 : : void visit (FnPtr &type) override;
76 : :
77 : : private:
78 : 10924 : TypeCheckCallExpr (HIR::CallExpr &c, TyTy::VariantDef &variant,
79 : : Resolver::TypeCheckContext *context)
80 : 10924 : : resolved (new TyTy::ErrorType (c.get_mappings ().get_hirid ())), call (c),
81 : 21848 : variant (variant), mappings (Analysis::Mappings::get ())
82 : 10924 : {}
83 : :
84 : : BaseType *resolved;
85 : : HIR::CallExpr &call;
86 : : TyTy::VariantDef &variant;
87 : : Analysis::Mappings &mappings;
88 : : };
89 : :
90 : : class Argument
91 : : {
92 : : public:
93 : 2099 : Argument (Analysis::NodeMapping mapping, BaseType *argument_type,
94 : : location_t locus)
95 : 2099 : : mapping (mapping), argument_type (argument_type), locus (locus)
96 : : {}
97 : :
98 : 2099 : location_t get_locus () const { return locus; }
99 : :
100 : 2099 : BaseType *get_argument_type () { return argument_type; }
101 : :
102 : 2099 : Analysis::NodeMapping get_mappings () const { return mapping; }
103 : :
104 : : private:
105 : : Analysis::NodeMapping mapping;
106 : : BaseType *argument_type;
107 : : location_t locus;
108 : : };
109 : :
110 : : class TypeCheckMethodCallExpr
111 : : {
112 : : public:
113 : : static BaseType *go (FnType *ref, HIR::MethodCallExpr &call,
114 : : TyTy::BaseType *adjusted_self,
115 : : Resolver::TypeCheckContext *context);
116 : :
117 : : static BaseType *go (FnType *ref, Analysis::NodeMapping call_mappings,
118 : : std::vector<Argument> &args, location_t call_locus,
119 : : location_t receiver_locus, TyTy::BaseType *adjusted_self,
120 : : Resolver::TypeCheckContext *context);
121 : :
122 : : protected:
123 : : BaseType *check (FnType &type);
124 : :
125 : : TypeCheckMethodCallExpr (Analysis::NodeMapping call_mappings,
126 : : std::vector<Argument> &args, location_t call_locus,
127 : : location_t receiver_locus,
128 : : TyTy::BaseType *adjusted_self,
129 : : Resolver::TypeCheckContext *context);
130 : :
131 : : Analysis::NodeMapping call_mappings;
132 : : std::vector<Argument> &arguments;
133 : : location_t call_locus;
134 : : location_t receiver_locus;
135 : : TyTy::BaseType *adjusted_self;
136 : : Resolver::TypeCheckContext *context;
137 : : Analysis::Mappings &mappings;
138 : : };
139 : :
140 : : } // namespace TyTy
141 : : } // namespace Rust
142 : :
143 : : #endif // RUST_TYTY_CALL
|