mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-06-14 02:29:28 +00:00
Allow string constants in initializers for arrays of char*.
For example, declarations like the following should be accepted:
char *p[] = {"abc", "def"};
This previously worked, but it was broken by commit 5871820e0c
.
This commit is contained in:
parent
c1b2a88a84
commit
7ac3fe6424
100
Parser.pas
100
Parser.pas
|
@ -2491,64 +2491,58 @@ var
|
||||||
kind := ktp^.kind;
|
kind := ktp^.kind;
|
||||||
|
|
||||||
{handle string constants}
|
{handle string constants}
|
||||||
if token.kind = stringConst then begin
|
if token.kind = stringConst then
|
||||||
stringElementType := StringType(token.prefix)^.aType;
|
stringElementType := StringType(token.prefix)^.aType;
|
||||||
if (kind = scalarType) and
|
if (token.kind = stringConst) and (kind = scalarType) and
|
||||||
(((ktp^.baseType in [cgByte,cgUByte])
|
(((ktp^.baseType in [cgByte,cgUByte])
|
||||||
and (stringElementType = charPtr))
|
and (stringElementType = charPtr))
|
||||||
or CompTypes(ktp,stringElementType)) then begin
|
or CompTypes(ktp,stringElementType)) then begin
|
||||||
stringLength := token.sval^.length div ord(stringElementType^.size);
|
stringLength := token.sval^.length div ord(stringElementType^.size);
|
||||||
if tp^.elements = 0 then begin
|
if tp^.elements = 0 then begin
|
||||||
tp^.elements := stringLength;
|
tp^.elements := stringLength;
|
||||||
RecomputeSizes(variable^.itype);
|
RecomputeSizes(variable^.itype);
|
||||||
end {if}
|
|
||||||
else if tp^.elements < stringLength-1 then begin
|
|
||||||
Error(44);
|
|
||||||
errorFound := true;
|
|
||||||
end; {else if}
|
|
||||||
with ktp^ do begin
|
|
||||||
iPtr := pointer(Malloc(sizeof(initializerRecord)));
|
|
||||||
iPtr^.next := variable^.iPtr;
|
|
||||||
variable^.iPtr := iPtr;
|
|
||||||
iPtr^.count := 1;
|
|
||||||
iPtr^.bitdisp := 0;
|
|
||||||
iPtr^.bitsize := 0;
|
|
||||||
iPtr^.isStructOrUnion := false;
|
|
||||||
if (variable^.storage in [external,global,private]) then begin
|
|
||||||
iPtr^.isConstant := true;
|
|
||||||
iPtr^.itype := cgString;
|
|
||||||
iPtr^.sval := token.sval;
|
|
||||||
count := tp^.elements - stringLength;
|
|
||||||
if count > 0 then
|
|
||||||
Fill(count, stringElementType)
|
|
||||||
else if count = -1 then begin
|
|
||||||
iPtr^.sval := pointer(GMalloc(token.sval^.length+2));
|
|
||||||
CopyLongString(iPtr^.sval, token.sval);
|
|
||||||
iPtr^.sval^.length :=
|
|
||||||
iPtr^.sval^.length - ord(stringElementType^.size);
|
|
||||||
end; {else if}
|
|
||||||
end {if}
|
|
||||||
else begin
|
|
||||||
iPtr^.isConstant := false;
|
|
||||||
new(ep);
|
|
||||||
iPtr^.iTree := ep;
|
|
||||||
ep^.next := nil;
|
|
||||||
ep^.left := nil;
|
|
||||||
ep^.middle := nil;
|
|
||||||
ep^.right := nil;
|
|
||||||
ep^.token := token;
|
|
||||||
end; {else}
|
|
||||||
end; {with}
|
|
||||||
NextToken;
|
|
||||||
end {if}
|
end {if}
|
||||||
else begin
|
else if tp^.elements < stringLength-1 then begin
|
||||||
Error(47);
|
Error(44);
|
||||||
errorFound := true;
|
errorFound := true;
|
||||||
NextToken;
|
end; {else if}
|
||||||
end; {else}
|
with ktp^ do begin
|
||||||
|
iPtr := pointer(Malloc(sizeof(initializerRecord)));
|
||||||
|
iPtr^.next := variable^.iPtr;
|
||||||
|
variable^.iPtr := iPtr;
|
||||||
|
iPtr^.count := 1;
|
||||||
|
iPtr^.bitdisp := 0;
|
||||||
|
iPtr^.bitsize := 0;
|
||||||
|
iPtr^.isStructOrUnion := false;
|
||||||
|
if (variable^.storage in [external,global,private]) then begin
|
||||||
|
iPtr^.isConstant := true;
|
||||||
|
iPtr^.itype := cgString;
|
||||||
|
iPtr^.sval := token.sval;
|
||||||
|
count := tp^.elements - stringLength;
|
||||||
|
if count > 0 then
|
||||||
|
Fill(count, stringElementType)
|
||||||
|
else if count = -1 then begin
|
||||||
|
iPtr^.sval := pointer(GMalloc(token.sval^.length+2));
|
||||||
|
CopyLongString(iPtr^.sval, token.sval);
|
||||||
|
iPtr^.sval^.length :=
|
||||||
|
iPtr^.sval^.length - ord(stringElementType^.size);
|
||||||
|
end; {else if}
|
||||||
|
end {if}
|
||||||
|
else begin
|
||||||
|
iPtr^.isConstant := false;
|
||||||
|
new(ep);
|
||||||
|
iPtr^.iTree := ep;
|
||||||
|
ep^.next := nil;
|
||||||
|
ep^.left := nil;
|
||||||
|
ep^.middle := nil;
|
||||||
|
ep^.right := nil;
|
||||||
|
ep^.token := token;
|
||||||
|
end; {else}
|
||||||
|
end; {with}
|
||||||
|
NextToken;
|
||||||
end {if}
|
end {if}
|
||||||
|
|
||||||
{handle arrays of non-strings}
|
{handle arrays not initialized with a string constant}
|
||||||
else if kind in
|
else if kind in
|
||||||
[scalarType,pointerType,enumType,arrayType,structType,unionType] then
|
[scalarType,pointerType,enumType,arrayType,structType,unionType] then
|
||||||
begin
|
begin
|
||||||
|
|
Loading…
Reference in New Issue
Block a user