home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / pascal2c / dir.c < prev    next >
C/C++ Source or Header  |  1992-08-03  |  6KB  |  258 lines

  1. /* "p2c", a Pascal to C translator.
  2.    Copyright (C) 1989, 1990, 1991 Free Software Foundation.
  3.    Author's address: daveg@csvax.caltech.edu; 256-80 Caltech/Pasadena CA 91125.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation (any version).
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING.  If not, write to
  16. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  17.  
  18.  
  19.  
  20. #define define_parameters
  21. #define PROTO_DIR_C
  22. #include "trans.h"
  23.  
  24.  
  25. /* This file is user-modifiable.  It is the "directory" of C functions
  26.    for compiling in-line various Pascal library routines. */
  27.  
  28.  
  29.  
  30. extern void setup_module_hp();
  31. extern void setup_module_cit();
  32. extern void setup_module_tanner();
  33.  
  34.  
  35.  
  36.  
  37. /* This function is called once when p2c is starting up, before
  38.    the p2crc file has been read.
  39. */
  40.  
  41. void init_dir()
  42. {
  43.  
  44.  
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51. /* This function is called once when p2c is starting up, after
  52.    the p2crc file has been read.
  53. */
  54.  
  55. void setup_dir()
  56. {
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. /* This procedure is called after reading the import text for a module,
  66.    where "name" is the module name, in upper-case letters.  Calls to
  67.    "addmeaning", "makestandardfunc", etc. will annotate the context of
  68.    the module.  Note that this will be called if the module is searched,
  69.    even if it is never actually imported.
  70. */
  71.  
  72. #if 0
  73. Static void _setup(name, defn)
  74. char *name;
  75. int defn;
  76. {
  77.     /* this is a dummy procedure which may be called by setup_module */
  78. }
  79. #endif
  80.  
  81. #define _setup(a,b)
  82.  
  83. void setup_module(name, defn)
  84. char *name;
  85. int defn;
  86. {
  87.     if (!strcicmp(name, "SYSTEM"))
  88.     decl_builtins();
  89. #ifdef CUST1
  90.     CUST1(name, defn);
  91. #endif
  92. #ifdef CUST2
  93.     CUST2(name, defn);
  94. #endif
  95. #ifdef CUST3
  96.     CUST3(name, defn);
  97. #endif
  98. #ifdef CUST4
  99.     CUST4(name, defn);
  100. #endif
  101. #ifdef CUST5
  102.     CUST5(name, defn);
  103. #endif
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110. /* This procedure is called once after the p2crc file has been
  111.    read and the built-in parameters have been "fixed".  It should
  112.    check ranges and add defaults for any newly introduced parameters
  113.    in the "rctable" (see "trans.h").
  114. */
  115.  
  116. void fix_parameters()
  117. {
  118.  
  119.  
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126. /* This function is called during a traversal of the tree of statements for
  127.    a procedure.  Ordinarily it returns its argument; it may instead return
  128.    an arbitrary other statement or sequence of statements, which will then
  129.    be spliced in to replace the original one.  It may return NULL to delete
  130.    the statement altogether.
  131. */
  132.  
  133. Stmt *fix_statement(sp)
  134. Stmt *sp;
  135. {
  136.     return sp;
  137. }
  138.  
  139.  
  140.  
  141.  
  142.  
  143. /* This is the analogous function for expression traversals.  It is
  144.    called after the arguments have been (recursively) fixed and all
  145.    built-in fixes have been performed.
  146. */
  147.  
  148. Expr *fix_expression(ex, env)
  149. Expr *ex;
  150. int env;
  151. {
  152.     return ex;
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159. /* This procedure is called when fixing an expression of type
  160.    EK_BICALL.  It is called before the arguments are fixed.  If
  161.    it recognizes the BICALL, it should fix the arguments, then
  162.    return a (possibly modified) fixed expression, which may or
  163.    may not be a BICALL.  That expression will then be sent to
  164.    fix_expression() as usual, but other standard fixes will not
  165.    automatically be performed on it.  If the BICALL is not
  166.    recognized, the function should return NULL.
  167. */
  168.  
  169. Expr *fix_bicall(ex, env)
  170. Expr *ex;
  171. int env;
  172. {
  173.     return NULL;
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180. /* This function returns nonzero if the built-in function "name"
  181.    should be written "if (f(x))" rather than "if (f(x) != 0)"
  182.    when used as a boolean.  The call does *not* necessarily have
  183.    to return a 1-or-0 value.
  184. */
  185.  
  186. int boolean_bicall(name)
  187. char *name;
  188. {
  189.     return (!strcmp(name, "strcmp") ||
  190.             !strcmp(name, "strncmp") ||
  191.             !strcmp(name, "memcmp") ||
  192.             !strcmp(name, "feof") ||
  193.             !strcmp(name, "feoln"));
  194. }
  195.  
  196.  
  197.  
  198.  
  199.  
  200. /* The function "name" promises not to change certain of its
  201.    VAR-style parameters.  For each of arguments i = 0 through 15,
  202.    if bit 1<<i of the return value of this function is set, and
  203.    the i'th parameter is a pointer to an object, then the function
  204.    guarantees not to change that object.
  205. */
  206.  
  207. unsigned int safemask_bicall(name)
  208. char *name;
  209. {
  210.     Symbol *sp;
  211.  
  212.     sp = findsymbol_opt(name);
  213.     if (sp) {
  214.     if (sp->flags & (STRUCTF|STRLAPF))
  215.         return ~1;
  216.     if (sp->flags & (NOSIDEEFF|DETERMF))
  217.         return ~0;
  218.     }
  219.     if (!strcmp(name, "fwrite") ||
  220.         !strcmp(name, "memchr"))
  221.         return 1;
  222.     if (!strcmp(name, "memcpy") ||
  223.         !strcmp(name, "memmove"))
  224.         return 2;
  225.     if (!strcmp(name, "memcmp"))
  226.         return 3;
  227.     if (!strcmp(name, "sprintf") ||
  228.         !strcmp(name, "fprintf"))
  229.         return ~1;
  230.     if (!strcmp(name, "printf"))
  231.         return ~0;
  232.     return 0;
  233. }
  234.  
  235.  
  236.  
  237.  
  238.  
  239. /* The function "name" has side effects that could affect other variables
  240.    in the program besides those that are explicitly mentioned.
  241. */
  242.  
  243. int sideeffects_bicall(name)
  244. char *name;
  245. {
  246.     return 0;
  247. }
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254. /* End. */
  255.  
  256.  
  257.  
  258.