paxCompiler/help/demo_explorer.htm
Dalibor Marković 9d0de424e8
Init
Signed-off-by: Dalibor Marković <dalibor31@gmail.com>
2024-07-06 22:28:12 +02:00

270 lines
10 KiB
HTML

<html>
<head>
<link rel=stylesheet type="text/css" href="styles.css">
</head>
<body>
<H2>
paxCompiler for Delphi. Code explorer.
</H2>
<hr>
<img src="code_expl.jpg" border="0" alt ="Code explorer" ></img>
<blockquote>
<pre>
<font color="blue"><b>unit</b></font> Unit1;
<font color="blue"><b>interface</b></font>
<font color="blue"><b>uses</b></font>
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, PaxCompilerExplorer, PaxCompiler, StdCtrls, ExtCtrls, ComCtrls,
IMPORT_Classes;
<font color="blue"><b>type</b></font>
TForm1 = <font color="blue"><b>class</b></font>(TForm)
Panel1: TPanel;
Memo1: TMemo;
Button1: TButton;
PaxCompiler1: TPaxCompiler;
PaxPascalLanguage1: TPaxPascalLanguage;
PaxCompilerExplorer1: TPaxCompilerExplorer;
TreeView1: TTreeView;
<font color="blue"><b>procedure</b></font> Button1Click(Sender: TObject);
<font color="blue"><b>procedure</b></font> TreeView1DblClick(Sender: TObject);
<font color="blue"><b>private</b></font>
{ Private declarations }
L: TList;
<font color="blue"><b>public</b></font>
{ Public declarations }
<font color="blue"><b>procedure</b></font> BuildTree;
<font color="blue"><b>procedure</b></font> EnumProc(Id: Integer;
Host: Boolean;
Kind: TMemberKind;
Data: Pointer);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
Form1: TForm1;
<font color="blue"><b>implementation</b></font>
{$R *.dfm}
<font color="blue"><b>procedure</b></font> TForm1.Button1Click(Sender: TObject);
<font color="blue"><b>var</b></font>
I: Integer;
<font color="blue"><b>begin</b></font>
PaxCompiler1.Reset;
PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
PaxCompiler1.AddModule(<font color="Red">'1'</font>, <font color="Red">'Pascal'</font>);
PaxCompiler1.AddCode(<font color="Red">'1'</font>, Memo1.Lines.Text);
<font color="blue"><b>if</b></font> PaxCompiler1.Compile <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
PaxCompilerExplorer1.RegisterCompiler(PaxCompiler1);
BuildTree;
<font color="blue"><b>end</b></font>
<font color="blue"><b>else</b></font>
<font color="blue"><b>for</b></font> I:=0 <font color="blue"><b>to</b></font> PaxCompiler1.ErrorCount - 1 <font color="blue"><b>do</b></font>
ShowMessage(PaxCompiler1.ErrorMessage[I]);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.BuildTree;
<font color="blue"><b>var</b></font>
N, N2: TTreeNode;
I: Integer;
<font color="blue"><b>begin</b></font>
L := TList.Create;
<font color="blue"><b>try</b></font>
TreeView1.Items.Clear;
N := TreeView1.Items.Add(<font color="blue"><b>nil</b></font>, <font color="Red">'Used namespaces'</font>);
L.Add(N);
PaxCompilerExplorer1.EnumMembers(0, true, mkNamespace, EnumProc, N);
PaxCompilerExplorer1.EnumMembers(0, false, mkNamespace, EnumProc, N);
N := TreeView1.Items.Add(<font color="blue"><b>nil</b></font>, <font color="Red">'Noname namespace'</font>);
N2 := TreeView1.Items.AddChild(N, <font color="Red">'Types'</font>);
L.Add(N2);
PaxCompilerExplorer1.EnumMembers(0, false, mkType, EnumProc, N2);
N2 := TreeView1.Items.AddChild(N, <font color="Red">'Procedures'</font>);
L.Add(N2);
PaxCompilerExplorer1.EnumMembers(0, false, mkProcedure, EnumProc, N2);
N2 := TreeView1.Items.AddChild(N, <font color="Red">'Functions'</font>);
L.Add(N2);
PaxCompilerExplorer1.EnumMembers(0, false, mkFunction, EnumProc, N2);
N2 := TreeView1.Items.AddChild(N, <font color="Red">'Constants'</font>);
L.Add(N2);
PaxCompilerExplorer1.EnumMembers(0, false, mkConst, EnumProc, N2);
N2 := TreeView1.Items.AddChild(N, <font color="Red">'Variables'</font>);
L.Add(N2);
PaxCompilerExplorer1.EnumMembers(0, false, mkVar, EnumProc, N2);
<font color="blue"><b>finally</b></font>
<font color="blue"><b>for</b></font> I := L.Count - 1 <font color="blue"><b>downto</b></font> 0 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
N2 := TTreeNode(L[I]);
<font color="blue"><b>if</b></font> N2.Count = 0 <font color="blue"><b>then</b></font>
N2.Delete;
<font color="blue"><b>end</b></font>;
L.Free;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.EnumProc(Id: Integer;
Host: Boolean;
Kind: TMemberKind;
Data: Pointer);
<font color="blue"><b>var</b></font>
N, N2, N3: TTreeNode;
Name: <font color="blue"><b>String</b></font>;
TypeName: <font color="blue"><b>String</b></font>;
<font color="blue"><b>begin</b></font>
N := TTreeNode(Data);
Name := PaxCompilerExplorer1.Names[Id];
TypeName := PaxCompilerExplorer1.TypeNames[Id];
<font color="blue"><b>with</b></font> TreeView1.Items <font color="blue"><b>do</b></font>
<font color="blue"><b>case</b></font> Kind <font color="blue"><b>of</b></font>
mkProcedure, mkFunction, mkConstructor, mkDestructor:
<font color="blue"><b>begin</b></font>
N2 := AddChildObject(N, Name, TObject(Id));
N3 := AddChild(N2, <font color="Red">'Parameters'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkParam, EnumProc, N3);
N3 := AddChild(N2, <font color="Red">'Local variables'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkVar, EnumProc, N3);
N3 := AddChild(N2, <font color="Red">'Local constants'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkConst, EnumProc, N3);
N3 := AddChild(N2, <font color="Red">'Local types'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkType, EnumProc, N3);
N3 := TreeView1.Items.AddChild(N2, <font color="Red">'Nested procedures'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, false, mkProcedure, EnumProc, N3);
N3 := TreeView1.Items.AddChild(N2, <font color="Red">'Nested functions'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, false, mkFunction, EnumProc, N3);
<font color="blue"><b>end</b></font>;
mkParam: AddChildObject(N, Name + <font color="Red">': '</font> + TypeName, TObject(Id));
mkVar: AddChildObject(N, Name + <font color="Red">': '</font> + TypeName, TObject(Id));
mkConst: AddChildObject(N, Name + <font color="Red">': '</font> + TypeName, TObject(Id));
mkField: AddChildObject(N, Name + <font color="Red">': '</font> + TypeName, TObject(Id));
mkProperty: AddChildObject(N, Name + <font color="Red">': '</font> + TypeName, TObject(Id));
mkType:
<font color="blue"><b>begin</b></font>
N2 := AddChildObject(N, Name, TObject(Id));
<font color="blue"><b>if</b></font> PaxCompilerExplorer1.IsRecordType(Id) <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
N3 := AddChild(N2, <font color="Red">'Fields'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkField, EnumProc, N3);
<font color="blue"><b>end</b></font>
<font color="blue"><b>else</b></font> <font color="blue"><b>if</b></font> PaxCompilerExplorer1.IsClassType(Id) <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
N3 := AddChild(N2, <font color="Red">'Fields'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkField, EnumProc, N3);
N3 := AddChild(N2, <font color="Red">'Properties'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkProperty, EnumProc, N3);
N3 := TreeView1.Items.AddChild(N2, <font color="Red">'Constructors'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, false, mkConstructor, EnumProc, N3);
N3 := TreeView1.Items.AddChild(N2, <font color="Red">'Destructor'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, false, mkDestructor, EnumProc, N3);
N3 := TreeView1.Items.AddChild(N2, <font color="Red">'Class procedures'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, false, mkProcedure, EnumProc, N3);
N3 := TreeView1.Items.AddChild(N2, <font color="Red">'Class functions'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, false, mkFunction, EnumProc, N3);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
mkNamespace:
<font color="blue"><b>begin</b></font>
N2 := AddChildObject(N, Name, TObject(Id));
N3 := AddChild(N2, <font color="Red">'Constants'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkConst, EnumProc, N3);
N3 := AddChild(N2, <font color="Red">'Variables'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkVar, EnumProc, N3);
N3 := AddChild(N2, <font color="Red">'Procedures'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkProcedure, EnumProc, N3);
N3 := AddChild(N2, <font color="Red">'Types'</font>);
L.Add(N3);
PaxCompilerExplorer1.EnumMembers(Id, Host, mkType, EnumProc, N3);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.TreeView1DblClick(Sender: TObject);
<font color="blue"><b>var</b></font>
N: TTreeNode;
Id, Position: Integer;
S: <font color="blue"><b>String</b></font>;
<font color="blue"><b>begin</b></font>
N := TTreeView(Sender).Selected;
<font color="blue"><b>if</b></font> N = <font color="blue"><b>nil</b></font> <font color="blue"><b>then</b></font>
Exit;
Id := Integer(N.Data);
<font color="blue"><b>if</b></font> Id = 0 <font color="blue"><b>then</b></font>
Exit;
S := PaxCompilerExplorer1.Names[Id];
Position := PaxCompilerExplorer1.Positions[Id];
<font color="blue"><b>if</b></font> Id <> 0 <font color="blue"><b>then</b></font>
<font color="blue"><b>with</b></font> Memo1 <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
SetFocus;
SelStart := Position;
SelLength := Length(S);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>.
</pre>
</blockquote>
<p>
<HR>
<font size = 1 color ="gray">
Copyright &copy; 2006-2009
VIRT Laboratory. All rights reserved.
</font>
</body>
</html>