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/.
10 #include "sal/config.h"
22 #include "osl/file.hxx"
23 #include "osl/process.h"
24 #include "rtl/process.h"
25 #include "rtl/ref.hxx"
26 #include "rtl/ustring.hxx"
28 #include "sal/types.h"
29 #include "unoidl/unoidl.hxx"
35 << "Usage:" << std::endl
<< std::endl
36 << " unoidl-read [--published] [<extra registries>] <registry>"
37 << std::endl
<< std::endl
38 << ("where each <registry> is either a new- or legacy-format .rdb file,"
41 << ("file, or a root directory of an .idl file tree. The complete"
44 << ("last <registry> is written to stdout; if --published is specified,"
47 << ("published entities (plus any non-published entities referenced"
50 << "via any unpublished optional bases) are written out." << std::endl
;
51 std::exit(EXIT_FAILURE
);
54 OUString
getArgumentUri(sal_uInt32 argument
) {
56 rtl_getAppCommandArg(argument
, &arg
.pData
);
58 osl::FileBase::RC e1
= osl::FileBase::getFileURLFromSystemPath(arg
, url
);
59 if (e1
!= osl::FileBase::E_None
) {
61 << "Cannot convert \"" << arg
<< "\" to file URL, error code "
63 std::exit(EXIT_FAILURE
);
66 oslProcessError e2
= osl_getProcessWorkingDir(&cwd
.pData
);
67 if (e2
!= osl_Process_E_None
) {
69 << "Cannot obtain working directory, error code " << +e2
71 std::exit(EXIT_FAILURE
);
74 e1
= osl::FileBase::getAbsoluteFileURL(cwd
, url
, abs
);
75 if (e1
!= osl::FileBase::E_None
) {
77 << "Cannot make \"" << url
78 << "\" into an absolute file URL, error code " << +e1
<< std::endl
;
79 std::exit(EXIT_FAILURE
);
84 OUString
decomposeType(
85 OUString
const & type
, std::size_t * rank
,
86 std::vector
<OUString
> * typeArguments
, bool * entity
)
89 assert(typeArguments
!= 0);
93 typeArguments
->clear();
94 while (nucl
.startsWith("[]", &nucl
)) {
97 sal_Int32 i
= nucl
.indexOf('<');
99 OUString
tmpl(nucl
.copy(0, i
));
101 ++i
; // skip '<' or ','
103 for (sal_Int32 level
= 0; j
!= nucl
.getLength(); ++j
) {
104 sal_Unicode c
= nucl
[j
];
109 } else if (c
== '<') {
111 } else if (c
== '>') {
118 if (j
!= nucl
.getLength()) {
119 typeArguments
->push_back(nucl
.copy(i
, j
- i
));
122 } while (i
!= nucl
.getLength() && nucl
[i
] != '>');
123 assert(i
== nucl
.getLength() - 1 && nucl
[i
] == '>');
124 assert(!typeArguments
->empty());
127 assert(!nucl
.isEmpty());
128 *entity
= nucl
!= "void" && nucl
!= "boolean" && nucl
!= "byte"
129 && nucl
!= "short" && nucl
!= "unsigned short" && nucl
!= "long"
130 && nucl
!= "unsigned long" && nucl
!= "hyper"
131 && nucl
!= "unsigned hyper" && nucl
!= "float" && nucl
!= "double"
132 && nucl
!= "char" && nucl
!= "string" && nucl
!= "type"
134 assert(*entity
|| typeArguments
->empty());
139 enum class Sorted
{ NO
, ACTIVE
, YES
};
142 rtl::Reference
<unoidl::Entity
> const & theEntity
, bool theRelevant
):
143 entity(theEntity
), relevant(theRelevant
), sorted(Sorted::NO
),
147 rtl::Reference
<unoidl::Entity
> const entity
;
148 std::set
<OUString
> dependencies
;
149 std::set
<OUString
> interfaceDependencies
;
155 void insertEntityDependency(
156 rtl::Reference
<unoidl::Manager
> const & manager
,
157 std::map
<OUString
, Entity
>::iterator
const & iterator
,
158 OUString
const & name
, bool weakInterfaceDependency
= false)
160 assert(manager
.is());
161 if (name
!= iterator
->first
) {
163 if (weakInterfaceDependency
) {
164 rtl::Reference
<unoidl::Entity
> ent(manager
->findEntity(name
));
166 std::cerr
<< "Unknown entity " << name
<< std::endl
;
167 std::exit(EXIT_FAILURE
);
169 ifc
= ent
->getSort() == unoidl::Entity::SORT_INTERFACE_TYPE
;
172 ? iterator
->second
.interfaceDependencies
173 : iterator
->second
.dependencies
)
178 void insertEntityDependencies(
179 rtl::Reference
<unoidl::Manager
> const & manager
,
180 std::map
<OUString
, Entity
>::iterator
const & iterator
,
181 std::vector
<OUString
> const & names
)
183 for (std::vector
<OUString
>::const_iterator
i(names
.begin());
184 i
!= names
.end(); ++i
)
186 insertEntityDependency(manager
, iterator
, *i
);
190 void insertEntityDependencies(
191 rtl::Reference
<unoidl::Manager
> const & manager
,
192 std::map
<OUString
, Entity
>::iterator
const & iterator
,
193 std::vector
<unoidl::AnnotatedReference
> const & references
)
195 for (std::vector
<unoidl::AnnotatedReference
>::const_iterator
i(
197 i
!= references
.end(); ++i
)
199 insertEntityDependency(manager
, iterator
, i
->name
);
203 void insertTypeDependency(
204 rtl::Reference
<unoidl::Manager
> const & manager
,
205 std::map
<OUString
, Entity
>::iterator
const & iterator
,
206 OUString
const & type
)
209 std::vector
<OUString
> args
;
211 OUString
nucl(decomposeType(type
, &rank
, &args
, &entity
));
213 insertEntityDependency(manager
, iterator
, nucl
, true);
214 for (std::vector
<OUString
>::iterator
i(args
.begin()); i
!= args
.end();
217 insertTypeDependency(manager
, iterator
, *i
);
223 rtl::Reference
<unoidl::Manager
> const & manager
,
224 rtl::Reference
<unoidl::MapCursor
> const & cursor
, bool published
,
225 OUString
const & prefix
, std::map
<OUString
, Entity
> & entities
)
230 rtl::Reference
<unoidl::Entity
> ent(cursor
->getNext(&id
));
234 OUString
name(prefix
+ id
);
235 if (ent
->getSort() == unoidl::Entity::SORT_MODULE
) {
238 static_cast<unoidl::ModuleEntity
*>(ent
.get())->createCursor(),
239 published
, name
+ ".", entities
);
241 std::map
<OUString
, Entity
>::iterator
i(
248 || (static_cast<unoidl::PublishableEntity
*>(
252 switch (ent
->getSort()) {
253 case unoidl::Entity::SORT_MODULE
:
254 assert(false && "this cannot happen");
255 case unoidl::Entity::SORT_ENUM_TYPE
:
256 case unoidl::Entity::SORT_CONSTANT_GROUP
:
258 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE
:
260 rtl::Reference
<unoidl::PlainStructTypeEntity
> ent2(
261 static_cast<unoidl::PlainStructTypeEntity
*>(
263 if (!ent2
->getDirectBase().isEmpty()) {
264 insertEntityDependency(
265 manager
, i
, ent2
->getDirectBase());
267 for (std::vector
<unoidl::PlainStructTypeEntity::Member
>::const_iterator
268 j(ent2
->getDirectMembers().begin());
269 j
!= ent2
->getDirectMembers().end(); ++j
)
271 insertTypeDependency(manager
, i
, j
->type
);
275 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
277 rtl::Reference
<unoidl::PolymorphicStructTypeTemplateEntity
>
279 static_cast<unoidl::PolymorphicStructTypeTemplateEntity
*>(
281 for (std::vector
<unoidl::PolymorphicStructTypeTemplateEntity::Member
>::const_iterator
282 j(ent2
->getMembers().begin());
283 j
!= ent2
->getMembers().end(); ++j
)
285 if (!j
->parameterized
) {
286 insertTypeDependency(manager
, i
, j
->type
);
291 case unoidl::Entity::SORT_EXCEPTION_TYPE
:
293 rtl::Reference
<unoidl::ExceptionTypeEntity
> ent2(
294 static_cast<unoidl::ExceptionTypeEntity
*>(ent
.get()));
295 if (!ent2
->getDirectBase().isEmpty()) {
296 insertEntityDependency(
297 manager
, i
, ent2
->getDirectBase());
299 for (std::vector
<unoidl::ExceptionTypeEntity::Member
>::const_iterator
300 j(ent2
->getDirectMembers().begin());
301 j
!= ent2
->getDirectMembers().end(); ++j
)
303 insertTypeDependency(manager
, i
, j
->type
);
307 case unoidl::Entity::SORT_INTERFACE_TYPE
:
309 rtl::Reference
<unoidl::InterfaceTypeEntity
> ent2(
310 static_cast<unoidl::InterfaceTypeEntity
*>(
312 insertEntityDependencies(
313 manager
, i
, ent2
->getDirectMandatoryBases());
314 insertEntityDependencies(
315 manager
, i
, ent2
->getDirectOptionalBases());
316 for (std::vector
<unoidl::InterfaceTypeEntity::Attribute
>::const_iterator
317 j(ent2
->getDirectAttributes().begin());
318 j
!= ent2
->getDirectAttributes().end(); ++j
)
320 insertTypeDependency(manager
, i
, j
->type
);
322 for (std::vector
<unoidl::InterfaceTypeEntity::Method
>::const_iterator
323 j(ent2
->getDirectMethods().begin());
324 j
!= ent2
->getDirectMethods().end(); ++j
)
326 insertTypeDependency(manager
, i
, j
->returnType
);
327 for (std::vector
<unoidl::InterfaceTypeEntity::Method::Parameter
>::const_iterator
328 k(j
->parameters
.begin());
329 k
!= j
->parameters
.end(); ++k
)
331 insertTypeDependency(manager
, i
, k
->type
);
333 insertEntityDependencies(manager
, i
, j
->exceptions
);
337 case unoidl::Entity::SORT_TYPEDEF
:
339 rtl::Reference
<unoidl::TypedefEntity
> ent2(
340 static_cast<unoidl::TypedefEntity
*>(ent
.get()));
341 insertTypeDependency(manager
, i
, ent2
->getType());
344 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE
:
346 rtl::Reference
<unoidl::SingleInterfaceBasedServiceEntity
>
348 static_cast<unoidl::SingleInterfaceBasedServiceEntity
*>(
350 insertEntityDependency(manager
, i
, ent2
->getBase());
351 for (std::vector
<unoidl::SingleInterfaceBasedServiceEntity::Constructor
>::const_iterator
352 j(ent2
->getConstructors().begin());
353 j
!= ent2
->getConstructors().end(); ++j
)
355 for (std::vector
<unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
>::const_iterator
356 k(j
->parameters
.begin());
357 k
!= j
->parameters
.end(); ++k
)
359 insertTypeDependency(manager
, i
, k
->type
);
361 insertEntityDependencies(manager
, i
, j
->exceptions
);
365 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE
:
367 rtl::Reference
<unoidl::AccumulationBasedServiceEntity
> ent2(
368 static_cast<unoidl::AccumulationBasedServiceEntity
*>(
370 insertEntityDependencies(
371 manager
, i
, ent2
->getDirectMandatoryBaseServices());
372 insertEntityDependencies(
373 manager
, i
, ent2
->getDirectOptionalBaseServices());
374 insertEntityDependencies(
375 manager
, i
, ent2
->getDirectMandatoryBaseInterfaces());
376 insertEntityDependencies(
377 manager
, i
, ent2
->getDirectOptionalBaseInterfaces());
378 for (std::vector
<unoidl::AccumulationBasedServiceEntity::Property
>::const_iterator
379 j(ent2
->getDirectProperties().begin());
380 j
!= ent2
->getDirectProperties().end(); ++j
)
382 insertTypeDependency(manager
, i
, j
->type
);
386 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON
:
388 rtl::Reference
<unoidl::InterfaceBasedSingletonEntity
> ent2(
389 static_cast<unoidl::InterfaceBasedSingletonEntity
*>(
391 insertEntityDependency(manager
, i
, ent2
->getBase());
394 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON
:
396 rtl::Reference
<unoidl::ServiceBasedSingletonEntity
> ent2(
397 static_cast<unoidl::ServiceBasedSingletonEntity
*>(
399 insertEntityDependency(manager
, i
, ent2
->getBase());
407 void propagateRelevant(std::map
<OUString
, Entity
> & entities
, Entity
& entity
) {
408 if (!entity
.relevant
) {
409 entity
.relevant
= true;
410 if (entity
.sorted
!= Entity::Sorted::YES
) {
411 for (std::set
<OUString
>::iterator
i(entity
.dependencies
.begin());
412 i
!= entity
.dependencies
.end(); ++i
)
414 std::map
<OUString
, Entity
>::iterator
j(entities
.find(*i
));
415 if (j
!= entities
.end()) {
416 propagateRelevant(entities
, j
->second
);
424 std::map
<OUString
, Entity
> & entities
,
425 std::map
<OUString
, Entity
>::iterator
const & iterator
,
426 std::vector
<OUString
> & result
)
428 switch (iterator
->second
.sorted
) {
429 case Entity::Sorted::NO
:
430 iterator
->second
.sorted
= Entity::Sorted::ACTIVE
;
431 for (std::set
<OUString
>::iterator
i(
432 iterator
->second
.dependencies
.begin());
433 i
!= iterator
->second
.dependencies
.end(); ++i
)
435 std::map
<OUString
, Entity
>::iterator
j(entities
.find(*i
));
436 if (j
!= entities
.end()) {
437 if (iterator
->second
.relevant
) {
438 propagateRelevant(entities
, j
->second
);
440 visit(entities
, j
, result
);
443 iterator
->second
.sorted
= Entity::Sorted::YES
;
444 result
.push_back(iterator
->first
);
446 case Entity::Sorted::ACTIVE
:
448 << "Entity " << iterator
->first
<< " recursively depends on itself"
450 std::exit(EXIT_FAILURE
);
451 // fall-through avoids warnings
457 std::vector
<OUString
> sort(std::map
<OUString
, Entity
> & entities
) {
458 std::vector
<OUString
> res
;
459 for (std::map
<OUString
, Entity
>::iterator
i(entities
.begin());
460 i
!= entities
.end(); ++i
)
462 visit(entities
, i
, res
);
467 void indent(std::vector
<OUString
> const & modules
, unsigned int extra
= 0) {
468 for (std::vector
<OUString
>::size_type i
= 0; i
!= modules
.size(); ++i
) {
471 for (unsigned int i
= 0; i
!= extra
; ++i
) {
477 std::vector
<OUString
> & modules
, std::vector
<OUString
>::size_type n
) {
478 for (std::vector
<OUString
>::size_type i
= 0; i
!= n
; ++i
) {
479 assert(!modules
.empty());
486 OUString
openModulesFor(std::vector
<OUString
> & modules
, OUString
const & name
)
488 std::vector
<OUString
>::iterator
i(modules
.begin());
489 for (sal_Int32 j
= 0;;) {
490 OUString
id(name
.getToken(0, '.', j
));
494 static_cast< std::vector
<OUString
>::size_type
>(
499 if (i
!= modules
.end()) {
506 static_cast< std::vector
<OUString
>::size_type
>(
511 std::cout
<< "module " << id
<< " {\n";
512 modules
.push_back(id
);
517 void writeName(OUString
const & name
) {
518 std::cout
<< "::" << name
.replaceAll(".", "::");
521 void writeAnnotations(std::vector
<OUString
> const & annotations
) {
522 if (!annotations
.empty()) {
524 for (std::vector
<OUString
>::const_iterator
i(annotations
.begin());
525 i
!= annotations
.end(); ++i
)
527 //TODO: i->indexOf("*/") == -1
528 std::cout
<< " @" << *i
;
534 void writePublished(rtl::Reference
<unoidl::PublishableEntity
> const & entity
) {
536 if (entity
->isPublished()) {
537 std::cout
<< "published ";
541 void writeAnnotationsPublished(
542 rtl::Reference
<unoidl::PublishableEntity
> const & entity
)
545 writeAnnotations(entity
->getAnnotations());
546 writePublished(entity
);
549 void writeType(OUString
const & type
) {
551 std::vector
<OUString
> args
;
553 OUString
nucl(decomposeType(type
, &rank
, &args
, &entity
));
554 for (std::size_t i
= 0; i
!= rank
; ++i
) {
555 std::cout
<< "sequence< ";
564 for (std::vector
<OUString
>::iterator
i(args
.begin()); i
!= args
.end();
567 if (i
!= args
.begin()) {
574 for (std::size_t i
= 0; i
!= rank
; ++i
) {
579 void writeExceptionSpecification(std::vector
<OUString
> const & exceptions
) {
580 if (!exceptions
.empty()) {
581 std::cout
<< " raises (";
582 for (std::vector
<OUString
>::const_iterator
i(exceptions
.begin());
583 i
!= exceptions
.end(); ++i
)
585 if (i
!= exceptions
.begin()) {
595 std::map
<OUString
, Entity
> & entities
, std::vector
<OUString
> & modules
,
596 OUString
const & name
)
598 std::map
<OUString
, Entity
>::iterator
i(entities
.find(name
));
599 if (i
!= entities
.end() && i
->second
.relevant
) {
600 assert(!i
->second
.written
);
601 i
->second
.written
= true;
602 for (std::set
<OUString
>::iterator
j(
603 i
->second
.interfaceDependencies
.begin());
604 j
!= i
->second
.interfaceDependencies
.end(); ++j
)
606 std::map
<OUString
, Entity
>::iterator
k(entities
.find(*j
));
607 if (k
!= entities
.end() && !k
->second
.written
) {
608 OUString
id(openModulesFor(modules
, *j
));
609 if (k
->second
.entity
->getSort()
610 != unoidl::Entity::SORT_INTERFACE_TYPE
)
613 << "Entity " << *j
<< " should be an interface type"
615 std::exit(EXIT_FAILURE
);
618 static_cast<unoidl::PublishableEntity
*>(
619 k
->second
.entity
.get()));
620 std::cout
<< "interface " << id
<< ";\n";
623 OUString
id(openModulesFor(modules
, name
));
624 rtl::Reference
<unoidl::PublishableEntity
> ent(
625 static_cast<unoidl::PublishableEntity
*>(i
->second
.entity
.get()));
626 switch (ent
->getSort()) {
627 case unoidl::Entity::SORT_MODULE
:
628 assert(false && "this cannot happen");
629 //deliberate fall-through anyway
630 case unoidl::Entity::SORT_ENUM_TYPE
:
632 rtl::Reference
<unoidl::EnumTypeEntity
> ent2(
633 static_cast<unoidl::EnumTypeEntity
*>(ent
.get()));
634 writeAnnotationsPublished(ent
);
635 std::cout
<< "enum " << id
<< " {\n";
636 for (std::vector
<unoidl::EnumTypeEntity::Member
>::const_iterator
637 j(ent2
->getMembers().begin());
638 j
!= ent2
->getMembers().end(); ++j
)
641 writeAnnotations(j
->annotations
);
642 std::cout
<< j
->name
<< " = " << j
->value
;
643 if (j
+ 1 != ent2
->getMembers().end()) {
652 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE
:
654 rtl::Reference
<unoidl::PlainStructTypeEntity
> ent2(
655 static_cast<unoidl::PlainStructTypeEntity
*>(ent
.get()));
656 writeAnnotationsPublished(ent
);
657 std::cout
<< "struct " << id
;
658 if (!ent2
->getDirectBase().isEmpty()) {
660 writeName(ent2
->getDirectBase());
663 for (std::vector
<unoidl::PlainStructTypeEntity::Member
>::const_iterator
664 j(ent2
->getDirectMembers().begin());
665 j
!= ent2
->getDirectMembers().end(); ++j
)
668 writeAnnotations(j
->annotations
);
670 std::cout
<< ' ' << j
->name
<< ";\n";
676 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
678 rtl::Reference
<unoidl::PolymorphicStructTypeTemplateEntity
>
680 static_cast<unoidl::PolymorphicStructTypeTemplateEntity
*>(
682 writeAnnotationsPublished(ent
);
683 std::cout
<< "struct " << id
<< '<';
684 for (std::vector
<OUString
>::const_iterator
j(
685 ent2
->getTypeParameters().begin());
686 j
!= ent2
->getTypeParameters().end(); ++j
)
688 if (j
!= ent2
->getTypeParameters().begin()) {
693 std::cout
<< "> {\n";
694 for (std::vector
<unoidl::PolymorphicStructTypeTemplateEntity::Member
>::const_iterator
695 j(ent2
->getMembers().begin());
696 j
!= ent2
->getMembers().end(); ++j
)
699 writeAnnotations(j
->annotations
);
700 if (j
->parameterized
) {
701 std::cout
<< j
->type
;
705 std::cout
<< ' ' << j
->name
<< ";\n";
711 case unoidl::Entity::SORT_EXCEPTION_TYPE
:
713 rtl::Reference
<unoidl::ExceptionTypeEntity
> ent2(
714 static_cast<unoidl::ExceptionTypeEntity
*>(ent
.get()));
715 writeAnnotationsPublished(ent
);
716 std::cout
<< "exception " << id
;
717 if (!ent2
->getDirectBase().isEmpty()) {
719 writeName(ent2
->getDirectBase());
722 for (std::vector
<unoidl::ExceptionTypeEntity::Member
>::const_iterator
723 j(ent2
->getDirectMembers().begin());
724 j
!= ent2
->getDirectMembers().end(); ++j
)
727 writeAnnotations(j
->annotations
);
729 std::cout
<< ' ' << j
->name
<< ";\n";
735 case unoidl::Entity::SORT_INTERFACE_TYPE
:
737 rtl::Reference
<unoidl::InterfaceTypeEntity
> ent2(
738 static_cast<unoidl::InterfaceTypeEntity
*>(
740 writeAnnotationsPublished(ent
);
741 std::cout
<< "interface " << id
<< " {\n";
742 for (std::vector
<unoidl::AnnotatedReference
>::const_iterator
j(
743 ent2
->getDirectMandatoryBases().begin());
744 j
!= ent2
->getDirectMandatoryBases().end(); ++j
)
747 writeAnnotations(j
->annotations
);
748 std::cout
<< "interface ";
752 for (std::vector
<unoidl::AnnotatedReference
>::const_iterator
j(
753 ent2
->getDirectOptionalBases().begin());
754 j
!= ent2
->getDirectOptionalBases().end(); ++j
)
757 writeAnnotations(j
->annotations
);
758 std::cout
<< "[optional] interface ";
762 for (std::vector
<unoidl::InterfaceTypeEntity::Attribute
>::const_iterator
763 j(ent2
->getDirectAttributes().begin());
764 j
!= ent2
->getDirectAttributes().end(); ++j
)
767 writeAnnotations(j
->annotations
);
768 std::cout
<< "[attribute";
770 std::cout
<< ", bound";
773 std::cout
<< ", readonly";
777 std::cout
<< ' ' << j
->name
;
778 if (!(j
->getExceptions
.empty() && j
->setExceptions
.empty()))
781 if (!j
->getExceptions
.empty()) {
784 writeExceptionSpecification(j
->getExceptions
);
787 if (!j
->setExceptions
.empty()) {
790 writeExceptionSpecification(j
->setExceptions
);
797 for (std::vector
<unoidl::InterfaceTypeEntity::Method
>::const_iterator
798 j(ent2
->getDirectMethods().begin());
799 j
!= ent2
->getDirectMethods().end(); ++j
)
802 writeAnnotations(j
->annotations
);
803 writeType(j
->returnType
);
804 std::cout
<< ' ' << j
->name
<< '(';
805 for (std::vector
<unoidl::InterfaceTypeEntity::Method::Parameter
>::const_iterator
806 k(j
->parameters
.begin());
807 k
!= j
->parameters
.end(); ++k
)
809 if (k
!= j
->parameters
.begin()) {
812 switch (k
->direction
) {
813 case unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN
:
814 std::cout
<< "[in] ";
816 case unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_OUT
:
817 std::cout
<< "[out] ";
819 case unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN_OUT
:
820 std::cout
<< "[inout] ";
824 std::cout
<< ' ' << k
->name
;
827 writeExceptionSpecification(j
->exceptions
);
834 case unoidl::Entity::SORT_TYPEDEF
:
836 rtl::Reference
<unoidl::TypedefEntity
> ent2(
837 static_cast<unoidl::TypedefEntity
*>(ent
.get()));
838 writeAnnotationsPublished(ent
);
839 std::cout
<< "typedef ";
840 writeType(ent2
->getType());
841 std::cout
<< ' ' << id
<< ";\n";
844 case unoidl::Entity::SORT_CONSTANT_GROUP
:
846 rtl::Reference
<unoidl::ConstantGroupEntity
> ent2(
847 static_cast<unoidl::ConstantGroupEntity
*>(ent
.get()));
848 writeAnnotationsPublished(ent
);
849 std::cout
<< "constants " << id
<< " {\n";
850 for (std::vector
<unoidl::ConstantGroupEntity::Member
>::const_iterator
851 j(ent2
->getMembers().begin());
852 j
!= ent2
->getMembers().end(); ++j
)
855 writeAnnotations(j
->annotations
);
856 std::cout
<< "const ";
857 switch (j
->value
.type
) {
858 case unoidl::ConstantValue::TYPE_BOOLEAN
:
859 std::cout
<< "boolean";
861 case unoidl::ConstantValue::TYPE_BYTE
:
864 case unoidl::ConstantValue::TYPE_SHORT
:
865 std::cout
<< "short";
867 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT
:
868 std::cout
<< "unsigned short";
870 case unoidl::ConstantValue::TYPE_LONG
:
873 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG
:
874 std::cout
<< "unsigned long";
876 case unoidl::ConstantValue::TYPE_HYPER
:
877 std::cout
<< "hyper";
879 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER
:
880 std::cout
<< "unsigned hyper";
882 case unoidl::ConstantValue::TYPE_FLOAT
:
883 std::cout
<< "float";
885 case unoidl::ConstantValue::TYPE_DOUBLE
:
886 std::cout
<< "double";
889 std::cout
<< ' ' << j
->name
<< " = ";
890 switch (j
->value
.type
) {
891 case unoidl::ConstantValue::TYPE_BOOLEAN
:
892 std::cout
<< (j
->value
.booleanValue
? "TRUE" : "FALSE");
894 case unoidl::ConstantValue::TYPE_BYTE
:
895 std::cout
<< int(j
->value
.byteValue
);
897 case unoidl::ConstantValue::TYPE_SHORT
:
898 std::cout
<< j
->value
.shortValue
;
900 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT
:
901 std::cout
<< j
->value
.unsignedShortValue
;
903 case unoidl::ConstantValue::TYPE_LONG
:
904 std::cout
<< j
->value
.longValue
;
906 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG
:
907 std::cout
<< j
->value
.unsignedLongValue
;
909 case unoidl::ConstantValue::TYPE_HYPER
:
910 std::cout
<< j
->value
.hyperValue
;
912 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER
:
913 std::cout
<< j
->value
.unsignedHyperValue
;
915 case unoidl::ConstantValue::TYPE_FLOAT
:
916 std::cout
<< j
->value
.floatValue
;
918 case unoidl::ConstantValue::TYPE_DOUBLE
:
919 std::cout
<< j
->value
.doubleValue
;
928 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE
:
930 rtl::Reference
<unoidl::SingleInterfaceBasedServiceEntity
> ent2(
931 static_cast<unoidl::SingleInterfaceBasedServiceEntity
*>(
933 writeAnnotationsPublished(ent
);
934 std::cout
<< "service " << id
<< ": ";
935 writeName(ent2
->getBase());
936 if (ent2
->getConstructors().size() != 1
937 || !ent2
->getConstructors().front().defaultConstructor
)
940 for (std::vector
<unoidl::SingleInterfaceBasedServiceEntity::Constructor
>::const_iterator
941 j(ent2
->getConstructors().begin());
942 j
!= ent2
->getConstructors().end(); ++j
)
945 writeAnnotations(j
->annotations
);
946 std::cout
<< j
->name
<< '(';
947 for (std::vector
<unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
>::const_iterator
948 k(j
->parameters
.begin());
949 k
!= j
->parameters
.end(); ++k
)
951 if (k
!= j
->parameters
.begin()) {
954 std::cout
<< "[in] ";
959 std::cout
<< ' ' << k
->name
;
962 writeExceptionSpecification(j
->exceptions
);
971 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE
:
973 rtl::Reference
<unoidl::AccumulationBasedServiceEntity
> ent2(
974 static_cast<unoidl::AccumulationBasedServiceEntity
*>(
976 writeAnnotationsPublished(ent
);
977 std::cout
<< "service " << id
<< " {\n";
978 for (std::vector
<unoidl::AnnotatedReference
>::const_iterator
j(
979 ent2
->getDirectMandatoryBaseServices().begin());
980 j
!= ent2
->getDirectMandatoryBaseServices().end(); ++j
)
983 writeAnnotations(j
->annotations
);
984 std::cout
<< "service ";
988 for (std::vector
<unoidl::AnnotatedReference
>::const_iterator
j(
989 ent2
->getDirectOptionalBaseServices().begin());
990 j
!= ent2
->getDirectOptionalBaseServices().end(); ++j
)
993 writeAnnotations(j
->annotations
);
994 std::cout
<< "[optional] service ";
998 for (std::vector
<unoidl::AnnotatedReference
>::const_iterator
j(
999 ent2
->getDirectMandatoryBaseInterfaces().begin());
1000 j
!= ent2
->getDirectMandatoryBaseInterfaces().end(); ++j
)
1003 writeAnnotations(j
->annotations
);
1004 std::cout
<< "interface ";
1008 for (std::vector
<unoidl::AnnotatedReference
>::const_iterator
j(
1009 ent2
->getDirectOptionalBaseInterfaces().begin());
1010 j
!= ent2
->getDirectOptionalBaseInterfaces().end(); ++j
)
1013 writeAnnotations(j
->annotations
);
1014 std::cout
<< "[optional] interface ";
1018 for (std::vector
<unoidl::AccumulationBasedServiceEntity::Property
>::const_iterator
1019 j(ent2
->getDirectProperties().begin());
1020 j
!= ent2
->getDirectProperties().end(); ++j
)
1023 writeAnnotations(j
->annotations
);
1024 std::cout
<< "[property";
1026 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_BOUND
)
1029 std::cout
<< ", bound";
1032 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED
)
1035 std::cout
<< ", constrained";
1038 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_MAYBE_AMBIGUOUS
)
1041 std::cout
<< ", maybeambiguous";
1044 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_MAYBE_DEFAULT
)
1047 std::cout
<< ", maybedefault";
1050 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_MAYBE_VOID
)
1053 std::cout
<< ", maybevoid";
1056 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_OPTIONAL
)
1059 std::cout
<< ", optional";
1062 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_READ_ONLY
)
1065 std::cout
<< ", readonly";
1068 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_REMOVABLE
)
1071 std::cout
<< ", removable";
1074 & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_TRANSIENT
)
1077 std::cout
<< ", transient";
1081 std::cout
<< ' ' << j
->name
<< ";\n";
1084 std::cout
<< "};\n";
1087 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON
:
1089 rtl::Reference
<unoidl::InterfaceBasedSingletonEntity
> ent2(
1090 static_cast<unoidl::InterfaceBasedSingletonEntity
*>(
1092 writeAnnotationsPublished(ent
);
1093 std::cout
<< "singleton " << id
<< ": ";
1094 writeName(ent2
->getBase());
1098 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON
:
1100 rtl::Reference
<unoidl::ServiceBasedSingletonEntity
> ent2(
1101 static_cast<unoidl::ServiceBasedSingletonEntity
*>(
1103 writeAnnotationsPublished(ent
);
1104 std::cout
<< "singleton " << id
<< " { service ";
1105 writeName(ent2
->getBase());
1106 std::cout
<< "; };";
1115 SAL_IMPLEMENT_MAIN() {
1117 sal_uInt32 args
= rtl_getAppCommandArgCount();
1122 rtl_getAppCommandArg(0, &arg
.pData
);
1123 bool published
= arg
== "--published";
1124 if (published
&& args
== 1) {
1127 rtl::Reference
<unoidl::Manager
> mgr(new unoidl::Manager
);
1128 rtl::Reference
<unoidl::Provider
> prov
;
1129 for (sal_uInt32 i
= (published
? 1 : 0); i
!= args
; ++i
) {
1130 OUString
uri(getArgumentUri(i
));
1132 prov
= mgr
->addProvider(uri
);
1133 } catch (unoidl::NoSuchFileException
&) {
1135 << "Input <" << uri
<< "> does not exist" << std::endl
;
1136 std::exit(EXIT_FAILURE
);
1139 std::map
<OUString
, Entity
> ents
;
1140 scanMap(mgr
, prov
->createRootCursor(), published
, "", ents
);
1141 std::vector
<OUString
> sorted(sort(ents
));
1142 std::vector
<OUString
> mods
;
1143 for (std::vector
<OUString
>::iterator
i(sorted
.begin());
1144 i
!= sorted
.end(); ++i
)
1146 writeEntity(ents
, mods
, *i
);
1148 closeModules(mods
, mods
.size());
1149 return EXIT_SUCCESS
;
1150 } catch (unoidl::FileFormatException
& e1
) {
1152 << "Bad input <" << e1
.getUri() << ">: " << e1
.getDetail()
1154 std::exit(EXIT_FAILURE
);
1158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */