Browse Source

ISPP cleanup. No actual changes.

Martijn Laan 5 years ago
parent
commit
434412d6c6

+ 6 - 2
Projects/ISPP/CParser.pas → Projects/ISPP/CTokenizer.pas

@@ -1,10 +1,14 @@
 {
   Inno Setup Preprocessor
   Copyright (C) 2001-2002 Alex Yackimoff
-  $Id: CParser.pas,v 1.3 2009/04/01 15:47:44 mlaan Exp $
+
+  Inno Setup
+  Copyright (C) 1997-2020 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
 }
 
-unit CParser;
+unit CTokenizer;
 
 interface
 

+ 11 - 9
Projects/ISPP/ISPP.dpr

@@ -1,6 +1,11 @@
 {
   Inno Setup Preprocessor
   Copyright (C) 2001-2002 Alex Yackimoff
+  
+  Inno Setup
+  Copyright (C) 1997-2020 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
 }
 
 library ISPP;
@@ -10,25 +15,23 @@ library ISPP;
 {$SETPESUBSYSVERSION 6.0}
 {$WEAKLINKRTTI ON}
 {$I ..\Version.inc}
-{$R *.RES}
 
 uses
   SysUtils,
-  //IsppDebug in 'IsppDebug.pas',
   Windows,
   Classes,
   CompPreprocInt in '..\CompPreprocInt.pas',
   IsppPreprocess in 'IsppPreprocess.pas',
-  IsppTranslate in 'IsppTranslate.pas',
+  IsppPreprocessor in 'IsppPreprocessor.pas',
   IsppFuncs in 'IsppFuncs.pas',
   IsppVarUtils in 'IsppVarUtils.pas',
   IsppConsts in 'IsppConsts.pas',
-  IsppStacks in 'IsppStacks.pas',
+  IsppStack in 'IsppStack.pas',
   IsppIntf in 'IsppIntf.pas',
   IsppParser in 'IsppParser.pas',
   IsppIdentMan in 'IsppIdentMan.pas',
   IsppSessions in 'IsppSessions.pas',
-  CParser in 'CParser.pas',
+  CTokenizer in 'CTokenizer.pas',
   IsppBase in 'IsppBase.pas',
   PathFunc in '..\..\Components\PathFunc.pas',
   CmnFunc2 in '..\CmnFunc2.pas',
@@ -37,11 +40,10 @@ uses
   MD5 in '..\MD5.pas',
   SHA1 in '..\SHA1.pas',
   Struct in '..\Struct.pas';
-  //IsppExceptWindow in 'IsppExceptWindow.pas' {IsppExceptWnd};
+  
+{$R *.RES}
 
-const
-  FuncNameSuffix = {$IFDEF UNICODE} 'W' {$ELSE} 'A' {$ENDIF};
 exports
-  ISPreprocessScript name 'ISPreprocessScript' + FuncNameSuffix;
+  ISPreprocessScript name 'ISPreprocessScriptW';
 
 end.

+ 5 - 0
Projects/ISPP/IsppConsts.pas

@@ -1,6 +1,11 @@
 {
   Inno Setup Preprocessor
   Copyright (C) 2001-2002 Alex Yackimoff
+
+  Inno Setup
+  Copyright (C) 1997-2020 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
 }
 
 unit IsppConsts;

+ 0 - 59
Projects/ISPP/IsppExceptWindow.dfm

