aboutsummaryrefslogtreecommitdiff
path: root/Sil/Error.icl
diff options
context:
space:
mode:
authorCamil Staps2017-07-30 00:51:48 +0200
committerCamil Staps2017-07-30 00:54:02 +0200
commit05a47988d9466b827f7dbab44bab33a67228efe9 (patch)
treec9f2ce96dec969f1d756e25357dbbe2c79dfbad2 /Sil/Error.icl
parentCleanup; add <> < > <= >= (diff)
Start with positional errors (see #5)
Diffstat (limited to 'Sil/Error.icl')
-rw-r--r--Sil/Error.icl47
1 files changed, 33 insertions, 14 deletions
diff --git a/Sil/Error.icl b/Sil/Error.icl
index 9c48ecc..ef3e4fa 100644
--- a/Sil/Error.icl
+++ b/Sil/Error.icl
@@ -7,22 +7,41 @@ import Text
import Sil.Syntax
import Sil.Types
+import Sil.Util.Parser
+
+:: ErrorPosition =
+ { ep_line :: Int
+ }
+
+instance toString ErrorPosition
+where
+ toString ep = ep.ep_line <+ ":\t"
instance toString Error
where
- toString (P_Invalid loc sym) = "Invalid token '" <+ sym <+ "' while parsing a " <+ loc <+ "."
- toString (P_Expected s) = "Expected " <+ s <+ "."
- toString (T_IllegalApplication ft et) = "Cannot apply a " <+ et <+ " to a " <+ ft <+ "."
- toString (T_IllegalField f t) = "Illegal field '" <+ f <+ "' on type " <+ t <+ "."
- toString (T_TooHighTupleArity i) = "Too high tuple arity " <+ i <+ " (maximum is 32)."
- toString (C_UndefinedName n) = "Undefined name '" <+ n <+ "'."
- toString (C_UndefinedField f) = "Undefined field '" <+ f <+ "'."
- toString C_VariableLabel = "Variable stored at label."
- toString C_FunctionOnStack = "Function stored on the stack."
- toString (C_TypeError err e) = "Type error in '" <+ e <+ "': " <+ err
- toString (C_CouldNotDeduceType e) = "Could not deduce type of '" <+ e <+ "'."
- toString (C_TypeMisMatch t e t`) = "Type mismatch: expected " <+ t <+ " for '" <+ e <+ "'; had " <+ t` <+ "."
- toString (C_BasicInitWithoutValue n) = "Basic value '" <+ n <+ "' must have an initial value."
- toString (UnknownError e) = "Unknown error: " <+ e <+ "."
+ toString (P_Invalid w tk) = "Invalid token '" <+ tk <+ "' while parsing a " <+ w <+ "."
+ toString (P_Expected s) = "Expected " <+ s <+ "."
+ toString (T_IllegalApplication ft et) = "Cannot apply a " <+ et <+ " to a " <+ ft <+ "."
+ toString (T_IllegalField f t) = "Illegal field '" <+ f <+ "' on type " <+ t <+ "."
+ toString (T_TooHighTupleArity i) = "Too high tuple arity " <+ i <+ " (maximum is 32)."
+ toString Ck_NoMainFunction = "Error: no main function."
+ toString (Ck_MainFunctionInvalidType p t) = p <+ "Error: function 'main' should not have arguments has type " <+ t <+ "."
+ toString (Ck_DuplicateFunctionName p n) = p <+ "Error: multiply defined: '" <+ n <+ "'."
+ toString (Ck_DuplicateLocalName p f arg) = p <+ "Error: multiply defined: '" <+ arg <+ "' in '" <+ f <+ "'."
+ toString (Ck_ReturnExpressionFromVoid p f) = p <+ "Type error: an expression was returned from void function '" <+ f <+ "'."
+ toString (Ck_NoReturnFromNonVoid p f) = p <+ "Type error: no return from non-void function '" <+ f <+ "'."
+ toString (Ck_LocalVoid f l) = "Type error: local variable '" <+ l <+ "' in '" <+ f <+ "' cannot have type Void."
+ toString (Ck_BasicGlobal p g) = p <+ "Error: global variable '" <+ g <+ "' cannot have a basic type."
+ toString (C_UndefinedName n) = "Undefined name '" <+ n <+ "'."
+ toString (C_UndefinedField f) = "Undefined field '" <+ f <+ "'."
+ toString C_VariableLabel = "Variable stored at label."
+ toString C_FunctionOnStack = "Function stored on the stack."
+ toString (C_CouldNotDeduceType e) = "Could not deduce type of '" <+ e <+ "'."
+ toString (C_TypeMisMatch t e u) = "Type mismatch: expected " <+ t <+ " for '" <+ e <+ "'; had " <+ u <+ "."
+ toString (C_BasicInitWithoutValue n) = "Basic value '" <+ n <+ "' must have an initial value."
+ toString (UnknownError e) = "Unknown error: " <+ e <+ "."
instance <<< Error where <<< f e = f <<< toString e <<< "\r\n"
+
+errpos :: (Positioned a) -> ErrorPosition
+errpos p = {ep_line=p.pos_line}