mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-12 10:19:15 +02:00
codetools: aded FindProcDeclaration
git-svn-id: trunk@30523 -
This commit is contained in:
parent
013afcfaf2
commit
92692eea39
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -450,6 +450,8 @@ components/codetools/examples/methodjumping.lpi svneol=native#text/plain
|
|||||||
components/codetools/examples/methodjumping.pas svneol=native#text/plain
|
components/codetools/examples/methodjumping.pas svneol=native#text/plain
|
||||||
components/codetools/examples/ppudependencies.lpi svneol=native#text/plain
|
components/codetools/examples/ppudependencies.lpi svneol=native#text/plain
|
||||||
components/codetools/examples/ppudependencies.lpr svneol=native#text/plain
|
components/codetools/examples/ppudependencies.lpr svneol=native#text/plain
|
||||||
|
components/codetools/examples/proctomethod.lpi svneol=native#text/plain
|
||||||
|
components/codetools/examples/proctomethod.lpr svneol=native#text/plain
|
||||||
components/codetools/examples/reduceifdefs.lpi svneol=native#text/plain
|
components/codetools/examples/reduceifdefs.lpi svneol=native#text/plain
|
||||||
components/codetools/examples/reduceifdefs.lpr svneol=native#text/plain
|
components/codetools/examples/reduceifdefs.lpr svneol=native#text/plain
|
||||||
components/codetools/examples/removeemptymethods.lpi svneol=native#text/plain
|
components/codetools/examples/removeemptymethods.lpi svneol=native#text/plain
|
||||||
@ -479,6 +481,7 @@ components/codetools/examples/scanexamples/modemacpas.pas svneol=native#text/pla
|
|||||||
components/codetools/examples/scanexamples/nestedclasses.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/nestedclasses.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/objctest1.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/objctest1.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/overloadedfunction.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/overloadedfunction.pas svneol=native#text/plain
|
||||||
|
components/codetools/examples/scanexamples/procsandmethods1.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/publishedmethods1.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/publishedmethods1.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/publishedmethods2.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/publishedmethods2.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/publishedvars.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/publishedvars.pas svneol=native#text/plain
|
||||||
|
@ -385,6 +385,9 @@ type
|
|||||||
out NewCode: TCodeBuffer;
|
out NewCode: TCodeBuffer;
|
||||||
out NewX, NewY, NewTopLine: integer;
|
out NewX, NewY, NewTopLine: integer;
|
||||||
out RevertableJump: boolean): boolean;
|
out RevertableJump: boolean): boolean;
|
||||||
|
function FindProcDeclaration(Code: TCodeBuffer; CleanDef: string;
|
||||||
|
out Tool: TCodeTool; out Node: TCodeTreeNode;
|
||||||
|
Attr: TProcHeadAttributes = [phpWithoutSemicolon]): boolean;
|
||||||
|
|
||||||
// find declaration
|
// find declaration
|
||||||
function FindDeclaration(Code: TCodeBuffer; X,Y: integer;
|
function FindDeclaration(Code: TCodeBuffer; X,Y: integer;
|
||||||
@ -1791,6 +1794,38 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCodeToolManager.FindProcDeclaration(Code: TCodeBuffer;
|
||||||
|
CleanDef: string; out Tool: TCodeTool; out Node: TCodeTreeNode;
|
||||||
|
Attr: TProcHeadAttributes): boolean;
|
||||||
|
var
|
||||||
|
Paths: TStringList;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
{$IFDEF CTDEBUG}
|
||||||
|
DebugLn(['TCodeToolManager.FindProcDeclaration A ',Code.Filename,' CleanDef=',CleanDef]);
|
||||||
|
{$ENDIF}
|
||||||
|
Tool:=nil;
|
||||||
|
Node:=nil;
|
||||||
|
if not InitCurCodeTool(Code) then exit;
|
||||||
|
Tool:=FCurCodeTool;
|
||||||
|
Paths:=TStringList.Create;
|
||||||
|
try
|
||||||
|
Paths.Add(CleanDef);
|
||||||
|
try
|
||||||
|
FCurCodeTool.BuildTree(lsrEnd);
|
||||||
|
Node:=FCurCodeTool.FindSubProcPath(Paths,Attr,false);
|
||||||
|
Result:=Node<>nil;
|
||||||
|
except
|
||||||
|
on e: Exception do Result:=HandleException(e);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
Paths.Free;
|
||||||
|
end;
|
||||||
|
{$IFDEF CTDEBUG}
|
||||||
|
DebugLn('TCodeToolManager.FindProcDeclaration END ');
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.FindDeclaration(Code: TCodeBuffer; X,Y: integer;
|
function TCodeToolManager.FindDeclaration(Code: TCodeBuffer; X,Y: integer;
|
||||||
out NewCode: TCodeBuffer;
|
out NewCode: TCodeBuffer;
|
||||||
out NewX, NewY, NewTopLine: integer;
|
out NewX, NewY, NewTopLine: integer;
|
||||||
|
@ -12,9 +12,8 @@ Then you must set the FPCDIR variable and start the example again. For example:
|
|||||||
Under linux:
|
Under linux:
|
||||||
export FPCDIR=/home/username/freepascal/fpc
|
export FPCDIR=/home/username/freepascal/fpc
|
||||||
|
|
||||||
For instance the FPC 2.2.0 source directory looks like this:
|
For instance the FPC 2.4.2 source directory contains the following files:
|
||||||
compiler
|
compiler
|
||||||
fv
|
|
||||||
ide
|
ide
|
||||||
installer
|
installer
|
||||||
Makefile
|
Makefile
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="7"/>
|
<Version Value="9"/>
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<MainUnitHasCreateFormStatements Value="False"/>
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
@ -10,8 +10,11 @@
|
|||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
<TargetFileExt Value=""/>
|
<UseAppBundle Value="False"/>
|
||||||
</General>
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
@ -42,11 +45,19 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="8"/>
|
<Version Value="10"/>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<OtherUnitFiles Value="scanexamples/"/>
|
<OtherUnitFiles Value="scanexamples"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
|
<Parsing>
|
||||||
|
<SyntaxOptions>
|
||||||
|
<UseAnsiStrings Value="False"/>
|
||||||
|
</SyntaxOptions>
|
||||||
|
</Parsing>
|
||||||
<Other>
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
</Other>
|
</Other>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="7"/>
|
<Version Value="9"/>
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<MainUnitHasUsesSectionForAllUnits Value="False"/>
|
<MainUnitHasUsesSectionForAllUnits Value="False"/>
|
||||||
@ -11,9 +11,12 @@
|
|||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
<TargetFileExt Value=""/>
|
|
||||||
<Title Value="autoindent"/>
|
<Title Value="autoindent"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
</General>
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
@ -57,8 +60,11 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="8"/>
|
<Version Value="10"/>
|
||||||
<Other>
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
</Other>
|
</Other>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="8"/>
|
<Version Value="9"/>
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<LRSInOutputDirectory Value="False"/>
|
<LRSInOutputDirectory Value="False"/>
|
||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
<TargetFileExt Value=""/>
|
<UseAppBundle Value="False"/>
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<BuildModes Count="1">
|
||||||
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion="0.0.0.0"/>
|
<Item1 Name="default" Default="True"/>
|
||||||
</VersionInfo>
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
@ -48,16 +48,14 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="9"/>
|
<Version Value="10"/>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<OtherUnitFiles Value="scanexamples/"/>
|
<OtherUnitFiles Value="scanexamples"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<Parsing>
|
|
||||||
<SyntaxOptions>
|
|
||||||
<UseAnsiStrings Value="False"/>
|
|
||||||
</SyntaxOptions>
|
|
||||||
</Parsing>
|
|
||||||
<Other>
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
</Other>
|
</Other>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="8"/>
|
<Version Value="9"/>
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<LRSInOutputDirectory Value="False"/>
|
<LRSInOutputDirectory Value="False"/>
|
||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
<TargetFileExt Value=""/>
|
<UseAppBundle Value="False"/>
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion=""/>
|
<StringTable ProductVersion=""/>
|
||||||
</VersionInfo>
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
@ -44,13 +47,11 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="9"/>
|
<Version Value="10"/>
|
||||||
<Parsing>
|
|
||||||
<SyntaxOptions>
|
|
||||||
<UseAnsiStrings Value="False"/>
|
|
||||||
</SyntaxOptions>
|
|
||||||
</Parsing>
|
|
||||||
<Other>
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
</Other>
|
</Other>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
</General>
|
</General>
|
||||||
<BuildModes Count="1">
|
<BuildModes Count="1">
|
||||||
<Item1 Name="default" Default="True"/>
|
<Item1 Name="default" Default="True"/>
|
||||||
@ -38,12 +39,10 @@
|
|||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="10"/>
|
<Version Value="10"/>
|
||||||
<Parsing>
|
|
||||||
<SyntaxOptions>
|
|
||||||
<UseAnsiStrings Value="False"/>
|
|
||||||
</SyntaxOptions>
|
|
||||||
</Parsing>
|
|
||||||
<Other>
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
</Other>
|
</Other>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
</Flags>
|
</Flags>
|
||||||
<SessionStorage Value="InIDEConfig"/>
|
<SessionStorage Value="InIDEConfig"/>
|
||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<StringTable ProductVersion=""/>
|
<StringTable ProductVersion=""/>
|
||||||
|
60
components/codetools/examples/proctomethod.lpi
Normal file
60
components/codetools/examples/proctomethod.lpi
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="9"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<LRSInOutputDirectory Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<Title Value="proctomethod"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
|
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="1">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="CodeTools"/>
|
||||||
|
</Item1>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="2">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="proctomethod.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="proctomethod"/>
|
||||||
|
</Unit0>
|
||||||
|
<Unit1>
|
||||||
|
<Filename Value="scanexamples/procsandmethods1.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="ProcsAndMethods1"/>
|
||||||
|
</Unit1>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="10"/>
|
||||||
|
<SearchPaths>
|
||||||
|
<OtherUnitFiles Value="scanexamples"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
</CONFIG>
|
68
components/codetools/examples/proctomethod.lpr
Normal file
68
components/codetools/examples/proctomethod.lpr
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
{
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* This source is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This code is distributed in the hope that it will be useful, but *
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||||
|
* General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* A copy of the GNU General Public License is available on the World *
|
||||||
|
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||||
|
* obtain it by writing to the Free Software Foundation, *
|
||||||
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
Author: Mattias Gaertner
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
Demonstration how to convert a procedure to a method.
|
||||||
|
}
|
||||||
|
program proctomethod;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, CodeCache, CodeToolManager, FileProcs, AVL_Tree, CodeAtom,
|
||||||
|
BasicCodeTools, SourceChanger, CodeTree, FindDeclarationTool,
|
||||||
|
ProcsAndMethods1;
|
||||||
|
|
||||||
|
const
|
||||||
|
ConfigFilename = 'codetools.config';
|
||||||
|
var
|
||||||
|
Filename: string;
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
Tool: TCodeTool;
|
||||||
|
CleanDef: String;
|
||||||
|
ProcNode: TCodeTreeNode;
|
||||||
|
begin
|
||||||
|
CodeToolBoss.SimpleInit(ConfigFilename);
|
||||||
|
|
||||||
|
// load the file
|
||||||
|
Filename:=ExpandFileName(SetDirSeparators('scanexamples/procsandmethods1.pas'));
|
||||||
|
Code:=CodeToolBoss.LoadFile(Filename,false,false);
|
||||||
|
if Code=nil then
|
||||||
|
raise Exception.Create('loading failed '+Filename);
|
||||||
|
|
||||||
|
// parse the unit
|
||||||
|
try
|
||||||
|
CleanDef:='DoSomething(integer)';
|
||||||
|
if not CodeToolBoss.FindProcDeclaration(Code,CleanDef,Tool,ProcNode)
|
||||||
|
then
|
||||||
|
raise Exception.Create('proc not found: "'+CleanDef+'"');
|
||||||
|
|
||||||
|
finally
|
||||||
|
|
||||||
|
end;
|
||||||
|
// write the new source:
|
||||||
|
writeln('-----------------------------------');
|
||||||
|
writeln('New source:');
|
||||||
|
writeln(Code.Source);
|
||||||
|
writeln('-----------------------------------');
|
||||||
|
end.
|
||||||
|
|
@ -0,0 +1,28 @@
|
|||||||
|
unit ProcsAndMethods1;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils;
|
||||||
|
|
||||||
|
type
|
||||||
|
TFoo = class
|
||||||
|
end;
|
||||||
|
|
||||||
|
TBar = class
|
||||||
|
public
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure DoSomething(i: integer);
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure DoSomething(i: integer);
|
||||||
|
begin
|
||||||
|
// code
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -931,7 +931,7 @@ function TMethodJumpingCodeTool.FindSubProcPath(SubProcPath: TStrings;
|
|||||||
if (PathIndex>SubProcPath.Count) or (StartNode=nil) then exit;
|
if (PathIndex>SubProcPath.Count) or (StartNode=nil) then exit;
|
||||||
ProcHead:=SubProcPath[PathIndex];
|
ProcHead:=SubProcPath[PathIndex];
|
||||||
ProcNode:=FindProcNode(StartNode,ProcHead,Attr);
|
ProcNode:=FindProcNode(StartNode,ProcHead,Attr);
|
||||||
DebugLn('TMethodJumpingCodeTool.SearchSubProcPath A ProcHead="',ProcHead,'" Found=',dbgs(ProcNode<>nil));
|
//DebugLn('TMethodJumpingCodeTool.SearchSubProcPath A ProcHead="',ProcHead,'" Found=',dbgs(ProcNode<>nil));
|
||||||
if ProcNode=nil then exit;
|
if ProcNode=nil then exit;
|
||||||
if PathIndex=SubProcPath.Count-1 then begin
|
if PathIndex=SubProcPath.Count-1 then begin
|
||||||
Result:=ProcNode;
|
Result:=ProcNode;
|
||||||
|
Loading…
Reference in New Issue
Block a user