mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-02-06 20:30:15 +00:00
Handle filling of array elements without explicit initializers.
At this point, designated initializers for arrays are at least largely working.
This commit is contained in:
parent
aa6b82a136
commit
58d8edf1ee
47
Parser.pas
47
Parser.pas
@ -2372,11 +2372,14 @@ var
|
|||||||
braces: boolean; {is the initializer inclosed in braces?}
|
braces: boolean; {is the initializer inclosed in braces?}
|
||||||
count,maxCount: longint; {for tracking the size of an initializer}
|
count,maxCount: longint; {for tracking the size of an initializer}
|
||||||
ep: tokenPtr; {for forming string expression}
|
ep: tokenPtr; {for forming string expression}
|
||||||
|
fillSize: longint; {size to fill with zeros}
|
||||||
iPtr: initializerPtr; {for creating an initializer entry}
|
iPtr: initializerPtr; {for creating an initializer entry}
|
||||||
ip: identPtr; {for tracing field lists}
|
ip: identPtr; {for tracing field lists}
|
||||||
kind: typeKind; {base type of an initializer}
|
kind: typeKind; {base type of an initializer}
|
||||||
ktp: typePtr; {array type with definedTypes removed}
|
ktp: typePtr; {array type with definedTypes removed}
|
||||||
lSuppressMacroExpansions: boolean;{local copy of suppressMacroExpansions}
|
lSuppressMacroExpansions: boolean;{local copy of suppressMacroExpansions}
|
||||||
|
maxDisp: longint; {maximum disp value so far}
|
||||||
|
newDisp: longint; {new disp set by a designator}
|
||||||
skipToNext: boolean; {skip to next array/struct element?}
|
skipToNext: boolean; {skip to next array/struct element?}
|
||||||
startingDisp: longint; {disp at start of this term}
|
startingDisp: longint; {disp at start of this term}
|
||||||
stringElementType: typePtr; {element type of string literal}
|
stringElementType: typePtr; {element type of string literal}
|
||||||
@ -2576,27 +2579,40 @@ var
|
|||||||
begin
|
begin
|
||||||
count := 0; {get the expressions|initializers}
|
count := 0; {get the expressions|initializers}
|
||||||
maxCount := tp^.elements;
|
maxCount := tp^.elements;
|
||||||
|
maxDisp := disp;
|
||||||
if token.kind <> rbracech then
|
if token.kind <> rbracech then
|
||||||
repeat
|
repeat
|
||||||
skipToNext := false;
|
skipToNext := false;
|
||||||
if token.kind = lbrackch then begin
|
if token.kind = lbrackch then begin
|
||||||
if not (braces or nestedDesignator) then begin
|
if not (braces or (nestedDesignator and (disp=startingDisp)))
|
||||||
|
then begin
|
||||||
skipComma := true;
|
skipComma := true;
|
||||||
goto 1;
|
goto 1;
|
||||||
end; {if}
|
end; {if}
|
||||||
NextToken;
|
NextToken;
|
||||||
Expression(arrayExpression, [rbrackch]);
|
Expression(arrayExpression, [rbrackch]);
|
||||||
if (expressionValue < 0)
|
if (expressionValue < 0)
|
||||||
or ((maxCount <> 0) and (expressionValue >= maxCount)) then begin
|
or ((maxCount <> 0) and (expressionValue >= maxCount)) then
|
||||||
|
begin
|
||||||
Error(183);
|
Error(183);
|
||||||
count := 0;
|
count := 0;
|
||||||
end {if}
|
end {if}
|
||||||
else begin
|
else begin
|
||||||
count := expressionValue;
|
count := expressionValue;
|
||||||
disp := startingDisp + count * ktp^.size;
|
|
||||||
end; {else}
|
end; {else}
|
||||||
Match(rbrackch, 24);
|
Match(rbrackch, 24);
|
||||||
{TODO if first designator (or expanding array size) and not nestedDesignator then fill in rest with zeros}
|
newDisp := startingDisp + count * ktp^.size;
|
||||||
|
if not nestedDesignator then begin
|
||||||
|
fillSize := newDisp - maxDisp;
|
||||||
|
if token.kind in [lbrackch,dotch] then
|
||||||
|
fillSize := fillSize + ktp^.size;
|
||||||
|
if fillSize > 0 then begin
|
||||||
|
disp := maxDisp;
|
||||||
|
Fill(fillSize, charPtr);
|
||||||
|
maxDisp := disp;
|
||||||
|
end; {if}
|
||||||
|
end; {if}
|
||||||
|
disp := newDisp;
|
||||||
if token.kind in [dotch,lbrackch] then begin
|
if token.kind in [dotch,lbrackch] then begin
|
||||||
InitializeTerm(ktp, 0, 0, false, true);
|
InitializeTerm(ktp, 0, 0, false, true);
|
||||||
skipToNext := true;
|
skipToNext := true;
|
||||||
@ -2606,6 +2622,8 @@ var
|
|||||||
end; {if}
|
end; {if}
|
||||||
if not skipToNext then
|
if not skipToNext then
|
||||||
InitializeTerm(ktp, 0, 0, false, false);
|
InitializeTerm(ktp, 0, 0, false, false);
|
||||||
|
if disp > maxDisp then
|
||||||
|
maxDisp := disp;
|
||||||
count := count+1;
|
count := count+1;
|
||||||
if (count = maxCount) and not braces then
|
if (count = maxCount) and not braces then
|
||||||
done := true
|
done := true
|
||||||
@ -2625,16 +2643,19 @@ var
|
|||||||
else
|
else
|
||||||
done := true;
|
done := true;
|
||||||
until done or (token.kind = eofsy);
|
until done or (token.kind = eofsy);
|
||||||
if maxCount <> 0 then begin
|
if maxCount = 0 then begin {set the array size}
|
||||||
count := maxCount-count;
|
maxCount := (maxDisp - startingDisp + ktp^.size - 1) div ktp^.size;
|
||||||
if count <> 0 then {if there weren't enough initializers...}
|
tp^.elements := maxCount;
|
||||||
if not nestedDesignator then
|
|
||||||
Fill(count,ktp); { fill in the blank spots}
|
|
||||||
end {if}
|
|
||||||
else begin
|
|
||||||
tp^.elements := count; {set the array size}
|
|
||||||
RecomputeSizes(variable^.itype);
|
RecomputeSizes(variable^.itype);
|
||||||
end; {else}
|
end; {if}
|
||||||
|
if not nestedDesignator then begin
|
||||||
|
disp := startingDisp + maxCount * ktp^.size;
|
||||||
|
if disp > maxDisp then begin {if there weren't enough initializers...}
|
||||||
|
fillSize := disp - maxDisp;
|
||||||
|
disp := maxDisp;
|
||||||
|
Fill(fillSize, charPtr); { fill in the blank spots}
|
||||||
|
end; {if}
|
||||||
|
end; {if}
|
||||||
end {else if}
|
end {else if}
|
||||||
|
|
||||||
else begin
|
else begin
|
||||||
|
Loading…
x
Reference in New Issue
Block a user