Allow log_ statements outside of a class
[delight/core.git] / gcc-mars.cc
blobb3c8826392a22676497226695da9199ae9a6bfa6
1 /* Pieces of mars.c needed for for GCC
3 Original copyright from mars.c:
5 // Copyright (c) 1999-2007 by Digital Mars
6 // All Rights Reserved
7 // written by Walter Bright
8 // www.digitalmars.com
9 // License for redistribution is by either the Artistic License
10 // in artistic.txt, or the GNU General Public License in gnu.txt.
11 // See the included readme.txt for details.
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <ctype.h>
18 #include "mem.h"
19 #include "root.h"
20 #include "mars.h"
21 #include "module.h"
22 #include "mtype.h"
24 Global global;
26 Global::Global()
28 mars_ext = "d";
29 sym_ext = "d";
30 hdr_ext = "di";
31 doc_ext = "html";
32 ddoc_ext = "ddoc";
33 dlt_ext = "dlt";
35 obj_ext = "o";
37 copyright = "Copyright (c) 1999-2007 by Digital Mars";
38 written = "written by Walter Bright";
39 version = "v1.020";
40 global.structalign = 8;
42 memset(&params, 0, sizeof(Param));
45 char *Loc::toChars()
47 OutBuffer buf;
49 if (filename)
51 buf.printf("%s", filename);
54 if (linnum)
55 buf.printf(":%u", linnum);
56 buf.writeByte(0);
57 return (char *)buf.extractData();
60 Loc::Loc(Module *mod, unsigned linnum)
62 this->linnum = linnum;
63 this->filename = mod ? mod->srcfile->toChars() : NULL;
66 /**************************************
67 * Print error message and exit.
70 void error(Loc loc, const char *format, ...)
72 va_list ap;
73 va_start(ap, format);
74 verror(loc, format, ap);
75 va_end( ap );
78 void verror(Loc loc, const char *format, va_list ap)
80 if (!global.gag)
82 char *p = loc.toChars();
84 if (*p)
85 fprintf(stderr, "%s: ", p);
86 mem.free(p);
88 fprintf(stderr, "Error: ");
89 vfprintf(stderr, format, ap);
90 fprintf(stderr, "\n");
91 fflush(stderr);
93 global.errors++;
96 /***************************************
97 * Call this after printing out fatal error messages to clean up and exit
98 * the compiler.
101 void fatal()
103 #if 0
104 *(char *)0 = 0;
105 #endif
106 exit(EXIT_FAILURE);