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