cfad47cfa3/t3compiler/tads3/tcmain.h

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
/* $Header: d:/cvsroot/tads/tads3/TCMAIN.H,v 1.3 1999/07/11 00:46:53 MJRoberts Exp $ */
2
3
/* 
4
 *   Copyright (c) 1999, 2002 Michael J. Roberts.  All Rights Reserved.
5
 *   
6
 *   Please see the accompanying license file, LICENSE.TXT, for information
7
 *   on using and copying this software.  
8
 */
9
/*
10
Name
11
  tcmain.h - TADS 3 Compiler - main compiler driver
12
Function
13
  
14
Notes
15
  
16
Modified
17
  04/22/99 MJRoberts  - Creation
18
*/
19
20
#ifndef TCMAIN_H
21
#define TCMAIN_H
22
23
#include <stdarg.h>
24
25
#include "t3std.h"
26
#include "tcerr.h"
27
28
/* 
29
 *   error display option flags
30
 */
31
#define TCMAIN_ERR_VERBOSE  0x00000001              /* use verbose messages */
32
#define TCMAIN_ERR_NUMBERS  0x00000002       /* include numeric error codes */
33
#define TCMAIN_ERR_WARNINGS 0x00000004                     /* show warnings */
34
#define TCMAIN_ERR_PEDANTIC 0x00000008           /* show pendantic warnings */
35
#define TCMAIN_ERR_TESTMODE 0x00000010                      /* testing mode */
36
#define TCMAIN_ERR_FNAME_QU 0x00000020                   /* quote filenames */
37
38
39
/* 
40
 *   main compiler driver class 
41
 */
