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