4
* (c) Copyright 1988-1994 Adobe Systems Incorporated.
7
* Permission to use, copy, modify, distribute, and sublicense this software
8
* and its documentation for any purpose and without fee is hereby granted,
9
* provided that the above copyright notices appear in all copies and that
10
* both those copyright notices and this permission notice appear in
11
* supporting documentation and that the name of Adobe Systems Incorporated
12
* not be used in advertising or publicity pertaining to distribution of the
13
* software without specific, written prior permission. No trademark license
14
* to use the Adobe trademarks is hereby granted. If the Adobe trademark
15
* "Display PostScript"(tm) is used to describe this software, its
16
* functionality or for any other purpose, such use shall be limited to a
17
* statement that this software works in conjunction with the Display
18
* PostScript system. Proper trademark attribution to reflect Adobe's
19
* ownership of the trademark shall be given whenever any such reference to
20
* the Display PostScript system is made.
22
* ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
23
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
24
* ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
25
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
* NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
27
* TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
28
* DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
29
* NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
30
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
31
* PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
33
* Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
34
* Incorporated which may be registered in certain jurisdictions
36
* Author: Adobe Systems Incorporated
54
#include "pswsemantics.h"
56
/***********************/
57
/* Module-wide globals */
58
/***********************/
60
char *currentPSWName = NULL;
61
int reportedPSWName = 0;
63
static PSWDict currentDict = NULL;
66
/*************************************************/
67
/* Procedures called by the parser's annotations */
68
/*************************************************/
70
static boolean IsCharType(Type t)
72
return (t == T_CHAR || t == T_UCHAR);
75
static boolean IsNumStrType(Type t)
80
|| t == T_SHORTNUMSTR);
85
currentPSWName = psw_malloc(strlen(s)+1);
86
strcpy(currentPSWName, s);
90
/* Generate the code for this wrap now */
91
void FinalizePSWrapDef(Header hdr, Body body)
93
if (header && ! hdr->isStatic) EmitPrototype(hdr);
95
printf("#line %d \"%s\"\n", ++outlineno, ofile);
98
printf("{\n"); outlineno++;
100
printf("}\n"); outlineno++;
101
printf("#line %d \"%s\"\n", yylineno, ifile); outlineno++;
103
/* release storage for this wrap */
104
/* Omit if you have lots of memory and want pswrap lean and mean */
106
register Arg arg, nextarg; register Item item, nextitem;
107
for(arg = hdr->inArgs; arg; arg = nextarg) {
109
for(item = arg->items; item; item = nextitem) {
110
nextitem = item->next;
111
if (item->subscripted) {
112
if (!item->subscript->constant) free(item->subscript->name);
113
free(item->subscript);
115
if (!item->scale->constant) free(item->scale->name);
119
free(item->name); free(item);
123
for(arg = hdr->outArgs; arg; arg = nextarg) {
125
for(item = arg->items; item; item = nextitem) {
126
nextitem = item->next;
127
if (item->subscripted) {
128
if (!item->subscript->constant) free(item->subscript->name);
129
free(item->subscript);
131
free(item->name); free(item);
135
free(hdr->name); free(hdr);
139
DestroyPSWDict(currentDict);
141
currentPSWName = NULL;
145
/* Complete construction of the Header tree and make some semantic checks */
146
Header PSWHeader(boolean isStatic, Args inArgs, Args outArgs)
148
char *name = currentPSWName;
149
register Arg arg, prevArg;
150
register Item item, prevItem;
153
Header hdr = (Header)psw_calloc(sizeof(HeaderRec), 1);
154
hdr->isStatic = isStatic;
157
currentDict = CreatePSWDict(511);
160
for (arg = inArgs; arg; arg = arg->next) { /* foreach input arg */
162
for (item = arg->items; item; item = item->next) {
163
if (IsCharType(arg->type)
164
&& !(item->starred || item->subscripted)) {
165
ErrIntro(item->sourceLine);
167
"char input parameter %s must be starred or subscripted\n",
169
/* remove item from list */
170
if (prevItem) {prevItem->next = item->next;}
171
else if (item == arg->items) {arg->items = item->next;};
172
/* free(item); XXX? */
175
if(item->scaled && !IsNumStrType(arg->type)) {
176
ErrIntro(item->sourceLine);
177
fprintf(stderr,"only numstring parameters may be scaled\n");
179
if (IsNumStrType(arg->type)
180
&& (item->starred || !item->subscripted)) {
181
ErrIntro(item->sourceLine);
183
"numstring parameter %s may only be subscripted\n",
185
/* remove item from list */
186
if (prevItem) {prevItem->next = item->next;}
187
else if (item == arg->items) {arg->items = item->next;};
188
/* free(item); XXX? */
191
if (arg->type != T_CONTEXT) {
192
if (PSWDictLookup(currentDict, item->name) != -1) {
193
ErrIntro(item->sourceLine);
194
fprintf(stderr,"parameter %s reused\n", item->name);
195
if (prevItem) {prevItem->next = item->next;}
196
else if (item == arg->items) {arg->items = item->next;};
200
PSWDictEnter(currentDict, item->name, (PSWDictValue) item);
201
item->isoutput = false;
202
item->type = arg->type;
206
if (arg->items == NULL) {
207
if (prevArg) { prevArg->next = arg->next;}
208
else if (arg == inArgs) {inArgs = arg->next;}
215
for (arg = outArgs; arg; arg = arg->next) { /* foreach output arg */
217
for (item = arg->items; item; item = item->next) {
218
if (arg->type == T_USEROBJECT) {
219
ErrIntro(item->sourceLine);
220
fprintf(stderr,"output parameter %s can not be of type userobject\n",
222
/* remove item from list */
223
if (prevItem) {prevItem->next = item->next;}
224
else if (item == arg->items) {arg->items = item->next;};
225
/* free(item); XXX */
228
if (arg->type == T_NUMSTR || arg->type == T_FLOATNUMSTR
229
|| arg->type == T_LONGNUMSTR || arg->type == T_SHORTNUMSTR) {
230
ErrIntro(item->sourceLine);
231
fprintf(stderr,"output parameter %s can not be of type numstring\n",
233
/* remove item from list */
234
if (prevItem) {prevItem->next = item->next;}
235
else if (item == arg->items) {arg->items = item->next;};
236
/* free(item); XXX */
239
if (!(item->starred || item->subscripted)) {
240
ErrIntro(item->sourceLine);
241
fprintf(stderr,"output parameter %s must be starred or subscripted\n",
243
/* remove item from list */
244
if (prevItem) {prevItem->next = item->next;}
245
else if (item == arg->items) {arg->items = item->next;};
246
/* free(item); XXX */
249
if (PSWDictLookup(currentDict, item->name) != -1) {
250
ErrIntro(item->sourceLine);
251
fprintf(stderr,"parameter %s reused\n", item->name);
252
/* remove item from list */
253
if (prevItem) {prevItem->next = item->next;}
254
else if (item == arg->items) {arg->items = item->next;};
255
/* free the storage? XXX */
258
PSWDictEnter(currentDict, item->name, (PSWDictValue) item);
259
item->isoutput = true;
260
item->type = arg->type;
261
item->tag = nextTag++;
263
} /* inside for loop */
264
if (arg->items == NULL) {
266
prevArg->next = arg->next;
267
} else if (arg == outArgs) {
273
} /* outside for loop */
275
/* now go looking for subscripts that name an input arg */
276
for (arg = inArgs; arg; arg = arg->next) { /* foreach input arg */
277
for (item = arg->items; item; item = item->next) {
278
if (item->subscripted && !item->subscript->constant) {
279
PSWDictValue v = PSWDictLookup(currentDict, item->subscript->name);
281
Item subItem = (Item)v;
282
if (subItem->isoutput) {
283
ErrIntro(subItem->sourceLine);
284
fprintf(stderr,"output parameter %s used as a subscript\n",
288
if (subItem->type != T_INT) {
289
ErrIntro(subItem->sourceLine);
291
"input parameter %s used as a subscript is not an int\n",
300
for (arg = outArgs; arg; arg = arg->next) { /* foreach output arg */
301
for (item = arg->items; item; item = item->next) {
302
if (item->subscripted && !item->subscript->constant) {
303
PSWDictValue v = PSWDictLookup(currentDict, item->subscript->name);
305
Item subItem = (Item)v;
306
if (subItem->isoutput) {
307
ErrIntro(subItem->sourceLine);
308
fprintf(stderr,"output parameter %s used as a subscript\n",
312
if (subItem->type != T_INT) {
313
ErrIntro(subItem->sourceLine);
315
"input parameter %s used as a subscript is not an int\n",
324
hdr->inArgs = inArgs;
325
hdr->outArgs = outArgs;
330
Token PSWToken(Type type, char *val)
332
register Token token = (Token)psw_calloc(sizeof(TokenRec), 1);
337
token->sourceLine = yylineno;
343
Item dictVal = (Item) PSWDictLookup(currentDict, (char *)val);
344
if ((PSWDictValue) dictVal != -1) {
345
if ((type != T_NAME) && (dictVal->isoutput)) {
347
fprintf(stderr,"output parameter %s used as %s\n",
349
(type == T_STRING) ? "string": "literal name");
351
if ((type != T_NAME) && !IsCharType(dictVal->type)) {
353
fprintf(stderr,"non-char input parameter %s used as %s\n",
355
(type == T_STRING) ? "string": "literal name");
357
token->namedFormal = dictVal; /* ok, so assign a value */
368
Token PSWToken2(Type type, char *val, char *ind)
370
register Token token = (Token)psw_calloc(sizeof(TokenRec), 1);
371
Item dictVal = (Item) PSWDictLookup(currentDict, val);
377
token->sourceLine = yylineno;
379
/* Assert(type == T_SUBSCRIPTED); */
380
if (((PSWDictValue) dictVal == -1) || (dictVal->isoutput)) {
382
fprintf(stderr,"%s not an input parameter\n", val);
384
else if (!dictVal->subscripted) {
386
fprintf(stderr,"%s not an array\n", val);
388
else if (dictVal->type >= T_NUMSTR) {
390
fprintf(stderr,"cannot subscript numstring %s\n", val);
392
else if (IsCharType(dictVal->type)) {
394
fprintf(stderr,"%s not a scalar type\n", val);
397
dvi = (Item) PSWDictLookup(currentDict, (char *)ind);
398
if (((PSWDictValue) dvi != -1)
399
&& ((dvi->isoutput) || IsCharType(dvi->type))) {
401
fprintf(stderr,"%s wrong type\n",(char *) ind);
404
token->body.var = (char *) ind;
405
token->namedFormal = dictVal; /* ok, so assign a value */
410
/* ERRORS fall through */
412
return (PSWToken(T_NAME,val));
415
Arg PSWArg(Type type, Items items)
417
register Arg arg = (Arg)psw_calloc(sizeof(ArgRec), 1);
424
Item PSWItem(char *name)
426
register Item item = (Item)psw_calloc(sizeof(ItemRec), 1);
429
item->sourceLine = yylineno;
433
Item PSWStarItem(char *name)
435
register Item item = (Item)psw_calloc(sizeof(ItemRec), 1);
438
item->starred = true;
439
item->sourceLine = yylineno;
443
Item PSWSubscriptItem(char *name, Subscript subscript)
445
register Item item = (Item)psw_calloc(sizeof(ItemRec), 1);
448
item->subscript = subscript;
449
item->subscripted = true;
450
item->sourceLine = yylineno;
454
Item PSWScaleItem(char *name, Subscript subscript, char *nameval, int val)
457
Scale scale = (Scale)psw_calloc(sizeof(ScaleRec), 1);
458
item = PSWSubscriptItem(name, subscript);
461
scale->name = nameval;
463
scale->constant = true;
470
Subscript PSWNameSubscript(char *name)
472
Subscript subscript = (Subscript)psw_calloc(sizeof(SubscriptRec), 1);
473
subscript->name = name;
477
Subscript PSWIntegerSubscript(int val)
479
Subscript subscript = (Subscript)psw_calloc(sizeof(SubscriptRec), 1);
480
subscript->constant = true;
481
subscript->val = val;
485
Args ConsPSWArgs(Arg arg, Args args)
491
Tokens AppendPSWToken(Token token, Tokens tokens)
494
static Token firstToken, lastToken; /* cache ptr to last */
496
if ((token->type == T_NAME) && (token->namedFormal)) {
497
if( token->namedFormal->isoutput) {
499
char *pos = "printobject";
500
char *ss = psw_malloc(strlen(pos) + 1);
504
token = PSWToken(T_INT, (char *) token->namedFormal->tag);
505
free((char *)oldtoken);
506
token->next = PSWToken(T_NAME, ss);
508
if (token->namedFormal->type == T_USEROBJECT) {
509
char *pos = "execuserobject";
510
char *ss = psw_malloc(strlen(pos) + 1);
512
token->next = PSWToken(T_NAME, ss);
516
if (tokens == NULL) {
517
firstToken = lastToken = token;
521
if (tokens != firstToken)
522
firstToken = lastToken = tokens;
523
for (t = lastToken; t->next; t = t->next);
524
lastToken = t->next = token;
529
Args AppendPSWArgs(Arg arg, Args args)
533
if (args == NULL) return arg;
535
for (a = args; a->next; a = a->next);
541
Items AppendPSWItems(Item item, Items items)
545
if (items == NULL) return item;
547
for (t = items; t->next; t = t->next);