Ablerr.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. //***************************************************************************
  5. //
  6. // ABLERR.CPP
  7. //
  8. //***************************************************************************
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #ifndef ABLGEN_H
  12. #include "ablgen.h"
  13. #endif
  14. #ifndef ABLSCAN_H
  15. #include "ablscan.h"
  16. #endif
  17. #ifndef ABLERR_H
  18. #include "ablerr.h"
  19. #endif
  20. #ifndef ABL_H
  21. #include "abl.h"
  22. #endif
  23. //***************************************************************************
  24. //----------
  25. // EXTERNALS
  26. extern char* tokenp;
  27. extern long execLineNumber;
  28. extern long lineNumber;
  29. extern long FileNumber;
  30. extern char SourceFiles[MAX_SOURCE_FILES][MAXLEN_FILENAME];
  31. extern ABLModulePtr CurModule;
  32. extern char wordString[];
  33. //---------------------------------------------------------------------------
  34. //----------------------
  35. // SYNTAX ERROR messages
  36. char* syntaxErrorMessages[] = {
  37. "No syntax error", // 0
  38. "Syntax error",
  39. "Too many errors",
  40. "Cannot open source file",
  41. "Unexpected end-of-file",
  42. "Invalid number",
  43. "Invalid fraction",
  44. "Invalid exponent",
  45. "Too many digits",
  46. "Real out of range",
  47. "Integer out of range", // 10
  48. "Missing right parenthesis",
  49. "Invalid expression",
  50. "Undefined identifier",
  51. "Redefined identifier",
  52. "Unexpected token",
  53. "Incompatible types",
  54. "Nesting too deep",
  55. "Code segment overflow",
  56. "Missing equal",
  57. "Missing semi-colon", // 20
  58. "Invalid constant",
  59. "Not a constant identifier",
  60. "No record types",
  61. "Missing colon (ouch)",
  62. "Not a type identifier",
  63. "Invalid type",
  64. "Missing end",
  65. "Invalid identifier usage",
  66. "Too many subscripts",
  67. "Missing right bracket", // 30
  68. "Incompatible assignment",
  69. "Missing until",
  70. "Missing then",
  71. "Invalid for control",
  72. "Missing identifier",
  73. "Missing to",
  74. "Missing period",
  75. "Missing module",
  76. "Missing library",
  77. "Already forwarded", // 40
  78. "Invalid reference parameter",
  79. "Wrong number of parameters",
  80. "Missing begin",
  81. "Missing endvar",
  82. "No function nesting",
  83. "Missing code",
  84. "Missing endif",
  85. "Missing endwhile",
  86. "Missing endfor",
  87. "Missing endfunction", // 50
  88. "Missing endmodule",
  89. "Missing endlibrary",
  90. "Missing do",
  91. "Invalid index type",
  92. "Missing comma",
  93. "Too many static variables",
  94. "Missing endcase",
  95. "Missing endswitch",
  96. "Missing constant",
  97. "Bad language directive parameter", // 60
  98. "Unknown language directive",
  99. "Too Many Formal Parameters",
  100. "Too Many Local Variables",
  101. "Order must have Integer Return Type",
  102. "Too many orders",
  103. "Missing state for transition",
  104. "Missing endfsm"
  105. };
  106. //---------------------------------------------------------------------------
  107. //-----------------------
  108. // RUNTIME ERROR messages
  109. char* runtimeErrorMessages[] = {
  110. "Runtime stack overflow",
  111. "Infinite Loop",
  112. "Nested function call",
  113. "Unimplemented feature",
  114. "Value out of range",
  115. "Division by zero",
  116. "Invalid function argument",
  117. "Invalid case value",
  118. "Abort",
  119. "No Previous State"
  120. };
  121. //---------------------------------------------------------------------------
  122. //--------
  123. // GLOBALS
  124. long errorCount = 0;
  125. extern DebuggerPtr debugger;
  126. //***************************************************************************
  127. void ABL_Fatal (long errCode, char* s) {
  128. ABLFatalCallback(errCode, s);
  129. }
  130. //---------------------------------------------------------------------------
  131. void ABL_Assert (bool test, long errCode, char* s) {
  132. #ifdef _DEBUG
  133. if (!test)
  134. ABLFatalCallback(errCode, s);
  135. #endif
  136. }
  137. //***************************************************************************
  138. void syntaxError (long errCode) {
  139. char errMessage[MAXLEN_ERROR_MESSAGE];
  140. sprintf(errMessage, "SYNTAX ERROR %s [line %d] - (type %d) %s \"%s\"\n", SourceFiles[FileNumber], lineNumber, errCode, syntaxErrorMessages[errCode], wordString);
  141. ABL_Fatal(0, errMessage);
  142. *tokenp = NULL;
  143. errorCount++;
  144. if (errorCount > MAX_SYNTAX_ERRORS) {
  145. sprintf(errMessage, "Way too many syntax errors. ABL aborted.\n");
  146. ABL_Fatal(0, errMessage);
  147. }
  148. }
  149. //---------------------------------------------------------------------------
  150. void runtimeError (long errCode) {
  151. char message[512];
  152. if (debugger) {
  153. sprintf(message, "RUNTIME ERROR: [%d] %s", errCode, runtimeErrorMessages[errCode]);
  154. debugger->print(message);
  155. sprintf(message, "MODULE %s", CurModule->getName());
  156. debugger->print(message);
  157. if (FileNumber > -1)
  158. sprintf(message, "FILE %s", CurModule->getSourceFile(FileNumber));
  159. else
  160. sprintf(message, "FILE %s: unavailable");
  161. debugger->print(message);
  162. sprintf(message, "LINE %d", execLineNumber);
  163. debugger->print(message);
  164. debugger->debugMode();
  165. }
  166. sprintf(message, "ABL RUNTIME ERROR %s [line %d] - (type %d) %s\n", (FileNumber > -1) ? CurModule->getSourceFile(FileNumber) : "unavailable", execLineNumber, errCode, runtimeErrorMessages[errCode]);
  167. ABL_Fatal(-ABL_ERR_RUNTIME_ABORT, message);
  168. }
  169. //***************************************************************************