Mercurial > projects > dang
comparison sema/TypeCheck.d @ 174:20ff3c31f600
Putting symbol on MemberRef -calls.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Thu, 24 Jul 2008 21:06:42 +0200 |
parents | 7982eb63c0eb |
children | c8e26556c24d |
comparison
equal
deleted
inserted
replaced
173:50b98a06a200 | 174:20ff3c31f600 |
---|---|
86 | 86 |
87 override void visitCallExp(CallExp exp) | 87 override void visitCallExp(CallExp exp) |
88 { | 88 { |
89 super.visitCallExp(exp); | 89 super.visitCallExp(exp); |
90 | 90 |
91 if (auto iden = cast(Identifier)exp.exp) | 91 Stdout(exp.exp).newline; |
92 { | 92 if (auto iden = cast(MemberReference)exp.exp) |
93 { | |
94 Symbol[] internalVisitMemberRef(MemberReference m) | |
95 { | |
96 Symbol[] visitRef(MemberReference m, Identifier target, Symbol st) | |
97 { | |
98 auto child = m.child; | |
99 auto res = st.findMembers(child.get); | |
100 return res; | |
101 } | |
102 switch(m.target.expType) | |
103 { | |
104 case ExpType.Identifier: | |
105 return visitRef(m, cast(Identifier)m.target, | |
106 (cast(Identifier)m.target).getSymbol); | |
107 case ExpType.MemberReference: | |
108 Symbol[] s = internalVisitMemberRef(cast(MemberReference)m.target); | |
109 if(s.length) | |
110 return s; | |
111 return visitRef(m, cast(Identifier)m.target, s[0]); | |
112 } | |
113 } | |
114 | |
93 Exp[] newArgs; | 115 Exp[] newArgs; |
94 | 116 |
95 Symbol[] methods; | 117 Symbol[] methods = internalVisitMemberRef(iden); |
96 | |
97 foreach (decl ; iden.env.find(iden.get)) | |
98 methods ~= decl.sym; | |
99 | 118 |
100 if (!methods.length) | 119 if (!methods.length) |
101 { | 120 { |
102 messages.report(NoMethodByName, iden.loc); | 121 messages.report(NoMethodByName, iden.loc); |
103 return; | 122 return; |
139 messages.report(CandidateNr, | 158 messages.report(CandidateNr, |
140 (cast(FuncDecl)s.decl).identifier.loc) | 159 (cast(FuncDecl)s.decl).identifier.loc) |
141 .arg(Integer.toString(i+1)); | 160 .arg(Integer.toString(i+1)); |
142 } | 161 } |
143 } | 162 } |
144 | 163 } |
164 else if (auto iden = cast(Identifier)exp.exp) | |
165 { | |
166 Exp[] newArgs; | |
167 | |
168 Symbol[] methods; | |
169 | |
170 foreach (decl ; iden.env.find(iden.get)) | |
171 methods ~= decl.sym; | |
172 | |
173 if (!methods.length) | |
174 { | |
175 messages.report(NoMethodByName, iden.loc); | |
176 return; | |
177 } | |
178 | |
179 Symbol sel = getBestMatch(exp.args, methods); | |
180 | |
181 if (sel) | |
182 { | |
183 foreach (i, arg; exp.args) | |
184 { | |
185 auto argType = sel.type.asFunction.params[i]; | |
186 auto expType = arg.type; | |
187 if (argType.byteSize != expType.byteSize) | |
188 { | |
189 if (!expType.hasImplicitConversionTo(argType)) | |
190 messages.report(InvalidImplicitCast, exp.loc) | |
191 .arg(expType.toString) | |
192 .arg(argType.toString); | |
193 | |
194 auto castExp = new CastExp( | |
195 SLoc.Invalid, | |
196 new Identifier(argType.name), | |
197 arg); | |
198 castExp.env = iden.env; | |
199 newArgs ~= castExp; | |
200 } | |
201 else | |
202 newArgs ~= arg; | |
203 } | |
204 exp.args = newArgs; | |
205 exp.callSym = sel; | |
206 } | |
207 else | |
208 { | |
209 messages.report(NoMachingMethod, exp.loc); | |
210 foreach ( i, s ; methods ) | |
211 { | |
212 messages.report(CandidateNr, | |
213 (cast(FuncDecl)s.decl).identifier.loc) | |
214 .arg(Integer.toString(i+1)); | |
215 } | |
216 } | |
145 } | 217 } |
146 else | 218 else |
147 { | 219 { |
148 Exp[] newArgs; | 220 Exp[] newArgs; |
149 | 221 |