aboutsummaryrefslogtreecommitdiff
path: root/Sil/Error.icl
blob: 36a614b95d05ad05fd565f6fd2c0298ca210bb0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
implementation module Sil.Error

import StdFile
import StdString

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                     w tk)  = "\tInvalid token '" <+ tk <+ "' while parsing a " <+ w <+ "."
	toString (P_Expected                    s)     = "\tExpected " <+ s <+ "."
	toString (T_IllegalApplication          ft et) = "\tCannot apply a " <+ et <+ " to a " <+ ft <+ "."
	toString (T_IllegalField                f t)   = "\tIllegal field '" <+ f <+ "' on type " <+ t <+ "."
	toString (T_TooHighTupleArity           i)     = "\tToo high tuple arity " <+ i <+ " (maximum is 32)."
	toString  Ck_NoMainFunction                    = "\tError: 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)   = "\tType 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)     = "\tUndefined name '" <+ n <+ "'."
	toString (C_UndefinedField              f)     = "\tUndefined field '" <+ f <+ "'."
	toString  C_VariableLabel                      = "\tVariable stored at label."
	toString  C_FunctionOnStack                    = "\tFunction stored on the stack."
	toString (C_CouldNotDeduceType          e)     = "\tCould not deduce type of '" <+ e <+ "'."
	toString (C_TypeMisMatch                t e u) = "\tType mismatch: expected " <+ t <+ " for '" <+ e <+ "'; had " <+ u <+ "."
	toString (C_BasicInitWithoutValue       n)     = "\tBasic value '" <+ n <+ "' must have an initial value."
	toString (UnknownError                  e)     = "\tUnknown error: " <+ e <+ "."

instance <<< Error where <<< f e = f <<< toString e <<< "\r\n"

errpos :: a -> ErrorPosition | getPos a
errpos x = {ep_line=(getPos x).pp_line}