]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/sorcerer.c
2 * sorcerer.c -- support code for SORCERER output
4 * Define your own or compile and link this in.
11 /***********************************************************************
12 2-Oct-97 The routine ast_dup() appeared to have a bug in it. Instead
13 of providing a deep copy of its argument it made a bushy copy
14 of its argument - by duplicating the nodes pointed to by
15 its right link. This is certainly not deliberate and does
16 not match code in PCCTSAST.cpp (which had its own bug). This
17 has been changed to do a deep copy in the traditional sense.
18 ***********************************************************************/
21 /* Given a result pointer, return the same one if *t is NULL,
22 * else find the end of the sibling list and return the address
23 * the 'next[write]' field in that last node.
27 _nextresult(STreeParser
*_parser
, AST
**t
)
29 _nextresult(_parser
, t
)
36 if ( p
==NULL
) return t
;
37 while ( p
->ast_right(_parser
->write
) != NULL
)
39 p
= p
->ast_right(_parser
->write
);
41 return &(p
->ast_right(_parser
->write
));
45 * Copy the read pointers to the write pointers for a node or entire subtree
49 _copy_wildcard(STreeParser
*_parser
, AST
*t
, int root
)
51 _copy_wildcard(_parser
, t
, root
)
59 if ( !root
) t
->ast_right(_parser
->write
) = t
->ast_right(_parser
->read
);
60 t
->ast_down(_parser
->write
) = t
->ast_down(_parser
->read
);
61 if ( t
->ast_down(_parser
->read
)!=NULL
)
62 _copy_wildcard(_parser
, t
->ast_down(_parser
->read
), 0);
65 t
= t
->ast_right(_parser
->read
);
72 _mkroot(SORAST
**r
, SORAST
**s
, SORAST
**e
, SORAST
*t
)
75 SORAST
**r
, **s
, **e
, *t
;
83 _mkchild(SORAST
**r
, SORAST
**s
, SORAST
**e
, SORAST
*t
)
86 SORAST
**r
, **s
, **e
, *t
;
89 /* if no sibling list, must attach to any existing root */
93 /* If r is NULL, then there was no root defined--must be sibling list */
94 if ( *r
==NULL
) *r
= *s
;
95 else (*r
)->ast_down
= t
;
97 else { (*e
)->ast_right
= t
; *e
= t
; }
100 /* THESE FUNCS HAVE TO GO HERE BECAUSE THEY ARE SENSITIVE TO USER'S SORAST DEF */
108 SORAST
*t
= (SORAST
*)calloc(1, sizeof(SORAST
));
109 if ( t
==NULL
) sorcerer_panic("out of memory");
115 ast_dup_bushy(SORAST
*t
)
123 if ( t
== NULL
) return NULL
;
125 *u
= *t
; /* copy contents */
126 u
->ast_down
= ast_dup_bushy(t
->ast_down
); /* copy the rest of the tree */
127 u
->ast_right
= ast_dup_bushy(t
->ast_right
);
132 /* Assume t is a root node of a tree--duplicate that node and what's below */
144 if ( t
== NULL
) return NULL
;
146 *u
= *t
; /* copy contents */
147 u
->ast_down
= ast_dup_bushy(t
->ast_down
); /* copy the rest of the tree */
152 /* Assume t is a root node of a tree--duplicate that node and what's below */
155 ast_dup_node(SORAST
*t
)
163 if ( t
== NULL
) return NULL
;
165 *u
= *t
; /* copy contents */