Error Reporting

Turbo Pascal reports errors with module name, source line and error position where the error occured. This is very handy to locate the problem. This information can also be used in some text editors to position the cursor where the compiler reported error.

For some errors also short additional information like identifier name is displayed. WriteCompilationError procedure takes care for this.
Procedure WriteCompilationError;
Var N: Integer;
begin
  If Assigned (ErrorSourceFile) then
    begin
      If LastError = CompilationAborted then
        Asm                                           { Move one row up to compensate ^C#13#10 }
          MOV   AH, 3
          XOR   BH, BH
          PUSH  SI
          PUSH  DI
          PUSH  BP
          PUSH  ES
          INT   $10
          DEC   DH
          MOV   AH, 2
          XOR   BH, BH
          INT   $10
          POP   ES
          POP   BP
          POP   DI
          POP   SI
        end;
      WriteModuleNameWithCurrentLineNumber (ErrorSourceFile);
      Write (': ');
    end;
  If LastError <> NoError then Write ('Error ', Ord (LastError), ': ');
  Write (CompilerErrorString [LastError]);
  If Assigned (AdditionalErrorStr) then Write (' (', AdditionalErrorStr, ')');
  Writeln ('.');

  If LastError = CompilationAborted then Halt ($FF);

  If Assigned (ErrorSourceFile) then
    begin
      Writeln (CurrentLine);
      For N := 0 to ErrorSourceFile^.CurrentPosition - 1 - Ofs (CurrentLine^) do
        Case CurrentLine [N] of
          #9: Write (#9);
          else Write (' ');
        end;
      Writeln ('^');
    end;
end;
This procedure reports error and halts the compiler.
Procedure WriteCompilationErrorAndHalt;
begin
  If LastError = CompilationAborted then Halt ($FF);
  WriteCompilationError;
  Halt (1);
end;
There are also few additional error procedures that display additional error information.
Procedure CurrentIdentifierError (Err: TCompilerError);
begin
  AdditionalErrorStr := @Identifier;
  StrPCopy (@Identifier, CurrentIdentifier);
  Error (Err);
end;
This procedure copies string paremeter as additional error information.
Procedure IdentifierError (Const Id: String; Err: TCompilerError);
begin
  AdditionalErrorStr := @Identifier;
  StrPCopy (@Identifier, Id);
  Error (Err);
end;
FileError reports error with file name as additional error string.
Procedure FileError (FileName: Pchar; Err: TCompilerError);
begin
  StrCopy (NameStr, FileName);
  AdditionalErrorStr := NameStr;
  Error (Err);
end;
 
 
 
© 2017 Turbo Pascal | Privacy Policy