mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-01-04 17:31:49 +00:00
Add flag to suppress printing of put-back tokens with #pragma expand.
This is currently used in a couple places in the designated initializer code (solving the problem with #pragma expand in the last commit). It could probably be used elsewhere too, but for now it is not.
This commit is contained in:
parent
39250629bd
commit
dc305a86b2
38
Parser.pas
38
Parser.pas
@ -988,7 +988,7 @@ case token.kind of
|
||||
lToken := token;
|
||||
NextToken;
|
||||
tToken := token;
|
||||
PutBackToken(token, true);
|
||||
PutBackToken(token, true, false);
|
||||
token := lToken;
|
||||
suppressMacroExpansions := lSuppressMacroExpansions;
|
||||
if tToken.kind = colonch then begin
|
||||
@ -1110,12 +1110,12 @@ Gen1(dc_lab, stPtr^.continueLab); {define the continue label}
|
||||
|
||||
tl := stPtr^.e3List; {place the expression back in the list}
|
||||
if tl <> nil then begin
|
||||
PutBackToken(token, false);
|
||||
PutBackToken(token, false, false);
|
||||
ltoken.kind := semicolonch;
|
||||
ltoken.class := reservedSymbol;
|
||||
PutBackToken(ltoken, false);
|
||||
PutBackToken(ltoken, false, false);
|
||||
while tl <> nil do begin
|
||||
PutBackToken(tl^.token, false);
|
||||
PutBackToken(tl^.token, false, false);
|
||||
tk := tl;
|
||||
tl := tl^.next;
|
||||
dispose(tk);
|
||||
@ -1463,12 +1463,12 @@ var
|
||||
NextToken;
|
||||
suppressMacroExpansions := lSuppressMacroExpansions;
|
||||
if token.kind = rparench then begin
|
||||
PutBackToken(token, false);
|
||||
PutBackToken(token, false, false);
|
||||
NextToken;
|
||||
tPtr2^.prototyped := true;
|
||||
end
|
||||
else begin
|
||||
PutBackToken(token, false);
|
||||
PutBackToken(token, false, false);
|
||||
token.kind := voidsy;
|
||||
token.class := reservedSymbol;
|
||||
end; {else}
|
||||
@ -1861,7 +1861,6 @@ var
|
||||
iPtr,jPtr,kPtr: initializerPtr; {for reversing the list}
|
||||
ip: identList; {used to place an id in the list}
|
||||
luseGlobalPool: boolean; {local copy of useGlobalPool}
|
||||
skipComma: boolean; {skip an expected comma}
|
||||
|
||||
|
||||
procedure InsertInitializerRecord (iPtr: initializerPtr; size: longint);
|
||||
@ -2442,11 +2441,8 @@ var
|
||||
{check for designators that need to}
|
||||
{be handled at an outer level }
|
||||
if token.kind in [dotch,lbrackch] then
|
||||
if not (braces or nestedDesignator) then begin
|
||||
{TODO fill?}
|
||||
skipComma := true;
|
||||
if not (braces or nestedDesignator) then
|
||||
goto 1;
|
||||
end; {if}
|
||||
startingDisp := disp;
|
||||
setNoFill := noFill;
|
||||
if kind = arrayType then begin
|
||||
@ -2521,7 +2517,9 @@ var
|
||||
if token.kind in [lbrackch,dotch] then begin
|
||||
if not (braces or (nestedDesignator and (disp=startingDisp)))
|
||||
then begin
|
||||
skipComma := true;
|
||||
PutBackToken(token, false, true);
|
||||
token.kind := commach;
|
||||
token.class := reservedSymbol;
|
||||
goto 1;
|
||||
end; {if}
|
||||
Match(lbrackch, 35);
|
||||
@ -2561,11 +2559,8 @@ var
|
||||
count := count+1;
|
||||
if (count = maxCount) and not braces then
|
||||
done := true
|
||||
else if (token.kind = commach) or skipComma then begin
|
||||
if skipComma then
|
||||
skipComma := false
|
||||
else
|
||||
NextToken;
|
||||
else if (token.kind = commach) then begin
|
||||
NextToken;
|
||||
done := token.kind = rbracech;
|
||||
if not done then
|
||||
if count = maxCount then
|
||||
@ -2613,7 +2608,9 @@ var
|
||||
if token.kind in [dotch,lbrackch] then begin
|
||||
if not (braces or (nestedDesignator and (disp=startingDisp)))
|
||||
then begin
|
||||
skipComma := true;
|
||||
PutBackToken(token, false, true);
|
||||
token.kind := commach;
|
||||
token.class := reservedSymbol;
|
||||
goto 1;
|
||||
end; {if}
|
||||
Match(dotch, 35);
|
||||
@ -2628,7 +2625,7 @@ var
|
||||
if ip = nil then
|
||||
Error(81);
|
||||
if ip^.anonMemberField then begin
|
||||
PutBackToken(token, false);
|
||||
PutBackToken(token, false, true);
|
||||
token.kind := dotch;
|
||||
token.class := reservedSymbol;
|
||||
token.isDigraph := false;
|
||||
@ -2735,7 +2732,6 @@ var
|
||||
begin {Initializer}
|
||||
disp := 0; {start at beginning of the object}
|
||||
errorFound := false; {no errors found so far}
|
||||
skipComma := false;
|
||||
luseGlobalPool := useGlobalPool; {use global memory for global vars}
|
||||
useGlobalPool := (variable^.storage in [external,global,private])
|
||||
or useGlobalPool;
|
||||
@ -4357,7 +4353,7 @@ case statementList^.kind of
|
||||
NextToken;
|
||||
suppressMacroExpansions := lSuppressMacroExpansions;
|
||||
nToken := token;
|
||||
PutBackToken(nToken, false);
|
||||
PutBackToken(nToken, false, false);
|
||||
token := lToken;
|
||||
if nToken.kind <> colonch then
|
||||
DoDeclaration(false)
|
||||
|
40
Scanner.pas
40
Scanner.pas
@ -49,6 +49,7 @@ type
|
||||
next: tokenListRecordPtr; {next element in list}
|
||||
token: tokenType; {token}
|
||||
expandEnabled: boolean; {can this token be macro expanded?}
|
||||
suppressPrint: boolean; {suppress printing with #pragma expand?}
|
||||
tokenStart,tokenEnd: ptr; {token start/end markers}
|
||||
end;
|
||||
macroRecordPtr = ^macroRecord;
|
||||
@ -153,13 +154,15 @@ procedure NextToken;
|
||||
{ Read the next token from the file. }
|
||||
|
||||
|
||||
procedure PutBackToken (var token: tokenType; expandEnabled: boolean);
|
||||
procedure PutBackToken (var token: tokenType; expandEnabled: boolean;
|
||||
suppressPrint: boolean);
|
||||
|
||||
{ place a token into the token stream }
|
||||
{ }
|
||||
{ parameters: }
|
||||
{ token - token to put back into the token stream }
|
||||
{ expandEnabled - can macro expansion be performed? }
|
||||
{ suppressPrint - suppress printing with #pragma expand? }
|
||||
|
||||
|
||||
procedure TermScanner;
|
||||
@ -510,13 +513,15 @@ macroFound := mPtr;
|
||||
end; {IsDefined}
|
||||
|
||||
|
||||
procedure PutBackToken {var token: tokenType; expandEnabled: boolean};
|
||||
procedure PutBackToken {var token: tokenType; expandEnabled: boolean;
|
||||
suppressPrint: boolean};
|
||||
|
||||
{ place a token into the token stream }
|
||||
{ }
|
||||
{ parameters: }
|
||||
{ token - token to put back into the token stream }
|
||||
{ expandEnabled - can macro expansion be performed? }
|
||||
{ suppressPrint - suppress printing with #pragma expand? }
|
||||
|
||||
var
|
||||
tPtr: tokenListRecordPtr; {work pointer}
|
||||
@ -527,6 +532,7 @@ tPtr^.next := tokenList;
|
||||
tokenList := tPtr;
|
||||
tPtr^.token := token;
|
||||
tPtr^.expandEnabled := expandEnabled;
|
||||
tPtr^.suppressPrint := suppressPrint;
|
||||
tPtr^.tokenStart := tokenStart;
|
||||
tPtr^.tokenEnd := tokenEnd;
|
||||
end; {PutBackToken}
|
||||
@ -1628,7 +1634,7 @@ else
|
||||
end; {for}
|
||||
token.sval^.str[len+1] := chr(0);
|
||||
token.sval^.length := len+1;
|
||||
PutBackToken(token, true);
|
||||
PutBackToken(token, true, false);
|
||||
end; {BuildStringToken}
|
||||
|
||||
|
||||
@ -1917,7 +1923,7 @@ if macro^.parameters >= 0 then begin {find the values of the parameters}
|
||||
Error(14);
|
||||
if token.kind <> rparench then begin {insist on a closing ')'}
|
||||
if not gettingFileName then {put back the source stream token}
|
||||
PutBackToken(token, true);
|
||||
PutBackToken(token, true, false);
|
||||
Error(12);
|
||||
end; {if}
|
||||
preprocessing := lPreprocessing;
|
||||
@ -1925,7 +1931,7 @@ if macro^.parameters >= 0 then begin {find the values of the parameters}
|
||||
else begin
|
||||
Error(13);
|
||||
if not gettingFileName then {put back the source stream token}
|
||||
PutBackToken(token, true);
|
||||
PutBackToken(token, true, false);
|
||||
end; {else}
|
||||
end; {if}
|
||||
if macro^.readOnly then begin {handle special macros}
|
||||
@ -2040,7 +2046,7 @@ if macro^.readOnly then begin {handle special macros}
|
||||
|
||||
end; {case}
|
||||
if macro^.algorithm <> 8 then {if not _Pragma}
|
||||
PutBackToken(token, true);
|
||||
PutBackToken(token, true, false);
|
||||
end {if}
|
||||
else begin
|
||||
|
||||
@ -2128,11 +2134,11 @@ else begin
|
||||
if expandEnabled then
|
||||
if tcPtr^.token.name^ = macro^.name^ then
|
||||
expandEnabled := false;
|
||||
PutBackToken(tcPtr^.token, expandEnabled);
|
||||
PutBackToken(tcPtr^.token, expandEnabled, false);
|
||||
end; {else}
|
||||
end {if}
|
||||
else
|
||||
PutBackToken(tcPtr^.token, true);
|
||||
PutBackToken(tcPtr^.token, true, false);
|
||||
tcPtr := tcPtr^.next;
|
||||
end; {while}
|
||||
end; {else}
|
||||
@ -2147,7 +2153,7 @@ else begin
|
||||
expandEnabled := false;
|
||||
tokenStart := tlPtr^.tokenStart;
|
||||
tokenEnd := tlPtr^.tokenEnd;
|
||||
PutBackToken(tlPtr^.token, expandEnabled);
|
||||
PutBackToken(tlPtr^.token, expandEnabled, false);
|
||||
end; {else}
|
||||
lastPtr := tlPtr;
|
||||
tlPtr := tlPtr^.next;
|
||||
@ -3438,7 +3444,7 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin
|
||||
end; {if}
|
||||
if token.name^ <> 'STDC' then begin
|
||||
{Allow macro expansion, other than for STDC }
|
||||
PutBackToken(token, true);
|
||||
PutBackToken(token, true, false);
|
||||
NextToken;
|
||||
end; {if}
|
||||
if token.name^ = 'keep' then
|
||||
@ -4903,6 +4909,7 @@ var
|
||||
tPtr: tokenListRecordPtr; {for removing tokens from putback buffer}
|
||||
tToken: tokenType; {for merging tokens}
|
||||
sPtr,tsPtr: gstringPtr; {for forming string constants}
|
||||
suppressPrint: boolean; {suppress printing the token?}
|
||||
lLastWasReturn: boolean; {local copy of lastWasReturn}
|
||||
codePoint: longint; {Unicode character value}
|
||||
chFromUCN: integer; {character given by UCN (converted)}
|
||||
@ -5166,6 +5173,7 @@ if tokenList <> nil then begin {get a token put back by a macro}
|
||||
tokenList := tPtr^.next;
|
||||
expandEnabled := tPtr^.expandEnabled;
|
||||
tokenExpandEnabled := expandEnabled;
|
||||
suppressPrint := tPtr^.suppressPrint;
|
||||
token := tPtr^.token;
|
||||
tokenStart := tPtr^.tokenStart;
|
||||
tokenEnd := tPtr^.tokenEnd;
|
||||
@ -5226,7 +5234,9 @@ if tokenList <> nil then begin {get a token put back by a macro}
|
||||
expandMacros := lExpandMacros;
|
||||
end; {if}
|
||||
goto 2;
|
||||
end; {if}
|
||||
end {if}
|
||||
else
|
||||
suppressPrint := false;
|
||||
5: {skip white space}
|
||||
while charKinds[ord(ch)] in [illegal,ch_white,ch_eol,ch_pound] do begin
|
||||
if charKinds[ord(ch)] = ch_pound then begin
|
||||
@ -5740,7 +5750,7 @@ if (token.kind = stringconst) and not mergingStrings {handle adjacent strings}
|
||||
done := false;
|
||||
end {if}
|
||||
else begin
|
||||
PutBackToken(token, tokenExpandEnabled);
|
||||
PutBackToken(token, tokenExpandEnabled, false);
|
||||
done := true;
|
||||
end; {else}
|
||||
token := tToken;
|
||||
@ -5755,8 +5765,10 @@ if doingPPExpression then begin
|
||||
if token.kind = typedef then
|
||||
token.kind := ident;
|
||||
end; {if}
|
||||
if printMacroExpansions and not suppressMacroExpansions then
|
||||
PrintToken(token); {print the token stream}
|
||||
if printMacroExpansions then
|
||||
if not suppressMacroExpansions then
|
||||
if not suppressPrint then
|
||||
PrintToken(token); {print the token stream}
|
||||
if token.kind = otherch then
|
||||
if not (skipping or preprocessing or suppressMacroExpansions)
|
||||
or doingPPExpression then
|
||||
|
Loading…
Reference in New Issue
Block a user