annotate basic/Message.d @ 93:621cedba53ea new_gen

Removed the Symbol from semantics - it was not needed anymore. From now on you set the type by doing a setType on an Identifier.
author Anders Johnsen <skabet@gmail.com>
date Mon, 05 May 2008 20:53:13 +0200
parents 771ac63898e2
children 5f258eaf9517
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,
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
26 }
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
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
28 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
29 {
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 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
31
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 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
33 {
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 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
35 }
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
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
37 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
38 {
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
39 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
40 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
41 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
42 }
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
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
44 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
45 {
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 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
47 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
48
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
49 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
50 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
51 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
52 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
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 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
55 }
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 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
58 }
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 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
61 {
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
62 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
63 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
64 {
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 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
66 }
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
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
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 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
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 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
72 }
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 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
75 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
76 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
77 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
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
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 class Message
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
81 {
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
82
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
83 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
84 {
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
85 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
86 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
87 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
88 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
89 this.msg_handler = msg_handler;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
90 }
6
606a57c90a0b Now lexing == as Equals
johnsen@johnsen-desktop
parents: 1
diff changeset
91
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
92 char[] toString()
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
93 {
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
94 char[256] tmp = void;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
95 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
96
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 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
98
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 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
100
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 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
102 msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
103 else
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
104 msg = msg.dup;
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
105
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
106
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
107 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
108 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
109 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
110 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
111 marks[p .. p + t.length] = '^';
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
112
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
113 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
114 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
115 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
116 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
117
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
118 return msg;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
119 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
120
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
121 Message arg(char[] s)
6
606a57c90a0b Now lexing == as Equals
johnsen@johnsen-desktop
parents: 1
diff changeset
122 {
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
123 if (args.length == 11)
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
124 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
125 args ~= s;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
126 return this;
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
127 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
128
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
129 Message arg(char[][] s)
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
130 {
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
131 char[] res = s[0 .. $ - 1].join(", ");
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
132 if (s.length > 1)
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
133 res ~= " and ";
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
134 res ~= s[$ - 1];
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
135 return arg(res);
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
136 }
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
137
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
138 Message arg(char c)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
139 {
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
140 return arg([c]);
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
141 }
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
142
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
143 Message arg(DType[] types)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
144 {
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
145 char[][] res;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
146 foreach (type; types)
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
147 res ~= type.name();
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
148 return arg(res);
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
149 }
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
150
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
151 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
152 {
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 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
154 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
155 }
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
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 56
diff changeset
157 /*
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
158 Message loc(SLoc loc)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
159 {
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
160 location = loc;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
161 return this;
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
162 }
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 56
diff changeset
163 */
33
084c2c147c4f Improvements to the Error class.
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
164
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
165 MessageType type;
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
166 private:
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 24
diff changeset
167 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
168 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
169 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
170 MessageHandler msg_handler;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
171 }