source: tags/ms_r16q3/AISC/aisc_location.h

Last change on this file was 7413, checked in by westram, 13 years ago

merged from dev [7355] [7369] [7370]

  • Refactored AISC (interpreter)
    • separated 'struct global' into several classes (mostly 'Interpreter').
    • precompile all commands and use a dispatcher
  • changes to behavior
    • new command WARNING
    • detects deadlocks
    • error if referencing data w/o loading it
    • error when files are not closed
    • tweaked/added several errors reported
File size: 2.4 KB
Line 
1//   Coded by Ralf Westram (coder@reallysoft.de) in March 2011   //
2//   Institute of Microbiology (Technical University Munich)     //
3//   http://www.arb-home.de/                                     //
4
5#ifndef AISC_LOCATION_H
6#define AISC_LOCATION_H
7
8#ifndef DUPSTR_H
9#include <dupstr.h>
10#endif
11
12class Location {
13    int linenr;
14    char *path;
15   
16    void print_internal(const char *msg, const char *msg_type, const char *launcher_file, int launcher_line) const;
17
18    void fprint_location(const char *file, int line, FILE *fp) const {
19        fprintf(fp, "%s:%i: ", file, line);
20    }
21    void fprint_location(FILE *fp) const {
22        fprint_location(path, linenr, fp);
23    }
24
25    static Location exit_pc;
26    static int global_error_count;
27   
28public:
29
30    Location() : linenr(-666), path(NULL) {}
31    Location(int linenr_, const char *path_)
32        : linenr(linenr_), path(strdup(path_)) { }
33    Location(const Location& other)
34        : linenr(other.linenr), path(strdup(other.path)) { }
35    Location& operator=(const Location& other) {
36        linenr = other.linenr;
37        freedup(path, other.path);
38        return *this;
39    }
40    ~Location() { free(path); }
41
42    bool valid() const { return path != 0; }
43
44    const char *get_path() const { return path; }
45    int get_linenr() const { return linenr; }
46
47    void print_error_internal(const char *err, const char *launcher_file, int launcher_line) const {
48        print_internal(err, "Error", launcher_file, launcher_line);
49        global_error_count++;
50    }
51    void print_warning_internal(const char *msg, const char *launcher_file, int launcher_line) const {
52        print_internal(msg, "Warning", launcher_file, launcher_line);
53    }
54    void start_message(const char *prefix) const {
55        print_internal(NULL, prefix, NULL, 0);
56    }
57
58    static const Location& guess_pc();
59    static void announce_exit_pc(const Location& exitingHere) { exit_pc = exitingHere; }
60
61    static int get_error_count() { return global_error_count; }
62
63    Location& operator++() {
64        aisc_assert(valid());
65        linenr++;
66        return *this;
67    }
68    bool operator == (const Location& other) const {
69        if (!valid()) return !other.valid();
70        return linenr == other.linenr && strcmp(path, other.path) == 0;
71    }
72    bool operator != (const Location& other) const { return !(*this == other); }
73};
74
75#else
76#error aisc_location.h included twice
77#endif // AISC_LOCATION_H
Note: See TracBrowser for help on using the repository browser.