* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)yycomm.c 5.2 (Berkeley) %G%";
* pxp - Pascal execution profiler
* Version 1.2 January 1979
* COMMENT PROCESSING CLUSTER
* The global organization of this cluster is as follows.
* While parsing the program information is saved in the tree which
* tells the source text coordinates (sequence numbers and columns)
* bounding each production. The comments from the source program
* are also saved, with information about their source text position
* and a classification as to their kind.
* When printing the reformatted program we flush out the comments
* at various points using the information in the comments and the parse
* tree to "resynchronize". A number of special cases are recognized to
* deal with the vagarities of producing a true "fixed point" so that
* a prettyprinted program will re-prettyprint to itself.
* Save sequence id's and column markers bounding a production
* for later use in placing comments. We save the sequence id
* and column of the leftmost token and the following token, and
* the sequence id of the last token in this reduction.
* See putcm, putcml, and putcmp below for motivation.
return(tree(6, l
, yypw
[i
].Wseqid
, yypw
[i
].Wcol
, yyseqid
, yycol
, yypw
[N
].Wseqid
));
* After a call to setline, Seqid is set to the sequence id
* of the symbol which followed the reduction in which the
* lineof call was embedded, Col to the associated column,
* and LSeqid to the sequence id of the last symbol in the reduction
* (Note that this is exact only if the last symbol was a terminal
* this is always true when it matters.)
* Retrieve the information from a call to lineof before beginning the
* output of a tree from a reduction. First flush to the left margin
* of the production, and then set so that later calls to putcm, putcml
* and putcmp will deal with the right margin of this comment.
* The routine setinfo is called when the lineof has no embedded line
* number to avoid trashing the current "line".
* The routine setinfo is often called after completing the output of
* the text of a tree to restore Seqid, Col, and LSeqid which may have
* been destroyed by the nested processing calls to setline.
* In this case the only effect of the call to setinfo is to
* modify the above three variables as a side effect.
* We return a word giving information about the comments which were
* actually put out. See putcm for details.
* Get the text of a comment from the input stream,
* recording its type and linking it into the linked
* list of comments headed by cmhp.
register struct comment
*cp
;
register struct commline
*kp
;
if (cmdelim
== '*' && yycol
== 10 || cmdelim
== '{' && yycol
== 9)
col
= yycol
- (cmdelim
== '{' ? 1 : 2);
cp
= tree5(NIL
, cmdelim
, NIL
, cmjust
, yyseqid
);
* Chain the new comment at "cp" onto the linked list of comments.
register struct comment
*cp
;
cp
->cmnext
= cmhp
->cmnext
;
newcomm(tree5(nilcml
, NIL
, NIL
, t
, yyseqid
));
newcomm(tree5(nilcml
, savestr(cp
), ch
, CINCLUD
, yyseqid
));
register struct commline
*kp
;
kp
= tree3(NIL
, yycol
, NIL
);
if (cmdelim
== '*' && lastc
== '*') {
yerror("Comment does not terminate - QUIT");
kp
->cmtext
= copystr(token
);
* Flush through the line this token is on.
* Ignore if next token on same line as this one.
register int i
, SSeqid
, SCol
;
SSeqid
= Seqid
, SCol
= Col
;
Seqid
= LSeqid
, Col
= 32767;
Seqid
= SSeqid
, Col
= SCol
;
* Flush to the beginning of the line this token is on.
* Ignore if this token is on the same line as the previous one
* (effectively since all such already then flushed.)
register int i
, SSeqid
, SCol
;
SSeqid
= Seqid
, SCol
= Col
;
Seqid
= SSeqid
, Col
= SCol
;
* Put out the comments to the border indicated by Seqid and Col
register struct comment
*cp
;
while (cp
->cmseqid
< Seqid
|| cp
->cmseqid
== Seqid
&& cp
->cml
->cmcol
< Col
) {
* Note that empty lines, form feeds and #include statements
* are treated as comments are regurgitated here.
register struct comment
*cp
;
register struct commline
*cml
, *cmf
;
printf("#include %c%s%c", cp
->cml
, cp
->cmdelim
, cp
->cml
);
ppbra(cp
->cmdelim
== '{' ? "{" : "(*");
for (cml
= cmf
->cml
; cml
!= cmf
; cml
= cml
->cml
) {
oneline(cmf
->cmcol
, cml
);
ppket(cp
->cmdelim
== '{' ? "}" : "*)");
* Do the preliminary horizontal and vertical
* motions necessary before beginning a comment,
* or between lines of a mult-line comment.
register struct comment
*cp
;
* One line of a multi-line comment
* Deal with alignment and initial white space trimming.
* The "margin" indicates where the first line of the
* comment began... don't print stuff in this comment
* which came before this.
for (i
= 8, tp
= cml
->cmtext
; i
< margin
&& *tp
; tp
++)
#define BLANKS ((1 << CNL) | (1 << CNLBL) | (1 << CFORM))
return ((i
& BLANKS
) == 0);
int needform
, neednlbl
, neednl
, needseqid
;
register struct comment
*cp
;
needform
= neednlbl
= neednl
= 0;
neednl
= neednlbl
= needform
= 0;
for (; needform
> 0; needform
--)
for (; neednl
> 0; neednl
--)
for (; neednlbl
> 0; neednlbl
--)