Initial revision
[TestXSLT.git] / libsablot / src / engine / error.h
1 /* 
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  * 
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  * 
12  * The Original Code is the Sablotron XSLT Processor.
13  * 
14  * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15  * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16  * Ginger Alliance Ltd. All Rights Reserved.
17  * 
18  * Contributor(s):
19  * 
20  * Alternatively, the contents of this file may be used under the
21  * terms of the GNU General Public License Version 2 or later (the
22  * "GPL"), in which case the provisions of the GPL are applicable 
23  * instead of those above.  If you wish to allow use of your 
24  * version of this file only under the terms of the GPL and not to
25  * allow others to use your version of this file under the MPL,
26  * indicate your decision by deleting the provisions above and
27  * replace them with the notice and other provisions required by
28  * the GPL.  If you do not delete the provisions above, a recipient
29  * may use your version of this file under either the MPL or the
30  * GPL.
31  */
32
33 #ifndef ErrorHIncl
34 #define ErrorHIncl
35
36 // GP: clean
37
38 /*
39 #define Err(situation, code)   { if (situation) { situation->error(code, (char*) NULL, (char*) NULL); return NOT_OK; } }
40 #define Err1(situation, code, arg1) { if (situation) { situation->error(code, arg1, (char*) NULL); return NOT_OK; } }
41 #define Err2(situation, code, arg1, arg2) { if (situation) { situation->error(code, arg1, arg2); return NOT_OK; } }
42 */
43
44 #define Err(sit, code) \
45 { report(sit, MT_ERROR, code, (char*)NULL, (char*)NULL); return NOT_OK; }
46 #define Err1(sit, code, arg1) \
47 { report(sit, MT_ERROR, code, arg1, (char*)NULL); return NOT_OK; }
48 #define Err2(sit, code, arg1, arg2) \
49 { report(sit, MT_ERROR, code, arg1, arg2); return NOT_OK; }
50
51 #define ErrT(obj, sit, code) \
52 { obj -> report(sit, MT_ERROR, code, (char*)NULL, (char*)NULL); return NOT_OK; }
53 #define Err1T(obj, sit, code, arg1) \
54 { obj -> report(sit, MT_ERROR, code, arg1, (char*)NULL); return NOT_OK; }
55 #define Err2T(obj, sit, code, arg1, arg2) \
56 { obj -> report(sit, MT_ERROR, code, arg1, arg2); return NOT_OK; }
57
58 #define E(statement) {if (statement) return NOT_OK;}
59 #define E_DO(statement, onExit) {if (statement) {{onExit;}; return NOT_OK;}}
60
61 // the memory allocation checking macro
62 // use as M( newInstance = new SomeClass );
63 #define M( sit, ptr ) {if (!(ptr)) Err(sit, E_MEMORY);}
64 #define MT( obj, sit, ptr ) {if (!(ptr)) ErrT(obj, sit, E_MEMORY);}
65
66 #define Warn(sit, code) \
67 report(sit, MT_WARN, code, (char*)NULL, (char*)NULL);
68 #define Warn1(sit, code, arg1) \
69 report(sit, MT_WARN, code, arg1, (char*)NULL);
70 #define Warn2(sit, code, arg1, arg2) \
71 report(sit, MT_WARN, code, arg1, arg2);
72 #define Log(sit, code) \
73 report(sit, MT_LOG, code, (char*)NULL, (char*)NULL);
74 #define Log1(sit, code, arg1) \
75 report(sit, MT_LOG, code, arg1, (char*)NULL);
76 #define Log2(sit, code, arg1, arg2) \
77 report(sit, MT_LOG, code, arg1, arg2);
78
79 enum MsgCode
80 {
81         
82     //
83     // errors
84     //
85             
86     // no error:
87     E_OK,
88     // generic error
89     E_NOT_OK,
90         
91     // XML parsing
92
93     // expat parsing error
94     E_XML,
95     // bad char for encoding '...' 
96     E1_BAD_CHAR,
97         
98     // resource allocation
99         
100     // file open problem
101     E_FILE_OPEN,
102     // not enough memory to open processor
103     E_MEMORY,
104
105     // XSLT parsing
106                         
107     // unsupported XSL instruction
108     E1_UNSUPP_XSL,
109     // nonexistent XSL instruction
110     ET_BAD_XSL,
111     // missing required attribute
112     ET_REQ_ATTR,
113     // unexpected attribute
114     ET_BAD_ATTR,
115     // bad axis
116     E1_UNKNOWN_AXIS,
117     // general expression syntax error
118     ET_EXPR_SYNTAX,
119     // number in bad format
120     ET_BAD_NUMBER,
121     // illegal variable name
122     ET_BAD_VAR,
123     // missing right delimiter of a literal
124     ET_INFINITE_LITERAL,
125     // '(' expected
126     ET_LPAREN_EXP,
127     // ')' expected
128     ET_RPAREN_EXP,
129     // '(' or '[' expected
130     ET_LPARCKET_EXP,
131     // ']' expected
132     ET_RBRACKET_EXP,
133     // pattern empty
134     ET_EMPTY_PATT,
135     // token not recognized
136     ET_BAD_TOKEN,
137     // patterns allow only several axes
138     E_BAD_AXIS_IN_PATTERN,
139     // invalid pattern
140     E_BAD_PATTERN,
141     // variable in match att
142     E_VAR_IN_MATCH,
143     // invalid namespace prefix
144     ET_BAD_PREFIX,
145     // name contains 2 colons
146     E1_EXTRA_COLON,
147     // this XSLT element must be empty
148     E_ELEM_MUST_EMPTY,
149     // element can only contain XSLT elements
150     E_ELEM_CONT_TEXT_OR_LRE,
151     // element cannot contain this element at this point
152     E_ELEM_CONTAINS_ELEM,
153     //element must contain PCDATA only
154     E_ELEM_MUST_BE_PCDATA,
155     // element can only be used at top level
156     E1_ELEM_TOPLEVEL,
157     // bad element content
158     E_BAD_ELEM_CONTENT,
159         
160     // XSLT stylesheet compilation
161         
162     // duplicit rule name
163     ET_DUPLICATE_RULE_NAME,
164     //duplicit attribute set name
165     ET_DUPLICATE_ASET_NAME,
166     E1_NONEX_ASET_NAME,
167     E1_CIRCULAR_ASET_REF, 
168     // name contains 2 colons
169     // E1_EXTRA_COLON,   (above)
170     // number in bad format
171     // ET_BAD_NUMBER,    (above)
172     // duplicit key name
173     E1_DUPLICIT_KEY,
174     // non-existent key name
175     E1_KEY_NOT_FOUND,
176
177     // decimal-format related:
178
179     // option specified twice
180     E1_FORMAT_DUPLICIT_OPTION,
181
182     // option value must be char
183     E1_FORMAT_OPTION_CHAR,
184
185     // decimal-format name conflict
186     E1_FORMAT_DUPLICIT_NAME,
187
188     // decimal-format not defined
189     E1_FORMAT_NOT_FOUND,
190
191     // invalid format string
192     E_FORMAT_INVALID,
193
194     // xsl:number related:
195     // invalid value of @level:
196     E1_NUMBER_LEVEL,
197     // invalid value of @letter-value:
198     E1_NUMBER_LETTER_VALUE,
199
200     // circular include/import/ext entity ref
201     E1_CIRCULAR_INCLUSION,
202         
203     // XSLT execution
204                 
205     // variable not found
206     E1_VAR_NOT_FOUND,
207     // circular var reference
208     E1_VAR_CIRCULAR_REF,
209     // expression is not a node set
210     ET_CONTEXT_FOR_BAD_EXPR,
211     // invalid # of arguments
212     ET_BAD_ARGS_N,
213     // illegal function argument type
214     ET_BAD_ARG_TYPE,
215     // called unsupported function
216     ET_FUNC_NOT_SUPPORTED,
217     // invalid namespace prefix
218     // ET_BAD_PREFIX,  (above)
219     // called non-existent rule
220     E1_RULE_NOT_FOUND,
221     // conflicting variable bindings (name)
222     E1_MULT_ASSIGNMENT,
223     // name contains 2 colons
224     // E1_EXTRA_COLON, (above)
225     // must be a yes/no attribute
226     E1_ATTR_YES_NO,
227     // attribute created after a child was added
228     E1_ATTRIBUTE_TOO_LATE,
229     // attribute with no parent
230     E1_ATTRIBUTE_OUTSIDE,
231     // character '...' is illegal in this encoding (on output)
232     E1_BAD_CHAR_IN_ENC,
233     // invalid processing instruction target
234     E1_PI_TARGET,
235     // element created inside a comment or PI
236     E_ELEM_IN_COMMENT_PI,
237     // terminating xsl:message
238     E1_XSL_MESSAGE_TERM,
239         
240     // hard to file
241         
242     // can't open document
243     E1_URI_OPEN,
244     // can't close document
245     E1_URI_CLOSE,
246     // can't read from document
247     E1_URI_READ,
248     // can't write to document
249     E1_URI_WRITE,
250     // named buffer (arg://...) not found
251     E1_ARG_NOT_FOUND,
252     // duplicit named buffer
253     E1_DUPLICATE_ARG,
254     // unsupported URI scheme
255     E1_UNSUPPORTED_SCHEME,
256     // invalid handler type
257     E1_INVALID_HLR_TYPE,
258     // unknown encoding
259     E1_UNKNOWN_ENC,         
260         
261     // DOM exception
262         
263     E2_SDOM,
264             
265     E_NONE,
266
267     //namespace exclusions
268     E_EX_NAMESPACE_UNKNOWN,
269
270     // ?> in PI data
271     E_INVALID_DATA_IN_PI,
272         
273     //extension elements
274     E_UNSUPPORTED_EXELEMENT,
275     E_ATTR_MISSING,
276     E_JS_EVAL_ERROR,
277
278     E_DUPLICIT_ATTRIBUTE,
279
280     //
281     // warnings
282     //
283         
284     // lang() not supported, returning false
285     W_UNSUPP_LANG,
286     // included/importe stylesheet is no stylesheet
287     W_NO_STYLESHEET,
288         
289     //  scheme handler warnings
290         
291     // conflicting handler registration
292     W1_HLR_REGISTERED,
293     // handler not registered, can't unregister
294     W1_HLR_NOT_REGISTERED,
295     // obsolete XSLT namespace
296     W1_OLD_NS_USED, 
297     // xsl prefix bound to non-XSLT URI
298     W1_XSL_NOT_XSL, 
299     // conflicting attributes on xsl:output
300     W1_OUTPUT_ATTR,
301     // can't disable output escaping on non-text
302     W_DISABLE_OUTPUT_ESC,
303     // unsupported output encoding
304     W1_UNSUPP_OUT_ENCODING,
305     // unsupported XSL instruction
306     W1_UNSUPP_XSL,
307     // non-terminating xsl:message
308     W1_XSL_MESSAGE_NOTERM,
309     // unknown data type on xsl:sort
310     W1_SORT_DATA_TYPE,
311     // invlaid sort order on xsl:sort
312     W1_SORT_ORDER,
313     // invalid case order on xsl:sort
314     W1_SORT_CASE_ORDER,
315     // unsupported language on xsl:sort
316     W1_LANG,
317     // wcsxfrm unavailable
318     W_NO_WCSXFRM,
319     // document starts with unrecognizable sequence
320     W_BAD_START,
321     // no valid value of @grouping-size or @grouping-seoarator on xsl:number
322     W_NUMBER_GROUPING,
323     // a non-positive number in xsl:number
324     W_NUMBER_NOT_POSITIVE,
325     // attribute set redefinition
326     W2_ATTSET_REDEF,
327     // alias redefinition
328     W1_ALIAS_REDEF,
329     //invalid xml names
330     E_INVALID_QNAME,
331     E_INVALID_NCNAME,
332     //doc fragment
333     E_DOC_FRAGMENT,
334     //invalid operand to comparison (usually EX_EXTERNAL)
335     E_INVALID_OPERAND_TYPE,
336     
337
338     W_NONE,
339
340     //
341     // log messages
342     //
343             
344     // starting processing
345     L_START,
346     // stopping processing
347     L_STOP,
348     // starting parse
349     L1_PARSING,
350     // parse finished
351     L1_PARSE_DONE,
352     // starting execution
353     L1_EXECUTING,
354     // execution finished
355     L1_EXECUTION_DONE,
356     // parsing external entity
357     L1_READING_EXT_ENTITY,
358     // destroying the arena
359     L2_DISP_ARENA,
360     // destroying the hash table
361     L2_DISP_HASH,
362     // key added
363     L2_KEY_ADDED,
364     //subsidiary document
365     L2_SUBDOC,
366     L2_SUBDOC_BASE,
367     L2_SUBDOC_STARTED,
368     //Javascript Logging
369     L_JS_LOG,
370
371     L_NONE,
372
373     //used for debugger
374     DBG_BREAK_PROCESSOR,
375
376     MSG_ERROR = 0x4000,
377     MSG_WARNING,
378     MSG_LOG,
379     
380     //terminal
381     MSG_LAST
382 };
383
384 struct SabMsg
385 {
386     MsgCode code;
387     const char *text;
388 };
389
390 extern SabMsg* GetMessage(MsgCode e);
391
392 #endif //ifndef ErrorHIncl