annotate basic/Message.d @ 100:5f258eaf9517 new_gen

Loading modules in. Just need to add them to the scope of the "main" Module now.
author Anders Johnsen <skabet@gmail.com>
date Tue, 06 May 2008 22:49:43 +0200
parents 621cedba53ea
children 89db676fbacb
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
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
45 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
46 {
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
47 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
48 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
49
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
50 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
51 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
52 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
53 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
54 {
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 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
56 }
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
57
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
58 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
59 }
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 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
62 {
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
63 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
64 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
65 {
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
66 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
67 }
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
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
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 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
71 {
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
72 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
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 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
76 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
77 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
78 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
79 }
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 class Message
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
82 {
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
83
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
84 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
85 {
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
86 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
87 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
88 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
89 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
90 this.msg_handler = msg_handler;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
91 }
6
606a57c90a0b Now lexing == as Equals
johnsen@johnsen-desktop
parents: 1
diff changeset
92
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
93 char[] toString()
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
94 {
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
95 char[256] tmp = void;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
96 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
97
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
98 Lexer l = new Lexer(location, src_mgr, new MessageHandler(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
99
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 Token t = l.next;
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
101
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 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
103 msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
104 else
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
105 msg = msg.dup;
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
106
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
107
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
108 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
109 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
110 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
111 size_t p = src_mgr.getColumn(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
112 marks[p .. p + t.length] = '^';
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
113
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
114 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
115 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
116 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
117 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
118
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
119 return msg;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
120 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
121
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
122 Message arg(char[] s)
6
606a57c90a0b Now lexing == as Equals
johnsen@johnsen-desktop
parents: 1
diff changeset
123 {
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
124 if (args.length == 11)
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
125 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
126 args ~= s;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
127 return this;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
128 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
129
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
130 Message arg(char[][] s)
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 char[] res = s[0 .. $ - 1].join(", ");
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
133 if (s.length > 1)
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
134 res ~= " and ";
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
135 res ~= s[$ - 1];
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
136 return arg(res);
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
137 }
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 Message arg(char c)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
140 {
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
141 return arg([c]);
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
142 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
143
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
144 Message arg(DType[] types)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
145 {
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
146 char[][] res;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
147 foreach (type; types)
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
148 res ~= type.name();
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
149 return arg(res);
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
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
152 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
153 {
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
154 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
155 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
156 }
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
157
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 56
diff changeset
158 /*
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
159 Message loc(SLoc loc)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
160 {
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
161 location = loc;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
162 return this;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
163 }
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 56
diff changeset
164 */
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
165
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
166 MessageType type;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
167 private:
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
168 char[][] 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
169 SLoc 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
170 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
171 MessageHandler msg_handler;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
172 }