PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/components/jcf2/Process/BaseVisitor.pas

http://github.com/graemeg/lazarus
Pascal | 113 lines | 49 code | 22 blank | 42 comment | 0 complexity | d898aff6cabf61f70ff91fc15458564d MD5 | raw file
  1unit BaseVisitor;
  2
  3{ AFS 28 Dec 2002
  4
  5  Base class that implments the tree node Visitor interface
  6}
  7
  8{(*}
  9(*------------------------------------------------------------------------------
 10 Delphi Code formatter source code 
 11
 12The Original Code is BaseVisitor, released May 2003.
 13The Initial Developer of the Original Code is Anthony Steele. 
 14Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele.
 15All Rights Reserved. 
 16Contributor(s): Anthony Steele. 
 17
 18The contents of this file are subject to the Mozilla Public License Version 1.1
 19(the "License"). you may not use this file except in compliance with the License.
 20You may obtain a copy of the License at http://www.mozilla.org/NPL/
 21
 22Software distributed under the License is distributed on an "AS IS" basis,
 23WITHOUT WARRANTY OF ANY KIND, either express or implied.
 24See the License for the specific language governing rights and limitations 
 25under the License.
 26
 27Alternatively, the contents of this file may be used under the terms of
 28the GNU General Public License Version 2 or later (the "GPL") 
 29See http://www.gnu.org/licenses/gpl.html
 30------------------------------------------------------------------------------*)
 31{*)}
 32
 33{$I JcfGlobal.inc}
 34
 35interface
 36
 37type
 38
 39  TBaseTreeNodeVisitor = class(TObject)
 40  private
 41    { which visits do I want to do?
 42      This is for speed - don't do the virtual fn call if not needed }
 43    fbHasPreVisit: Boolean;
 44    fbHasPostVisit: Boolean;
 45    fbHasSourceTokenVisit: Boolean;
 46
 47  public
 48    constructor Create; virtual;
 49
 50    { these are called when visiting interior nodes before and after thier children
 51      Must return true if the visited node is deleted, or if nodes are inserted before it
 52      ie if the curent node's index is not correct and the same after the visit}
 53    procedure PreVisitParseTreeNode(const {%H-}pcNode: TObject); virtual;
 54    procedure PostVisitParseTreeNode(const {%H-}pcNode: TObject); virtual;
 55
 56    { this is called when visiting a leaf node (ie a source token) }
 57    function VisitSourceToken(const {%H-}pcToken: TObject): Boolean; virtual;
 58
 59    function FinalSummary(out psMessage: string): boolean; virtual;
 60    function IsIncludedInSettings: boolean; virtual;
 61
 62    property HasPreVisit: boolean read fbHasPreVisit write fbHasPreVisit;
 63    property HasPostVisit: boolean read fbHasPostVisit write fbHasPostVisit;
 64    property HasSourceTokenVisit: boolean read fbHasSourceTokenVisit write fbHasSourceTokenVisit;
 65  end;
 66
 67type
 68  TTreeNodeVisitorType = class of TBaseTreeNodeVisitor;
 69
 70implementation
 71
 72
 73// need a virtual constructor for the create-by-class-ref
 74constructor TBaseTreeNodeVisitor.Create;
 75begin
 76  inherited;
 77
 78  { most visitors just touch the leaves }
 79  fbHasPreVisit := False;
 80  fbHasPostVisit := False;
 81  fbHasSourceTokenVisit := True;
 82end;
 83
 84function TBaseTreeNodeVisitor.FinalSummary(out psMessage: string): boolean;
 85begin
 86  // no message
 87  Result    := False;
 88  psMessage := '';
 89end;
 90
 91procedure TBaseTreeNodeVisitor.PreVisitParseTreeNode(const pcNode: TObject);
 92begin
 93  // do nothing, here for override
 94end;
 95
 96procedure TBaseTreeNodeVisitor.PostVisitParseTreeNode(const pcNode: TObject);
 97begin
 98  // do nothing, here for override
 99end;
100
101function TBaseTreeNodeVisitor.VisitSourceToken(const pcToken: TObject): Boolean;
102begin
103  // do nothing, here for override
104  Result := False;
105end;
106
107function TBaseTreeNodeVisitor.IsIncludedInSettings: boolean;
108begin
109  // here for override
110  Result := True;
111end;
112
113end.