42
class CTcMain
43
{
44
public:
45
    /* Initialize the compiler.  Creates all global objects. */
46
    static void init(class CTcHostIfc *hostifc,
47
                     class CResLoader *res_loader,
48
                     const char *default_charset);
49
50
    /* Terminate the compiler.  Deletes all global objects. */
51
    static void terminate();
52
53
    /* initialize/terminate the error subsystem */
54
    static void tc_err_init(size_t param_stack_size,
55
                            class CResLoader *res_loader);
56
    static void tc_err_term();
57
    
58
    /* log an error - varargs arguments - static routine */
59
    static void S_log_error(class CTcTokFileDesc *linedesc, long linenum,
60
                            int *err_counter, int *warn_counter,
61
                            unsigned long options,
62
                            const int *suppress_list, size_t suppress_cnt,
63
                            tc_severity_t severity, int err, ...)
64
    {
65
        va_list args;
66
67
        /* pass through to our va_list-style handler */
68
        va_start(args, err);
69
        S_v_log_error(linedesc, linenum, err_counter, warn_counter, 0, 0,
70
                      options, suppress_list, suppress_cnt,
71
                      severity, err, args);
72
        va_end(args);
73
    }
74
75
    /* log an error - arguments from a CVmException object */
76
    static void S_log_error(class CTcTokFileDesc *linedesc, long linenum,
77
                            int *err_counter, int *warn_counter,
78
                            unsigned long options,
79
                            const int *suppress_list, size_t suppress_cnt,
80
                            tc_severity_t severity,
81
                            struct CVmException *exc);
82
83
    /* show or don't show numeric error codes */
84
    void set_show_err_numbers(int show)
85
    {
86
        if (show)
87
            err_options_ |= TCMAIN_ERR_NUMBERS;
88
        else
89
            err_options_ &= ~TCMAIN_ERR_NUMBERS;
90
    }
91
92
    /* set verbosity for error messages */
93
    void set_verbosity(int verbose)
94
    {
95
        if (verbose)
96
            err_options_ |= TCMAIN_ERR_VERBOSE;
97
        else
98
            err_options_ &= ~TCMAIN_ERR_VERBOSE;
99
    }
100
101
    /* turn all warnings on or off */
102
    void set_warnings(int show)
103
    {
104
        if (show)
105
            err_options_ |= TCMAIN_ERR_WARNINGS;
106
        else
107
            err_options_ &= ~TCMAIN_ERR_WARNINGS;
108
    }
109
110
    /* turn pedantic warnings on or off */
111
    void set_pedantic(int show)
112
    {
113
        if (show)
114
            err_options_ |= TCMAIN_ERR_PEDANTIC;
115
        else
116
            err_options_ &= ~TCMAIN_ERR_PEDANTIC;
117
    }
118
119
    /* 
120
     *   Get/set regression test reporting mode.  In test mode, we'll only
121
     *   show the root name of each file in our status reports and error
122
     *   messages.  This is useful when running regression tests, because it
123
     *   allows us to diff the compiler output against a reference log
124
     *   without worrying about the local directory structure.  
125
     */
126
    int get_test_report_mode() const
127
        { return (err_options_ & TCMAIN_ERR_TESTMODE) != 0; }
128
    void set_test_report_mode(int flag)
129
    {
130
        if (flag)
131
            err_options_ |= TCMAIN_ERR_TESTMODE;
132
        else
133
            err_options_ &= ~TCMAIN_ERR_TESTMODE;
134
    }
135
136
    /* 
137
     *   Set the quoted filenames option.  If this option is set, we'll quote
138
     *   the filenames we report in our error messages; this makes it easier
139
     *   for automated tools to parse the error messages, because it ensures
140
     *   that the contents of a filename won't be mistaken for part of the
141
     *   error message format.  
142
     */
143
    void set_quote_filenames(int flag)
144
    {
145
        if (flag)
146
            err_options_ |= TCMAIN_ERR_FNAME_QU;
147
        else
148
            err_options_ &= ~TCMAIN_ERR_FNAME_QU;
149
    }
150
151
    /*
152
     *   Set an array of warning codes to suppress.  We will suppress any
153
     *   warnings and pedantic warnings whose error numbers appear in this
154
     *   array; errors of greater severity will be shown even when they
155
     *   appear here.
156
     *   
157
     *   The memory of this list is managed by the caller.  We merely keep a
158
     *   reference to the caller's array.  The caller is responsible for
159
     *   ensuring that the memory remains valid for as long as we're around.
160
     */
161
    void set_suppress_list(const int *lst, size_t cnt)
162
    {
163
        /* remember the list and its size */
164
        suppress_list_ = lst;
165
        suppress_cnt_ = cnt;
166
    }
167
168
    /* log an error - va_list-style arguments - static routine */
169
    static void S_v_log_error(class CTcTokFileDesc *linedesc, long linenum,
170
                              int *err_counter, int *warn_counter,
171
                              int *first_error, int *first_warning,
172
                              unsigned long options,
173
                              const int *suppress_list, size_t suppress_cnt,
174
                              tc_severity_t severity, int err, va_list args);
175
176
    /* log an error - varargs */
177
    void log_error(class CTcTokFileDesc *linedesc, long linenum,
178
                   tc_severity_t severity, int err, ...)
179
    {
180
        va_list args;
181
182
        /* pass through to our va_list-style handler */
183
        va_start(args, err);
184
        v_log_error(linedesc, linenum, severity, err, args);
185
        va_end(args);
186
    }
187
188
    void v_log_error(class CTcTokFileDesc *linedesc, long linenum,
189
                     tc_severity_t severity, int err, va_list args)
190
    {
191
        /* call our static routine */
192
        S_v_log_error(linedesc, linenum, &error_count_, &warning_count_,
193
                      &first_error_, &first_warning_, err_options_,
194
                      suppress_list_, suppress_cnt_,
195
                      severity, err, args);
196
197
        /* if we've exceeded the maximum error limit, throw a fatal error */
198
        check_error_limit();
199
    }
200
201
    /* get the error/warning count */
202
    int get_error_count() const { return error_count_; }
203
    int get_warning_count() const { return warning_count_; }
204
205
    /* reset the error and warning counters */
206
    void reset_error_counts()
207
    {
208
        /* clear the counters */
209
        error_count_ = 0;
210
        warning_count_ = 0;
211
212
        /* clear the error/warning memories */
213
        first_error_ = 0;
214
        first_warning_ = 0;
215
    }
216
217
    /* 
218
     *   get the first compilation error/warning code - we keep track of
219
     *   these for times when we have limited error reporting capabilities
220
     *   and can only report a single error, such as when we're compiling
221
     *   an expression in the debugger 
222
     */
223
    int get_first_error() const { return first_error_; }
224
    int get_first_warning() const { return first_warning_; }
225
226
    /* 
227
     *   check the error count against the error limit, and throw a fatal
228
     *   error if we've exceeded it 
229
     */
230
    void check_error_limit();
231
232
    /* get the console output character mapper */
233
    static class CCharmapToLocal *get_console_mapper()
234
        { return console_mapper_; }
235
236
private:
237
    CTcMain(class CResLoader *res_loader, const char *default_charset);
238
    ~CTcMain();
239
240
    /* error and warning count */
241
    int error_count_;
242
    int warning_count_;
243
244
    /* first error/warning code we've encountered */
245
    int first_error_;
246
    int first_warning_;
247
248
    /*
249
     *   Maximum error limit - if we encounter more than this many errors
250
     *   in a single compilation unit, we'll abort the compilation with a
251
     *   fatal error.  This at least limits the amount of garbage we'll
252
     *   display if we run into a really bad cascading parsing error
253
     *   situation where we just can't resynchronize.  
254
     */
255
    int max_error_count_;
256
257
    /* error options - this is a combination of TCMAIN_ERR_xxx flags */
258
    unsigned long err_options_;
259
260
    /*
261
     *   An array of warning messages to suppress.  We'll only use this to
262
     *   suppress warnings and pedantic warnings; errors of greater severity
263
     *   will be displayed even if they appear in this list.  The memory used
264
     *   for this list is managed by our client; we just keep a reference to
265
     *   the client's list.  
266
     */
267
    const int *suppress_list_;
268
    size_t suppress_cnt_;
269
270
    /* resource loader */
271
    class CResLoader *res_loader_;
272
273
    /* default character set name */
274
    char *default_charset_;
275
276
    /* 
277
     *   flag: we have tried loading an external compiler error message
278
     *   file and failed; if we fail once during a session, we won't try
279
     *   again, to avoid repeated searches for a message file during
280
     *   compilations of multiple files 
281
     */
282
    static int err_no_extern_messages_;
283
284
    /* count of references to the error subsystem */
285
    static int err_refs_;
286
287
    /* 
288
     *   The console character mapper.  We use this to map error messages
289
     *   to the console character set.  This is a static so that we can
290
     *   access it from the static error message printer routines.  
291
     */
292
    static class CCharmapToLocal *console_mapper_;
293
};
294
295
#endif /* TCMAIN_H */
296