codetools: renamed unitname identifiers

git-svn-id: trunk@22334 -
This commit is contained in:
mattias 2009-10-29 11:23:40 +00:00
parent fbac1ba4b8
commit 192ee15737
4 changed files with 39 additions and 39 deletions

View File

@ -188,7 +188,7 @@ type
FUnitName: string;
public
constructor Create(const TheUnitName, TheFilename: string);
property UnitName: string read FUnitName;
property FileUnitName: string read FUnitName;
property Filename: string read FFilename;
end;
@ -226,7 +226,7 @@ function FindUnitNameInSource(const Source:string;
var UnitNameStart,UnitNameEnd:integer):string;
// uses sections
function UnitIsUsedInSource(const Source,UnitName:string):boolean;
function UnitIsUsedInSource(const Source,SrcUnitName:string):boolean;
function RenameUnitInProgramUsesSection(Source:TSourceLog;
const OldUnitName, NewUnitName, NewInFile:string): boolean;
function AddToProgramUsesSection(Source:TSourceLog;
@ -241,14 +241,14 @@ function RemoveFromInterfaceUsesSection(Source:TSourceLog;
const AUnitName:string):boolean;
// single uses section
function IsUnitUsedInUsesSection(const Source,UnitName:string;
function IsUnitUsedInUsesSection(const Source,SrcUnitName:string;
UsesStart:integer):boolean;
function RenameUnitInUsesSection(Source:TSourceLog; UsesStart: integer;
const OldUnitName, NewUnitName, NewInFile:string): boolean;
function AddUnitToUsesSection(Source:TSourceLog;
const UnitName,InFilename:string; UsesStart:integer):boolean;
const AnUnitName,InFilename:string; UsesStart:integer):boolean;
function RemoveUnitFromUsesSection(Source:TSourceLog;
const UnitName:string; UsesStart:integer):boolean;
const AnUnitName:string; UsesStart:integer):boolean;
// compiler directives
function FindIncludeDirective(const Source,Section:string; Index:integer;
@ -434,7 +434,7 @@ begin
Result:='';
end;
function UnitIsUsedInSource(const Source,UnitName:string):boolean;
function UnitIsUsedInSource(const Source,SrcUnitName:string):boolean;
// search in all uses sections
var UsesStart,UsesEnd:integer;
begin
@ -443,7 +443,7 @@ begin
UsesStart:=SearchCodeInSource(Source,'uses',1,UsesEnd,false);
if UsesEnd=0 then ;
if UsesStart>0 then begin
if IsUnitUsedInUsesSection(Source,UnitName,UsesStart) then begin
if IsUnitUsedInUsesSection(Source,SrcUnitName,UsesStart) then begin
Result:=true;
exit;
end;
@ -615,20 +615,20 @@ begin
Result:=RemoveUnitFromUsesSection(Source,AUnitName,UsesStart);
end;
function IsUnitUsedInUsesSection(const Source,UnitName:string;
function IsUnitUsedInUsesSection(const Source,SrcUnitName:string;
UsesStart:integer):boolean;
var UsesEnd:integer;
Atom:string;
begin
Result:=false;
if UnitName='' then exit;
if SrcUnitName='' then exit;
if UsesStart<1 then exit;
if not (lowercase(copy(Source,UsesStart,4))='uses') then exit;
UsesEnd:=UsesStart+4;
// parse through all used units and see if it is there
repeat
Atom:=ReadNextPascalAtom(Source,UsesEnd,UsesStart);
if (lowercase(Atom)=lowercase(UnitName)) then begin
if (lowercase(Atom)=lowercase(SrcUnitName)) then begin
// unit found
Result:=true;
exit;
@ -692,20 +692,20 @@ begin
end;
function AddUnitToUsesSection(Source:TSourceLog;
const UnitName,InFilename:string; UsesStart:integer):boolean;
const AnUnitName,InFilename:string; UsesStart:integer):boolean;
var UsesEnd:integer;
LineStart,LineEnd:integer;
s,Atom,NewUnitTerm:string;
begin
Result:=false;
if (UnitName='') or (UnitName=';') or (UsesStart<1) then exit;
if (AnUnitName='') or (AnUnitName=';') or (UsesStart<1) then exit;
UsesEnd:=UsesStart+4;
if not (lowercase(copy(Source.Source,UsesStart,4))='uses') then exit;
// parse through all used units and see if it is already there
s:=', ';
repeat
Atom:=ReadNextPascalAtom(Source.Source,UsesEnd,UsesStart);
if (lowercase(Atom)=lowercase(UnitName)) then begin
if (lowercase(Atom)=lowercase(AnUnitName)) then begin
// unit found
Result:=true;
exit;
@ -719,9 +719,9 @@ begin
until Atom<>',';
// unit not used yet -> add it
if InFilename<>'' then
NewUnitTerm:=UnitName+' in '''+InFileName+''''
NewUnitTerm:=AnUnitName+' in '''+InFileName+''''
else
NewUnitTerm:=UnitName;
NewUnitTerm:=AnUnitName;
Source.Insert(UsesStart,s+NewUnitTerm);
GetLineStartEndAtPosition(Source.Source,UsesStart,LineStart,LineEnd);
if (LineEnd-LineStart>MaxLineLength) or (InFileName<>'') then
@ -729,13 +729,13 @@ begin
Result:=true;
end;
function RemoveUnitFromUsesSection(Source:TSourceLog; const UnitName:string;
function RemoveUnitFromUsesSection(Source:TSourceLog; const AnUnitName:string;
UsesStart:integer):boolean;
var UsesEnd,OldUsesStart,OldUsesEnd:integer;
Atom:string;
begin
Result:=false;
if (UsesStart<1) or (UnitName='') or (UnitName=',') or (UnitName=';') then
if (UsesStart<1) or (AnUnitName='') or (AnUnitName=',') or (AnUnitName=';') then
exit;
// search interface section
UsesEnd:=UsesStart+4;
@ -744,7 +744,7 @@ begin
OldUsesEnd:=-1;
repeat
Atom:=ReadNextPascalAtom(Source.Source,UsesEnd,UsesStart);
if (lowercase(Atom)=lowercase(UnitName)) then begin
if (lowercase(Atom)=lowercase(AnUnitName)) then begin
// unit found
OldUsesStart:=UsesStart;
// find comma or semicolon
@ -755,7 +755,7 @@ begin
// first used unit
Source.Delete(OldUsesStart,UsesStart-OldUsesStart)
else
// not first used unit (remove comma in front of unitname too)
// not first used unit (remove comma in front of AnUnitName too)
Source.Delete(OldUsesEnd,UsesStart-OldUsesEnd);
Result:=true;
exit;
@ -4713,15 +4713,15 @@ end;
function CompareUnitFileInfos(Data1, Data2: Pointer): integer;
begin
Result:=CompareIdentifiers(PChar(TUnitFileInfo(Data1).UnitName),
PChar(TUnitFileInfo(Data2).UnitName));
Result:=CompareIdentifiers(PChar(TUnitFileInfo(Data1).FileUnitName),
PChar(TUnitFileInfo(Data2).FileUnitName));
end;
function CompareUnitNameAndUnitFileInfo(UnitnamePAnsiString,
UnitFileInfo: Pointer): integer;
begin
Result:=CompareIdentifiers(PChar(UnitnamePAnsiString),
PChar(TUnitFileInfo(UnitFileInfo).UnitName));
PChar(TUnitFileInfo(UnitFileInfo).FileUnitName));
end;
function CountNeededLineEndsToAddForward(const Src: string;

View File

@ -38,11 +38,11 @@ uses
procedure AddUnitDependency(P: TPackage; T: TTarget; Filename: string);
var
UnitName: String;
FileUnitName: String;
begin
if Filename='' then exit;
UnitName:=copy(Filename,1,length(Filename)-length(ExtractFileExt(Filename)));
T.Dependencies.AddUnit(UnitName);
FileUnitName:=copy(Filename,1,length(Filename)-length(ExtractFileExt(Filename)));
T.Dependencies.AddUnit(FileUnitName);
P.Targets.AddUnit(Filename);
end;

View File

@ -1347,12 +1347,12 @@ begin
ANode:=TreeOfUnitFiles.FindLowest;
while ANode<>nil do begin
UnitFileInfo:=TUnitFileInfo(ANode.Data);
if CompareIdentifiers(PChar(Pointer(UnitFileInfo.UnitName)),
if CompareIdentifiers(PChar(Pointer(UnitFileInfo.FileUnitName)),
PChar(Pointer(CurSourceName)))<>0
then begin
NewItem:=TIdentifierListItem.Create(
icompCompatible,true,0,
CurrentIdentifierList.CreateIdentifier(UnitFileInfo.UnitName),
CurrentIdentifierList.CreateIdentifier(UnitFileInfo.FileUnitName),
0,nil,nil,ctnUnit);
CurrentIdentifierList.Add(NewItem);
end;

View File

@ -798,7 +798,7 @@ begin
end;
end;
// build insert text "unitname in 'file'"
// build insert text "newunitname in 'file'"
NewUsesTerm:=NewUnitName;
if NewUnitInFile<>'' then
NewUsesTerm:=NewUsesTerm+' '
@ -816,12 +816,12 @@ begin
NewComma:=NewComma+' ';
if InsertBehind then begin
// insert behind unitname, in front of semicolon or comma
// insert behind unit name, in front of semicolon or comma
// for example: uses unit1|, unit2 in 'unit2.pp'|;
InsertPos:=InsertNode.EndPos;
InsertCode:=NewComma+NewUsesTerm;
end else begin
// insert in front of unitname, behind 'uses' or comma
// insert in front of unit name, behind 'uses' or comma
// for example: uses |unit1, |unit2;
InsertPos:=InsertNode.StartPos;
InsertCode:=NewUsesTerm+NewComma;
@ -1413,7 +1413,7 @@ function TStandardCodeTool.FindMissingUnits(var MissingUnits: TStrings;
else
ToPos:=UnitNameAtom.EndPos;
SourceChangeCache.Replace(gtNone,gtNone,FromPos,ToPos,s);
DebugLn('CheckUsesSection fix case UnitName(',OldUnitName,'->',NewUnitName,') InFile(',OldInFilename,'->',NewInFilename,')');
DebugLn('CheckUsesSection fix case Unit Name(',OldUnitName,'->',NewUnitName,') InFile(',OldInFilename,'->',NewInFilename,')');
end;
end else begin
// unit not found
@ -1726,7 +1726,7 @@ var
var
UnitNamePos: TAtomPosition;
UnitInFilePos: TAtomPosition;
UnitName: String;
Unit_Name: String;
UnitInFilename: String;
Tool: TFindDeclarationTool;
HasCode: boolean;
@ -1754,9 +1754,9 @@ var
ReadNextAtom;
end else
UnitInFilePos.StartPos:=-1;
UnitName:=copy(Src,UnitNamePos.StartPos,
Unit_Name:=copy(Src,UnitNamePos.StartPos,
UnitNamePos.EndPos-UnitNamePos.StartPos);
if not IsUnitAlreadyChecked(UnitName) then begin
if not IsUnitAlreadyChecked(Unit_Name) then begin
OldPos:=CurPos.StartPos;
if UnitInFilePos.StartPos>=1 then begin
UnitInFilename:=copy(Src,UnitInFilePos.StartPos+1,
@ -1764,8 +1764,8 @@ var
end else
UnitInFilename:='';
// try to load the used unit
DebugLn(['CheckUsesSection ',UnitName,UnitInFilename]);
Tool:=FindCodeToolForUsedUnit(UnitName,UnitInFilename,true);
DebugLn(['CheckUsesSection ',Unit_Name,UnitInFilename]);
Tool:=FindCodeToolForUsedUnit(Unit_Name,UnitInFilename,true);
// parse the used unit
CheckUnit(Tool,HasCode,UseInterface);
Flags:='';
@ -1775,8 +1775,8 @@ var
Flags:=Flags+',code';
if UseInterface then
Flags:=Flags+',used';
DebugLn(['CheckUsesSection ',UnitName,'=',Flags]);
Units.Add(UnitName+'='+Flags);
DebugLn(['CheckUsesSection ',Unit_Name,'=',Flags]);
Units.Add(Unit_Name+'='+Flags);
// restore cursor
MoveCursorToCleanPos(OldPos);
ReadNextAtom;
@ -4918,7 +4918,7 @@ var
repeat
// read all property infos of current class
TypeData:=GetTypeData(TypeInfo);
// skip unitname
// skip unit name
PropInfo:=PPropInfo(PByte(@TypeData^.UnitName)+Length(TypeData^.UnitName)+1);
// read property count
CurCount:=PWord(PropInfo)^;