Mercurial > projects > dang
annotate sema/TypeCheck.d @ 126:c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 27 May 2008 10:32:31 +0200 |
parents | 3a0cd42de9cc |
children | 57b0b4464a0b |
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, |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
4 sema.DType; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
5 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
6 import tango.io.Stdout; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
7 |
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
|
8 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
|
9 basic.Message; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
10 |
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
|
11 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
|
12 { |
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
|
13 this(MessageHandler messages) |
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.messages = messages; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
16 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
17 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
18 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
|
19 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
20 super.visitBinaryExp(exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
21 |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
22 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
|
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.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
|
25 !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
|
26 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
|
27 .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
|
28 .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
|
29 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
30 { |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 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
|
54 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 else |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 exp.right); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
70 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
71 |
126
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
72 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
|
73 { |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 else |
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.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
|
79 |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
80 } |
c3b24e7e8cf8
Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
114
diff
changeset
|
81 } |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
82 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
83 } |
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 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
|
86 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
87 super.visitCallExp(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 Exp[] newArgs; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
90 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
91 foreach(i, arg; exp.args) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
92 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
93 auto argType = (cast(DFunction)exp.exp.type).params[i]; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
94 auto expType = arg.type; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
95 if(argType.byteSize != expType.byteSize) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
96 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
97 if(!expType.hasImplicitConversionTo(argType)) |
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
|
98 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
|
99 .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
|
100 .arg(argType.toString); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
101 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
102 auto castExp = new CastExp( |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
103 SLoc.Invalid, |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
104 new Identifier(argType.name), |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
105 arg); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
106 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
|
107 newArgs ~= castExp; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
108 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
109 else |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
110 newArgs ~= arg; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
111 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
112 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
113 exp.args = newArgs; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
114 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
115 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
116 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
|
117 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
118 super.visitAssignExp(exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
119 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
120 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
|
121 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
|
122 |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
70
diff
changeset
|
123 if(identifierType != expType) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
124 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
125 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
|
126 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
|
127 .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
|
128 .arg(identifierType.toString); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
129 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
130 auto castExp = new CastExp( |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
131 SLoc.Invalid, |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
92
diff
changeset
|
132 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
|
133 exp.exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
134 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
|
135 exp.exp = castExp; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
136 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
137 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
138 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
139 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
|
140 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
141 super.visitReturnStmt(stmt); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
142 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
143 if(stmt.exp) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
144 { |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
70
diff
changeset
|
145 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
|
146 auto expType = stmt.exp.type; |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
70
diff
changeset
|
147 if(returnType != expType) |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
148 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
149 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
|
150 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
|
151 .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
|
152 .arg(returnType.toString); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
153 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
154 auto castExp = new CastExp( |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
155 SLoc.Invalid, |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
156 new Identifier(returnType.name), |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
157 stmt.exp); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
158 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
|
159 stmt.exp = castExp; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
160 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
161 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
162 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
163 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
164 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
|
165 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
166 super.visitVarDecl(decl); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
167 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
168 if(decl.init) |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
169 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
170 auto varType = decl.type; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
171 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
|
172 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
|
173 { |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
174 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
|
175 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
|
176 .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
|
177 .arg(varType.toString); |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
178 |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
179 auto castExp = new CastExp( |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
87
diff
changeset
|
180 SLoc.Invalid, |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
181 new Identifier(varType.name), |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
182 decl.init); |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
183 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
|
184 decl.init = castExp; |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
185 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
186 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
187 } |
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
|
188 |
3a0cd42de9cc
Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents:
107
diff
changeset
|
189 MessageHandler messages; |
70
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
190 } |
70a002b3fba4
Added missing files and also cleaned up some Stdout debug-output.
Anders Johnsen <skabet@gmail.com>
parents:
diff
changeset
|
191 |