pp.h revision 7c2fbfb345896881c631598ee3852ce9ce33fb07
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1986-2008 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* preprocessor library public definitions
*/
#ifndef _PP_H
#define _PP_H
#ifdef ppsymbol
/*
* undo old nmake cpp name-space intrusion
* this disables __LINE__, __FILE__, __DATE__ and __TIME__
*/
#define __LINE__ 0
#define __FILE__ "libpp"
#define __DATE__ "MMM DD YYYY"
#define __TIME__ "HH:MM:SS"
#endif
#if PROTOMAIN
#define HASH_HEADER int hash_header
#define Hash_table_t char
#define Sfio_t char
#define CC_vt 0013
#else
#include <limits.h>
#include <hash.h>
#include <error.h>
#include <ccode.h>
#endif
#define PPWRITE(n) do{if(write(1,pp.outbuf,n)!=(n))pperror(ERROR_SYSTEM|3,"%s: write error",pp.outfile);pp.offset+=(n);pp.lastout=pp.outbuf[(n)-1];}while(0)
#define ppflushout() do{if(pp.outp>pp.outbuf){PPWRITE(pp.outp-pp.outbuf);pp.outp=pp.outbuf;}}while(0)
#define ppcheckout() do{if(pp.outp>pp.oute){PPWRITE(PPBUFSIZ);if(pp.outbuf==pp.outb){pp.outbuf+=PPBUFSIZ;pp.oute+=PPBUFSIZ;}else{pp.outbuf-=PPBUFSIZ;memcpy(pp.outbuf,pp.oute,pp.outp-pp.oute);pp.oute-=PPBUFSIZ;pp.outp-=2*PPBUFSIZ;}}}while(0)
#define ppsymref(t,n) (struct ppsymbol*)hashlook(t,n,pp.truncate?HASH_LOOKUP:HASH_LOOKUP|HASH_INTERNAL,NiL)
#define ppsymset(t,n) (struct ppsymbol*)hashlook(t,n,HASH_CREATE|HASH_SIZE(sizeof(struct ppsymbol)),NiL)
#if CHAR_MIN < 0
#else
#endif
#define C_ID (1<<0)
#define REF_NORMAL 0 /* normal macro reference */
#define PP_sync 0 /* normal line sync */
/*
* numeric modifiers
*
* NOTE: 0400 is claimed by error in yacc
* (N_PP+30) is the largest valid pp token
* free tokens start at T_TOKEN
*/
/*
* NOTE: preserve the token ranges and encodings for is*(x)
*/
#define N_LONG 0001
#define N_REAL 0004
#define N_OCTAL 0010
#define N_HEXADECIMAL 0020
#if !defined(T_DOUBLE)
/*
* numeric constants
*/
/*
* identifier and invalid token
*/
/*
* quoted constants
*/
/*
* multichar operators
*/
/*
* C++ tokens
*/
/*
* compiler tokens
*/
#endif
/*
* start of free tokens
*/
struct ppdirs /* directory list */
{
char* name; /* directory name */
#ifdef _PP_DIRS_PRIVATE_
#endif
};
struct ppkeyword /* pp keyword info */
{
char* name; /* keyword name */
int value; /* keyword token value */
};
struct ppmacro /* pp macro info */
{
int arity; /* # formal arguments */
char* value; /* definition value */
#ifdef _PP_MACRO_PRIVATE_
#endif
};
struct ppsymbol /* pp symbol info */
{
HASH_HEADER; /* hash stuff and symbol name */
unsigned long flags; /* SYM_* status */
void* value; /* value (for other passes) */
#ifdef _PP_SYMBOL_PRIVATE_
#endif
};
#define _PP_CONTEXT_PUBLIC_ \
int flags; /* PP_[a-z]* flags */ \
struct ppglobals /* globals accessed by pp.* */
{
const char* version; /* version stamp */
char* lineid; /* line sync directive id */
char* outfile; /* output file name */
char* pass; /* pass name */
char* token; /* pplex() token name */
/* exposed for the output macros */
char* outb; /* output buffer base */
char* outbuf; /* output buffer */
char* outp; /* outbuf pointer */
char* oute; /* outbuf end */
unsigned long offset; /* output offset */
#ifdef _PP_CONTEXT_PUBLIC_
_PP_CONTEXT_PUBLIC_ /* public context */
#endif
#ifdef _PP_CONTEXT_PRIVATE_
_PP_CONTEXT_PRIVATE_ /* library private context */
#endif
#ifdef _PP_GLOBALS_PRIVATE_
_PP_GLOBALS_PRIVATE_ /* library private additions */
#endif
};
/*
* library interface globals
*/
extern char ppctype[];
extern int ppargs(char**, int);
extern void ppcpp(void);
extern void ppcomment(char*, char*, char*, int);
extern void* ppcontext(void*, int);
extern void pperror(int, ...);
extern void ppincref(char*, char*, int, int);
extern void ppinput(char*, char*, int);
extern int pplex(void);
extern void ppline(int, char*);
extern void ppop(int, ...);
extern void pppragma(char*, char*, char*, char*, int);
extern int ppprintf(char*, ...);
extern int ppsync(void);
#endif