AAda Compiler Error Package

17
Jan
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
with ada.text_io;
with aada_compiler_token_position;
with aada_vstrings;
with ada.command_line;
 
package body aada_compiler_error_package is
 
-- TODO: the idea here is to transform the PUT() to
--       console to a PUT() to whatever the user specifies
--       (i.e. console, text file, network connection, etc.)
procedure output_error(compiler_error: in out aada_compiler_error;
                code: in errcode;
                position: aada_compiler_token_position.token_position_type;
                label: in string;
                message: in string) is
  package position_type_io is new
      ada.text_io.integer_io(aada_compiler_token_position.position_type); 
begin
  aada_vstrings.put(aada_compiler_token_position.get_position_filename(position));
  ada.text_io.put(":");
  position_type_io.put(aada_compiler_token_position
                                  .get_position(position));
  ada.text_io.put(":");
  position_type_io.put(aada_compiler_token_position.get_position(position,
                                        aada_compiler_token_position.character));
  ada.text_io.put(":");
  ada.text_io.put(label);
  ada.text_io.put(":");
  ada.text_io.put(message);
  ada.text_io.new_line;
end output_error;
 
procedure todo(compiler_error: in out aada_compiler_error;
               code: in errcode;
               position: aada_compiler_token_position.token_position_type;
               message: in string) is
begin
  compiler_error.todo_count := natural'succ(compiler_error.todo_count);
  output_error(compiler_error, code, position, "todo", message);
end todo;
 
procedure error(compiler_error: in out aada_compiler_error;
                code: in errcode;
                position: aada_compiler_token_position.token_position_type;
                message: in string) is
begin
  ada.command_line.set_exit_status(ada.command_line.failure);
  compiler_error.error_count := natural'succ(compiler_error.error_count);
  output_error(compiler_error, code, position, "error", message);
end error;
 
procedure warning(compiler_error: in out aada_compiler_error;
                  code: in errcode;
                  position: aada_compiler_token_position.token_position_type;
                  message: in string) is
begin
  if compiler_error.warnings_are_errors then
    error(compiler_error, code, position, message);
  else
    compiler_error.warning_count := natural'succ(compiler_error.warning_count);
    output_error(compiler_error, code, position, "warning", message);
  end if;
end warning;
 
end aada_compiler_error_package;
 
-- vim: ts=2 sw=2 et syntax=ada
Project aada v1.0-338 (Project id #3)
Process Done (Last compiled on 2012/01/13 01:21:26)
Description Alexis Ada Compiler written in Ada (my first attempt was in C++ which is not correct for an Ada compiler.)