| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- {
- Inno Setup Preprocessor
- Copyright (C) 2001-2002 Alex Yackimoff
- Inno Setup
- Copyright (C) 1997-2025 Jordan Russell
- Portions by Martijn Laan
- For conditions of distribution and use, see LICENSE.TXT.
- }
- unit ISPP.VarUtils;
- interface
- uses
- ISPP.Intf, ISPP.Base, ISPP.Preprocessor;
- function SimplifyLValue(var Src: TIsppVariant): Boolean;
- procedure MakeRValue(var Src: TIsppVariant);
- function GetRValue(const Src: TIsppVariant): TIsppVariant;
- procedure CopyExpVar(Src: TIsppVariant; var Dest: TIsppVariant);
- procedure MakeInt(var Op: TIsppVariant; Value: Int64);
- procedure MakeStr(var Op: TIsppVariant; const Value: string);
- procedure MakeBool(var Op: TIsppVariant; Value: Boolean);
- function TryStrToInt(Str: string; var Int: Integer): Boolean;
- function ToInt(Op: TIsppVariant): TIsppVariant;
- function ToStr(Op: TIsppVariant): TIsppVariant;
- const
- NULL: TIsppVariant = (Typ: evNull; AsStr: ''; AsInt64: 0);
- implementation
- uses
- SysUtils, ISPP.Consts;
- function SimplifyLValue(var Src: TIsppVariant): Boolean;
- begin
- Result := Src.Typ = evLValue;
- if Result then
- while Src.AsPtr^.Typ = evLValue do Src := Src.AsPtr^;
- end;
- procedure MakeRValue(var Src: TIsppVariant);
- begin
- while Src.Typ = evLValue do Src := Src.AsPtr^;
- end;
- function GetRValue(const Src: TIsppVariant): TIsppVariant;
- begin
- Result := Src;
- MakeRValue(Result);
- end;
- procedure CopyExpVar(Src: TIsppVariant; var Dest: TIsppVariant);
- begin
- MakeRValue(Src);
- if Src.Typ = evStr then
- begin
- Dest.Typ := evStr;
- Dest.AsInt64 := 0;
- Dest.AsStr := Src.AsStr;
- end
- else
- Move(Src, Dest, SizeOf(TIsppVariant));
- end;
- procedure MakeInt(var Op: TIsppVariant; Value: Int64);
- begin
- Op.Typ := evInt;
- Op.AsInt64 := Value;
- Op.AsStr := '';
- end;
- procedure MakeStr(var Op: TIsppVariant; const Value: string);
- begin
- Op.Typ := evStr;
- Op.AsInt64 := 0;
- Op.AsStr := Value;
- end;
- procedure MakeBool(var Op: TIsppVariant; Value: Boolean);
- begin
- MakeInt(Op, Int64(Value));
- end;
- function TryStrToInt(Str: string; var Int: Integer): Boolean;
- var
- Err: Integer;
- begin
- if (Length(Str) > 2) and (Str[1] = '0') and ((Str[2] = 'x') or
- (Str[2] = 'X')) then
- Str := '$' + Copy(Str, 3, MaxInt);
- Val(Str, Int, Err);
- Result := Err = 0
- end;
- function ToInt(Op: TIsppVariant): TIsppVariant;
- var
- I: Integer;
- begin
- MakeRValue(Op);
- I := 0;
- if Op.Typ = evStr then
- if (Op.AsStr = '') or TryStrToInt(Op.AsStr, I) then
- MakeInt(Result, I)
- else
- raise EConvertError.CreateFmt('Cannot convert "%s" to integer', [Op.AsStr])
- else
- if Op.Typ = evNull then
- MakeInt(Result, 0)
- else
- CopyExpVar(Op, Result)
- end;
- function ToStr(Op: TIsppVariant): TIsppVariant;
- begin
- MakeRValue(Op);
- if Op.Typ = evInt then
- MakeStr(Result, IntToStr(Op.AsInt64))
- else
- if Op.Typ = evNull then
- MakeStr(Result, '')
- else
- MakeStr(Result, Op.AsStr)
- end;
- end.
|