Rework handling of scopes created for function declarators.

This is preparatory to other changes.
This commit is contained in:
Stephen Heumann 2022-11-05 21:13:44 -05:00
parent 986a283540
commit d3ba8b5551

View File

@ -1285,6 +1285,7 @@ var
i: integer; {loop variable} i: integer; {loop variable}
lastWasIdentifier: boolean; {for deciding if the declarator is a function} lastWasIdentifier: boolean; {for deciding if the declarator is a function}
lastWasPointer: boolean; {was the last type a pointer?} lastWasPointer: boolean; {was the last type a pointer?}
madeFunctionTable: boolean; {made symbol table for function type?}
newName: stringPtr; {new symbol name} newName: stringPtr; {new symbol name}
parameterStorage: boolean; {is the new symbol in a parm list?} parameterStorage: boolean; {is the new symbol in a parm list?}
state: stateKind; {declaration state of the variable} state: stateKind; {declaration state of the variable}
@ -1292,7 +1293,7 @@ var
tPtr2: typePtr; {work pointer} tPtr2: typePtr; {work pointer}
tsPtr: typeDefPtr; {work pointer} tsPtr: typeDefPtr; {work pointer}
typeStack: typeDefPtr; {stack of type definitions} typeStack: typeDefPtr; {stack of type definitions}
firstIteration: boolean; {first iteration of type-unstacking loop?} lTable: symbolTablePtr; {saved copy of table}
{for checking function compatibility} {for checking function compatibility}
{-----------------------------------} {-----------------------------------}
@ -1571,6 +1572,10 @@ var
if not tPtr2^.prototyped then if not tPtr2^.prototyped then
Error(105); Error(105);
Match(rparench,12); {insist on a closing ')' token} Match(rparench,12); {insist on a closing ')' token}
if madeFunctionTable or not lastWasIdentifier then
PopTable
else
madeFunctionTable := true;
end {if} end {if}
{handle array declarations} {handle array declarations}
@ -1651,11 +1656,11 @@ if declSpecifiers.storageClass = externsy then {decide on a storage state}
state := declared state := declared
else else
state := defined; state := defined;
madeFunctionTable := false; {no symbol table for function}
typeStack := nil; {no types so far} typeStack := nil; {no types so far}
parameterStorage := false; {symbol is not in a parameter list} parameterStorage := false; {symbol is not in a parameter list}
checkParms := false; {assume we won't need to check for parameter type errors} checkParms := false; {assume we won't need to check for parameter type errors}
StackDeclarations; {stack the type records} StackDeclarations; {stack the type records}
firstIteration := true;
while typeStack <> nil do begin {reverse the type stack} while typeStack <> nil do begin {reverse the type stack}
tsPtr := typeStack; tsPtr := typeStack;
typeStack := tsPtr^.next; typeStack := tsPtr^.next;
@ -1667,9 +1672,6 @@ while typeStack <> nil do begin {reverse the type stack}
else else
tPtr2 := tsPtr^.typeDef; tPtr2 := tsPtr^.typeDef;
dispose(tsPtr); dispose(tsPtr);
if tPtr^.kind = functionType then
if not firstIteration then
PopTable; {balance push in StackDeclarations}
case tPtr2^.kind of case tPtr2^.kind of
pointerType: begin pointerType: begin
tPtr2^.pType := tPtr; tPtr2^.pType := tPtr;
@ -1688,7 +1690,6 @@ while typeStack <> nil do begin {reverse the type stack}
otherwise: ; otherwise: ;
end; {case} end; {case}
tPtr := tPtr2; tPtr := tPtr2;
firstIteration := false;
end; {while} end; {while}
if doingParameters then {adjust array parameters to pointers} if doingParameters then {adjust array parameters to pointers}
@ -1813,6 +1814,10 @@ if tPtr^.kind = functionType then begin {declare the identifier}
end; {if} end; {if}
if tPtr^.kind = functionType then if tPtr^.kind = functionType then
state := declared; state := declared;
if madeFunctionTable then begin
lTable := table;
table := table^.next;
end; {if}
if newName <> nil then {declare the variable} if newName <> nil then {declare the variable}
variable := NewSymbol(newName, tPtr, declSpecifiers.storageClass, space, state) variable := NewSymbol(newName, tPtr, declSpecifiers.storageClass, space, state)
else if unnamedParm then else if unnamedParm then
@ -1822,6 +1827,8 @@ else begin
Error(9); Error(9);
variable := nil; variable := nil;
end; {else} end; {else}
if madeFunctionTable then
table := lTable;
if variable <> nil then begin if variable <> nil then begin
if parameterStorage then if parameterStorage then
variable^.storage := parameter; variable^.storage := parameter;