xref: /trunk/main/idlc/source/errorhandler.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_idlc.hxx"
30 #include <idlc/errorhandler.hxx>
31 #include <idlc/astinterface.hxx>
32 
33 using namespace ::rtl;
34 
35 static const sal_Char* errorCodeToMessage(ErrorCode eCode)
36 {
37     switch (eCode)
38     {
39     case EIDL_NONE:
40         return "all is fine ";
41     case EIDL_SYNTAX_ERROR:
42         return "";
43     case EIDL_REDEF:
44         return "illegal redefinition ";
45     case EIDL_REDEF_SCOPE:
46         return "illegal redefinition in scope ";
47     case EIDL_DEF_USE:
48         return "redefinition after use, ";
49     case EIDL_MULTIPLE_BRANCH:
50         return "union with duplicate branch label ";
51     case EIDL_COERCION_FAILURE:
52         return "coercion failure ";
53     case EIDL_SCOPE_CONFLICT:
54         return "definition scope is different than fwd declare scope, ";
55     case EIDL_ONEWAY_CONFLICT:
56         return "oneway operation with OUT|INOUT parameters or raises exceptions, ";
57     case EIDL_DISC_TYPE:
58         return "union with illegal discriminator type, ";
59     case EIDL_LABEL_TYPE:
60         return "label type incompatible with union discriminator type, ";
61     case EIDL_ILLEGAL_ADD:
62         return "illegal add operation, ";
63     case EIDL_ILLEGAL_USE:
64         return "illegal type used in expression, ";
65     case EIDL_ILLEGAL_RAISES:
66         return "non-exception type in raises(..) clause, ";
67     case EIDL_CANT_INHERIT:
68         return "cannot inherit ";
69     case EIDL_LOOKUP_ERROR:
70         return "error in lookup of symbol: ";
71     case EIDL_INHERIT_FWD_ERROR:
72         return "";
73     case EIDL_CONSTANT_EXPECTED:
74         return "constant expected: ";
75     case EIDL_NAME_CASE_ERROR:
76         return "identifier used with two differing spellings: ";
77     case EIDL_ENUM_VAL_EXPECTED:
78         return "enumerator expected: ";
79     case EIDL_ENUM_VAL_NOT_FOUND:
80         return "enumerator by this name not defined: ";
81     case EIDL_EVAL_ERROR:
82         return "expression evaluation error: ";
83     case EIDL_AMBIGUOUS:
84         return "ambiguous definition: ";
85     case EIDL_DECL_NOT_DEFINED:
86         return "forward declared but never defined: ";
87     case EIDL_FWD_DECL_LOOKUP:
88         return "";
89     case EIDL_RECURSIVE_TYPE:
90         return "illegal recursive use of type: ";
91     case EIDL_NONVOID_ONEWAY:
92         return "non-void return type in oneway operation: ";
93     case EIDL_NOT_A_TYPE:
94         return "specified symbol is not a type: ";
95     case EIDL_TYPE_NOT_VALID:
96         return "specified type is not valid in this context: ";
97     case EIDL_INTERFACEMEMBER_LOOKUP:
98         return "error in lookup of symbol, expected interface is not defined and no forward exists: ";
99     case EIDL_SERVICEMEMBER_LOOKUP:
100         return "error in lookup of symbol, expected service is not defined: ";
101     case EIDL_TYPE_IDENT_CONFLICT:
102         return "type and parameter/member name are equal: ";
103     case EIDL_ONEWAY_RAISE_CONFLICT:
104         return "oneway operation cannot raises exceptions: ";
105     case EIDL_WRONGATTRIBUTEFLAG:
106         return "the used flag is not valid in this context: ";
107     case EIDL_DEFINED_ATTRIBUTEFLAG:
108         return "flag is already set: ";
109     case EIDL_WRONGATTRIBUTEKEYWORD:
110         return "keyword not allowed: ";
111     case EIDL_MISSINGATTRIBUTEKEYWORD:
112         return "missing keyword: ";
113     case EIDL_BAD_ATTRIBUTE_FLAGS:
114         return
115             "the 'attribute' flag is mandatory, and only the 'bound' and"
116             " 'readonly' optional flags are accepted: ";
117     case EIDL_OPTIONALEXPECTED:
118         return "only the 'optional' flag is accepted: ";
119     case EIDL_MIXED_INHERITANCE:
120         return "interface inheritance declarations cannot appear in both an"
121             " interface's header and its body";
122     case EIDL_DOUBLE_INHERITANCE:
123         return
124             "interface is (directly or indirectly) inherited more than once: ";
125     case EIDL_DOUBLE_MEMBER:
126         return
127             "member is (directly or indirectly) declared more than once: ";
128     case EIDL_CONSTRUCTOR_PARAMETER_NOT_IN:
129         return
130             "a service constructor parameter may not be an out or inout"
131             " parameter";
132     case EIDL_CONSTRUCTOR_REST_PARAMETER_NOT_FIRST:
133         return
134             "no parameters may precede a rest parameter in a service"
135             " constructor";
136     case EIDL_REST_PARAMETER_NOT_LAST:
137         return "no parameters may follow a rest parameter";
138     case EIDL_REST_PARAMETER_NOT_ANY:
139         return "a rest parameter must be of type any";
140     case EIDL_METHOD_HAS_REST_PARAMETER:
141         return "a rest parameter may not be used on an interface method";
142     case EIDL_READONLY_ATTRIBUTE_SET_EXCEPTIONS:
143         return "a readonly attribute may not have a setter raises clause";
144     case EIDL_UNSIGNED_TYPE_ARGUMENT:
145         return "an unsigned type cannot be used as a type argument";
146     case EIDL_WRONG_NUMBER_OF_TYPE_ARGUMENTS:
147         return
148             "the number of given type arguments does not match the expected"
149             " number of type parameters";
150     case EIDL_INSTANTIATED_STRUCT_TYPE_TYPEDEF:
151         return
152             "an instantiated polymorphic struct type cannot be used in a"
153             " typedef";
154     case EIDL_IDENTICAL_TYPE_PARAMETERS:
155         return "two type parameters have the same name";
156     case EIDL_STRUCT_TYPE_TEMPLATE_WITH_BASE:
157         return "a polymorphic struct type template may not have a base type";
158     case EIDL_PUBLISHED_FORWARD:
159         return
160             "a published forward declaration of an interface type cannot be"
161             " followed by an unpublished declaration of that type";
162     case EIDL_PUBLISHED_USES_UNPUBLISHED:
163         return
164             "an unpublished entity cannot be used in the declaration of a"
165             " published entity: ";
166     case EIDL_SIMILAR_CONSTRUCTORS:
167         return "two constructors have identical lists of parameter types";
168     }
169     return "unknown errror";
170 }
171 
172 static const sal_Char* warningCodeToMessage(WarningCode wCode)
173 {
174     switch (wCode)
175     {
176     case WIDL_EXPID_CONFLICT:
177         return "exception id conflict: ";
178     case WIDL_REQID_CONFLICT:
179         return "request id conflict: ";
180     case WIDL_INHERIT_IDCONFLICT:
181         return "request id conflict in inheritance tree: ";
182     case WIDL_TYPE_IDENT_CONFLICT:
183         return "type and parameter|member name are equal: ";
184     case WIDL_WRONG_NAMING_CONV:
185         return "type or identifier doesn't fulfill the UNO naming convention: ";
186     }
187     return "unkown warning";
188 }
189 
190 static const sal_Char* parseStateToMessage(ParseState state)
191 {
192     switch (state)
193     {
194     case PS_NoState:
195         return "Statement can not be parsed";
196     case PS_TypeDeclSeen:
197         return "Malformed type declaration";
198     case PS_ConstantDeclSeen:
199         return "Malformed const declaration";
200     case PS_ExceptionDeclSeen:
201         return "Malformed exception declaration";
202     case PS_InterfaceDeclSeen:
203         return "Malformed interface declaration";
204     case PS_ServiceDeclSeen:
205         return "Malformed servicve declaration";
206     case PS_ModuleDeclSeen:
207         return "Malformed module declaration";
208     case PS_AttributeDeclSeen:
209         return "Malformed attribute declaration";
210     case PS_PropertyDeclSeen:
211         return "Malformed property declaration";
212     case PS_OperationDeclSeen:
213         return "Malformed operation declaration";
214     case PS_InterfaceInheritanceDeclSeen:
215         return "Malformed interface inheritance declaration";
216     case PS_ConstantsDeclSeen:
217         return "Malformed constants declaration";
218     case PS_ServiceSeen:
219         return "Missing service identifier following SERVICE keyword";
220     case PS_ServiceIDSeen:
221         return "Missing '{' or illegal syntax following service identifier";
222     case PS_ServiceSqSeen:
223         return "Illegal syntax following service '{' opener";
224     case PS_ServiceBodySeen:
225         return "Illegal syntax following service '}' closer";
226     case PS_ServiceMemberSeen:
227         return "Illegal syntax following service member declaration";
228     case PS_ServiceIFHeadSeen:
229         return "Illegal syntax following header of an interface member";
230     case PS_ServiceSHeadSeen:
231         return "Illegal syntax following header of an service member";
232     case PS_ModuleSeen:
233         return "Missing module identifier following MODULE keyword";
234     case PS_ModuleIDSeen:
235         return "Missing '{' or illegal syntax following module identifier";
236     case PS_ModuleSqSeen:
237         return "Illegal syntax following module '{' opener";
238     case PS_ModuleQsSeen:
239         return "Illegal syntax following module '}' closer";
240     case PS_ModuleBodySeen:
241         return "Illegal syntax following module export(s)";
242     case PS_ConstantsSeen:
243         return "Missing constants identifier following CONSTANTS keyword";
244     case PS_ConstantsIDSeen:
245         return "Missing '{' or illegal syntax following constants identifier";
246     case PS_ConstantsSqSeen:
247         return "Illegal syntax following module '{' opener";
248     case PS_ConstantsQsSeen:
249         return "Illegal syntax following module '}' closer";
250     case PS_ConstantsBodySeen:
251         return "Illegal syntax following constants export(s)";
252     case PS_InterfaceSeen:
253         return "Missing interface identifier following INTERFACE keyword";
254     case PS_InterfaceIDSeen:
255         return "Illegal syntax following interface identifier";
256     case PS_InterfaceHeadSeen:
257         return "Illegal syntax following interface head";
258     case PS_InheritSpecSeen:
259         return "Missing '{' or illegal syntax following inheritance spec";
260     case PS_ForwardDeclSeen:
261         return "Missing ';' following forward interface declaration";
262     case PS_InterfaceSqSeen:
263         return "Illegal syntax following interface '{' opener";
264     case PS_InterfaceQsSeen:
265         return "Illegal syntax following interface '}' closer";
266     case PS_InterfaceBodySeen:
267         return "Illegal syntax following interface export(s)";
268     case PS_InheritColonSeen:
269         return "Illegal syntax following ':' starting inheritance list";
270     case PS_SNListCommaSeen:
271         return "Found illegal scoped name in scoped name list";
272     case PS_ScopedNameSeen:
273         return "Missing ',' following scoped name in scoped name list";
274     case PS_SN_IDSeen:
275         return "Illegal component in scoped name";
276     case PS_ScopeDelimSeen:
277         return "Illegal component in scoped name following '::'";
278     case PS_ConstSeen:
279         return "Missing type or illegal syntax following CONST keyword";
280     case PS_ConstTypeSeen:
281         return "Missing identifier or illegal syntax following const type";
282     case PS_ConstIDSeen:
283         return "Missing '=' or illegal syntax after const identifier";
284     case PS_ConstAssignSeen:
285         return "Missing value expr or illegal syntax following '='";
286     case PS_ConstExprSeen:
287         return "Missing ';' or illegal syntax following value expr in const";
288     case PS_TypedefSeen:
289         return "Missing type or illegal syntax following TYPEDEF keyword";
290     case PS_TypeSpecSeen:
291         return "Missing declarators or illegal syntax following type spec";
292     case PS_DeclaratorsSeen:
293         return "Illegal syntax following declarators in TYPEDEF declaration";
294     case PS_StructSeen:
295         return "Missing struct identifier following STRUCT keyword";
296     case PS_StructHeaderSeen:
297         return "Missing '{' or illegal syntax following struct inheritance spec";
298     case PS_StructIDSeen:
299         return "Missing '{' or illegal syntax following struct identifier";
300     case PS_StructSqSeen:
301         return "Illegal syntax following struct '{' opener";
302     case PS_StructQsSeen:
303         return "Illegal syntax following struct '}' closer";
304     case PS_StructBodySeen:
305         return "Illegal syntax following struct member(s)";
306     case PS_MemberTypeSeen:
307         return "Illegal syntax or missing identifier following member type";
308     case PS_MemberDeclsSeen:
309         return "Illegal syntax following member declarator(s)";
310     case PS_MemberDeclsCompleted:
311         return "Missing ',' between member decls of same type(?)";
312     case PS_UnionSeen:
313         return "Missing identifier following UNION keyword";
314     case PS_UnionIDSeen:
315         return "Illegal syntax following union identifier";
316     case PS_SwitchSeen:
317         return "Illegal syntax following SWITCH keyword";
318     case PS_SwitchOpenParSeen:
319         return "Illegal syntax following '(' in switch in union";
320     case PS_SwitchTypeSeen:
321         return "Illegal syntax following type decl in switch in union";
322     case PS_SwitchCloseParSeen:
323         return "Missing union '{' opener";
324     case PS_UnionSqSeen:
325         return "Illegal syntax following union '{' opener";
326     case PS_UnionQsSeen:
327         return "Illegal syntax following union '}' closer";
328     case PS_DefaultSeen:
329         return "Illegal syntax or missing ':' following DEFAULT keyword";
330     case PS_UnionLabelSeen:
331         return "Illegal syntax following branch label in union";
332     case PS_LabelColonSeen:
333         return "Illegal syntax following ':' in branch label in union";
334     case PS_LabelExprSeen:
335         return "Illegal syntax following label expression in union";
336     case PS_UnionElemSeen:
337     case PS_UnionElemCompleted:
338         return "Illegal syntax following union element";
339     case PS_CaseSeen:
340         return "Illegal syntax following CASE keyword in union";
341     case PS_UnionElemTypeSeen:
342         return "Illegal syntax following type decl in union element";
343     case PS_UnionElemDeclSeen:
344         return "Illegal syntax following declarator in union element";
345     case PS_UnionBodySeen:
346         return "Illegal syntax following union body statement(s)";
347     case PS_EnumSeen:
348         return "Illegal syntax or missing identifier following ENUM keyword";
349     case PS_EnumIDSeen:
350         return "Illegal syntax or missing '{' following enum identifier";
351     case PS_EnumSqSeen:
352         return "Illegal syntax following enum '{' opener";
353     case PS_EnumQsSeen:
354         return "Illegal syntax following enum '}' closer";
355     case PS_EnumBodySeen:
356         return "Illegal syntax following enum enumerator(s)";
357     case PS_EnumCommaSeen:
358         return "Illegal syntax or missing identifier following ',' in enum";
359     case PS_SequenceSeen:
360         return "Illegal syntax or missing '<' following SEQUENCE keyword";
361     case PS_SequenceSqSeen:
362         return "Illegal syntax or missing type following '<' in sequence";
363     case PS_SequenceQsSeen:
364         return "Illegal syntax following '>' in sequence";
365     case PS_SequenceTypeSeen:
366         return "Illegal syntax following sequence type declaration";
367     case PS_ArrayIDSeen:
368         return "Illegal syntax or missing dimensions after array identifier";
369     case PS_ArrayCompleted:
370         return "Illegal syntax after array declaration";
371     case PS_DimSqSeen:
372         return "Illegal syntax or missing size expr after '[' in array declaration";
373     case PS_DimQsSeen:
374         return "Illegal syntax after ']' in array declaration";
375     case PS_DimExprSeen:
376         return "Illegal syntax or missing ']' after size expr in array declaration";
377     case PS_FlagHeaderSeen:
378         return "Illegal syntax after flags";
379     case PS_AttrSeen:
380         return "Illegal syntax after ATTRIBUTE keyword";
381     case PS_AttrTypeSeen:
382         return "Illegal syntax after type in attribute declaration";
383     case PS_AttrCompleted:
384         return "Illegal syntax after attribute declaration";
385     case PS_ReadOnlySeen:
386         return "Illegal syntax after READONLY keyword";
387     case PS_OptionalSeen:
388         return "Illegal syntax after OPTIONAL keyword";
389     case PS_MayBeVoidSeen:
390         return "Illegal syntax after MAYBEVOID keyword";
391     case PS_BoundSeen:
392         return "Illegal syntax after BOUND keyword";
393     case PS_ConstrainedSeen:
394         return "Illegal syntax after CONSTRAINED keyword";
395     case PS_TransientSeen:
396         return "Illegal syntax after TRANSIENT keyword";
397     case PS_MayBeAmbigiousSeen:
398         return "Illegal syntax after MAYBEAMBIGIOUS keyword";
399     case PS_MayBeDefaultSeen:
400         return "Illegal syntax after MAYBEDEFAULT keyword";
401     case PS_RemoveableSeen:
402         return "Illegal syntax after REMOVEABLE keyword";
403     case PS_PropertySeen:
404         return "Illegal syntax after PROPERTY keyword";
405     case PS_PropertyTypeSeen:
406         return "Illegal syntax after type in property declaration";
407     case PS_PropertyCompleted:
408         return "Illegal syntax after property declaration";
409     case PS_ExceptSeen:
410         return "Illegal syntax or missing identifier after EXCEPTION keyword";
411     case PS_ExceptHeaderSeen:
412         return "Missing '{' or illegal syntax following exception inheritance spec";
413     case PS_ExceptIDSeen:
414         return "Illegal syntax or missing '{' after exception identifier";
415     case PS_ExceptSqSeen:
416         return "Illegal syntax after exception '{' opener";
417     case PS_ExceptQsSeen:
418         return "Illegal syntax after exception '}' closer";
419     case PS_ExceptBodySeen:
420         return "Illegal syntax after exception member(s)";
421     case PS_OpHeadSeen:
422         return "Illegasl syntax after operation header";
423     case PS_OpTypeSeen:
424         return "Illegal syntax or missing identifier after operation type";
425     case PS_OpIDSeen:
426         return "Illegal syntax or missing '(' after operation identifier";
427     case PS_OpParsCompleted:
428         return "Illegal syntax after operation parameter list";
429     case PS_OpCompleted:
430         return "Illegal syntax after operation declaration";
431     case PS_OpSqSeen:
432         return "Illegal syntax after operation parameter list '(' opener";
433     case PS_OpQsSeen:
434         return "Illegal syntax after operation parameter list ')' closer";
435     case PS_OpParCommaSeen:
436         return "Illegal syntax or missing direction in parameter declaration";
437     case PS_OpParDirSeen:
438         return "Illegal syntax or missing type in parameter declaration";
439     case PS_OpParTypeSeen:
440         return "Illegal syntax or missing declarator in parameter declaration";
441     case PS_OpParDeclSeen:
442         return "Illegal syntax following parameter declarator";
443     case PS_OpOnewaySeen:
444         return "Illegal syntax after ONEWAY keyword";
445     case PS_RaiseSeen:
446         return "Illegal syntax or missing '(' after RAISES keyword";
447     case PS_RaiseSqSeen:
448         return "Illegal syntax after RAISES '(' opener";
449     case PS_RaiseQsSeen:
450         return "Illegal syntax after RAISES ')' closer";
451     case PS_DeclsCommaSeen:
452         return "Illegal syntax after ',' in declarators list";
453     case PS_DeclsDeclSeen:
454         return "Illegal syntax after declarator in declarators list";
455     default:
456         return "no wider described syntax error";
457     }
458 }
459 
460 static OString flagToString(sal_uInt32 flag)
461 {
462     OString flagStr;
463     if ( (flag & AF_READONLY) == AF_READONLY )
464         flagStr += "'readonly'";
465     if ( (flag & AF_OPTIONAL) == AF_OPTIONAL )
466         flagStr += "'optional'";
467     if ( (flag & AF_MAYBEVOID) == AF_MAYBEVOID )
468         flagStr += "'maybevoid'";
469     if ( (flag & AF_BOUND) == AF_BOUND )
470         flagStr += "'bound'";
471     if ( (flag & AF_CONSTRAINED) == AF_CONSTRAINED )
472         flagStr += "'constrained'";
473     if ( (flag & AF_TRANSIENT) == AF_TRANSIENT )
474             flagStr += "'transient'";
475     if ( (flag & AF_MAYBEAMBIGUOUS) == AF_MAYBEAMBIGUOUS )
476         flagStr += "'maybeambiguous'";
477     if ( (flag & AF_MAYBEDEFAULT) == AF_MAYBEDEFAULT )
478         flagStr += "'maybedefault'";
479     if ( (flag & AF_REMOVEABLE) == AF_REMOVEABLE )
480         flagStr += "'removeable'";
481     if ( (flag & AF_ATTRIBUTE) == AF_ATTRIBUTE )
482         flagStr += "'attribute'";
483     if ( (flag & AF_PROPERTY) == AF_PROPERTY )
484         flagStr += "'property'";
485     if ( !flagStr.getLength() )
486         flagStr += "'unknown'";
487 
488     return flagStr;
489 }
490 
491 static void errorHeader(ErrorCode eCode, sal_Int32 lineNumber)
492 {
493     OString file;
494     if ( idlc()->getFileName() == idlc()->getRealFileName() )
495         file = idlc()->getMainFileName();
496     else
497         file = idlc()->getFileName();
498 
499     fprintf(stderr, "%s(%lu) : %s", file.getStr(),
500             sal::static_int_cast< unsigned long >(lineNumber),
501             errorCodeToMessage(eCode));
502 }
503 
504 static void errorHeader(ErrorCode eCode)
505 {
506     errorHeader(eCode, idlc()->getLineNumber());
507 }
508 
509 static void warningHeader(WarningCode wCode)
510 {
511     OString file;
512     if ( idlc()->getFileName() == idlc()->getRealFileName() )
513         file = idlc()->getMainFileName();
514     else
515         file = idlc()->getFileName();
516 
517     fprintf(stderr, "%s(%lu) : WARNING, %s", file.getStr(),
518             sal::static_int_cast< unsigned long >(idlc()->getLineNumber()),
519             warningCodeToMessage(wCode));
520 }
521 
522 void ErrorHandler::error0(ErrorCode e)
523 {
524     errorHeader(e);
525     fprintf(stderr, "\n");
526     idlc()->incErrorCount();
527 }
528 
529 void ErrorHandler::error1(ErrorCode e, AstDeclaration const * d)
530 {
531     errorHeader(e);
532     fprintf(stderr, "'%s'\n", d->getScopedName().getStr());
533     idlc()->incErrorCount();
534 }
535 
536 void ErrorHandler::error2(
537     ErrorCode e, AstDeclaration const * d1, AstDeclaration const * d2)
538 {
539     errorHeader(e);
540     fprintf(stderr, "'%s', '%s'\n", d1->getScopedName().getStr(),
541             d2->getScopedName().getStr());
542     idlc()->incErrorCount();
543 }
544 
545 void ErrorHandler::error3(ErrorCode e, AstDeclaration* d1, AstDeclaration* d2, AstDeclaration* d3)
546 {
547     errorHeader(e);
548     fprintf(stderr, "'%s', '%s', '%s'\n", d1->getScopedName().getStr(),
549             d2->getScopedName().getStr(), d3->getScopedName().getStr());
550     idlc()->incErrorCount();
551 }
552 
553 void ErrorHandler::warning0(WarningCode w, const sal_Char* warningmsg)
554 {
555     if ( idlc()->getOptions()->isValid("-w") || idlc()->getOptions()->isValid("-we") ) {
556         warningHeader(w);
557         fprintf(stderr, "%s\n", warningmsg);
558     }
559 
560     if ( idlc()->getOptions()->isValid("-we") )
561         idlc()->incErrorCount();
562     else
563         idlc()->incWarningCount();
564 }
565 
566 void ErrorHandler::syntaxError(ParseState ps, sal_Int32 lineNumber, const sal_Char* errmsg)
567 {
568     errorHeader(EIDL_SYNTAX_ERROR, lineNumber);
569     fprintf(stderr, "%s: %s\n", parseStateToMessage(ps), errmsg);
570     idlc()->incErrorCount();
571 }
572 
573 void ErrorHandler::coercionError(AstExpression *pExpr, ExprType et)
574 {
575     errorHeader(EIDL_COERCION_FAILURE);
576     fprintf(stderr, "'%s' to '%s'\n", pExpr->toString().getStr(),
577             exprTypeToString(et));
578     idlc()->incErrorCount();
579 }
580 
581 void ErrorHandler::lookupError(const ::rtl::OString& n)
582 {
583     errorHeader(EIDL_LOOKUP_ERROR);
584     fprintf(stderr, "'%s'\n", n.getStr());
585     idlc()->incErrorCount();
586 }
587 
588 void ErrorHandler::lookupError(ErrorCode e, const ::rtl::OString& n, AstDeclaration* pScope)
589 {
590     errorHeader(e);
591     fprintf(stderr, "'%s' in '%s'\n", n.getStr(), pScope->getFullName().getStr());
592     idlc()->incErrorCount();
593 }
594 
595 void ErrorHandler::flagError(ErrorCode e, sal_uInt32 flag)
596 {
597     errorHeader(e);
598     fprintf(stderr, "'%s'\n", flagToString(flag).getStr());
599     idlc()->incErrorCount();
600 }
601 
602 void ErrorHandler::noTypeError(AstDeclaration const * pDecl)
603 {
604     errorHeader(EIDL_NOT_A_TYPE);
605     fprintf(stderr, "'%s'\n", pDecl->getScopedName().getStr());
606     idlc()->incErrorCount();
607 }
608 
609 namespace {
610 
611 char const * nodeTypeName(NodeType nodeType) {
612     switch (nodeType) {
613     case NT_interface:
614         return "interface";
615 
616     case NT_exception:
617         return "exception";
618 
619     case NT_struct:
620         return "struct";
621 
622     default:
623         return "";
624     }
625 }
626 
627 }
628 
629 void ErrorHandler::inheritanceError(NodeType nodeType, const OString* name, AstDeclaration* pDecl)
630 {
631     if ( nodeType == NT_interface &&
632          (pDecl->getNodeType() == NT_interface) &&
633          !((AstInterface*)pDecl)->isDefined() )
634     {
635         errorHeader(EIDL_INHERIT_FWD_ERROR);
636         fprintf(stderr, "interface '%s' cannot inherit from forward declared interface '%s'\n",
637                 name->getStr(), pDecl->getScopedName().getStr());
638     } else
639     {
640         errorHeader(EIDL_CANT_INHERIT);
641         fprintf(stderr, "%s '%s' from '%s'\n",
642                 nodeTypeName(nodeType), name->getStr(),
643                 pDecl->getScopedName().getStr());
644     }
645     idlc()->incErrorCount();
646 }
647 
648 void ErrorHandler::forwardLookupError(AstDeclaration* pForward,
649                                       const ::rtl::OString& name)
650 {
651     errorHeader(EIDL_FWD_DECL_LOOKUP);
652     fprintf(stderr, "trying to look up '%s' in undefined forward declared interface '%s'\n",
653             pForward->getScopedName().getStr(), name.getStr());
654     idlc()->incErrorCount();
655 }
656 
657 void ErrorHandler::constantExpected(AstDeclaration* pDecl,
658                                     const ::rtl::OString& name)
659 {
660     errorHeader(EIDL_CONSTANT_EXPECTED);
661     fprintf(stderr, "'%s' is bound to '%s'\n", name.getStr(), pDecl->getScopedName().getStr());
662     idlc()->incErrorCount();
663 }
664 
665 void ErrorHandler::evalError(AstExpression* pExpr)
666 {
667     errorHeader(EIDL_EVAL_ERROR);
668     fprintf(stderr, "'%s'\n", pExpr->toString().getStr());
669     idlc()->incErrorCount();
670 }
671 
672 void ErrorHandler::enumValExpected(AstUnion* pUnion)
673 {
674     errorHeader(EIDL_ENUM_VAL_EXPECTED);
675     fprintf(stderr, " union %s\n", pUnion->getLocalName().getStr());
676     idlc()->incErrorCount();
677 }
678 
679 void ErrorHandler::enumValLookupFailure(AstUnion* pUnion, AstEnum* pEnum, const ::rtl::OString& name)
680 {
681     errorHeader(EIDL_ENUM_VAL_NOT_FOUND);
682     fprintf(stderr, " union %s, enum %s, enumerator %s\n",
683             pUnion->getLocalName().getStr(),
684             pEnum->getLocalName().getStr(), name.getStr());
685     idlc()->incErrorCount();
686 }
687 
688 bool ErrorHandler::checkPublished(AstDeclaration const * decl, bool bOptional) {
689     if (idlc()->isPublished() && !decl->isPublished() && !bOptional) {
690         error1(EIDL_PUBLISHED_USES_UNPUBLISHED, decl);
691         return false;
692     } else {
693         return true;
694     }
695 }
696