File: getcontext.lpr

package info (click to toggle)
lazarus 1.2.4%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 170,220 kB
  • ctags: 115,165
  • sloc: pascal: 1,386,898; xml: 257,878; sh: 2,935; java: 603; makefile: 549; perl: 297; sql: 174; ansic: 137
file content (45 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
program GetContext;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils, FileProcs, CodeCache, CodeToolManager, DefineTemplates,
  CodeToolsConfig, GetContextExample, IdentCompletionTool, FindDeclarationTool;

const
  ConfigFilename = 'codetools.config';
var
  Code: TCodeBuffer;
  CodeContexts: TCodeContextInfo;
  i: Integer;
  Filename: String;
  Item: TCodeContextInfoItem;
begin
  // setup the Options
  CodeToolBoss.SimpleInit(ConfigFilename);

  // Example: find declaration of 'TObject'

  // Step 1: load the file
  Filename:=CleanAndExpandFilename('scanexamples/getcontextexample.pas');
  Code:=CodeToolBoss.LoadFile(Filename,false,false);
  if Code=nil then
    raise Exception.Create('loading failed '+Filename);

  // Step 2: find context
  if CodeToolBoss.FindCodeContext(Code,7,14,CodeContexts) then
  begin
    writeln('Contexts found: Count=',CodeContexts.Count);
    for i:=0 to CodeContexts.Count-1 do begin
      Item:=CodeContexts[i];
      write('i=',i,' ',ExprTypeToString(Item.Expr));
      if Item.Expr.Context.Node<>nil then
        write(' ',Item.Expr.Context.Tool.ExtractNode(Item.Expr.Context.Node,[]));
      writeln;
    end;
  end else begin
    writeln('Contexts not found: ',CodeToolBoss.ErrorMessage);
  end;
  CodeContexts.Free;
end.