]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CodeTools/Source/Pccts/antlr/dumpnode.c
35 int isEndRule(Node
* p
)
42 if ( p
->ntype
== nJunction
&&
43 ( (Junction
*) p
)->jtype
== EndRule
) {
50 void dumppred1(int depth
,Predicate
*p
)
52 void dumppred1(depth
,p
)
60 for (i
=0; i
<depth
; i
++) {
63 if (p
->expr
== PRED_AND_LIST
||
64 p
->expr
== PRED_OR_LIST
) {
65 fprintf(stderr
," %s", (p
->expr
== NULL
? "null expr" : p
->expr
));
66 if (p
->inverted
) fprintf(stderr
," predicate inverted !");
68 fprintf(stderr
," Redundant!");
70 if (p
->isConst
) fprintf(stderr
," const %d !",p
->constValue
);
73 fprintf(stderr
,"predicate k=%d",p
->k
);
74 k
=set_int(p
->completionSet
);
76 fprintf(stderr
," Incomplete Set=%d !",k
);
78 k
=set_int(p
->completionTree
);
80 fprintf(stderr
," Incomplete Tree=%d !",k
);
83 fprintf(stderr
," Redundant!");
85 fprintf(stderr
," \"%s\" (%x)", (p
->expr
== NULL
? "null expr" : p
->expr
) ,p
);
86 if (p
->source
!= NULL
) {
87 fprintf(stderr
,"line %d",p
->source
->line
);
89 if (p
->inverted
) fprintf(stderr
," predicate inverted !");
91 for (i
=0; i
<depth
; i
++) {
94 fprintf(stderr
,"scontext: ");
95 dumpset(p
->scontext
[1]);
96 for (i
=0; i
<depth
; i
++) {
99 fprintf(stderr
,"tcontext: ");
100 preorder(p
->tcontext
);
101 fprintf(stderr
,"\n");
103 fprintf(stderr
,"\n");
104 if (p
->down
!= NULL
) {
105 dumppred1(depth
+1,p
->down
);
107 if (p
->right
!= NULL
) {
108 dumppred1(depth
,p
->right
);
113 void dumppred(Predicate
*p
)
119 fprintf(stderr
,"---------------------------------\n");
121 fprintf(stderr
,"\n");
125 void dumppredtree(Predicate
*p
)
131 fprintf(stderr
,"predicate k=%d \"%s\" line %d\n",p
->k
,p
->expr
,p
->source
->line
);
132 dumpset(p
->scontext
[1]);
136 void dumppredexpr(Predicate
*p
)
142 fprintf(stderr
," pred expr \"%s\"\n",p
->expr
);
152 MR_dumpTreeF(stderr
,0,t
,5);
169 fprintf(stderr
,"dumpNode: Node is NULL");
176 fprintf(stderr
, "Junction (#%d in rule %s line %d) ",j
->seq
,j
->rname
,j
->line
);
177 if (j
->guess
) fprintf(stderr
,"guess block ");
180 fprintf(stderr
,"aSubBlk");
183 fprintf(stderr
,"aOptBlk");
186 fprintf(stderr
,"aLoopBeginBlk");
189 fprintf(stderr
,"aLoopBlk");
192 fprintf(stderr
,"aPlusBlk");
195 fprintf(stderr
,"EndBlk");
198 fprintf(stderr
,"RuleBlk");
201 fprintf(stderr
,"Generic");
204 fprintf(stderr
,"EndRule");
207 if (j
->halt
) fprintf(stderr
," halt!");
208 if (j
->p1
) fprintf(stderr
," p1 valid");
210 if (j
->p2
->ntype
== nJunction
) {
211 fprintf(stderr
," (p2=#%d)",( (Junction
*) j
->p2
)->seq
);
213 fprintf(stderr
," (p2 valid)");
216 if (j
->ignore
) fprintf(stderr
, " ignore/plus-block-bypass");
217 if (j
->fset
!= NULL
&& set_deg(*j
->fset
) != 0) {
218 fprintf(stderr
,"\nfset:\n");
221 if (j
->ftree
!= NULL
) {
222 fprintf(stderr
,"\nftree:\n");
225 fprintf(stderr
,"\n");
228 r
= (RuleRefNode
*) p
;
229 fprintf(stderr
, "RuleRefNode (in rule %s line %d) to rule %s\n", r
->rname
,r
->line
,r
->text
);
233 fprintf(stderr
, "TokNode (in rule %s line %d) token %s\n",t
->rname
,t
->line
,TerminalString(t
->token
));
237 if (a
->is_predicate
) {
238 fprintf(stderr
, "Predicate (in rule %s line %d) %s",a
->rname
,a
->line
,a
->action
);
239 if (a
->inverted
) fprintf(stderr
," action inverted !");
240 if (a
->guardpred
!= NULL
) {
241 fprintf(stderr
," guarded");
242 dumppredexpr(a
->guardpred
);
243 if (a
->ampersandPred
) {
244 fprintf(stderr
," \"&&\" style");
246 fprintf(stderr
," \"=>\" style");
249 if (a
->predEntry
!= NULL
) fprintf(stderr
," predEntry \"%s\" ",a
->predEntry
->str
);
250 fprintf(stderr
,"\n");
251 } else if (a
->init_action
) {
252 fprintf(stderr
, "Init-Action (in rule %s line %d) %s\n",a
->rname
,a
->line
,a
->action
);
254 fprintf(stderr
, "Action (in rule %s line %d) %s\n",a
->rname
,a
->line
,a
->action
);
269 if (p
->ntype
== nJunction
) {
270 result
=( (Junction
*) p
)->p1
;
273 fprintf(stderr
,"dp1: Not a Junction node");
287 if (p
->ntype
== nJunction
) {
288 result
=( (Junction
*) p
)->p2
;
291 fprintf(stderr
,"dp2: Not a Junction node");
306 if (p
->ntype
== nRuleRef
) {
307 result
=( (RuleRefNode
*)p
)->next
;
308 } else if (p
->ntype
== nAction
) {
309 result
=( (ActionNode
*)p
)->next
;
310 } else if (p
->ntype
== nToken
) {
311 result
=( (TokNode
*)p
)->next
;
313 fprintf(stderr
,"No next field: Neither a RuleRefNode, ActionNode, nor TokNode");
315 if (result
!= NULL
) d(result
);
329 fprintf(stderr
,"\n#%d ",++count
);
332 for (next
=p
; next
!= NULL
&& !isEndRule(next
) ; ) {
333 fprintf(stderr
,"#%d ",++count
);
334 if (next
->ntype
== nJunction
) {
343 Node
* dfn(Node
* p
,int target
)
354 fprintf(stderr
,"#%d ",++count
);
357 for (next
=p
; next
!= NULL
&& !isEndRule(next
) ; ) {
358 fprintf(stderr
,"#%d ",++count
);
359 if (next
->ntype
== nJunction
) {
364 if (count
== target
) {
373 static int findnodeMatch
;
376 Junction
*findnode1(Node
*n
)
378 Junction
*findnode1(n
)
386 if (n
== NULL
) return NULL
;
387 if (n
->ntype
== nJunction
) {
389 if (j
->seq
== findnodeMatch
) return j
;
390 if (j
->jtype
== EndRule
) return NULL
;
391 if (j
->jtype
!= RuleBlk
&& j
->jtype
!= EndBlk
) {
392 if (j
->p2
!= NULL
&& !j
->ignore
) {
393 match
=findnode1(j
->p2
);
394 if (match
!= NULL
) return match
;
399 return findnode1(next
);
403 Junction
*findnode(int match
)
405 Junction
*findnode(match
)
410 Junction
*result
=NULL
;
414 for (j
=SynDiag
; j
!= NULL
; j
=(Junction
*)j
->p2
) {
415 require (j
->ntype
== nJunction
&& j
->jtype
== RuleBlk
,"Not a rule block");
416 result
=findnode1( (Node
*) j
);
417 if (result
!= NULL
) break;
419 if (result
!= NULL
) {