ソースを参照

ISPP change: Added new Message, Warning, and Error support functions.
Also: issue warnings on GetFileVersion or ParseVersion calls (because these have been renamed).

Martijn Laan 5 年 前
コミット
4252cca657

+ 3 - 1
Files/ISPPBuiltins.iss

@@ -186,7 +186,9 @@
     Build   = Int(Local[1]), \
   Local[0])
 //
-#define ParseVersion(str FileName, *Major, *Minor, *Rev, *Build) GetVersionComponents(FileName, Major, Minor, Rev, Build)
+#define ParseVersion(str FileName, *Major, *Minor, *Rev, *Build) \
+  Warning("Function ""ParseVersion"" has been renamed. Use ""GetVersionComponents"" instead."), \
+  GetVersionComponents(FileName, Major, Minor, Rev, Build)
 //
 #define GetVersionNumbers(str FileName, *MS, *LS) \
   Local[0] = GetVersionComponents(FileName, Local[1], Local[2], Local[3], Local[4]), \

+ 37 - 1
Projects/ISPP/Help/ispp.xml

@@ -632,6 +632,9 @@ The list of options is provided at the end of this topic.</para>
 						<line>#pragma spansymbol "_"</line>
 					</pre>
 				</section>
+				<section title="See also">
+					<para><synel><link href="Message">Message</link></synel>, <synel><link href="Warning">Warning</link></synel>, <synel><link href="Error2">Error</link></synel>.</para>
+				</section>
 			</topic>
 			<topic id="error">
 				<title>#error</title>
@@ -652,7 +655,7 @@ The list of options is provided at the end of this topic.</para>
 					</pre>
 				</section>
 				<section title="See also">
-					<para>&pragma;, &if;.</para>
+					<para>&pragma;, &if;, <synel><link href="Error2">Error</link></synel>.</para>
 				</section>
 			</topic>
 		</topic>
@@ -1673,6 +1676,39 @@ The list of options is provided at the end of this topic.</para>
           <para>Declared in &builtins;.</para>
 				</description>
 			</topic>
+			<topic id="Message">
+				<title>Message</title>
+				<section title="Prototype">
+					<pre>
+						<line><b>void</b> Message(<b>str</b> S)</line>
+					</pre>
+				</section>
+				<description>
+					<para>Functional version of <synel><link href="pragma">pragma message</link></synel>.</para>
+				</description>
+			</topic>
+			<topic id="Warning">
+				<title>Warning</title>
+				<section title="Prototype">
+					<pre>
+						<line><b>void</b> Warning(<b>str</b> S)</line>
+					</pre>
+				</section>
+				<description>
+					<para>Functional version of <synel><link href="pragma">pragma warning</link></synel>.</para>
+				</description>
+			</topic>
+			<topic id="Error2">
+				<title>Error</title>
+				<section title="Prototype">
+					<pre>
+						<line><b>void</b> Error(<b>str</b> S)</line>
+					</pre>
+				</section>
+				<description>
+					<para>Functional version of &error;.</para>
+				</description>
+			</topic>
 		</topic>
     <topic id="macros">
 			<keywords>

+ 87 - 3
Projects/ISPP/IsppFuncs.pas

@@ -876,7 +876,7 @@ begin
   end;
 end;
 
