File: dir.c

package info (click to toggle)
p2c 1.21alpha2-1
  • links: PTS
  • area: main
  • in suites: potato, woody
  • size: 1,996 kB
  • ctags: 3,399
  • sloc: ansic: 38,617; pascal: 2,499; makefile: 213; perl: 101
file content (257 lines) | stat: -rw-r--r-- 5,238 bytes parent folder | download | duplicates (2)
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
/* "p2c", a Pascal to C translator.
   Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation.
   Author's address: daveg@synaptics.com.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation (any version).

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */



#define define_parameters
#define PROTO_DIR_C
#include "trans.h"


/* This file is user-modifiable.  It is the "directory" of C functions
   for compiling in-line various Pascal library routines. */



extern void setup_module_hp();
extern void setup_module_cit();
extern void setup_module_tanner();




/* This function is called once when p2c is starting up, before
   the p2crc file has been read.
*/

void init_dir()
{


}





/* This function is called once when p2c is starting up, after
   the p2crc file has been read.
*/

void setup_dir()
{


}





/* This procedure is called after reading the import text for a module,
   where "name" is the module name, in upper-case letters.  Calls to
   "addmeaning", "makestandardfunc", etc. will annotate the context of
   the module.  Note that this will be called if the module is searched,
   even if it is never actually imported.
*/

#if 0
Static void _setup(name, defn)
char *name;
int defn;
{
    /* this is a dummy procedure which may be called by setup_module */
}
#endif

#define _setup(a,b)

void setup_module(name, defn)
char *name;
int defn;
{
    if (!strcicmp(name, "SYSTEM"))
	decl_builtins();
#ifdef CUST1
    CUST1(name, defn);
#endif
#ifdef CUST2
    CUST2(name, defn);
#endif
#ifdef CUST3
    CUST3(name, defn);
#endif
#ifdef CUST4
    CUST4(name, defn);
#endif
#ifdef CUST5
    CUST5(name, defn);
#endif
}





/* This procedure is called once after the p2crc file has been
   read and the built-in parameters have been "fixed".  It should
   check ranges and add defaults for any newly introduced parameters
   in the "rctable" (see "trans.h").
*/

void fix_parameters()
{


}





/* This function is called during a traversal of the tree of statements for
   a procedure.  Ordinarily it returns its argument; it may instead return
   an arbitrary other statement or sequence of statements, which will then
   be spliced in to replace the original one.  It may return NULL to delete
   the statement altogether.
*/

Stmt *fix_statement(sp)
Stmt *sp;
{
    return sp;
}





/* This is the analogous function for expression traversals.  It is
   called after the arguments have been (recursively) fixed and all
   built-in fixes have been performed.
*/

Expr *fix_expression(ex, env)
Expr *ex;
int env;
{
    return ex;
}





/* This procedure is called when fixing an expression of type
   EK_BICALL.  It is called before the arguments are fixed.  If
   it recognizes the BICALL, it should fix the arguments, then
   return a (possibly modified) fixed expression, which may or
   may not be a BICALL.  That expression will then be sent to
   fix_expression() as usual, but other standard fixes will not
   automatically be performed on it.  If the BICALL is not
   recognized, the function should return NULL.
*/

Expr *fix_bicall(ex, env)
Expr *ex;
int env;
{
    return NULL;
}





/* This function returns nonzero if the built-in function "name"
   should be written "if (f(x))" rather than "if (f(x) != 0)"
   when used as a boolean.  The call does *not* necessarily have
   to return a 1-or-0 value.
*/

int boolean_bicall(name)
char *name;
{
    return (!strcmp(name, "strcmp") ||
            !strcmp(name, "strncmp") ||
            !strcmp(name, "memcmp") ||
            !strcmp(name, "feof") ||
            !strcmp(name, "feoln"));
}





/* The function "name" promises not to change certain of its
   VAR-style parameters.  For each of arguments i = 0 through 15,
   if bit 1<<i of the return value of this function is set, and
   the i'th parameter is a pointer to an object, then the function
   guarantees not to change that object.
*/

unsigned int safemask_bicall(name)
char *name;
{
    Symbol *sp;

    sp = findsymbol_opt(name);
    if (sp) {
	if (sp->flags & (STRUCTF|STRLAPF))
	    return ~1;
	if (sp->flags & (NOSIDEEFF|DETERMF))
	    return ~0;
    }
    if (!strcmp(name, "fwrite") ||
        !strcmp(name, "memchr"))
        return 1;
    if (!strcmp(name, "memcpy") ||
        !strcmp(name, "memmove"))
        return 2;
    if (!strcmp(name, "memcmp"))
        return 3;
    if (!strcmp(name, "sprintf") ||
        !strcmp(name, "fprintf"))
        return ~1;
    if (!strcmp(name, "printf"))
        return ~0;
    return 0;
}





/* The function "name" has side effects that could affect other variables
   in the program besides those that are explicitly mentioned.
*/

int sideeffects_bicall(name)
char *name;
{
    return 0;
}






/* End. */