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