mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-30 20:30:41 +02:00
Converter: implement the dummy source replacements using TSourceChangeCache.ReplaceEx. Fixes issue #23552
git-svn-id: trunk@41971 -
This commit is contained in:
parent
c75d6e62dc
commit
5d64e62ba7
@ -61,6 +61,7 @@ type
|
||||
constructor Create(ACode: TCodeBuffer);
|
||||
destructor Destroy; override;
|
||||
procedure ResetMainScanner;
|
||||
function DummyReplacements: Boolean;
|
||||
public
|
||||
property CodeTool: TCodeTool read fCodeTool;
|
||||
property Code: TCodeBuffer read fCode;
|
||||
@ -140,6 +141,29 @@ begin
|
||||
fSrcCache.MainScanner:=fCodeTool.Scanner;
|
||||
end;
|
||||
|
||||
function TCodeToolLink.DummyReplacements: Boolean;
|
||||
// If Codetools cannot parse the code, do dummy replacement of some known problematic
|
||||
// syntax, currently only OleVariant.type. Most Codetools functions cannot
|
||||
// be used because the code is invalid, but TSourceChangeCache.ReplaceEx works.
|
||||
const
|
||||
ReplString = '.type';
|
||||
var
|
||||
p: Integer;
|
||||
begin
|
||||
p:=1;
|
||||
repeat
|
||||
// find next '.type'
|
||||
p:=PosEx(ReplString,fCode.Source,p);
|
||||
if p<1 then break;
|
||||
if not fSrcCache.ReplaceEx(gtNone,gtNone,1,1,fCode,p+1,p+1,'&') then
|
||||
Exit(False);
|
||||
inc(p,length(ReplString));
|
||||
until false;
|
||||
if not fSrcCache.Apply then
|
||||
Exit(False);
|
||||
Result:=True;
|
||||
end;
|
||||
|
||||
{ TConvDelphiCodeTool }
|
||||
|
||||
constructor TConvDelphiCodeTool.Create(APascalBuffer: TCodeBuffer);
|
||||
|
@ -542,7 +542,6 @@ begin
|
||||
repeat
|
||||
CodeOk:=True;
|
||||
try
|
||||
DebugLn('TDelphiUnit.CopyAndLoadFile: Creating UsedUnitsTool');
|
||||
// Create a tool for missing units.
|
||||
fUsedUnitsTool:=TUsedUnitsTool.Create(fCTLink, fOrigUnitFilename);
|
||||
except
|
||||
@ -551,9 +550,8 @@ begin
|
||||
if CodeFixed then
|
||||
Raise // There was a second exception -> we are doomed!
|
||||
else begin
|
||||
DebugLn('TDelphiUnit.CopyAndLoadFile exception: Replacing .type -> .&type');
|
||||
with fPascalBuffer do
|
||||
Source:=StringReplace(Source,'.type','.&type',[rfReplaceAll]);
|
||||
if not fCTLink.DummyReplacements then
|
||||
Raise;
|
||||
CodeOk := False;
|
||||
CodeFixed := True; // Try replacements only once
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user