/components/jcf2/Settings/SetPreProcessor.pas

http://github.com/graemeg/lazarus · Pascal · 153 lines · 85 code · 36 blank · 32 comment · 2 complexity · fdffcdf441659b9291380c330c0fcc90 MD5 · raw file

  1. unit SetPreProcessor;
  2. {(*}
  3. (*------------------------------------------------------------------------------
  4. Delphi Code formatter source code
  5. The Original Code is SetPreprocessor, released 2003
  6. The Initial Developer of the Original Code is Anthony Steele.
  7. Portions created by Anthony Steele are Copyright (C) 2003-2008 Anthony Steele.
  8. All Rights Reserved.
  9. Contributor(s): Anthony Steele.
  10. The contents of this file are subject to the Mozilla Public License Version 1.1
  11. (the "License"). you may not use this file except in compliance with the License.
  12. You may obtain a copy of the License at http://www.mozilla.org/NPL/
  13. Software distributed under the License is distributed on an "AS IS" basis,
  14. WITHOUT WARRANTY OF ANY KIND, either express or implied.
  15. See the License for the specific language governing rights and limitations
  16. under the License.
  17. Alternatively, the contents of this file may be used under the terms of
  18. the GNU General Public License Version 2 or later (the "GPL")
  19. See http://www.gnu.org/licenses/gpl.html
  20. ------------------------------------------------------------------------------*)
  21. {*)}
  22. {$I JcfGlobal.inc}
  23. interface
  24. { settings for preprocessor
  25. }
  26. uses
  27. { delphi }
  28. Classes,
  29. { local }
  30. JcfSetBase, SettingsStream;
  31. type
  32. TSetPreProcessor = class(TSetBase)
  33. private
  34. fbEnabled: boolean;
  35. fcDefinedSymbols: TStringList;
  36. fcDefinedOptions: TStringList;
  37. procedure AddDefaultSymbols;
  38. procedure AddDefaultOptions;
  39. public
  40. constructor Create;
  41. destructor Destroy; override;
  42. procedure WriteToStream(const pcOut: TSettingsOutput); override;
  43. procedure ReadFromStream(const pcStream: TSettingsInput); override;
  44. property Enabled: boolean Read fbEnabled Write fbEnabled;
  45. function OptionIsDefined(const psOption: string): boolean;
  46. function SymbolIsDefined(const psSymbol: string): boolean;
  47. property DefinedSymbols: TStringList Read fcDefinedSymbols Write fcDefinedSymbols;
  48. property DefinedOptions: TStringList Read fcDefinedOptions Write fcDefinedOptions;
  49. end;
  50. implementation
  51. uses SysUtils;
  52. const
  53. REG_ENABLED = 'Enabled';
  54. REG_DEFINED_SYMBOLS = 'DefinedSymbols';
  55. REG_DEFINED_OPTIONS = 'DefinedOptions';
  56. { TSetPreProcessor }
  57. constructor TSetPreProcessor.Create;
  58. begin
  59. inherited;
  60. SetSection('PreProcessor');
  61. fcDefinedSymbols := TStringList.Create;
  62. //fcDefinedSymbols.Sorted := True;
  63. fcDefinedSymbols.Duplicates := dupIgnore;
  64. fcDefinedOptions := TStringList.Create;
  65. //fcDefinedOptions.Sorted := True;
  66. fcDefinedOptions.Duplicates := dupIgnore;
  67. end;
  68. destructor TSetPreProcessor.Destroy;
  69. begin
  70. FreeAndNil(fcDefinedSymbols);
  71. FreeAndNil(fcDefinedOptions);
  72. inherited;
  73. end;
  74. procedure TSetPreProcessor.AddDefaultSymbols;
  75. begin
  76. fcDefinedSymbols.Add('MSWINDOWS');
  77. fcDefinedSymbols.Add('WIN32');
  78. fcDefinedSymbols.Add('DELPHI5_UP');
  79. end;
  80. procedure TSetPreProcessor.AddDefaultOptions;
  81. begin
  82. end;
  83. procedure TSetPreProcessor.ReadFromStream(const pcStream: TSettingsInput);
  84. begin
  85. Assert(pcStream <> nil);
  86. fbEnabled := pcStream.Read(REG_ENABLED, True);
  87. fcDefinedSymbols.Sorted := False;
  88. if not pcStream.Read(REG_DEFINED_SYMBOLS, fcDefinedSymbols) then
  89. AddDefaultSymbols;
  90. fcDefinedSymbols.Sort;
  91. fcDefinedSymbols.Sorted := True;
  92. fcDefinedOptions.Sorted := False;
  93. if not pcStream.Read(REG_DEFINED_OPTIONS, fcDefinedOptions) then
  94. AddDefaultOptions;
  95. fcDefinedOptions.Sort;
  96. fcDefinedOptions.Sorted := True;
  97. end;
  98. procedure TSetPreProcessor.WriteToStream(const pcOut: TSettingsOutput);
  99. begin
  100. Assert(pcOut <> nil);
  101. pcOut.Write(REG_ENABLED, fbEnabled);
  102. pcOut.Write(REG_DEFINED_SYMBOLS, fcDefinedSymbols);
  103. pcOut.Write(REG_DEFINED_OPTIONS, fcDefinedOptions);
  104. end;
  105. function TSetPreProcessor.OptionIsDefined(const psOption: string): boolean;
  106. begin
  107. Result := fcDefinedOptions.IndexOf(psOption) >= 0;
  108. end;
  109. function TSetPreProcessor.SymbolIsDefined(const psSymbol: string): boolean;
  110. begin
  111. Result := fcDefinedSymbols.IndexOf(psSymbol) >= 0;
  112. end;
  113. end.