[go: up one dir, main page]

Menu

[r49]: / trunk / error.e  Maximize  Restore  History

Download this file

198 lines (168 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
-- Euphoria 2.5
-- Compile-time Error Handling
include global.e
include reswords.e
include std/machine.e
include std/io.e
-- 22 + the final "too many" warning
constant MAX_WARNINGS = 23
integer Errors
Errors = 0 -- number of errors detected during compile
export integer TempErrFile
export sequence TempErrName
export object ThisLine -- current line of source (or -1)
export integer bp -- input line index of next character
export sequence warning_list
warning_list = {}
export procedure screen_output(integer f, sequence msg)
-- output messages to the screen or a file
puts(f, msg)
end procedure
export procedure Warning(sequence msg)
-- add a warning message to the list
sequence p
--?1/0
if OpWarning and length(warning_list) < MAX_WARNINGS then
if length(warning_list) = MAX_WARNINGS-1 then
p = "Too many warnings - no more will be issued"
else
p = sprintf("Warning: %s\n", {msg})
if find(p, warning_list) then
return -- duplicate
end if
end if
warning_list = append(warning_list, p)
end if
end procedure
export function ShowWarnings(integer errfile)
-- print the warnings to the screen (or ex.err)
for i = 1 to length(warning_list) do
if errfile = 0 then
screen_output(STDERR, warning_list[i])
else
puts(errfile, warning_list[i])
end if
end for
return length(warning_list)
end function
export procedure Cleanup(integer status)
-- clean things up before quitting
integer w
w = ShowWarnings(0)
if not TRANSLATE and
(BIND or EWINDOWS or ELINUX) and
(w or Errors) then
if getc(0) then -- prompt
end if
end if
-- begin mwl
if debugger > 0 then
c_proc( cleanup_cb, {})
debugger = 0
end if
-- Uncomment the following to get eu.ex tracebacks for where an error
-- ocurred. This is useful for development and debugging eu.ex:
-- if status = -1 then
-- ? 1/0
-- end if
-- end mwl
abort(status)
end procedure
export procedure OpenErrFile()
-- open the error diagnostics file - normally "ex.err"
TempErrFile = open(TempErrName, "w")
if TempErrFile = -1 then
if length(TempErrName) > 0 then
screen_output(STDERR, "Can't create error message file: ")
screen_output(STDERR, TempErrName)
screen_output(STDERR, "\n")
end if
abort(1) --Cleanup(1)
end if
end procedure
procedure ShowErr(integer f)
-- Show place where syntax error occurred
if length(file_name) = 0 then
return
end if
if ThisLine[1] = END_OF_FILE then
screen_output(f, "<end-of-file>\n")
else
screen_output(f, ThisLine)
end if
for i = 1 to bp-2 do
if ThisLine[i] = '\t' then
screen_output(f, "\t")
else
screen_output(f, " ")
end if
end for
screen_output(f, "^\n\n")
end procedure
export procedure CompileErr(sequence msg)
-- Handle fatal compilation errors
sequence errmsg
-- begin mwl
if find(1, eval_stack) and not length(eval_error[$]) then
if ThisLine[1] = END_OF_FILE then
errmsg = msg -- "<end-of-file>\n"
else
errmsg = msg & "\n" & ThisLine[1..bp-1] & "\n"
for i = 1 to bp - 2 do
if ThisLine[i] = '\t' then
errmsg &= '\t'
else
errmsg &= 32
end if
end for
errmsg &= "^\n"
end if
eval_error[$] = errmsg
geval_error = errmsg
call_proc(forward_putback,{{END_OF_FILE,0}})
return
elsif length(eval_error[$]) then
call_proc(forward_putback,{{END_OF_FILE,0}})
return
end if
-- end mwl
Errors += 1
if length(file_name) then
errmsg = sprintf("%s:%d\n%s\n", {file_name[current_file_no],
line_number, msg})
else
errmsg = msg
end if
-- try to open err file *before* displaying diagnostics on screen
OpenErrFile() -- exits if error filename is ""
screen_output(STDERR, errmsg)
ShowErr(STDERR)
puts(TempErrFile, errmsg)
ShowErr(TempErrFile)
if ShowWarnings(TempErrFile) then
end if
puts(TempErrFile, "\n")
close(TempErrFile)
--? 1/0
Cleanup(-1)
end procedure
procedure not_supported_compile(sequence feature)
-- report feature not supported
CompileErr(sprintf("%s is not supported in Euphoria for %s",
{feature, version_name}))
end procedure
export procedure InternalErr(sequence msg)
-- Handles internal compile-time errors
-- see RTInternal() for run-time internal errors
if TRANSLATE then
screen_output(STDERR, sprintf("Internal Error: %s\n", {msg}))
else
screen_output(STDERR, sprintf("\nInternal Error at %s:%d - %s\n",
{file_name[current_file_no], line_number, msg}))
end if
screen_output(STDERR, "\nPress Enter\n")
if getc(0) then
end if
? 1/0
abort(1)
end procedure