@@ -1,59 +0,0 @@
-object IsppExceptWnd: TIsppExceptWnd
-  Left = 307
-  Top = 155
-  Width = 532
-  Height = 355
-  BorderIcons = []
-  Caption = 'Inno Setup Preprocessor Exception'
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'MS Shell Dlg 2'
-  Font.Style = []
-  OldCreateOrder = False
-  Position = poScreenCenter
-  OnShow = FormShow
-  DesignSize = (
-    524
-    328)
-  PixelsPerInch = 96
-  TextHeight = 13
-  object PaintBox1: TPaintBox
-    Left = 8
-    Top = 8
-    Width = 32
-    Height = 32
-    OnPaint = PaintBox1Paint
-  end
-  object mmLog: TMemo
-    Left = 48
-    Top = 8
-    Width = 470
-    Height = 284
-    Anchors = [akLeft, akTop, akRight, akBottom]
-    Color = clBtnFace
-    Font.Charset = DEFAULT_CHARSET
-    Font.Color = clWindowText
-    Font.Height = -11
-    Font.Name = 'Courier New'
-    Font.Style = []
-    ParentFont = False
-    ReadOnly = True
-    ScrollBars = ssVertical
-    TabOrder = 0
-    WantReturns = False
-  end
-  object CloseBtn: TButton
-    Left = 441
-    Top = 299
-    Width = 75
-    Height = 25
-    Anchors = [akRight, akBottom]
-    Cancel = True
-    Caption = 'Close'
-    Default = True
-    ModalResult = 2
-    TabOrder = 1
-  end
-end

+ 0 - 39
Projects/ISPP/IsppExceptWindow.pas

@@ -1,39 +0,0 @@
-unit IsppExceptWindow;
-
-interface
-
-uses
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, StdCtrls, ExtCtrls;
-
-type
-  TIsppExceptWnd = class(TForm)
-    mmLog: TMemo;
-    CloseBtn: TButton;
-    PaintBox1: TPaintBox;
-    procedure FormShow(Sender: TObject);
-    procedure PaintBox1Paint(Sender: TObject);
-  private
-    FIconHandle: HICON;
-  public
-  end;
-
-var
-  IsppExceptWnd: TIsppExceptWnd;
-
-implementation
-
-{$R *.dfm}
-
-procedure TIsppExceptWnd.FormShow(Sender: TObject);
-begin
-  FIconHandle := LoadIcon(0, IDI_HAND);
-  MessageBeep(MB_ICONHAND);
-end;
-
-procedure TIsppExceptWnd.PaintBox1Paint(Sender: TObject);
-begin
-  DrawIcon(PaintBox1.Canvas.Handle, 0, 0, FIconHandle)
-end;
-
-end.

+ 11 - 32
Projects/ISPP/IsppFuncs.pas

@@ -1,6 +1,11 @@
 {
   Inno Setup Preprocessor
   Copyright (C) 2001-2002 Alex Yackimoff
+
+  Inno Setup
+  Copyright (C) 1997-2020 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
 }
 
 unit IsppFuncs;
@@ -10,9 +15,9 @@ interface
 {$I ..\Version.inc}
 
 uses
-  Windows, Classes, IsppVarUtils, IsppIntf, IsppTranslate, IsppParser;
+  Windows, Classes, IsppVarUtils, IsppIntf, IsppPreprocessor, IsppParser;
 
-procedure Register(Preproc: TPreprocessor);
+procedure RegisterFunctions(Preproc: TPreprocessor);
 
 implementation
 
@@ -32,32 +37,6 @@ begin
     Preprocessor.SourcePath));
 end;
 
-{$IF RTLVersion < 18}  { < Delphi 2006 }
-function FileAge(const FileName: string; out FileDateTime: TDateTime): Boolean;
-var
-  Handle: THandle;
-  FindData: TWin32FindData;
-  LSystemTime: TSystemTime;
-  LocalFileTime: TFileTime;
-begin
-  Result := False;
-  Handle := FindFirstFile(PChar(FileName), FindData);
-  if Handle <> INVALID_HANDLE_VALUE then
-  begin
-    Windows.FindClose(Handle);
-    if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
-    begin
-      Result := True;
-      FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
-      FileTimeToSystemTime(LocalFileTime, LSystemTime);
-      with LSystemTime do
-        FileDateTime := EncodeDate(wYear, wMonth, wDay) +
-          EncodeTime(wHour, wMinute, wSecond, wMilliSeconds);
-    end;
-  end;
-end;
-{$IFEND}
-
 function CheckParams(const Params: IIsppFuncParams;
   Types: array of TIsppVarType; Minimum: Byte; var Error: TIsppFuncResult): Boolean;
 var
