Simplify some declaration-processing logic.

This should not cause any functional change.
This commit is contained in:
Stephen Heumann 2022-11-01 18:43:44 -05:00
parent 9a7dc23c5d
commit 7d6b732d23

View File

@ -189,7 +189,6 @@ var
{ referencing a forward struct/union? } { referencing a forward struct/union? }
isFunction: boolean; {is the declaration a function?} isFunction: boolean; {is the declaration a function?}
returnLabel: integer; {label for exit point} returnLabel: integer; {label for exit point}
skipDeclarator: boolean; {for enum,struct,union with no declarator}
statementList: statementPtr; {list of open statements} statementList: statementPtr; {list of open statements}
savedVolatile: boolean; {saved copy of volatile} savedVolatile: boolean; {saved copy of volatile}
doingForLoopClause1: boolean; {doing the first clause of a for loop?} doingForLoopClause1: boolean; {doing the first clause of a for loop?}
@ -2760,8 +2759,6 @@ procedure DeclarationSpecifiers (var declSpecifiers: declSpecifiersRecord;
{ outputs: } { outputs: }
{ isForwardDeclared - is the field list component } { isForwardDeclared - is the field list component }
{ referencing a forward struct/union? } { referencing a forward struct/union? }
{ skipDeclarator - for enum,struct,union with no }
{ declarator }
{ declaredTagOrEnumConst - set if a tag or an enum const } { declaredTagOrEnumConst - set if a tag or an enum const }
{ is declared (otherwise unchanged) } { is declared (otherwise unchanged) }
@ -2787,7 +2784,6 @@ var
typeQualifiers: typeQualifierSet; {set of type qualifiers found} typeQualifiers: typeQualifierSet; {set of type qualifiers found}
myIsForwardDeclared: boolean; {value of isForwardDeclared to generate} myIsForwardDeclared: boolean; {value of isForwardDeclared to generate}
mySkipDeclarator: boolean; {value of skipDeclarator to generate}
myTypeSpec: typePtr; {value of typeSpec to generate} myTypeSpec: typePtr; {value of typeSpec to generate}
myDeclarationModifiers: tokenSet; {all modifiers in this declaration} myDeclarationModifiers: tokenSet; {all modifiers in this declaration}
myStorageClass: tokenEnum; {storage class} myStorageClass: tokenEnum; {storage class}
@ -3095,7 +3091,6 @@ var
begin {DeclarationSpecifiers} begin {DeclarationSpecifiers}
myTypeSpec := nil; myTypeSpec := nil;
myIsForwardDeclared := false; {not doing a forward reference (yet)} myIsForwardDeclared := false; {not doing a forward reference (yet)}
mySkipDeclarator := false; {declarations are required (so far)}
myDeclarationModifiers := []; myDeclarationModifiers := [];
myStorageClass := ident; myStorageClass := ident;
typeQualifiers := []; typeQualifiers := [];
@ -3308,8 +3303,7 @@ while token.kind in allowedTokens do begin
SkipStatement; SkipStatement;
end; {else} end; {else}
end; {if} end; {if}
1: mySkipDeclarator := token.kind = semicolonch; 1: myTypeSpec := intPtr;
myTypeSpec := intPtr;
typeDone := true; typeDone := true;
end; end;
@ -3412,7 +3406,6 @@ while token.kind in allowedTokens do begin
if globalStruct then if globalStruct then
useGlobalPool := lUseGlobalPool; useGlobalPool := lUseGlobalPool;
myTypeSpec := structTypePtr; myTypeSpec := structTypePtr;
mySkipDeclarator := token.kind = semicolonch;
if tKind = structType then if tKind = structType then
myDeclarationModifiers := myDeclarationModifiers + [structsy] myDeclarationModifiers := myDeclarationModifiers + [structsy]
else else
@ -3461,7 +3454,6 @@ while token.kind in allowedTokens do begin
end; {while} end; {while}
3: 3:
isForwardDeclared := myIsForwardDeclared; isForwardDeclared := myIsForwardDeclared;
skipDeclarator := mySkipDeclarator;
declSpecifiers.declarationModifiers := myDeclarationModifiers; declSpecifiers.declarationModifiers := myDeclarationModifiers;
if _Thread_localsy in myDeclarationModifiers then if _Thread_localsy in myDeclarationModifiers then
if myStorageClass = ident then if myStorageClass = ident then
@ -3490,7 +3482,6 @@ procedure DoDeclaration {doingPrototypes: boolean};
label 1,2,3,4; label 1,2,3,4;
var var
done: boolean; {for loop termination}
fName: stringPtr; {for forming uppercase names} fName: stringPtr; {for forming uppercase names}
i: integer; {loop variable} i: integer; {loop variable}
isAsm: boolean; {has the asm modifier been used?} isAsm: boolean; {has the asm modifier been used?}
@ -3734,19 +3725,17 @@ if token.kind = semicolonch then
if not doingPrototypes then if not doingPrototypes then
if not declaredTagOrEnumConst then if not declaredTagOrEnumConst then
Error(176); Error(176);
if not skipDeclarator then begin variable := nil;
variable := nil; Declarator(declSpecifiers, variable, variableSpace, doingPrototypes);
Declarator(declSpecifiers, variable, variableSpace, doingPrototypes); if variable = nil then begin
if variable = nil then begin inhibitHeader := false;
inhibitHeader := false; if token.kind = semicolonch then
if token.kind = semicolonch then NextToken
NextToken else begin
else begin Error(22);
Error(22); SkipStatement;
SkipStatement; end; {else}
end; {else} goto 1;
goto 1;
end; {if}
end; {if} end; {if}
{make sure variables have some type info} {make sure variables have some type info}
@ -4052,61 +4041,55 @@ else {if not isFunction then} begin
if alignmentSpecified then if alignmentSpecified then
if declSpecifiers.storageClass in [typedefsy,registersy] then if declSpecifiers.storageClass in [typedefsy,registersy] then
Error(142); Error(142);
if not SkipDeclarator then if isPascal then
repeat variable^.itype := MakePascalType(variable^.itype);
if isPascal then if isInline then
variable^.itype := MakePascalType(variable^.itype); Error(119);
if isInline then if isNoreturn then
Error(119); Error(141);
if isNoreturn then if token.kind = eqch then begin
Error(141); if declSpecifiers.storageClass = typedefsy then
if token.kind = eqch then begin Error(52);
if declSpecifiers.storageClass = typedefsy then if doingPrototypes then
Error(52); Error(88);
if doingPrototypes then
Error(88);
{allocate copy of incomplete array type,} {allocate copy of incomplete array type,}
tp := variable^.itype; {so it can be completed by Initializer} tp := variable^.itype; {so it can be completed by Initializer}
if (tp^.kind = arrayType) and (tp^.elements = 0) then begin if (tp^.kind = arrayType) and (tp^.elements = 0) then begin
variable^.itype := pointer(Malloc(sizeof(typeRecord))); variable^.itype := pointer(Malloc(sizeof(typeRecord)));
variable^.itype^ := tp^; variable^.itype^ := tp^;
variable^.itype^.saveDisp := 0; variable^.itype^.saveDisp := 0;
end; end;
TermHeader; {make sure the header file is closed} TermHeader; {make sure the header file is closed}
NextToken; {handle an initializer} NextToken; {handle an initializer}
Initializer(variable); Initializer(variable);
end; {if} end; {if}
{check to insure array sizes are specified} {check to insure array sizes are specified}
if declSpecifiers.storageClass <> typedefsy then if declSpecifiers.storageClass <> typedefsy then
CheckArray(variable, CheckArray(variable,
(declSpecifiers.storageClass = externsy) (declSpecifiers.storageClass = externsy)
or doingParameters or not doingFunction); or doingParameters or not doingFunction);
{allocate space} {allocate space}
if variable^.storage = stackFrame then begin if variable^.storage = stackFrame then begin
variable^.lln := GetLocalLabel; variable^.lln := GetLocalLabel;
Gen2(dc_loc, variable^.lln, long(variable^.itype^.size).lsw); Gen2(dc_loc, variable^.lln, long(variable^.itype^.size).lsw);
if variable^.state = initialized then if variable^.state = initialized then
AutoInit(variable, startLine, false); {initialize auto variable} AutoInit(variable, startLine, false); {initialize auto variable}
end; {if} end; {if}
if (token.kind = commach) and (not doingPrototypes) then begin if (token.kind = commach) and (not doingPrototypes) then begin
done := false; {allow multiple variables on one line} NextToken; {allow multiple variables on one line}
NextToken; variable := nil;
variable := nil; Declarator(declSpecifiers, variable, variableSpace, doingPrototypes);
Declarator(declSpecifiers, variable, variableSpace, doingPrototypes); if variable = nil then begin
if variable = nil then begin if token.kind = semicolonch then
if token.kind = semicolonch then NextToken
NextToken else begin
else begin Error(22);
Error(22); SkipStatement;
SkipStatement; end; {else}
end; {else} goto 1;
goto 1; end; {if}
end; {if} goto 3;
goto 3; end; {if}
end {if}
else
done := true;
until done or (token.kind = eofsy);
if doingPrototypes then begin if doingPrototypes then begin
protoVariable := variable; {make the var available to Declarator} protoVariable := variable; {make the var available to Declarator}
if protoVariable = nil then if protoVariable = nil then