home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / p2c / part20 < prev    next >
Encoding:
Internet Message Format  |  1990-04-05  |  50.1 KB

  1. Subject:  v21i065:  Pascal to C translator, Part20/32
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 56297e7e 4d776505 61ec1f27 671b79ac
  5.  
  6. Submitted-by: Dave Gillespie <daveg@csvax.caltech.edu>
  7. Posting-number: Volume 21, Issue 65
  8. Archive-name: p2c/part20
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 20 (of 32)."
  17. # Contents:  src/trans.h.1
  18. # Wrapped by rsalz@litchi.bbn.com on Mon Mar 26 14:29:43 1990
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'src/trans.h.1' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'src/trans.h.1'\"
  22. else
  23. echo shar: Extracting \"'src/trans.h.1'\" \(48347 characters\)
  24. sed "s/^X//" >'src/trans.h.1' <<'END_OF_FILE'
  25. X/* "p2c", a Pascal to C translator, version 1.14.
  26. X   Copyright (C) 1989 David Gillespie.
  27. X   Author's address: daveg@csvax.caltech.edu; 256-80 Caltech/Pasadena CA 91125.
  28. X
  29. XThis program is free software; you can redistribute it and/or modify
  30. Xit under the terms of the GNU General Public License as published by
  31. Xthe Free Software Foundation (any version).
  32. X
  33. XThis program is distributed in the hope that it will be useful,
  34. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  35. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36. XGNU General Public License for more details.
  37. X
  38. XYou should have received a copy of the GNU General Public License
  39. Xalong with this program; see the file COPYING.  If not, write to
  40. Xthe Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  41. X
  42. X
  43. X
  44. X
  45. X#ifdef __STDC__
  46. X# define PP(x)  x             /* use true prototypes */
  47. X# define PV()   (void)
  48. X# define Anyptr void
  49. X# define __CAT__(a,b)a##b
  50. X#else
  51. X# define PP(x)  ()            /* use old-style declarations */
  52. X# define PV()   ()
  53. X# define Anyptr char
  54. X# define __ID__(a)a
  55. X# define __CAT__(a,b)__ID__(a)b
  56. X#endif
  57. X
  58. X#define Static                /* For debugging purposes */
  59. X
  60. X
  61. X
  62. X#include <stdio.h>
  63. X
  64. X
  65. X/* If the following heuristic fails, compile -DBSD=0 for non-BSD systems,
  66. X   or -DBSD=1 for BSD systems. */
  67. X
  68. X#ifdef M_XENIX
  69. X# define BSD 0
  70. X#endif
  71. X
  72. X#ifdef FILE       /* a #define in BSD, a typedef in SYSV (hp-ux, at least) */
  73. X# ifndef BSD
  74. X#  define BSD 1
  75. X# endif
  76. X#endif
  77. X
  78. X#ifdef BSD
  79. X# if !BSD
  80. X#  undef BSD
  81. X# endif
  82. X#endif
  83. X
  84. X
  85. X#ifdef __STDC__
  86. X# include <stddef.h>
  87. X# include <stdlib.h>
  88. X# include <limits.h>
  89. X#else
  90. X# ifndef BSD
  91. X#  include <malloc.h>
  92. X#  include <memory.h>
  93. X#  include <values.h>
  94. X# endif
  95. X# define EXIT_SUCCESS 0
  96. X# define EXIT_FAILURE 1
  97. X# define CHAR_BIT 8
  98. X# define LONG_MAX (((unsigned long)~0L) >> 1)
  99. X# define LONG_MIN (- LONG_MAX - 1)
  100. X#endif
  101. X
  102. X
  103. X
  104. X#ifdef BSD
  105. X# include <strings.h>
  106. X# define memcpy(a,b,n) bcopy(b,a,n)
  107. X# define memcmp(a,b,n) bcmp(a,b,n)
  108. Xchar *malloc(), *realloc();
  109. X#else
  110. X# include <string.h>
  111. X#endif
  112. X
  113. X#include <ctype.h>
  114. X
  115. X
  116. X#ifdef __GNUC__      /* Fast, in-line version of strcmp */
  117. X# define strcmp(a,b) ({ char *_aa = (a), *_bb = (b); int _diff;  \
  118. X            for (;;) {    \
  119. X                if (!*_aa && !*_bb) { _diff = 0; break; }   \
  120. X                            if (*_aa++ != *_bb++)    \
  121. X                { _diff = _aa[-1] - _bb[-1]; break; }   \
  122. X            } _diff; })
  123. X#endif
  124. X
  125. X
  126. X#if defined(HASDUMPS) && defined(define_globals)
  127. X# define DEFDUMPS
  128. X#endif
  129. X
  130. X
  131. X
  132. X/* Constants */
  133. X
  134. X#undef MININT      /* we want the Pascal definitions, not the local C definitions */
  135. X#undef MAXINT
  136. X
  137. X#define MININT     0x80000000
  138. X#define MAXINT     0x7fffffff
  139. X
  140. X
  141. X#ifndef EXIT_SUCCESS
  142. X# define EXIT_SUCCESS  0
  143. X# define EXIT_FAILURE  1
  144. X#endif
  145. X
  146. X
  147. X#ifndef P2C_HOME
  148. X# ifdef citPWS
  149. X#  define    P2C_HOME        "/lib/p2c"
  150. X# else
  151. X#  define    P2C_HOME        "/usr/local/p2c"     /* sounds reasonable... */
  152. X# endif
  153. X#endif
  154. X
  155. X#ifdef define_globals
  156. Xchar *p2c_home = P2C_HOME;
  157. X#else
  158. Xextern char *p2c_home;
  159. X#endif
  160. X
  161. X#define P2C_VERSION  "1.14"
  162. X
  163. X
  164. X
  165. X
  166. X/* Types */
  167. X
  168. X#ifdef __STDC__
  169. Xtypedef void *anyptr;
  170. X#else
  171. Xtypedef char *anyptr;
  172. X#endif
  173. X
  174. Xtypedef unsigned char uchar;
  175. X
  176. X
  177. X
  178. X/* Ought to rearrange token assignments at the next full re-compile */
  179. X
  180. Xtypedef enum E_token {
  181. X    TOK_NONE,
  182. X
  183. X    /* reserved words */
  184. X    TOK_AND, TOK_ARRAY, TOK_BEGIN, TOK_CASE, TOK_CONST,
  185. X    TOK_DIV, TOK_DO, TOK_DOWNTO, TOK_ELSE, TOK_END,
  186. X    TOK_FILE, TOK_FOR, TOK_FUNCTION, TOK_GOTO, TOK_IF,
  187. X    TOK_IN, TOK_LABEL, TOK_MOD, TOK_NIL, TOK_NOT,
  188. X    TOK_OF, TOK_OR, TOK_PACKED, TOK_PROCEDURE, TOK_PROGRAM,
  189. X    TOK_RECORD, TOK_REPEAT, TOK_SET, TOK_THEN, TOK_TO,
  190. X    TOK_TYPE, TOK_UNTIL, TOK_VAR, TOK_WHILE, TOK_WITH,
  191. X
  192. X    /* symbols */
  193. X    TOK_DOLLAR, TOK_STRLIT, TOK_LPAR, TOK_RPAR, TOK_STAR,
  194. X    TOK_PLUS, TOK_COMMA, TOK_MINUS, TOK_DOT, TOK_DOTS,
  195. X    TOK_SLASH, TOK_INTLIT, TOK_REALLIT, TOK_COLON, TOK_ASSIGN,
  196. X    TOK_SEMI, TOK_NE, TOK_LT, TOK_GT, TOK_LE, TOK_GE,
  197. X    TOK_EQ, TOK_LBR, TOK_RBR, TOK_HAT,
  198. X    TOK_INCLUDE, TOK_ENDIF,
  199. X    TOK_IDENT, TOK_MININT, TOK_EOF,
  200. X
  201. X    /* C symbols */
  202. X    TOK_ARROW, TOK_AMP, TOK_VBAR, TOK_BANG,
  203. X    TOK_TWIDDLE, TOK_PERC, TOK_QM,
  204. X    TOK_LTLT, TOK_GTGT, TOK_EQEQ, TOK_BANGEQ,
  205. X    TOK_PLPL, TOK_MIMI, TOK_ANDAND, TOK_OROR,
  206. X    TOK_LBRACE, TOK_RBRACE, TOK_CHARLIT,
  207. X
  208. X    /* HP Pascal tokens */
  209. X    TOK_ANYVAR, TOK_EXPORT, TOK_IMPLEMENT, TOK_IMPORT, TOK_MODULE,
  210. X    TOK_OTHERWISE, TOK_RECOVER, TOK_TRY,
  211. X
  212. X    /* Turbo Pascal tokens */
  213. X    TOK_SHL, TOK_SHR, TOK_XOR, TOK_INLINE, TOK_ABSOLUTE,
  214. X    TOK_INTERRUPT, TOK_ADDR, TOK_HEXLIT,
  215. X
  216. X    /* Oregon Software Pascal tokens */
  217. X    TOK_ORIGIN, TOK_INTFONLY,
  218. X
  219. X    /* VAX Pascal tokens */
  220. X    TOK_REM, TOK_VALUE, TOK_VARYING, TOK_OCTLIT, TOK_COLONCOLON,
  221. X    TOK_STARSTAR,
  222. X
  223. X    /* Modula-2 tokens */
  224. X    TOK_BY, TOK_DEFINITION, TOK_ELSIF, TOK_FROM, TOK_LOOP,
  225. X    TOK_POINTER, TOK_QUALIFIED, TOK_RETURN,
  226. X
  227. X    /* UCSD Pascal tokens */
  228. X    TOK_SEGMENT,
  229. X
  230. X    TOK_LAST
  231. X} Token;
  232. X
  233. X#ifdef define_globals
  234. Xchar *toknames[(int)TOK_LAST] = { "",
  235. X    "AND", "ARRAY", "BEGIN", "CASE", "CONST",
  236. X    "DIV", "DO", "DOWNTO", "ELSE", "END",
  237. X    "FILE", "FOR", "FUNCTION", "GOTO", "IF",
  238. X    "IN", "LABEL", "MOD", "NIL", "NOT",
  239. X    "OF", "OR", "PACKED", "PROCEDURE", "PROGRAM",
  240. X    "RECORD", "REPEAT", "SET", "THEN", "TO",
  241. X    "TYPE", "UNTIL", "VAR", "WHILE", "WITH",
  242. X
  243. X    "a '$'", "a string literal", "a '('", "a ')'", "a '*'",
  244. X    "a '+'", "a comma", "a '-'", "a '.'", "'..'",
  245. X    "a '/'", "an integer", "a real number", "a colon", "a ':='",
  246. X    "a semicolon", "a '<>'", "a '<'", "a '>'", "a '<='", "a '>='",
  247. X    "an '='", "a '['", "a ']'", "a '^'",
  248. X    "an \"include\" file", "$end$",
  249. X    "an identifier", "an integer", "end of file",
  250. X
  251. X    "an '->'", "an '&'", "a '|'", "a '!'", 
  252. X    "a '~'", "a '%'", "a '?'",
  253. X    "a '<<'", "a '>>'", "a '=='", "a '!='",
  254. X    "a '++'", "a '--'", "a '&&'", "a '||'",
  255. X    "a '{'", "a '}'", "a character literal",
  256. X
  257. X    "ANYVAR", "EXPORT", "IMPLEMENT", "IMPORT", "MODULE",
  258. X    "OTHERWISE", "RECOVER", "TRY",
  259. X
  260. X    "SHL", "SHR", "XOR", "INLINE", "ABSOLUTE",
  261. X    "INTERRUPT", "an '@'", "a hex integer",
  262. X
  263. X    "ORIGIN", "INTF-ONLY",
  264. X
  265. X    "REM", "VALUE", "VARYING", "an octal integer", "a '::'",
  266. X    "a '**'",
  267. X
  268. X    "BY", "DEFINITION", "ELSIF", "FROM", "LOOP",
  269. X    "POINTER", "QUALIFIED", "RETURN",
  270. X
  271. X    "SEGMENT"
  272. X} ;
  273. X#else
  274. Xextern char *toknames[];
  275. X#endif /*define_globals*/
  276. X
  277. Xtypedef struct S_strlist {
  278. X    struct S_strlist *next;
  279. X    long value;
  280. X    char s[1];
  281. X} Strlist;
  282. X
  283. X
  284. X
  285. Xtypedef struct S_value {
  286. X    struct S_type *type;
  287. X    long i;
  288. X    char *s;
  289. X} Value;
  290. X
  291. X
  292. X
  293. X/* "Symbol" notes:
  294. X *
  295. X * The symbol table is used for several things.  Mainly it records all
  296. X * identifiers in the Pascal program (normally converted to upper case).
  297. X * Also used for recording certain properties about C and Pascal names.
  298. X *
  299. X * The symbol table is a hash table of binary trees.
  300. X */
  301. X
  302. X#define AVOIDNAME  0x1         /* Avoid this name in C code */
  303. X#define WARNNAME   0x2           /* Warn if using this name in C code */
  304. X#define AVOIDGLOB  0x4           /* Avoid C name except private to module */
  305. X#define NOSIDEEFF  0x8           /* Function by this name has no side effects */
  306. X#define STRUCTF    0x10           /* Function by this name is a StructFunction */
  307. X#define STRLAPF    0x20           /* Function by this name is a StrlapFunction */
  308. X#define LEAVEALONE 0x40           /* Do not use custom handler for function */
  309. X#define DETERMF    0x80           /* Function by this name is Deterministic */
  310. X#define FMACREC    0x100       /* Used by FieldMacro stuff */
  311. X#define AVOIDFIELD 0x200       /* Avoid this name as a struct field name */
  312. X#define NEEDSTATIC 0x400       /* This name must be declared static */
  313. X#define KWPOSS     0x800       /* This word may be a keyword */
  314. X#define FUNCBREAK  0x7000      /* Line breaking flags (see sys.p2crc) */
  315. X# define FALLBREAK  0x1000     /*  Break at all commas if at any */
  316. X# define FSPCARG1   0x2000     /*  First argument is special */
  317. X# define FSPCARG2   0x3000     /*  First two arguments are special */
  318. X# define FSPCARG3   0x4000     /*  First three arguments are special */
  319. X#define WARNLIBR   0x8000      /* Warn for all uses of this library function */
  320. X#define FWDPARAM   0x10000     /* Was a param name for forward-declared func */
  321. X#define SSYNONYM   0x20000     /* Symbol is a synonym for another */
  322. X
  323. Xtypedef struct S_symbol {
  324. X    struct S_symbol *left;     /* Left pointer in binary tree */
  325. X    struct S_symbol *right;    /* Right pointer in binary tree */
  326. X    struct S_meaning *mbase;   /* First normal meaning for this symbol */
  327. X    struct S_meaning *fbase;   /* First record-field meaning for this symbol */
  328. X    Strlist *symbolnames;      /* List of NameOf's for this name */
  329. X    long flags;               /* (above) */
  330. X    Token kwtok;           /* Token, if symbol is a keyword */
  331. X    char name[1];              /* Pascal name (actually variable-sized) */
  332. X} Symbol;
  333. X
  334. X
  335. X
  336. X/* "Meaning" notes:
  337. X *
  338. X * This represents one meaning of a symbol (see below).  Meanings are
  339. X * organized in a tree of contexts (i.e., scopes), and also in linked
  340. X * lists of meanings per symbol.  Fields described in the following are
  341. X * undefined for kinds where they are not listed.  Other fields are
  342. X * defined in all kinds of meanings.
  343. X *
  344. X * MK_MODULE:  Program, module, or unit.
  345. X *    mp->anyvarflag = 1 if main program, 0 if module.
  346. X *    mp->cbase => First meaning in module's context.
  347. X *
  348. X * MK_CONST:  Pascal CONST.
  349. X *    mp->type => Type of constant, same as mp->constdefn->type & mp->val.type.
  350. X *    mp->anyvarflag = 1 if FoldConstants was true when defined.
  351. X *    mp->constdefn => Expression for the value of the constant.
  352. X *    mp->val = Value of the const, if can be evaluated, else val.type is NULL.
  353. X *    mp->xnext => Next constant in enumeration, else NULL.
  354. X *    mp->isreturn = 1 if constant was declared as a macro (with #define).
  355. X *
  356. X * MK_TYPE:  Pascal type name.
  357. X *    mp->type => Type which name represents.
  358. X *
  359. X * MK_VAR:  Normal variable.
  360. X *    mp->type => Type of variable.
  361. X *    mp->constdefn => Initializer for variable, else NULL.
  362. X *    mp->varstructflag = 1 if variable is in parent function's varstruct.
  363. X *    mp->isforward = 1 if should be declared static.
  364. X *    mp->isfunction = 1 if should be declared extern.
  365. X *    mp->namedfile = 1 if this file variable has a shadow file-name variable.
  366. X *    mp->bufferedfile = 1 if this file variable has a shadow buffer variable.
  367. X *    mp->val.s => name format string if temporary var, else NULL.
  368. X *
  369. X * MK_VARREF:  Variable always referenced through a pointer.
  370. X *    mp->type => Type "pointer to T" where T is type of variable.
  371. X *    mp->constdefn => Initializer for the pointer, else NULL.
  372. X *    (Others same as for MK_VAR.)
  373. X *
  374. X * MK_VARMAC:  Variable which has a VarMacro.
  375. X *    mp->type => Type of variable.
  376. X *    mp->constdefn => Expression for VarMacro definition.
  377. X *    (Others same as for MK_VAR.)
  378. X *
  379. X * MK_SPVAR:  Special variable.
  380. X *    mp->handler => C function to parse and translate the special variable.
  381. X *
  382. X * MK_FIELD:  Record/struct field name.
  383. X *    mp->ctx, cbase = unused (unlike other meanings).
  384. X *    mp->cnext => Next field in record or variant.
  385. X *    mp->type => Type of field (base type if a bit-field).
  386. X *    mp->rectype => Type of containing record.
  387. X *    mp->constdefn => Expression for definition if FieldMacro, else NULL.
  388. X *    mp->val.i = Number of bits if bit-field, or 0 if normal field.
  389. X *    mp->val.type => True type of bit-field, else same as mp->type.
  390. X *    mp->isforward = 1 if tag field for following variant, else 0.
  391. X *    mp->namedfile = 1 if this file field has a shadow file-name field.
  392. X *    mp->bufferedfile = 1 if this file field has a shadow buffer field.
  393. X *
  394. X * MK_VARIANT:  Header for variant record case.
  395. X *    mp->ctx => First field in variant (unlike other meanings).
  396. X *    mp->cbase = unused (unlike other meanings).
  397. X *    mp->cnext => Next variant in record (or next sub-variant in variant).
  398. X *    mp->rectype => Type of containing record.
  399. X *    mp->val = Tag value of variant.
  400. X *
  401. X * MK_LABEL:  Statement label.
  402. X *    mp->val.i => Case number if used by non-local gotos, else -1.
  403. X *    mp->xnext => MK_VAR representing associated jmp_buf variable.
  404. X *    (All optional fields are unused.)
  405. X *
  406. X * MK_FUNCTION:  Procedure or function.
  407. X *    mp->type => TK_FUNCTION type.
  408. X *    mp->cbase => First meaning in procedure's context (when isfunction is 1,
  409. X *           this will always be the return-value meaning.)
  410. X *    mp->val.i => Body of the function (cast to Stmt *).
  411. X *    mp->constdefn => Expression for definition if FuncMacro, else NULL.
  412. X *    mp->handler => C function to adjust parse tree if predefined, else NULL.
  413. X *    mp->isfunction = 1 if function, 0 if procedure.
  414. X *    mp->isforward = 1 if function has been declared forward.
  415. X *    mp->varstructflag = 1 if function has a varstruct.
  416. X *    mp->needvarstruct = 1 if no varstruct yet but may need one.
  417. X *    mp->namedfile = 1 if function should be declared "inline".
  418. X *
  419. X * MK_SPECIAL:  Special, irregular built-in function.
  420. X *    mp->handler => C function to parse and translate the special function.
  421. X *    mp->constdefn => Expression for definition if FuncMacro, else NULL.
  422. X *    mp->isfunction = 1 if function, 0 if procedure.
  423. X *
  424. X * MK_PARAM:  Procedure or function parameter, or function return value.
  425. X *    mp->type => Type of parameter.
  426. X *    mp->isreturn = 1 if a function return value (not on parameter list).
  427. X *    mp->xnext => Next parameter of function.
  428. X *    mp->fakeparam = 1 if a fake parameter (e.g., conformant array size).
  429. X *    mp->othername => Name of true param if this one is a local copy.
  430. X *    mp->rectype => Type of true param if this one is a local copy.
  431. X *             If a normal copy param, will be "pointer to" mp->type.
  432. X *             If copied for varstruct reasons, will be same as mp->type.
  433. X *    mp->varstructflag = 1 if variable is in parent function's varstruct.
  434. X *
  435. X * MK_VARPARAM:  VAR parameter, or StructFunction return value.
  436. X *    mp->type => Type "pointer to T" where T is type of parameter.
  437. X *    mp->anyvarflag = 1 if no type checking is to be applied to parameter.
  438. X *    mp->isreturn = 1 if a StructFunction return value (will be first param).
  439. X *    (Others same as for MK_PARAM.)
  440. X *
  441. X * MK_VARPARAM with mp->type == tp_anyptr:  Turbo "typeless var" parameter.
  442. X *    mp->type = tp_anyptr.
  443. X *    mp->anyvarflag = 1.
  444. X *    (Others same as for MK_PARAM.)
  445. X *
  446. X * MK_VARPARAM with mp->type == tp_strptr:  HP Pascal "var s:string" parameter.
  447. X *    mp->type = tp_strptr.
  448. X *    mp->anyvarflag = 1 if a separate "strmax" parameter is passed.
  449. X *    (Others same as for MK_PARAM.)
  450. X *
  451. X * MK_SYNONYM:  Meaning which should be treated as identical to another.
  452. X *    mp->xnext => Actual meaning to be used.
  453. X *
  454. X */
  455. X
  456. Xenum meaningkind {
  457. X    MK_NONE, MK_SPECIAL,
  458. X    MK_MODULE, MK_FUNCTION, MK_CONST, MK_VAR, MK_TYPE,
  459. X    MK_FIELD, MK_LABEL, MK_VARIANT,
  460. X    MK_PARAM, MK_VARPARAM, MK_VARREF, MK_VARMAC,
  461. X    MK_SPVAR, MK_SYNONYM,
  462. X    MK_LAST
  463. X} ;
  464. X
  465. X#ifdef DEFDUMPS
  466. Xchar *meaningkindnames[(int)MK_LAST] = {
  467. X    "MK_NONE", "MK_SPECIAL",
  468. X    "MK_MODULE", "MK_FUNCTION", "MK_CONST", "MK_VAR", "MK_TYPE",
  469. X    "MK_FIELD", "MK_LABEL", "MK_VARIANT",
  470. X    "MK_PARAM", "MK_VARPARAM", "MK_VARREF", "MK_VARMAC",
  471. X    "MK_SPVAR", "MK_SYNONYM"
  472. X} ;
  473. X#endif /*DEFDUMPS*/
  474. X
  475. Xtypedef struct S_meaning {
  476. X    struct S_meaning *snext;   /* Next meaning for this symbol */
  477. X    struct S_meaning *cnext;   /* Next meaning in this meaning's context */
  478. X    struct S_meaning *cbase;   /* First meaning in this context */
  479. X    struct S_meaning *ctx;     /* Context of this meaning */
  480. X    struct S_meaning *xnext;   /* (above) */
  481. X    struct S_symbol *sym;      /* Symbol of which this is a meaning */
  482. X    struct S_type *type;       /* (above) */
  483. X    struct S_type *rectype;    /* (above) */
  484. X    struct S_expr *constdefn;  /* (above) */
  485. X    enum meaningkind kind;     /* Kind of meaning */
  486. X    unsigned needvarstruct:1,  /* (above) */
  487. X             varstructflag:1,  /* (above) */
  488. X             wasdeclared:1,    /* Declaration has been written for meaning */
  489. X             istemporary:1,    /* Is a temporary variable */
  490. X             isforward:1,      /* (above) */
  491. X             isfunction:1,     /* (above) */
  492. X             anyvarflag:1,     /* (above) */
  493. X             isactive:1,       /* Meaning is currently in scope */
  494. X             exported:1,       /* Meaning is visible outside this module */
  495. X             warnifused:1,     /* WarnNames was 1 when meaning was declared */
  496. X             dumped:1,           /* Has been dumped (for debugging) */
  497. X             isreturn:1,       /* (above) */
  498. X             fakeparam:1,      /* (above) */
  499. X             namedfile:1,      /* (above) */
  500. X             bufferedfile:1,   /* (above) */
  501. X             volatilequal:1,   /* Object has C "volatile" qualifier */
  502. X             constqual:1,      /* Object has C "const" qualifier */
  503. X             dummy17:1, dummy18:1, dummy19:1, 
  504. X         dummy20:1, dummy21:1, dummy22:1, dummy23:1, dummy24:1, dummy25:1, 
  505. X         dummy26:1, dummy27:1, dummy28:1, dummy29:1, dummy30:1, dummy31:1;
  506. X    Value val;               /* (above) */
  507. X    int refcount;           /* Number of references to meaning in program */
  508. X    char *name;               /* Print name (i.e., C name) of the meaning */
  509. X    char *othername;           /* (above) */
  510. X    struct S_expr *(*handler)();   /* Custom translator for procedure */
  511. X    Strlist *comments;           /* Comments associated with meaning */
  512. X} Meaning;
  513. X
  514. X
  515. X
  516. X/* "Type" notes:
  517. X *
  518. X * This struct represents a data type.  Types are stored in a strange
  519. X * cross between Pascal and C semantics.  (This usually works out okay.)
  520. X *
  521. X * TK_INTEGER:  Base integer type.
  522. X *    The following types are TK_INTEGER:
  523. X *        tp_integer, tp_unsigned, tp_int, tp_uint, tp_sint.
  524. X *    All other integer types are represented by subranges.
  525. X *    tp->smin => Minimum value for integer.
  526. X *    tp->smax => Maximum value for integer.
  527. X *
  528. X * TK_CHAR:  Base character type.
  529. X *    The following types are TK_CHAR:  tp_char, tp_schar, tp_uchar.
  530. X *    All other character types are represented by subranges.
  531. X *    tp->smin => Minimum value for character.
  532. X *    tp->smax => Maximum value for character.
  533. X *
  534. X * TK_BOOLEAN:  Boolean type.
  535. X *    The only TK_BOOLEAN type is tp_boolean.
  536. X *    tp->smin => "False" expression.
  537. X *    tp->smax => "True" expression.
  538. X *
  539. X * TK_REAL:  Real types.
  540. X *    The only TK_REAL types are tp_real, tp_longreal, and/or the SINGLE type.
  541. X *
  542. X * TK_VOID:  C "void" type.
  543. X *    The only TK_VOID type is tp_void.
  544. X *
  545. X * TK_SUBR:  Subrange of ordinal type.
  546. X *    tp->basetype => a TK_INTEGER, TK_CHAR, TK_BOOLEAN, or TK_ENUM type.
  547. X *    tp->smin => Minimum ordinal value for subrange.
  548. X *    tp->smax => Maximum ordinal value for subrange.
  549. X *
  550. X * TK_ENUM:  Enumerated type.
  551. X *    tp->fbase => First enumeration constant.
  552. X *    tp->smin => Minimum value (zero).
  553. X *    tp->smax => Maximum value (number of choices minus 1).
  554. X *
  555. X * TK_POINTER:  Pointer type.
  556. X *    tp->basetype => Base type of pointer.
  557. X *    Only one pointer type is ever generated for a given other type;
  558. X *    each tp->pointertype points back to that type if it has been generated.
  559. X *
  560. X * TK_STRING:  Pascal string or VARYING OF CHAR type.
  561. X *    tp->basetype => tp_char.
  562. X *    tp->indextype => TK_SUBR from 0 to maximum string length.
  563. X *    tp->structdefd = 1 if type is for a conformant VARYING OF CHAR parameter.
  564. X *
  565. X * TK_RECORD:  Pascal record/C struct type.
  566. X *    tp->fbase => First field in record.
  567. X *    tp->structdefd = 1 if struct type has been declared in output.
  568. X *
  569. X * TK_ARRAY with smax == NULL:  Normal array type.
  570. X *    tp->basetype => Element type of array.
  571. X *    tp->indextype => Index type (usually a TK_SUBR).
  572. X *    tp->smin => Integer constant if SkipIndices was used, else NULL.
  573. X *    tp->smax = NULL.
  574. X *    tp->structdefd = 1 if type is for a conformant array parameter.
  575. X *
  576. X * TK_ARRAY with smax != NULL:  Large packed array type.
  577. X *    tp->basetype => Element type of C array (tp_ubyte/tp_sbyte/tp_sshort).
  578. X *    tp->indextype => Index type (usually a TK_SUBR).
  579. X *    tp->smin => Integer constant is SkipIndices was used, else NULL.
  580. X *    tp->smax => EK_TYPENAME for element type of Pascal array.
  581. X *    tp->escale = log-base-two of number of bits per packed element, else 0.
  582. X *    tp->issigned = 1 if packed array elements are signed, 0 if unsigned.
  583. X *    tp->structdefd = 1 if type is for a conformant array parameter.
  584. X *
  585. X * TK_SMALLARRAY:  Packed array fitting within a single integer.
  586. X *    (Same as for packed TK_ARRAY.)
  587. X *
  588. X * TK_SET:  Normal set type.
  589. X *    tp->basetype => tp_integer.
  590. X *    tp->indextype => Element type of the set.
  591. X *
  592. X * TK_SMALLSET:  Set fitting within a single integer.
  593. X *    (Same as for TK_SET.)
  594. X *
  595. X * TK_FILE:  File type (corresponds to C "FILE" type).
  596. X *    tp->basetype => Type of file elements, or tp_abyte if UCSD untyped file.
  597. X *    A Pascal "file" variable is represented as a TK_POINTER to a TK_FILE.
  598. X *
  599. X * TK_FUNCTION:  Procedure or procedure-pointer type.
  600. X *    tp->basetype => Return type of function, or tp_void if procedure.
  601. X *    tp->issigned = 1 if type has a generic static link.
  602. X *    tp->fbase => First argument (or StructFunction return buffer pointer).
  603. X *
  604. X * TK_PROCPTR:  Procedure pointer with static link.
  605. X *    tp->basetype => TK_FUNCTION type.
  606. X *    tp->fbase => Internal Meaning struct associated with basetype.
  607. X *    tp->escale = Value of StaticLinks when type was declared.
  608. X *
  609. X * TK_CPROCPTR:  Procedure pointer without static link.
  610. X *    tp->basetype => TK_FUNCTION type.
  611. X *    tp->fbase => Internal Meaning struct associated with basetype.
  612. X *    tp->escale = Value of StaticLinks = 0.
  613. X *
  614. X * TK_SPECIAL:  Special strange data type.
  615. X *    Only TK_SPECIAL type at present is tp_jmp_buf.
  616. X *
  617. X */
  618. X
  619. Xenum typekind {
  620. X    TK_NONE,
  621. X    TK_INTEGER, TK_CHAR, TK_BOOLEAN, TK_REAL, TK_VOID,
  622. X    TK_SUBR, TK_ENUM, TK_POINTER, TK_STRING,
  623. X    TK_RECORD, TK_ARRAY, TK_SET, TK_FILE, TK_FUNCTION,
  624. X    TK_PROCPTR, TK_SMALLSET, TK_SMALLARRAY, TK_CPROCPTR,
  625. X    TK_SPECIAL,
  626. X    TK_LAST
  627. X} ;
  628. X
  629. X#ifdef DEFDUMPS
  630. Xchar *typekindnames[(int)TK_LAST] = {
  631. X    "TK_NONE",
  632. X    "TK_INTEGER", "TK_CHAR", "TK_BOOLEAN", "TK_REAL", "TK_VOID",
  633. X    "TK_SUBR", "TK_ENUM", "TK_POINTER", "TK_STRING",
  634. X    "TK_RECORD", "TK_ARRAY", "TK_SET", "TK_FILE", "TK_FUNCTION",
  635. X    "TK_PROCPTR", "TK_SMALLSET", "TK_SMALLARRAY", "TK_CPROCPTR",
  636. X    "TK_SPECIAL"
  637. X} ;
  638. X#endif /*DEFDUMPS*/
  639. X
  640. Xtypedef struct S_type {
  641. X    enum typekind kind;        /* Kind of type */
  642. X    struct S_type *basetype;   /* (above) */
  643. X    struct S_type *indextype;  /* (above) */
  644. X    struct S_type *pointertype; /* Pointer to this type */
  645. X    struct S_meaning *meaning; /* Name of this type, if any */
  646. X    struct S_meaning *fbase;   /* (above) */
  647. X    struct S_expr *smin;       /* (above) */
  648. X    struct S_expr *smax;       /* (above) */
  649. X    unsigned issigned:1,       /* (above) */
  650. X             dumped:1,         /* Has been dumped (for debugging) */
  651. X             structdefd:1;     /* (above) */
  652. X    short escale;              /* (above) */
  653. X} Type;
  654. X
  655. X
  656. X/* "Expr" notes:
  657. X *
  658. X * Expression trees generally reflect C notation and semantics.  For example,
  659. X * EK_ASSIGN is not generated for string arguments; these would get an
  660. X * EK_BICALL to strcpy instead.
  661. X *
  662. X * The data type of each expression node is stored in its "val.type" field.
  663. X * The rest of the "val" field is used only when shown below.
  664. X * The "nargs" field always contains the number of arguments; the "args"
  665. X * array is allocated to that size and will contain non-NULL Expr pointers.
  666. X *
  667. X * EK_EQ, EK_NE, EK_LT, EK_GT, EK_LE, EK_GE:  Relational operators.
  668. X *    ep->nargs = 2.
  669. X *
  670. X * EK_PLUS:  Addition.
  671. X *    ep->nargs >= 2.
  672. X *
  673. X * EK_NEG:  Negation.
  674. X *    ep->nargs = 1.
  675. X *
  676. X * EK_TIMES:  Multiplication.
  677. X *    ep->nargs >= 2.
  678. X *
  679. X * EK_DIVIDE:  Real division.
  680. X *    ep->nargs = 2.
  681. X *
  682. X * EK_DIV:  Integer division.
  683. X *    ep->nargs = 2.
  684. X *
  685. X * EK_MOD:  Integer modulo (C "%" operator).
  686. X *    ep->nargs = 2.
  687. X *
  688. X * EK_OR, EK_AND:  Logical operators (C "&&" and "||").
  689. X *    ep->nargs = 2.
  690. X *
  691. X * EK_NOT:  Logical NOT (C "!" operator).
  692. X *    ep->nargs = 1.
  693. X *
  694. X * EK_BAND, EK_BOR, EK_BXOR:  Bitwise operators (C "&", "|", "^").
  695. X *    ep->nargs = 2.
  696. X *
  697. X * EK_BNOT:  Bitwise NOT (C "~" operator).
  698. X *    ep->nargs = 1.
  699. X *
  700. X * EK_LSH, EK_RSH:  Shift operators.
  701. X *    ep->nargs = 2.
  702. X *
  703. X * EK_HAT:  Pointer dereference.
  704. X *    ep->nargs = 1.
  705. X *
  706. X * EK_INDEX:  Array indexing.
  707. X *    ep->nargs = 2.
  708. X *
  709. X * EK_CAST:  "Soft" type cast, change data type retaining value.
  710. X *    ep->type => New data type.
  711. X *    ep->nargs = 1.
  712. X *
  713. X * EK_ACTCAST:  "Active" type cast, performs a computation as result of cast.
  714. X *    ep->type => New data type.
  715. X *    ep->nargs = 1.
  716. X *
  717. X * EK_LITCAST:  Literal type cast.
  718. X *    ep->nargs = 2.
  719. X *    ep->args[0] => EK_TYPENAME expression for name of new data type.
  720. X *    ep->args[1] => Argument of cast.
  721. X *
  722. X * EK_DOT:  Struct field extraction.
  723. X *    ep->nargs = 1.  (Only one of the following will be nonzero:)
  724. X *    ep->val.i => MK_FIELD being extracted (cast to Meaning *), else 0.
  725. X *    ep->val.s => Literal name of field being extracted, else NULL.
  726. X *
  727. X * EK_COND:  C conditional expression.
  728. X *    ep->nargs = 3.
  729. X *    ep->args[0] => Condition expression.
  730. X *    ep->args[1] => "Then" expression.
  731. X *    ep->args[2] => "Else" expression.
  732. X *
  733. X * EK_ADDR:  Address-of operator.
  734. X *    ep->nargs = 1.
  735. X *
  736. X * EK_SIZEOF:  Size-of operator.
  737. X *    ep->nargs = 1.
  738. X *    ep->args[0] => Argument expression, may be EK_TYPENAME.
  739. X *
  740. X * EK_CONST:  Literal constant.
  741. X *    ep->nargs = 0 or 1.
  742. X *    ep->val = Value of constant.
  743. X *    ep->args[0] => EK_NAME of printf format string for constant, if any.
  744. X *
  745. X * EK_LONGCONST:  Literal constant, type "long int".
  746. X *    (Same as for EK_CONST.)
  747. X *
  748. X * EK_VAR:  Variable name.
  749. X *    ep->nargs = 0.
  750. X *    ep->val.i => Variable being referenced (cast to Meaning *).
  751. X *
  752. X * EK_ASSIGN:  Assignment operator.
  753. X *    ep->nargs = 2.
  754. X *    ep->args[0] => Destination l-value expression.
  755. X *    ep->args[1] => Source expression.
  756. X *
  757. X * EK_POSTINC, EK_POSTDEC:  Post-increment/post-decrement operators.
  758. X *    ep->nargs = 1.
  759. X *
  760. X * EK_MACARG:  Placeholder for argument in expression for FuncMacro, etc.
  761. X *    ep->nargs = 0.
  762. X *    ep->val.i = Code selecting which argument.
  763. X *
  764. X * EK_CHECKNIL:  Null-pointer check.
  765. X *    ep->nargs = 1.
  766. X *
  767. X * EK_BICALL:  Call to literal function name.
  768. X *    ep->val.s => Name of function.
  769. X *
  770. X * EK_STRUCTCONST:  Structured constant.
  771. X *    ep->nargs = Number of elements in constant.
  772. X *    (Note:  constdefn points to an EK_CONST whose val.i points to this.)
  773. X *
  774. X * EK_STRUCTOF:  Repeated element in structured constant.
  775. X *    ep->nargs = 1.
  776. X *    ep->val.i = Number of repetitions.
  777. X *
  778. X * EK_COMMA:  C comma operator.
  779. X *    ep->nargs >= 2.
  780. X *
  781. X * EK_NAME:  Literal variable name.
  782. X *    ep->nargs = 0.
  783. X *    ep->val.s => Name of variable.
  784. X *
  785. X * EK_CTX:  Name of a context, with static links.
  786. X *    ep->nargs = 0.
  787. X *    ep->val.i => MK_FUNCTION or MK_MODULE to name (cast to Meaning *).
  788. X *
  789. X * EK_SPCALL:  Special function call.
  790. X *    ep->nargs = 1 + number of arguments to function.
  791. X *    ep->args[0] => Expression which is the function to call.
  792. X *
  793. X * EK_TYPENAME:  Type name.
  794. X *    ep->nargs = 0.
  795. X *    ep->val.type => Type whose name should be printed.
  796. X *
  797. X * EK_FUNCTION:  Normal function call.
  798. X *    ep->val.i => MK_FUNCTION being called (cast to Meaning *).
  799. X *
  800. X */
  801. X
  802. Xenum exprkind {
  803. X    EK_EQ, EK_NE, EK_LT, EK_GT, EK_LE, EK_GE,
  804. X    EK_PLUS, EK_NEG, EK_TIMES, EK_DIVIDE,
  805. X    EK_DIV, EK_MOD,
  806. X    EK_OR, EK_AND, EK_NOT,
  807. X    EK_BAND, EK_BOR, EK_BXOR, EK_BNOT, EK_LSH, EK_RSH,
  808. X    EK_HAT, EK_INDEX, EK_CAST, EK_DOT, EK_COND,
  809. X    EK_ADDR, EK_SIZEOF, EK_ACTCAST,
  810. X    EK_CONST, EK_VAR, EK_FUNCTION,
  811. X    EK_ASSIGN, EK_POSTINC, EK_POSTDEC, EK_CHECKNIL,
  812. X    EK_MACARG, EK_BICALL, EK_STRUCTCONST, EK_STRUCTOF,
  813. X    EK_COMMA, EK_LONGCONST, EK_NAME, EK_CTX, EK_SPCALL,
  814. X    EK_LITCAST, EK_TYPENAME,
  815. X    EK_LAST
  816. X} ;
  817. X
  818. X#ifdef DEFDUMPS
  819. Xchar *exprkindnames[(int)EK_LAST] = {
  820. X    "EK_EQ", "EK_NE", "EK_LT", "EK_GT", "EK_LE", "EK_GE",
  821. X    "EK_PLUS", "EK_NEG", "EK_TIMES", "EK_DIVIDE",
  822. X    "EK_DIV", "EK_MOD",
  823. X    "EK_OR", "EK_AND", "EK_NOT",
  824. X    "EK_BAND", "EK_BOR", "EK_BXOR", "EK_BNOT", "EK_LSH", "EK_RSH",
  825. X    "EK_HAT", "EK_INDEX", "EK_CAST", "EK_DOT", "EK_COND",
  826. X    "EK_ADDR", "EK_SIZEOF", "EK_ACTCAST",
  827. X    "EK_CONST", "EK_VAR", "EK_FUNCTION",
  828. X    "EK_ASSIGN", "EK_POSTINC", "EK_POSTDEC", "EK_CHECKNIL",
  829. X    "EK_MACARG", "EK_BICALL", "EK_STRUCTCONST", "EK_STRUCTOF",
  830. X    "EK_COMMA", "EK_LONGCONST", "EK_NAME", "EK_CTX", "EK_SPCALL",
  831. X    "EK_LITCAST", "EK_TYPENAME"
  832. X} ;
  833. X#endif /*DEFDUMPS*/
  834. X
  835. Xtypedef struct S_expr {
  836. X    enum exprkind kind;
  837. X    short nargs;
  838. X    Value val;
  839. X    struct S_expr *args[1];    /* (Actually, variable-sized) */
  840. X} Expr;
  841. X
  842. X
  843. X
  844. X/* "Stmt" notes.
  845. X *
  846. X * Statements form linked lists along the "next" pointers.
  847. X * All other pointers are NULL and unused unless shown below.
  848. X *
  849. X * SK_ASSIGN:  Assignment or function call (C expression statement).
  850. X *    sp->exp1 => Expression to be evaluated.
  851. X *
  852. X * SK_RETURN:  C "return" statement.
  853. X *    sp->exp1 => Value to return, else NULL.
  854. X *
  855. X * SK_CASE:  C "switch" statement.
  856. X *    sp->exp1 => Switch selector expression.
  857. X *    sp->stm1 => List of SK_CASELABEL statements, followed by list of
  858. X *          statements that make up the "default:" clause.
  859. X *
  860. X * SK_CASELABEL:  C "case" label.
  861. X *    sp->exp1 => Case value.
  862. X *    sp->stm1 => List of SK_CASELABELs labelling the same clause, followed
  863. X *                by list of statements in that clause.
  864. X *
  865. X * SK_CASECHECK:  Case-value-range-error, occurs in "default:" clause.
  866. X *
  867. X * SK_IF:  C "if" statement.
  868. X *    sp->exp1 => Conditional expression.
  869. X *    sp->exp2 => Constant expression, "1" if this "if" should be else-if'd
  870. X *          on to parent "if".  NULL => follow ElseIf parameter.
  871. X *    sp->stm1 => "Then" clause.
  872. X *    sp->stm2 => "Else" clause.
  873. X *
  874. X * SK_FOR:  C "for" statement.
  875. X *    sp->exp1 => Initialization expression (may be NULL).
  876. X *    sp->exp2 => Conditional expression (may be NULL).
  877. X *    sp->exp3 => Iteration expression (may be NULL).
  878. X *    sp->stm1 => Loop body.
  879. X *
  880. X * SK_REPEAT:  C "do-while" statement.
  881. X *    sp->exp1 => Conditional expression (True = continue loop).
  882. X *    sp->stm1 => Loop body.
  883. X *
  884. X * SK_WHILE:  C "while" statement.
  885. X *    sp->exp1 => Conditional expression.
  886. X *    sp->stm1 => Loop body.
  887. X *
  888. X * SK_BREAK:  C "break" statement.
  889. X *
  890. X * SK_CONTINUE:  C "continue" statement.
  891. X *
  892. X * SK_TRY:  HP Pascal TRY-RECOVER statement.
  893. X *    sp->exp1->val.i = Global serial number of the TRY statement.
  894. X *    sp->exp2 = Non-NULL if must generate a label for RECOVER block.
  895. X *    sp->stm1 => TRY block.
  896. X *    sp->stm2 => RECOVER block.
  897. X *
  898. X * SK_GOTO:  C "goto" statement.
  899. X *    sp->exp1 => EK_NAME for the label number or name.
  900. X *
  901. X * SK_LABEL:  C statement label.
  902. X *    sp->exp1 => EK_NAME for the label number of name.
  903. X *
  904. X * SK_HEADER:  Function/module header.
  905. X *    sp->exp1 => EK_VAR pointing to MK_FUNCTION or MK_MODULE.
  906. X *    (This always comes first in a context's statement list.)
  907. X *
  908. X * SK_BODY:  Body of function/module.
  909. X *    sp->stm1 => SK_HEADER that begins the body.
  910. X *    (This exists only during fixblock.)
  911. X *
  912. X */
  913. X
  914. Xenum stmtkind {
  915. X    SK_ASSIGN, SK_RETURN,
  916. X    SK_CASE, SK_CASELABEL, SK_IF,
  917. X    SK_FOR, SK_REPEAT, SK_WHILE, SK_BREAK, SK_CONTINUE,
  918. X    SK_TRY, SK_GOTO, SK_LABEL,
  919. X    SK_HEADER, SK_CASECHECK, SK_BODY,
  920. X    SK_LAST
  921. X} ;
  922. X
  923. X#ifdef DEFDUMPS
  924. Xchar *stmtkindnames[(int)SK_LAST] = {
  925. X    "SK_ASSIGN", "SK_RETURN",
  926. X    "SK_CASE", "SK_CASELABEL", "SK_IF",
  927. X    "SK_FOR", "SK_REPEAT", "SK_WHILE", "SK_BREAK", "SK_CONTINUE",
  928. X    "SK_TRY", "SK_GOTO", "SK_LABEL",
  929. X    "SK_HEADER", "SK_CASECHECK", "SK_BODY"
  930. X} ;
  931. X#endif /*DEFDUMPS*/
  932. X
  933. Xtypedef struct S_stmt {
  934. X    enum stmtkind kind;
  935. X    struct S_stmt *next, *stm1, *stm2;
  936. X    struct S_expr *exp1, *exp2, *exp3;
  937. X    long serial;
  938. X} Stmt;
  939. X
  940. X
  941. X
  942. X/* Flags for out_declarator(): */
  943. X
  944. X#define ODECL_CHARSTAR      0x1
  945. X#define ODECL_FREEARRAY     0x2
  946. X#define ODECL_FUNCTION      0x4
  947. X#define ODECL_HEADER        0x8
  948. X#define ODECL_FORWARD       0x10
  949. X
  950. X
  951. X/* Flags for fixexpr(): */
  952. X
  953. X#define ENV_EXPR    0       /* return value needed */
  954. X#define ENV_STMT    1       /* return value ignored */
  955. X#define ENV_BOOL    2       /* boolean return value needed */
  956. X
  957. X
  958. X/* Flags for defmacro(): */
  959. X#define MAC_VAR     0       /* VarMacro */
  960. X#define MAC_CONST   1       /* ConstMacro */
  961. X#define MAC_FIELD   2       /* FieldMacro */
  962. X#define MAC_FUNC    3       /* FuncMacro */
  963. X
  964. X#define FMACRECname  "<rec>"
  965. X
  966. X
  967. X/* Kinds of comment lines: */
  968. X#define CMT_SHIFT   24
  969. X#define CMT_MASK    ((1L<<CMT_SHIFT)-1)
  970. X#define CMT_KMASK   ((1<<(32-CMT_SHIFT))-1)
  971. X#define CMT_DONE    0       /* comment that has already been printed */
  972. X#define CMT_PRE     1       /* comment line preceding subject */
  973. X#define CMT_POST    2       /* comment line following subject */
  974. X#define CMT_TRAIL   4       /* comment at end of line of code */
  975. X#define CMT_ONBEGIN 6       /* comment on "begin" of procedure */
  976. X#define CMT_ONEND   7       /* comment on "end" of procedure */
  977. X#define CMT_ONELSE  8       /* comment on "else" keyword */
  978. X#define CMT_NOT     256     /* negation of above, for searches */
  979. X
  980. X#ifdef define_globals
  981. Xchar *CMT_NAMES[] = { "DONE", "PRE", "POST", "3", "TRAIL", "5",
  982. X                      "BEGIN", "END", "ELSE" };
  983. X#else
  984. Xextern char *CMT_NAMES[];
  985. X#endif
  986. X
  987. X#define getcommentkind(cmt)  (((cmt)->value >> CMT_SHIFT) & CMT_KMASK)
  988. X
  989. X
  990. X/* Kinds of operator line-breaking: */
  991. X#define BRK_LEFT     0x1
  992. X#define BRK_RIGHT    0x2
  993. X#define BRK_LPREF    0x4
  994. X#define BRK_RPREF    0x8
  995. X#define BRK_ALLNONE  0x10
  996. X#define BRK_HANG     0x20
  997. X
  998. X
  999. X
  1000. X
  1001. X/* Translation parameters: */
  1002. X
  1003. X#ifdef define_parameters
  1004. X# define extern
  1005. X#endif /* define_parameters */
  1006. X
  1007. Xextern enum {
  1008. X    UNIX_ANY, UNIX_BSD, UNIX_SYSV
  1009. X} which_unix;
  1010. X
  1011. Xextern enum {
  1012. X    LANG_HP, LANG_UCSD, LANG_TURBO, LANG_OREGON, LANG_VAX,
  1013. X    LANG_MODULA, LANG_MPW, LANG_BERK
  1014. X} which_lang;
  1015. X
  1016. Xextern short debug, tokentrace, quietmode, cmtdebug, copysource;
  1017. Xextern int showprogress, maxerrors;
  1018. Xextern short hpux_lang, integer16, doublereals, pascalenumsize;
  1019. Xextern short needsignedbyte, unsignedchar, importall;
  1020. Xextern short nestedcomments, pascalsignif, pascalcasesens;
  1021. Xextern short dollar_idents, ignorenonalpha, modula2;
  1022. Xextern short ansiC, cplus, signedchars, signedfield, signedshift;
  1023. Xextern short hassignedchar, voidstar, symcase, ucconsts, csignif;
  1024. Xextern short copystructs, usevextern, implementationmodules;
  1025. Xextern short useAnyptrMacros, usePPMacros;
  1026. Xextern short sprintf_value;
  1027. Xextern char codefnfmt[40], modulefnfmt[40], logfnfmt[40];
  1028. Xextern char headerfnfmt[40], headerfnfmt2[40], includefnfmt[40];
  1029. Xextern char constformat[40], moduleformat[40], functionformat[40];
  1030. Xextern char varformat[40], fieldformat[40], typeformat[40];
  1031. Xextern char enumformat[40], symbolformat[40];
  1032. Xextern char p2c_h_name[40], exportsymbol[40], export_symbol[40];
  1033. Xextern char externalias[40];
  1034. Xextern char memcpyname[40], sprintfname[40];
  1035. Xextern char roundname[40], divname[40], modname[40], remname[40];
  1036. Xextern char strposname[40], strcicmpname[40];
  1037. Xextern char strsubname[40], strdeletename[40], strinsertname[40];
  1038. Xextern char strmovename[40], strpadname[40];
  1039. Xextern char strltrimname[40], strrtrimname[40], strrptname[40];
  1040. Xextern char absname[40], oddname[40], evenname[40], swapname[40];
  1041. Xextern char mallocname[40], freename[40], freervaluename[40];
  1042. Xextern char randrealname[40], randintname[40], randomizename[40];
  1043. Xextern char skipspacename[40], readlnname[40], freopenname[40];
  1044. Xextern char eofname[40], eolnname[40], fileposname[40], maxposname[40];
  1045. Xextern char setunionname[40], setintname[40], setdiffname[40];
  1046. Xextern char setinname[40], setaddname[40], setaddrangename[40];
  1047. Xextern char setremname[40];
  1048. Xextern char setequalname[40], subsetname[40], setxorname[40];
  1049. Xextern char setcopyname[40], setexpandname[40], setpackname[40];
  1050. Xextern char getbitsname[40], clrbitsname[40], putbitsname[40];
  1051. Xextern char declbufname[40], declbufncname[40];
  1052. Xextern char resetbufname[40], setupbufname[40];
  1053. Xextern char getfbufname[40], chargetfbufname[40], arraygetfbufname[40];
  1054. Xextern char putfbufname[40], charputfbufname[40], arrayputfbufname[40];
  1055. Xextern char getname[40], chargetname[40], arraygetname[40];
  1056. Xextern char putname[40], charputname[40], arrayputname[40];
  1057. Xextern char storebitsname[40], signextname[40];
  1058. Xextern char filenotfoundname[40], filenotopenname[40];
  1059. Xextern char filewriteerrorname[40], badinputformatname[40], endoffilename[40];
  1060. Xextern short strcpyleft;
  1061. Xextern char language[40], target[40];
  1062. Xextern int sizeof_char, sizeof_short, sizeof_integer, sizeof_pointer, 
  1063. X           sizeof_double, sizeof_float, sizeof_enum, sizeof_int, sizeof_long;
  1064. Xextern short size_t_long;
  1065. Xextern int setbits, defaultsetsize, seek_base, integerwidth, realwidth;
  1066. Xextern short quoteincludes, expandincludes, collectnest;
  1067. Xextern int phystabsize, intabsize, linewidth, maxlinewidth;
  1068. Xextern int majorspace, minorspace, functionspace, minfuncspace;
  1069. Xextern int casespacing, caselimit;
  1070. Xextern int returnlimit, breaklimit, continuelimit;
  1071. Xextern short nullstmtline, shortcircuit, shortopt, usecommas, elseif;
  1072. Xextern short usereturns, usebreaks, infloopstyle, reusefieldnames;
  1073. Xextern short bracesalways, braceline, bracecombine, braceelse, braceelseline;
  1074. Xextern short newlinefunctions;
  1075. Xextern short eatcomments, spitcomments, spitorphancomments;
  1076. Xextern short commentafter, blankafter;
  1077. Xextern int tabsize, blockindent, bodyindent, argindent;
  1078. Xextern int switchindent, caseindent, labelindent;
  1079. Xextern int openbraceindent, closebraceindent;
  1080. Xextern int funcopenindent, funccloseindent;
  1081. Xextern int structindent, structinitindent, extrainitindent;
  1082. Xextern int constindent, commentindent, bracecommentindent, commentoverindent;
  1083. Xextern int declcommentindent;
  1084. Xextern int minspacing, minspacingthresh;
  1085. Xextern int extraindent, bumpindent;
  1086. Xextern double overwidepenalty, overwideextrapenalty;
  1087. Xextern double commabreakpenalty, commabreakextrapenalty;
  1088. Xextern double assignbreakpenalty, assignbreakextrapenalty;
  1089. Xextern double specialargbreakpenalty;
  1090. Xextern double opbreakpenalty, opbreakextrapenalty, exhyphenpenalty;
  1091. Xextern double morebreakpenalty, morebreakextrapenalty;
  1092. Xextern double parenbreakpenalty, parenbreakextrapenalty;
  1093. Xextern double qmarkbreakpenalty, qmarkbreakextrapenalty;
  1094. Xextern double wrongsidepenalty, earlybreakpenalty, extraindentpenalty;
  1095. Xextern double bumpindentpenalty, nobumpindentpenalty;
  1096. Xextern double indentamountpenalty, sameindentpenalty;
  1097. Xextern double showbadlimit;
  1098. Xextern long maxalts;
  1099. Xextern short breakbeforearith, breakbeforerel, breakbeforelog;
  1100. Xextern short breakbeforedot, breakbeforeassign;
  1101. Xextern short for_allornone;
  1102. Xextern short extraparens, breakparens, returnparens;
  1103. Xextern short variablearrays, stararrays;
  1104. Xextern short spaceexprs, implicitzero, starindex;
  1105. Xextern int casetabs;
  1106. Xextern short starfunctions, mixfields, alloczeronil, postincrement;
  1107. Xextern short mixvars, mixtypes, mixinits, nullcharconst, castnull, addindex;
  1108. Xextern short highcharints, highcharbits, hasstaticlinks;
  1109. Xextern short mainlocals, storefilenames, addrstdfiles, readwriteopen;
  1110. Xextern short charfiletext, messagestderr, literalfilesflag;
  1111. Xextern short printfonly, mixwritelns, usegets, newlinespace, binarymode;
  1112. Xextern char openmode[40], filenamefilter[40];
  1113. Xextern short atan2flag, div_po2, mod_po2, assumebits, assumesigns;
  1114. Xextern short fullstrwrite, fullstrread, whilefgets, buildreads, buildwrites;
  1115. Xextern short foldconsts, foldstrconsts, useconsts, useundef;
  1116. Xextern short elimdeadcode, offsetforloops, forevalorder;
  1117. Xextern short smallsetconst, bigsetconst, lelerange, unsignedtrick;
  1118. Xextern short useisalpha, useisspace, usestrncmp;
  1119. Xextern short casecheck, arraycheck, rangecheck, nilcheck, malloccheck;
  1120. Xextern short checkfileopen, checkfileisopen, checkfilewrite;
  1121. Xextern short checkreadformat, checkfileeof, checkstdineof, checkfileseek;
  1122. Xextern short squeezesubr, useenum, enumbyte, packing, packsigned, keepnulls;
  1123. Xextern short compenums, formatstrings, alwayscopyvalues;
  1124. Xextern short use_static, var_static, void_args, prototypes, fullprototyping;
  1125. Xextern short procptrprototypes, promote_enums;
  1126. Xextern short castargs, castlongargs, promoteargs;
  1127. Xextern short varstrings, varfiles, copystructfuncs;
  1128. Xextern long skipindices;
  1129. Xextern short stringleaders;
  1130. Xextern int stringceiling, stringdefault, stringtrunclimit, longstringsize;
  1131. Xextern short warnnames, warnmacros;
  1132. Xextern Strlist *importfrom, *importdirs, *includedirs, *includefrom;
  1133. Xextern Strlist *librfiles, *bufferedfiles, *unbufferedfiles;
  1134. Xextern Strlist *externwords, *cexternwords;
  1135. Xextern Strlist *varmacros, *constmacros, *fieldmacros;
  1136. Xextern Strlist *funcmacros, *funcmacroargs, *nameoflist;
  1137. Xextern Strlist *specialmallocs, *specialfrees, *specialsizeofs;
  1138. Xextern Strlist *initialcalls, *eatnotes, *literalfiles;
  1139. X
  1140. Xextern char fixedcomment[40], permanentcomment[40], interfacecomment[40];
  1141. Xextern char embedcomment[40],  skipcomment[40], noskipcomment[40];
  1142. Xextern char signedcomment[40], unsignedcomment[40];
  1143. X
  1144. Xextern char name_RETV[40], name_STRMAX[40], name_LINK[40];
  1145. Xextern char name_COPYPAR[40], name_TEMP[40], name_DUMMY[40];
  1146. Xextern char name_LOC[40], name_VARS[40], name_STRUCT[40];
  1147. Xextern char name_FAKESTRUCT[40], name_AHIGH[40], name_ALOW[40];
  1148. Xextern char name_UNION[40], name_VARIANT[40], name_LABEL[40], name_LABVAR[40];
  1149. Xextern char name_WITH[40], name_FOR[40], name_ENUM[40];
  1150. Xextern char name_PTR[40], name_STRING[40], name_SET[40];
  1151. Xextern char name_PROCEDURE[40], name_MAIN[40], name_UNITINIT[40];
  1152. Xextern char name_HSYMBOL[40], name_GSYMBOL[40];
  1153. Xextern char name_SETBITS[40], name_UCHAR[40], name_SCHAR[40];
  1154. Xextern char name_BOOLEAN[40], name_TRUE[40], name_FALSE[40], name_NULL[40];
  1155. Xextern char name_ESCAPECODE[40], name_IORESULT[40];
  1156. Xextern char name_ARGC[40], name_ARGV[40];
  1157. Xextern char name_ESCAPE[40], name_ESCIO[40], name_CHKIO[40], name_SETIO[40];
  1158. Xextern char name_OUTMEM[40], name_CASECHECK[40], name_NILCHECK[40];
  1159. Xextern char name_FNSIZE[40], name_FNVAR[40];
  1160. Xextern char alternatename1[40], alternatename2[40], alternatename[40];
  1161. X
  1162. X
  1163. X#ifndef define_parameters
  1164. Xextern
  1165. X#endif
  1166. Xstruct rcstruct {
  1167. X    char kind;
  1168. X    char chgmode;
  1169. X    char *name;
  1170. X    anyptr ptr;
  1171. X    long def;
  1172. X} rctable[]
  1173. X#ifdef define_parameters
  1174. X   = {
  1175. X    'S', 'R', "DEBUG",           (anyptr) &debug,             0,
  1176. X    'I', 'R', "SHOWPROGRESS",    (anyptr) &showprogress,      0,
  1177. X    'S', 'V', "TOKENTRACE",      (anyptr) &tokentrace,        0,
  1178. X    'S', 'V', "QUIET",           (anyptr) &quietmode,         0,
  1179. X    'S', 'V', "COPYSOURCE",      (anyptr) ©source,        0,
  1180. X    'I', 'R', "MAXERRORS",     (anyptr) &maxerrors,          0,
  1181. X    'X', ' ', "INCLUDE",         (anyptr) NULL,               2,
  1182. X
  1183. X/* INPUT LANGUAGE */
  1184. X    'U', 'T', "LANGUAGE",        (anyptr)  language,         40,
  1185. X    'S', 'V', "MODULA2",         (anyptr) &modula2,          -1,
  1186. X    'S', 'T', "INTEGER16",       (anyptr) &integer16,        -1,
  1187. X    'S', 'T', "DOUBLEREALS",     (anyptr) &doublereals,      -1,
  1188. X    'S', 'V', "UNSIGNEDCHAR",    (anyptr) &unsignedchar,     -1,
  1189. X    'S', 'V', "NEEDSIGNEDBYTE",  (anyptr) &needsignedbyte,    0,
  1190. X    'S', 'V', "PASCALENUMSIZE",  (anyptr) &pascalenumsize,   -1,
  1191. X    'S', 'V', "NESTEDCOMMENTS",  (anyptr) &nestedcomments,   -1,
  1192. X    'S', 'V', "IMPORTALL",       (anyptr) &importall,        -1,
  1193. X    'S', 'V', "IMPLMODULES",     (anyptr) &implementationmodules, -1,
  1194. X    'A', 'V', "EXTERNWORDS",     (anyptr) &externwords,          0,
  1195. X    'A', 'V', "CEXTERNWORDS",     (anyptr) &cexternwords,      0,
  1196. X    'S', 'V', "PASCALSIGNIF",    (anyptr) &pascalsignif,     -1,
  1197. X    'S', 'V', "PASCALCASESENS",  (anyptr) &pascalcasesens,   -1,
  1198. X    'S', 'V', "DOLLARIDENTS",    (anyptr) &dollar_idents,    -1,
  1199. X    'S', 'V', "IGNORENONALPHA",  (anyptr) &ignorenonalpha,   -1,
  1200. X    'I', 'V', "SEEKBASE",        (anyptr) &seek_base,        -1,
  1201. X    'I', 'R', "INPUTTABSIZE",    (anyptr) &intabsize,         8,
  1202. X
  1203. X/* TARGET LANGUAGE */
  1204. X    'S', 'T', "ANSIC",           (anyptr) &ansiC,            -1,
  1205. X    'S', 'T', "C++",             (anyptr) &cplus,            -1,
  1206. X    'S', 'T', "VOID*",           (anyptr) &voidstar,         -1,
  1207. X    'S', 'T', "HASSIGNEDCHAR",   (anyptr) &hassignedchar,    -1,
  1208. X    'S', 'V', "CASTNULL",        (anyptr) &castnull,         -1,
  1209. X    'S', 'V', "COPYSTRUCTS",     (anyptr) ©structs,      -1,
  1210. X    'S', 'V', "VARIABLEARRAYS",  (anyptr) &variablearrays,   -1,
  1211. X    'S', 'V', "REUSEFIELDNAMES", (anyptr) &reusefieldnames,   1,
  1212. X    'S', 'V', "USEVEXTERN",      (anyptr) &usevextern,        1,
  1213. X    'S', 'V', "CSIGNIF",         (anyptr) &csignif,          -1,
  1214. X    'S', 'V', "USEANYPTRMACROS", (anyptr) &useAnyptrMacros,  -1,
  1215. X    'S', 'V', "USEPPMACROS",     (anyptr) &usePPMacros,      -1,
  1216. X
  1217. X/* TARGET MACHINE */
  1218. X    'U', 'T', "TARGET",          (anyptr)  target,           40,
  1219. X    'S', 'T', "SIGNEDCHAR",      (anyptr) &signedchars,      -1,
  1220. X    'S', 'T', "SIGNEDFIELD",     (anyptr) &signedfield,      -1,
  1221. X    'S', 'T', "SIGNEDSHIFT",     (anyptr) &signedshift,      -1,
  1222. X    'I', 'T', "CHARSIZE",        (anyptr) &sizeof_char,       0,
  1223. X    'I', 'T', "SHORTSIZE",       (anyptr) &sizeof_short,      0,
  1224. X    'I', 'T', "INTSIZE",         (anyptr) &sizeof_int,        0,
  1225. X    'I', 'T', "LONGSIZE",        (anyptr) &sizeof_long,       0,
  1226. X    'I', 'T', "PTRSIZE",         (anyptr) &sizeof_pointer,    0,
  1227. X    'I', 'T', "DOUBLESIZE",      (anyptr) &sizeof_double,     0,
  1228. X    'I', 'T', "FLOATSIZE",       (anyptr) &sizeof_float,      0,
  1229. X    'I', 'T', "ENUMSIZE",        (anyptr) &sizeof_enum,       0,
  1230. X    'S', 'T', "SIZE_T_LONG",     (anyptr) &size_t_long,      -1,
  1231. X
  1232. X/* BRACES */
  1233. X    'S', 'V', "NULLSTMTLINE",    (anyptr) &nullstmtline,      0,
  1234. X    'S', 'V', "BRACESALWAYS",    (anyptr) &bracesalways,     -1,
  1235. X    'S', 'V', "BRACELINE",       (anyptr) &braceline,        -1,
  1236. X    'S', 'V', "BRACECOMBINE",    (anyptr) &bracecombine,      0,
  1237. X    'S', 'V', "BRACEELSE",       (anyptr) &braceelse,         0,
  1238. X    'S', 'V', "BRACEELSELINE",   (anyptr) &braceelseline,     0,
  1239. X    'S', 'V', "ELSEIF",          (anyptr) &elseif,           -1,
  1240. X    'S', 'V', "NEWLINEFUNCS",    (anyptr) &newlinefunctions,  0,
  1241. X
  1242. X/* INDENTATION */
  1243. X    'I', 'R', "PHYSTABSIZE",     (anyptr) &phystabsize,       8,
  1244. X    'D', 'R', "INDENT",          (anyptr) &tabsize,           2,
  1245. X    'D', 'R', "BLOCKINDENT",     (anyptr) &blockindent,       0,
  1246. X    'D', 'R', "BODYINDENT",      (anyptr) &bodyindent,        0,
  1247. X    'D', 'R', "FUNCARGINDENT",   (anyptr) &argindent,      1000,
  1248. X    'D', 'R', "OPENBRACEINDENT", (anyptr) &openbraceindent,   0,
  1249. X    'D', 'R', "CLOSEBRACEINDENT",(anyptr) &closebraceindent,  0,
  1250. X    'D', 'R', "FUNCOPENINDENT",  (anyptr) &funcopenindent,    0,
  1251. X    'D', 'R', "FUNCCLOSEINDENT", (anyptr) &funccloseindent,   0,
  1252. X    'D', 'R', "SWITCHINDENT",    (anyptr) &switchindent,      0,
  1253. X    'D', 'R', "CASEINDENT",      (anyptr) &caseindent,       -2,
  1254. X    'D', 'R', "LABELINDENT",     (anyptr) &labelindent,    1000,
  1255. X    'D', 'R', "STRUCTINDENT",    (anyptr) &structindent,      0,
  1256. X    'D', 'R', "STRUCTINITINDENT",(anyptr) &structinitindent,  0,
  1257. X    'D', 'R', "EXTRAINITINDENT", (anyptr) &extrainitindent,   2,
  1258. X    'I', 'R', "EXTRAINDENT",     (anyptr) &extraindent,       2,
  1259. X    'I', 'R', "BUMPINDENT",      (anyptr) &bumpindent,        1,
  1260. X    'D', 'R', "CONSTINDENT",     (anyptr) &constindent,    1024,
  1261. X    'D', 'R', "COMMENTINDENT",   (anyptr) &commentindent,     3,
  1262. X    'D', 'R', "BRACECOMMENTINDENT",(anyptr)&bracecommentindent, 2,
  1263. X    'D', 'R', "DECLCOMMENTINDENT",(anyptr)&declcommentindent, -999,
  1264. X    'D', 'R', "COMMENTOVERINDENT",(anyptr)&commentoverindent, 4,  /*1000*/
  1265. X    'I', 'R', "MINSPACING",      (anyptr) &minspacing,        2,
  1266. X    'I', 'R', "MINSPACINGTHRESH",(anyptr) &minspacingthresh, -1,
  1267. X
  1268. X/* LINE BREAKING */
  1269. X    'I', 'R', "LINEWIDTH",       (anyptr) &linewidth,        78,
  1270. X    'I', 'R', "MAXLINEWIDTH",    (anyptr) &maxlinewidth,     90,
  1271. X    'R', 'V', "OVERWIDEPENALTY",       (anyptr) &overwidepenalty,         2500,
  1272. X    'R', 'V', "OVERWIDEEXTRAPENALTY",  (anyptr) &overwideextrapenalty,     100,
  1273. X    'R', 'V', "COMMABREAKPENALTY",     (anyptr) &commabreakpenalty,       1000,
  1274. X    'R', 'V', "COMMABREAKEXTRAPENALTY",(anyptr) &commabreakextrapenalty,   500,
  1275. X    'R', 'V', "ASSIGNBREAKPENALTY",    (anyptr) &assignbreakpenalty,      5000,
  1276. X    'R', 'V', "ASSIGNBREAKEXTRAPENALTY",(anyptr)&assignbreakextrapenalty, 3000,
  1277. X    'R', 'V', "SPECIALARGBREAKPENALTY",(anyptr) &specialargbreakpenalty,   500,
  1278. X    'R', 'V', "OPBREAKPENALTY",        (anyptr) &opbreakpenalty,          2500,
  1279. X    'R', 'V', "OPBREAKEXTRAPENALTY",   (anyptr) &opbreakextrapenalty,     2000,
  1280. X    'R', 'V', "EXHYPHENPENALTY",       (anyptr) &exhyphenpenalty,         1000,
  1281. X    'R', 'V', "MOREBREAKPENALTY",      (anyptr) &morebreakpenalty,        -500,
  1282. X    'R', 'V', "MOREBREAKEXTRAPENALTY", (anyptr) &morebreakextrapenalty,   -300,
  1283. END_OF_FILE
  1284. if test 48347 -ne `wc -c <'src/trans.h.1'`; then
  1285.     echo shar: \"'src/trans.h.1'\" unpacked with wrong size!
  1286. fi
  1287. # end of 'src/trans.h.1'
  1288. fi
  1289. echo shar: End of archive 20 \(of 32\).
  1290. cp /dev/null ark20isdone
  1291. MISSING=""
  1292. for I in 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 ; do
  1293.     if test ! -f ark${I}isdone ; then
  1294.     MISSING="${MISSING} ${I}"
  1295.     fi
  1296. done
  1297. if test "${MISSING}" = "" ; then
  1298.     echo You have unpacked all 32 archives.
  1299.     echo "Now see PACKNOTES and the README"
  1300.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1301. else
  1302.     echo You still need to unpack the following archives:
  1303.     echo "        " ${MISSING}
  1304. fi
  1305. ##  End of shell archive.
  1306. exit 0
  1307.