mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 07:16:16 +02:00
Converter: Add thread support, insert cthreads in main unit's uses section.
git-svn-id: trunk@29066 -
This commit is contained in:
parent
769e36bac2
commit
d80fadfa54
@ -146,6 +146,7 @@ type
|
||||
// Units that are found and will be added to project and converted.
|
||||
fUnitsToAddToProject: TStringList;
|
||||
fSettings: TConvertSettings;
|
||||
fUseThreads: boolean; // The project/package uses TThread.
|
||||
function ConvertSub: TModalResult;
|
||||
procedure CleanUpCompilerOptionsSearchPaths(Options: TBaseCompilerOptions);
|
||||
procedure SetCompilerModeForDefineTempl(DefTempl: TDefineTemplate);
|
||||
@ -464,6 +465,7 @@ end;
|
||||
|
||||
destructor TConvertDelphiUnit.Destroy;
|
||||
begin
|
||||
fUsedUnitsTool.Free;
|
||||
fCTLink.Free;
|
||||
if fOwnerConverter=nil then
|
||||
fSettings.Free;
|
||||
@ -676,7 +678,6 @@ begin
|
||||
if Assigned(fUsedUnitsTool) then begin
|
||||
Result:=fUsedUnitsTool.Convert;
|
||||
if Result<>mrOk then exit;
|
||||
FreeAndNil(fUsedUnitsTool);
|
||||
end;
|
||||
Result:=mrOk;
|
||||
end;
|
||||
@ -782,6 +783,7 @@ constructor TConvertDelphiPBase.Create(const AFilename, ADescription: string);
|
||||
begin
|
||||
fOrigPFilename:=AFilename;
|
||||
fIsConsoleApp:=False; // Default = GUI app.
|
||||
fUseThreads:=True; // For testing.
|
||||
fUnitSearchPaths:=TStringList.Create;
|
||||
fUnitSearchPaths.Delimiter:=';';
|
||||
fUnitSearchPaths.StrictDelimiter:=True;
|
||||
@ -1463,8 +1465,13 @@ begin
|
||||
Result:=ConvertOne(CurUnitInfo);
|
||||
if Result<>mrOK then Break;
|
||||
end;
|
||||
if Result=mrOK then
|
||||
if Result=mrOK then begin
|
||||
if fUseThreads then begin
|
||||
Result:=fMainUnitConverter.fUsedUnitsTool.AddThreadSupport;
|
||||
if Result<>mrOK then exit;
|
||||
end;
|
||||
Result:=ConvertAllFormFiles(ConvUnits);
|
||||
end;
|
||||
finally
|
||||
ConvUnits.Free; // Owns and frees converter objects.
|
||||
end;
|
||||
|
@ -121,6 +121,7 @@ type
|
||||
function Convert: TModalResult;
|
||||
procedure MoveMissingToComment(AAllCommentedUnits: TStrings);
|
||||
procedure AddUnitIfNeeded(AUnitName: string);
|
||||
function AddThreadSupport: TModalResult;
|
||||
public
|
||||
property MainUsedUnits: TUsedUnits read fMainUsedUnits;
|
||||
property ImplUsedUnits: TUsedUnits read fImplUsedUnits;
|
||||
@ -629,6 +630,25 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TUsedUnitsTool.AddThreadSupport: TModalResult;
|
||||
// AddUnitToSpecificUsesSection would insert cthreads in the beginning automatically
|
||||
// It doesn't work with {$IFDEF UNIX} directive -> use UsesInsertPolicy.
|
||||
var
|
||||
OldPolicy: TUsesInsertPolicy;
|
||||
begin
|
||||
Result:=mrCancel;
|
||||
with fCTLink do
|
||||
try
|
||||
OldPolicy:=SrcCache.BeautifyCodeOptions.UsesInsertPolicy;
|
||||
SrcCache.BeautifyCodeOptions.UsesInsertPolicy:=uipFirst;
|
||||
if not CodeTool.AddUnitToSpecificUsesSection(fMainUsedUnits.fUsesSection,
|
||||
'{$IFDEF UNIX}cthreads{$ENDIF}', '', SrcCache) then exit;
|
||||
finally
|
||||
SrcCache.BeautifyCodeOptions.UsesInsertPolicy:=OldPolicy;
|
||||
end;
|
||||
Result:=mrOK;
|
||||
end;
|
||||
|
||||
function TUsedUnitsTool.GetMissingUnitCount: integer;
|
||||
begin
|
||||
Result:=fMainUsedUnits.fMissingUnits.Count+fImplUsedUnits.fMissingUnits.Count;
|
||||
|
Loading…
Reference in New Issue
Block a user