/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

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