mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-03 12:20:32 +02:00
codetools: example unit dictionary
git-svn-id: trunk@33662 -
This commit is contained in:
parent
0c5bf06d0c
commit
8dfd0d5a07
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -549,6 +549,8 @@ components/codetools/examples/testscompleteblock/tryif1_result.inc svneol=native
|
||||
components/codetools/examples/testscompleteblock/unit1.pas svneol=native#text/plain
|
||||
components/codetools/examples/testscompleteblock/whilebegin1.inc svneol=native#text/plain
|
||||
components/codetools/examples/testscompleteblock/whilebegin1_result.inc svneol=native#text/plain
|
||||
components/codetools/examples/unitdicttest.lpi svneol=native#text/plain
|
||||
components/codetools/examples/unitdicttest.lpr svneol=native#text/plain
|
||||
components/codetools/examples/usedbyunits.lpi svneol=native#text/plain
|
||||
components/codetools/examples/usedbyunits.lpr svneol=native#text/plain
|
||||
components/codetools/expreval.pas svneol=native#text/pascal
|
||||
|
69
components/codetools/examples/unitdicttest.lpi
Normal file
69
components/codetools/examples/unitdicttest.lpi
Normal file
@ -0,0 +1,69 @@
|
||||
<?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="unitdicttest"/>
|
||||
</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="2">
|
||||
<Item1>
|
||||
<PackageName Value="Cody"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="CodeTools"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Unit0>
|
||||
<Filename Value="unitdicttest.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="unitdicttest"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="scanexamples/simpleunit1.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="SimpleUnit1"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="scanexamples/addeventexample.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="AddEventExample"/>
|
||||
</Unit2>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<SearchPaths>
|
||||
<OtherUnitFiles Value="scanexamples"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</CONFIG>
|
90
components/codetools/examples/unitdicttest.lpr
Normal file
90
components/codetools/examples/unitdicttest.lpr
Normal file
@ -0,0 +1,90 @@
|
||||
{
|
||||
***************************************************************************
|
||||
* *
|
||||
* 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:
|
||||
Demonstrating, how to read, update and use the unitdictionary.
|
||||
}
|
||||
program unitdicttest;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Classes, SysUtils, AVL_Tree, CodeCache, CodeToolManager, FileProcs,
|
||||
BasicCodeTools, SourceChanger, CodeTree, DefineTemplates, unitdictionary,
|
||||
CodeToolsStructs, zstream;
|
||||
|
||||
const
|
||||
ConfigFilename = 'codetools.config';
|
||||
DictionaryFilename = 'dictionary.txt';
|
||||
var
|
||||
Filename: string;
|
||||
Dictionary: TUnitDictionary;
|
||||
UnitSet: TFPCUnitSetCache;
|
||||
CfgCache: TFPCTargetConfigCache;
|
||||
AVLNode: TAVLTreeNode;
|
||||
Item: PStringToStringTreeItem;
|
||||
Directory: String;
|
||||
D2: TUnitDictionary;
|
||||
begin
|
||||
CodeToolBoss.SimpleInit(ConfigFilename);
|
||||
|
||||
Dictionary:=TUnitDictionary.Create;
|
||||
try
|
||||
UnitSet:=CodeToolBoss.GetUnitSetForDirectory('');
|
||||
CfgCache:=UnitSet.GetConfigCache(true);
|
||||
AVLNode:=CfgCache.Units.Tree.FindLowest;
|
||||
Directory:=AppendPathDelim(UnitSet.FPCSourceDirectory)+'packages';
|
||||
while AVLNode<>nil do begin
|
||||
Item:=PStringToStringTreeItem(AVLNode.Data);
|
||||
FileName:=UnitSet.GetUnitSrcFile(Item^.Name,false);
|
||||
//writeln('UnitName=',Item^.Name,' Source=',Filename);
|
||||
if FilenameIsPascalUnit(Filename)
|
||||
and FileIsInPath(Filename,Directory) then begin
|
||||
//writeln('Filename: ',Filename);
|
||||
// parse the unit
|
||||
try
|
||||
Dictionary.ParseUnit(Filename);
|
||||
except
|
||||
on E: Exception do begin
|
||||
writeln(Filename,' Error: ',E.Message);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
AVLNode:=CfgCache.Units.Tree.FindSuccessor(AVLNode);
|
||||
end;
|
||||
|
||||
Dictionary.ConsistencyCheck;
|
||||
Dictionary.SaveToFile(DictionaryFilename);
|
||||
|
||||
D2:=TUnitDictionary.Create;
|
||||
D2.LoadFromFile(DictionaryFilename,false);
|
||||
D2.ConsistencyCheck;
|
||||
|
||||
if not D2.Equals(Dictionary) then
|
||||
raise Exception.Create('SaveToFile/LoadFromFile difference');
|
||||
|
||||
D2.Free;
|
||||
finally
|
||||
Dictionary.Free;
|
||||
end;
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user