codetools: extended examples to sue environment variable FPCTARGET

git-svn-id: trunk@17714 -
This commit is contained in:
mattias 2008-12-07 22:09:57 +00:00
parent 6c76be7c59
commit 991a580e12
5 changed files with 17 additions and 56 deletions

View File

@ -918,7 +918,7 @@ begin
Options.FPCSrcDir:=ExpandFileNameUTF8('~/freepascal/fpc');
if Options.LazarusSrcDir='' then
Options.LazarusSrcDir:=ExpandFileNameUTF8('~/pascal/lazarus');
DebugLn(['TCodeToolManager.SimpleInit PP=',Options.FPCPath,' FPCDIR=',Options.FPCSrcDir,' LAZARUSDIR=',Options.LazarusSrcDir]);
DebugLn(['TCodeToolManager.SimpleInit PP=',Options.FPCPath,' FPCDIR=',Options.FPCSrcDir,' LAZARUSDIR=',Options.LazarusSrcDir,' FPCTARGET=',Options.TargetOS]);
// init the codetools
if not Options.UnitLinkListValid then
debugln('Scanning FPC sources may take a while ...');

View File

@ -261,6 +261,8 @@ begin
FPCSrcDir:=GetEnvironmentVariableUTF8('FPCDIR');
if GetEnvironmentVariableUTF8('LAZARUSDIR')<>'' then
LazarusSrcDir:=GetEnvironmentVariableUTF8('LAZARUSDIR');
if GetEnvironmentVariableUTF8('FPCTARGET')<>'' then
TargetOS:=GetEnvironmentVariableUTF8('FPCTARGET');
end;
function TCodeToolsOptions.FindDefaultCompilerFilename: string;

View File

@ -2,32 +2,12 @@
<CONFIG>
<ProjectOptions>
<PathDelim Value="/"/>
<Version Value="5"/>
<Version Value="6"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=""/>
</General>
<VersionInfo>
<UseVersionInfo Value="False"/>
<AutoIncrementBuild Value="False"/>
<CurrentVersionNr Value="0"/>
<CurrentMajorRevNr Value="0"/>
<CurrentMinorRevNr Value="0"/>
<CurrentBuildNr Value="0"/>
<ProjectVersion Value="1.0.0.0"/>
<Language Value="0409"/>
<CharSet Value="04E4"/>
<Comments Value=""/>
<CompanyName Value=""/>
<FileDescription Value=""/>
<InternalName Value=""/>
<LegalCopyright Value=""/>
<LegalTrademarks Value=""/>
<OriginalFilename Value=""/>
<ProductName Value=""/>
</VersionInfo>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
@ -58,13 +38,15 @@
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<Version Value="8"/>
<SearchPaths>
<OtherUnitFiles Value="scanexamples/"/>
</SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Parsing>
<SyntaxOptions>
<CStyleOperator Value="False"/>
</SyntaxOptions>
</Parsing>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>

View File

@ -3,49 +3,28 @@ program GetContext;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, CodeCache, CodeToolManager, DefineTemplates,
Classes, SysUtils, FileProcs, CodeCache, CodeToolManager, DefineTemplates,
CodeToolsConfig, GetContextExample, IdentCompletionTool, FindDeclarationTool;
const
ConfigFilename = 'codetools.config';
var
Options: TCodeToolsOptions;
Code: TCodeBuffer;
CodeContexts: TCodeContextInfo;
i: Integer;
ExprType: TExpressionType;
Filename: String;
begin
// setup the Options
Options:=TCodeToolsOptions.Create;
// To not parse the FPC sources every time, the options are saved to a file.
if FileExists(ConfigFilename) then
Options.LoadFromFile(ConfigFilename);
// setup your paths
Options.FPCPath:='/usr/bin/ppc386';
Options.FPCSrcDir:=ExpandFileName('~/freepascal/fpc');
Options.LazarusSrcDir:=ExpandFileName('~/pascal/lazarus');
// optional: ProjectDir and TestPascalFile exists only to easily test some
// things.
Options.ProjectDir:=GetCurrentDir+'/scanexamples/';
Options.TestPascalFile:=Options.ProjectDir+'getcontextexample.pas';
// init the codetools
if not Options.UnitLinkListValid then
writeln('Scanning FPC sources may take a while ...');
CodeToolBoss.Init(Options);
// save the options and the FPC unit links results.
Options.SaveToFile(ConfigFilename);
CodeToolBoss.SimpleInit(ConfigFilename);
// Example: find declaration of 'TObject'
// Step 1: load the file
Code:=CodeToolBoss.LoadFile(Options.TestPascalFile,false,false);
Filename:=CleanAndExpandFilename('scanexamples/getcontextexample.pas');
Code:=CodeToolBoss.LoadFile(Filename,false,false);
if Code=nil then
raise Exception.Create('loading failed '+Options.TestPascalFile);
raise Exception.Create('loading failed '+Filename);
// Step 2: find context
if CodeToolBoss.FindCodeContext(Code,7,14,CodeContexts) then
@ -62,7 +41,5 @@ begin
writeln('Contexts not found: ',CodeToolBoss.ErrorMessage);
end;
CodeContexts.Free;
Options.Free;
end.

View File

@ -5,7 +5,7 @@ unit GetContextExample;
interface
uses
Classes, SysUtils;
{$IFDEF MSWindows}Windows,{$ENDIF} Classes, SysUtils;
implementation