mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-06-18 11:29:30 +00:00
Fill logic for when to fill uninitialized data with zeros.
This could maybe be simplified to just fill on levels with braces, but I want to consider that after implementing designated initializers for structs and unions.
This commit is contained in:
parent
6260a27b11
commit
def9e56e8e
20
Parser.pas
20
Parser.pas
|
@ -2353,7 +2353,7 @@ var
|
||||||
|
|
||||||
|
|
||||||
procedure InitializeTerm (tp: typePtr; bitsize,bitdisp: integer;
|
procedure InitializeTerm (tp: typePtr; bitsize,bitdisp: integer;
|
||||||
main, nestedDesignator: boolean);
|
main, nestedDesignator, noFill: boolean);
|
||||||
|
|
||||||
{ initialize one level of the type }
|
{ initialize one level of the type }
|
||||||
{ }
|
{ }
|
||||||
|
@ -2364,6 +2364,7 @@ var
|
||||||
{ main - is this a call from the main level? }
|
{ main - is this a call from the main level? }
|
||||||
{ nestedDesignator - handling second or later level of }
|
{ nestedDesignator - handling second or later level of }
|
||||||
{ designator in a designator list? }
|
{ designator in a designator list? }
|
||||||
|
{ noFill - if set, do not fill empty space with zeros }
|
||||||
|
|
||||||
label 1;
|
label 1;
|
||||||
|
|
||||||
|
@ -2380,6 +2381,7 @@ var
|
||||||
lSuppressMacroExpansions: boolean;{local copy of suppressMacroExpansions}
|
lSuppressMacroExpansions: boolean;{local copy of suppressMacroExpansions}
|
||||||
maxDisp: longint; {maximum disp value so far}
|
maxDisp: longint; {maximum disp value so far}
|
||||||
newDisp: longint; {new disp set by a designator}
|
newDisp: longint; {new disp set by a designator}
|
||||||
|
setNoFill: boolean; {set noFill on recursive calls?}
|
||||||
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}
|
||||||
|
@ -2499,6 +2501,7 @@ var
|
||||||
if token.kind = lbracech then begin
|
if token.kind = lbracech then begin
|
||||||
NextToken;
|
NextToken;
|
||||||
braces := true;
|
braces := true;
|
||||||
|
noFill := false;
|
||||||
end; {if}
|
end; {if}
|
||||||
|
|
||||||
{handle arrays}
|
{handle arrays}
|
||||||
|
@ -2514,6 +2517,7 @@ var
|
||||||
goto 1;
|
goto 1;
|
||||||
end; {if}
|
end; {if}
|
||||||
startingDisp := disp;
|
startingDisp := disp;
|
||||||
|
setNoFill := noFill;
|
||||||
if kind = arrayType then begin
|
if kind = arrayType then begin
|
||||||
ktp := tp^.atype;
|
ktp := tp^.atype;
|
||||||
while ktp^.kind = definedType do
|
while ktp^.kind = definedType do
|
||||||
|
@ -2602,7 +2606,7 @@ var
|
||||||
end; {else}
|
end; {else}
|
||||||
Match(rbrackch, 24);
|
Match(rbrackch, 24);
|
||||||
newDisp := startingDisp + count * ktp^.size;
|
newDisp := startingDisp + count * ktp^.size;
|
||||||
if not nestedDesignator then begin
|
if not noFill then begin
|
||||||
fillSize := newDisp - maxDisp;
|
fillSize := newDisp - maxDisp;
|
||||||
if token.kind in [lbrackch,dotch] then
|
if token.kind in [lbrackch,dotch] then
|
||||||
fillSize := fillSize + ktp^.size;
|
fillSize := fillSize + ktp^.size;
|
||||||
|
@ -2612,16 +2616,17 @@ var
|
||||||
maxDisp := disp;
|
maxDisp := disp;
|
||||||
end; {if}
|
end; {if}
|
||||||
end; {if}
|
end; {if}
|
||||||
|
setNoFill := true;
|
||||||
disp := newDisp;
|
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, true);
|
||||||
skipToNext := true;
|
skipToNext := true;
|
||||||
end {if}
|
end {if}
|
||||||
else
|
else
|
||||||
Match(eqch, 182);
|
Match(eqch, 182);
|
||||||
end; {if}
|
end; {if}
|
||||||
if not skipToNext then
|
if not skipToNext then
|
||||||
InitializeTerm(ktp, 0, 0, false, false);
|
InitializeTerm(ktp, 0, 0, false, false, setNoFill);
|
||||||
if disp > maxDisp then
|
if disp > maxDisp then
|
||||||
maxDisp := disp;
|
maxDisp := disp;
|
||||||
count := count+1;
|
count := count+1;
|
||||||
|
@ -2648,7 +2653,7 @@ var
|
||||||
tp^.elements := maxCount;
|
tp^.elements := maxCount;
|
||||||
RecomputeSizes(variable^.itype);
|
RecomputeSizes(variable^.itype);
|
||||||
end; {if}
|
end; {if}
|
||||||
if not nestedDesignator then begin
|
if not noFill then begin
|
||||||
disp := startingDisp + maxCount * ktp^.size;
|
disp := startingDisp + maxCount * ktp^.size;
|
||||||
if disp > maxDisp then begin {if there weren't enough initializers...}
|
if disp > maxDisp then begin {if there weren't enough initializers...}
|
||||||
fillSize := disp - maxDisp;
|
fillSize := disp - maxDisp;
|
||||||
|
@ -2693,7 +2698,8 @@ var
|
||||||
bitCount := 0;
|
bitCount := 0;
|
||||||
disp := startingDisp + tp^.size - count;
|
disp := startingDisp + tp^.size - count;
|
||||||
end; {if}
|
end; {if}
|
||||||
InitializeTerm(ip^.itype, ip^.bitsize, ip^.bitdisp, false, false);
|
InitializeTerm(ip^.itype, ip^.bitsize, ip^.bitdisp, false, false,
|
||||||
|
setNoFill);
|
||||||
if ip^.bitSize <> 0 then begin
|
if ip^.bitSize <> 0 then begin
|
||||||
bitCount := bitCount + ip^.bitSize;
|
bitCount := bitCount + ip^.bitSize;
|
||||||
if bitCount > maxBitField then begin
|
if bitCount > maxBitField then begin
|
||||||
|
@ -2775,7 +2781,7 @@ if not (token.kind in [lbracech,stringConst]) then
|
||||||
Error(27);
|
Error(27);
|
||||||
errorFound := true;
|
errorFound := true;
|
||||||
end; {if}
|
end; {if}
|
||||||
InitializeTerm(variable^.itype, 0, 0, true, false); {do the initialization}
|
InitializeTerm(variable^.itype, 0, 0, true, false, false); {do the initialization}
|
||||||
variable^.state := initialized; {mark the variable as initialized}
|
variable^.state := initialized; {mark the variable as initialized}
|
||||||
iPtr := variable^.iPtr; {reverse the initializer list}
|
iPtr := variable^.iPtr; {reverse the initializer list}
|
||||||
jPtr := nil;
|
jPtr := nil;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user