ISPP.Base.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {
  2. Inno Setup Preprocessor
  3. Copyright (C) 2001-2002 Alex Yackimoff
  4. Inno Setup
  5. Copyright (C) 1997-2025 Jordan Russell
  6. Portions by Martijn Laan
  7. For conditions of distribution and use, see LICENSE.TXT.
  8. }
  9. unit ISPP.Base;
  10. interface
  11. uses ISPP.Intf, SysUtils;
  12. type
  13. ICallContext = interface;
  14. PIsppVariant = ^TIsppVariant;
  15. TIsppVariant = record
  16. Typ: TIsppVarType;
  17. AsStr: string;
  18. AsCallContext: ICallContext;
  19. function AsBoolean: Boolean;
  20. function AsCardinal: Cardinal;
  21. function AsInteger: Integer;
  22. function AsWord: Word;
  23. case TIsppVarType of
  24. evInt: (AsInt64: Int64);
  25. evLValue: (AsPtr: PIsppVariant);
  26. end;
  27. TIsppParamFlags = set of (pfTypeDefined, pfHasDefault, pfByRef, pfFunc);
  28. TIsppMacroParam = record
  29. Name: string;
  30. ParamFlags: TIsppParamFlags;
  31. DefValue: TIsppVariant;
  32. end;
  33. PParamList = ^TParamList;
  34. TParamList = array[Byte] of TIsppMacroParam;
  35. TArgGroupingStyle = (agsNone, agsParenteses, agsBrackets, agsBraces);
  36. ICallContext = interface
  37. procedure Add(const Name: string; const Value: TIsppVariant);
  38. function Call: TIsppVariant;
  39. function GroupingStyle: TArgGroupingStyle;
  40. procedure Clone(out NewContext: ICallContext);
  41. end;
  42. TIdentType = (itUnknown, itVariable, itMacro, itFunc, itDefinedFunc,
  43. itTypeOfFunc, itDimOfFunc);
  44. IIdentManager = interface
  45. function GetIdent(const Name: string; out CallContext: ICallContext): TIdentType;
  46. function Defined(const Name: string): Boolean;
  47. function TypeOf(const Name: string): Byte;
  48. function DimOf(const Name: string): Integer;
  49. end;
  50. function GetOption(const Options: TOptions; Option: Char): Boolean;
  51. procedure SetOption(var Options: TOptions; Option: Char; Value: Boolean);
  52. implementation
  53. uses
  54. ISPP.Consts;
  55. function GetOption(const Options: TOptions; Option: Char): Boolean;
  56. begin
  57. Result := (Ord(UpCase(Option)) - Ord('A')) in Options
  58. end;
  59. procedure SetOption(var Options: TOptions; Option: Char; Value: Boolean);
  60. begin
  61. if Value then
  62. Include(Options, Ord(UpCase(Option)) - Ord('A'))
  63. else
  64. Exclude(Options, Ord(UpCase(Option)) - Ord('A'))
  65. end;
  66. { TIsppVariant }
  67. function TIsppVariant.AsBoolean: Boolean;
  68. begin
  69. case Typ of
  70. evNull: Result := False;
  71. evInt: Result := AsInt64 <> 0;
  72. else
  73. Result := AsStr <> '';
  74. end;
  75. end;
  76. function TIsppVariant.AsCardinal: Cardinal;
  77. begin
  78. const I = AsInt64;
  79. if (I < Low(Result)) or (I > High(Result)) then
  80. raise Exception.Create(SRangeCheckError);
  81. Result := Cardinal(I);
  82. end;
  83. function TIsppVariant.AsInteger: Integer;
  84. begin
  85. const I = AsInt64;
  86. if (I < Low(Result)) or (I > High(Result)) then
  87. raise Exception.Create(SRangeCheckError);
  88. Result := Integer(I);
  89. end;
  90. function TIsppVariant.AsWord: Word;
  91. begin
  92. const I = AsInt64;
  93. if (I < Low(Result)) or (I > High(Result)) then
  94. raise Exception.Create(SRangeCheckError);
  95. Result := Word(I);
  96. end;
  97. end.