@@ -1768,7 +1747,7 @@ begin
   if CheckParams(Params, [evStr], 1, Result) then
   try
     with IInternalFuncParams(Params) do begin
-      { Also see Pragma in IsppTranslate }
+      { Also see Pragma in IsppPreprocessor }
       TPreprocessor(Ext).StatusMsg(Get(0).AsStr, []);
       ResPtr^ := NULL;
     end;
@@ -1787,7 +1766,7 @@ begin
   if CheckParams(Params, [evStr], 1, Result) then
   try
     with IInternalFuncParams(Params) do begin
-      { Also see Pragma in IsppTranslate }
+      { Also see Pragma in IsppPreprocessor }
       TPreprocessor(Ext).WarningMsg(Get(0).AsStr, []);
       ResPtr^ := NULL;
     end;
@@ -1810,7 +1789,7 @@ begin
   if CheckParams(Params, [evStr], 1, Result) then
   try
     with IInternalFuncParams(Params) do begin
-      { Also see Pragma and pcErrorDir in IsppTranslate }
+      { Also see Pragma and pcErrorDir in IsppPreprocessor }
       ErrorMsg := Get(0).AsStr;
       if ErrorMsg = '' then ErrorMsg := 'Error';
       CatchException := False;
@@ -1828,7 +1807,7 @@ begin
   end;
 end;
 
-procedure Register(Preproc: TPreprocessor);
+procedure RegisterFunctions(Preproc: TPreprocessor);
 begin
   with Preproc do
   begin

+ 2 - 2
Projects/ISPP/IsppIdentMan.pas

@@ -3,7 +3,7 @@
   Copyright (C) 2001-2002 Alex Yackimoff
 
   Inno Setup
-  Copyright (C) 1997-2010 Jordan Russell
+  Copyright (C) 1997-2020 Jordan Russell
   Portions by Martijn Laan
   For conditions of distribution and use, see LICENSE.TXT.
 }
@@ -118,7 +118,7 @@ const
 
 implementation
 
-uses Windows, Types, IsppTranslate, CParser, IsppParser, IsppVarUtils, IsppConsts,
+uses Windows, Types, IsppPreprocessor, CTokenizer, IsppParser, IsppVarUtils, IsppConsts,
   IsppSessions;
 
 const

+ 1 - 1
Projects/ISPP/IsppParser.pas

@@ -12,7 +12,7 @@ unit IsppParser;
 
 interface
 
-uses IsppIntf, IsppBase, IsppIdentMan, CParser;
+uses IsppIntf, IsppBase, IsppIdentMan, CTokenizer;
 
 type
 

+ 8 - 4
Projects/ISPP/IsppPreprocess.pas

@@ -1,7 +1,11 @@
 {
   Inno Setup Preprocessor
   Copyright (C) 2001-2002 Alex Yackimoff
-  $Id: IsppPreprocess.pas,v 1.3 2010/12/30 15:26:34 mlaan Exp $
+ 
+  Inno Setup
+  Copyright (C) 1997-2020 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
 }
 
 unit IsppPreprocess;
@@ -17,7 +21,7 @@ implementation
 
 uses
   SysUtils, CmnFunc2, PathFunc,
-  IsppBase, IsppTranslate, IsppSessions, IsppIntf, IsppIdentMan, IsppVarUtils, IsppConsts;
+  IsppBase, IsppPreprocessor, IsppSessions, IsppIntf, IsppIdentMan, IsppVarUtils, IsppConsts;
 
 var
   LastPreprocOutput: string;
@@ -272,13 +276,13 @@ begin
         Result := ispeSilentAbort
       else
       begin
