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