1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
|
/******************************************************************************
* FREXXWARE
* ----------------------------------------------------------------------------
*
* Project: Frexx C Preprocessor
* $Source: /cvsroot/silgraphite/silgraphite/src/GrCompiler/GdlPp/cppadd.h,v $
* $Revision: 1.2 $
* $Date: 2003/07/17 10:16:34 $
* $Author: mhosken $
* $State: Exp $
* $Locker: $
*
* ----------------------------------------------------------------------------
* $Log: cppadd.h,v $
* Revision 1.2 2003/07/17 10:16:34 mhosken
* Main linux port checkin
*
* Revision 1.1 2003/04/21 21:24:18 wardak
* Add files for the GDL pre-processor (gdlpp.exe).
*
* Revision 1.5 1994/01/24 09:38:12 start
* Added the 'rightconcat' in the global structure.
*
* Revision 1.4 1993/12/06 13:51:20 start
* A lot of new stuff (too much to mention)
*
* Revision 1.3 1993/11/29 14:01:13 start
* New features added
*
* Revision 1.2 1993/11/11 07:16:39 start
* New stuff
*
* Revision 1.1 1993/11/03 09:15:59 start
* Initial revision
*
*
*****************************************************************************/
/**********************************************************************
*
* cppadd.h
*
* Prototypes and structures added by Daniel Stenberg.
*
*******/
#include <stdarg.h>
#include "memory.h"
struct Global {
/*
* Commonly used global variables:
* line is the current input line number.
* wrongline is set in many places when the actual output
* line is out of sync with the numbering, e.g,
* when expanding a macro with an embedded newline.
*
* tokenbuf holds the last identifier scanned (which might
* be a candidate for macro expansion).
* errors is the running cpp error counter.
* infile is the head of a linked list of input files (extended by
* #include and macros being expanded). infile always points
* to the current file/macro. infile->parent to the includer,
* etc. infile->fd is NULL if this input stream is a macro.
*/
int line; /* Current line number */
int wrongline; /* Force #line to compiler */
char *tokenbuf; /* Buffer for current input token */
char *functionname; /* Buffer for current function */
int funcline; /* Line number of current function */
int tokenbsize; /* Allocated size of tokenbuf, */
/* not counting zero at end. */
int errors; /* cpp error counter */
FILEINFO *infile; /* Current input file */
#if DEBUG
int debug; /* TRUE if debugging now */
#endif
/*
* This counter is incremented when a macro expansion is initiated.
* If it exceeds a built-in value, the expansion stops -- this tests
* for a runaway condition:
* #define X Y
* #define Y X
* X
* This can be disabled by falsifying rec_recover. (Nothing does this
* currently: it is a hook for an eventual invocation flag.)
*/
int recursion; /* Infinite recursion counter */
int rec_recover; /* Unwind recursive macros */
/*
* instring is set TRUE when a string is scanned. It modifies the
* behavior of the "get next character" routine, causing all characters
* to be passed to the caller (except <DEF_MAGIC>). Note especially that
* comments and \<newline> are not removed from the source. (This
* prevents cpp output lines from being arbitrarily long).
*
* inmacro is set by #define -- it absorbs comments and converts
* form-feed and vertical-tab to space, but returns \<newline>
* to the caller. Strictly speaking, this is a bug as \<newline>
* shouldn't delimit tokens, but we'll worry about that some other
* time -- it is more important to prevent infinitly long output lines.
*
* instring and inmarcor are parameters to the get() routine which
* were made global for speed.
*/
int instring; /* TRUE if scanning string */
int inmacro; /* TRUE if #defining a macro */
/*
* work[] and workp are used to store one piece of text in a temporay
* buffer. To initialize storage, set workp = work. To store one
* character, call save(c); (This will fatally exit if there isn't
* room.) To terminate the string, call save(EOS). Note that
* the work buffer is used by several subroutines -- be sure your
* data won't be overwritten. The extra byte in the allocation is
* needed for string formal replacement.
*/
char work[NWORK + 1]; /* Work buffer */
char *workp; /* Work buffer pointer */
/*
* keepcomments is set TRUE by the -C option. If TRUE, comments
* are written directly to the output stream. This is needed if
* the output from cpp is to be passed to lint (which uses commands
* embedded in comments). cflag contains the permanent state of the
* -C flag. keepcomments is always falsified when processing #control
* commands and when compilation is supressed by a false #if
*
* If eflag is set, CPP returns "success" even if non-fatal errors
* were detected.
*
* If nflag is non-zero, no symbols are predefined except __LINE__.
* __FILE__, and __DATE__. If nflag > 1, absolutely no symbols
* are predefined.
*/
char keepcomments; /* Write out comments flag */
char cflag; /* -C option (keep comments) */
char eflag; /* -E option (never fail) */
char nflag; /* -N option (no predefines) */
char wflag; /* -W option (write #defines) */
/*
* ifstack[] holds information about nested #if's. It is always
* accessed via *ifptr. The information is as follows:
* WAS_COMPILING state of compiling flag at outer level.
* ELSE_SEEN set TRUE when #else seen to prevent 2nd #else.
* TRUE_SEEN set TRUE when #if or #elif succeeds
* ifstack[0] holds the compiling flag. It is TRUE if compilation
* is currently enabled. Note that this must be initialized TRUE.
*/
char ifstack[BLK_NEST]; /* #if information */
char *ifptr; /* -> current ifstack[] */
/*
* incdir[] stores the -i directories (and the system-specific
* #include <...> directories.
*/
char *incdir[NINCLUDE]; /* -i directories */
char **incend; /* -> free space in incdir[] */
/*
* include[] stores the -X and -x files.
*/
char *include[NINCLUDE];
char includeshow[NINCLUDE]; /* show it or not! */
char included;
/*
* This is the table used to predefine target machine and operating
* system designators. It may need hacking for specific circumstances.
* Note: it is not clear that this is part of the Ansi Standard.
* The -B option supresses preset definitions.
*/
char *preset[5]; /* names defined at cpp start */
/*
* The value of these predefined symbols must be recomputed whenever
* they are evaluated. The order must not be changed.
*/
char *magic[5]; /* Note: order is important */
/*
* This is the variable saying if Cpp should remove C++ style comments from
* the output. Default is... TRUE, yes, pronto, do it!!!
*/
char cplusplus;
char *sharpfilename;
/*
* parm[], parmp, and parlist[] are used to store #define() argument
* lists. nargs contains the actual number of parameters stored.
*/
char parm[NPARMWORK + 1]; /* define param work buffer */
char *parmp; /* Free space in parm */
char *parlist[LASTPARM]; /* -> start of each parameter */
int nargs; /* Parameters for this macro */
DEFBUF *macro; /* Catches start of infinite macro */
DEFBUF *symtab[SBSIZE]; /* Symbol table queue headers */
int evalue; /* Current value from evallex() */
char *(*input)(char *, int, void *); /* Input function */
char *first_file; /* Preprocessed file. */
void *userdata; /* Data sent to input function */
void (*output)(int, void *); /* output function */
void (*error)(void *, char *, va_list); /* error function */
char linelines;
char warnillegalcpp; /* warn for illegal preprocessor instructions? */
char outputLINE; /* output 'line' in #line instructions */
char showversion; /* display version */
char showincluded; /* display included files */
char showbalance; /* display paren balance */
char showspace; /* display all whitespaces as they are */
char comment; /* TRUE if a comment just has been written to output */
char *spacebuf; /* Buffer to store whitespaces in if -H */
long chpos; /* Number of whitespaces in buffer */
char nestcomments; /* Allow nested comments */
char warnnestcomments; /* Warn at nested comments */
char warnnoinclude; /* Warn at missing include file */
char outputfile; /* output the main file */
char out; /* should we output anything now? */
char rightconcat; /* should the right part of a concatenation be avaluated
before the concat (TRUE) or after (FALSE) */
char *initialfunc; /* file to include first in all functions */
char *excludedinit[20]; /* functions (names) excluded from the initfunc */
int excluded;
char outputfunctions; /* output all discovered functions to stderr! */
char webmode; /* WWW process mode */
};
typedef enum {
ERROR_STRING_MUST_BE_IF,
ERROR_STRING_MAY_NOT_FOLLOW_ELSE,
ERROR_ERROR,
ERROR_PREPROC_FAILURE,
ERROR_MISSING_ARGUMENT,
ERROR_INCLUDE_SYNTAX,
ERROR_DEFINE_SYNTAX,
ERROR_REDEFINE,
ERROR_ILLEGAL_UNDEF,
ERROR_RECURSIVE_MACRO,
ERROR_EOF_IN_ARGUMENT,
ERROR_MISPLACED_CONSTANT,
ERROR_IF_OVERFLOW,
ERROR_ILLEGAL_IF_LINE,
ERROR_OPERATOR,
ERROR_EXPR_OVERFLOW,
ERROR_UNBALANCED_PARENS,
ERROR_MISPLACED,
ERROR_STRING_IN_IF,
ERROR_DEFINED_SYNTAX,
ERROR_ILLEGAL_ASSIGN,
ERROR_ILLEGAL_BACKSLASH,
ERROR_SIZEOF_SYNTAX,
ERROR_SIZEOF_UNKNOWN,
ERROR_SIZEOF_ILLEGAL_TYPE,
ERROR_SIZEOF_NO_TYPE,
ERROR_UNTERMINATED_STRING,
ERROR_EOF_IN_COMMENT,
ERROR_IFDEF_DEPTH,
ERROR_ILLEGAL_CHARACTER,
ERROR_ILLEGAL_CHARACTER2,
ERROR_SIZEOF_BUG,
ERROR_IF_OPERAND,
ERROR_STRANG_CHARACTER,
ERROR_STRANG_CHARACTER2,
BORDER_ERROR_WARN, /* below this number: errors, above: warnings */
WARN_CONTROL_LINE_IN_MACRO,
WARN_ILLEGAL_COMMAND,
WARN_UNEXPECTED_TEXT_IGNORED,
WARN_TOO_FEW_VALUES_TO_SIZEOF,
WARN_TOO_MANY_VALUES_TO_SIZEOF,
WARN_NOT_DEFINED,
WARN_INTERNAL_ERROR,
WARN_MACRO_NEEDS_ARGUMENTS,
WARN_WRONG_NUMBER_ARGUMENTS,
WARN_DIVISION_BY_ZERO,
WARN_ILLEGAL_OCTAL,
WARN_MULTIbyte_NOT_PORTABLE,
WARN_CANNOT_OPEN_INCLUDE,
WARN_BRACKET_DEPTH,
WARN_PAREN_DEPTH,
WARN_BRACE_DEPTH,
WARN_NESTED_COMMENT,
BORDER_WARN_FATAL, /* below this number: warnings, above: fatals */
FATAL_TOO_MANY_NESTINGS,
FATAL_FILENAME_BUFFER_OVERFLOW,
FATAL_TOO_MANY_INCLUDE_DIRS,
FATAL_TOO_MANY_INCLUDE_FILES,
FATAL_TOO_MANY_ARGUMENTS_MACRO,
FATAL_MACRO_AREA_OVERFLOW,
FATAL_ILLEGAL_MACRO,
FATAL_TOO_MANY_ARGUMENTS_EXPANSION,
FATAL_OUT_OF_SPACE_IN_ARGUMENT,
FATAL_WORK_AREA_OVERFLOW,
FATAL_WORK_BUFFER_OVERFLOW,
FATAL_OUT_OF_MEMORY,
FATAL_TOO_MUCH_PUSHBACK
} ErrorCode;
/**********************************************************************
* RETURN CODES:
*********************************************************************/
typedef enum {
FPP_OK,
FPP_OUT_OF_MEMORY,
FPP_TOO_MANY_NESTED_STATEMENTS,
FPP_FILENAME_BUFFER_OVERFLOW,
FPP_NO_INCLUDE,
FPP_OPEN_ERROR,
FPP_TOO_MANY_ARGUMENTS,
FPP_WORK_AREA_OVERFLOW,
FPP_ILLEGAL_MACRO,
FPP_EOF_IN_MACRO,
FPP_OUT_OF_SPACE_IN_MACRO_EXPANSION,
FPP_ILLEGAL_CHARACTER,
FPP_CANT_USE_STRING_IN_IF,
FPP_BAD_IF_DEFINED_SYNTAX,
FPP_IF_ERROR,
FPP_SIZEOF_ERROR,
FPP_UNTERMINATED_STRING,
FPP_TOO_MANY_INCLUDE_DIRS,
FPP_TOO_MANY_INCLUDE_FILES,
FPP_INTERNAL_ERROR,
FPP_LAST_ERROR
} ReturnCode;
/* Nasty defines to make them appear as three different functions! */
#define cwarn cerror
#define cfatal cerror
/**********************************************************************
* PROTOTYPES:
*********************************************************************/
int PREFIX fppPreProcess(REG(a0) struct fppTag *);
void Freemem(void *);
void Error(struct Global *, char *, ...);
void Putchar(struct Global *, int);
void Putstring(struct Global *, char *);
void Putint(struct Global *, int);
char *savestring(struct Global *, char *);
ReturnCode addfile(struct Global *, FILE *, char *);
int catenate(struct Global *, ReturnCode *);
void cerror(struct Global *, ErrorCode, ...);
ReturnCode control(struct Global *, int *);
ReturnCode dodefine(struct Global *);
int dooptions(struct Global *, struct fppTag *);
void doundef(struct Global *);
void dumpparm(char *);
ReturnCode expand(struct Global *, DEFBUF *);
int get(struct Global *);
ReturnCode initdefines(struct Global *);
void outdefines(struct Global *);
ReturnCode save(struct Global *, int);
void scanid(struct Global *, int);
ReturnCode scannumber(struct Global *, int, ReturnCode(*)(struct Global *, int));
ReturnCode scanstring(struct Global *, int, ReturnCode(*)(struct Global *, int));
void unget(struct Global *);
ReturnCode ungetstring(struct Global *, char *);
ReturnCode eval(struct Global *, int *);
#ifdef DEBUG_EVAL
void dumpstack(OPTAB[NEXP], register OPTAB *, int [NEXP], register int *);
#endif
void skipnl(struct Global *);
int skipws(struct Global *);
ReturnCode macroid(struct Global *, int *);
ReturnCode getfile(struct Global *, int, char *, FILEINFO **);
DEFBUF *lookid(struct Global *, int );
DEFBUF *defendel(struct Global *, char *, int);
#if DEBUG
void dumpdef(char *);
void dumpadef(char *, register DEFBUF *);
#endif
ReturnCode openfile(struct Global *,char *);
int cget(struct Global *);
void deldefines(struct Global *);
char *Getmem(struct Global *, int);
ReturnCode openinclude(struct Global *, char *, int);
ReturnCode expstuff(struct Global *, char *, char *);
|