Mercurial > projects > dang
annotate sema/TypeCheck.d @ 181:59cd211a1bd3
Better support for function pointers
author | Anders Halager <halager@gmail.com> |
---|---|
date | Fri, 25 Jul 2008 01:39:01 +0200 |
parents | 2a1a635bd531 |
children | 8ea749b7da91 |
rev | line source |
---|---|
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
1 module sema.TypeCheck; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
2 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
3 import sema.Visitor, |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
4 sema.Symbol, |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
5 sema.DType; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
6 |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
7 import tango.io.Stdout, |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
8 Integer = tango.text.convert.Integer; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
9 |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
10 import basic.SourceLocation, |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
11 basic.Message; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
12 |
92
771ac63898e2
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
13 class TypeCheck : Visitor!(void) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
14 { |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
15 this(MessageHandler messages) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
16 { |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
17 this.messages = messages; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
18 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
19 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
20 override void visitBinaryExp(BinaryExp exp) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
21 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
22 super.visitBinaryExp(exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
23 |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
24 if(!(exp.left.type is exp.right.type)) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
25 { |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
26 if (!exp.right.type.hasImplicitConversionTo(exp.left.type) && |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
27 !exp.left.type.hasImplicitConversionTo(exp.right.type)) |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
28 messages.report(InvalidImplicitCast, exp.loc) |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
29 .arg(exp.right.type.toString) |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
30 .arg(exp.left.type.toString); |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
31 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
32 { |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
33 CastExp castExp; |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
34 if(exp.left.type.isReal && exp.right.type.isReal) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
35 if(exp.left.type.byteSize > exp.right.type.byteSize) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
36 castExp = new CastExp( |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
37 SLoc.Invalid, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
38 new Identifier(exp.left.type.name), |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
39 exp.right); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
40 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
41 castExp = new CastExp( |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
42 SLoc.Invalid, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
43 new Identifier(exp.right.type.name), |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
44 exp.left); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
45 else if(exp.left.type.isReal || exp.right.type.isReal) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
46 if(exp.left.type.isReal) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
47 castExp = new CastExp( |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
48 SLoc.Invalid, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
49 new Identifier(exp.left.type.name), |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
50 exp.right); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
51 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
52 castExp = new CastExp( |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
53 SLoc.Invalid, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
54 new Identifier(exp.right.type.name), |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
55 exp.left); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
56 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
57 if(exp.left.type.byteSize > exp.right.type.byteSize) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
58 castExp = new CastExp( |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
59 SLoc.Invalid, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
60 new Identifier(exp.left.type.name), |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
61 exp.right); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
62 else if(exp.left.type.byteSize > exp.right.type.byteSize) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
63 castExp = new CastExp( |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
64 SLoc.Invalid, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
65 new Identifier(exp.right.type.name), |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
66 exp.left); |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
67 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
68 castExp = new CastExp( |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
69 SLoc.Invalid, |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
70 new Identifier(exp.left.type.name), |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
71 exp.right); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
72 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
73 |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
74 if(castExp) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
75 { |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
76 castExp.env = exp.env; |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
77 if(castExp.exp == exp.right) |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
78 exp.right = castExp; |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
79 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
80 exp.left = castExp; |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
81 |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
82 } |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
83 } |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
84 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
85 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
86 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
87 override void visitCallExp(CallExp exp) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
88 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
89 super.visitCallExp(exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
90 |
174
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
91 if (auto iden = cast(MemberReference)exp.exp) |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
92 { |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
93 Symbol[] internalVisitMemberRef(MemberReference m) |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
94 { |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
95 Symbol[] visitRef(MemberReference m, Identifier target, Symbol st) |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
96 { |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
97 auto child = m.child; |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
98 auto res = st.findMembers(child.get); |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
99 return res; |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
100 } |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
101 switch(m.target.expType) |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
102 { |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
103 case ExpType.Identifier: |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
104 return visitRef(m, cast(Identifier)m.target, |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
105 (cast(Identifier)m.target).getSymbol); |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
106 case ExpType.MemberReference: |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
107 Symbol[] s = internalVisitMemberRef(cast(MemberReference)m.target); |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
108 if(s.length) |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
109 return s; |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
110 return visitRef(m, cast(Identifier)m.target, s[0]); |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
111 } |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
112 } |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
113 |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
114 Exp[] newArgs; |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
115 |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
116 DFunction function_type; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
117 if (iden.type.isFunction()) |
174
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
118 { |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
119 Symbol[] methods = internalVisitMemberRef(iden); |
174
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
120 |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
121 if (!methods.length) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
122 { |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
123 messages.report(NoMethodByName, iden.loc); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
124 return; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
125 } |
174
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
126 |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
127 Symbol sel = getBestMatch(exp.args, methods); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
128 exp.callSym = sel; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
129 if (sel) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
130 function_type = sel.type.asFunction(); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
131 else |
174
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
132 { |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
133 messages.report(NoMachingMethod, exp.loc); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
134 foreach ( i, s ; methods ) |
174
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
135 { |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
136 messages.report(CandidateNr, |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
137 (cast(FuncDecl)s.decl).identifier.loc) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
138 .arg(Integer.toString(i+1)); |
174
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
139 } |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
140 } |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
141 } |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
142 else if (iden.type.isCallable) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
143 function_type = iden.type.asCallable(); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
144 else assert(0, "Should not happen"); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
145 |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
146 foreach (i, arg; exp.args) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
147 { |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
148 auto argType = function_type.params[i]; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
149 auto expType = arg.type; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
150 if (argType.isSame(expType)) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
151 { |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
152 if (!expType.hasImplicitConversionTo(argType)) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
153 messages.report(InvalidImplicitCast, exp.loc) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
154 .arg(expType.toString) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
155 .arg(argType.toString); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
156 |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
157 auto castExp = new CastExp( |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
158 SLoc.Invalid, |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
159 new Identifier(argType.name), |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
160 arg); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
161 castExp.env = iden.env; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
162 newArgs ~= castExp; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
163 } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
164 else |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
165 newArgs ~= arg; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
166 } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
167 exp.args = newArgs; |
174
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
168 } |
20ff3c31f600
Putting symbol on MemberRef -calls.
Anders Johnsen <skabet@gmail.com>
parents:
168
diff
changeset
|
169 else if (auto iden = cast(Identifier)exp.exp) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
170 { |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
171 Exp[] newArgs; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
172 |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
173 DFunction function_type; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
174 if (iden.type.isFunction()) |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
175 { |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
176 Symbol[] methods; |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
177 |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
178 foreach (decl ; iden.env.find(iden.get)) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
179 methods ~= decl.sym; |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
180 |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
181 if (!methods.length) |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
182 { |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
183 messages.report(NoMethodByName, iden.loc); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
184 return; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
185 } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
186 |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
187 Symbol sel = getBestMatch(exp.args, methods); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
188 exp.callSym = sel; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
189 if (sel) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
190 function_type = sel.type.asFunction(); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
191 else |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
192 { |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
193 messages.report(NoMachingMethod, exp.loc); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
194 foreach ( i, s ; methods ) |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
195 { |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
196 messages.report(CandidateNr, |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
197 (cast(FuncDecl)s.decl).identifier.loc) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
198 .arg(Integer.toString(i+1)); |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
199 } |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
200 } |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
201 } |
181
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
202 else if (iden.type.isCallable) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
203 function_type = iden.type.asCallable(); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
204 else assert(0, "Should not happen"); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
205 |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
206 foreach (i, arg; exp.args) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
207 { |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
208 auto argType = function_type.params[i]; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
209 auto expType = arg.type; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
210 if (argType.isSame(expType)) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
211 { |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
212 if (!expType.hasImplicitConversionTo(argType)) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
213 messages.report(InvalidImplicitCast, exp.loc) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
214 .arg(expType.toString) |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
215 .arg(argType.toString); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
216 |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
217 auto castExp = new CastExp( |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
218 SLoc.Invalid, |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
219 new Identifier(argType.name), |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
220 arg); |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
221 castExp.env = iden.env; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
222 newArgs ~= castExp; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
223 } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
224 else |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
225 newArgs ~= arg; |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
226 } |
59cd211a1bd3
Better support for function pointers
Anders Halager <halager@gmail.com>
parents:
179
diff
changeset
|
227 exp.args = newArgs; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
228 } |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
229 else |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
230 { |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
231 Exp[] newArgs; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
232 |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
233 foreach(i, arg; exp.args) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
234 { |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
235 auto argType = exp.exp.type.asFunction.params[i]; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
236 auto expType = arg.type; |
177
491b5fc4782a
Small fixes to type checks.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
237 if(!argType.isSame(expType)) |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
238 { |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
239 if(!expType.hasImplicitConversionTo(argType)) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
240 messages.report(InvalidImplicitCast, exp.loc) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
241 .arg(expType.toString) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
242 .arg(argType.toString); |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
243 |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
244 auto castExp = new CastExp( |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
245 SLoc.Invalid, |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
246 new Identifier(argType.name), |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
247 arg); |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
248 castExp.env = exp.exp.env; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
249 newArgs ~= castExp; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
250 } |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
251 else |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
252 newArgs ~= arg; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
253 } |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
254 |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
255 exp.args = newArgs; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
256 } |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
257 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
258 |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
259 override void visitNewExp(NewExp exp) |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
260 { |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
261 super.visitNewExp(exp); |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
262 |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
263 Exp[] newArgs; |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
264 |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
265 Symbol[] methods = exp.newType.getSymbol.findFunctionMembers("this"); |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
266 |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
267 if (!methods.length) |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
268 { |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
269 messages.report(NoConstructor, exp.newType.loc); |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
270 return; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
271 } |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
272 |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
273 Symbol sel = getBestMatch(exp.c_args, methods); |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
274 |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
275 if (sel) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
276 { |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
277 foreach (i, arg; exp.c_args) |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
278 { |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
279 auto argType = sel.type.asFunction.params[i]; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
280 auto expType = arg.type; |
177
491b5fc4782a
Small fixes to type checks.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
281 if (!argType.isSame(expType)) |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
282 { |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
283 if (!expType.hasImplicitConversionTo(argType)) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
284 messages.report(InvalidImplicitCast, exp.loc) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
285 .arg(expType.toString) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
286 .arg(argType.toString); |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
287 |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
288 auto castExp = new CastExp( |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
289 SLoc.Invalid, |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
290 new Identifier(argType.name), |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
291 arg); |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
292 castExp.env = exp.newType.env; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
293 newArgs ~= castExp; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
294 } |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
295 else |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
296 newArgs ~= arg; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
297 } |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
298 exp.c_args = newArgs; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
299 exp.callSym = sel; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
300 } |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
301 else |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
302 { |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
303 messages.report(NoMachingCon, exp.newType.loc); |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
304 foreach ( i, s ; methods ) |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
305 { |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
306 messages.report(CandidateNr, |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
307 (cast(FuncDecl)s.decl).identifier.loc) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
308 .arg(Integer.toString(i+1)); |
158
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
309 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
310 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
311 } |
57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
Anders Johnsen <skabet@gmail.com>
parents:
126
diff
changeset
|
312 |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
313 override void visitAssignExp(AssignExp exp) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
314 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
315 super.visitAssignExp(exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
316 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
317 auto identifierType = exp.identifier.type; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
318 auto expType = exp.exp.type; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
319 |
176
dc9bf56b7ace
Can now use & as a unary operator and take an AddressOf
Anders Johnsen <skabet@gmail.com>
parents:
175
diff
changeset
|
320 if(!identifierType.isSame(expType)) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
321 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
322 if(!expType.hasImplicitConversionTo(identifierType)) |
179
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
177
diff
changeset
|
323 messages.report(InvalidImplicitCast, |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
177
diff
changeset
|
324 [exp.identifier.sourceRange, exp.exp.sourceRange][], |
2a1a635bd531
Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents:
177
diff
changeset
|
325 [exp.loc]) |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
326 .arg(expType.toString) |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
327 .arg(identifierType.toString); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
328 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
329 auto castExp = new CastExp( |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
330 SLoc.Invalid, |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
92
diff
changeset
|
331 new Identifier(identifierType.name), |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
332 exp.exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
333 castExp.env = exp.exp.env; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
334 exp.exp = castExp; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
335 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
336 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
337 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
338 override void visitReturnStmt(ReturnStmt stmt) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
339 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
340 super.visitReturnStmt(stmt); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
341 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
342 if(stmt.exp) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
343 { |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
70
diff
changeset
|
344 auto returnType = stmt.env.parentFunction.type.asFunction.returnType; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
345 auto expType = stmt.exp.type; |
177
491b5fc4782a
Small fixes to type checks.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
346 if(!returnType.isSame(expType)) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
347 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
348 if(!expType.hasImplicitConversionTo(returnType)) |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
349 messages.report(InvalidImplicitCast, stmt.exp.loc) |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
350 .arg(expType.toString) |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
351 .arg(returnType.toString); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
352 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
353 auto castExp = new CastExp( |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
354 SLoc.Invalid, |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
355 new Identifier(returnType.name), |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
356 stmt.exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
357 castExp.env = stmt.exp.env; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
358 stmt.exp = castExp; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
359 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
360 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
361 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
362 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
363 override void visitVarDecl(VarDecl decl) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
364 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
365 super.visitVarDecl(decl); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
366 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
367 if(decl.init) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
368 { |
160 | 369 auto varType = decl.identifier.type; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
370 auto expType = decl.init.type; |
177
491b5fc4782a
Small fixes to type checks.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
371 if(!varType.isSame(expType)) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
372 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
373 if(!expType.hasImplicitConversionTo(varType)) |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
374 messages.report(InvalidImplicitCast, decl.init.loc) |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
375 .arg(expType.toString) |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
376 .arg(varType.toString); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
377 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
378 auto castExp = new CastExp( |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
379 SLoc.Invalid, |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
380 new Identifier(varType.name), |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
381 decl.init); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
382 castExp.env = decl.init.env; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
383 decl.init = castExp; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
384 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
385 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
386 } |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
387 |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
388 private Symbol getBestMatch(Exp[] arg_list , Symbol[] available) |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
389 in |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
390 { |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
391 foreach (a ; available) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
392 assert(a.type.isFunction, "A non-function found in available-list."); |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
393 } |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
394 body |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
395 { |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
396 assert(available.length, "No available methods in symbol-list."); |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
397 |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
398 Symbol[] possible; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
399 Symbol perfect; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
400 |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
401 foreach (s ; available) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
402 { |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
403 if (s.type.asFunction.params.length < arg_list.length) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
404 continue; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
405 |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
406 bool per = true; |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
407 bool work = true; |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
408 |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
409 foreach (i, arg; arg_list) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
410 { |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
411 auto argType = s.type.asFunction.params[i]; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
412 auto expType = arg.type; |
177
491b5fc4782a
Small fixes to type checks.
Anders Johnsen <skabet@gmail.com>
parents:
176
diff
changeset
|
413 if (argType.isSame(expType)) |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
414 { |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
415 per = false; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
416 if( !expType.hasImplicitConversionTo(argType) ) |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
417 { |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
418 work = false; |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
419 break; |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
420 } |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
421 } |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
422 } |
168
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
423 |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
424 foreach (a ; (cast(FuncDecl)s.decl).funcArgs[arg_list.length..$]) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
425 if (a.init is null) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
426 work = false; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
427 |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
428 if (work) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
429 if (per) |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
430 return s; |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
431 else |
7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
Anders Johnsen <skabet@gmail.com>
parents:
165
diff
changeset
|
432 possible ~= s; |
165
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
433 } |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
434 |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
435 if (possible.length) |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
436 return possible[0]; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
437 |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
438 return null; |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
439 } |
7606387b2f0a
Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents:
164
diff
changeset
|
440 |
114
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
441 MessageHandler messages; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
442 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
443 |