-        while Preprocessor.GetNext(LineFilename, LineNumber, LineText) do
+        while Preprocessor.GetNextOutputLine(LineFilename, LineNumber, LineText) do
           Params.LineOutProc(Params.CompilerData, PChar(LineFilename),
             LineNumber, PChar(LineText));
         Result := ispeSuccess;
       end;
     finally
-      LastPreprocOutput := Preprocessor.GetAll;
+      LastPreprocOutput := Preprocessor.GetOutput;
       Params.PreprocOutput := PChar(LastPreprocOutput);
       Preprocessor.Free;
     end;

+ 44 - 51
Projects/ISPP/IsppTranslate.pas → Projects/ISPP/IsppPreprocessor.pas

@@ -1,20 +1,22 @@
 {
   Inno Setup Preprocessor
   Copyright (C) 2001-2002 Alex Yackimoff
-  $Id: IsppTranslate.pas,v 1.17 2011/04/08 04:54:45 jr Exp $
+  
+  Inno Setup
+  Copyright (C) 1997-2020 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
 }
 
-unit IsppTranslate;
+unit IsppPreprocessor;
 
 interface
 
 uses Windows, SysUtils, Classes, CompPreprocInt, IniFiles, Registry, IsppIntf,
-  IsppBase, IsppStacks, IsppIdentMan, IsppParser;
+  IsppBase, IsppStack, IsppIdentMan, IsppParser;
 
 {$I ..\Version.inc}
 
-function GetTempFileName(const Original: string): string;
-
 type
 
   TPreprocessor = class;
@@ -94,6 +96,10 @@ type
     function CheckFile(const FileName: string): Boolean;
     function EmitDestination: TStringList;
     procedure SendMsg(Msg: string; Typ: TIsppMessageType);
+    function GetFileName(Code: Integer): string;
+    function GetLineNumber(Code: Integer): Word;
+    procedure RaiseErrorEx(const Message: string; Column: Integer);
+    procedure ExecProc(Body: TStrings);
   protected
     function GetDefaultScope: TDefineScope;
     procedure SetDefaultScope(Scope: TDefineScope);
@@ -122,21 +128,16 @@ type
     procedure VerboseMsg(Level: Byte; const Msg: string; const Args: array of const);
     procedure StatusMsg(const Msg: string; const Args: array of const);
     procedure WarningMsg(const Msg: string; const Args: array of const);
