File: build/runtimeError.ml (return to index)



Statistics:  
kind coverage
binding 0 / 0 (- %)
sequence 0 / 0 (- %)
for 0 / 0 (- %)
if/then 0 / 0 (- %)
try 0 / 0 (- %)
while 0 / 0 (- %)
match/function 19 / 29 (65 %)
kind coverage
class expression 0 / 0 (- %)
class initializer 0 / 0 (- %)
class method 0 / 0 (- %)
class value 0 / 0 (- %)
toplevel expression 0 / 0 (- %)
lazy operator 0 / 0 (- %)



Source:

fold all unfold all
000001| (**
000002| This program is free software; you can redistribute it and / or modify
000003| it under the terms of the GNU General Public License as published by
000004| the Free Software Foundation; version 3 of the License.
000005|  
000006| This program is distributed in the hope that it will be useful,
000007| but WITHOUT ANY WARRANTY; without even the implied warranty of
000008| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
000009| GNU General Public License for more details.
000010|  
000011| This module defines runtime errors that are reported to the user
000012|  
000013| @author Tony BenBrahim < tony.benbrahim at gmail.com >
000014|  
000015| *)
000016|  
000017| open Ast
000018|  
000019| (** this error represents an unexpected condition, caused by a programming
000020| error in the interpreter implementation *)
000021| exception InternalError of string
000022|  
000023| (** this error is a generic error thrown by library routines to indicate an
000024| error condition, such as the incorrect type of a passed in argument *)
000025| exception LibraryError of string
000026|  
000027| (** this error is caused by an abnormal error caused by the lexer, such as an
000028| unterminated string **)
000029| exception LexerException of string * int * int
000030|  
000031| (** marker exception to note that the program should exit, error has already
000032| been reported during analysis *)
000033| exception FatalExit
000034|  
000035| (** indicates that an assignment was attempted on two incompatible types*)
000036| exception EIncompatibleTypes of string * string (* type1, type2 *)
000037|  
000038| (** indicates that the value is not of the expected type *)
000039| exception EInvalidCast of string * string (* value type name, typename *)
000040|  
000041| (** indicates that an invalid operation was attempted on the specified types *)
000042| exception EInvalidOperation of string * string  (* operator, typename *)
000043|  
000044| (** indicates that an invalid comparaison was attempted on the given types *)
000045| exception EInvalidComparaison of string * string * string (* comparator, typename *)
000046|  
000047| (** indicates that a member expression is not applied to a map *)
000048| exception ELeftSideIsNotAMap of string * string (* typename value *)
000049|  
000050| (** indicates that a member expression is not applied to a map *)
000051| exception ELeftSideIsNotAMap of string * string (* typename value *)
000052|  
000053| (** indicates an attempt at an assignment to something that is a not a variable or map *)
000054| exception ELeftSideCannotBeAssigned
000055|  
000056| (** indicates that the map member did not evaluate to a string or integer *)
000057| exception EInvalidMember of string * string (* typename,value *)
000058|  
000059| (** indicates that a reference was made to a map member that does not exist *)
000060| exception EUndefinedMapMember of string (* value *)
000061|  
000062| (** indicates a non integer array index *)
000063| exception EInvalidArrayIndex of string * string (* type value *)
000064|  
000065| (** indicates an out of bounds index *)
000066| exception EArrayIndexOutOfBounds of string (*index*)
000067|  
000068| (** indicates that the type in the assignment does not match the declare type *)
000069| exception ETypeMismatchInAssignment of string * string * string (* name oldtype new type *)
000070|  
000071| (** indicates that an incorrect number of arguments were passed to a function *)
000072| exception EMismatchedFunctionArgs of int * int (* expected actual *)
000073|  
000074| (** indicates an attempt to apply a function to a non function *)
000075| exception ENotAFunction
000076|  
000077| (** indicates applying for each on a non collection type *)
000078| exception ENotACollectionType of string * string (* message, value *)
000079|  
000080| (** indicates that the default case should be last *)
000081| exception EDefaultCaseShouldBeLast
000082|  
000083| (** indicates a parsing error *)
000084| exception ParseException of string
000085|  
000086| let string_of_error ex =
000087|         match ex with
000088|         | InternalError msg -> (*[14]*)"INT-00 internal error, interpreter is in inconsistent state: "^msg
000089|         | LibraryError msg -> (*[14]*)"LIB-00 library error: "^msg
000090|         | LexerException (msg, line, col) -> (*[0]*)"PRS-00 parsing error: " ^ msg ^ " at line " ^
000091|                         (string_of_int line) ^ " column " ^ (string_of_int col)
000092|         | ParseException msg -> (*[0]*)"PRS-01 parsing error: " ^ msg
000093|         | EIncompatibleTypes(type1, type2) -> (*[6]*)"EXP-00 incompatible types " ^ type1 ^ " and " ^ type2
000094|         | EInvalidCast(type1, type2) ->(*[4]*)"EXP-01 cannot cast a " ^ type1 ^ " to a " ^ type2
000095|         | EInvalidOperation(operator, type1) -> (*[4]*)"EXP-02 invalid operation " ^ operator ^ " for " ^ type1 ^ "s"
000096|         | EInvalidComparaison(operator, type1, type2) -> (*[2]*)"EXP-03 invalid comparaison " ^ operator ^ " for " ^
000097|                         type1 ^ " and " ^ type2
000098|         | ELeftSideIsNotAMap (typename, value) -> (*[8]*)"EXP-04 left side of member expression is not a map or array, but a " ^
000099|                         typename ^ " with value " ^ value
000100|         | ELeftSideCannotBeAssigned -> (*[2]*)"EXP-05 left side of assignment expression cannot be assigned"
000101|         | EInvalidMember (typename, value) -> (*[4]*)"EXP-06 member expression did not evaluate to a string or integer, but to a " ^
000102|                         typename ^ " with value " ^ value
000103|         | EUndefinedMapMember(name) -> (*[2]*)"EXP-07 member expression " ^ name ^ " is undefined"
000104|         | EInvalidArrayIndex(typename, value) -> (*[2]*)"EXP-08 invalid array index of type " ^ typename ^ " with value " ^ value
000105|         | EArrayIndexOutOfBounds(value) -> (*[4]*)"EXP-09 array index out of bounds: " ^ value
000106|         | ETypeMismatchInAssignment(name, shouldbe, is) -> (*[2]*)"EXP-10 type mismatch in assignment of " ^ name ^
000107|                         " declared as " ^ shouldbe ^ ", attempting to assign "^is
000108|         | EMismatchedFunctionArgs(expected, actual) -> (*[6]*)"EXP-11 wrong number of arguments in function call, expected " ^
000109|                         (string_of_int expected) ^ ", got " ^ (string_of_int actual)
000110|         | ENotAFunction -> (*[2]*)"EXP-12 invalid function call on a non-function variable"
000111|         | ENotACollectionType (msg, typename) -> (*[2]*)"EXP-13 expected a collection type for " ^ msg ^ ", but got a " ^
000112|                         typename
000113|         | Division_by_zero -> (*[2]*)"EXP-14 Division by zero"
000114|         | EDefaultCaseShouldBeLast -> (*[6]*)"STM-00 the default case in a switch statement should be the last case"
000115|         | CFReturn _ -> (*[0]*)"STM-01 unexpected return statement outside of a function definition"
000116|         | CFBreak -> (*[0]*)"STM-02 unexpected break statement outside of a loop"
000117|         | CFContinue -> (*[0]*)"STM-03 unexpected continue statement outside of a loop"
000118|         | CFUserException (_, value) -> (*[0]*)"USR-00 unhandled user exception " ^ value
000119|         | Parsing.Parse_error -> (*[0]*)""
000120|         | e -> (*[2]*)"uncaught exception "^(Printexc.to_string e)
000121|  
000122| let display_error err cloc =
000123|         (*[0]*)let (file, line) = cloc
000124|         in match string_of_error err with
000125|         | "" -> (*[0]*)()
000126|         | msg -> (*[0]*)print_string ("\nAt line " ^ (string_of_int line) ^ " in file " ^ file ^ ":\n\t" ^
000127|                                         msg ^ "\n" )

Legend:
   some code - line containing no point
   some code - line containing only visited points
   some code - line containing only unvisited points
   some code - line containing both visited and unvisited points