MG: fixed project codetool variable

git-svn-id: trunk@535 -
This commit is contained in:
lazarus 2001-12-16 12:55:58 +00:00
parent 746f33a85e
commit 9a99f03e56
4 changed files with 56 additions and 8 deletions

View File

@ -1071,8 +1071,11 @@ begin
Result:=nil;
if Code=nil then exit;
//DefineTree.WriteDebugReport;
Result:=DefineTree.GetDefinesForDirectory(
ExtractFilePath(TCodeBuffer(Code).Filename));
if not TCodeBuffer(Code).IsVirtual then
Result:=DefineTree.GetDefinesForDirectory(
ExtractFilePath(TCodeBuffer(Code).Filename))
else
Result:=DefineTree.GetDefinesForVirtualDirectory;
end;
procedure TCodeToolManager.OnDefineTreeReadValue(Sender: TObject;

View File

@ -69,7 +69,10 @@ const
StdDefTemplFPCSrc = 'Free Pascal Sources';
StdDefTemplLazarusSources = 'Lazarus Sources';
StdDefTemplLCLProject = 'LCL Project';
// virtual directory
VirtualDirectory='VIRTUALDIRECTORY';
// FPC operating systems and processor types
FPCOperatingSystemNames: array[1..11] of shortstring =(
'linux', 'freebsd', 'win32', 'go32v1', 'go32v2', 'beos', 'os2', 'amiga',
@ -144,6 +147,7 @@ type
private
FFirstDefineTemplate: TDefineTemplate;
FCache: TAVLTree; // tree of TDirectoryDefines
FVirtualDirCache: TDirectoryDefines;
FOnReadValue: TOnReadValue;
FErrorTemplate: TDefineTemplate;
FErrorDescription: string;
@ -151,6 +155,7 @@ type
function Calculate(DirDef: TDirectoryDefines): boolean;
public
function GetDefinesForDirectory(const Path: string): TExpressionEvaluator;
function GetDefinesForVirtualDirectory: TExpressionEvaluator;
property RootTemplate: TDefineTemplate
read FFirstDefineTemplate write FFirstDefineTemplate;
procedure Add(ADefineTemplate: TDefineTemplate);
@ -649,6 +654,8 @@ end;
procedure TDefineTree.ClearCache;
begin
FCache.FreeAndClear;
FVirtualDirCache.Free;
FVirtualDirCache:=nil;
end;
constructor TDefineTree.Create;
@ -712,6 +719,25 @@ begin
end;
end;
function TDefineTree.GetDefinesForVirtualDirectory: TExpressionEvaluator;
begin
if FVirtualDirCache<>nil then
Result:=FVirtualDirCache.Values
else begin
writeln('################');
FVirtualDirCache:=TDirectoryDefines.Create;
FVirtualDirCache.Path:=VirtualDirectory;
if Calculate(FVirtualDirCache) then begin
Result:=FVirtualDirCache.Values;
writeln(Result.AsString);
end else begin
FVirtualDirCache.Free;
FVirtualDirCache:=nil;
Result:=nil;
end;
end;
end;
function TDefineTree.Calculate(DirDef: TDirectoryDefines): boolean;
// calculates the values for a single directory
// returns false on error
@ -915,7 +941,10 @@ begin
//writeln('[TDefineTree.Calculate] "',DirDef.Path,'"');
Result:=true;
FErrorTemplate:=nil;
ExpandedDirectory:=ReadValue(DirDef.Path);
if DirDef.Path<>VirtualDirectory then
ExpandedDirectory:=ReadValue(DirDef.Path)
else
ExpandedDirectory:=DirDef.Path;
DirDef.Values.Clear;
// compute the result of all matching DefineTemplates
CalculateTemplate(FFirstDefineTemplate,'');

View File

@ -192,14 +192,21 @@ writeln('TFindDeclarationTool.FindUnitSource.LoadFile ',ExpandedFilename);
function SearchUnitFileInPath(const APath, TheUnitName: string): TCodeBuffer;
var PathStart, PathEnd: integer;
ADir: string;
begin
writeln('--------------------------------------');
writeln(APath,' ',TheUnitName);
writeln('--------------------------------------');
PathStart:=1;
while PathStart<=length(APath) do begin
PathEnd:=PathStart;
while (PathEnd<=length(APath)) and (APath[PathEnd]<>';') do inc(PathEnd);
if PathEnd>PathStart then begin
Result:=SearchUnitFileInDir(copy(APath,PathStart,PathEnd-PathStart),
TheUnitName);
ADir:=copy(APath,PathStart,PathEnd-PathStart);
if (ADir<>'') and (ADir[length(ADir)]<>OSDirSeparator) then
ADir:=ADir+OSDirSeparator;
writeln('B ',ADir);
Result:=SearchUnitFileInDir(ADir,TheUnitName);
if Result<>nil then exit;
end;
PathStart:=PathEnd+1;

View File

@ -3192,7 +3192,7 @@ writeln('TMainIDE.DoNewProject A');
end;
CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'ProjectDir']:=
'(unknown Project Directory)';
VirtualDirectory;
Project:=TProject.Create(NewProjectType);
Project.OnFileBackup:=@DoBackupFile;
@ -3358,6 +3358,9 @@ writeln('AnUnitInfo.Filename=',AnUnitInfo.Filename);
end;
end;
Project.ProjectFile:=NewFilename;
CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'ProjectDir']:=
ExtractFilePath(Project.ProjectFile);
CodeToolBoss.DefineTree.ClearCache;
EnvironmentOptions.AddToRecentProjectFiles(NewFilename);
if (MainUnitInfo<>nil) then begin
// switch MainUnitInfo to new code
@ -3514,6 +3517,9 @@ CheckHeap(IntToStr(GetMem_Cnt));
LPIFilename:=ChangeFileExt(AFilename,'.lpi');
Project:=TProject.Create(ptProgram);
Project.ReadProject(LPIFilename);
CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'ProjectDir']:=
ExtractFilePath(Project.ProjectFile);
CodeToolBoss.DefineTree.ClearCache;
writeln('TMainIDE.DoOpenProjectFile B2');
if Project.MainUnit>=0 then begin
// read MainUnit Source
@ -4831,7 +4837,7 @@ begin
Variables[ExternalMacroStart+'FPCSrcDir']:=
EnvironmentOptions.FPCSourceDirectory;
Variables[ExternalMacroStart+'LCLWidgetType']:='gtk';
Variables[ExternalMacroStart+'ProjectDir']:='';
Variables[ExternalMacroStart+'ProjectDir']:=VirtualDirectory;
end;
// build DefinePool and Define Tree
@ -5375,6 +5381,9 @@ end.
{ =============================================================================
$Log$
Revision 1.184 2001/12/16 12:55:57 lazarus
MG: fixed project codetool variable
Revision 1.183 2001/12/16 11:20:26 lazarus
MG: find declaration for uses sections