annotate sema/ScopeCheck.d @ 135:9869194de9b7

Removed some output We have 15 tests that fail in release mode and 17 in debug - both from things that are only handled by an assert. One is a comments lexing test, that fails on an invalid location in debug The other is returning a struct - it's cought in codegen by an assert, but should be checked explicitly before that
author Anders Halager <halager@gmail.com>
date Wed, 09 Jul 2008 13:38:11 +0200
parents 6545a8d59596
children 2be29b296081
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.ScopeCheck;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
2
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
3 import sema.Visitor,
130
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
4 sema.Symbol,
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
5 sema.DType;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
6
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
7 import basic.Message;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
8
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
9 import tango.io.Stdout;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
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 ScopeCheck : Visitor!(void)
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
12 {
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
13
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
14 this(MessageHandler messages)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 28
diff changeset
15 {
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
16 this.messages = messages;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 28
diff changeset
17 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 28
diff changeset
18
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
19 override void visitIdentifier(Identifier i)
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
20 {
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
21 auto symbol = i.env.find(i);
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
22
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
23 if(symbol is null)
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
24 messages.report(UndefinedIdentifier, i.loc)
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
25 .arg(i.get);
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
26 }
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
27
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
28 override void visitVarDecl(VarDecl d)
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
29 {
63
9f8131676242 Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
30 if(!d.env.findType(d.varType))
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
31 messages.report(UndefinedType, d.varType.loc)
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
32 .arg(d.varType.get);
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
33
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
34 visitExp(d.identifier);
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
35 if (d.init)
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
36 visitExp(d.init);
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
37 }
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 63
diff changeset
38
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
39 override void visitFuncDecl(FuncDecl f)
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
40 {
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
41 visitExp(f.identifier);
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
42
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
43 foreach (stmt; f.statements)
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
44 visitStmt(stmt);
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
45 }
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
46
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 92
diff changeset
47 override void visitImportDecl(ImportDecl) { }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 92
diff changeset
48
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 63
diff changeset
49 override void visitCastExp(CastExp exp)
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 63
diff changeset
50 {
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 63
diff changeset
51 visitExp(exp.exp);
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 63
diff changeset
52 }
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 63
diff changeset
53
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 39
diff changeset
54 override void visitMemberReference(MemberReference m)
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
55 {
130
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
56 internalVisitMemberRef(m);
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
57 }
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
58
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
59 private Symbol internalVisitMemberRef(MemberReference m)
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
60 {
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
61 switch(m.target.expType)
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
62 {
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
63 case ExpType.Identifier:
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
64 auto target = cast(Identifier)m.target;
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
65 auto child = m.child;
130
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
66 auto st = target.getSymbol;
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
67 auto res = st.findMember(child.get);
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
68
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
69 if(!res)
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
70 messages.report(MissingMember, m.loc)
130
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
71 .arg(st.type.name)
30
3147a52d1247 Ooops.. should have compiled before commit.. now works again
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
72 .arg(target.get)
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 68
diff changeset
73 .arg(child.get);
130
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
74
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
75 return res;
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 39
diff changeset
76 case ExpType.MemberReference:
130
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
77 Symbol s = internalVisitMemberRef(cast(MemberReference)m.target);
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
78 if(!s)
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
79 return null;
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
80 auto target = cast(Identifier)m.target;
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
81 auto child = m.child;
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
82 auto res = s.findMember(child.get);
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
83
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
84 if(!res)
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
85 messages.report(MissingMember, m.loc)
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
86 .arg(s.type.name)
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
87 .arg(s.getFQN)
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
88 .arg(child.get);
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
89
6545a8d59596 Recursive member-lookup.
Anders Johnsen <skabet@gmail.com>
parents: 114
diff changeset
90 return res;
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
91 }
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 24
diff changeset
92 }
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
93
63
9f8131676242 Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
94 private bool isType(char[] s)
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
95 {
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
96 return (s in types? true : false);
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
97 }
114
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
98
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
99 int[char[]] types;
3a0cd42de9cc Removed misc/Error.d and is now using the error system all way through.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
100 MessageHandler messages;
13
e5caf9971207 Checking for types and identifiers. TODO: Make each varDecl create a new scope
johnsen@johnsen-desktop
parents:
diff changeset
101 }
22
e331e4e816e4 now handling structs to some extend
johnsen@johnsen-laptop
parents: 15
diff changeset
102