Kiwi Engine
VM for interpreter
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
KEException.h
Go to the documentation of this file.
1 
8 #ifndef KEEXCEPTION_H
9 #define KEEXCEPTION_H
10 
11 #include "KEForwarders.h"
12 #include "KELineInfo.h"
13 
15 typedef enum {
27 
31 struct KEException {
35  struct KELineInfo * lineInfo ;
37  union {
38  struct {
40  int exitCode ;
41  } exitException ;
42  struct {
43  struct KEPath * givenPath ;
44  } invalidPathException ;
45  struct {
46  uint64_t invalidIndex ;
47  } invalidArrayIndex ;
48  struct {
49  struct CNString * nonExistKey ;
50  } nonExistDictionaryKey ;
51  } ; /* No name */
52 } ;
53 
58 static inline struct KEException
59 KEMakeNoException(void)
60 {
61  struct KEException except = {
63  .lineInfo = NULL
64  } ;
65  return except ;
66 }
67 
72 static inline void
73 KEDestroyException(struct KEException * dst)
74 {
75  if(dst->lineInfo){
76  KEReleaseLineInfo(dst->lineInfo) ;
77  }
78 }
79 
86 static inline void
87 KESetExitException(struct KEException * dst, int code, struct KELineInfo * linfo)
88 {
90  KERetainLineInfo(dst->lineInfo = linfo) ;
91  (dst->exitException).exitCode = code ;
92 }
93 
99 static inline void
100 KESetZeroDivideException(struct KEException * dst, struct KELineInfo * linfo)
101 {
103  KERetainLineInfo(dst->lineInfo = linfo) ;
104 }
105 
111 static inline void
112 KESetZeroModuleException(struct KEException * dst, struct KELineInfo * linfo)
113 {
115  KERetainLineInfo(dst->lineInfo = linfo) ;
116 }
117 
124 static inline void
125 KESetInvalidPathException(struct KEException * dst, struct KEPath * path, struct KELineInfo * linfo)
126 {
128  KERetainLineInfo(dst->lineInfo = linfo) ;
129  (dst->invalidPathException).givenPath = path ;
130 }
131 
138 static inline void
139 KESetInvalidArrayIndexException(struct KEException * dst, uint64_t index, struct KELineInfo * linfo)
140 {
142  KERetainLineInfo(dst->lineInfo = linfo) ;
143  (dst->invalidArrayIndex).invalidIndex = index ;
144 
145 }
146 
153 static inline void
154 KESetNonExistDictionaryKeyException(struct KEException * dst, struct CNString * key, struct KELineInfo * linfo)
155 {
157  KERetainLineInfo(dst->lineInfo = linfo) ;
158  (dst->nonExistDictionaryKey).nonExistKey = key ;
159 }
160 
167 static inline void
168 KESetJumpException(struct KEException * dst, KEExceptionKind kind, struct KELineInfo * linfo)
169 {
170  dst->exceptionKind = kind ;
171  KERetainLineInfo(dst->lineInfo = linfo) ;
172 }
173 
180 static inline CNBoolean
181 KEHasException(const struct KEException * src)
182 {
183  return src->exceptionKind != KENoException ;
184 }
185 
191 void
192 KEPrintException(FILE * outfp, const struct KEException * src) ;
193 
194 #endif /* KEEXCEPTION_H */
KEProgram class.
Definition: KELineInfo.h:19
KEExceptionKind
Definition: KEException.h:15
Definition: KEException.h:17
Definition: KEException.h:20
Exception information.
Definition: KEException.h:31
void KEPrintException(FILE *outfp, const struct KEException *src)
Print exception information.
Definition: KEException.h:22
Definition: KEException.h:19
Definition: KEException.h:24
Define KELineInfo class.
KEExceptionKind exceptionKind
Definition: KEException.h:33
Definition: KEException.h:16
Definition: KEException.h:21
Definition: KEException.h:25
struct KELineInfo * lineInfo
Definition: KEException.h:35
Forward declarations of the data type in KiwiEngine.
int exitCode
Definition: KEException.h:40
Definition: KEPath.h:16
Definition: KEException.h:23
Definition: KEException.h:18