' Gambas module file

'{
Private Const ERR_001 As String = ("&1 cannot be static")
Private Const ERR_002 As String = ("&1 declaration does not match")
Private Const ERR_003 As String = ("&1 is declared but is not a function")
Private Const ERR_004 As String = ("&1 is not a structure")
Private Const ERR_005 As String = ("&1 is not declared")
Private Const ERR_006 As String = ("&1 must be static")
Private Const ERR_007 As String = ("&1: not in archive")
Private Const ERR_008 As String = ("&1: syntax error")
Private Const ERR_009 As String = ("&1: syntax error in form data")
Private Const ERR_010 As String = ("&1: syntax error in form file")
Private Const ERR_011 As String = ("&1: too many nested containers")
Private Const ERR_012 As String = ("'&1' already declared")
Private Const ERR_013 As String = ("'&1.&2' is incorrectly overridden in class '&3'")
Private Const ERR_014 As String = ("'&1.&2' is not a property")
Private Const ERR_015 As String = ("'&1.&2' is not static")
Private Const ERR_016 As String = ("'&1.&2' is read only")
Private Const ERR_017 As String = ("'&1.&2' is static")
Private Const ERR_018 As String = ("'&1.&2' is write only")
Private Const ERR_019 As String = ("',' or ')'")
Private Const ERR_020 As String = ("A module cannot raise events")
Private Const ERR_021 As String = ("A property implementation cannot be public")
Private Const ERR_022 As String = ("A property must be public")
Private Const ERR_023 As String = ("Access forbidden")
Private Const ERR_024 As String = ("Alias name must be a string")
Private Const ERR_025 As String = ("Ambiguous expression. Please use brackets")
Private Const ERR_026 As String = ("Argument cannot be passed by reference")
Private Const ERR_027 As String = ("Arrays of structure are not supported")
Private Const ERR_028 As String = ("Assertion failed")
Private Const ERR_029 As String = ("Bad archive: &1: &2")
Private Const ERR_030 As String = ("Bad argument")
Private Const ERR_031 As String = ("Bad character constant in string")
Private Const ERR_032 As String = ("Bad constant type")
Private Const ERR_033 As String = ("Bad event handler in &1.&2(): &3")
Private Const ERR_034 As String = ("Bad expression: &1")
Private Const ERR_035 As String = ("Bad form file version")
Private Const ERR_036 As String = ("Bad format in section: ")
Private Const ERR_037 As String = ("Bad format string")
Private Const ERR_038 As String = ("Bad indirect jump")
Private Const ERR_039 As String = ("Bad number of dimensions")
Private Const ERR_040 As String = ("Bad project file: line &1: &2")
Private Const ERR_041 As String = ("Bad regular expression: &1")
Private Const ERR_042 As String = ("Bad string conversion")
Private Const ERR_043 As String = ("Bad subscript range")
Private Const ERR_044 As String = ("Bad use of virtual class")
Private Const ERR_045 As String = ("Bad version string")
Private Const ERR_046 As String = ("Cannot change current directory to '&1': &2")
Private Const ERR_047 As String = ("Cannot create '&1' file")
Private Const ERR_048 As String = ("Cannot create action file: &1")
Private Const ERR_049 As String = ("Cannot create callback: &1")
Private Const ERR_050 As String = ("Cannot create class information: &1: &2")
Private Const ERR_051 As String = ("Cannot create file: &1")
Private Const ERR_052 As String = ("Cannot create file: &1: &2")
Private Const ERR_053 As String = ("Cannot create temporary archive file: &1")
Private Const ERR_054 As String = ("Cannot find dynamic library '&1': &2")
Private Const ERR_055 As String = ("Cannot find symbol '&2' in dynamic library '&1'")
Private Const ERR_056 As String = ("Cannot inherit itself")
Private Const ERR_057 As String = ("Cannot instantiate native types")
Private Const ERR_058 As String = ("Cannot load class '&1': &2&3")
Private Const ERR_059 As String = ("Cannot load component '&1': &2")
Private Const ERR_060 As String = ("Cannot load file: &1")
Private Const ERR_061 As String = ("Cannot load source file: &1")
Private Const ERR_062 As String = ("Cannot make executable: &1: &2")
Private Const ERR_063 As String = ("Cannot mix NEW and embedded array")
Private Const ERR_064 As String = ("Cannot mix NEW and embedded structure")
Private Const ERR_065 As String = ("Cannot open file '&1': &2")
Private Const ERR_066 As String = ("Cannot open file: &1")
Private Const ERR_067 As String = ("Cannot raise events in static function")
Private Const ERR_068 As String = ("Cannot read file: &1: &2")
Private Const ERR_069 As String = ("Cannot register class '&1'")
Private Const ERR_070 As String = ("Cannot remove file '&1': &2")
Private Const ERR_071 As String = ("Cannot rename file '&1' to '&2': &3")
Private Const ERR_072 As String = ("Cannot run child process: &1&2")
Private Const ERR_073 As String = ("Cannot set file owner: &1: &2")
Private Const ERR_074 As String = ("Cannot use &1 twice")
Private Const ERR_075 As String = ("Cannot use &1 with &2")
Private Const ERR_076 As String = ("Cannot use NEW operator here")
Private Const ERR_077 As String = ("Class")
Private Const ERR_078 As String = ("Class '&1' is not creatable")
Private Const ERR_079 As String = ("Class already has a parent")
Private Const ERR_080 As String = ("Class is already exported")
Private Const ERR_081 As String = ("Comparison operator expected")
Private Const ERR_082 As String = ("Component information file not found: &1")
Private Const ERR_083 As String = ("Component name must be a string")
Private Const ERR_084 As String = ("Constant expression expected")
Private Const ERR_085 As String = ("Constant expression too complex")
Private Const ERR_086 As String = ("Constant string expected")
Private Const ERR_087 As String = ("Contents already declared")
Private Const ERR_088 As String = ("Default case already defined")
Private Const ERR_089 As String = ("Default case must be the last one")
Private Const ERR_090 As String = ("Device is full")
Private Const ERR_091 As String = ("Directory is not empty")
Private Const ERR_092 As String = ("Division by zero")
Private Const ERR_093 As String = ("Dynamic symbols cannot be used in static function")
Private Const ERR_094 As String = ("Embedded arrays are forbidden here")
Private Const ERR_095 As String = ("End of file")
Private Const ERR_096 As String = ("Enumeration value already declared")
Private Const ERR_097 As String = ("Equality or inequality operator expected")
Private Const ERR_098 As String = ("Expression too complex")
Private Const ERR_099 As String = ("Expression too complex. Too many operands")
Private Const ERR_100 As String = ("Extern library name must be a string")
Private Const ERR_101 As String = ("Failed to run child process: &1")
Private Const ERR_102 As String = ("File already exists")
Private Const ERR_103 As String = ("File is a directory")
Private Const ERR_104 As String = ("File is locked")
Private Const ERR_105 As String = ("File name is too long")
Private Const ERR_106 As String = ("File or directory does not exist")
Private Const ERR_107 As String = ("Forbidden GOSUB")
Private Const ERR_108 As String = ("Forbidden GOTO")
Private Const ERR_109 As String = ("Free object referenced")
Private Const ERR_110 As String = ("Illegal instruction")
Private Const ERR_111 As String = ("Incorrect declaration of symbol '&1' in class '&2'")
Private Const ERR_112 As String = ("Internal compiler error")
Private Const ERR_113 As String = ("Invalid assignment")
Private Const ERR_114 As String = ("Invalid date")
Private Const ERR_115 As String = ("Invalid object")
Private Const ERR_116 As String = ("Invalid path")
Private Const ERR_117 As String = ("IsMissing() requires a function argument")
Private Const ERR_118 As String = ("Jump is too far")
Private Const ERR_119 As String = ("Label '&1' not declared")
Private Const ERR_120 As String = ("Label must be top-level")
Private Const ERR_121 As String = ("Library name must be a string")
Private Const ERR_122 As String = ("Local symbols are not allowed in AFTER or EVERY expressions")
Private Const ERR_123 As String = ("Loop variable already in use")
Private Const ERR_124 As String = ("Loop variable cannot be an argument")
Private Const ERR_125 As String = ("Loop variable cannot be global")
Private Const ERR_126 As String = ("ME cannot be used in a static function")
Private Const ERR_127 As String = ("Mathematic error")
Private Const ERR_128 As String = ("Missing #Endif")
Private Const ERR_129 As String = ("Missing ']'")
Private Const ERR_130 As String = ("Missing '}'")
Private Const ERR_131 As String = ("Missing operator")
Private Const ERR_132 As String = ("Missing right brace")
Private Const ERR_133 As String = ("Multidimensional array")
Private Const ERR_134 As String = ("NEW cannot have arguments passed by reference")
Private Const ERR_135 As String = ("Named enumeration can only be public")
Private Const ERR_136 As String = ("No information found about class &1")
Private Const ERR_137 As String = ("No instantiation method")
Private Const ERR_138 As String = ("No parent class")
Private Const ERR_139 As String = ("No return value")
Private Const ERR_140 As String = ("No startup method")
Private Const ERR_141 As String = ("Non terminated string")
Private Const ERR_142 As String = ("Not a directory: &1")
Private Const ERR_143 As String = ("Not a function")
Private Const ERR_144 As String = ("Not a procedure")
Private Const ERR_145 As String = ("Not an array")
Private Const ERR_146 As String = ("Not an enumeration")
Private Const ERR_147 As String = ("Not an object")
Private Const ERR_148 As String = ("Not enough argument to New()")
Private Const ERR_149 As String = ("Not enough arguments")
Private Const ERR_150 As String = ("Not enough arguments to &1()")
Private Const ERR_151 As String = ("Not implemented yet")
Private Const ERR_152 As String = ("Not supported")
Private Const ERR_153 As String = ("Null object")
Private Const ERR_154 As String = ("Number")
Private Const ERR_155 As String = ("Number or Date expected")
Private Const ERR_156 As String = ("Number or date")
Private Const ERR_157 As String = ("Number, Date or String")
Private Const ERR_158 As String = ("Number, String or Object")
Private Const ERR_159 As String = ("Object")
Private Const ERR_160 As String = ("Out of bounds")
Private Const ERR_161 As String = ("Out of memory")
Private Const ERR_162 As String = ("Out of range")
Private Const ERR_163 As String = ("Overflow")
Private Const ERR_164 As String = ("Overriding an already inherited class is forbidden")
Private Const ERR_165 As String = ("Read error")
Private Const ERR_166 As String = ("Read-only object")
Private Const ERR_167 As String = ("STOP instruction encountered")
Private Const ERR_168 As String = ("SUPER cannot be used alone")
Private Const ERR_169 As String = ("Serialization error")
Private Const ERR_170 As String = ("Stack overflow")
Private Const ERR_171 As String = ("Stream is closed")
Private Const ERR_172 As String = ("String expected")
Private Const ERR_173 As String = ("Structures must be public")
Private Const ERR_174 As String = ("Subroutine arguments cannot be passed by reference")
Private Const ERR_175 As String = ("Syntax error")
Private Const ERR_176 As String = ("Syntax error at function declaration")
Private Const ERR_177 As String = ("Syntax error in event name")
Private Const ERR_178 As String = ("Syntax error in file open mode")
Private Const ERR_179 As String = ("Syntax error in return type")
Private Const ERR_180 As String = ("Syntax error. &1 expected")
Private Const ERR_181 As String = ("Syntax error. '...' must be the last argument")
Private Const ERR_182 As String = ("Syntax error. CASE or DEFAULT expected after SELECT")
Private Const ERR_183 As String = ("Syntax error. Cannot use this syntax in assignment")
Private Const ERR_184 As String = ("Syntax error. Class name expected")
Private Const ERR_185 As String = ("Syntax error. Identifier expected")
Private Const ERR_186 As String = ("Syntax error. Identifier expected for namespace")
Private Const ERR_187 As String = ("Syntax error. Identifier expected for property name")
Private Const ERR_188 As String = ("Syntax error. Identifier expected for property synonymous")
Private Const ERR_189 As String = ("Syntax error. Identifier expected for property variable")
Private Const ERR_190 As String = ("Syntax error. Incorrect enumeration name")
Private Const ERR_191 As String = ("Syntax error. Invalid identifier in function name")
Private Const ERR_192 As String = ("Syntax error. Invalid optional parameter")
Private Const ERR_193 As String = ("Syntax error. Invalid property type")
Private Const ERR_194 As String = ("Syntax error. Invalid return type")
Private Const ERR_195 As String = ("Syntax error. Invalid type description of &1 argument")
Private Const ERR_196 As String = ("Syntax error. Invalid type description of &1 field")
Private Const ERR_197 As String = ("Syntax error. Needless arguments")
Private Const ERR_198 As String = ("Syntax error. Point syntax used outside of WITH / END WITH")
Private Const ERR_199 As String = ("Syntax error. STRUCT must be followed by an identifier")
Private Const ERR_200 As String = ("Syntax error. The &1 argument is not a valid identifier")
Private Const ERR_201 As String = ("Syntax error. The &1 field is not a valid identifier")
Private Const ERR_202 As String = ("Syntax error. VarPtr() takes only one identifier")
Private Const ERR_203 As String = ("System error #&1: &2")
Private Const ERR_204 As String = ("The '!' operator must be followed by an identifier")
Private Const ERR_205 As String = ("The '&1()' subroutine only exists since version &2")
Private Const ERR_206 As String = ("The '.' operator must be followed by an identifier")
Private Const ERR_207 As String = ("The function must take a fixed number of arguments")
Private Const ERR_208 As String = ("The special method &1 cannot be a function")
Private Const ERR_209 As String = ("The special method &1 cannot be implemented")
Private Const ERR_210 As String = ("The special method &1 cannot be static")
Private Const ERR_211 As String = ("The special method &1 must be a function")
Private Const ERR_212 As String = ("The special method &1 must be public")
Private Const ERR_213 As String = ("The special method &1 must be static")
Private Const ERR_214 As String = ("The special method &1 must return a boolean")
Private Const ERR_215 As String = ("The special method &1 must take a variable number of arguments only")
Private Const ERR_216 As String = ("The special method &1 must take at least one argument")
Private Const ERR_217 As String = ("The special method &1 takes no arguments")
Private Const ERR_218 As String = ("The special method must return an integer")
Private Const ERR_219 As String = ("The special method must take exactly one argument")
Private Const ERR_220 As String = ("The special method must take exactly two arguments")
Private Const ERR_221 As String = ("The special method signature is incorrect")
Private Const ERR_222 As String = ("This expression cannot be a statement")
Private Const ERR_223 As String = ("This expression cannot be passed by reference")
Private Const ERR_224 As String = ("This function does not return a value")
Private Const ERR_225 As String = ("This statement is not allowed with DO NEXT")
Private Const ERR_226 As String = ("Too many arguments")
Private Const ERR_227 As String = ("Too many arguments to &1()")
Private Const ERR_228 As String = ("Too many array declarations")
Private Const ERR_229 As String = ("Too many components")
Private Const ERR_230 As String = ("Too many constants")
Private Const ERR_231 As String = ("Too many different classes used")
Private Const ERR_232 As String = ("Too many dimensions")
Private Const ERR_233 As String = ("Too many dynamic variables")
Private Const ERR_234 As String = ("Too many enumeration references")
Private Const ERR_235 As String = ("Too many events")
Private Const ERR_236 As String = ("Too many expressions in CASE")
Private Const ERR_237 As String = ("Too many external functions")
Private Const ERR_238 As String = ("Too many functions")
Private Const ERR_239 As String = ("Too many imbricated #If...#Endif")
Private Const ERR_240 As String = ("Too many labels")
Private Const ERR_241 As String = ("Too many local variables")
Private Const ERR_242 As String = ("Too many nested WITH")
Private Const ERR_243 As String = ("Too many nested control structures.")
Private Const ERR_244 As String = ("Too many property synonymous")
Private Const ERR_245 As String = ("Too many simultaneous new strings")
Private Const ERR_246 As String = ("Too many static variables")
Private Const ERR_247 As String = ("Too many structures")
Private Const ERR_248 As String = ("Too many unknown symbols")
Private Const ERR_249 As String = ("Trailing backslash")
Private Const ERR_250 As String = ("Type mismatch")
Private Const ERR_251 As String = ("Type mismatch: wanted &1, got &2 instead")
Private Const ERR_252 As String = ("Unable to create closure")
Private Const ERR_253 As String = ("Unable to get file position")
Private Const ERR_254 As String = ("Unable to prepare function description")
Private Const ERR_255 As String = ("Unexpected &1")
Private Const ERR_256 As String = ("Unexpected end of line")
Private Const ERR_257 As String = ("Unexpected string")
Private Const ERR_258 As String = ("Unknown class '&1'")
Private Const ERR_259 As String = ("Unknown constant: gb.&1")
Private Const ERR_260 As String = ("Unknown error")
Private Const ERR_261 As String = ("Unknown file extension")
Private Const ERR_262 As String = ("Unknown identifier: &1")
Private Const ERR_263 As String = ("Unknown operator")
Private Const ERR_264 As String = ("Unknown stream size")
Private Const ERR_265 As String = ("Unknown symbol")
Private Const ERR_266 As String = ("Unknown symbol '&2' in class '&1'")
Private Const ERR_267 As String = ("Unknown user or group")
Private Const ERR_268 As String = ("Unsupported datatype")
Private Const ERR_269 As String = ("Unsupported string conversion")
Private Const ERR_270 As String = ("Useless LOCK")
Private Const ERR_271 As String = ("VarPtr() argument must be a dynamic, a static or a local variable")
Private Const ERR_272 As String = ("Void identifier")
Private Const ERR_273 As String = ("Void key")
Private Const ERR_274 As String = ("Write error")
Private Const ERR_275 As String = ("cannot find component")
Private Const ERR_276 As String = ("cannot find library")
Private Const ERR_277 As String = ("class name hidden by global declaration: &1")
Private Const ERR_278 As String = ("class name hidden by local declaration: &1")
Private Const ERR_279 As String = ("constant hidden by local declaration: &1")
Private Const ERR_280 As String = ("extern function hidden by local declaration: &1")
Private Const ERR_281 As String = ("function hidden by local declaration: &1")
Private Const ERR_282 As String = ("global variable hidden by local declaration: &1")
Private Const ERR_283 As String = ("integer and boolean mixed with `&1' operator")
Private Const ERR_284 As String = ("the left expression of `&1' should not be a boolean")
Private Const ERR_285 As String = ("the right expression of `&1' should not be a boolean")
Private Const ERR_286 As String = ("uninitialized global variable: &1")
Private Const ERR_287 As String = ("uninitialized variable: &1")
Private Const ERR_288 As String = ("unknown error")
Private Const ERR_289 As String = ("unused argument: &1")
Private Const ERR_290 As String = ("unused extern function: &1")
Private Const ERR_291 As String = ("unused function: &1")
Private Const ERR_292 As String = ("unused global variable: &1")
Private Const ERR_293 As String = ("unused variable: &1")
Private Const ERR_294 As String = ("variable prefix does not match its datatype: &1")
'}

