home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
prgramer
/
adaptor
/
src
/
transfor.c
< prev
next >
Wrap
Text File
|
1994-01-02
|
13KB
|
619 lines
# include "Transfor.h"
# include "yyTransf.w"
# include <stdio.h>
# if defined __STDC__ | defined __cplusplus
# include <stdlib.h>
# else
extern void exit ();
# endif
# include "Tree.h"
# include "Definiti.h"
# ifndef NULL
# define NULL 0L
# endif
# ifndef false
# define false 0
# endif
# ifndef true
# define true 1
# endif
# ifdef yyInline
# define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
free += nodesize [kind]; \
ptr->yyHead.yyMark = 0; \
ptr->Kind = kind;
# else
# define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
# endif
# define yyWrite(s) (void) fputs (s, yyf)
# define yyWriteNl (void) fputc ('\n', yyf)
# line 25 "Transform.puma"
# include <stdio.h>
# include "Tree.h"
# include "Idents.h"
# include "StringMe.h"
static FILE * yyf = stdout;
static void yyAbort
# ifdef __cplusplus
(char * yyFunction)
# else
(yyFunction) char * yyFunction;
# endif
{
(void) fprintf (stderr, "Error: module Transform, routine %s failed\n", yyFunction);
exit (1);
}
tTree CombineACF ARGS((tTree list1, tTree list2));
tTree CombineBTP ARGS((tTree list1, tTree list2));
tTree ReplaceACF ARGS((tTree old, tTree newelem, tTree newnext));
static tTree ReplaceACF_h ARGS((tTree old, tTree newelem, tTree newnext));
static void ReplaceACF_Set ARGS((tTree newelem, int line));
tTree ReplaceDECL ARGS((tTree old, tTree newelem, tTree newnext));
static tTree ReplaceDECL_h ARGS((tTree old, tTree newelem, tTree newnext));
tTree AppendDECLS ARGS((tTree t, tTree newlist));
tTree MakeFuncCall ARGS((tIdent id, tTree exps));
static void MakeFuncParams ARGS((tTree t));
tTree ExpToVarParam ARGS((tTree exp));
tTree AppendParam ARGS((tTree plist, tTree param));
tTree CombineACF
# if defined __STDC__ | defined __cplusplus
(register tTree list1, register tTree list2)
# else
(list1, list2)
register tTree list1;
register tTree list2;
# endif
{
# line 44 "Transform.puma"
{
# line 45 "Transform.puma"
if (! ((list1 == NoTree))) goto yyL1;
}
return list2;
yyL1:;
if (list1->Kind == kACF_EMPTY) {
# line 49 "Transform.puma"
return list2;
}
if (list1->Kind == kACF_LIST) {
# line 53 "Transform.puma"
{
# line 54 "Transform.puma"
if (! ((list1->ACF_LIST.Next == NoTree))) goto yyL3;
{
# line 55 "Transform.puma"
list1->ACF_LIST.Next = list2;
}
}
return list1;
yyL3:;
if (list1->ACF_LIST.Next->Kind == kACF_EMPTY) {
# line 59 "Transform.puma"
{
# line 60 "Transform.puma"
list1->ACF_LIST.Next = list2;
}
return list1;
}
# line 64 "Transform.puma"
{
# line 65 "Transform.puma"
list1->ACF_LIST.Next = CombineACF (list1->ACF_LIST.Next, list2);
}
return list1;
}
# line 69 "Transform.puma"
return mACF_LIST (list1, list2);
}
tTree CombineBTP
# if defined __STDC__ | defined __cplusplus
(register tTree list1, register tTree list2)
# else
(list1, list2)
register tTree list1;
register tTree list2;
# endif
{
# line 84 "Transform.puma"
{
# line 85 "Transform.puma"
if (! ((list1 == NoTree))) goto yyL1;
}
return list2;
yyL1:;
if (list1->Kind == kBTP_EMPTY) {
# line 89 "Transform.puma"
return list2;
}
if (list1->Kind == kBTP_LIST) {
# line 93 "Transform.puma"
{
# line 94 "Transform.puma"
if (! ((list1->BTP_LIST.Next == NoTree))) goto yyL3;
{
# line 95 "Transform.puma"
list1->BTP_LIST.Next = list2;
}
}
return list1;
yyL3:;
if (list1->BTP_LIST.Next->Kind == kBTP_EMPTY) {
# line 99 "Transform.puma"
{
# line 100 "Transform.puma"
list1->BTP_LIST.Next = list2;
}
return list1;
}
# line 104 "Transform.puma"
{
# line 105 "Transform.puma"
list1->BTP_LIST.Next = CombineBTP (list1->BTP_LIST.Next, list2);
}
return list1;
}
# line 109 "Transform.puma"
return mBTP_LIST (list1, list2);
}
tTree ReplaceACF
# if defined __STDC__ | defined __cplusplus
(register tTree old, register tTree newelem, register tTree newnext)
# else
(old, newelem, newnext)
register tTree old;
register tTree newelem;
register tTree newnext;
# endif
{
# line 128 "Transform.puma"
tTree t;
if (old->Kind == kACF_LIST) {
if (equalint (old->ACF_LIST.Elem->ACF_NODE.Label, 0)) {
# line 132 "Transform.puma"
{
# line 134 "Transform.puma"
if (newelem == NoTree)
t = old->ACF_LIST.Next;
else
t = ReplaceACF_h (old, newelem, newnext);
}
return t;
}
# line 142 "Transform.puma"
{
# line 143 "Transform.puma"
if (newelem == NoTree)
{ t = mACF_DUMMY ();
t->ACF_NODE.Label = old->ACF_LIST.Elem->ACF_NODE.Label;
t->ACF_NODE.Line = old->ACF_LIST.Elem->ACF_NODE.Line;
old->ACF_LIST.Elem = t;
old->ACF_LIST.Next = newnext;
t = old;
}
else
t = ReplaceACF_h (old, newelem, newnext);
}
return t;
}
yyAbort ("ReplaceACF");
}
static tTree ReplaceACF_h
# if defined __STDC__ | defined __cplusplus
(register tTree old, register tTree newelem, register tTree newnext)
# else
(old, newelem, newnext)
register tTree old;
register tTree newelem;
register tTree newnext;
# endif
{
# line 162 "Transform.puma"
tTree hacf;
int hlabel;
if (old->Kind == kACF_LIST) {
# line 167 "Transform.puma"
{
# line 168 "Transform.puma"
if (! (old->ACF_LIST.Elem == newelem)) goto yyL1;
{
# line 169 "Transform.puma"
old->ACF_LIST.Next = newnext;
}
}
return old;
yyL1:;
if (Tree_IsType (newelem, kACF_NODE)) {
# line 173 "Transform.puma"
{
# line 175 "Transform.puma"
newelem->ACF_NODE.Label = old->ACF_LIST.Elem->ACF_NODE.Label;
old->ACF_LIST.Elem->ACF_NODE.Label = 0;
newelem->ACF_NODE.Line = old->ACF_LIST.Elem->ACF_NODE.Line;
old->ACF_LIST.Elem = newelem;
old->ACF_LIST.Next = newnext;
}
return old;
}
if (newelem->Kind == kACF_LIST) {
# line 185 "Transform.puma"
{
# line 187 "Transform.puma"
hlabel = old->ACF_LIST.Elem->ACF_NODE.Label;
ReplaceACF_Set (newelem, old->ACF_LIST.Elem->ACF_NODE.Line);
newelem->ACF_LIST.Elem->ACF_NODE.Label = hlabel;
hacf = newelem;
while (hacf->ACF_LIST.Next != NoTree)
hacf = hacf->ACF_LIST.Next;
hacf->ACF_LIST.Next = newnext;
}
return newelem;
}
}
yyAbort ("ReplaceACF_h");
}
static void ReplaceACF_Set
# if defined __STDC__ | defined __cplusplus
(register tTree newelem, register int line)
# else
(newelem, line)
register tTree newelem;
register int line;
# endif
{
if (newelem == NoTree) return;
if (newelem->Kind == kACF_LIST) {
# line 200 "Transform.puma"
{
# line 201 "Transform.puma"
newelem->ACF_LIST.Elem->ACF_NODE.Label = 0;
newelem->ACF_LIST.Elem->ACF_NODE.Line = line;
if (newelem->ACF_LIST.Next != NoTree)
ReplaceACF_Set (newelem->ACF_LIST.Next, line);
}
return;
}
;
}
tTree ReplaceDECL
# if defined __STDC__ | defined __cplusplus
(register tTree old, register tTree newelem, register tTree newnext)
# else
(old, newelem, newnext)
register tTree old;
register tTree newelem;
register tTree newnext;
# endif
{
# line 220 "Transform.puma"
tTree t;
if (old->Kind == kDECL_LIST) {
# line 224 "Transform.puma"
{
# line 225 "Transform.puma"
if (newelem == NoTree)
t = old->DECL_LIST.Next;
else
t = ReplaceDECL_h (old, newelem, newnext);
}
return t;
}
yyAbort ("ReplaceDECL");
}
static tTree ReplaceDECL_h
# if defined __STDC__ | defined __cplusplus
(register tTree old, register tTree newelem, register tTree newnext)
# else
(old, newelem, newnext)
register tTree old;
register tTree newelem;
register tTree newnext;
# endif
{
# line 237 "Transform.puma"
tTree hdecl;
if (old->Kind == kDECL_LIST) {
if (Tree_IsType (newelem, kDECL_NODE)) {
# line 241 "Transform.puma"
{
# line 244 "Transform.puma"
old->DECL_LIST.Elem = newelem;
old->DECL_LIST.Next = newnext;
}
return old;
}
if (newelem->Kind == kDECL_LIST) {
# line 250 "Transform.puma"
{
# line 252 "Transform.puma"
hdecl = newelem;
while (hdecl->DECL_LIST.Next != NoTree)
hdecl = hdecl->DECL_LIST.Next;
hdecl->DECL_LIST.Next = newnext;
}
return newelem;
}
}
# line 260 "Transform.puma"
{
# line 261 "Transform.puma"
printf ("ReplaceDECL_h failed, old tree = \n");
# line 262 "Transform.puma"
WriteTree (stdout, old);
# line 263 "Transform.puma"
printf ("new elem = \n");
# line 264 "Transform.puma"
WriteTree (stdout, newelem);
# line 265 "Transform.puma"
FileUnparse (stdout, newelem);
# line 266 "Transform.puma"
printf ("new tail = \n");
# line 267 "Transform.puma"
WriteTree (stdout, newnext);
# line 268 "Transform.puma"
kill_in_protocol ();
}
return NoTree;
}
tTree AppendDECLS
# if defined __STDC__ | defined __cplusplus
(register tTree t, register tTree newlist)
# else
(t, newlist)
register tTree t;
register tTree newlist;
# endif
{
# line 280 "Transform.puma"
{
# line 281 "Transform.puma"
if (! (newlist == NoTree)) goto yyL1;
{
# line 282 "Transform.puma"
printf ("AppendDECLS: newlist = NoTree\n");
# line 283 "Transform.puma"
exit (- 1);
}
}
return t;
yyL1:;
if (t->Kind == kDECL_LIST) {
if (t->DECL_LIST.Elem->Kind == kSTMT_FUNC_DECL) {
if (newlist->Kind == kDECL_LIST) {
if (newlist->DECL_LIST.Elem->Kind == kSTMT_FUNC_DECL) {
# line 287 "Transform.puma"
{
# line 288 "Transform.puma"
t->DECL_LIST.Next = AppendDECLS (t->DECL_LIST.Next, newlist);
}
return t;
}
}
# line 292 "Transform.puma"
return AppendDECLS (newlist, t);
}
# line 296 "Transform.puma"
{
# line 297 "Transform.puma"
t->DECL_LIST.Next = AppendDECLS (t->DECL_LIST.Next, newlist);
}
return t;
}
if (t->Kind == kDECL_EMPTY) {
# line 301 "Transform.puma"
return newlist;
}
yyAbort ("AppendDECLS");
}
tTree MakeFuncCall
# if defined __STDC__ | defined __cplusplus
(register tIdent id, register tTree exps)
# else
(id, exps)
register tIdent id;
register tTree exps;
# endif
{
# line 315 "Transform.puma"
tTree v;
# line 319 "Transform.puma"
{
# line 320 "Transform.puma"
MakeFuncParams (exps);
v = mFUNC_CALL_EXP (mPROC_OBJ (id), exps);
}
return v;
}
static void MakeFuncParams
# if defined __STDC__ | defined __cplusplus
(register tTree t)
# else
(t)
register tTree t;
# endif
{
if (t == NoTree) return;
if (t->Kind == kBTE_LIST) {
if (t->BTE_LIST.Elem->Kind == kVAR_EXP) {
# line 327 "Transform.puma"
{
# line 328 "Transform.puma"
MakeFuncParams (t->BTE_LIST.Next);
# line 329 "Transform.puma"
t->Kind = kBTP_LIST;
t->BTP_LIST.Elem = mVAR_PARAM (t->BTE_LIST.Elem->VAR_EXP.V);
}
return;
}
if (t->BTE_LIST.Elem->Kind == kNAMED_EXP) {
if (t->BTE_LIST.Elem->NAMED_EXP.VAL->Kind == kVAR_EXP) {
# line 333 "Transform.puma"
{
# line 334 "Transform.puma"
MakeFuncParams (t->BTE_LIST.Next);
# line 335 "Transform.puma"
t->Kind = kBTP_LIST;
t->BTE_LIST.Elem->Kind = kNAMED_PARAM;
t->BTE_LIST.Elem->NAMED_PARAM.VAL = mVAR_PARAM (t->BTE_LIST.Elem->NAMED_EXP.VAL->VAR_EXP.V);
}
return;
}
# line 340 "Transform.puma"
{
# line 341 "Transform.puma"
MakeFuncParams (t->BTE_LIST.Next);
# line 342 "Transform.puma"
t->Kind = kBTP_LIST;
t->BTE_LIST.Elem->Kind = kNAMED_PARAM;
t->BTE_LIST.Elem->NAMED_PARAM.VAL = mVAR_PARAM (mADDR(t->BTE_LIST.Elem->NAMED_EXP.VAL));
}
return;
}
# line 347 "Transform.puma"
{
# line 348 "Transform.puma"
MakeFuncParams (t->BTE_LIST.Next);
# line 349 "Transform.puma"
MakeFuncParams (t->BTE_LIST.Next);
# line 350 "Transform.puma"
t->Kind = kBTP_LIST;
t->BTP_LIST.Elem = mVAR_PARAM (mADDR(t->BTE_LIST.Elem));
}
return;
}
if (t->Kind == kBTE_EMPTY) {
# line 354 "Transform.puma"
{
# line 355 "Transform.puma"
t->Kind = kBTP_EMPTY;
}
return;
}
;
}
tTree ExpToVarParam
# if defined __STDC__ | defined __cplusplus
(register tTree exp)
# else
(exp)
register tTree exp;
# endif
{
if (exp->Kind == kVAR_EXP) {
# line 366 "Transform.puma"
return (mVAR_PARAM (exp->VAR_EXP.V));
}
# line 370 "Transform.puma"
return (mVAR_PARAM (mADDR (exp)));
}
tTree AppendParam
# if defined __STDC__ | defined __cplusplus
(register tTree plist, register tTree param)
# else
(plist, param)
register tTree plist;
register tTree param;
# endif
{
if (plist->Kind == kBTP_EMPTY) {
# line 376 "Transform.puma"
return mBTP_LIST (param, plist);
}
if (plist->Kind == kBTP_LIST) {
# line 380 "Transform.puma"
{
# line 381 "Transform.puma"
plist->BTP_LIST.Next = AppendParam (plist->BTP_LIST.Next, param);
}
return plist;
}
yyAbort ("AppendParam");
}
void BeginTransform ()
{
}
void CloseTransform ()
{
}