mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 17:16:01 +02:00
delphi package conversion: implemented converting package units
git-svn-id: trunk@8978 -
This commit is contained in:
parent
e710e115ed
commit
1d9f747f93
@ -2222,7 +2222,8 @@ begin
|
||||
else
|
||||
Offset:=-1;
|
||||
if (Offset>0) then begin
|
||||
if (CompareIdentifiers('i',@ASource[Result+Offset])=0)
|
||||
if ((UpChars[ASource[Result+Offset]]='I')
|
||||
and (ASource[Result+Offset+1]=' '))
|
||||
or (CompareIdentifiers('include',@ASource[Result+Offset])=0) then begin
|
||||
CommentEndPos:=FindCommentEnd(ASource,Result,NestedComments);
|
||||
if ASource[Result]='{' then
|
||||
|
@ -438,6 +438,8 @@ type
|
||||
FixCase: boolean = false): boolean;
|
||||
function FindDelphiProjectUnits(Code: TCodeBuffer;
|
||||
var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean;
|
||||
function FindDelphiPackageUnits(Code: TCodeBuffer;
|
||||
var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean;
|
||||
function CommentUnitsInUsesSections(Code: TCodeBuffer;
|
||||
MissingUnits: TStrings): boolean;
|
||||
function FindUnit(Code: TCodeBuffer;
|
||||
@ -2898,6 +2900,22 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCodeToolManager.FindDelphiPackageUnits(Code: TCodeBuffer;
|
||||
var FoundInUnits, MissingInUnits, NormalUnits: TStrings): boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
{$IFDEF CTDEBUG}
|
||||
DebugLn('TCodeToolManager.FindDelphiPackageUnits A ',Code.Filename);
|
||||
{$ENDIF}
|
||||
if not InitCurCodeTool(Code) then exit;
|
||||
try
|
||||
Result:=FCurCodeTool.FindDelphiProjectUnits(FoundInUnits,
|
||||
MissingInUnits, NormalUnits,true);
|
||||
except
|
||||
on e: Exception do Result:=HandleException(e);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCodeToolManager.CommentUnitsInUsesSections(Code: TCodeBuffer;
|
||||
MissingUnits: TStrings): boolean;
|
||||
begin
|
||||
|
@ -696,7 +696,7 @@ type
|
||||
function FindDeclarationNodeInInterface(const Identifier: string;
|
||||
BuildTheTree: Boolean): TCodeTreeNode;
|
||||
|
||||
function FindMainUsesSection: TCodeTreeNode;
|
||||
function FindMainUsesSection(UseContainsSection: boolean = false): TCodeTreeNode;
|
||||
function FindImplementationUsesSection: TCodeTreeNode;
|
||||
|
||||
function FindUnitSource(const AnUnitName,
|
||||
@ -1496,17 +1496,25 @@ begin
|
||||
Result:=BestNode;
|
||||
end;
|
||||
|
||||
function TFindDeclarationTool.FindMainUsesSection: TCodeTreeNode;
|
||||
function TFindDeclarationTool.FindMainUsesSection(UseContainsSection: boolean
|
||||
): TCodeTreeNode;
|
||||
begin
|
||||
Result:=Tree.Root;
|
||||
if Result=nil then exit;
|
||||
if Result.Desc=ctnUnit then begin
|
||||
Result:=Result.NextBrother;
|
||||
if Result=nil then exit;
|
||||
if UseContainsSection then begin
|
||||
if Result.Desc<>ctnPackage then exit(nil);
|
||||
Result:=Result.FirstChild;
|
||||
while (Result<>nil) and (Result.Desc<>ctnContainsSection) do
|
||||
Result:=Result.NextBrother;
|
||||
end else begin
|
||||
if Result.Desc=ctnUnit then begin
|
||||
Result:=Result.NextBrother;
|
||||
if Result=nil then exit;
|
||||
end;
|
||||
Result:=Result.FirstChild;
|
||||
if (Result=nil) then exit;
|
||||
if (Result.Desc<>ctnUsesSection) then Result:=nil;
|
||||
end;
|
||||
Result:=Result.FirstChild;
|
||||
if (Result=nil) then exit;
|
||||
if (Result.Desc<>ctnUsesSection) then Result:=nil;
|
||||
end;
|
||||
|
||||
function TFindDeclarationTool.FindImplementationUsesSection: TCodeTreeNode;
|
||||
|
@ -1529,20 +1529,24 @@ end;
|
||||
|
||||
procedure TPascalReaderTool.MoveCursorToUsesStart(UsesNode: TCodeTreeNode);
|
||||
begin
|
||||
if (UsesNode=nil) or (UsesNode.Desc<>ctnUsesSection) then
|
||||
if (UsesNode=nil)
|
||||
or ((UsesNode.Desc<>ctnUsesSection) and (UsesNode.Desc<>ctnContainsSection))
|
||||
then
|
||||
RaiseException('[TPascalParserTool.MoveCursorToUsesStart] '
|
||||
+'internal error: invalid UsesNode');
|
||||
// search backwards through the uses section
|
||||
MoveCursorToCleanPos(UsesNode.StartPos);
|
||||
ReadNextAtom;
|
||||
if not UpAtomIs('USES') then
|
||||
if (not UpAtomIs('USES')) and (not UpAtomIs('CONTAINS')) then
|
||||
RaiseExceptionFmt(ctsStrExpectedButAtomFound,['uses',GetAtom]);
|
||||
ReadNextAtom;
|
||||
end;
|
||||
|
||||
procedure TPascalReaderTool.MoveCursorToUsesEnd(UsesNode: TCodeTreeNode);
|
||||
begin
|
||||
if (UsesNode=nil) or (UsesNode.Desc<>ctnUsesSection) then
|
||||
if (UsesNode=nil)
|
||||
or ((UsesNode.Desc<>ctnUsesSection) and (UsesNode.Desc<>ctnContainsSection))
|
||||
then
|
||||
RaiseException('[TPascalParserTool.MoveCursorToUsesEnd] '
|
||||
+'internal error: invalid UsesNode');
|
||||
// search backwards through the uses section
|
||||
|
@ -106,7 +106,8 @@ type
|
||||
function FindUsedUnitFiles(var MainUsesSection,
|
||||
ImplementationUsesSection: TStrings): boolean;
|
||||
function FindDelphiProjectUnits(var FoundInUnits, MissingInUnits,
|
||||
NormalUnits: TStrings): boolean;
|
||||
NormalUnits: TStrings;
|
||||
UseContainsSection: boolean = false): boolean;
|
||||
function UsesSectionToFilenames(UsesNode: TCodeTreeNode): TStrings;
|
||||
function UsesSectionToUnitnames(UsesNode: TCodeTreeNode): TStrings;
|
||||
function FindMissingUnits(var MissingUnits: TStrings; FixCase: boolean;
|
||||
@ -402,7 +403,7 @@ begin
|
||||
if SectionNode.Desc in [ctnProgram, ctnInterface, ctnImplementation] then
|
||||
begin
|
||||
UsesNode:=SectionNode.FirstChild;
|
||||
if (UsesNode.Desc=ctnUsesSection)
|
||||
if (UsesNode<>nil) and (UsesNode.Desc=ctnUsesSection)
|
||||
and FindUnitInUsesSection(UsesNode,UpperUnitName,NamePos,InPos) then begin
|
||||
Result:=true;
|
||||
exit;
|
||||
@ -781,7 +782,7 @@ end;
|
||||
function TStandardCodeTool.FindDelphiProjectUnits(var FoundInUnits,
|
||||
MissingInUnits, NormalUnits: TStrings): boolean;
|
||||
|
||||
Reads the main uses section backwards and tries to find each unit file having
|
||||
Reads the main uses section and tries to find each unit file having
|
||||
an 'in' modifier.
|
||||
The associated objects in the list will be the found codebuffers.
|
||||
FoundInUnits returns the list of found 'in' unitnames plus TCodeBuffer
|
||||
@ -792,7 +793,7 @@ end;
|
||||
plus the 'in' extension.
|
||||
------------------------------------------------------------------------------}
|
||||
function TStandardCodeTool.FindDelphiProjectUnits(var FoundInUnits,
|
||||
MissingInUnits, NormalUnits: TStrings): boolean;
|
||||
MissingInUnits, NormalUnits: TStrings; UseContainsSection: boolean): boolean;
|
||||
var
|
||||
InAtom, UnitNameAtom: TAtomPosition;
|
||||
AnUnitName, AnUnitInFilename: string;
|
||||
@ -803,9 +804,10 @@ begin
|
||||
FoundInUnits:=nil;
|
||||
MissingInUnits:=nil;
|
||||
NormalUnits:=nil;
|
||||
DebugLn('TStandardCodeTool.FindDelphiProjectUnits UseContainsSection=',dbgs(UseContainsSection));
|
||||
// find the uses sections
|
||||
BuildTree(false);
|
||||
UsesNode:=FindMainUsesSection;
|
||||
UsesNode:=FindMainUsesSection(UseContainsSection);
|
||||
if UsesNode=nil then exit;
|
||||
MoveCursorToUsesStart(UsesNode);
|
||||
FoundInUnits:=TStringList.Create;
|
||||
@ -832,7 +834,7 @@ begin
|
||||
FoundInUnits.AddObject(AnUnitName+' in '+AnUnitInFilename,NewCode);
|
||||
end;
|
||||
end else begin
|
||||
// the non 'in' units are 'Forms' or units added by the user
|
||||
// the units without 'in' are 'Forms' or units added by the user
|
||||
NewCode:=FindUnitSource(AnUnitName,AnUnitInFilename,false);
|
||||
NormalUnits.AddObject(AnUnitName,NewCode);
|
||||
end;
|
||||
|
@ -470,16 +470,13 @@ begin
|
||||
NormalUnits:=nil;
|
||||
try
|
||||
debugln('FindAllDelphiPackageUnits gathering all units ...');
|
||||
NotImplementedDialog('FindAllDelphiPackageUnits: Reading .dpk file');
|
||||
exit(mrAbort);
|
||||
|
||||
//if not CodeToolBoss.FindDelphiPackageUnits(DPKCode,FoundInUnits,
|
||||
//MissingInUnits, NormalUnits) then
|
||||
//begin
|
||||
//LazarusIDE.DoJumpToCodeToolBossError;
|
||||
//Result:=mrCancel;
|
||||
//exit;
|
||||
//end;
|
||||
if not CodeToolBoss.FindDelphiPackageUnits(DPKCode,FoundInUnits,
|
||||
MissingInUnits, NormalUnits) then
|
||||
begin
|
||||
LazarusIDE.DoJumpToCodeToolBossError;
|
||||
Result:=mrCancel;
|
||||
exit;
|
||||
end;
|
||||
debugln('FindAllDelphiPackageUnits FoundInUnits=[',FoundInUnits.Text,']',
|
||||
' MissingInUnits=[',MissingInUnits.Text,']',
|
||||
' NormalUnits=[',NormalUnits.Text,']');
|
||||
|
@ -2753,6 +2753,7 @@ begin
|
||||
if i>=FileCount then continue;
|
||||
if not FileExistsCached(Files[i].Filename) then
|
||||
RemoveFile(Files[i]);
|
||||
dec(i);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user