Mercurial > projects > dang
annotate basic/Message.d @ 150:6c5a3c0bb4fb
Make switch work again
Also added locations to statements (only filled out for switch)
Added a verification pass
Removed some comments
author | Anders Halager <halager@gmail.com> |
---|---|
date | Mon, 21 Jul 2008 20:35:03 +0200 |
parents | 89db676fbacb |
children | 2a1a635bd531 |
rev | line source |
---|---|
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
1 module basic.Message; |
1 | 2 |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
3 import tango.core.Exception, |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
4 Array = tango.core.Array, |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
5 tango.io.Stdout, |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
6 tango.text.Util; |
1 | 7 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
8 import tango.stdc.stdlib; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
9 |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
10 import llvm.type; |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
11 |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
12 import lexer.Token, |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
13 lexer.Lexer, |
93
621cedba53ea
Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
Anders Johnsen <skabet@gmail.com>
parents:
92
diff
changeset
|
14 sema.DType; |
6 | 15 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
16 import basic.SourceLocation, |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
17 basic.SourceManager; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
18 |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
19 public import basic.Messages; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
20 |
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:
89
diff
changeset
|
21 enum ExitLevel |
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:
89
diff
changeset
|
22 { |
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:
89
diff
changeset
|
23 Normal = 1, |
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:
89
diff
changeset
|
24 Lexer = 2, |
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:
89
diff
changeset
|
25 Parser = 3, |
100
5f258eaf9517
Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents:
93
diff
changeset
|
26 Semantic = 3, |
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:
89
diff
changeset
|
27 } |
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:
89
diff
changeset
|
28 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
29 class MessageHandler |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
30 { |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
31 public: |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
32 |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
33 this(SourceManager src_mgr) |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
34 { |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
35 this.src_mgr = src_mgr; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
36 } |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
37 |
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:
89
diff
changeset
|
38 Message report(uint opcode, SLoc location) |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
39 { |
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:
89
diff
changeset
|
40 Message m = new Message(opcode, location, src_mgr, this); |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
41 messages ~= m; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
42 return m; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
43 } |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
44 |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
45 Message report(uint opcode, SLoc location1, SLoc location2) |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
46 { |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
47 Message m = new Message(opcode, location1, location2, src_mgr, this); |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
48 messages ~= m; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
49 return m; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
50 } |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
51 |
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:
89
diff
changeset
|
52 void checkErrors(ExitLevel exitlevel = ExitLevel.Normal) |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
53 { |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
54 if(messages.length == 0) |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
55 return; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
56 |
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:
89
diff
changeset
|
57 if(warnings) |
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:
89
diff
changeset
|
58 checkWarnings; |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
59 foreach(m ; messages) |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
60 if(m.type == MessageType.Error) |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
61 { |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
62 Stdout(m).newline; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
63 } |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
64 |
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:
89
diff
changeset
|
65 exit(exitlevel); |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
66 } |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
67 |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
68 void checkWarnings() |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
69 { |
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:
89
diff
changeset
|
70 foreach(m ; messages) |
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:
89
diff
changeset
|
71 if(m.type == MessageType.Warning) |
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:
89
diff
changeset
|
72 { |
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:
89
diff
changeset
|
73 Stdout(m).newline; |
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:
89
diff
changeset
|
74 } |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
75 } |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
76 |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
77 void showWarnings(bool value) |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
78 { |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
79 warnings = value; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
80 } |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
81 |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
82 private: |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
83 Message[] messages; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
84 SourceManager src_mgr; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
85 bool warnings; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
86 } |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
87 |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
88 class Message |
1 | 89 { |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
90 |
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:
89
diff
changeset
|
91 this(int opcode, SLoc location, SourceManager src_mgr, MessageHandler msg_handler) |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
92 { |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
93 this.src_mgr = src_mgr; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
94 this.location = location; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
95 args ~= Messages[opcode].message; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
96 this.type = Messages[opcode].type; |
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:
89
diff
changeset
|
97 this.msg_handler = msg_handler; |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
98 } |
6 | 99 |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
100 this(int opcode, SLoc location, SLoc end, SourceManager src_mgr, MessageHandler msg_handler) |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
101 { |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
102 this.src_mgr = src_mgr; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
103 this.location = location; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
104 this.end = end; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
105 args ~= Messages[opcode].message; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
106 this.type = Messages[opcode].type; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
107 this.msg_handler = msg_handler; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
108 haveEnd = true; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
109 } |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
110 |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
111 char[] toString() |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
112 { |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
113 char[256] tmp = void; |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
114 char[] msg = layout(tmp, args); |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
115 |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
116 int len = 0; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
117 if(!haveEnd) |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
118 { |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
119 Lexer l = new Lexer(location, src_mgr, new MessageHandler(src_mgr)); |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
120 |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
121 Token t = l.next; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
122 len = t.length; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
123 } |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
124 else |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
125 len = end - location; |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
126 |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
127 if (src_mgr.getRawData(location).length > 0) |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
128 msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg; |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
129 else |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
130 msg = msg.dup; |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
131 |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
132 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
133 char[] line = src_mgr.getLine(location); |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
134 char[] marks = line.dup; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
135 marks[] = ' '; |
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:
89
diff
changeset
|
136 size_t p = src_mgr.getColumn(location); |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
137 marks[p .. p + len] = '^'; |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
138 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
139 msg ~= "\n "; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
140 msg ~= line; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
141 msg ~= "\n "; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
142 msg ~= marks; |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
143 |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
144 return msg; |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
145 } |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
146 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
147 Message arg(char[] s) |
6 | 148 { |
150 | 149 if (args.length > 10) |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
150 throw new Exception("Sorry, errors only support up to 10 args"); |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
151 args ~= s; |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
152 return this; |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
153 } |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
154 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
155 Message arg(char[][] s) |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
156 { |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
157 char[] res = s[0 .. $ - 1].join(", "); |
36
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
33
diff
changeset
|
158 if (s.length > 1) |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
33
diff
changeset
|
159 res ~= " and "; |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
160 res ~= s[$ - 1]; |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
161 return arg(res); |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
162 } |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
163 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
164 Message arg(char c) |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
165 { |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
166 return arg([c]); |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
167 } |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
168 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
169 Message arg(DType[] types) |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
170 { |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
171 char[][] res; |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
172 foreach (type; types) |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
173 res ~= type.name(); |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
174 return arg(res); |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
175 } |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
176 |
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:
89
diff
changeset
|
177 Message fatal(ExitLevel exitlevel = ExitLevel.Normal) |
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:
89
diff
changeset
|
178 { |
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:
89
diff
changeset
|
179 msg_handler.checkErrors(exitlevel); |
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:
89
diff
changeset
|
180 return this; |
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:
89
diff
changeset
|
181 } |
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:
89
diff
changeset
|
182 |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
56
diff
changeset
|
183 /* |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
184 Message loc(SLoc loc) |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
185 { |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
186 location = loc; |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
187 return this; |
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
188 } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
56
diff
changeset
|
189 */ |
33
084c2c147c4f
Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents:
29
diff
changeset
|
190 |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
191 MessageType type; |
29
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
192 private: |
41d23f2762c3
Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents:
24
diff
changeset
|
193 char[][] args; |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
194 SLoc location, end; |
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
195 bool haveEnd; |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
196 SourceManager src_mgr; |
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:
89
diff
changeset
|
197 MessageHandler msg_handler; |
106
89db676fbacb
Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents:
100
diff
changeset
|
198 Token t; |
1 | 199 } |