1 /* Copyright (C) 2005,2006,2008 G.P. Halkes
2    This program is free software: you can redistribute it and/or modify
3    it under the terms of the GNU General Public License version 3, as
4    published by the Free Software Foundation.
5 
6    This program is distributed in the hope that it will be useful,
7    but WITHOUT ANY WARRANTY; without even the implied warranty of
8    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9    GNU General Public License for more details.
10 
11    You should have received a copy of the GNU General Public License
12    along with this program.  If not, see <http://www.gnu.org/licenses/>.
13 */
14 
15 #ifndef GLOBALS_H
16 #define GLOBALS_H
17 
18 /* This should be automatically determined from the repository
19    [and is, by the mkdist.sh script] */
20 #define VERSION_STRING "0.5.5"
21 /* Version number in HEX. Must be defined to current version to allow self
22    compilation. Will be set to correct value by mkdist.sh script. Used to
23    create a define in the output such that users can #ifdef for features. */
24 #define VERSION_HEX "0x000505L"
25 
26 #include <stdio.h>
27 #include "nonRuleAnalysis.h"
28 #include "list.h"
29 
30 /* Variables */
31 extern bool errorSeen, softErrorSeen;
32 
33 /* Functions */
34 
35 /* Allocate a block of memory, and die if it cannot be allocated */
36 void *safeMalloc(size_t size, const char *where);
37 /* Is the same as safeMalloc, but also clears the memory block */
38 void *safeCalloc(size_t size, const char *where);
39 void *safeRealloc(void *ptr, size_t size, const char *where);
40 char *safeStrdup(const char *orig, const char *where);
41 char *safeStrndup(const char *orig, size_t length, const char *where);
42 void safeStrcatWithSpace(char **base, const char *append, const char *where);
43 FILE *safeFopen(const char *name, const char *mode);
44 
45 #define WARNING_UNMASKED (0)
46 #define WARNING_ARG_SEPARATOR (1<<0)
47 #define WARNING_OPTION_OVERRIDE (1<<1)
48 #define WARNING_UNBALANCED_C (1<<2)
49 #define WARNING_MULTIPLE_PARSER (1<<3)
50 #define WARNING_EOFILE (1<<4)
51 #define WARNING_UNUSED (1<<5)
52 #define WARNING_DATATYPE (1<<6)
53 #define WARNING_DISCARD_RETVAL (1<<6)
54 
55 /* If gcc is used, it can check whether the correct types are used for the
56    arguments after the format string. Furthermore we can tell it about certain
57    functions that do not return (i.e. call exit or abort) such that it won't
58    complain about not returning values elsewhere. To this end we define the
59    GCC_ATTRIBUTE macro. */
60 #ifdef __GNUC__
61 #define GCC_ATTRIBUTE(x) __attribute__((x))
62 #define UNUSED __attribute__((unused))
63 #else
64 #define GCC_ATTRIBUTE(x)
65 #define UNUSED
66 #endif
67 
68 /*@noreturn@*/ void fatal(const char *fmt, ...) GCC_ATTRIBUTE(format(printf, 1, 2)) GCC_ATTRIBUTE(noreturn);
69 /*@noreturn@*/ void fail(const char *fmt, ...) GCC_ATTRIBUTE(format(printf, 1, 2)) GCC_ATTRIBUTE(noreturn);
70 void error(Token *token, const char *fmt, ...) GCC_ATTRIBUTE(format(printf, 2, 3));
71 void softError(Token *token, const char *fmt, ...) GCC_ATTRIBUTE(format(printf, 2, 3));
72 void warning(int warningType, Token *token, const char *fmt, ...) GCC_ATTRIBUTE(format(printf, 3, 4));
73 void generalWarning(int warningType, const char *fmt, ...) GCC_ATTRIBUTE(format(printf, 2, 3));
74 void continueMessage(const char *fmt, ...) GCC_ATTRIBUTE(format(printf, 1, 2));
75 
76 
77 void printAt(Token *token);
78 void endMessage(void);
79 
80 #define PANIC() fail("Program failure in file %s on line %d.\nPlease see the section Bugs in the manual.\n", __FILE__, __LINE__)
81 #ifdef DEBUG
82 #define PANICMSG(msg) fail("%s:%d: %s", __FILE__, __LINE__, msg)
83 #else
84 #define PANICMSG(msg) PANIC()
85 #endif
86 #define ASSERT(cond) do { if (!(cond)) PANICMSG("Assertion (" #cond ") failed\n"); } while (0)
87 
88 char *processString(Token *file);
89 char *strtokReentrant(char *string, const char *separators, char **state);
90 List *split(char *string, const char *separators, bool keepEmpty);
91 
92 /* Don't want to bother making a header file just for this. */
93 void freeMemory(void);
94 
95 #define uDeclaration un.declaration
96 #define uDirective un.directive
97 #define uCode un.code
98 #define uToken un.token
99 #define uLiteral un.literal
100 #define uNumber un.number
101 #define uNonTerminal un.nonTerminal
102 #define uTerminal un.terminal
103 #define uTerm un.term
104 #define uAction un.action
105 #define uNext un.next
106 #define uPtr un.ptr
107 
108 #endif
109 
110