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