From 5b953e2db0911f04faab4d4354507affe981c7b4 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 2 Nov 2021 22:17:55 -0500 Subject: [PATCH] Allow 'static' and type qualifiers in parameter array declarators (C99). This has the side effect of treating most parameters declared as arrays as actually having pointer types. This affects the value returned by sizeof, among other things. The new behavior is correct under the C standards; however, it does not yet apply when using a typedef'd array type. --- Parser.pas | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Parser.pas b/Parser.pas index 70ff539..545a15c 100644 --- a/Parser.pas +++ b/Parser.pas @@ -1304,6 +1304,7 @@ var ttPtr: typeDefPtr; {work pointer} parencount: integer; {for skipping in parm list} lvarParmList: boolean; {did we prototype a variable?} + gotStatic: boolean; {got 'static' in array declarator?} {variables used to preserve states} { across recursive calls } @@ -1574,11 +1575,36 @@ var {tPtr2^.qualifiers := [];} tPtr2^.kind := arrayType; {tPtr2^.elements := 0;} + NextToken; + gotStatic := false; + if doingParameters and (typeStack = nil) then begin + tPtr2^.kind := pointerType; {adjust to pointer type} + tPtr2^.size := cgPointerSize; + if token.kind = staticsy then begin + gotStatic := true; + NextToken; + end; {if} + while token.kind in [constsy,volatilesy,restrictsy] do begin + if token.kind = constsy then + tPtr2^.qualifiers := tPtr2^.qualifiers + [tqConst] + else if token.kind = volatilesy then begin + tPtr2^.qualifiers := tPtr2^.qualifiers + [tqVolatile]; + volatile := true; + end {else} + else {if token.kind = restrictsy then} + tPtr2^.qualifiers := tPtr2^.qualifiers + [tqRestrict]; + NextToken; + end; {while} + if not gotStatic then + if token.kind = staticsy then begin + gotStatic := true; + NextToken; + end; {if} + end; {if} new(ttPtr); ttPtr^.next := typeStack; typeStack := ttPtr; ttPtr^.typeDef := tPtr2; - NextToken; if token.kind <> rbrackch then begin Expression(arrayExpression, [rbrackch,semicolonch]); if expressionValue <= 0 then begin @@ -1586,7 +1612,9 @@ var expressionValue := 1; end; {if} tPtr2^.elements := expressionValue; - end; {if} + end {if} + else if gotStatic then + Error(35); Match(rbrackch,24); end; {else if} end; {while}