-    procedure AddLine(const LineRead: string);
-    function GetAll: String;
-    function GetFileName(Code: Integer): string;
-    function GetLineNumber(Code: Integer): Word;
-    function GetNext(var LineFilename: string; var LineNumber: Integer;
+    function GetOutput: String;
+    function GetNextOutputLine(var LineFilename: string; var LineNumber: Integer;
       var LineText: string): Boolean;
+    procedure GetNextOutputLineReset;
     procedure IncludeFile(FileName: string; Builtins, UseIncludePathOnly, ResetCurrentFile: Boolean);
     procedure QueueLine(const LineRead: string);
     function PrependDirName(const FileName, Dir: string): string;
     procedure RegisterFunction(const Name: string; Handler: TIsppFunction; Ext: Longint);
     procedure RaiseError(const Message: string);
-    procedure RaiseErrorEx(const Message: string; Column: Integer);
-    procedure Reset;
     procedure SaveToFile(const FileName: string);
-    procedure ExecProc(Body: TStrings);
     procedure CollectGarbage(Item: Pointer; Proc: TDropGarbageProc);
     procedure UncollectGarbage(Item: Pointer);
     property IncludedFiles: TStringList read FIncludes;
@@ -147,11 +148,9 @@ type
     property VarMan: TIdentManager read FIdentManager;
   end;
 
-function GetEnv (const EnvVar: string): string;
-
 implementation
 
-uses IsppConsts, IsppFuncs, IsppVarUtils, IsppSessions, CParser, PathFunc,
+uses IsppConsts, IsppFuncs, IsppVarUtils, IsppSessions, CTokenizer, PathFunc,
   CmnFunc2, FileClass, Struct;
 
 const
@@ -164,9 +163,9 @@ const
     (#0, '?', #0, #0, #0, #0, #0, '^', '.', ':', #0, '+', #0, #0, #0, #0,
     '=', '%', #0, '!', #0, #0, #0, #0, #0, #0, #0, #0);
 
-function GetEnv (const EnvVar: String): String;
+function GetEnv(const EnvVar: String): String;
 
-  function AdjustLength (var S: String; const Res: Cardinal): Boolean;
+  function AdjustLength(var S: String; const Res: Cardinal): Boolean;
   begin
     Result := Integer(Res) < Length(S);
     SetLength (S, Res);
@@ -175,7 +174,7 @@ function GetEnv (const EnvVar: String): String;
 var
   Res: DWORD;
 begin
-  SetLength (Result, 255);
+  SetLength(Result, 255);
   repeat
     Res := GetEnvironmentVariable(PChar(EnvVar), PChar(Result), Length(Result));
     if Res = 0 then begin
@@ -185,23 +184,6 @@ begin
   until AdjustLength(Result, Res);
 end;
 
-function GetTempFileName(const Original: string): string;
-var
-  Path: string;
-begin
-  SetLength(Path, MAX_PATH);
-  SetLength(Path, GetTempPath(MAX_PATH, PChar(Path)));
-  SetLength(Result, MAX_PATH);
-  if Windows.GetTempFileName(PChar(Path), PChar(UpperCase(Original)), 0, PChar(Result)) <> 0 then
-    SetLength(Result, StrLen(PChar(Result)))
-  else
-    {$IFDEF IS_D7}
-    RaiseLastOSError
-    {$ELSE}
-    RaiseLastWin32Error;
-    {$ENDIF}
-end;
-
 function ParsePreprocCommand(var P: PChar; ExtraTerminator: Char): TPreprocessorCommand;
 begin
   for Result := TPreprocessorCommand(1) to High(TPreprocessorCommand) do
@@ -274,7 +256,7 @@ begin
   FOutput := TStringList.Create;
   FProcs := TStringList.Create;
   FStack := TConditionalTranslationStack.Create(Self);
-  if VarManager = nil then IsppFuncs.Register(Self);
+  if VarManager = nil then IsppFuncs.RegisterFunctions(Self);
 end;
 
 destructor TPreprocessor.Destroy;
@@ -293,13 +275,7 @@ begin
   FIdentManager._Release;
 end;
 
-procedure TPreprocessor.AddLine(const LineRead: string);
-begin
-  InternalAddLine(LineRead, 0, FMainCounter, False);
-  Inc(FMainCounter, 1);
-end;
-
-function TPreprocessor.GetAll: String;
+function TPreprocessor.GetOutput: String;
 begin
   Result := FOutput.Text;
 end;
@@ -320,7 +296,7 @@ begin
     Result := Word(FOutput.Objects[Code]) and $FFFF
 end;
 
-function TPreprocessor.GetNext(var LineFilename: string; var LineNumber: Integer;
+function TPreprocessor.GetNextOutputLine(var LineFilename: string; var LineNumber: Integer;
   var LineText: string): Boolean;
 begin
   Result := False;
@@ -334,6 +310,11 @@ begin
   end;
 end;
 
+procedure TPreprocessor.GetNextOutputLineReset;
+begin
+  FLinePointer := 0;
+end;
+
 procedure TPreprocessor.InternalAddLine(const LineRead: string; FileIndex, LineNo: Word;
   NonISS: Boolean);
 var
@@ -873,6 +854,24 @@ function TPreprocessor.ProcessPreprocCommand(Command: TPreprocessorCommand;
   end;
 
   function DoFile(FileName: string): string;
+
+    function GetTempFileName(const Original: string): string;
+    var
+      Path: string;
+    begin
+      SetLength(Path, MAX_PATH);
+      SetLength(Path, GetTempPath(MAX_PATH, PChar(Path)));
+      SetLength(Result, MAX_PATH);
+      if Windows.GetTempFileName(PChar(Path), PChar(UpperCase(Original)), 0, PChar(Result)) <> 0 then
+        SetLength(Result, StrLen(PChar(Result)))
+      else
+        {$IFDEF IS_D7}
+        RaiseLastOSError
+        {$ELSE}
+        RaiseLastWin32Error;
+        {$ENDIF}
+    end;
+
   var
     F: TTextFileReader;
     ALine: string;
@@ -1048,7 +1047,6 @@ begin
   end;
 end;
 
-
 function TPreprocessor.InternalQueueLine(const LineRead: string;
   FileIndex, LineNo: Word; NonISS: Boolean): Integer; //how many just been added
 var
@@ -1086,11 +1084,6 @@ begin
   FIdentManager.DefineFunction(Name, Handler, Ext);
 end;
 
-procedure TPreprocessor.Reset;
-begin
-  FLinePointer := 0;
-end;
-
 procedure TPreprocessor.SaveToFile(const FileName: string);
 {$IFDEF UNICODE}
 var

+ 7 - 2
Projects/ISPP/IsppSessions.pas

@@ -1,13 +1,18 @@
 {
   Inno Setup Preprocessor
   Copyright (C) 2001-2002 Alex Yackimoff
+
+  Inno Setup
+  Copyright (C) 1997-2020 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
 }
 
 unit IsppSessions;
 
 interface
 
-uses IsppTranslate;
+uses IsppPreprocessor;
 
 procedure PushPreproc(APreproc: TPreprocessor);
 function PopPreproc: TPreprocessor;
@@ -20,7 +25,7 @@ implementation
 
 {$I ..\Version.inc}
 
-uses SysUtils, Classes, IsppStacks {$IFDEF IS_D12}, Windows{$ENDIF};
+uses SysUtils, Classes, IsppStack {$IFDEF IS_D12}, Windows{$ENDIF};
 
 procedure WarningMsg(const Msg: string; const Args: array of const);
 var

+ 6 - 2
Projects/ISPP/IsppStacks.pas → Projects/ISPP/IsppStack.pas

@@ -1,10 +1,14 @@
 {
   Inno Setup Preprocessor
   Copyright (C) 2001-2002 Alex Yackimoff
-  $Id: IsppStacks.pas,v 1.1 2004/02/26 22:24:19 mlaan Exp $
+  
+  Inno Setup
+  Copyright (C) 1997-2020 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
 }
 
-unit IsppStacks;
+unit IsppStack;
 
 interface
 

+ 2 - 3
Projects/ISPP/IsppVarUtils.pas

@@ -3,7 +3,7 @@
   Copyright (C) 2001-2002 Alex Yackimoff
 
   Inno Setup
-  Copyright (C) 1997-2010 Jordan Russell
+  Copyright (C) 1997-2020 Jordan Russell
   Portions by Martijn Laan
   For conditions of distribution and use, see LICENSE.TXT.
 }
@@ -12,7 +12,7 @@ unit IsppVarUtils;
 
 interface
 
-uses IsppIntf, IsppBase, IsppTranslate;
+uses IsppIntf, IsppBase, IsppPreprocessor;
 
 function SimplifyLValue(var Src: TIsppVariant): Boolean;
 procedure MakeRValue(var Src: TIsppVariant);
@@ -104,7 +104,6 @@ begin
       MakeInt(Result, I)
     else
       raise EConvertError.CreateFmt('Cannot convert "%s" to integer', [Op.AsStr])
-      //Sender.RaiseError(PChar(Format(SCannotConvert, [Op.AsStr])))
   else
     if Op.Typ = evNull then
       MakeInt(Result, 0)