Skip to content

Commit 1cabc17

Browse files
committed
Improve previous: Use AnyString instead of const because types like Integer don't work because of the lack of 'var' in the prototypes. Putting 'var' + 'const' does not work at run time and was not able to fix this. Also improve AnyString: the compiler didn't actually check that an AnyString parameter in the call was actually a string type, instead it accepted any type as if the prototype said 'const'.
1 parent 7e96130 commit 1cabc17

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

Source/uPSC_classes.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ procedure SIRegisterTSTREAM(Cl: TPSPascalCompiler);
137137
{$IFNDEF DELPHI_SYDNEY_UP}
138138
IsAbstract := True;
139139
{$ENDIF}
140-
RegisterMethod('function Read(Buffer: const; Count: LongInt): LongInt');
141-
RegisterMethod('function Write(Buffer: const; Count: LongInt): LongInt');
140+
RegisterMethod('function Read(Buffer: AnyString; Count: LongInt): LongInt');
141+
RegisterMethod('function Write(Buffer: AnyString; Count: LongInt): LongInt');
142142
{$IFDEF DELPHI_TOKYO_UP}
143143
{$IFNDEF PS_NOINT64}
144144
RegisterMethod('function Seek(Offset: Int64; Origin: Word): Int64');
145145
{$ENDIF}
146146
{$ELSE}
147147
RegisterMethod('function Seek(Offset: LongInt; Origin: Word): LongInt');
148148
{$ENDIF}
149-
RegisterMethod('procedure ReadBuffer(Buffer: const; Count: LongInt)');
150-
RegisterMethod('procedure WriteBuffer(Buffer: const; Count: LongInt)');
149+
RegisterMethod('procedure ReadBuffer(Buffer: AnyString; Count: LongInt)');
150+
RegisterMethod('procedure WriteBuffer(Buffer: AnyString; Count: LongInt)');
151151
{$IFDEF DELPHI4UP}
152152
{$IFNDEF PS_NOINT64}
153153
RegisterMethod('function CopyFrom(Source: TStream; Count: Int64): Int64');

Source/uPSCompiler.pas

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,20 @@ function IsCharType(b: TPSBaseType): Boolean;
27552755
end;
27562756
end;
27572757

2758+
function IsStringType(b: TPSBaseType): Boolean;
2759+
begin
2760+
case b of
2761+
btString{$IFNDEF PS_NOWIDESTRING}, btWideString, btUnicodeString{$ENDIF}: Result := True;
2762+
else
2763+
Result := False;
2764+
end;
2765+
end;
2766+
2767+
function IsStringOrCharType(b: TPSBaseType): Boolean;
2768+
begin
2769+
Result := IsStringType(b) or IsCharType(b);
2770+
end;
2771+
27582772
function IsRealType(b: TPSBaseType): Boolean;
27592773
begin
27602774
case b of
@@ -5254,9 +5268,8 @@ function TPSPascalCompiler.ValidateParameters(BlockInfo: TPSBlockInfo; Params: T
52545268
begin
52555269
Params[c].ExpectedType := GetTypeNo(BlockInfo, Params[c].Val);
52565270
if PType <> nil then
5257-
if (Params[c].ExpectedType = nil) or not (Params[c].ExpectedType.BaseType in [btString,
5258-
{$IFNDEF PS_NOWIDESTRING}btWideString, btUnicodeString, btWideChar,{$ENDIF}
5259-
btChar]) then begin
5271+
if (Params[c].ExpectedType = nil) or not IsStringOrCharType(Params[c].ExpectedType.BaseType) then
5272+
begin
52605273
MakeError('', ecTypeMismatch, '');
52615274
Result := False;
52625275
exit;
@@ -9572,8 +9585,17 @@ function TPSPascalCompiler.ProcessSub(BlockInfo: TPSBlockInfo): Boolean;
95729585
end
95739586
else
95749587
begin
9575-
if (Tmp.ExpectedType = nil) or (Tmp.ExpectedType = FAnyString) then
9588+
if Tmp.ExpectedType = nil then
9589+
Tmp.ExpectedType := GetTypeNo(BlockInfo, tmp.Val)
9590+
else if Tmp.ExpectedType = FAnyString then begin
95769591
Tmp.ExpectedType := GetTypeNo(BlockInfo, tmp.Val);
9592+
if not IsStringType(Tmp.ExpectedType.BaseType) then
9593+
begin
9594+
MakeError('', ecTypeMismatch, '');
9595+
Cleanup;
9596+
exit;
9597+
end;
9598+
end;
95779599
if Tmp.ExpectedType.BaseType = btPChar then
95789600
begin
95799601
Tmp.TempVar := AllocStackReg(at2ut(FindBaseType(btstring)))

0 commit comments

Comments
 (0)