OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [src/] [error.c] - Blame information for rev 180

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
#include "c.h"
2
 
3
static char rcsid[] = "$Id: error.c,v 1.1 2002/08/28 23:12:43 drh Exp $";
4
 
5
static void printtoken(void);
6
int errcnt   = 0;
7
int errlimit = 20;
8
char kind[] = {
9
#define xx(a,b,c,d,e,f,g) f,
10
#define yy(a,b,c,d,e,f,g) f,
11
#include "token.h"
12
};
13
int wflag;              /* != 0 to suppress warning messages */
14
 
15
void test(int tok, char set[]) {
16
        if (t == tok)
17
                t = gettok();
18
        else {
19
                expect(tok);
20
                skipto(tok, set);
21
                if (t == tok)
22
                        t = gettok();
23
        }
24
}
25
void expect(int tok) {
26
        if (t == tok)
27
                t = gettok();
28
        else {
29
                error("syntax error; found");
30
                printtoken();
31
                fprint(stderr, " expecting `%k'\n", tok);
32
        }
33
}
34
void error(const char *fmt, ...) {
35
        va_list ap;
36
 
37
        if (errcnt++ >= errlimit) {
38
                errcnt = -1;
39
                error("too many errors\n");
40
                exit(1);
41
        }
42
        va_start(ap, fmt);
43
        if (firstfile != file && firstfile && *firstfile)
44
                fprint(stderr, "%s: ", firstfile);
45
        fprint(stderr, "%w: ", &src);
46
        vfprint(stderr, NULL, fmt, ap);
47
        va_end(ap);
48
}
49
 
50
void skipto(int tok, char set[]) {
51
        int n;
52
        char *s;
53
 
54
        assert(set);
55
        for (n = 0; t != EOI && t != tok; t = gettok()) {
56
                for (s = set; *s && kind[t] != *s; s++)
57
                        ;
58
                if (kind[t] == *s)
59
                        break;
60
                if (n++ == 0)
61
                        error("skipping");
62
                if (n <= 8)
63
                        printtoken();
64
                else if (n == 9)
65
                        fprint(stderr, " ...");
66
        }
67
        if (n > 8) {
68
                fprint(stderr, " up to");
69
                printtoken();
70
        }
71
        if (n > 0)
72
                fprint(stderr, "\n");
73
}
74
/* fatal - issue fatal error message and exit */
75
int fatal(const char *name, const char *fmt, int n) {
76
        print("\n");
77
        errcnt = -1;
78
        error("compiler error in %s--", name);
79
        fprint(stderr, fmt, n);
80
        exit(EXIT_FAILURE);
81
        return 0;
82
}
83
 
84
/* printtoken - print current token preceeded by a space */
85
static void printtoken(void) {
86
        switch (t) {
87
        case ID: fprint(stderr, " `%s'", token); break;
88
        case ICON:
89
                fprint(stderr, " `%s'", vtoa(tsym->type, tsym->u.c.v));
90
                break;
91
        case SCON: {
92
                int i, n;
93
                if (ischar(tsym->type->type)) {
94
                        char *s = tsym->u.c.v.p;
95
                        n = tsym->type->size;
96
                        fprint(stderr, " \"");
97
                        for (i = 0; i < 20 && i < n && *s; s++, i++)
98
                                if (*s < ' ' || *s >= 0177)
99
                                        fprint(stderr, "\\%o", *s);
100
                                else
101
                                        fprint(stderr, "%c", *s);
102
                } else {        /* wchar_t string */
103
                        unsigned int *s = tsym->u.c.v.p;
104
                        assert(tsym->type->type->size == widechar->size);
105
                        n = tsym->type->size/widechar->size;
106
                        fprint(stderr, " L\"");
107
                        for (i = 0; i < 20 && i < n && *s; s++, i++)
108
                                if (*s < ' ' || *s >= 0177)
109
                                        fprint(stderr, "\\x%x", *s);
110
                                else
111
                                        fprint(stderr, "%c", *s);
112
                }
113
                if (i < n)
114
                        fprint(stderr, " ...");
115
                else
116
                        fprint(stderr, "\"");
117
                break;
118
                }
119
        case FCON:
120
                fprint(stderr, " `%S'", token, (char*)cp - token);
121
                break;
122
        case '`': case '\'': fprint(stderr, " \"%k\"", t); break;
123
        default: fprint(stderr, " `%k'", t);
124
        }
125
}
126
 
127
/* warning - issue warning error message */
128
void warning(const char *fmt, ...) {
129
        va_list ap;
130
 
131
        va_start(ap, fmt);
132
        if (wflag == 0) {
133
                errcnt--;
134
                error("warning: ");
135
                vfprint(stderr, NULL, fmt, ap);
136
        }
137
        va_end(ap);
138
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.