' E_CHILD specific errors, updated by hand
Private Const ERR_CHILD_1 As String = ("cannot open slave pseudo-terminal: ")
Private Const ERR_CHILD_2 As String = ("cannot initialize pseudo-terminal: ")
Private Const ERR_CHILD_3 As String = ("cannot plug standard input: ")
Private Const ERR_CHILD_4 As String = ("cannot plug standard output and standard error: ")
Private Const ERR_CHILD_5 As String = ("cannot run executable: ")


Private $aErr As String[]

Private Sub AddError(sErr As String)
  
  If Not Trim(sErr) Then Return
  If UCase(sErr) = sErr Then Return
  If $aErr.Exist(sErr) Then Return
  $aErr.Add(sErr)
  
End

Public Sub Main()
  
  Dim sErr As String
  Dim hFile As File
  Dim sLine As String
  Dim iPos, iPos2 As Integer
  Dim sGrep As String
  Dim iInd As Integer
  Dim sData As String
  Dim sPath As String
  Dim bIgnore As Boolean
  Dim sRoot As String
  
  $aErr = New String[]

  sRoot = "~/gambas/git/master"
  
  For Each sPath In [sRoot &/ "main/gbx/gb_error.c", sRoot &/ "main/gbc/gb_error.c"]
  
    hFile = Open sPath
    While Not Eof(hFile)
      Line Input #hFile, sLine
      If InStr(sLine, "const char *const _message[") Then Break
    Wend
    
    Line Input #hFile, sLine
    Do
      Line Input #hFile, sLine
      iPos = InStr(sLine, Chr$(34))
      If iPos = 0 Then Break
      iPos2 = InStr(sLine, Chr$(34), iPos + 1)
      sErr = Mid$(sLine, iPos + 1, iPos2 - iPos - 1)
      If Left(sErr) = "." Then sErr = Mid$(sErr, 3)
      AddError(sErr)
    Loop
    
    Close #hFile
    
  Next
  
  Shell "cd " & sRoot &/ "main" & "; grep -h \"THROW(\" gbc/*.c share/*.h gbx/*.c" To sGrep
  
  For Each sLine In Split(sGrep, "\n")
    sLine = Trim(sLine)
    If Not sLine Then Continue
    If Left(sLine, 2) = "//" Then Continue
    iPos = InStr(sLine, "THROW(")
    sLine = Mid$(sLine, iPos)
    While sLine
      iPos = InStr(sLine, Chr$(34))
      If iPos = 0 Then Break
      bIgnore = Mid$(sLine, iPos - 2, 2) = "$("
      iPos2 = InStr(sLine, Chr$(34), iPos + 1)
      sErr = Mid$(sLine, iPos + 1, iPos2 - iPos - 1)
      sLine = Mid$(sLine, iPos2 + 1)
      If Not bIgnore Then AddError(sErr)
    Wend
  Next
  
  Shell "cd " & sRoot &/ "main" & "; grep -h \"COMPILE_print(MSG_WARNING,\" gbc/*.c" To sGrep
  
  For Each sLine In Split(sGrep, "\n")
    sLine = Trim(sLine)
    If Not sLine Then Continue
    If Left(sLine, 2) = "//" Then Continue
    iPos = InStr(sLine, "COMPILE_print(")
    sLine = Mid$(sLine, iPos)
    While sLine
      iPos = InStr(sLine, Chr$(34))
      If iPos = 0 Then Break
      'If Mid$(sLine, iPos - 1, 1) <> "(" Then Continue
      iPos2 = InStr(sLine, Chr$(34), iPos + 1)
      sErr = Mid$(sLine, iPos + 1, iPos2 - iPos - 1)
      sLine = Mid$(sLine, iPos2 + 1)
      AddError(sErr)
    Wend
  Next
  
  $aErr.Sort
  
  For iInd = 0 To $aErr.Max
    $aErr[iInd] = "Private Const ERR_" & Format(iInd + 1, "000") & " As String = (" & Quote($aErr[iInd]) & ")"
    Print $aErr[iInd]
  Next
  
  sPath = sRoot &/ "app/src/gambas3/.src/Util/MErrorMessage.module"
  sData = File.Load(sPath)
  iPos = InStr(sData, "\n'{\n")
  If iPos = 0 Then Return
  iPos2 = InStr(sData, "\n'}\n", iPos + 1)
  If iPos = 0 Then Return
  sData = Left(sData, iPos + 3) & $aErr.Join("\n") & Mid$(sData, iPos2)
  File.Save(sPath, sData)
  
End

