Browse Source

Use Data.Outlines instead of Params.PreprocOutput to get preproc output.

Martijn Laan 5 years ago
parent
commit
07d41c8294

+ 0 - 1
Projects/CompPreprocInt.pas

@@ -103,7 +103,6 @@ type
                                          ErrorProc with a description of the
                                          error.}
 
-    PreprocOutput: PChar;              { [out] Full preprocessor output. }
     PreprocCleanupProc: TPreprocCleanupProc;
                                        { [out] Preprocessor-defined function
                                          that, if set, is called after

+ 36 - 12
Projects/Compile.pas

@@ -145,6 +145,7 @@ type
     FLines: TLowFragList;
     function Get(Index: Integer): PScriptFileLine;
     function GetCount: Integer;
+    function GetText: String;
   public
     constructor Create;
     destructor Destroy; override;
@@ -152,6 +153,7 @@ type
       const LineText: String);
     property Count: Integer read GetCount;
     property Lines[Index: Integer]: PScriptFileLine read Get; default;
+    property Text: String read GetText;
   end;
 
   TCheckOrInstallKind = (cikCheck, cikDirectiveCheck, cikInstall);
@@ -1045,17 +1047,45 @@ begin
   Result := FLines.Count;
 end;
 
+function TScriptFileLines.GetText: String;
+var
+  I, L, Size, Count: Integer;
+  P: PChar;
+  S, LB: string;
+begin
+  Count := GetCount;
+  Size := 0;
+  LB := sLineBreak;
+  for I := 0 to Count-1 do
+    Inc(Size, Length(Get(I).LineText) + Length(LB));
+  Dec(Size, Length(LB));
+  SetString(Result, nil, Size);
+  P := Pointer(Result);
+  for I := 0 to Count-1 do begin
+    S := Get(I).LineText;
+    L := Length(S);
+    if L <> 0 then begin
+      System.Move(Pointer(S)^, P^, L * SizeOf(Char));
+      Inc(P, L);
+    end;
+    if I < Count-1 then begin
+      L := Length(LB);
+      if L <> 0 then begin
+        System.Move(Pointer(LB)^, P^, L * SizeOf(Char));
+        Inc(P, L);
+      end;
+    end;
+  end;
+end;
+
 { Built-in preprocessor }
 
 type
   EBuiltinPreprocessScriptError = class(Exception);
 
-var
-  LastBuiltinPreprocOutput: String;
-
 function BuiltinPreprocessScript(var Params: TPreprocessScriptParams): Integer; stdcall;
 var
-  Output, IncludeStack: TStringList;
+  IncludeStack: TStringList;
 
   procedure RaiseError(const LineFilename: String; const LineNumber: Integer;
     const Msg: String);
@@ -1137,11 +1167,9 @@ var
       SkipWhitespace(L);
       if L^ = '#' then
         ProcessDirective(Filename, I + 1, L + 1)
-      else begin
+      else
         Params.LineOutProc(Params.CompilerData, PChar(Filename), I + 1,
           LineText);
-        Output.Add(LineText);
-      end;
       Inc(I);
     end;
     IncludeStack.Delete(IncludeStack.Count-1);
@@ -1155,16 +1183,12 @@ begin
   end;
 
   try
-    Output := TStringList.Create;
     IncludeStack := nil;
     try
       IncludeStack := TStringList.Create;
       ProcessLines(Params.Filename, 0);
     finally
-      LastBuiltinPreprocOutput := Output.Text;
-      Params.PreprocOutput := PChar(LastBuiltinPreprocOutput);
       IncludeStack.Free;
-      Output.Free;
     end;
     Result := ispeSuccess;
   except
@@ -2085,7 +2109,7 @@ function TSetupCompiler.ReadScriptFile(const Filename: String;
           AddStatus(SCompilerStatusPreprocessing);
         ResultCode := PreProc(Params);
         if Filename = '' then begin
-          PreprocOutput := Params.PreprocOutput;
+          PreprocOutput := Data.Outlines.Text;
           { Defer cleanup of main script until after compilation }
           PreprocCleanupProcData := Params.PreprocCleanupProcData;
           PreprocCleanupProc := Params.PreprocCleanupProc;

+ 0 - 5
Projects/ISPP/IsppPreprocess.pas

@@ -23,9 +23,6 @@ uses
   SysUtils, CmnFunc2, PathFunc,
   IsppBase, IsppPreprocessor, IsppSessions, IsppIntf, IsppIdentMan, IsppVarUtils, IsppConsts;
 
-var
-  LastPreprocOutput: string;
-
 procedure ReadScript(const Params: TPreprocessScriptParams;
   const Preprocessor: TPreprocessor);
 var
@@ -283,8 +280,6 @@ begin
         Result := ispeSuccess;
       end;
     finally
-      LastPreprocOutput := Preprocessor.GetOutput;
-      Params.PreprocOutput := PChar(LastPreprocOutput);
       Preprocessor.Free;
     end;
   except

+ 0 - 6
Projects/ISPP/IsppPreprocessor.pas

@@ -128,7 +128,6 @@ 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);
-    function GetOutput: String;
     function GetNextOutputLine(var LineFilename: string; var LineNumber: Integer;
       var LineText: string): Boolean;
     procedure GetNextOutputLineReset;
@@ -275,11 +274,6 @@ begin
   FIdentManager._Release;
 end;
 
-function TPreprocessor.GetOutput: String;
-begin
-  Result := FOutput.Text;
-end;
-
 function TPreprocessor.GetFileName(Code: Integer): string;
 begin
   if Code = -1 then