annotate basic/Message.d @ 189:75d0544ddc45

Better error handling on unexpected EOF.
author Anders Johnsen <skabet@gmail.com>
date Fri, 25 Jul 2008 13:50:01 +0200
parents 2a1a635bd531
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
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
606a57c90a0b Now lexing == as Equals
johnsen@johnsen-desktop
parents: 1
diff changeset
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
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
45 Message report(uint opcode, SourceRange[] ranges, SourceLocation[] locs)
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
46 {
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
47 Message m = new Message(opcode, ranges, locs, src_mgr, this);
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
48 messages ~= m;
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
49 return m;
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
50 }
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
51
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
52 Message report(uint opcode, SLoc location1, SLoc location2, SLoc location3 = SLoc.Invalid)
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
53 {
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
54 Message m = new Message(opcode, [SourceRange(location1, location2)][], [location3][], src_mgr, this);
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
55 messages ~= m;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
56 return m;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
57 }
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
58
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
59 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
60 {
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 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
62 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
63
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
64 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
65 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
66 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
67 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
68 {
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 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
70 }
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
71
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
72 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
73 }
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
74
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 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
76 {
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
77 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
78 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
79 {
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
80 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
81 }
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
82 }
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
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 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
85 {
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 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
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
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
89 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
90 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
91 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
92 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
93 }
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
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 class Message
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
96 {
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
97
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
98 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
99 {
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
100 this.src_mgr = src_mgr;
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
101 this.interests ~= 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
102 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
103 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
104 this.msg_handler = msg_handler;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
105 }
6
606a57c90a0b Now lexing == as Equals
johnsen@johnsen-desktop
parents: 1
diff changeset
106
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
107 this(int opcode, SourceRange[] locs, SLoc[] interests,
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
108 SourceManager src_mgr, MessageHandler msg_handler)
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
109 in
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
110 {
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
111 assert(locs.length + interests.length, "Atleast one location is requiret for a mark");
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
112 }
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
113 body
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
114 {
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
115 this.src_mgr = src_mgr;
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
116 this.locs = locs;
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
117 this.interests = interests;
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
118 args ~= Messages[opcode].message;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
119 this.type = Messages[opcode].type;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
120 this.msg_handler = msg_handler;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
121 haveEnd = true;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
122 }
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
123
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
124 char[] toString()
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
125 {
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
126 char[256] tmp = void;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
127 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
128
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
129 SLoc location;
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
130 if (interests.length)
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
131 location = interests[0];
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
132 else
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
133 location = locs[0].begin;
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
134
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
135 int len = 0;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
136 if(!haveEnd)
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
137 {
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
138 Lexer l = new Lexer(interests[0], 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
139
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
140 Token t = l.next;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
141 len = t.length;
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
142 }
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
143 // else
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
144 // 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
145
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
146 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
147 msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
148 else
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
149 msg = msg.dup;
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
150
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
151
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
152 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
153 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
154 marks[] = ' ';
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
155
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
156 foreach (s ; locs)
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
157 {
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
158 size_t p = src_mgr.getColumn(s.begin);
189
75d0544ddc45 Better error handling on unexpected EOF.
Anders Johnsen <skabet@gmail.com>
parents: 179
diff changeset
159 marks[p .. p + (s.end-s.begin)] = interests.length ? '~' : '^';
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
160 }
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
161
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
162 foreach (interest ; interests)
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
163 {
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
164 size_t i = src_mgr.getColumn(interest);
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
165 marks[i] = '^';
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
166 }
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
167
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
168 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
169 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
170 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
171 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
172
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
173 return msg;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
174 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
175
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
176 Message arg(char[] s)
6
606a57c90a0b Now lexing == as Equals
johnsen@johnsen-desktop
parents: 1
diff changeset
177 {
150
6c5a3c0bb4fb Make switch work again
Anders Halager <halager@gmail.com>
parents: 106
diff changeset
178 if (args.length > 10)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
179 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
180 args ~= s;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
181 return this;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
182 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
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 arg(char[][] s)
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
185 {
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
186 char[] res = s[0 .. $ - 1].join(", ");
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
187 if (s.length > 1)
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
188 res ~= " and ";
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
189 res ~= s[$ - 1];
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
190 return arg(res);
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
191 }
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
192
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
193 Message arg(char c)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
194 {
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
195 return arg([c]);
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
196 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
197
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
198 Message arg(DType[] types)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
199 {
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
200 char[][] res;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
201 foreach (type; types)
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
202 res ~= type.name();
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
203 return arg(res);
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
204 }
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
205
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
206 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
207 {
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
208 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
209 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
210 }
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
211
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 56
diff changeset
212 /*
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
213 Message loc(SLoc loc)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
214 {
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
215 location = loc;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
216 return this;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
217 }
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 56
diff changeset
218 */
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
219
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
220 MessageType type;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
221 private:
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
222 char[][] args;
179
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
223 SourceRange[] locs;
2a1a635bd531 Changes the way messages can be displayed. Also added a toString to DType's for type printing.
Anders Johnsen <skabet@gmail.com>
parents: 150
diff changeset
224 SLoc[] interests;
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
225 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
226 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
227 MessageHandler msg_handler;
106
89db676fbacb Now able of understanding strings.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
228 Token t;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
229 }