-function GetVersionNumbersString(Ext: Longint; const Params: IIsppFuncParams;
+function GetVersionNumbersStringFunc(Ext: Longint; const Params: IIsppFuncParams;
   const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
 var
   Filename: string;
@@ -921,6 +921,21 @@ begin
   end;
 end;
 
+function GetFileVersionFunc(Ext: Longint; const Params: IIsppFuncParams;
+  const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
+begin
+  try
+    TPreprocessor(Ext).Warning('Function "%s" has been renamed. Use "%s" instead.', ['GetFileVersion', 'GetVersionNumbersString']);
+    Result := GetVersionNumbersStringFunc(Ext, Params, FuncResult);
+  except
+    on E: Exception do
+    begin
+      FuncResult.Error(PChar(E.Message));
+      Result.Error := ISPPFUNC_FAIL
+    end;
+  end;
+end;
+
 {str GetStringFileInfo(str FileName, str StringName, int Lang)}
 function GetFileVersionInfoItem(Ext: Longint; const Params: IIsppFuncParams;
   const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
@@ -1725,6 +1740,72 @@ begin
   end;
 end;
 
+function MessageFunc(Ext: Longint; const Params: IIsppFuncParams;
+  const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
+begin
+  if CheckParams(Params, [evStr], 1, Result) then
+  try
+    with IInternalFuncParams(Params) do begin
+      { Also see Pragma in IsppTranslate }
+      TPreprocessor(Ext).SendMsg(Get(0).AsStr, imtStatus);
+      ResPtr^ := NULL;
+    end;
+  except
+    on E: Exception do
+    begin
+      FuncResult.Error(PChar(E.Message));
+      Result.Error := ISPPFUNC_FAIL
+    end;
+  end;
+end;
+
+function WarningFunc(Ext: Longint; const Params: IIsppFuncParams;
+  const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
+begin
+  if CheckParams(Params, [evStr], 1, Result) then
+  try
+    with IInternalFuncParams(Params) do begin
+      { Also see Pragma in IsppTranslate }
+      TPreprocessor(Ext).Warning(Get(0).AsStr, []);
+      ResPtr^ := NULL;
+    end;
+  except
+    on E: Exception do
+    begin
+      FuncResult.Error(PChar(E.Message));
+      Result.Error := ISPPFUNC_FAIL
+    end;
+  end;
+end;
+
+function ErrorFunc(Ext: Longint; const Params: IIsppFuncParams;
+  const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
+var
+  CatchException: Boolean;
+  ErrorMsg: String;
+begin
+  CatchException := True;
+  if CheckParams(Params, [evStr], 1, Result) then
+  try
+    with IInternalFuncParams(Params) do begin
+      { Also see Pragma and pcErrorDir in IsppTranslate }
+      ErrorMsg := Get(0).AsStr;
+      if ErrorMsg = '' then ErrorMsg := 'Error';
+      CatchException := False;
+      TPreprocessor(Ext).RaiseError(ErrorMsg);
+    end;
+  except
+    on E: Exception do
+    begin
+      if CatchException then begin
+        FuncResult.Error(PChar(E.Message));
+        Result.Error := ISPPFUNC_FAIL
+      end else
+        raise;
+    end;
+  end;
+end;
+
 procedure Register(Preproc: TPreprocessor);
 begin
   with Preproc do
@@ -1745,8 +1826,8 @@ begin
     RegisterFunction('Pos', PosFunc, -1);
     RegisterFunction('RPos', RPosFunc, -1);
     RegisterFunction('Len', LenFunc, -1);
-    RegisterFunction('GetVersionNumbersString', GetVersionNumbersString, -1);
-    RegisterFunction('GetFileVersion', GetVersionNumbersString, -1); { The old name of GetVersionNumbersString }
+    RegisterFunction('GetVersionNumbersString', GetVersionNumbersStringFunc, -1);
+    RegisterFunction('GetFileVersion', GetFileVersionFunc, -1);
     RegisterFunction('GetStringFileInfo', GetFileVersionInfoItem, -1);
     RegisterFunction('SaveToFile', IsppFuncs.SaveToFile, -1);
     RegisterFunction('Find', FindLine, -1);
@@ -1784,6 +1865,9 @@ begin
     RegisterFunction('Trim', TrimFunc, -1);
     RegisterFunction('StringChange', StringChangeFunc, -1);
     RegisterFunction('IsWin64', IsWin64Func, -1);
+    RegisterFunction('Message', MessageFunc, -1);
+    RegisterFunction('Warning', WarningFunc, -1);
+    RegisterFunction('Error', ErrorFunc, -1);
   end;
 end;
 

+ 9 - 6
Projects/ISPP/IsppTranslate.pas

@@ -92,7 +92,6 @@ type
     procedure PushFile(const FileName: string);
     procedure PopFile;
     function CheckFile(const FileName: string): Boolean;
-    procedure SendMsg(const Msg: string; Typ: TIsppMessageType);
     function EmitDestination: TStringList;
   protected
     function GetDefaultScope: TDefineScope;
@@ -121,13 +120,14 @@ type
     destructor Destroy; override;
     procedure VerboseMsg(Level: Byte; const Msg: string; const Args: array of const);
     procedure Warning(const Msg: string; const Args: array of const);
+    procedure IssueMessage(const Message: string; MsgType: TIsppMessageType);
+    procedure SendMsg(const Msg: string; Typ: TIsppMessageType);
     procedure AddLine(const LineRead: string);
     function GetFileName(Code: Integer): string;
     function GetLineNumber(Code: Integer): Word;
     function GetNext(var LineFilename: string; var LineNumber: Integer;
       var LineText: string): Boolean;
     procedure IncludeFile(FileName: string; UseIncludePathOnly, ResetCurrentFile: Boolean);
-    procedure IssueMessage(const Message: string; MsgType: TIsppMessageType);
     procedure QueueLine(const LineRead: string);
     function PrependDirName(const FileName, Dir: string): string;
     procedure RegisterFunction(const Name: string; Handler: TIsppFunction; Ext: Longint);
@@ -840,12 +840,14 @@ function TPreprocessor.ProcessPreprocCommand(Command: TPreprocessorCommand;
           FOptions.VerboseLevel := IntExpr(True);
           EndOfExpr;
         end
-        else if P = 'warning' then
+        else if P = 'warning' then begin
+          { Also see WarningFunc in IsppFuncs }
           Warning(StrPragma(True), [])
-        else if P = 'message' then
+        end else if P = 'message' then begin
+          { Also see MessageFunc in IsppFuncs }
           SendMsg(StrPragma(True), imtStatus)
-        else if P = 'error' then
-        begin
+        end else if P = 'error' then begin
+          { Also see ErrorFunc in IsppFuncs }
           ErrorMsg := StrPragma(True);
           if ErrorMsg = '' then ErrorMsg := 'Error';
           CatchException := False;
@@ -1012,6 +1014,7 @@ begin
       pcInclude: IncludeFile(Params);
       pcErrorDir:
         begin
+          { Also see ErrorFunc in IsppFuncs }
           if Params = '' then Params := 'Error';
           RaiseError(Params);
         end;

+ 3 - 2
whatsnew.htm

@@ -70,7 +70,7 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
   <li>ISPP's <tt>int</tt> type is now a signed 64-bit integer type.</tt>
   <li>Support function <tt>FileSize</tt> now supports 64-bit file sizes.</li>
   <li>Added new <tt>PackVersionNumbers</tt>, <tt>PackVersionComponents</tt>, <tt>UnpackVersionNumbers</tt>, <tt>UnpackVersionComponents</tt>, and <tt>VersionToStr</tt> support functions.</li>
-  <li>Support function <tt>GetFileVersion</tt> and <tt>ParseVersion</tt> have been renamed to <tt>GetVersionNumbersString</tt> and <tt>GetVersionComponents</tt> respectively. The old names are still supported, but it is recommended to update your scripts to the new names.</li>
+  <li>Support function <tt>GetFileVersion</tt> and <tt>ParseVersion</tt> have been renamed to <tt>GetVersionNumbersString</tt> and <tt>GetVersionComponents</tt> respectively. The old names are still supported, but it is recommended to update your scripts to the new names and the compiler will issue a warning if you don't.</li>
 </ul>
 <p>Similar Pascal Scripting changes have been done for [Code]:</p>
 <ul>
@@ -89,6 +89,7 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
     <li>Setup now shows <a href="https://i.imgur.com/VBDuZ7U.png">more user friendly prompts</a> to keep or overwrite existing files if the <tt>promptifolder</tt> flag is set.</li>
   </ul>
   </li>
+  <li>Console-mode compiler (ISCC) change: Warnings and errors are now <a href="https://i.imgur.com/9VvbFGJ.png">colorized</a>.</li>
   <li>Pascal Scripting changes:
   <ul>
     <li>Added new <tt>CalculateButtonWidth</tt> function to the <tt>TSetupForm</tt> support class.</li>
@@ -96,7 +97,7 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
     <li><i>Fix:</i> Support function <tt>WizardSelectComponents</tt> now also updates component sizes and the current selection's required disk space.</li>
   </ul>
   </li>
-  <li>Console-mode compiler (ISCC) change: Warnings and errors are now <a href="https://i.imgur.com/9VvbFGJ.png">colorized</a>.</li>
+  <li>ISPP change: Added new <tt>Message</tt>, <tt>Warning</tt>, and <tt>Error</tt> support functions.</li>
   <li>Various documentation improvements.</li>
   <li>Minor tweaks.</li>
 </ul>