1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 static const sal_Char
* errorCodeToMessage(ErrorCode eCode
)
28 return "all is fine ";
29 case EIDL_SYNTAX_ERROR
:
32 return "illegal redefinition ";
33 case EIDL_REDEF_SCOPE
:
34 return "illegal redefinition in scope ";
36 return "redefinition after use, ";
37 case EIDL_COERCION_FAILURE
:
38 return "coercion failure ";
39 case EIDL_SCOPE_CONFLICT
:
40 return "definition scope is different than fwd declare scope, ";
41 case EIDL_ILLEGAL_ADD
:
42 return "illegal add operation, ";
43 case EIDL_ILLEGAL_USE
:
44 return "illegal type used in expression, ";
45 case EIDL_ILLEGAL_RAISES
:
46 return "non-exception type in raises(..) clause, ";
47 case EIDL_CANT_INHERIT
:
48 return "cannot inherit ";
49 case EIDL_LOOKUP_ERROR
:
50 return "error in lookup of symbol: ";
51 case EIDL_INHERIT_FWD_ERROR
:
53 case EIDL_CONSTANT_EXPECTED
:
54 return "constant expected: ";
55 case EIDL_NAME_CASE_ERROR
:
56 return "identifier used with two differing spellings: ";
58 return "expression evaluation error: ";
60 return "ambiguous definition: ";
61 case EIDL_DECL_NOT_DEFINED
:
62 return "forward declared but never defined: ";
63 case EIDL_FWD_DECL_LOOKUP
:
65 case EIDL_RECURSIVE_TYPE
:
66 return "illegal recursive use of type: ";
68 return "specified symbol is not a type: ";
69 case EIDL_TYPE_NOT_VALID
:
70 return "specified type is not valid in this context: ";
71 case EIDL_INTERFACEMEMBER_LOOKUP
:
72 return "error in lookup of symbol, expected interface is not defined and no forward exists: ";
73 case EIDL_SERVICEMEMBER_LOOKUP
:
74 return "error in lookup of symbol, expected service is not defined: ";
75 case EIDL_TYPE_IDENT_CONFLICT
:
76 return "type and parameter/member name are equal: ";
77 case EIDL_WRONGATTRIBUTEFLAG
:
78 return "the used flag is not valid in this context: ";
79 case EIDL_DEFINED_ATTRIBUTEFLAG
:
80 return "flag is already set: ";
81 case EIDL_WRONGATTRIBUTEKEYWORD
:
82 return "keyword not allowed: ";
83 case EIDL_MISSINGATTRIBUTEKEYWORD
:
84 return "missing keyword: ";
85 case EIDL_BAD_ATTRIBUTE_FLAGS
:
87 "the 'attribute' flag is mandatory, and only the 'bound' and"
88 " 'readonly' optional flags are accepted: ";
89 case EIDL_OPTIONALEXPECTED
:
90 return "only the 'optional' flag is accepted: ";
91 case EIDL_MIXED_INHERITANCE
:
92 return "interface inheritance declarations cannot appear in both an"
93 " interface's header and its body";
94 case EIDL_DOUBLE_INHERITANCE
:
96 "interface is (directly or indirectly) inherited more than once: ";
97 case EIDL_DOUBLE_MEMBER
:
99 "member is (directly or indirectly) declared more than once: ";
100 case EIDL_CONSTRUCTOR_PARAMETER_NOT_IN
:
102 "a service constructor parameter may not be an out or inout"
104 case EIDL_CONSTRUCTOR_REST_PARAMETER_NOT_FIRST
:
106 "no parameters may precede a rest parameter in a service"
108 case EIDL_REST_PARAMETER_NOT_LAST
:
109 return "no parameters may follow a rest parameter";
110 case EIDL_REST_PARAMETER_NOT_ANY
:
111 return "a rest parameter must be of type any";
112 case EIDL_METHOD_HAS_REST_PARAMETER
:
113 return "a rest parameter may not be used on an interface method";
114 case EIDL_READONLY_ATTRIBUTE_SET_EXCEPTIONS
:
115 return "a readonly attribute may not have a setter raises clause";
116 case EIDL_UNSIGNED_TYPE_ARGUMENT
:
117 return "an unsigned type cannot be used as a type argument";
118 case EIDL_WRONG_NUMBER_OF_TYPE_ARGUMENTS
:
120 "the number of given type arguments does not match the expected"
121 " number of type parameters";
122 case EIDL_INSTANTIATED_STRUCT_TYPE_TYPEDEF
:
124 "an instantiated polymorphic struct type cannot be used in a"
126 case EIDL_IDENTICAL_TYPE_PARAMETERS
:
127 return "two type parameters have the same name";
128 case EIDL_STRUCT_TYPE_TEMPLATE_WITH_BASE
:
129 return "a polymorphic struct type template may not have a base type";
130 case EIDL_PUBLISHED_FORWARD
:
132 "a published forward declaration of an interface type cannot be"
133 " followed by an unpublished declaration of that type";
134 case EIDL_PUBLISHED_USES_UNPUBLISHED
:
136 "an unpublished entity cannot be used in the declaration of a"
137 " published entity: ";
138 case EIDL_SIMILAR_CONSTRUCTORS
:
139 return "two constructors have identical lists of parameter types";
141 return "unknown error";
144 static const sal_Char
* warningCodeToMessage(WarningCode wCode
)
148 case WIDL_EXPID_CONFLICT
:
149 return "exception id conflict: ";
150 case WIDL_REQID_CONFLICT
:
151 return "request id conflict: ";
152 case WIDL_INHERIT_IDCONFLICT
:
153 return "request id conflict in inheritance tree: ";
154 case WIDL_TYPE_IDENT_CONFLICT
:
155 return "type and parameter|member name are equal: ";
156 case WIDL_WRONG_NAMING_CONV
:
157 return "type or identifier doesn't fulfill the UNO naming convention: ";
159 return "unknown warning";
162 static const sal_Char
* parseStateToMessage(ParseState state
)
167 return "Statement can not be parsed";
168 case PS_TypeDeclSeen
:
169 return "Malformed type declaration";
170 case PS_ConstantDeclSeen
:
171 return "Malformed const declaration";
172 case PS_ExceptionDeclSeen
:
173 return "Malformed exception declaration";
174 case PS_InterfaceDeclSeen
:
175 return "Malformed interface declaration";
176 case PS_ServiceDeclSeen
:
177 return "Malformed service declaration";
178 case PS_ModuleDeclSeen
:
179 return "Malformed module declaration";
180 case PS_AttributeDeclSeen
:
181 return "Malformed attribute declaration";
182 case PS_PropertyDeclSeen
:
183 return "Malformed property declaration";
184 case PS_OperationDeclSeen
:
185 return "Malformed operation declaration";
186 case PS_InterfaceInheritanceDeclSeen
:
187 return "Malformed interface inheritance declaration";
188 case PS_ConstantsDeclSeen
:
189 return "Malformed constants declaration";
191 return "Missing service identifier following SERVICE keyword";
192 case PS_ServiceIDSeen
:
193 return "Missing '{' or illegal syntax following service identifier";
194 case PS_ServiceSqSeen
:
195 return "Illegal syntax following service '{' opener";
196 case PS_ServiceBodySeen
:
197 return "Illegal syntax following service '}' closer";
198 case PS_ServiceMemberSeen
:
199 return "Illegal syntax following service member declaration";
200 case PS_ServiceIFHeadSeen
:
201 return "Illegal syntax following header of an interface member";
202 case PS_ServiceSHeadSeen
:
203 return "Illegal syntax following header of an service member";
205 return "Missing module identifier following MODULE keyword";
206 case PS_ModuleIDSeen
:
207 return "Missing '{' or illegal syntax following module identifier";
208 case PS_ModuleSqSeen
:
209 return "Illegal syntax following module '{' opener";
210 case PS_ModuleQsSeen
:
211 return "Illegal syntax following module '}' closer";
212 case PS_ModuleBodySeen
:
213 return "Illegal syntax following module export(s)";
214 case PS_ConstantsSeen
:
215 return "Missing constants identifier following CONSTANTS keyword";
216 case PS_ConstantsIDSeen
:
217 return "Missing '{' or illegal syntax following constants identifier";
218 case PS_ConstantsSqSeen
:
219 return "Illegal syntax following module '{' opener";
220 case PS_ConstantsQsSeen
:
221 return "Illegal syntax following module '}' closer";
222 case PS_ConstantsBodySeen
:
223 return "Illegal syntax following constants export(s)";
224 case PS_InterfaceSeen
:
225 return "Missing interface identifier following INTERFACE keyword";
226 case PS_InterfaceIDSeen
:
227 return "Illegal syntax following interface identifier";
228 case PS_InterfaceHeadSeen
:
229 return "Illegal syntax following interface head";
230 case PS_InheritSpecSeen
:
231 return "Missing '{' or illegal syntax following inheritance spec";
232 case PS_ForwardDeclSeen
:
233 return "Missing ';' following forward interface declaration";
234 case PS_InterfaceSqSeen
:
235 return "Illegal syntax following interface '{' opener";
236 case PS_InterfaceQsSeen
:
237 return "Illegal syntax following interface '}' closer";
238 case PS_InterfaceBodySeen
:
239 return "Illegal syntax following interface export(s)";
240 case PS_InheritColonSeen
:
241 return "Illegal syntax following ':' starting inheritance list";
242 case PS_SNListCommaSeen
:
243 return "Found illegal scoped name in scoped name list";
244 case PS_ScopedNameSeen
:
245 return "Missing ',' following scoped name in scoped name list";
247 return "Illegal component in scoped name";
248 case PS_ScopeDelimSeen
:
249 return "Illegal component in scoped name following '::'";
251 return "Missing type or illegal syntax following CONST keyword";
252 case PS_ConstTypeSeen
:
253 return "Missing identifier or illegal syntax following const type";
255 return "Missing '=' or illegal syntax after const identifier";
256 case PS_ConstAssignSeen
:
257 return "Missing value expr or illegal syntax following '='";
258 case PS_ConstExprSeen
:
259 return "Missing ';' or illegal syntax following value expr in const";
261 return "Missing type or illegal syntax following TYPEDEF keyword";
262 case PS_TypeSpecSeen
:
263 return "Missing declarators or illegal syntax following type spec";
264 case PS_DeclaratorsSeen
:
265 return "Illegal syntax following declarators in TYPEDEF declaration";
267 return "Missing struct identifier following STRUCT keyword";
268 case PS_StructHeaderSeen
:
269 return "Missing '{' or illegal syntax following struct inheritance spec";
270 case PS_StructIDSeen
:
271 return "Missing '{' or illegal syntax following struct identifier";
272 case PS_StructSqSeen
:
273 return "Illegal syntax following struct '{' opener";
274 case PS_StructQsSeen
:
275 return "Illegal syntax following struct '}' closer";
276 case PS_StructBodySeen
:
277 return "Illegal syntax following struct member(s)";
278 case PS_MemberTypeSeen
:
279 return "Illegal syntax or missing identifier following member type";
280 case PS_MemberDeclsSeen
:
281 return "Illegal syntax following member declarator(s)";
282 case PS_MemberDeclsCompleted
:
283 return "Missing ',' between member decls of same type(?)";
285 return "Illegal syntax or missing identifier following ENUM keyword";
287 return "Illegal syntax or missing '{' following enum identifier";
289 return "Illegal syntax following enum '{' opener";
291 return "Illegal syntax following enum '}' closer";
292 case PS_EnumBodySeen
:
293 return "Illegal syntax following enum enumerator(s)";
294 case PS_EnumCommaSeen
:
295 return "Illegal syntax or missing identifier following ',' in enum";
296 case PS_SequenceSeen
:
297 return "Illegal syntax or missing '<' following SEQUENCE keyword";
298 case PS_SequenceSqSeen
:
299 return "Illegal syntax or missing type following '<' in sequence";
300 case PS_SequenceQsSeen
:
301 return "Illegal syntax following '>' in sequence";
302 case PS_SequenceTypeSeen
:
303 return "Illegal syntax following sequence type declaration";
304 case PS_FlagHeaderSeen
:
305 return "Illegal syntax after flags";
307 return "Illegal syntax after ATTRIBUTE keyword";
308 case PS_AttrTypeSeen
:
309 return "Illegal syntax after type in attribute declaration";
310 case PS_AttrCompleted
:
311 return "Illegal syntax after attribute declaration";
312 case PS_ReadOnlySeen
:
313 return "Illegal syntax after READONLY keyword";
314 case PS_OptionalSeen
:
315 return "Illegal syntax after OPTIONAL keyword";
316 case PS_MayBeVoidSeen
:
317 return "Illegal syntax after MAYBEVOID keyword";
319 return "Illegal syntax after BOUND keyword";
320 case PS_ConstrainedSeen
:
321 return "Illegal syntax after CONSTRAINED keyword";
322 case PS_TransientSeen
:
323 return "Illegal syntax after TRANSIENT keyword";
324 case PS_MayBeAmbigiousSeen
:
325 return "Illegal syntax after MAYBEAMBIGIOUS keyword";
326 case PS_MayBeDefaultSeen
:
327 return "Illegal syntax after MAYBEDEFAULT keyword";
328 case PS_RemoveableSeen
:
329 return "Illegal syntax after REMOVABLE keyword";
330 case PS_PropertySeen
:
331 return "Illegal syntax after PROPERTY keyword";
332 case PS_PropertyTypeSeen
:
333 return "Illegal syntax after type in property declaration";
334 case PS_PropertyCompleted
:
335 return "Illegal syntax after property declaration";
337 return "Illegal syntax or missing identifier after EXCEPTION keyword";
338 case PS_ExceptHeaderSeen
:
339 return "Missing '{' or illegal syntax following exception inheritance spec";
340 case PS_ExceptIDSeen
:
341 return "Illegal syntax or missing '{' after exception identifier";
342 case PS_ExceptSqSeen
:
343 return "Illegal syntax after exception '{' opener";
344 case PS_ExceptQsSeen
:
345 return "Illegal syntax after exception '}' closer";
346 case PS_ExceptBodySeen
:
347 return "Illegal syntax after exception member(s)";
349 return "Illegal syntax or missing identifier after operation type";
351 return "Illegal syntax or missing '(' after operation identifier";
352 case PS_OpParsCompleted
:
353 return "Illegal syntax after operation parameter list";
355 return "Illegal syntax after operation declaration";
357 return "Illegal syntax after operation parameter list '(' opener";
359 return "Illegal syntax after operation parameter list ')' closer";
360 case PS_OpParCommaSeen
:
361 return "Illegal syntax or missing direction in parameter declaration";
362 case PS_OpParDirSeen
:
363 return "Illegal syntax or missing type in parameter declaration";
364 case PS_OpParTypeSeen
:
365 return "Illegal syntax or missing declarator in parameter declaration";
366 case PS_OpParDeclSeen
:
367 return "Illegal syntax following parameter declarator";
369 return "Illegal syntax or missing '(' after RAISES keyword";
371 return "Illegal syntax after RAISES '(' opener";
373 return "Illegal syntax after RAISES ')' closer";
374 case PS_DeclsCommaSeen
:
375 return "Illegal syntax after ',' in declarators list";
376 case PS_DeclsDeclSeen
:
377 return "Illegal syntax after declarator in declarators list";
379 return "no wider described syntax error";
383 static OString
flagToString(sal_uInt32 flag
)
386 if ( (flag
& AF_READONLY
) == AF_READONLY
)
387 flagStr
+= "'readonly'";
388 if ( (flag
& AF_OPTIONAL
) == AF_OPTIONAL
)
389 flagStr
+= "'optional'";
390 if ( (flag
& AF_MAYBEVOID
) == AF_MAYBEVOID
)
391 flagStr
+= "'maybevoid'";
392 if ( (flag
& AF_BOUND
) == AF_BOUND
)
393 flagStr
+= "'bound'";
394 if ( (flag
& AF_CONSTRAINED
) == AF_CONSTRAINED
)
395 flagStr
+= "'constrained'";
396 if ( (flag
& AF_TRANSIENT
) == AF_TRANSIENT
)
397 flagStr
+= "'transient'";
398 if ( (flag
& AF_MAYBEAMBIGUOUS
) == AF_MAYBEAMBIGUOUS
)
399 flagStr
+= "'maybeambiguous'";
400 if ( (flag
& AF_MAYBEDEFAULT
) == AF_MAYBEDEFAULT
)
401 flagStr
+= "'maybedefault'";
402 if ( (flag
& AF_REMOVABLE
) == AF_REMOVABLE
)
403 flagStr
+= "'removable'";
404 if ( (flag
& AF_ATTRIBUTE
) == AF_ATTRIBUTE
)
405 flagStr
+= "'attribute'";
406 if ( (flag
& AF_PROPERTY
) == AF_PROPERTY
)
407 flagStr
+= "'property'";
408 if ( flagStr
.isEmpty() )
409 flagStr
+= "'unknown'";
414 static void errorHeader(ErrorCode eCode
, sal_Int32 lineNumber
, sal_uInt32 start
, sal_uInt32 end
)
417 if ( idlc()->getFileName() == idlc()->getRealFileName() )
418 file
= idlc()->getMainFileName();
420 file
= idlc()->getFileName();
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 errorCodeToMessage(eCode
));
429 static void errorHeader(ErrorCode eCode
, sal_uInt32 lineNumber
)
431 errorHeader(eCode
, lineNumber
,
432 idlc()->getOffsetStart(), idlc()->getOffsetEnd());
435 static void errorHeader(ErrorCode eCode
)
437 errorHeader(eCode
, idlc()->getLineNumber(),
438 idlc()->getOffsetStart(), idlc()->getOffsetEnd());
441 static void warningHeader(WarningCode wCode
)
444 if ( idlc()->getFileName() == idlc()->getRealFileName() )
445 file
= idlc()->getMainFileName();
447 file
= idlc()->getFileName();
449 fprintf(stderr
, "%s(%lu) : WARNING, %s", file
.getStr(),
450 sal::static_int_cast
< unsigned long >(idlc()->getLineNumber()),
451 warningCodeToMessage(wCode
));
454 void ErrorHandler::error0(ErrorCode e
)
457 fprintf(stderr
, "\n");
458 idlc()->incErrorCount();
461 void ErrorHandler::error1(ErrorCode e
, AstDeclaration
const * d
)
464 fprintf(stderr
, "'%s'\n", d
->getScopedName().getStr());
465 idlc()->incErrorCount();
468 void ErrorHandler::error2(
469 ErrorCode e
, AstDeclaration
const * d1
, AstDeclaration
const * d2
)
472 fprintf(stderr
, "'%s', '%s'\n", d1
->getScopedName().getStr(),
473 d2
->getScopedName().getStr());
474 idlc()->incErrorCount();
477 void ErrorHandler::error3(ErrorCode e
, AstDeclaration
* d1
, AstDeclaration
* d2
, AstDeclaration
* d3
)
480 fprintf(stderr
, "'%s', '%s', '%s'\n", d1
->getScopedName().getStr(),
481 d2
->getScopedName().getStr(), d3
->getScopedName().getStr());
482 idlc()->incErrorCount();
485 void ErrorHandler::warning0(WarningCode w
, const sal_Char
* warningmsg
)
487 if ( idlc()->getOptions()->isValid("-w") || idlc()->getOptions()->isValid("-we") ) {
489 fprintf(stderr
, "%s\n", warningmsg
);
492 if ( idlc()->getOptions()->isValid("-we") )
493 idlc()->incErrorCount();
495 idlc()->incWarningCount();
498 void ErrorHandler::syntaxError(ParseState ps
, sal_Int32 lineNumber
, const sal_Char
* errmsg
)
500 errorHeader(EIDL_SYNTAX_ERROR
, lineNumber
);
501 fprintf(stderr
, "%s: %s\n", parseStateToMessage(ps
), errmsg
);
502 idlc()->incErrorCount();
505 void ErrorHandler::coercionError(AstExpression
*pExpr
, ExprType et
)
507 errorHeader(EIDL_COERCION_FAILURE
);
508 fprintf(stderr
, "'%s' to '%s'\n", pExpr
->toString().getStr(),
509 exprTypeToString(et
));
510 idlc()->incErrorCount();
513 void ErrorHandler::lookupError(const OString
& n
)
515 errorHeader(EIDL_LOOKUP_ERROR
);
516 fprintf(stderr
, "'%s'\n", n
.getStr());
517 idlc()->incErrorCount();
520 void ErrorHandler::lookupError(ErrorCode e
, const OString
& n
, AstDeclaration
* pScope
)
523 fprintf(stderr
, "'%s' in '%s'\n", n
.getStr(), pScope
->getFullName().getStr());
524 idlc()->incErrorCount();
527 void ErrorHandler::flagError(ErrorCode e
, sal_uInt32 flag
)
530 fprintf(stderr
, "'%s'\n", flagToString(flag
).getStr());
531 idlc()->incErrorCount();
534 void ErrorHandler::noTypeError(AstDeclaration
const * pDecl
)
536 errorHeader(EIDL_NOT_A_TYPE
);
537 fprintf(stderr
, "'%s'\n", pDecl
->getScopedName().getStr());
538 idlc()->incErrorCount();
543 char const * nodeTypeName(NodeType nodeType
) {
561 void ErrorHandler::inheritanceError(NodeType nodeType
, const OString
* name
, AstDeclaration
* pDecl
)
563 if ( nodeType
== NT_interface
&&
564 (pDecl
->getNodeType() == NT_interface
) &&
565 !(static_cast<AstInterface
*>(pDecl
)->isDefined()) )
567 errorHeader(EIDL_INHERIT_FWD_ERROR
);
568 fprintf(stderr
, "interface '%s' cannot inherit from forward declared interface '%s'\n",
569 name
->getStr(), pDecl
->getScopedName().getStr());
572 errorHeader(EIDL_CANT_INHERIT
);
573 fprintf(stderr
, "%s '%s' from '%s'\n",
574 nodeTypeName(nodeType
), name
->getStr(),
575 pDecl
->getScopedName().getStr());
577 idlc()->incErrorCount();
580 void ErrorHandler::forwardLookupError(const AstDeclaration
* pForward
,
583 errorHeader(EIDL_FWD_DECL_LOOKUP
);
584 fprintf(stderr
, "trying to look up '%s' in undefined forward declared interface '%s'\n",
585 pForward
->getScopedName().getStr(), name
.getStr());
586 idlc()->incErrorCount();
589 void ErrorHandler::constantExpected(AstDeclaration
* pDecl
,
592 errorHeader(EIDL_CONSTANT_EXPECTED
);
593 fprintf(stderr
, "'%s' is bound to '%s'\n", name
.getStr(), pDecl
->getScopedName().getStr());
594 idlc()->incErrorCount();
597 void ErrorHandler::evalError(AstExpression
* pExpr
)
599 errorHeader(EIDL_EVAL_ERROR
);
600 fprintf(stderr
, "'%s'\n", pExpr
->toString().getStr());
601 idlc()->incErrorCount();
604 bool ErrorHandler::checkPublished(AstDeclaration
const * decl
, bool bOptional
) {
605 if (idlc()->isPublished() && !decl
->isPublished() && !bOptional
) {
606 error1(EIDL_PUBLISHED_USES_UNPUBLISHED
, decl
);
613 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */