annotate sema/TypeCheck.d @ 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.
author Anders Johnsen <skabet@gmail.com>
date Thu, 24 Jul 2008 12:06:48 +0200
parents 7606387b2f0a
children 20ff3c31f600
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
91 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
92 {
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
93 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
94
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
95 Symbol[] methods;
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
96
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
97 foreach (decl ; iden.env.find(iden.get))
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
98 methods ~= decl.sym;
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
99
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
100 if (!methods.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
101 {
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
102 messages.report(NoMethodByName, iden.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
103 return;
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
104 }
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
105
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
106 Symbol sel = getBestMatch(exp.args, methods);
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
107
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
108 if (sel)
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
109 {
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
110 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
111 {
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
112 auto argType = sel.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
113 auto expType = arg.type;
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
114 if (argType.byteSize != expType.byteSize)
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
115 {
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
116 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
117 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
118 .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
119 .arg(argType.toString);
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
120
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
121 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
122 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
123 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
124 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
125 castExp.env = iden.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
126 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
127 }
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
128 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
129 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
130 }
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
131 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
132 exp.callSym = sel;
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
133 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
134 else
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
135 {
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
136 messages.report(NoMachingMethod, 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
137 foreach ( i, s ; methods )
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
138 {
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
139 messages.report(CandidateNr,
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
140 (cast(FuncDecl)s.decl).identifier.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
141 .arg(Integer.toString(i+1));
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
142 }
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
143 }
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
144
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
145 }
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
146 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
147 {
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
148 Exp[] newArgs;
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
149
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
150 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
151 {
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
152 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
153 auto expType = arg.type;
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
154 if(argType.byteSize != expType.byteSize)
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
155 {
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
156 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
157 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
158 .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
159 .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
160
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
161 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
162 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
163 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
164 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
165 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
166 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
167 }
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
168 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
169 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
170 }
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
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 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
173 }
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
174 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
175
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
176 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
177 {
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
178 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
179
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
180 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
181
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 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
183
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
184 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
185 {
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
186 messages.report(NoConstructor, exp.newType.loc);
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
187 return;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
188 }
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
189
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
190 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
191
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
192 if (sel)
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
193 {
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
194 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
195 {
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
196 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
197 auto expType = arg.type;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
198 if (argType.byteSize != expType.byteSize)
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
199 {
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
200 if (!expType.hasImplicitConversionTo(argType))
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
201 messages.report(InvalidImplicitCast, exp.loc)
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
202 .arg(expType.toString)
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
203 .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
204
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
205 auto castExp = new CastExp(
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
206 SLoc.Invalid,
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
207 new Identifier(argType.name),
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
208 arg);
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
209 castExp.env = exp.newType.env;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
210 newArgs ~= castExp;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
211 }
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
212 else
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
213 newArgs ~= arg;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
214 }
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
215 exp.c_args = newArgs;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
216 exp.callSym = sel;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
217 }
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
218 else
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
219 {
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
220 messages.report(NoMachingCon, exp.newType.loc);
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
221 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
222 {
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
223 messages.report(CandidateNr,
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
224 (cast(FuncDecl)s.decl).identifier.loc)
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
225 .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
226 }
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
227 }
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
228 }
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
229
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
230 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
231 {
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
232 super.visitAssignExp(exp);
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
233
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
234 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
235 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
236
80
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 70
diff changeset
237 if(identifierType != expType)
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
238 {
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
239 if(!expType.hasImplicitConversionTo(identifierType))
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
240 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
241 .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
242 .arg(identifierType.toString);
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
243
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
244 auto castExp = new CastExp(
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
245 SLoc.Invalid,
107
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 92
diff changeset
246 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
247 exp.exp);
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
248 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
249 exp.exp = castExp;
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
250 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
251 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
252
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
253 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
254 {
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
255 super.visitReturnStmt(stmt);
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
256
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
257 if(stmt.exp)
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
258 {
80
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 70
diff changeset
259 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
260 auto expType = stmt.exp.type;
80
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 70
diff changeset
261 if(returnType != expType)
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
262 {
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
263 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
264 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
265 .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
266 .arg(returnType.toString);
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
267
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
268 auto castExp = new CastExp(
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
269 SLoc.Invalid,
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
270 new Identifier(returnType.name),
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
271 stmt.exp);
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
272 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
273 stmt.exp = castExp;
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
274 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
275 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
276 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
277
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
278 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
279 {
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
280 super.visitVarDecl(decl);
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
281
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
282 if(decl.init)
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
283 {
160
6cb2f4201e2a Improved static arrays
Anders Halager <halager@gmail.com>
parents: 158
diff changeset
284 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
285 auto expType = decl.init.type;
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
286 if(varType.byteSize != expType.byteSize)
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
287 {
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
288 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
289 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
290 .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
291 .arg(varType.toString);
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
292
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
293 auto castExp = new CastExp(
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 87
diff changeset
294 SLoc.Invalid,
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
295 new Identifier(varType.name),
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
296 decl.init);
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
297 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
298 decl.init = castExp;
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
299 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
300 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
301 }
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
302
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
303 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
304 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
305 {
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
306 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
307 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
308 }
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
309 body
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
310 {
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
311 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
312
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
313 Symbol[] possible;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
314 Symbol perfect;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
315
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
316 foreach (s ; available)
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
317 {
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
318 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
319 continue;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
320
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
321 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
322 bool work = true;
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
323
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
324 foreach (i, arg; arg_list)
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
325 {
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
326 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
327 auto expType = arg.type;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
328 if (argType != expType)
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
329 {
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
330 per = false;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
331 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
332 {
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
333 work = false;
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
334 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
335 }
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
336 }
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
337 }
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
338
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
339 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
340 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
341 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
342
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
343 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
344 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
345 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
346 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
347 possible ~= s;
165
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
348 }
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
349
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
350 if (possible.length)
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
351 return possible[0];
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
352
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
353 return null;
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
354 }
7606387b2f0a Better handling of param checking on method calls.
Anders Johnsen <skabet@gmail.com>
parents: 164
diff changeset
355
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
356 MessageHandler messages;
70
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
357 }
70a002b3fba4 Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
358