1 --- cli_ure/source/bootstrap/makefile.mk.old 2009-04-06 16:41:58.000000000 +0000
2 +++ cli_ure/source/bootstrap/makefile.mk 2009-04-06 16:41:58.000000000 +0000
3 @@ -76,8 +76,12 @@ $(ASSEMBLY_ATTRIBUTES) .PHONY: assembly.
5 EXTERNAL_DIR=$(PRJ)$/..$/external/cli
7 -$(OUT)$/bin$/cli_uretypes.dll : $(EXTERNAL_DIR)$/cli_uretypes.dll
9 +.IF "$(ENABLE_MONO_CLIMAKER)" != "YES"
11 +$(OUT)$/bin$/cli_uretypes.dll : $(EXTERNAL_DIR)$/cli_uretypes.dll $(EXTERNAL_DIR)$/cli_uretypes.config $(EXTERNAL_DIR)$/policy.1.0.cli_uretypes.dll
12 + +$(COPY) $? $(OUT)$/bin$/
16 $(BIN)$/cli_cppuhelper.dll : $(CSFILES) $(OUT)$/bin$/cli_uretypes.dll
18 --- cli_ure/source/climaker/makefile.mk.old 2009-04-02 10:49:20.000000000 +0000
19 +++ cli_ure/source/climaker/makefile.mk 2009-04-06 16:41:58.000000000 +0000
20 @@ -45,6 +45,30 @@ CCACHE_DISABLE=TRUE
21 .INCLUDE : settings.mk
22 .INCLUDE : $(PRJ)$/util$/makefile.pmk
24 +.IF "$(ENABLE_MONO)" == "YES"
26 +.IF "$(ENABLE_MONO_CLIMAKER)" != "YES"
28 +ALLTAR : # do nothing
32 +SLOFILES = $(SLO)$/climaker_mono.obj
34 +SHL1STDLIBS= $(CPPULIB) $(CPPUHELPERLIB) $(SALLIB)
37 +ALLTAR : $(BIN)$/climaker
39 +$(BIN)$/climaker : climaker_csharp.cs
40 + gmcs -debug -unsafe climaker_csharp.cs -reference:$(BIN)/cli_basetypes.dll -out:$(BIN)$/climaker.exe
41 + mkbundle2 --static -o $(BIN)$/climaker $(BIN)$/climaker.exe -L $(OUT)/lib
48 .IF "$(BUILD_FOR_CLI)" != ""
51 @@ -138,6 +162,4 @@ $(OBJFILES): $(BIN)$/cli_basetypes.dll
59 --- cli_ure/unotypes/makefile.mk.old 2009-04-06 16:41:58.000000000 +0000
60 +++ cli_ure/unotypes/makefile.mk 2009-04-06 16:41:58.000000000 +0000
61 @@ -41,7 +41,14 @@ TARGET = unotypes
62 .INCLUDE : $(PRJ)$/util$/target.pmk
65 -.IF "$(BUILD_FOR_CLI)" != ""
66 +.IF "$(BUILD_FOR_CLI)" != "" && ("$(GUI)" == "WNT" || "$(ENABLE_MONO_CLIMAKER)" == "YES")
68 +.IF "$(ENABLE_MONO_CLIMAKER)" == "YES"
69 +WRAPCMD=MONO_PATH=$(OUT)/bin:$(MONO_PATH) LD_LIBRARY_PATH=$(SOLARLIBDIR):$(OUT)/lib
70 +CLIMAKER=$(BIN)$/climaker
72 +CLIMAKER=climaker.exe
75 .INCLUDE : $(BIN)$/cliureversion.mk
77 @@ -57,8 +64,8 @@ CLIMAKERFLAGS += --verbose
80 #When changing the assembly version then this must also be done in scp2
81 -$(OUT)$/bin$/cli_uretypes.dll : $(BIN)$/climaker.exe $(SOLARBINDIR)$/types.rdb $(BIN)$/cliureversion.mk
82 - $(subst,$(SOLARBINDIR)$/climaker,$(BIN)$/climaker $(CLIMAKER)) $(CLIMAKERFLAGS) \
83 +$(OUT)$/bin$/cli_uretypes.dll : $(CLIMAKER) $(SOLARBINDIR)$/types.rdb $(BIN)$/cliureversion.mk
84 + $(WRAPCMD) $(CLIMAKER) $(CLIMAKERFLAGS) \
86 --keyfile $(BIN)$/cliuno.snk \
87 --assembly-version $(CLI_URETYPES_NEW_VERSION) \
88 @@ -69,7 +76,7 @@ $(OUT)$/bin$/cli_uretypes.dll : $(BIN)$/
89 #do not forget to deliver cli_uretypes.config. It is NOT embedded in the policy file.
90 #see i62886 for the dependency on cli_uretypes.dll
91 $(POLICY_ASSEMBLY_FILE) : $(BIN)$/cli_uretypes.config $(OUT)$/bin$/cli_uretypes.dll
92 - $(WRAPCMD) AL.exe -out:$@ \
93 + $(WRAPCMD) $(AL) -out:$@ \
94 -version:$(CLI_URETYPES_POLICY_VERSION) \
95 -keyfile:$(BIN)$/cliuno.snk \
96 -link:cli_uretypes.config,$(BIN)$/cli_uretypes.config
97 --- cli_ure/source/climaker/climaker_mono.cxx.old 1970-01-01 00:00:00.000000000 +0000
98 +++ cli_ure/source/climaker/climaker_mono.cxx 2009-04-06 16:41:58.000000000 +0000
105 +#include "osl/process.h"
106 +#include "osl/file.hxx"
107 +#include "osl/thread.h"
108 +#include "rtl/ustring.hxx"
109 +#include "rtl/ustrbuf.hxx"
110 +#include "cppuhelper/shlib.hxx"
111 +#include "cppuhelper/bootstrap.hxx"
112 +#include "com/sun/star/lang/XInitialization.hpp"
113 +#include "com/sun/star/lang/XSingleComponentFactory.hpp"
114 +#include "com/sun/star/lang/XComponent.hpp"
115 +#include "com/sun/star/container/XSet.hpp"
116 +#include "com/sun/star/container/XHierarchicalNameAccess.hpp"
117 +#include "com/sun/star/reflection/XConstantTypeDescription.hpp"
118 +#include "com/sun/star/reflection/XConstantsTypeDescription.hpp"
119 +#include "com/sun/star/reflection/XEnumTypeDescription.hpp"
120 +#include "com/sun/star/reflection/XIndirectTypeDescription.hpp"
121 +#include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp"
122 +#include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp"
123 +#include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp"
124 +#include "com/sun/star/reflection/XMethodParameter.hpp"
125 +#include "com/sun/star/reflection/XParameter.hpp"
126 +#include "com/sun/star/reflection/XServiceConstructorDescription.hpp"
127 +#include "com/sun/star/reflection/XServiceTypeDescription2.hpp"
128 +#include "com/sun/star/reflection/XSingletonTypeDescription2.hpp"
129 +#include "com/sun/star/reflection/XStructTypeDescription.hpp"
130 +#include "com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp"
131 +#include "com/sun/star/registry/XSimpleRegistry.hpp"
133 +using namespace ::std;
135 +using namespace ::rtl;
136 +using namespace ::com::sun::star;
137 +using namespace ::com::sun::star::uno;
139 +#define OUSTR(x) ::rtl::OUString(x, strlen (x), osl_getThreadTextEncoding ())
164 + UTC_InterfaceAttribute,
165 + UTC_InterfaceMethod,
173 +UnoTypeClass unoTypeClassToCLI (TypeClass tc)
176 + case TypeClass_UNKNOWN:
177 + return UTC_Unknown;
178 + case TypeClass_VOID:
180 + case TypeClass_CHAR:
182 + case TypeClass_BOOLEAN:
183 + return UTC_Boolean;
184 + case TypeClass_BYTE:
186 + case TypeClass_SHORT:
188 + case TypeClass_UNSIGNED_SHORT:
189 + return UTC_UnsignedShort;
190 + case TypeClass_LONG:
192 + case TypeClass_UNSIGNED_LONG:
193 + return UTC_UnsignedLong;
194 + case TypeClass_HYPER:
196 + case TypeClass_UNSIGNED_HYPER:
197 + return UTC_UnsignedHyper;
198 + case TypeClass_FLOAT:
200 + case TypeClass_DOUBLE:
202 + case TypeClass_STRING:
204 + case TypeClass_TYPE:
206 + case TypeClass_ANY:
208 + case TypeClass_ENUM:
210 + case TypeClass_TYPEDEF:
211 + return UTC_Typedef;
212 + case TypeClass_STRUCT:
214 + case TypeClass_EXCEPTION:
215 + return UTC_Exception;
216 + case TypeClass_SEQUENCE:
217 + return UTC_Sequence;
218 + case TypeClass_INTERFACE:
219 + return UTC_Interface;
220 + case TypeClass_INTERFACE_ATTRIBUTE:
221 + return UTC_InterfaceAttribute;
222 + case TypeClass_INTERFACE_METHOD:
223 + return UTC_InterfaceMethod;
224 + case TypeClass_CONSTANT:
225 + return UTC_Constant;
226 + case TypeClass_CONSTANTS:
227 + return UTC_Constants;
228 + case TypeClass_SERVICE:
229 + return UTC_Service;
230 + case TypeClass_SINGLETON:
231 + return UTC_Singleton;
232 + case TypeClass_MODULE:
238 + throw RuntimeException(
239 + OUSTR("unexpected type in unoTypeClassToCLI"),
240 + Reference< XInterface >() );
243 +UnoTypeClass unoTypeClass (reflection::XTypeDescription* xType)
245 + return unoTypeClassToCLI (xType->getTypeClass ());
250 + Reference< XComponentContext > mxContext;
251 + Reference< lang::XSingleComponentFactory > mxTDprov_factory;
252 + Reference< container::XHierarchicalNameAccess > mxTDmgr;
253 + Reference< XInterface > mxTD_provider;
254 + Reference< reflection::XTypeDescriptionEnumeration > mxTD_enum;
255 + Reference< reflection::XTypeDescription > mxTD;
258 + vector< OUString > mMandatoryRegistries;
259 + vector< OUString > mExtraRegistries;
260 + vector< OUString > mExplicitTypes;
262 + static OUString const & path_get_working_dir()
264 + static OUString s_workingDir;
265 + if (! s_workingDir.getLength())
266 + osl_getProcessWorkingDir( &s_workingDir.pData );
267 + return s_workingDir;
270 + static OUString path_make_absolute_file_url( OUString const & path )
273 + oslFileError rc = osl_getFileURLFromSystemPath(
274 + path.pData, &file_url.pData );
275 + if (osl_File_E_None == rc)
278 + rc = osl_getAbsoluteFileURL(
279 + path_get_working_dir().pData, file_url.pData, &abs.pData );
280 + if (osl_File_E_None == rc)
286 + throw RuntimeException(
287 + OUSTR("cannot make absolute: ") + file_url,
288 + Reference< XInterface >() );
293 + throw RuntimeException(
294 + OUSTR("cannot get file url from system path: ") + path,
295 + Reference< XInterface >() );
299 + Reference< registry::XSimpleRegistry > open_registries(
300 + vector< OUString > const & registries )
302 + if (registries.empty())
304 + throw RuntimeException(OUSTR("no registries given!"),
305 + Reference< XInterface >() );
308 + Reference< registry::XSimpleRegistry > xSimReg;
309 + for ( size_t nPos = registries.size(); nPos--; )
311 + Reference< registry::XSimpleRegistry > xReg(
312 + mxContext->getServiceManager()->createInstanceWithContext(
313 + OUSTR("com.sun.star.registry.SimpleRegistry"), mxContext ),
315 + xReg->open( registries[ nPos ], sal_True, sal_False );
316 + if (! xReg->isValid())
318 + throw RuntimeException(
319 + OUSTR("invalid registry: ") + registries[ nPos ],
320 + Reference< XInterface >() );
323 + if (xSimReg.is()) // nest?
325 + Reference< registry::XSimpleRegistry > xNested(
326 + mxContext->getServiceManager()->createInstanceWithContext(
327 + OUSTR("com.sun.star.registry.NestedRegistry"), mxContext ),
329 + Reference< lang::XInitialization > xInit(
330 + xNested, UNO_QUERY_THROW );
331 + Sequence< Any > args( 2 );
332 + args[ 0 ] <<= xReg;
333 + args[ 1 ] <<= xSimReg;
334 + xInit->initialize( args );
351 + mxContext = ::cppu::bootstrap_InitialComponentContext(
352 + Reference< registry::XSimpleRegistry >() );
353 + mxTDmgr = Reference< container::XHierarchicalNameAccess > (
354 + mxContext->getValueByName(
355 + OUSTR("/singletons/com.sun.star.reflection."
356 + "theTypeDescriptionManager") ),
359 + // get rdb tdprovider factory
360 + mxTDprov_factory = Reference< lang::XSingleComponentFactory > (
361 + ::cppu::loadSharedLibComponentFactory(
362 + OUSTR("bootstrap.uno" SAL_DLLEXTENSION), OUString(),
363 + OUSTR("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider"),
364 + Reference< lang::XMultiServiceFactory >(
365 + mxContext->getServiceManager(), UNO_QUERY ),
366 + Reference< registry::XRegistryKey >() ), UNO_QUERY );
367 + if (! mxTDprov_factory.is())
369 + throw RuntimeException(
370 + OUSTR("cannot get registry typedescription provider: "
371 + "bootstrap.uno" SAL_DLLEXTENSION "!"),
372 + Reference< XInterface >() );
376 + void AddMandatoryRegistry (char *registry)
378 + mMandatoryRegistries.push_back(
379 + path_make_absolute_file_url( OUSTR( registry ) ) );
382 + void AddExtraRegistry (char *registry)
384 + mExtraRegistries.push_back(
385 + path_make_absolute_file_url( OUSTR( registry ) ) );
388 + void AddExplicitType (char *typeName)
390 + mExplicitTypes.push_back( OUSTR( typeName ) );
393 + void OpenRegistries ()
395 + // create registry td provider for mandatory registry files
396 + Any arg( makeAny( open_registries( mMandatoryRegistries ) ) );
397 + mxTD_provider = Reference< XInterface >(
398 + mxTDprov_factory->createInstanceWithArgumentsAndContext(
399 + Sequence< Any >( &arg, 1 ), mxContext ) );
401 + // insert provider to tdmgr
402 + Reference< container::XSet > xSet( mxTDmgr, UNO_QUERY_THROW );
403 + Any provider( makeAny( mxTD_provider ) );
404 + xSet->insert( provider );
405 + OSL_ASSERT( xSet->has( provider ) );
407 + if (! mExtraRegistries.empty())
409 + arg = makeAny( open_registries( mExtraRegistries ) );
410 + provider = makeAny(
411 + mxTDprov_factory->createInstanceWithArgumentsAndContext(
412 + Sequence< Any >( &arg, 1 ), mxContext ) );
413 + xSet->insert( provider );
414 + OSL_ASSERT( xSet->has( provider ) );
417 + // and emit types to it
418 + if (mExplicitTypes.empty())
420 + mxTD_enum = Reference< reflection::XTypeDescriptionEnumeration > (
421 + Reference< reflection::XTypeDescriptionEnumerationAccess >(
422 + mxTD_provider, UNO_QUERY_THROW )
423 + ->createTypeDescriptionEnumeration(
424 + OUString() /* all IDL modules */,
425 + Sequence< TypeClass >() /* all classes of types */,
426 + reflection::TypeDescriptionSearchDepth_INFINITE ) );
433 + Reference< reflection::XTypeDescription > xTD;
435 + if (mnPos < mExplicitTypes.size()) {
436 + Reference< container::XHierarchicalNameAccess > xHNA(
437 + mxTD_provider, UNO_QUERY_THROW );
438 + xTD = Reference< reflection::XTypeDescription >(
439 + xHNA->getByHierarchicalName( mExplicitTypes[ mnPos ] ),
442 + } else if (mxTD_enum.is() && mxTD_enum->hasMoreElements())
443 + xTD = Reference< reflection::XTypeDescription >(mxTD_enum->nextTypeDescription());
446 + xTD.get ()->acquire ();
461 + static char* oustr_to_char (OUString oustr)
463 + OString os = OUStringToOString (oustr, osl_getThreadTextEncoding());
465 + size_t len = os.getLength () + 1;
466 + char *str = (char *) malloc (len);
467 + memcpy (str, os.getStr (), len);
472 + /* UnoHelper class glue */
475 + cmm_uno_helper_new ()
477 + return new UnoHelper ();
481 + cmm_uno_helper_add_mandatory_registry (void *ptr, char *registry)
483 + UnoHelper *helper = (UnoHelper *) ptr;
485 + helper->AddMandatoryRegistry (registry);
489 + cmm_uno_helper_add_extra_registry (void *ptr, char *registry)
491 + UnoHelper *helper = (UnoHelper *) ptr;
493 + helper->AddExtraRegistry (registry);
497 + cmm_uno_helper_add_explicit_type (void *ptr, char *typeName)
499 + UnoHelper *helper = (UnoHelper *) ptr;
501 + helper->AddExplicitType (typeName);
505 + cmm_uno_helper_open_registries (void *ptr)
507 + UnoHelper *helper = (UnoHelper *) ptr;
509 + helper->OpenRegistries ();
513 + cmm_uno_helper_next_type (void *ptr)
515 + UnoHelper *helper = (UnoHelper *) ptr;
517 + return helper->NextType ();
521 + cmm_uno_helper_delete (void *ptr)
523 + UnoHelper *helper = (UnoHelper *) ptr;
528 + /* XTypeDescription glue */
531 + cmm_x_type_description_get_name (void *ptr)
533 + reflection::XTypeDescription* xTD = (reflection::XTypeDescription *) ptr;
535 + return oustr_to_char (xTD->getName ());
539 + cmm_x_type_description_get_type_class (void *ptr)
541 + reflection::XTypeDescription* xTD = (reflection::XTypeDescription *) ptr;
543 + return unoTypeClass (xTD);
547 + cmm_x_type_description_release (void *ptr)
549 + reflection::XTypeDescription* xTD = (reflection::XTypeDescription *) ptr;
554 + /* XEnumTypeDescription glue */
557 + cmm_x_enum_type_description_get_name (void *ptr, int idx)
559 + reflection::XEnumTypeDescription* xTD = (reflection::XEnumTypeDescription *) ptr;
561 + Sequence< OUString > seq_enum_names (xTD->getEnumNames ());
563 + return oustr_to_char (seq_enum_names [idx]);
567 + cmm_x_enum_type_description_get_value (void *ptr, int idx)
569 + reflection::XEnumTypeDescription* xTD = (reflection::XEnumTypeDescription *) ptr;
571 + Sequence< sal_Int32 > seq_enum_values (xTD->getEnumValues ());
573 + return seq_enum_values [idx];
577 + cmm_x_enum_type_description_get_length (void *ptr)
579 + reflection::XEnumTypeDescription* xTD = (reflection::XEnumTypeDescription *) ptr;
581 + Sequence< sal_Int32 > seq_enum_values (xTD->getEnumValues ());
583 + return seq_enum_values.getLength ();
586 + /* XInterfaceTypeDescription glue */
589 + cmm_x_interface_type_description_get_members (void *ptr, const void **handle)
591 + reflection::XInterfaceTypeDescription* xTD = (reflection::XInterfaceTypeDescription *) ptr;
594 + Reference< reflection::XInterfaceMemberTypeDescription > > seq_members (xTD->getMembers ());
595 + Reference< reflection::XInterfaceMemberTypeDescription > const * types = seq_members.getConstArray();
597 + int length = seq_members.getLength ();
598 + reflection::XInterfaceMemberTypeDescription **array = (reflection::XInterfaceMemberTypeDescription**) malloc (length*sizeof (reflection::XInterfaceMemberTypeDescription *));
602 + for (int i = 0; i < length; i ++) {
603 + array [i] = types [i].get ();
604 + array [i]->acquire ();
611 + cmm_x_interface_type_description_get_member (void *ptr, int idx)
613 + reflection::XInterfaceMemberTypeDescription** members = (reflection::XInterfaceMemberTypeDescription**) ptr;
615 + members [idx]->acquire ();
617 + return members [idx];
621 + cmm_x_interface_type_description_members_release (void *ptr)
623 +// uno_Sequence* seq = (uno_Sequence*) ptr;
628 + /* XInterfaceTypeDescription2 glue */
631 + cmm_resolveInterface (Reference< reflection::XTypeDescription > type)
633 + Reference<reflection::XInterfaceTypeDescription2>
634 + xIfaceTd (type, UNO_QUERY);
636 + if (xIfaceTd.is()) {
637 + reflection::XTypeDescription* xtd = type.get ();
643 + Reference<reflection::XIndirectTypeDescription> xIndTd(
645 + if (xIndTd.is() == sal_False)
646 + throw uno::Exception(
647 + OUSTR("resolveInterfaceTypedef was called with an invalid argument"), 0);
648 + return cmm_resolveInterface (xIndTd->getReferencedType());
654 + cmm_x_interface_type_description_get_base_type (void *ptr, int idx)
656 + reflection::XInterfaceTypeDescription2* xTD = (reflection::XInterfaceTypeDescription2 *) ptr;
658 + Sequence< Reference< reflection::XTypeDescription > > seq_base_types (xTD->getBaseTypes ());
660 + Reference< reflection::XTypeDescription > type (seq_base_types [idx]);
662 + return cmm_resolveInterface (type);
666 + cmm_x_interface_type_description_get_length (void *ptr)
668 + reflection::XInterfaceTypeDescription2* xTD = (reflection::XInterfaceTypeDescription2 *) ptr;
670 + Sequence< Reference< reflection::XTypeDescription > > seq_base_types (xTD->getBaseTypes ());
672 + return seq_base_types.getLength ();
675 + /* XInterfaceAttributeTypeDescription glue */
678 + cmm_x_interface_attribute_type_description_get_type (void *ptr)
680 + reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
681 + Reference< reflection::XTypeDescription > xrt = xTD->getType ();
683 + xrt.get ()->acquire ();
689 + cmm_x_interface_attribute_type_description_is_bound (void *ptr)
691 + reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
693 + return xTD->isBound ();
697 + cmm_x_interface_attribute_type_description_is_read_only (void *ptr)
699 + reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
701 + return xTD->isReadOnly ();
705 + get_exception_types (const Sequence<Reference< reflection::XCompoundTypeDescription > >& seq_exceptionsCTD, void **handle)
707 + int length = seq_exceptionsCTD.getLength ();
712 + Reference< reflection::XCompoundTypeDescription > const * types = seq_exceptionsCTD.getConstArray();
713 + size_t size = length*sizeof (reflection::XCompoundTypeDescription *);
714 + reflection::XCompoundTypeDescription **array = (reflection::XCompoundTypeDescription**) malloc (size);
718 + for (int i = 0; i < length; i ++) {
719 + array [i] = types [i].get ();
720 + array [i]->acquire ();
727 + cmm_x_interface_attribute_type_description_get_get_exception_types (void *ptr, void **handle)
729 + reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
731 + return get_exception_types (xTD->getGetExceptions (), handle);
735 + cmm_x_interface_attribute_type_description_get_set_exception_types (void *ptr, void **handle)
737 + reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
739 + return get_exception_types (xTD->getSetExceptions (), handle);
743 + cmm_x_interface_attribute_type_description_get_exception_type (void *ptr, int index)
745 + reflection::XCompoundTypeDescription **array = (reflection::XCompoundTypeDescription**) ptr;;
747 + return array [index];
751 + free_exception_types (void *ptr, int count)
753 + reflection::XCompoundTypeDescription **array = (reflection::XCompoundTypeDescription**) ptr;;
756 + for (i = 0; i < count; i ++)
757 + array [i]->release ();
763 + cmm_x_interface_attribute_type_description_free_exception_types (void *ptr, int count)
765 + free_exception_types (ptr, count);
768 + /* XInterfaceMemberTypeDescription glue */
771 + cmm_x_interface_member_type_description_get_member_name (void *ptr)
773 + reflection::XInterfaceMemberTypeDescription* xTD = (reflection::XInterfaceMemberTypeDescription *) ptr;
775 + return oustr_to_char (xTD->getMemberName ());;
778 + /* XInterfaceMethodTypeDescription glue */
781 + cmm_x_interface_method_type_description_get_parameters (void *ptr, const void **parametersHandle, const void** parametersArrayHandle)
783 + reflection::XInterfaceMethodTypeDescription* xTD = (reflection::XInterfaceMethodTypeDescription *) ptr;
786 + Reference< reflection::XMethodParameter > > seq_parameters (xTD->getParameters ());
787 + Reference< reflection::XMethodParameter > const * parameters = seq_parameters.getConstArray();
789 + *parametersHandle = seq_parameters.get ();
791 + int length = seq_parameters.getLength();
792 + size_t size = length*sizeof (Reference< reflection::XMethodParameter > const);
793 + Reference< reflection::XMethodParameter > *copy = (Reference< reflection::XMethodParameter > *) malloc (size);
794 + memcpy (copy, parameters, size);
796 + *parametersArrayHandle = copy;
798 + for (int i=0; i<length; i++) {
799 + copy[i].get()->acquire ();
806 + cmm_x_interface_method_type_description_get_parameter (void *ptr, int idx)
808 + Reference< reflection::XMethodParameter > const * parameters = (Reference< reflection::XMethodParameter > const *) ptr;
810 + reflection::XMethodParameter* parameterHandle = parameters [idx].get ();
812 + parameterHandle->acquire ();
814 + return parameterHandle;
818 + cmm_x_interface_method_type_description_get_exception_types (void *ptr, const void **exceptionTypesHandle, const void** exceptionTypesArrayHandle)
820 + reflection::XInterfaceMethodTypeDescription* xMethod = (reflection::XInterfaceMethodTypeDescription *) ptr;
822 + const Sequence<Reference<reflection::XTypeDescription> > seqTD = xMethod->getExceptions();
823 + int length = seqTD.getLength();
824 + Sequence<Reference<reflection::XCompoundTypeDescription> > seqCTD( length );
825 + Reference< reflection::XCompoundTypeDescription > * arCTD = seqCTD.getArray();
828 + size_t size = length*sizeof (Reference< reflection::XCompoundTypeDescription > const);
829 + Reference< reflection::XCompoundTypeDescription > *copy = (Reference< reflection::XCompoundTypeDescription > *) malloc (size);
831 + for (int i=0; i<length; i++) {
832 + arCTD[i] = Reference<reflection::XCompoundTypeDescription>(seqTD[i], UNO_QUERY_THROW);
835 + memcpy (copy, arCTD, size);
837 + *exceptionTypesArrayHandle = copy;
839 + for (int i=0; i<length; i++) {
840 + copy[i].get()->acquire ();
843 + *exceptionTypesArrayHandle = NULL;
844 + *exceptionTypesHandle = NULL;
851 + cmm_x_interface_method_type_description_get_exception_type (void *ptr, int idx)
853 + Reference< reflection::XCompoundTypeDescription > const * exceptionTypes = (Reference< reflection::XCompoundTypeDescription > const *) ptr;
855 + reflection::XCompoundTypeDescription* exceptionTypeHandle = exceptionTypes [idx].get ();
857 + exceptionTypeHandle->acquire ();
859 + return exceptionTypeHandle;
863 + cmm_x_interface_method_type_description_get_return_type (void *ptr)
865 + reflection::XInterfaceMethodTypeDescription* xTD = (reflection::XInterfaceMethodTypeDescription *) ptr;
866 + Reference< reflection::XTypeDescription > xrt = xTD->getReturnType ();
868 + xrt.get ()->acquire ();
874 + cmm_x_interface_method_type_description_returns_struct (void *ptr)
876 + reflection::XInterfaceMethodTypeDescription* xTD = (reflection::XInterfaceMethodTypeDescription *) ptr;
877 + Reference< reflection::XStructTypeDescription > xrt (xTD->getReturnType (), UNO_QUERY);
883 + cmm_x_interface_method_type_description_is_oneway (void *ptr)
885 + reflection::XInterfaceMethodTypeDescription* xTD = (reflection::XInterfaceMethodTypeDescription *) ptr;
887 + return xTD->isOneway ();
890 + /* XMethodParameter glue */
893 + cmm_x_method_parameter_is_out (void *ptr)
895 + reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
897 + return p->isOut ();
901 + cmm_x_method_parameter_is_in (void *ptr)
903 + reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
909 + cmm_x_method_parameter_position (void *ptr)
911 + reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
913 + return p->getPosition ();
917 + cmm_x_method_parameter_name (void *ptr)
919 + reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
921 + return oustr_to_char (p->getName ());
925 + cmm_x_method_parameter_type (void *ptr)
927 + reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
928 + Reference< reflection::XTypeDescription > xtd = p->getType ();
930 + xtd.get ()->acquire ();
935 + /* XCompoundTypeDescription glue */
938 + cmm_x_compound_type_description_get_base_type (void *ptr)
940 + reflection::XCompoundTypeDescription* xTD = (reflection::XCompoundTypeDescription *) ptr;
941 + Reference< reflection::XTypeDescription > xrt = xTD->getBaseType ();
946 + xrt.get ()->acquire ();
952 + cmm_x_compound_type_description_get_member_names (void *ptr, const void **handle)
954 + reflection::XCompoundTypeDescription* xTD = (reflection::XCompoundTypeDescription *) ptr;
956 + Sequence< OUString > seq_member_names = xTD->getMemberNames ();
957 + int length = seq_member_names.getLength ();
962 + OUString const * parameters = seq_member_names.getConstArray();
963 + char **array = (char**) malloc (length*sizeof (char *));
967 + for (int i = 0; i < length; i ++) {
968 + array [i] = oustr_to_char (parameters [i]);
975 + cmm_x_compound_type_description_get_member_name (void *ptr, int idx)
977 + char** member_names = (char **) ptr;
979 + return strdup (member_names [idx]);
983 + cmm_x_compound_type_description_get_member_types (void *ptr, const void **handle)
985 + reflection::XCompoundTypeDescription* xTD = (reflection::XCompoundTypeDescription *) ptr;
987 + Sequence< Reference< reflection::XTypeDescription > > seq_member_types = xTD->getMemberTypes ();
988 + int length = seq_member_types.getLength ();
993 + Reference< reflection::XTypeDescription > const * types = seq_member_types.getConstArray();
994 + reflection::XTypeDescription **array = (reflection::XTypeDescription**) malloc (length*sizeof (reflection::XTypeDescription*));
998 + for (int i = 0; i < length; i ++) {
999 + array [i] = types [i].get ();
1000 + array [i]->acquire ();
1007 + cmm_x_compound_type_description_get_member_type (void *ptr, int idx)
1009 + reflection::XTypeDescription** member_types = (reflection::XTypeDescription **) ptr;
1010 + member_types [idx]->acquire ();
1012 + return member_types [idx];
1015 + /* XStructTypeDescription glue */
1018 + cmm_x_struct_type_description_get_type_parameters (void *ptr, const void **handle)
1020 + reflection::XStructTypeDescription* xTD = (reflection::XStructTypeDescription *) ptr;
1022 + Sequence< OUString > seq_type_parameters = xTD->getTypeParameters ();
1023 + int length = seq_type_parameters.getLength ();
1028 + OUString const * parameters = seq_type_parameters.getConstArray();
1029 + char **array = (char**) malloc (length*sizeof (char *));
1033 + for (int i = 0; i < length; i ++) {
1034 + array [i] = oustr_to_char (parameters [i]);
1041 + cmm_x_struct_type_description_get_type_parameter (void *ptr, int idx)
1043 + char** type_parameters = (char **) ptr;
1045 + return strdup (type_parameters [idx]);
1049 + cmm_x_struct_type_description_get_type_arguments (void *ptr, const void **typeArgumentsHandle, const void** typeArgumentsArrayHandle)
1051 + reflection::XStructTypeDescription* xTD = (reflection::XStructTypeDescription *) ptr;
1054 + Reference< reflection::XTypeDescription > > seq_type_arguments (xTD->getTypeArguments ());
1055 + Reference< reflection::XTypeDescription > const * type_arguments = seq_type_arguments.getConstArray();
1057 + *typeArgumentsHandle = seq_type_arguments.get ();
1059 + int length = seq_type_arguments.getLength();
1060 + size_t size = length*sizeof (Reference< reflection::XTypeDescription > const);
1061 + Reference< reflection::XTypeDescription > *copy = (Reference< reflection::XTypeDescription > *) malloc (size);
1062 + memcpy (copy, type_arguments, size);
1064 + *typeArgumentsArrayHandle = copy;
1066 + for (int i=0; i<length; i++) {
1067 + copy[i].get()->acquire ();
1074 + cmm_x_struct_type_description_get_type_argument (void *ptr, int idx)
1076 + Reference< reflection::XTypeDescription > const * type_arguments = (Reference< reflection::XTypeDescription > const *) ptr;
1078 + reflection::XTypeDescription* typeArgumentHandle = type_arguments [idx].get ();
1080 + typeArgumentHandle->acquire ();
1082 + return typeArgumentHandle;
1085 + /* XIndirectTypeDescription glue */
1088 + cmm_x_indirect_type_description_get_referenced_type (void *ptr)
1090 + reflection::XIndirectTypeDescription* xTD = (reflection::XIndirectTypeDescription *) ptr;
1091 + Reference< reflection::XTypeDescription > xrt = xTD->getReferencedType ();
1093 + xrt.get ()->acquire ();
1095 + return xrt.get ();
1098 + /* XConstantTypeDescription glue */
1100 + UnoTypeClass SAL_CALL
1101 + cmm_any_to_cli_constant (void *ptr,
1102 + sal_Unicode *tChar, sal_Bool *tBool,
1104 + sal_Int16 *tInt16, sal_uInt16 *tUInt16,
1105 + sal_Int32 *tInt32, sal_uInt32 *tUInt32,
1106 + sal_Int16 *tInt64, sal_uInt64 *tUInt64,
1107 + float *tFloat, double *tDouble)
1109 + reflection::XConstantTypeDescription* xtd = (reflection::XConstantTypeDescription*) ptr;
1110 + Any const & value (xtd->getConstantValue ());
1112 + switch (value.getValueTypeClass ()) {
1113 + case TypeClass_CHAR:
1114 + *tChar = *reinterpret_cast< sal_Unicode const * > (value.getValue ());
1116 + case TypeClass_BOOLEAN:
1117 + *tBool = *reinterpret_cast< sal_Bool const * > (value.getValue ());
1118 + case TypeClass_BYTE:
1119 + *tByte = *reinterpret_cast< sal_uInt8 const * > (value.getValue ());
1121 + case TypeClass_SHORT:
1122 + *tInt16 = *reinterpret_cast< sal_Int16 const * > (value.getValue ());
1124 + case TypeClass_UNSIGNED_SHORT:
1125 + *tUInt16 = *reinterpret_cast< sal_uInt16 const * > (value.getValue ());
1127 + case TypeClass_LONG:
1128 + *tInt32 = *reinterpret_cast< sal_Int32 const * > (value.getValue ());
1130 + case TypeClass_UNSIGNED_LONG:
1131 + *tUInt32 = *reinterpret_cast< sal_uInt32 const * > (value.getValue ());
1133 + case TypeClass_HYPER:
1134 + *tInt64 = *reinterpret_cast< sal_Int64 const * > (value.getValue ());
1136 + case TypeClass_UNSIGNED_HYPER:
1137 + *tUInt64 = *reinterpret_cast< sal_uInt64 const * > (value.getValue ());
1139 + case TypeClass_FLOAT:
1140 + *tFloat = *reinterpret_cast< float const * > (value.getValue ());
1142 + case TypeClass_DOUBLE:
1143 + *tDouble = *reinterpret_cast< double const * > (value.getValue ());
1146 + throw RuntimeException(OUSTR("unexpected constant type ") +
1147 + value.getValueType().getTypeName(),
1148 + Reference< XInterface >() );
1151 + return unoTypeClassToCLI (value.getValueTypeClass ());
1154 + /* XConstantsTypeDescription glue */
1157 + cmm_x_constants_type_description_get_constants (void *ptr, const void **handle)
1159 + reflection::XConstantsTypeDescription* xTD = (reflection::XConstantsTypeDescription *) ptr;
1161 + Sequence< Reference< reflection::XConstantTypeDescription > > seq_member_types = xTD->getConstants ();
1162 + int length = seq_member_types.getLength ();
1167 + Reference< reflection::XConstantTypeDescription > const * types = seq_member_types.getConstArray();
1168 + reflection::XConstantTypeDescription **array = (reflection::XConstantTypeDescription**) malloc (length*sizeof (reflection::XConstantTypeDescription*));
1172 + for (int i = 0; i < length; i ++) {
1173 + array [i] = types [i].get ();
1174 + array [i]->acquire ();
1181 + cmm_x_constants_type_description_get_constant (void *ptr, int idx)
1183 + reflection::XConstantTypeDescription** array = (reflection::XConstantTypeDescription **) ptr;
1184 + array [idx]->acquire ();
1186 + return array [idx];
1189 + /* XServiceTypeDescription glue */
1192 + cmm_x_service_type_description_is_single_interface_based (void *ptr)
1194 + reflection::XServiceTypeDescription2* xTD = (reflection::XServiceTypeDescription2 *) ptr;
1196 + return xTD->isSingleInterfaceBased ();
1200 + cmm_x_service_type_description_get_interface (void *ptr)
1202 + reflection::XServiceTypeDescription2* xTD = (reflection::XServiceTypeDescription2 *) ptr;
1203 + reflection::XTypeDescription* xTDiface = xTD->getInterface ().get ();
1205 + xTDiface->acquire ();
1211 + cmm_x_service_type_description_get_constructors (void *ptr, const void **handle)
1213 + reflection::XServiceTypeDescription2* xTD = (reflection::XServiceTypeDescription2 *) ptr;
1215 + Sequence< Reference< reflection::XServiceConstructorDescription > > seq_member_types = xTD->getConstructors ();
1216 + int length = seq_member_types.getLength ();
1221 + Reference< reflection::XServiceConstructorDescription > const * types = seq_member_types.getConstArray();
1222 + reflection::XServiceConstructorDescription **array = (reflection::XServiceConstructorDescription**) malloc (length*sizeof (reflection::XServiceConstructorDescription*));
1226 + for (int i = 0; i < length; i ++) {
1227 + array [i] = types [i].get ();
1228 + array [i]->acquire ();
1235 + cmm_x_service_type_description_get_constructor (void *ptr, int idx)
1237 + reflection::XServiceConstructorDescription** array = (reflection::XServiceConstructorDescription **) ptr;
1238 + array [idx]->acquire ();
1240 + return array [idx];
1243 + /* XServiceConstructorDescription glue */
1246 + cmm_x_service_constructor_description_get_parameters (void *ptr, const void **handle)
1248 + reflection::XServiceConstructorDescription* xTD = (reflection::XServiceConstructorDescription *) ptr;
1250 + Sequence< Reference< reflection::XParameter > > seq_member_types = xTD->getParameters ();
1251 + int length = seq_member_types.getLength ();
1256 + Reference< reflection::XParameter > const * types = seq_member_types.getConstArray();
1257 + reflection::XParameter **array = (reflection::XParameter**) malloc (length*sizeof (reflection::XParameter*));
1261 + for (int i = 0; i < length; i ++) {
1262 + array [i] = types [i].get ();
1263 + array [i]->acquire ();
1270 + cmm_x_service_constructor_description_get_parameter (void *ptr, int idx)
1272 + reflection::XParameter** array = (reflection::XParameter **) ptr;
1273 + array [idx]->acquire ();
1275 + return array [idx];
1279 + cmm_x_service_constructor_description_get_name (void *ptr)
1281 + reflection::XServiceConstructorDescription* xTD = (reflection::XServiceConstructorDescription *) ptr;
1283 + return oustr_to_char (xTD->getName ());
1287 + cmm_x_service_constructor_description_is_default_constructor (void *ptr)
1289 + reflection::XServiceConstructorDescription* xTD = (reflection::XServiceConstructorDescription *) ptr;
1291 + return xTD->isDefaultConstructor ();
1295 + cmm_x_service_constructor_description_get_exception_types (void *ptr, void **handle)
1297 + reflection::XServiceConstructorDescription* xTD = (reflection::XServiceConstructorDescription *) ptr;
1299 + return get_exception_types (xTD->getExceptions (), handle);
1303 + cmm_x_service_constructor_description_get_exception_type (void *ptr, int index)
1305 + reflection::XCompoundTypeDescription **array = (reflection::XCompoundTypeDescription**) ptr;;
1307 + return array [index];
1311 + cmm_x_service_constructor_description_free_exception_types (void *ptr, int count)
1313 + free_exception_types (ptr, count);
1316 + /* XParameter glue */
1319 + cmm_x_parameter_is_rest (void *ptr)
1321 + reflection::XParameter* xTD = (reflection::XParameter *) ptr;
1323 + return xTD->isRestParameter ();
1326 + /* XServiceTypeDescription glue */
1329 + cmm_x_singleton_type_description_is_interface_based (void *ptr)
1331 + reflection::XSingletonTypeDescription2* xTD = (reflection::XSingletonTypeDescription2 *) ptr;
1333 + return xTD->isInterfaceBased ();
1337 + cmm_x_singleton_type_description_get_interface (void *ptr)
1339 + reflection::XSingletonTypeDescription2* xTD = (reflection::XSingletonTypeDescription2 *) ptr;
1340 + Reference< reflection::XTypeDescription > xrt = xTD->getInterface ();
1342 + xrt.get ()->acquire ();
1344 + return xrt.get ();
1347 --- cli_ure/source/climaker/climaker_csharp.cs.old 1970-01-01 00:00:00.000000000 +0000
1348 +++ cli_ure/source/climaker/climaker_csharp.cs 2009-04-06 16:41:58.000000000 +0000
1351 +using System.Collections;
1352 +using System.Reflection;
1353 +using System.Reflection.Emit;
1354 +using System.Runtime.InteropServices;
1356 +enum UnoTypeClass {
1379 + InterfaceAttribute,
1390 + public static readonly string UnoVoid = "void";
1391 + public static readonly string UnoType = "type";
1392 + public static readonly string UnoAny = "any";
1393 + public static readonly string UnoBool = "boolean";
1394 + public static readonly string UnoByte = "byte";
1395 + public static readonly string UnoChar = "char";
1396 + public static readonly string UnoShort = "short";
1397 + public static readonly string UnoUShort = "unsigned short";
1398 + public static readonly string UnoLong = "long";
1399 + public static readonly string UnoULong = "unsigned long";
1400 + public static readonly string UnoHyper = "hyper";
1401 + public static readonly string UnoUHyper = "unsigned hyper";
1402 + public static readonly string UnoString = "string";
1403 + public static readonly string UnoFloat = "float";
1404 + public static readonly string UnoDouble = "double";
1405 + public static readonly string UnoXInterface = "com.sun.star.uno.XInterface";
1406 + public static readonly string Brackets = "[]";
1408 + public static readonly string Object = "System.Object";
1409 + public static readonly string Type = "System.Type";
1410 + public static readonly string Unoidl = "unoidl.";
1411 + public static readonly string Void = "System.Void";
1412 + public static readonly string Any = "uno.Any";
1413 + public static readonly string Boolean = "System.Boolean";
1414 + public static readonly string Char = "System.Char";
1415 + public static readonly string Byte = "System.Byte";
1416 + public static readonly string Int16 = "System.Int16";
1417 + public static readonly string UInt16 = "System.UInt16";
1418 + public static readonly string Int32 = "System.Int32";
1419 + public static readonly string UInt32 = "System.UInt32";
1420 + public static readonly string Int64 = "System.Int64";
1421 + public static readonly string UInt64 = "System.UInt64";
1422 + public static readonly string String = "System.String";
1423 + public static readonly string Single = "System.Single";
1424 + public static readonly string Double = "System.Double";
1425 + public static readonly string Comma = ",";
1428 +class TypeEmitter : IDisposable
1430 + ResolveEventHandler mTypeResolver;
1431 + ModuleBuilder mModuleBuilder;
1432 + ArrayList mExtraAssemblies;
1433 + Hashtable mIncompleteIFaces;
1434 + Hashtable mIncompleteServices;
1435 + Hashtable mIncompleteSingletons;
1436 + Hashtable mGeneratedStructs;
1439 + Type mTypeException = null;
1440 + Type mTypeRuntimeException = null;
1442 + readonly static MethodAttributes cCtorMethodAttr =
1443 + MethodAttributes.Public |
1444 + MethodAttributes.HideBySig |
1445 + MethodAttributes.SpecialName |
1446 + MethodAttributes.RTSpecialName;
1447 + /* | xxx todo: ??? compiler does not know Instance ???
1448 + ::System::Reflection::MethodAttributes::Instance*/
1450 + MethodInfo mMethodInfoTypeGetTypeFromHandle;
1454 + public UnoXInterfaceTypeDescription mType;
1455 + public TypeBuilder mTypeBuilder;
1458 + class ServiceEntry
1460 + public UnoXServiceTypeDescription mType;
1461 + public TypeBuilder mTypeBuilder;
1464 + class SingletonEntry
1466 + public UnoXSingletonTypeDescription mType;
1467 + public TypeBuilder mTypeBuilder;
1472 + public string[] mMemberNames;
1473 + public Type[] mParamTypes;
1474 + public ConstructorInfo mDefaultConstructor;
1475 + public ConstructorInfo mConstructor;
1478 + public TypeEmitter (Config config, ModuleBuilder builder)
1482 + // load extra assemblies
1483 + mExtraAssemblies = new ArrayList ();
1484 + foreach (string assemblyPath in mConfig.mExtraAssemblies)
1485 + mExtraAssemblies.Add (Assembly.LoadFrom (assemblyPath));
1487 + mTypeResolver = new ResolveEventHandler (TypeResolveHandler);
1488 + mModuleBuilder = builder;
1490 + mIncompleteIFaces = new Hashtable ();
1491 + mIncompleteServices = new Hashtable ();
1492 + mIncompleteSingletons = new Hashtable ();
1493 + mGeneratedStructs = new Hashtable ();
1495 + Type[] paramTypes = { typeof (RuntimeTypeHandle) };
1496 + mMethodInfoTypeGetTypeFromHandle = typeof (Type).GetMethod ("GetTypeFromHandle", paramTypes);
1499 + public ResolveEventHandler ResolveEventHandler
1503 + return mTypeResolver;
1507 + Assembly TypeResolveHandler (object o, ResolveEventArgs args)
1509 + Type ret = mModuleBuilder.GetType (args.Name, false);
1510 + //Console.WriteLine ("mModuleBuilder.GetType yields {0}", ret);
1512 + if (ret is TypeBuilder) {
1513 + TypeBuilder tb = ret as TypeBuilder;
1514 + //Console.WriteLine ("{0} is type builder", tb);
1515 + if (tb.IsCreated ()) {
1516 + ret = tb.CreateType ();
1517 + //Console.WriteLine ("resolving to created {0} {1}", ret, tb);
1521 + if (ret == null) {
1522 + IFaceEntry entry = mIncompleteIFaces [args.Name] as IFaceEntry;
1523 + if (entry != null)
1524 + ret = entry.mTypeBuilder;
1527 + if (ret == null && mExtraAssemblies != null) {
1528 + //Console.WriteLine ("assemblies {0}", mExtraAssemblies);
1529 + foreach (Assembly assembly in mExtraAssemblies) {
1530 + ret = assembly.GetType (args.Name, false);
1531 + if (ret != null) {
1532 + if (mConfig.mVerbose) {
1533 + Console.WriteLine ("> resolving type {0} from {1}.",
1534 + args.Name, ret.Assembly.FullName);
1539 + //Console.WriteLine ("done {0}", ret);
1543 + return ret.Assembly;
1548 + Type GetType (string name, bool throwExc)
1550 + Type ret = mModuleBuilder.GetType (name, false);
1551 + //Console.WriteLine ("mModuleBuilder.GetType yields {0}", ret);
1553 + if (ret is TypeBuilder) {
1554 + TypeBuilder tb = ret as TypeBuilder;
1555 + //Console.WriteLine ("{0} is type builder", tb);
1556 + if (tb.IsCreated ()) {
1557 + ret = tb.CreateType ();
1558 + //Console.WriteLine ("resolving to created {0} {1}", ret, tb);
1562 + if (ret == null) {
1563 + //Console.WriteLine ("looking name {0}", name);
1564 + IFaceEntry entry = mIncompleteIFaces [name] as IFaceEntry;
1565 + if (entry != null)
1566 + ret = entry.mTypeBuilder;
1569 + //try the cli_basetypes assembly
1570 + if (ret == null) {
1571 + ret = Type.GetType (name + ",cli_basetypes");
1574 + if (ret == null) {
1576 + // may call on type_resolve()
1577 + return Type.GetType (name, throwExc);
1578 + } catch (Exception e) {
1579 + //If the type is not found one may have forgotten to specify assemblies with
1580 + //additional types
1582 + throw new Exception ("\nThe type " + name + " \n could not be found. Did you forget to " +
1583 + "specify an additional assembly with the --reference option?\n", e);
1590 + public Type GetType (UnoXEnumTypeDescription xtd)
1592 + //Console.WriteLine ("emit enum {0} {1}", xtd.Name, xtd.Length);
1593 + string name = "unoidl." + xtd.Name;
1595 + Type ret = GetType (name, false /* no exc */);
1596 + if (ret == null) {
1597 +// Emit::EnumBuilder * enum_builder =
1598 +// m_module_builder->DefineEnum(
1600 +// (TypeAttributes) (TypeAttributes::Public |
1601 +// // TypeAttributes::Sealed |
1602 +// TypeAttributes::AnsiClass),
1603 +// __typeof (::System::Int32) );
1604 + // workaround enum builder bug
1605 + TypeBuilder enumBuilder =
1606 + mModuleBuilder.DefineType (name,
1607 + TypeAttributes.Public |
1608 + TypeAttributes.Sealed,
1609 + typeof (System.Enum));
1610 + enumBuilder.DefineField ("value__", typeof (System.Int32),
1611 + FieldAttributes.Public |
1612 + FieldAttributes.SpecialName |
1613 + FieldAttributes.RTSpecialName);
1615 + int length = xtd.Length;
1616 + for (int pos = 0; pos < length; pos ++) {
1617 +// enum_builder->DefineLiteral(
1618 +// ustring_to_String( enum_names[ enum_pos ] ),
1619 +// __box ((::System::Int32) enum_values[ enum_pos ]) );
1620 + FieldBuilder fieldBuilder =
1621 + enumBuilder.DefineField (xtd.ValueName (pos),
1623 + FieldAttributes.Public |
1624 + FieldAttributes.Static |
1625 + FieldAttributes.Literal);
1626 + fieldBuilder.SetConstant (xtd.Value (pos));
1629 + if (mConfig.mVerbose)
1630 + Console.WriteLine ("> emitting enum type {0}", name );
1632 + ret = enumBuilder.CreateType ();
1638 + public Type GetType (UnoXInterfaceTypeDescription xtd)
1640 + //Console.WriteLine ("get iface {0}", xtd.Name);
1642 + if (String.Compare (xtd.Name, "com.sun.star.uno.XInterface") == 0) {
1643 + return typeof (object);
1646 + string name = "unoidl." + xtd.Name;
1648 + Type ret = GetType (name, false /* no exc */);
1650 + if (ret == null) {
1651 + //Console.WriteLine ("creating name {0}", name);
1652 + TypeBuilder typeBuilder;
1654 + TypeAttributes attr = TypeAttributes.Public |
1655 + TypeAttributes.Interface |
1656 + TypeAttributes.Abstract |
1657 + TypeAttributes.AnsiClass;
1659 + int length = xtd.BaseTypes;
1661 + ArrayList ifaces = new ArrayList ();
1664 + for (i = 0; i < length; i ++) {
1665 + UnoXInterfaceTypeDescription baseType = xtd.BaseType (i);
1666 + if (String.Compare (baseType.Name, "com.sun.star.uno.XInterface") != 0)
1667 + ifaces.Add (baseType);
1669 + Type[] baseInterfaces = new Type [ifaces.Count];
1672 + foreach (UnoXInterfaceTypeDescription iface in ifaces) {
1673 + baseInterfaces[i] = GetType (iface);
1677 + typeBuilder = mModuleBuilder.DefineType (name, attr, null, baseInterfaces);
1679 + System.Console.WriteLine ("warning: IDL interface {0} is not derived from " +
1680 + "com.sun.star.uno.XInterface!", name);
1682 + typeBuilder = mModuleBuilder.DefineType (name, attr);
1685 + // insert to be completed
1686 + IFaceEntry entry = new IFaceEntry ();
1687 + entry.mType = xtd;
1688 + entry.mTypeBuilder = typeBuilder;
1689 + mIncompleteIFaces [name] = entry;
1691 + // type is incomplete
1692 + ret = typeBuilder;
1698 + string PolymorphicStructNameToStructName (string name)
1700 + if (!name.EndsWith (">"))
1703 + int index = name.IndexOf ('<');
1708 + return name.Substring (0, index);
1711 + Type TypeException ()
1713 + if (mTypeException == null) {
1714 + mTypeException = GetType ("unoidl.com.sun.star.uno.Exception", false);
1716 + if (mTypeException == null) {
1717 + // define hardcoded type unoidl.com.sun.star.uno.Exception
1718 + TypeBuilder typeBuilder = mModuleBuilder.DefineType ("unoidl.com.sun.star.uno.Exception",
1719 + TypeAttributes.Public |
1720 + TypeAttributes.BeforeFieldInit |
1721 + TypeAttributes.AnsiClass,
1722 + typeof (System.Exception));
1723 + FieldBuilder fieldContext = typeBuilder.DefineField ("Context", typeof (object),
1724 + FieldAttributes.Public);
1726 + typeBuilder.DefineDefaultConstructor (cCtorMethodAttr);
1728 + Type[] paramTypes = new Type [2];
1729 + paramTypes [0] = typeof (string);
1730 + paramTypes [1] = typeof (object);
1731 + ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr,
1732 + CallingConventions.Standard,
1734 + ctorBuilder.DefineParameter (1, ParameterAttributes.In, "Message");
1735 + ctorBuilder.DefineParameter (2, ParameterAttributes.In, "Context");
1736 + ILGenerator code = ctorBuilder.GetILGenerator ();
1737 + code.Emit (OpCodes.Ldarg_0);
1738 + code.Emit (OpCodes.Ldarg_1);
1739 + paramTypes = new Type [1];
1740 + paramTypes [0] = typeof (string);
1741 + code.Emit (OpCodes.Call, typeof (System.Exception).GetConstructor (paramTypes));
1742 + code.Emit( OpCodes.Ldarg_0 );
1743 + code.Emit( OpCodes.Ldarg_2 );
1744 + code.Emit( OpCodes.Stfld, fieldContext );
1745 + code.Emit( OpCodes.Ret );
1747 + if (mConfig.mVerbose)
1748 + Console.WriteLine ("> emitting exception type unoidl.com.sun.star.uno.Exception");
1750 + mTypeException = typeBuilder.CreateType ();
1754 + return mTypeException;
1757 + Type TypeRuntimeException ()
1759 + if (mTypeRuntimeException == null) {
1760 + mTypeRuntimeException = GetType ("unoidl.com.sun.star.uno.RuntimeException", false);
1761 + if (mTypeRuntimeException == null) {
1762 + // define hardcoded type unoidl.com.sun.star.uno.RuntimeException
1763 + Type typeException = TypeException ();
1764 + TypeBuilder typeBuilder = mModuleBuilder.DefineType ("unoidl.com.sun.star.uno.RuntimeException",
1765 + TypeAttributes.Public |
1766 + TypeAttributes.BeforeFieldInit |
1767 + TypeAttributes.AnsiClass,
1770 + typeBuilder.DefineDefaultConstructor (cCtorMethodAttr);
1772 + Type[] paramTypes = new Type [2];
1773 + paramTypes [0] = typeof (string);
1774 + paramTypes [1] = typeof (object);
1775 + ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr,
1776 + CallingConventions.Standard,
1778 + ctorBuilder.DefineParameter (1, ParameterAttributes.In, "Message");
1779 + ctorBuilder.DefineParameter (2, ParameterAttributes.In, "Context");
1780 + ILGenerator code = ctorBuilder.GetILGenerator ();
1781 + code.Emit (OpCodes.Ldarg_0);
1782 + code.Emit (OpCodes.Ldarg_1);
1783 + code.Emit (OpCodes.Ldarg_2 );
1784 + code.Emit (OpCodes.Call,
1785 + typeException.GetConstructor (paramTypes));
1786 + code.Emit (OpCodes.Ret);
1788 + if (mConfig.mVerbose)
1789 + Console.WriteLine ("> emitting exception type unoidl.com.sun.star.uno.RuntimeException");
1791 + mTypeRuntimeException = typeBuilder.CreateType ();
1795 + return mTypeRuntimeException;
1798 + public Type GetType (UnoXServiceTypeDescription xtd)
1800 + // Console.WriteLine ("get service {0}", xtd.Name);
1802 + if (!xtd.IsSingleInterfaceBased)
1805 + string name = "unoidl." + xtd.Name;
1807 + Type ret = GetType (name, false /* no exc */);
1812 + TypeAttributes attr =
1813 + TypeAttributes.Public |
1814 + TypeAttributes.Sealed |
1815 + TypeAttributes.BeforeFieldInit |
1816 + TypeAttributes.AnsiClass;
1818 + // insert to be completed
1819 + ServiceEntry entry = new ServiceEntry ();
1820 + entry.mType = xtd;
1821 + entry.mTypeBuilder = mModuleBuilder.DefineType (name, attr);
1822 + mIncompleteServices.Add (name, entry);
1824 + return entry.mTypeBuilder;
1827 + static void EmitLdarg (ILGenerator code, int index)
1831 + code.Emit( OpCodes.Ldarg_0 );
1834 + code.Emit( OpCodes.Ldarg_1 );
1837 + code.Emit( OpCodes.Ldarg_2 );
1840 + code.Emit( OpCodes.Ldarg_3 );
1843 + if (index < 0x100)
1844 + code.Emit (OpCodes.Ldarg_S, (byte) index);
1845 + else if (index < 0x8000)
1846 + code.Emit (OpCodes.Ldarg_S, (System.Int16) index);
1848 + code.Emit (OpCodes.Ldarg, index);
1853 + /** For example, there is a uno type
1854 + com.sun.star.Foo<char, long>.
1855 + The values in the type list
1856 + are uno types and are replaced by cli types, such as System.Char,
1857 + System.Int32, etc.
1859 + Strings can be as complicated as this
1860 + test.MyStruct<char,test.MyStruct<long, []string>>
1862 + string MapUnoPolymorphicName (string unoName)
1864 + int index = unoName.IndexOf('<');
1868 + System.Text.StringBuilder builder = new System.Text.StringBuilder (unoName.Substring (0, index + 1));
1870 + //Find the first occurrence of ','
1871 + //If the parameter is a polymorphic struct then we neede to ignore everything
1872 + //between the brackets because it can also contain commas
1873 + //get the type list within < and >
1874 + int endIndex = unoName.Length - 1;
1877 + int countParams = 0;
1878 + while (cur <= endIndex) {
1879 + char c = unoName [cur];
1881 + if (c == ',' || c == '>') {
1882 + //insert a comma if needed
1883 + if (countParams != 0)
1884 + builder.Append (",");
1886 + string param = unoName.Substring (index, cur - index);
1889 + //the the index to the beginning of the next param
1891 + builder.Append (MapUnoTypeName (param));
1892 + } else if (c == '<') {
1894 + //continue until the matching '>'
1895 + int numNested = 0;
1897 + char curChar = unoName [cur];
1898 + if (curChar == '<')
1900 + else if (curChar == '>') {
1901 + if (numNested > 0)
1911 + builder.Append ('>');
1912 + return builder.ToString();
1915 + string MapUnoTypeName (string typeName)
1917 + System.Text.StringBuilder buf= new System.Text.StringBuilder ();
1918 + string unoName = String.Copy (typeName);
1920 + //determine if the type is a sequence and its dimensions
1922 + if (typeName.StartsWith ("[")) {
1925 + if (typeName [index ++] == ']')
1927 + if (typeName [index ++] != '[')
1930 + unoName = unoName.Substring (index - 1);
1933 + if (unoName.Equals (Constants.UnoBool))
1934 + buf.Append (Constants.Boolean);
1935 + else if (unoName.Equals(Constants.UnoChar))
1936 + buf.Append (Constants.Char);
1937 + else if (unoName.Equals(Constants.UnoByte))
1938 + buf.Append (Constants.Byte);
1939 + else if (unoName.Equals(Constants.UnoShort))
1940 + buf.Append (Constants.Int16);
1941 + else if (unoName.Equals(Constants.UnoUShort))
1942 + buf.Append (Constants.UInt16);
1943 + else if (unoName.Equals(Constants.UnoLong))
1944 + buf.Append (Constants.Int32);
1945 + else if (unoName.Equals(Constants.UnoULong))
1946 + buf.Append (Constants.UInt32);
1947 + else if (unoName.Equals(Constants.UnoHyper))
1948 + buf.Append (Constants.Int64);
1949 + else if (unoName.Equals(Constants.UnoUHyper))
1950 + buf.Append (Constants.UInt64);
1951 + else if (unoName.Equals(Constants.UnoFloat))
1952 + buf.Append (Constants.Single);
1953 + else if (unoName.Equals(Constants.UnoDouble))
1954 + buf.Append (Constants.Double);
1955 + else if (unoName.Equals(Constants.UnoString))
1956 + buf.Append (Constants.String);
1957 + else if (unoName.Equals(Constants.UnoVoid))
1958 + buf.Append (Constants.Void);
1959 + else if (unoName.Equals(Constants.UnoType))
1960 + buf.Append (Constants.Type);
1961 + else if (unoName.Equals(Constants.UnoXInterface))
1962 + buf.Append (Constants.Object);
1963 + else if (unoName.Equals(Constants.UnoAny)) {
1964 + buf.Append (Constants.Any);
1966 + //put "unoidl." at the beginning
1967 + buf.Append (Constants.Unoidl);
1968 + buf.Append (MapUnoPolymorphicName (unoName));
1972 + for (;dims-- > 0;)
1973 + buf.Append (Constants.Brackets);
1975 + // Console.WriteLine ("MapUnoTypeName {0} => {1}", typeName, buf.ToString ());
1977 + return buf.ToString();
1980 + public Type GetType (UnoXCompoundTypeDescription xtd)
1982 + // Console.WriteLine ("get compound type {0}", xtd.Name);
1984 + if (xtd.TypeClass == UnoTypeClass.Exception) {
1985 + if (xtd.Name.Equals ("com.sun.star.uno.Exception"))
1986 + return TypeException ();
1988 + if (xtd.Name.Equals ("com.sun.star.uno.RuntimeException"))
1989 + return TypeRuntimeException ();
1992 + string name = "unoidl." + xtd.Name;
1994 + // if the struct is an instantiated polymorpic struct then we create the simple struct name
1996 + // void func ([in] PolyStruct<boolean> arg);
1997 + // PolyStruct<boolean> will be converted to PolyStruct
1998 + name = PolymorphicStructNameToStructName (name);
2000 + Type ret = GetType (name, false /* no exc */);
2001 + UnoXStructTypeDescription xsd = xtd as UnoXStructTypeDescription;
2003 + if (ret == null) {
2004 + // Console.WriteLine ("create compound type {0}", name);
2005 + UnoXTypeDescription baseTD = xtd.BaseType;
2006 + Type baseType = baseTD != null ? GetType (baseTD) : typeof (object);
2007 + CustomAttributeBuilder attrBuilder;
2008 + TypeBuilder typeBuilder = mModuleBuilder.DefineType (name,
2009 + TypeAttributes.Public |
2010 + TypeAttributes.BeforeFieldInit |
2011 + TypeAttributes.AnsiClass,
2015 + // Polymorphic struct, define uno.TypeParametersAttribute
2016 + // A polymorphic struct cannot have a basetype.
2017 + // When we create the template of the struct then we have no exact types
2018 + // and the name does not contain a parameter list
2019 + if (xsd != null && xsd.TypeParameters > 0) {
2020 + object[] args = new object [xsd.TypeParameters];
2022 + for (i = 0; i < xsd.TypeParameters; i ++)
2023 + args [i] = xsd.TypeParameter (i);
2024 + object[] aargs = { args };
2026 + Type[] typesCtor = { typeof (string[]) };
2027 + attrBuilder = new CustomAttributeBuilder (typeof (uno.TypeParametersAttribute).GetConstructor (typesCtor), aargs);
2028 + typeBuilder.SetCustomAttribute (attrBuilder);
2031 + // optional: lookup base type whether generated entry of this session
2032 + StructEntry baseTypeEntry = null;
2033 + if (baseType != null)
2034 + baseTypeEntry = (StructEntry) mGeneratedStructs [baseType.FullName];
2037 + for (i = 0; i < xtd.MemberTypes; i ++) {
2038 + if (xtd.MemberType (i) == null)
2039 + throw new Exception ("Missing type description . Check if you need to " +
2040 + "specify additional RDBs with the --extra option. Type missing for: " +
2041 + xtd.Name + "::" + xtd.MemberName (i));
2044 + // collect base types; wrong order
2045 + ArrayList baseTypes = new ArrayList (3);
2046 + int allMembersLength = 0;
2047 + for (Type baseTypePos = baseType; !baseTypePos.Equals (typeof (object)); baseTypePos = baseTypePos.BaseType) {
2048 + baseTypes.Add (baseTypePos);
2049 + if (baseTypePos.Equals (typeof (System.Exception))) {
2050 + // special Message member
2051 + allMembersLength ++;
2052 + break; // don't include System.Exception base classes
2054 + allMembersLength += baseTypePos.GetFields (BindingFlags.Instance |
2055 + BindingFlags.Public |
2056 + BindingFlags.DeclaredOnly).Length;
2060 + // create all_members arrays; right order
2061 + string[] allMemberNames = new string [allMembersLength + xtd.MemberTypes];
2062 + Type[] allParamTypes = new Type [allMembersLength + xtd.MemberTypes];
2063 + int memberPos = 0;
2064 + for (i = baseTypes.Count - 1; i >= 0; i--) {
2065 + Type type = baseTypes [i] as Type;
2067 + if (type.Equals (typeof (System.Exception))) {
2068 + allMemberNames [memberPos] = "Message";
2069 + allParamTypes [memberPos] = typeof (string);
2072 + StructEntry baseEntry = mGeneratedStructs [type.FullName] as StructEntry;
2073 + if (baseEntry == null) {
2075 + FieldInfo[] fields = type.GetFields (BindingFlags.Instance |
2076 + BindingFlags.Public |
2077 + BindingFlags.DeclaredOnly);
2078 + foreach (FieldInfo fieldInfo in fields) {
2079 + allMemberNames [memberPos] = fieldInfo.Name;
2080 + allParamTypes [memberPos] = fieldInfo.FieldType;
2084 + // generated during this session:
2085 + // members may be incomplete ifaces
2087 + for (j = 0; j < baseEntry.mParamTypes.Length; j ++) {
2088 + allMemberNames [memberPos] = baseEntry.mMemberNames [j];
2089 + allParamTypes [memberPos] = baseEntry.mParamTypes [j];
2095 + if (allMembersLength != memberPos)
2096 + throw new Exception ("something went wrong, allMembersLength != memberPos");
2100 + StructEntry entry = new StructEntry ();
2101 + entry.mMemberNames = new string [xtd.MemberTypes];
2102 + entry.mParamTypes = new Type [xtd.MemberTypes];
2105 + FieldBuilder[] members = new FieldBuilder [xtd.MemberTypes];
2106 + int curParamIndex = 0;
2107 + int typeParamPos = 0;
2109 + for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) {
2110 + string fieldName = xtd.MemberName (memberPos);
2113 + //Special handling of struct parameter types
2114 + bool parameterizedType = false;
2115 + if (xtd.MemberType (memberPos).TypeClass == UnoTypeClass.Unknown) {
2116 + parameterizedType = true;
2117 + if (xsd != null && typeParamPos < xsd.TypeParameters) {
2118 + fieldType = typeof (object);
2121 + throw new Exception ("unexpected member type in " + xtd.Name);
2124 + fieldType = GetType (xtd.MemberType (memberPos));
2126 + members [memberPos] = typeBuilder.DefineField (fieldName, fieldType, FieldAttributes.Public);
2128 + //parameterized type (polymorphic struct) ?
2129 + if (parameterizedType && xsd != null) {
2130 + object[] args = { xsd.TypeParameter (curParamIndex ++) };
2131 + Type[] ctorTypes = { typeof (string) };
2132 + attrBuilder = new CustomAttributeBuilder (typeof (uno.ParameterizedTypeAttribute).GetConstructor (ctorTypes), args);
2133 + members [memberPos].SetCustomAttribute (attrBuilder);
2136 + // add to all_members
2137 + allMemberNames [allMembersLength + memberPos] = fieldName;
2138 + allParamTypes [allMembersLength + memberPos] = fieldType;
2141 + entry.mMemberNames [memberPos] = fieldName;
2142 + entry.mParamTypes [memberPos] = fieldType;
2145 + allMembersLength += xtd.MemberTypes;
2148 + ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr, CallingConventions.Standard, new Type [0]);
2149 + ILGenerator code = ctorBuilder.GetILGenerator ();
2151 + code.Emit (OpCodes.Ldarg_0);
2152 + // Console.WriteLine ("baseType: {0}", baseType);
2153 + code.Emit (OpCodes.Call, baseTypeEntry == null ? baseType.GetConstructor (new Type [0]) : baseTypeEntry.mDefaultConstructor);
2155 + // default initialize members
2156 + for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) {
2157 + FieldInfo fieldInfo = members [memberPos];
2159 + // default initialize
2160 + // string, type, enum, sequence, struct, exception, any
2161 + if (fieldInfo.FieldType.Equals (typeof (string))) {
2162 + code.Emit (OpCodes.Ldarg_0);
2163 + code.Emit (OpCodes.Ldstr, "");
2164 + code.Emit (OpCodes.Stfld, fieldInfo);
2165 + } else if (fieldInfo.FieldType.Equals (typeof (Type))) {
2166 + code.Emit (OpCodes.Ldarg_0);
2167 + code.Emit (OpCodes.Ldtoken, typeof (void));
2168 + code.Emit (OpCodes.Call, mMethodInfoTypeGetTypeFromHandle);
2169 + code.Emit (OpCodes.Stfld, fieldInfo);
2170 + } else if (fieldInfo.FieldType.IsArray) {
2171 + code.Emit (OpCodes.Ldarg_0);
2172 + code.Emit (OpCodes.Ldc_I4_0);
2173 + code.Emit (OpCodes.Newarr, fieldInfo.FieldType.GetElementType ());
2174 + code.Emit (OpCodes.Stfld, fieldInfo);
2175 + } else if (fieldInfo.FieldType.IsValueType) {
2176 + if (fieldInfo.FieldType.FullName.Equals ("uno.Any")) {
2177 + code.Emit (OpCodes.Ldarg_0);
2178 + code.Emit (OpCodes.Ldsfld, typeof (uno.Any).GetField ("VOID"));
2179 + code.Emit (OpCodes.Stfld, fieldInfo);
2181 + } else if (fieldInfo.FieldType.IsClass) {
2182 + // may be XInterface
2183 + if (!fieldInfo.FieldType.Equals (typeof (object))) {
2184 + code.Emit (OpCodes.Ldarg_0);
2185 + code.Emit (OpCodes.Newobj, fieldInfo.FieldType.GetConstructor (new Type [0]));
2186 + code.Emit (OpCodes.Stfld, fieldInfo);
2191 + code.Emit (OpCodes.Ret);
2192 + entry.mDefaultConstructor = ctorBuilder;
2194 + // parameterized .ctor including all base members
2195 + ctorBuilder = typeBuilder.DefineConstructor (cCtorMethodAttr, CallingConventions.Standard, allParamTypes);
2196 + for (memberPos = 0; memberPos < allMembersLength; memberPos ++)
2197 + ctorBuilder.DefineParameter (memberPos + 1, ParameterAttributes.In, allMemberNames [memberPos]);
2199 + code = ctorBuilder.GetILGenerator ();
2200 + // call base .ctor
2201 + code.Emit (OpCodes.Ldarg_0); // push this
2202 + int baseMembersLength = allMembersLength - xtd.MemberTypes;
2203 + Type[] paramTypes = new Type [baseMembersLength];
2205 + for (memberPos = 0; memberPos < baseMembersLength; memberPos ++) {
2206 + EmitLdarg (code, memberPos + 1);
2207 + paramTypes [memberPos] = allParamTypes [memberPos];
2210 + code.Emit (OpCodes.Call, baseTypeEntry == null ? baseType.GetConstructor (paramTypes) : baseTypeEntry.mConstructor);
2212 + // initialize members
2214 + for (memberPos = 0; memberPos < xtd.MemberTypes; memberPos ++) {
2215 + code.Emit (OpCodes.Ldarg_0); // push this
2216 + EmitLdarg (code, memberPos + baseMembersLength + 1);
2217 + code.Emit (OpCodes.Stfld, members [memberPos]);
2220 + code.Emit (OpCodes.Ret);
2221 + entry.mConstructor = ctorBuilder;
2223 + if (mConfig.mVerbose)
2224 + Console.WriteLine ("> emitting {0} type {1}", xtd is UnoXStructTypeDescription ? "struct" : "exception", name);
2227 + mGeneratedStructs.Add (name, entry);
2228 + //Console.WriteLine ("added entry to mGeneratedStructs: {0}", name);
2229 + //if (baseTD != null)
2230 + //Console.WriteLine ("baseTD: {0}", baseTD.Name, GetType (baseTD).Name);
2231 + ret = typeBuilder.CreateType ();
2234 + // In case of an instantiated polymorphic struct we want to return a
2235 + // uno.PolymorphicType (inherits Type) rather then Type.
2236 + if (xsd != null && xsd.TypeArguments > 0) {
2237 + //Console.WriteLine ("polymorphic struct: call uno.PolymorphicType.GetType ({0}, {1})", ret, xtd.Name);
2238 + ret = uno.PolymorphicType.GetType (ret, MapUnoTypeName (xtd.Name));
2239 + //Console.WriteLine ("polymorphic struct: {0} ({1})", ret, xtd.Name);
2245 + public Type GetType (UnoXConstantTypeDescription xtd)
2247 + //Console.WriteLine ("get constant type {0}", xtd.Name);
2249 + string name = "unoidl." + xtd.Name;
2251 + Type ret = GetType (name, false /* no exc */);
2253 + if (ret == null) {
2254 + object constant = xtd.ConstantValue;
2256 + TypeBuilder typeBuilder = mModuleBuilder.DefineType (name,
2257 + TypeAttributes.Public |
2258 + TypeAttributes.Sealed |
2259 + TypeAttributes.BeforeFieldInit |
2260 + TypeAttributes.AnsiClass);
2261 + FieldBuilder field = typeBuilder.DefineField (name.Substring (name.LastIndexOf ('.') + 1),
2262 + constant.GetType (),
2263 + FieldAttributes.Public |
2264 + FieldAttributes.Static |
2265 + FieldAttributes.Literal);
2266 + field.SetConstant (constant);
2268 + if (mConfig.mVerbose)
2269 + Console.WriteLine ("> emitting constant type {0}", name);
2271 + ret = typeBuilder.CreateType ();
2277 + public Type GetType (UnoXConstantsTypeDescription xtd)
2279 + //Console.WriteLine ("get constants type {0}", xtd.Name);
2281 + string name = "unoidl." + xtd.Name;
2283 + Type ret = GetType (name, false /* no exc */);
2285 + if (ret == null) {
2286 + TypeBuilder typeBuilder = mModuleBuilder.DefineType (name,
2287 + TypeAttributes.Public |
2288 + TypeAttributes.Sealed |
2289 + TypeAttributes.BeforeFieldInit |
2290 + TypeAttributes.AnsiClass);
2292 + for (i = 0; i < xtd.Constants; i ++) {
2293 + UnoXConstantTypeDescription constantTD = xtd.Constant (i);
2294 + object constant = constantTD.ConstantValue;
2295 + FieldBuilder field = typeBuilder.DefineField (constantTD.Name.Substring (constantTD.Name.LastIndexOf ('.') + 1),
2296 + constant.GetType (),
2297 + FieldAttributes.Public |
2298 + FieldAttributes.Static |
2299 + FieldAttributes.Literal);
2300 + field.SetConstant (constant);
2303 + if (mConfig.mVerbose)
2304 + Console.WriteLine ( "> emitting constants group type {0}", name);
2306 + ret = typeBuilder.CreateType ();
2312 + public Type GetType (UnoXSingletonTypeDescription xtd)
2314 + //Console.WriteLine ("get singleton {0}", xtd.Name);
2316 + if (!xtd.IsInterfaceBased)
2319 + //Console.WriteLine ("singleton {0} is interface based", xtd.Name);
2321 + string name = "unoidl." + xtd.Name;
2323 + Type ret = GetType (name, false /* no exc */);
2328 + TypeAttributes attr =
2329 + TypeAttributes.Public |
2330 + TypeAttributes.Sealed |
2331 + TypeAttributes.BeforeFieldInit |
2332 + TypeAttributes.AnsiClass;
2334 + // insert to be completed
2335 + SingletonEntry entry = new SingletonEntry ();
2336 + entry.mType = xtd;
2337 + entry.mTypeBuilder = mModuleBuilder.DefineType (name, attr);
2338 + mIncompleteSingletons.Add (name, entry);
2340 + return entry.mTypeBuilder;
2343 + public Type GetType (UnoXTypeDescription xtd)
2345 + UnoTypeClass tc = xtd.TypeClass;
2348 + case UnoTypeClass.Void:
2349 + return typeof (void);
2350 + case UnoTypeClass.Char:
2351 + return typeof (char);
2352 + case UnoTypeClass.Boolean:
2353 + return typeof (bool);
2354 + case UnoTypeClass.Byte:
2355 + return typeof (byte);
2356 + case UnoTypeClass.Short:
2357 + return typeof (Int16);
2358 + case UnoTypeClass.UnsignedShort:
2359 + return typeof (UInt16);
2360 + case UnoTypeClass.Long:
2361 + return typeof (Int32);
2362 + case UnoTypeClass.UnsignedLong:
2363 + return typeof (UInt32);
2364 + case UnoTypeClass.Hyper:
2365 + return typeof (Int64);
2366 + case UnoTypeClass.UnsignedHyper:
2367 + return typeof (UInt64);
2368 + case UnoTypeClass.Float:
2369 + return typeof (Single);
2370 + case UnoTypeClass.Double:
2371 + return typeof (double);
2372 + case UnoTypeClass.String:
2373 + return typeof (string);
2374 + case UnoTypeClass.Type:
2375 + return typeof (Type);
2376 + case UnoTypeClass.Any:
2377 + return typeof (uno.Any);
2378 + case UnoTypeClass.Enum:
2379 + return GetType (xtd as UnoXEnumTypeDescription);
2380 + case UnoTypeClass.Interface:
2381 + return GetType (xtd as UnoXInterfaceTypeDescription);
2382 + case UnoTypeClass.Struct:
2383 + case UnoTypeClass.Exception:
2384 + return GetType (xtd as UnoXCompoundTypeDescription);
2385 + case UnoTypeClass.Module:
2387 + case UnoTypeClass.Sequence:
2388 + Type elementType = GetType ((xtd as UnoXIndirectTypeDescription).ReferencedType);
2389 + Type retType = GetType (elementType.FullName + "[]", true);
2390 + uno.PolymorphicType polyType = elementType as uno.PolymorphicType;
2391 + if (polyType != null) {
2392 + string name = polyType.PolymorphicName + "[]";
2393 + retType = uno.PolymorphicType.GetType (retType, name);
2396 + case UnoTypeClass.Typedef:
2397 + return GetType ((xtd as UnoXIndirectTypeDescription).ReferencedType);
2398 + case UnoTypeClass.Constant:
2399 + return GetType (xtd as UnoXConstantTypeDescription);
2400 + case UnoTypeClass.Constants:
2401 + return GetType (xtd as UnoXConstantsTypeDescription);
2402 + case UnoTypeClass.Service:
2403 + return GetType (xtd as UnoXServiceTypeDescription);
2404 + case UnoTypeClass.Singleton:
2405 + return GetType (xtd as UnoXSingletonTypeDescription);
2407 + // fixme, use double for unfinished types
2408 + //Console.WriteLine ("warning: unfinished type reached: {0}", xtd.Name);
2409 + return typeof (void);
2412 + //throw new Exception (String.Format ("Unknown type requested {0}", tc));
2415 + CustomAttributeBuilder IFaceMethodExceptionAttribute (UnoXInterfaceMethodTypeDescription method)
2417 + Type[] exceptionTypes = new Type [method.ExceptionTypes];
2420 + for (i = 0; i < method.ExceptionTypes; i ++) {
2421 + exceptionTypes [i] = GetType (method.ExceptionType (i));
2424 + return ExceptionAttribute (exceptionTypes);
2427 + CustomAttributeBuilder ExceptionAttribute (Type[] exceptionTypes)
2429 + CustomAttributeBuilder attrBuilder = null;
2431 + if (exceptionTypes.Length > 0) {
2432 + object[] args = { exceptionTypes };
2433 + Type[] arTypesCtor = { typeof (Type[]) };
2434 + ConstructorInfo ctorInfo = typeof (uno.ExceptionAttribute).GetConstructor (arTypesCtor);
2435 + attrBuilder = new CustomAttributeBuilder (ctorInfo, args);
2438 + return attrBuilder;
2441 + Type[] GetTypes (UnoXTypeDescription[] tds)
2443 + Type[] types = new Type [tds.Length];
2446 + for (i = 0; i < tds.Length; i ++)
2447 + types [i] = GetType (tds [i]);
2452 + Type CompleteIFaceType (IFaceEntry entry)
2454 + //Console.WriteLine ("going to complete {0}", entry.mTypeBuilder.FullName);
2456 + // complete base interfaces first
2457 + foreach (Type type in entry.mTypeBuilder.GetInterfaces ()) {
2458 + IFaceEntry baseEntry = mIncompleteIFaces [type.FullName] as IFaceEntry;
2459 + if (baseEntry != null)
2460 + CompleteIFaceType (baseEntry);
2464 + const MethodAttributes methodAttr =
2465 + MethodAttributes.Public |
2466 + MethodAttributes.Abstract |
2467 + MethodAttributes.Virtual |
2468 + MethodAttributes.NewSlot |
2469 + MethodAttributes.HideBySig;
2472 + for (i = 0; i < entry.mType.Members; i ++) {
2473 + UnoXInterfaceMemberTypeDescription member = entry.mType.Member (i);
2474 + MethodBuilder methodBuilder;
2475 + CustomAttributeBuilder attrBuilder;
2477 + if (member.TypeClass == UnoTypeClass.InterfaceMethod) {
2478 + UnoXInterfaceMethodTypeDescription method = new UnoXInterfaceMethodTypeDescription (member.Handle);
2479 + UnoXMethodParameter[] parameters = new UnoXMethodParameter [method.Parameters];
2480 + Type[] pTypes = new Type [method.Parameters];
2483 + //Console.WriteLine ("method {0}.{1}", entry.mTypeBuilder.FullName, method.MemberName);
2485 + // first determine all types
2486 + for (j = 0; j < method.Parameters; j ++) {
2487 + parameters [j] = method.Parameter (j);
2488 + pTypes [j] = GetType (parameters [j].Type);
2489 + if (parameters [j].IsOut)
2490 + pTypes [j] = GetType (pTypes [j].FullName + "&", true);
2494 + methodBuilder = entry.mTypeBuilder.DefineMethod (method.MemberName,
2496 + GetType (method.ReturnType),
2499 + // then define parameter infos
2500 + for (j = 0; j < method.Parameters; j ++) {
2501 + ParameterAttributes attr = 0;
2502 + if (parameters [j].IsIn)
2503 + attr |= ParameterAttributes.In;
2504 + if (parameters [j].IsOut)
2505 + attr |= ParameterAttributes.Out;
2508 + throw new Exception ("wrong parameter attributes");
2510 + methodBuilder.DefineParameter (parameters [j].Position + 1,
2512 + parameters [j].Name);
2515 + if (method.ReturnsStruct) {
2516 + //Console.WriteLine ("returns struct");
2518 + UnoXStructTypeDescription std = method.ReturnType as UnoXStructTypeDescription;
2519 + Type[] ats = new Type [std.TypeArguments];
2521 + //Console.WriteLine ("type arguments: {0}", std.TypeArguments);
2523 + for (j = 0; j < std.TypeArguments; j ++) {
2524 + ats [j] = GetType (std.TypeArgument (j));
2525 + //Console.WriteLine ("ats [{0}] = {1}", j, ats [j]);
2528 + object[] atso = { ats };
2529 + Type[] ctor = { typeof (Type[]) };
2530 + attrBuilder = new CustomAttributeBuilder (typeof (uno.TypeArgumentsAttribute).GetConstructor (ctor),
2532 + methodBuilder.SetCustomAttribute (attrBuilder);
2535 + // define UNO exception attribute (exceptions) --------------------------------------
2536 + attrBuilder = IFaceMethodExceptionAttribute (method);
2537 + if (attrBuilder != null)
2538 + methodBuilder.SetCustomAttribute (attrBuilder);
2540 + // oneway attribute
2541 + if (method.IsOneway) {
2542 + Type[] arCtorOneway = new Type [0];
2543 + object[] arArgs = new object [0];
2544 + attrBuilder = new CustomAttributeBuilder (typeof (uno.OnewayAttribute).GetConstructor (arCtorOneway),
2546 + methodBuilder.SetCustomAttribute (attrBuilder);
2550 + if (member.TypeClass != UnoTypeClass.InterfaceAttribute)
2551 + throw new Exception (String.Format ("Unknown member type class: {0} ", member.TypeClass));
2553 + UnoXInterfaceAttributeTypeDescription attribute = new UnoXInterfaceAttributeTypeDescription (member.Handle);
2554 + const MethodAttributes propMethodAttr = methodAttr | MethodAttributes.SpecialName;
2556 + Type attrType = GetType (attribute.Type);
2557 + //Console.WriteLine ("attribute {2} type: {0} => {1}", attribute.Type, attrType, attribute.Name);
2558 + Type[] parameters = new Type [0];
2560 + PropertyBuilder propBuilder = entry.mTypeBuilder.DefineProperty (attribute.MemberName, PropertyAttributes.None, attrType, parameters);
2562 + //set BoundAttribute, if necessary
2563 + if (attribute.IsBound) {
2564 + ConstructorInfo ctorBoundAttr = typeof (uno.BoundAttribute).GetConstructor (new Type [0]);
2565 + attrBuilder = new CustomAttributeBuilder (ctorBoundAttr, new object [0]);
2566 + propBuilder.SetCustomAttribute (attrBuilder);
2570 + methodBuilder = entry.mTypeBuilder.DefineMethod ("get_" + attribute.MemberName,
2571 + propMethodAttr, attrType, parameters);
2573 + attrBuilder = ExceptionAttribute (GetTypes (attribute.GetExceptionTypes));
2574 + if (attrBuilder != null)
2575 + methodBuilder.SetCustomAttribute (attrBuilder);
2577 + propBuilder.SetGetMethod (methodBuilder);
2579 + if (!attribute.IsReadOnly) {
2581 + parameters = new Type [1];
2582 + parameters [0] = attrType;
2583 + //parameters [0] = null;
2584 + //Console.WriteLine ("setter parameters: {0} ({1})", parameters, parameters [0]);
2585 + methodBuilder = entry.mTypeBuilder.DefineMethod ("set_" + attribute.MemberName,
2586 + propMethodAttr, typeof (void), parameters);
2587 + methodBuilder.DefineParameter (1, ParameterAttributes.In, "value");
2589 + attrBuilder = ExceptionAttribute (GetTypes (attribute.SetExceptionTypes));
2590 + if (attrBuilder != null)
2591 + methodBuilder.SetCustomAttribute (attrBuilder);
2593 + propBuilder.SetSetMethod (methodBuilder);
2597 + // cmm_x_interface_type_description_members_release (membersHandle);
2599 + if (mConfig.mVerbose)
2600 + Console.WriteLine ("> emitting interface type {0}", "unoidl." + entry.mType.Name);
2602 + mIncompleteIFaces.Remove (entry.mTypeBuilder.FullName);
2604 + //Console.WriteLine ("completed {0}", entry.mTypeBuilder.FullName);
2606 + return entry.mTypeBuilder.CreateType ();
2609 + UnoXInterfaceTypeDescription ResolveInterfaceTypedef (UnoXTypeDescription xtd)
2611 + UnoXInterfaceTypeDescription xtdIface = xtd as UnoXInterfaceTypeDescription;
2613 + if (xtdIface != null)
2616 + UnoXIndirectTypeDescription xtdIndirect = xtd as UnoXIndirectTypeDescription;
2618 + if (xtdIndirect != null)
2619 + return ResolveInterfaceTypedef (xtdIndirect.ReferencedType);;
2621 + throw new Exception ("resolveInterfaceTypedef was called with an invalid argument");
2624 + ArrayList GetServiceConstructorMethodExceptionsReduced (UnoXTypeDescription[] exceptionTypes)
2626 + if (exceptionTypes.Length == 0)
2627 + return new ArrayList ();
2629 + ArrayList types = new ArrayList();
2632 + for (i = 0; i < exceptionTypes.Length; i ++)
2633 + types.Add (GetType ("unoidl." + exceptionTypes [i].Name, true));
2637 + bool bRemove = false;
2639 + for (i = start; i < types.Count; i ++) {
2640 + Type t = types [i] as Type;
2643 + for (j = 0; j < types.Count; j ++) {
2644 + if (t.IsSubclassOf (types [j] as Type)) {
2645 + types.RemoveAt (i);
2655 + if (bRemove == false)
2662 + Type CompleteServiceType (ServiceEntry entry)
2664 + // Create the private default constructor
2665 + ConstructorBuilder ctorBuilder = entry.mTypeBuilder.DefineConstructor (MethodAttributes.Private |
2666 + MethodAttributes.HideBySig |
2667 + MethodAttributes.SpecialName |
2668 + MethodAttributes.RTSpecialName,
2669 + CallingConventions.Standard,
2672 + ILGenerator ilGen = ctorBuilder.GetILGenerator ();
2673 + ilGen.Emit (OpCodes.Ldarg_0); // push this
2674 + ilGen.Emit (OpCodes.Call, entry.mTypeBuilder.BaseType.GetConstructor (new Type[0]));
2675 + ilGen.Emit (OpCodes.Ret);
2677 + // Create the service constructors.
2678 + // obtain the interface which makes up this service, it is the return
2679 + // type of the constructor functions
2680 + UnoXInterfaceTypeDescription iface = entry.mType.Interface as UnoXInterfaceTypeDescription;
2682 + if (iface == null)
2683 + iface = ResolveInterfaceTypedef (entry.mType.Interface);
2685 + Type ret = GetType (iface);
2687 + // Create the ConstructorInfo for a DeploymentException
2688 + Type typeDeploymentException = GetType ("unoidl.com.sun.star.uno.DeploymentException", true);
2689 + Type[] arTypeCtor = { typeof (string), typeof (object) };
2690 + ConstructorInfo ctorDeploymentException = typeDeploymentException.GetConstructor (arTypeCtor);
2692 + Type typeUnoException = GetType ("unoidl.com.sun.star.uno.Exception", true);
2695 + for (i = entry.mType.Constructors - 1; i >= 0; i --) {
2696 + bool bParameterArray = false;
2697 + UnoXServiceConstructorDescription ctorDesc = entry.mType.Constructor (i);
2698 + Type[] typeParameters = new Type [ctorDesc.Parameters + 1];
2699 + typeParameters [0] = GetType ("unoidl.com.sun.star.uno.XComponentContext", true);
2701 + for (j = 0; j < ctorDesc.Parameters; j ++) {
2702 + UnoXParameter parameter = ctorDesc.Parameter (j);
2704 + if (parameter.IsRest)
2705 + typeParameters [j + 1] = typeof (uno.Any[]);
2707 + typeParameters [j + 1] = GetType (parameter.Type);
2710 + // The array typeParameters can contain:
2711 + // System.Type and uno.PolymorphicType.
2712 + // Passing PolymorphicType to MethodBuilder.DefineMethod will cause a problem.
2713 + // The exception will read something like no on information for parameter # d
2714 + // Maybe we need no override another Type method in PolymorphicType ...
2715 + // Until we have figured this out, we will create another array of System.Type which
2716 + // we pass on to DefineMethod.
2718 + Type[] paramTypes = new Type [ctorDesc.Parameters + 1];
2720 + for (j = 0; j < ctorDesc.Parameters + 1; j ++) {
2721 + if (typeParameters [j] is uno.PolymorphicType)
2722 + paramTypes [j] = (typeParameters [j] as uno.PolymorphicType).OriginalType;
2724 + paramTypes [j] = typeParameters [j];
2729 + if (ctorDesc.IsDefault)
2730 + ctorName = "create";
2732 + ctorName = ctorDesc.Name;
2734 + MethodBuilder methodBuilder = entry.mTypeBuilder.DefineMethod (ctorName,
2735 + MethodAttributes.Public |
2736 + MethodAttributes.HideBySig |
2737 + MethodAttributes.Static,
2741 + //define UNO exception attribute (exceptions)--------------------------------------
2742 + CustomAttributeBuilder attrBuilder = ExceptionAttribute (GetTypes (ctorDesc.ExceptionTypes));
2743 + if (attrBuilder != null)
2744 + methodBuilder.SetCustomAttribute (attrBuilder);
2746 + // define parameter attributes (paramarray), names etc.
2747 + // The first parameter is the XComponentContext, which cannot be obtained
2748 + // from reflection.
2749 + // The context is not part of the idl description
2751 + methodBuilder.DefineParameter (1, ParameterAttributes.In, "the_context");
2753 + ParameterBuilder[] parameterBuilder = new ParameterBuilder [ctorDesc.Parameters];
2756 + for (iparam = 0; iparam < ctorDesc.Parameters; iparam ++) {
2757 + UnoXParameter parameter = ctorDesc.Parameter (iparam);
2759 + parameterBuilder [iparam] = methodBuilder.DefineParameter (iparam + 2, ParameterAttributes.In, parameter.Name);
2761 + if (parameter.IsRest) {
2762 + bParameterArray = true;
2763 + //set the ParameterArrayAttribute
2764 + ConstructorInfo ctorInfo = typeof (System.ParamArrayAttribute).GetConstructor (new Type [0]);
2765 + attrBuilder = new CustomAttributeBuilder (ctorInfo, new object [0]);
2767 + parameterBuilder[iparam].SetCustomAttribute (attrBuilder);
2772 + ilGen = methodBuilder.GetILGenerator ();
2774 + // Define locals ---------------------------------
2775 + // XMultiComponentFactory
2776 + LocalBuilder localFactory = ilGen.DeclareLocal (GetType ("unoidl.com.sun.star.lang.XMultiComponentFactory", true));
2778 + // The return type
2779 + LocalBuilder localReturnVal = ilGen.DeclareLocal (ret);
2781 + // Obtain the XMultiComponentFactory and throw an exception if we do not get one
2782 + ilGen.Emit (OpCodes.Ldarg_0);
2784 + MethodInfo methodGetServiceManager = GetType ("unoidl.com.sun.star.uno.XComponentContext", true).GetMethod ("getServiceManager");
2785 + ilGen.Emit (OpCodes.Callvirt, methodGetServiceManager);
2786 + ilGen.Emit (OpCodes.Stloc, localFactory);
2787 + ilGen.Emit (OpCodes.Ldloc, localFactory);
2788 + Label label1 = ilGen.DefineLabel ();
2789 + ilGen.Emit (OpCodes.Brtrue, label1);
2791 + // The string for the exception
2792 + System.Text.StringBuilder strBuilder = new System.Text.StringBuilder (256);
2794 + strBuilder.Append ("The service ");
2795 + strBuilder.Append ("unoidl." + entry.mType.Name);
2796 + strBuilder.Append (" could not be created. The context failed to supply the service manager.");
2798 + ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString ());
2799 + ilGen.Emit (OpCodes.Ldarg_0);
2800 + ilGen.Emit (OpCodes.Newobj, ctorDeploymentException);
2801 + ilGen.Emit (OpCodes.Throw);
2802 + ilGen.MarkLabel (label1);
2804 + // We create a try/ catch around the createInstanceWithContext, etc. functions
2805 + // There are 3 cases
2806 + // 1. function do not specify exceptions. Then RuntimeExceptions are retrhown and other
2807 + // exceptions produce a DeploymentException.
2808 + // 2. function specify Exception. Then all exceptions fly through
2809 + // 3. function specifies exceptions but no Exception. Then these are rethrown
2810 + // and other exceptions, except RuntimeException, produce a deployment exception.
2811 + // In case there are no parameters we call
2812 + // XMultiComponentFactory.createInstanceWithContext
2814 + ArrayList exceptionTypes = GetServiceConstructorMethodExceptionsReduced (ctorDesc.ExceptionTypes);
2815 + if (!exceptionTypes.Contains (typeUnoException)) {
2816 + ilGen.BeginExceptionBlock ();
2819 + if (ctorDesc.Parameters == 0) {
2820 + ilGen.Emit (OpCodes.Ldloc, localFactory);
2821 + ilGen.Emit (OpCodes.Ldstr, entry.mType.Name);
2822 + ilGen.Emit (OpCodes.Ldarg_0);
2824 + MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithContext");
2825 + ilGen.Emit (OpCodes.Callvirt, methodCreate);
2826 + } else if(bParameterArray) {
2827 + //Service constructor with parameter array
2828 + ilGen.Emit (OpCodes.Ldloc, localFactory);
2829 + ilGen.Emit (OpCodes.Ldstr, entry.mType.Name);
2830 + ilGen.Emit (OpCodes.Ldarg_1);
2831 + ilGen.Emit (OpCodes.Ldarg_0);
2832 + MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithArgumentsAndContext");
2833 + ilGen.Emit(OpCodes.Callvirt, methodCreate);
2835 + // Any param1, Any param2, etc.
2836 + // For each parameter,except the component context, and parameter array
2837 + // and Any is created.
2838 + LocalBuilder[] localAny = new LocalBuilder [ctorDesc.Parameters];
2840 + for (iparam = 0; iparam < ctorDesc.Parameters; iparam ++) {
2841 + localAny [iparam] = ilGen.DeclareLocal (typeof (uno.Any));
2844 + // Any[]. This array is filled with the created Anys which contain the parameters
2845 + // and the values contained in the parameter array
2846 + LocalBuilder localAnyParams = ilGen.DeclareLocal (typeof (uno.Any []));
2848 + // Create the Any for every argument, except for the parameter array
2849 + // arLocalAny contains the LocalBuilder for all these parameters.
2850 + // we call the ctor Any(Type, Object)
2851 + // If the parameter is an Any then the Any is created with Any(param.Type, param.Value);
2852 + Type[] typesCtorAny = { typeof (Type),
2853 + typeof (object) };
2854 + ConstructorInfo ctorAny = typeof (uno.Any).GetConstructor (typesCtorAny);
2855 + MethodInfo methodAnyGetType = typeof (uno.Any).GetProperty ("Type").GetGetMethod ();
2856 + MethodInfo methodAnyGetValue = typeof (uno.Any).GetProperty ("Value").GetGetMethod ();
2858 + for (j = 0; j < localAny.Length; j ++) {
2859 + //check if the parameter is a polymorphic struct
2860 + if (typeParameters [j + 1] is uno.PolymorphicType) {
2861 + // It is a polymorphic struct
2862 + uno.PolymorphicType polyType = typeParameters [j + 1] as uno.PolymorphicType;
2864 + // Load the uninitialized local Any on which we will call the ctor
2865 + ilGen.Emit (OpCodes.Ldloca, localAny [j]);
2867 + // Call PolymorphicType PolymorphicType::GetType(Type t, String polyName)
2868 + // Prepare the first parameter
2869 + ilGen.Emit (OpCodes.Ldtoken, polyType.OriginalType);
2870 + Type[] typeParams = { typeof (System.RuntimeTypeHandle) };
2871 + ilGen.Emit (OpCodes.Call, typeof(Type).GetMethod ("GetTypeFromHandle", typeParams));
2873 + // Prepare the second parameter
2874 + ilGen.Emit (OpCodes.Ldstr, polyType.PolymorphicName);
2876 + // Make the actual call
2877 + Type[] typeParamGetType = { typeof (Type), typeof (string) };
2878 + ilGen.Emit (OpCodes.Call,
2879 + typeof (uno.PolymorphicType).GetMethod("GetType",
2880 + typeParamGetType));
2882 + // Stack is: localAny, PolymorphicType
2883 + // Call Any::Any(Type, Object)
2884 + // Prepare the second parameter for the any ctor
2885 + ilGen.Emit (OpCodes.Ldarg, j + 1);
2887 + // if the parameter is a value type then we need to box it, because
2888 + // the Any ctor takes an Object
2889 + if (typeParameters [j + 1].IsValueType)
2890 + ilGen.Emit (OpCodes.Box, typeParameters [j + 1]);
2891 + ilGen.Emit (OpCodes.Call, ctorAny);
2892 + } else if (typeParameters [j + 1] == typeof (uno.Any)) {
2893 + // Create the call new Any(param.Type,param,Value)
2894 + // Stack must be Any,Type,Value
2895 + // First load the Any which is to be constructed
2896 + ilGen.Emit (OpCodes.Ldloca, localAny [j]);
2898 + //Load the Type, which is obtained by calling param.Type
2899 + ilGen.Emit (OpCodes.Ldarga, j + 1);
2900 + ilGen.Emit (OpCodes.Call, methodAnyGetType);
2902 + //Load the Value, which is obtained by calling param.Value
2903 + ilGen.Emit (OpCodes.Ldarga, j + 1);
2904 + ilGen.Emit (OpCodes.Call, methodAnyGetValue);
2906 + //Call the Any ctor.
2907 + ilGen.Emit (OpCodes.Call, ctorAny);
2909 + ilGen.Emit (OpCodes.Ldloca, localAny [j]);
2910 + ilGen.Emit (OpCodes.Ldtoken, typeParameters [j + 1]);
2912 + Type[] typeParams = { typeof (System.RuntimeTypeHandle) };
2913 + ilGen.Emit (OpCodes.Call, typeof (Type).GetMethod ("GetTypeFromHandle", typeParams));
2914 + ilGen.Emit(OpCodes.Ldarg, j + 1);
2916 + // if the parameter is a value type then we need to box it, because
2917 + // the Any ctor takes an Object
2918 + if (typeParameters [j + 1].IsValueType)
2919 + ilGen.Emit (OpCodes.Box, typeParameters [j + 1]);
2920 + ilGen.Emit(OpCodes.Call, ctorAny);
2925 + // Create the Any[] that is passed to the
2926 + // createInstanceWithContext[AndArguments] function
2927 + ilGen.Emit (OpCodes.Ldc_I4, localAny.Length);
2928 + ilGen.Emit (OpCodes.Newarr, typeof (uno.Any));
2929 + ilGen.Emit (OpCodes.Stloc, localAnyParams);
2931 + // Assign all anys created from the parameters
2932 + // array to the Any[]
2933 + for (j = 0; j < localAny.Length; j ++) {
2934 + ilGen.Emit (OpCodes.Ldloc, localAnyParams);
2935 + ilGen.Emit (OpCodes.Ldc_I4, j);
2936 + ilGen.Emit (OpCodes.Ldelema, typeof (uno.Any));
2937 + ilGen.Emit (OpCodes.Ldloc, localAny [j]);
2938 + ilGen.Emit (OpCodes.Stobj, typeof (uno.Any));
2941 + // call createInstanceWithContextAndArguments
2942 + ilGen.Emit (OpCodes.Ldloc, localFactory);
2943 + ilGen.Emit (OpCodes.Ldstr, entry.mType.Name);
2944 + ilGen.Emit (OpCodes.Ldloc, localAnyParams);
2945 + ilGen.Emit (OpCodes.Ldarg_0);
2946 + MethodInfo methodCreate = localFactory.LocalType.GetMethod ("createInstanceWithArgumentsAndContext");
2947 + ilGen.Emit (OpCodes.Callvirt, methodCreate);
2950 + // cast the object returned by the functions createInstanceWithContext or
2951 + // createInstanceWithArgumentsAndContext to the interface type
2952 + ilGen.Emit (OpCodes.Castclass, ret);
2953 + ilGen.Emit (OpCodes.Stloc, localReturnVal);
2955 + //catch exceptions thrown by createInstanceWithArgumentsAndContext and createInstanceWithContext
2956 + if (!exceptionTypes.Contains (typeUnoException)) {
2957 + // catch (unoidl.com.sun.star.uno.RuntimeException) {throw;}
2958 + ilGen.BeginCatchBlock (GetType ("unoidl.com.sun.star.uno.RuntimeException", true));
2959 + ilGen.Emit (OpCodes.Pop);
2960 + ilGen.Emit (OpCodes.Rethrow);
2962 + //catch and rethrow all other defined Exceptions
2963 + for (j = 0; j < exceptionTypes.Count; j ++) {
2964 + Type excType = exceptionTypes [j] as Type;
2965 + if (excType.IsInstanceOfType (GetType ("unoidl.com.sun.star.uno.RuntimeException", true))) {
2966 + // we have a catch for RuntimeException already defined
2970 + //catch Exception and rethrow
2971 + ilGen.BeginCatchBlock (excType);
2972 + ilGen.Emit (OpCodes.Pop);
2973 + ilGen.Emit (OpCodes.Rethrow);
2976 + //catch (unoidl.com.sun.star.uno.Exception) {throw DeploymentException...}
2977 + ilGen.BeginCatchBlock (typeUnoException);
2979 + //Define the local variabe that keeps the exception
2980 + LocalBuilder localException = ilGen.DeclareLocal (typeUnoException);
2982 + //Store the exception
2983 + ilGen.Emit (OpCodes.Stloc, localException);
2985 + //prepare the construction of the exception
2986 + strBuilder = new System.Text.StringBuilder (256);
2987 + strBuilder.Append ("The context (com.sun.star.uno.XComponentContext) failed to supply the service ");
2988 + strBuilder.Append ("unoidl." + entry.mType.Name);
2989 + strBuilder.Append (": ");
2991 + ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString());
2993 + // add to the string the Exception.Message
2994 + ilGen.Emit (OpCodes.Ldloc, localException);
2995 + //Console.WriteLine ("get message property of type: {0}", typeUnoException);
2996 + ilGen.Emit (OpCodes.Callvirt, typeUnoException.GetProperty ("Message").GetGetMethod ());
2997 + Type[] concatParams = { typeof (string), typeof (string)};
2998 + ilGen.Emit (OpCodes.Call, typeof (string).GetMethod ("Concat", concatParams));
3000 + //load contex argument
3001 + ilGen.Emit (OpCodes.Ldarg_0);
3002 + ilGen.Emit (OpCodes.Newobj, ctorDeploymentException);
3003 + ilGen.Emit (OpCodes.Throw); //Exception(typeDeploymentExc);
3005 + ilGen.EndExceptionBlock();
3009 + // Check if the service instance was create and throw a exception if not.
3010 + Label labelServiceCreated = ilGen.DefineLabel ();
3011 + ilGen.Emit (OpCodes.Ldloc, localReturnVal);
3012 + ilGen.Emit (OpCodes.Brtrue_S, labelServiceCreated);
3014 + strBuilder = new System.Text.StringBuilder(256);
3015 + strBuilder.Append ("The context (com.sun.star.uno.XComponentContext) failed to supply the service ");
3016 + strBuilder.Append ("unoidl." + entry.mType.Name);
3017 + strBuilder.Append (".");
3018 + ilGen.Emit (OpCodes.Ldstr, strBuilder.ToString());
3019 + ilGen.Emit (OpCodes.Ldarg_0);
3020 + ilGen.Emit (OpCodes.Newobj, ctorDeploymentException);
3021 + ilGen.Emit (OpCodes.Throw); //Exception(typeDeploymentExc);
3023 + ilGen.MarkLabel (labelServiceCreated);
3024 + ilGen.Emit (OpCodes.Ldloc, localReturnVal);
3025 + ilGen.Emit (OpCodes.Ret);
3028 + mIncompleteServices.Remove (entry.mTypeBuilder.FullName);
3030 + if (mConfig.mVerbose)
3031 + Console.WriteLine("> emitting service type {0}", "unoidl." + entry.mType.Name);
3033 + //Console.WriteLine ("completed service {0}", entry.mTypeBuilder.FullName);
3035 + return entry.mTypeBuilder.CreateType ();
3038 + Type CompleteSingletonType (SingletonEntry entry)
3040 + string name = "unoidl." + entry.mType.Name;
3042 + // Create the private default constructor
3043 + ConstructorBuilder ctorBuilder = entry.mTypeBuilder.DefineConstructor (MethodAttributes.Private |
3044 + MethodAttributes.HideBySig |
3045 + MethodAttributes.SpecialName |
3046 + MethodAttributes.RTSpecialName,
3047 + CallingConventions.Standard, null);
3049 + ILGenerator ilGen = ctorBuilder.GetILGenerator ();
3050 + ilGen.Emit (OpCodes.Ldarg_0); // push this
3051 + ilGen.Emit (OpCodes.Call, entry.mTypeBuilder.BaseType.GetConstructor (new Type [0]));
3052 + ilGen.Emit (OpCodes.Ret);
3054 + // obtain the interface which makes up this service, it is the return
3055 + // type of the constructor functions
3056 + UnoXTypeDescription ifaceTD = entry.mType.Interface;
3057 + if (!(ifaceTD is UnoXInterfaceTypeDescription))
3058 + ifaceTD = ResolveInterfaceTypedef (ifaceTD);
3059 + Type retType = GetType (ifaceTD);
3062 + Type[] typeParameters = { GetType ("unoidl.com.sun.star.uno.XComponentContext", true) };
3063 + MethodBuilder methodBuilder = entry.mTypeBuilder.DefineMethod ("get", MethodAttributes.Public |
3064 + MethodAttributes.HideBySig |
3065 + MethodAttributes.Static,
3069 + // The first parameter is the XComponentContext, which cannot be obtained
3070 + // from reflection.
3071 + // The context is not part of the idl description
3072 + methodBuilder.DefineParameter (1, ParameterAttributes.In, "the_context");
3074 + ilGen = methodBuilder.GetILGenerator();
3075 + // Define locals ---------------------------------
3076 + // Any, returned by XComponentContext.getValueByName
3077 + LocalBuilder localAny = ilGen.DeclareLocal (typeof (uno.Any));
3079 + // Call XContext.getValueByName
3080 + ilGen.Emit (OpCodes.Ldarg_0);
3082 + // build the singleton name : /singleton/unoidl.com.sun.star.XXX
3083 + ilGen.Emit(OpCodes.Ldstr, "/singletons/" + name);
3085 + MethodInfo methodGetValueByName = GetType ("unoidl.com.sun.star.uno.XComponentContext", true).GetMethod ("getValueByName");
3086 + ilGen.Emit(OpCodes.Callvirt, methodGetValueByName);
3087 + ilGen.Emit(OpCodes.Stloc_0);
3089 + //Contains the returned Any a value?
3090 + ilGen.Emit(OpCodes.Ldloca_S, localAny);
3091 + MethodInfo methodHasValue = typeof (uno.Any).GetMethod ("hasValue");
3092 + ilGen.Emit (OpCodes.Call, methodHasValue);
3094 + //If not, then throw an DeploymentException
3095 + Label labelSingletonExists = ilGen.DefineLabel ();
3096 + ilGen.Emit (OpCodes.Brtrue_S, labelSingletonExists);
3097 + ilGen.Emit (OpCodes.Ldstr, "Component context fails to supply singleton " + name + " of type " + retType.FullName + ".");
3098 + ilGen.Emit (OpCodes.Ldarg_0);
3099 + Type[] typesCtorDeploymentException = { typeof (string), typeof (object) };
3100 + ilGen.Emit (OpCodes.Newobj, GetType ("unoidl.com.sun.star.uno.DeploymentException", true).GetConstructor (typesCtorDeploymentException));
3101 + ilGen.Emit (OpCodes.Throw);
3102 + ilGen.MarkLabel (labelSingletonExists);
3104 + //Cast the singleton contained in the Any to the expected interface and return it.
3105 + ilGen.Emit (OpCodes.Ldloca_S, localAny);
3106 + ilGen.Emit (OpCodes.Call, typeof (uno.Any).GetProperty ("Value").GetGetMethod ());
3107 + ilGen.Emit (OpCodes.Castclass, retType);
3108 + ilGen.Emit (OpCodes.Ret);
3110 + if (mConfig.mVerbose)
3111 + Console.WriteLine ("> emitting singleton type {0}", name);
3113 + mIncompleteSingletons.Remove (entry.mTypeBuilder.FullName);
3115 + //Console.WriteLine ("completed singleton {0}", entry.mTypeBuilder.FullName);
3117 + return entry.mTypeBuilder.CreateType ();
3120 + public void Dispose ()
3122 + while (mIncompleteIFaces.Count > 0) {
3123 + IDictionaryEnumerator e = mIncompleteIFaces.GetEnumerator ();
3125 + CompleteIFaceType (e.Value as IFaceEntry);
3128 + while (mIncompleteServices.Count > 0) {
3129 + IDictionaryEnumerator e = mIncompleteServices.GetEnumerator ();
3131 + CompleteServiceType (e.Value as ServiceEntry);
3134 + while (mIncompleteSingletons.Count > 0) {
3135 + IDictionaryEnumerator e = mIncompleteSingletons.GetEnumerator ();
3137 + CompleteSingletonType (e.Value as SingletonEntry);
3144 + public ArrayList mMandatoryRegistries = new ArrayList ();
3145 + public ArrayList mExplicitTypes = new ArrayList ();
3146 + public ArrayList mExtraAssemblies = new ArrayList ();
3147 + public ArrayList mExtraRegistries = new ArrayList ();
3148 + public bool mVerbose = false;
3152 + mDescription = null,
3155 + mCopyright = null,
3156 + mTrademark = null,
3158 + mDelaySign = null;
3163 + IntPtr mUnoHelper;
3165 +// string mOutputDir = "./";
3166 +// string mOutputFile = "cli_uretypes.dll";
3167 +// string mName = "cli_uretypes";
3169 + string mOutputDir;
3170 + string mOutputFile;
3175 + AssemblyBuilder mAssemblyBuilder;
3176 + ResolveEventHandler mTypeResolver = null;
3178 + public CliMaker (Config config)
3181 + mUnoHelper = cmm_uno_helper_new ();
3186 + cmm_uno_helper_delete (mUnoHelper);
3189 + public void OpenRegistries ()
3191 + if (mConfig.mExplicitTypes.Count > 0)
3192 + foreach (string typeName in mConfig.mExplicitTypes)
3193 + cmm_uno_helper_add_explicit_type (mUnoHelper, typeName);
3195 + foreach (string registry in mConfig.mMandatoryRegistries)
3196 + cmm_uno_helper_add_mandatory_registry (mUnoHelper, registry);
3198 + foreach (string registry in mConfig.mExtraRegistries)
3199 + cmm_uno_helper_add_extra_registry (mUnoHelper, registry);
3201 + cmm_uno_helper_open_registries (mUnoHelper);
3204 + public void PrepareAssembly ()
3206 + // Get the key pair for making a strong name
3207 + StrongNameKeyPair kp = null;
3208 + if (mConfig.mKeyfile != null) {
3210 + System.IO.FileStream fs = new System.IO.FileStream (mConfig.mKeyfile, System.IO.FileMode.Open);
3211 + kp = new StrongNameKeyPair (fs);
3213 + } catch (System.IO.FileNotFoundException) {
3214 + throw new Exception ("Could not find the keyfile. Verify the --keyfile argument!");
3217 + if (mConfig.mVerbose)
3218 + Console.WriteLine ("> no key file specified. Cannot create strong name!");
3221 + mOutputFile = System.IO.Path.GetFileName (mConfig.mOutput);
3222 + mOutputDir = System.IO.Path.GetDirectoryName (mConfig.mOutput);
3223 + mName = System.IO.Path.GetFileNameWithoutExtension (mConfig.mOutput);
3224 +// int idx = mOutputFile.LastIndexOf (System.IO.Path.DirectorySeparatorChar);
3226 +// mOutputDir = mOutputFile.Substring (0, idx);
3228 +// mOutputDir = System.IO.Path.CurrentDirectory;
3229 +// idx = mOutputFile.LastIndexOf (".dll");
3230 +// mName = mOutputFile.Substring (0, idx);
3231 + //Console.WriteLine ("file {0}\ndir {1}\nname {2}", mOutputFile, mOutputDir, mName);
3233 + // setup assembly info: xxx todo set more? e.g. avoid strong versioning
3234 + AssemblyName assemblyName = new AssemblyName();
3235 + assemblyName.CodeBase = mOutputDir;
3236 + assemblyName.Name = mName;
3239 + assemblyName.KeyPair = kp;
3241 + if (mConfig.mVersion != null)
3242 + assemblyName.Version = new System.Version (mConfig.mVersion);
3244 + // target assembly
3245 + mAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.Save, mOutputDir);
3247 + if (mConfig.mProduct != null) {
3248 + Type[] paramTypes = { typeof (string) };
3249 + object[] args = { mConfig.mProduct };
3250 + mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyProductAttribute).GetConstructor (paramTypes), args));
3253 + if (mConfig.mDescription != null) {
3254 + Type[] paramTypes = { typeof (string) };
3255 + object[] args = { mConfig.mDescription };
3256 + mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyDescriptionAttribute).GetConstructor (paramTypes), args));
3259 + if (mConfig.mCompany != null) {
3260 + Type[] paramTypes = { typeof (string) };
3261 + object[] args = { mConfig.mCompany };
3262 + mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyCompanyAttribute).GetConstructor (paramTypes), args));
3265 + if (mConfig.mCopyright != null) {
3266 + Type[] paramTypes = { typeof (string) };
3267 + object[] args = { mConfig.mCopyright };
3268 + mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyCopyrightAttribute).GetConstructor (paramTypes), args));
3271 + if (mConfig.mTrademark != null) {
3272 + Type[] paramTypes = { typeof (string) };
3273 + object[] args = { mConfig.mTrademark };
3274 + mAssemblyBuilder.SetCustomAttribute (new CustomAttributeBuilder (typeof (AssemblyTrademarkAttribute).GetConstructor (paramTypes), args));
3278 + public UnoXTypeDescription NextType ()
3280 + IntPtr handle = cmm_uno_helper_next_type (mUnoHelper);
3282 + if (handle != IntPtr.Zero) {
3283 + return UnoXTypeDescription.Create (handle);
3289 + public void Emit ()
3291 + TypeEmitter mTypeEmitter = new TypeEmitter (mConfig, mAssemblyBuilder.DefineDynamicModule( mOutputFile ));
3293 + AppDomain.CurrentDomain.TypeResolve += mTypeEmitter.ResolveEventHandler;
3295 + UnoXTypeDescription type;
3297 + while ((type = NextType ()) != null)
3298 + mTypeEmitter.GetType (type);
3300 + mTypeEmitter.Dispose ();
3303 + public void Save ()
3305 + if (mConfig.mVerbose)
3306 + Console.Write ("> saving assembly {0}{1}{2}...",
3308 + System.IO.Path.DirectorySeparatorChar,
3311 + mAssemblyBuilder.Save (mOutputFile);
3313 + if (mConfig.mVerbose)
3314 + Console.WriteLine ("ok.");
3316 + AppDomain.CurrentDomain.TypeResolve -= mTypeResolver;
3319 + [DllImport("climaker")]
3320 + private static extern IntPtr cmm_uno_helper_new ();
3322 + [DllImport("climaker")]
3323 + private static extern void cmm_uno_helper_delete (IntPtr handle);
3325 + [DllImport("climaker")]
3326 + private static extern void cmm_uno_helper_add_mandatory_registry (IntPtr handle, string registry);
3328 + [DllImport("climaker")]
3329 + private static extern void cmm_uno_helper_add_extra_registry (IntPtr handle, string registry);
3331 + [DllImport("climaker")]
3332 + private static extern void cmm_uno_helper_add_explicit_type (IntPtr handle, string typeName);
3334 + [DllImport("climaker")]
3335 + private static extern void cmm_uno_helper_open_registries (IntPtr handle);
3337 + [DllImport("climaker")]
3338 + private static extern IntPtr cmm_uno_helper_next_type (IntPtr handle);
3343 + protected IntPtr mHandle;
3345 + protected UnoObject (IntPtr handle)
3350 + public IntPtr Handle
3359 +class UnoXTypeDescription : UnoObject
3361 + protected UnoXTypeDescription (IntPtr handle) : base (handle)
3365 + public static UnoXTypeDescription Create (IntPtr handle)
3367 + //Console.WriteLine ("Create {0}", handle);
3368 + if (handle == IntPtr.Zero)
3371 + UnoTypeClass tc = cmm_x_type_description_get_type_class (handle);
3373 + case UnoTypeClass.Enum:
3374 + return new UnoXEnumTypeDescription (handle);
3375 + case UnoTypeClass.Interface:
3376 + return new UnoXInterfaceTypeDescription (handle);
3377 + case UnoTypeClass.Struct:
3378 + return new UnoXStructTypeDescription (handle);
3379 + case UnoTypeClass.Exception:
3380 + return new UnoXExceptionTypeDescription (handle);
3381 + case UnoTypeClass.Sequence:
3382 + case UnoTypeClass.Typedef:
3383 + return new UnoXIndirectTypeDescription (handle);
3384 + case UnoTypeClass.Constant:
3385 + return new UnoXConstantTypeDescription (handle);
3386 + case UnoTypeClass.Constants:
3387 + return new UnoXConstantsTypeDescription (handle);
3388 + case UnoTypeClass.Service:
3389 + return new UnoXServiceTypeDescription (handle);
3390 + case UnoTypeClass.Singleton:
3391 + return new UnoXSingletonTypeDescription (handle);
3394 + //Console.WriteLine ("unknown type {0}", tc);
3396 + return new UnoXTypeDescription (handle);
3399 + public string Name
3403 + return cmm_x_type_description_get_name (mHandle);
3407 + public UnoTypeClass TypeClass
3411 + return cmm_x_type_description_get_type_class (mHandle);
3415 + [DllImport("climaker")]
3416 + private static extern string cmm_x_type_description_get_name (IntPtr handle);
3418 + [DllImport("climaker")]
3419 + private static extern UnoTypeClass cmm_x_type_description_get_type_class (IntPtr handle);
3422 +class UnoXEnumTypeDescription : UnoXTypeDescription
3424 + public UnoXEnumTypeDescription (IntPtr mHandle) : base (mHandle)
3432 + return cmm_x_enum_type_description_get_length (mHandle);
3436 + public string ValueName (int idx)
3438 + return cmm_x_enum_type_description_get_name (mHandle, idx);
3441 + public int Value (int idx)
3443 + return cmm_x_enum_type_description_get_value (mHandle, idx);
3446 + [DllImport("climaker")]
3447 + private static extern int cmm_x_enum_type_description_get_length (IntPtr handle);
3449 + [DllImport("climaker")]
3450 + private static extern int cmm_x_enum_type_description_get_value (IntPtr handle, int idx);
3452 + [DllImport("climaker")]
3453 + private static extern string cmm_x_enum_type_description_get_name (IntPtr handle, int idx);
3456 +class UnoXInterfaceTypeDescription : UnoXTypeDescription
3459 + IntPtr mMembersHandle = IntPtr.Zero;
3461 + public UnoXInterfaceTypeDescription (IntPtr mHandle) : base (mHandle)
3465 + public int BaseTypes
3469 + return cmm_x_interface_type_description_get_length (mHandle);
3473 + public UnoXInterfaceTypeDescription BaseType (int idx)
3475 + return new UnoXInterfaceTypeDescription (cmm_x_interface_type_description_get_base_type (mHandle, idx));
3478 + void AssureMembers ()
3480 + if (mMembersHandle == IntPtr.Zero)
3481 + mMembers = cmm_x_interface_type_description_get_members (mHandle, out mMembersHandle);
3484 + public int Members
3494 + public UnoXInterfaceMemberTypeDescription Member (int idx)
3498 + if (idx < 0 || idx >= mMembers)
3501 + return new UnoXInterfaceMemberTypeDescription (cmm_x_interface_type_description_get_member (mMembersHandle, idx));
3504 + [DllImport("climaker")]
3505 + private static extern int cmm_x_interface_type_description_get_length (IntPtr handle);
3507 + [DllImport("climaker")]
3508 + private static extern IntPtr cmm_x_interface_type_description_get_base_type (IntPtr handle, int idx);
3510 + [DllImport("climaker")]
3511 + private static extern int cmm_x_interface_type_description_get_members (IntPtr handle, out IntPtr membersHandle);
3513 + [DllImport("climaker")]
3514 + private static extern IntPtr cmm_x_interface_type_description_get_member (IntPtr membersArrayHandle, int idx);
3517 +class UnoXInterfaceMemberTypeDescription : UnoXTypeDescription
3519 + public UnoXInterfaceMemberTypeDescription (IntPtr handle) : base (handle)
3523 + public string MemberName
3527 + return cmm_x_interface_member_type_description_get_member_name (mHandle);
3531 + [DllImport("climaker")]
3532 + private static extern string cmm_x_interface_member_type_description_get_member_name (IntPtr handle);
3535 +class UnoXInterfaceAttributeTypeDescription : UnoXInterfaceMemberTypeDescription
3537 + public UnoXInterfaceAttributeTypeDescription (IntPtr handle) : base (handle)
3541 + public UnoXTypeDescription Type
3545 + return UnoXTypeDescription.Create (cmm_x_interface_attribute_type_description_get_type (mHandle));
3549 + public bool IsBound
3553 + return cmm_x_interface_attribute_type_description_is_bound (mHandle);
3557 + public bool IsReadOnly
3561 + return cmm_x_interface_attribute_type_description_is_read_only (mHandle);
3565 + UnoXTypeDescription[] ExceptionTypes (IntPtr handle, int count)
3569 + UnoXTypeDescription[] types = new UnoXTypeDescription [count];
3570 + for (i = 0; i < count; i ++) {
3571 + types [i] = UnoXTypeDescription.Create (cmm_x_interface_attribute_type_description_get_exception_type (handle, i));
3577 + public UnoXTypeDescription[] GetExceptionTypes
3584 + count = cmm_x_interface_attribute_type_description_get_get_exception_types (mHandle, out handle);
3585 + UnoXTypeDescription[] types = ExceptionTypes (handle, count);
3588 + cmm_x_interface_attribute_type_description_free_exception_types (handle, count);
3594 + public UnoXTypeDescription[] SetExceptionTypes
3601 + count = cmm_x_interface_attribute_type_description_get_set_exception_types (mHandle, out handle);
3602 + UnoXTypeDescription[] types = ExceptionTypes (handle, count);
3605 + cmm_x_interface_attribute_type_description_free_exception_types (handle, count);
3611 + [DllImport("climaker")]
3612 + private static extern IntPtr cmm_x_interface_attribute_type_description_get_type (IntPtr handle);
3614 + [DllImport("climaker")]
3615 + private static extern bool cmm_x_interface_attribute_type_description_is_bound (IntPtr handle);
3617 + [DllImport("climaker")]
3618 + private static extern bool cmm_x_interface_attribute_type_description_is_read_only (IntPtr handle);
3620 + [DllImport("climaker")]
3621 + private static extern int cmm_x_interface_attribute_type_description_get_get_exception_types (IntPtr handle, out IntPtr exceptionTypesHandle);
3623 + [DllImport("climaker")]
3624 + private static extern int cmm_x_interface_attribute_type_description_get_set_exception_types (IntPtr handle, out IntPtr exceptionTypesHandle);
3626 + [DllImport("climaker")]
3627 + private static extern IntPtr cmm_x_interface_attribute_type_description_get_exception_type (IntPtr handle, int index);
3629 + [DllImport("climaker")]
3630 + private static extern void cmm_x_interface_attribute_type_description_free_exception_types (IntPtr handle, int count);
3633 +class UnoXInterfaceMethodTypeDescription : UnoXInterfaceMemberTypeDescription
3635 + int mParameters = 0;
3636 + IntPtr mParametersHandle = IntPtr.Zero;
3637 + IntPtr mParametersArrayHandle = IntPtr.Zero;
3639 + bool mGotExceptionTypes = false;
3640 + int mExceptionTypes = 0;
3641 + IntPtr mExceptionTypesHandle = IntPtr.Zero;
3642 + IntPtr mExceptionTypesArrayHandle = IntPtr.Zero;
3644 + public UnoXInterfaceMethodTypeDescription (IntPtr handle) : base (handle)
3648 + public UnoXTypeDescription ReturnType
3652 + return UnoXTypeDescription.Create (cmm_x_interface_method_type_description_get_return_type (mHandle));
3656 + public bool ReturnsStruct
3660 + return cmm_x_interface_method_type_description_returns_struct (mHandle);
3664 + void AssureParameters ()
3666 + if (mParametersHandle == IntPtr.Zero)
3667 + mParameters = cmm_x_interface_method_type_description_get_parameters (mHandle, out mParametersHandle, out mParametersArrayHandle);
3670 + public int Parameters
3674 + AssureParameters ();
3676 + return mParameters;
3680 + public UnoXMethodParameter Parameter (int idx)
3682 + AssureParameters ();
3684 + if (idx < 0 || idx >= mParameters)
3687 + return new UnoXMethodParameter (cmm_x_interface_method_type_description_get_parameter (mParametersArrayHandle, idx));
3690 + void AssureExceptionTypes ()
3692 + if (!mGotExceptionTypes) {
3693 + mExceptionTypes = cmm_x_interface_method_type_description_get_exception_types (mHandle, out mExceptionTypesHandle, out mExceptionTypesArrayHandle);
3694 + mGotExceptionTypes = true;
3698 + public int ExceptionTypes
3702 + AssureExceptionTypes ();
3704 + return mExceptionTypes;
3708 + public UnoXCompoundTypeDescription ExceptionType (int idx)
3710 + AssureExceptionTypes ();
3712 + if (idx < 0 || idx >= mExceptionTypes)
3715 + return UnoXTypeDescription.Create (cmm_x_interface_method_type_description_get_exception_type (mExceptionTypesArrayHandle, idx)) as UnoXCompoundTypeDescription;
3718 + public bool IsOneway
3722 + return cmm_x_interface_method_type_description_is_oneway (mHandle);
3726 + [DllImport("climaker")]
3727 + private static extern int cmm_x_interface_method_type_description_get_parameters (IntPtr handle, out IntPtr parametersHandle, out IntPtr parametersArrayHandle);
3729 + [DllImport("climaker")]
3730 + private static extern IntPtr cmm_x_interface_method_type_description_get_parameter (IntPtr parametersArrayHandle, int idx);
3732 + [DllImport("climaker")]
3733 + private static extern int cmm_x_interface_method_type_description_get_exception_types (IntPtr handle, out IntPtr exceptionTypesHandle, out IntPtr exceptionTypesArrayHandle);
3735 + [DllImport("climaker")]
3736 + private static extern IntPtr cmm_x_interface_method_type_description_get_exception_type (IntPtr exceptionTypesArrayHandle, int idx);
3738 + [DllImport("climaker")]
3739 + private static extern IntPtr cmm_x_interface_method_type_description_get_return_type (IntPtr handle);
3741 + [DllImport("climaker")]
3742 + private static extern bool cmm_x_interface_method_type_description_returns_struct (IntPtr handle);
3744 + [DllImport("climaker")]
3745 + private static extern bool cmm_x_interface_method_type_description_is_oneway (IntPtr handle);
3748 +class UnoXCompoundTypeDescription : UnoXTypeDescription
3750 + int mMemberNames = 0;
3751 + IntPtr mMemberNamesHandle = IntPtr.Zero;
3753 + int mMemberTypes = 0;
3754 + IntPtr mMemberTypesHandle = IntPtr.Zero;
3756 + public UnoXCompoundTypeDescription (IntPtr handle) : base (handle)
3760 + public UnoXTypeDescription BaseType
3764 + return UnoXTypeDescription.Create (cmm_x_compound_type_description_get_base_type (mHandle));
3768 + void AssureMemberNames ()
3770 + if (mMemberNamesHandle == IntPtr.Zero)
3771 + mMemberNames = cmm_x_compound_type_description_get_member_names (mHandle, out mMemberNamesHandle);
3774 + public string MemberName (int idx)
3776 + AssureMemberNames ();
3778 + if (idx < 0 || idx >= mMemberNames)
3781 + return cmm_x_compound_type_description_get_member_name (mMemberNamesHandle, idx);
3784 + public int MemberNames
3788 + AssureMemberNames ();
3790 + return mMemberNames;
3794 + void AssureMemberTypes ()
3796 + if (mMemberTypesHandle == IntPtr.Zero)
3797 + mMemberTypes = cmm_x_compound_type_description_get_member_types (mHandle, out mMemberTypesHandle);
3800 + public UnoXTypeDescription MemberType (int idx)
3802 + AssureMemberTypes ();
3804 + if (idx < 0 || idx >= mMemberTypes)
3807 + return UnoXTypeDescription.Create (cmm_x_compound_type_description_get_member_type (mMemberTypesHandle, idx));
3810 + public int MemberTypes
3814 + AssureMemberTypes ();
3816 + return mMemberTypes;
3820 + [DllImport("climaker")]
3821 + private static extern IntPtr cmm_x_compound_type_description_get_base_type (IntPtr handle);
3823 + [DllImport("climaker")]
3824 + private static extern int cmm_x_compound_type_description_get_member_names (IntPtr handle, out IntPtr memberNamesHandle);
3826 + [DllImport("climaker")]
3827 + private static extern string cmm_x_compound_type_description_get_member_name (IntPtr handle, int idx);
3829 + [DllImport("climaker")]
3830 + private static extern int cmm_x_compound_type_description_get_member_types (IntPtr handle, out IntPtr memberTypesHandle);
3832 + [DllImport("climaker")]
3833 + private static extern IntPtr cmm_x_compound_type_description_get_member_type (IntPtr handle, int idx);
3836 +class UnoXExceptionTypeDescription : UnoXCompoundTypeDescription
3838 + public UnoXExceptionTypeDescription (IntPtr handle) : base (handle)
3843 +class UnoXStructTypeDescription : UnoXCompoundTypeDescription
3845 + int mTypeArguments = 0;
3846 + IntPtr mTypeArgumentsHandle = IntPtr.Zero;
3847 + IntPtr mTypeArgumentsArrayHandle = IntPtr.Zero;
3849 + int mTypeParameters = 0;
3850 + IntPtr mTypeParametersHandle = IntPtr.Zero;
3852 + public UnoXStructTypeDescription (IntPtr handle) : base (handle)
3856 + void AssureTypeParameters ()
3858 + if (mTypeParametersHandle == IntPtr.Zero)
3859 + mTypeParameters = cmm_x_struct_type_description_get_type_parameters (mHandle, out mTypeParametersHandle);
3862 + public string TypeParameter (int idx)
3864 + AssureTypeParameters ();
3866 + if (idx < 0 || idx >= mTypeParameters)
3869 + return cmm_x_struct_type_description_get_type_parameter (mTypeParametersHandle, idx);
3872 + public int TypeParameters
3876 + AssureTypeParameters ();
3878 + return mTypeParameters;
3882 + void AssureTypeArguments ()
3884 + if (mTypeArgumentsHandle == IntPtr.Zero)
3885 + mTypeArguments = cmm_x_struct_type_description_get_type_arguments (mHandle, out mTypeArgumentsHandle, out mTypeArgumentsArrayHandle);
3888 + public int TypeArguments
3892 + AssureTypeArguments ();
3894 + return mTypeArguments;
3898 + public UnoXTypeDescription TypeArgument (int idx)
3900 + AssureTypeArguments ();
3902 + if (idx < 0 || idx >= mTypeArguments)
3905 + return UnoXTypeDescription.Create (cmm_x_struct_type_description_get_type_argument (mTypeArgumentsArrayHandle, idx));
3908 + [DllImport("climaker")]
3909 + private static extern int cmm_x_struct_type_description_get_type_parameters (IntPtr handle, out IntPtr typeParametersHandle);
3911 + [DllImport("climaker")]
3912 + private static extern string cmm_x_struct_type_description_get_type_parameter (IntPtr typeParametersHandle, int idx);
3914 + [DllImport("climaker")]
3915 + private static extern int cmm_x_struct_type_description_get_type_arguments (IntPtr handle, out IntPtr typeArgumentsHandle, out IntPtr typeArgumentsArrayHandle);
3917 + [DllImport("climaker")]
3918 + private static extern IntPtr cmm_x_struct_type_description_get_type_argument (IntPtr typeArgumentsArrayHandle, int idx);
3921 +class UnoXMethodParameter : UnoObject
3923 + public UnoXMethodParameter (IntPtr handle) : base (handle)
3931 + return cmm_x_method_parameter_is_out (mHandle);
3939 + return cmm_x_method_parameter_is_in (mHandle);
3943 + public string Name
3947 + return cmm_x_method_parameter_name (mHandle);
3951 + public int Position
3955 + return cmm_x_method_parameter_position (mHandle);
3959 + public UnoXTypeDescription Type
3963 + return UnoXTypeDescription.Create (cmm_x_method_parameter_type (mHandle));
3967 + [DllImport("climaker")]
3968 + private static extern bool cmm_x_method_parameter_is_out (IntPtr handle);
3970 + [DllImport("climaker")]
3971 + private static extern bool cmm_x_method_parameter_is_in (IntPtr handle);
3973 + [DllImport("climaker")]
3974 + private static extern int cmm_x_method_parameter_position (IntPtr handle);
3976 + [DllImport("climaker")]
3977 + private static extern string cmm_x_method_parameter_name (IntPtr handle);
3979 + [DllImport("climaker")]
3980 + private static extern IntPtr cmm_x_method_parameter_type (IntPtr handle);
3983 +class UnoXParameter : UnoXMethodParameter
3985 + public UnoXParameter (IntPtr handle) : base (handle)
3989 + public bool IsRest
3993 + return cmm_x_parameter_is_rest (mHandle);
3997 + [DllImport("climaker")]
3998 + private static extern bool cmm_x_parameter_is_rest (IntPtr handle);
4001 +class UnoXIndirectTypeDescription : UnoXTypeDescription
4003 + public UnoXIndirectTypeDescription (IntPtr handle) : base (handle)
4007 + public UnoXTypeDescription ReferencedType
4011 + return UnoXTypeDescription.Create (cmm_x_indirect_type_description_get_referenced_type (mHandle));
4015 + [DllImport("climaker")]
4016 + private static extern IntPtr cmm_x_indirect_type_description_get_referenced_type (IntPtr handle);
4019 +class UnoXServiceTypeDescription : UnoXTypeDescription
4021 + int mConstructors = 0;
4022 + IntPtr mConstructorsHandle = IntPtr.Zero;
4024 + public UnoXServiceTypeDescription (IntPtr handle) : base (handle)
4028 + public bool IsSingleInterfaceBased
4032 + return cmm_x_service_type_description_is_single_interface_based (mHandle);
4036 + public UnoXTypeDescription Interface
4040 + return UnoXTypeDescription.Create (cmm_x_service_type_description_get_interface (mHandle));
4044 + void AssureConstructors ()
4046 + if (mConstructorsHandle == IntPtr.Zero)
4047 + mConstructors = cmm_x_service_type_description_get_constructors (mHandle, out mConstructorsHandle);
4050 + public int Constructors
4054 + AssureConstructors ();
4056 + return mConstructors;
4060 + public UnoXServiceConstructorDescription Constructor (int idx)
4062 + AssureConstructors ();
4064 + if (idx < 0 || idx >= mConstructors)
4067 + return new UnoXServiceConstructorDescription (cmm_x_service_type_description_get_constructor (mConstructorsHandle, idx));
4070 + [DllImport("climaker")]
4071 + private static extern int cmm_x_service_type_description_get_constructors (IntPtr handle, out IntPtr constructorssHandle);
4073 + [DllImport("climaker")]
4074 + private static extern IntPtr cmm_x_service_type_description_get_constructor (IntPtr constructorsHandle, int idx);
4076 + [DllImport("climaker")]
4077 + private static extern bool cmm_x_service_type_description_is_single_interface_based (IntPtr handle);
4079 + [DllImport("climaker")]
4080 + private static extern IntPtr cmm_x_service_type_description_get_interface (IntPtr handle);
4083 +class UnoXSingletonTypeDescription : UnoXTypeDescription
4085 + public UnoXSingletonTypeDescription (IntPtr handle) : base (handle)
4089 + public bool IsInterfaceBased
4093 + return cmm_x_singleton_type_description_is_interface_based (mHandle);
4097 + public UnoXTypeDescription Interface
4101 + return UnoXTypeDescription.Create (cmm_x_singleton_type_description_get_interface (mHandle));
4105 + [DllImport("climaker")]
4106 + private static extern IntPtr cmm_x_singleton_type_description_get_interface (IntPtr handle);
4108 + [DllImport("climaker")]
4109 + private static extern bool cmm_x_singleton_type_description_is_interface_based (IntPtr handle);
4112 +class UnoXConstantTypeDescription : UnoXTypeDescription
4114 + public UnoXConstantTypeDescription (IntPtr handle) : base (handle)
4118 + public object ConstantValue
4126 + System.UInt16 tUInt16;
4128 + System.UInt32 tUInt32;
4130 + System.UInt64 tUInt64;
4131 + System.Single tFloat;
4134 + UnoTypeClass tc = cmm_any_to_cli_constant (mHandle,
4135 + out tChar, out tBool,
4137 + out tInt16, out tUInt16,
4138 + out tInt32, out tUInt32,
4139 + out tInt64, out tUInt64,
4140 + out tFloat, out tDouble);
4142 + case UnoTypeClass.Char:
4144 + case UnoTypeClass.Boolean:
4146 + case UnoTypeClass.Byte:
4148 + case UnoTypeClass.Short:
4150 + case UnoTypeClass.UnsignedShort:
4152 + case UnoTypeClass.Long:
4154 + case UnoTypeClass.UnsignedLong:
4156 + case UnoTypeClass.Hyper:
4158 + case UnoTypeClass.UnsignedHyper:
4160 + case UnoTypeClass.Float:
4162 + case UnoTypeClass.Double:
4166 + throw new Exception (String.Format ("Unexpected type {0} for XConstantTypeDescription", tc));
4170 + [DllImport("climaker")]
4171 + private static extern UnoTypeClass cmm_any_to_cli_constant (IntPtr handle,
4172 + out char tChar, out bool tBool,
4174 + out Int16 tInt16, out System.UInt16 tUInt16,
4175 + out Int32 tInt32, out System.UInt32 tUInt32,
4176 + out Int16 tInt64, out System.UInt64 tUInt64,
4177 + out System.Single tFloat, out double tDouble);
4180 +class UnoXConstantsTypeDescription : UnoXTypeDescription
4182 + int mConstants = 0;
4183 + IntPtr mConstantsHandle = IntPtr.Zero;
4185 + public UnoXConstantsTypeDescription (IntPtr handle) : base (handle)
4189 + void AssureConstants ()
4191 + if (mConstantsHandle == IntPtr.Zero)
4192 + mConstants = cmm_x_constants_type_description_get_constants (mHandle, out mConstantsHandle);
4195 + public int Constants
4199 + AssureConstants ();
4201 + return mConstants;
4205 + public UnoXConstantTypeDescription Constant (int idx)
4207 + AssureConstants ();
4209 + if (idx < 0 || idx >= mConstants)
4212 + return UnoXTypeDescription.Create (cmm_x_constants_type_description_get_constant (mConstantsHandle, idx)) as UnoXConstantTypeDescription;
4215 + [DllImport("climaker")]
4216 + private static extern int cmm_x_constants_type_description_get_constants (IntPtr handle, out IntPtr constantssHandle);
4218 + [DllImport("climaker")]
4219 + private static extern IntPtr cmm_x_constants_type_description_get_constant (IntPtr constantsHandle, int idx);
4222 +class UnoXServiceConstructorDescription : UnoObject
4224 + int mParameters = 0;
4225 + IntPtr mParametersHandle = IntPtr.Zero;
4227 + public UnoXServiceConstructorDescription (IntPtr handle) : base (handle)
4231 + void AssureParameters ()
4233 + if (mParametersHandle == IntPtr.Zero)
4234 + mParameters = cmm_x_service_constructor_description_get_parameters (mHandle, out mParametersHandle);
4237 + public int Parameters
4241 + AssureParameters ();
4243 + return mParameters;
4247 + public UnoXParameter Parameter (int idx)
4249 + AssureParameters ();
4251 + if (idx < 0 || idx >= mParameters)
4254 + return new UnoXParameter (cmm_x_service_constructor_description_get_parameter (mParametersHandle, idx));
4257 + public string Name
4261 + return cmm_x_service_constructor_description_get_name (mHandle);
4265 + public bool IsDefault
4269 + return cmm_x_service_constructor_description_is_default_constructor (mHandle);
4273 + public UnoXTypeDescription[] ExceptionTypes
4280 + count = cmm_x_service_constructor_description_get_exception_types (mHandle, out handle);
4281 + UnoXTypeDescription[] types = new UnoXTypeDescription [count];
4283 + for (i = 0; i < count; i ++) {
4284 + types [i] = UnoXTypeDescription.Create (cmm_x_service_constructor_description_get_exception_type (handle, i));
4288 + cmm_x_service_constructor_description_free_exception_types (handle, count);
4294 + [DllImport("climaker")]
4295 + private static extern int cmm_x_service_constructor_description_get_parameters (IntPtr handle, out IntPtr parameterssHandle);
4297 + [DllImport("climaker")]
4298 + private static extern IntPtr cmm_x_service_constructor_description_get_parameter (IntPtr parametersHandle, int idx);
4300 + [DllImport("climaker")]
4301 + private static extern string cmm_x_service_constructor_description_get_name (IntPtr handle);
4303 + [DllImport("climaker")]
4304 + private static extern bool cmm_x_service_constructor_description_is_default_constructor (IntPtr handle);
4306 + [DllImport("climaker")]
4307 + private static extern int cmm_x_service_constructor_description_get_exception_types (IntPtr handle, out IntPtr exceptionTypesHandle);
4309 + [DllImport("climaker")]
4310 + private static extern IntPtr cmm_x_service_constructor_description_get_exception_type (IntPtr handle, int index);
4312 + [DllImport("climaker")]
4313 + private static extern void cmm_x_service_constructor_description_free_exception_types (IntPtr handle, int count);
4317 +public class MainClass
4321 + public string mName;
4322 + public char mShortOption;
4323 + public bool mHasArgument;
4325 + public OptionInfo (string name, char shortOption, bool hasArgument)
4328 + mShortOption = shortOption;
4329 + mHasArgument = hasArgument;
4333 + static OptionInfo[] sOptionInfos = {
4334 + new OptionInfo ("out", 'O', true ),
4335 + new OptionInfo ("types", 'T', true),
4336 + new OptionInfo ("extra", 'X', true),
4337 + new OptionInfo ("reference", 'r', true),
4338 + new OptionInfo ("keyfile", 'k', true),
4339 + new OptionInfo ("delaySign", 'd', true),
4340 + new OptionInfo ("assembly-version", '\0', true),
4341 + new OptionInfo ("assembly-description", '\0', true),
4342 + new OptionInfo ("assembly-product", '\0', true),
4343 + new OptionInfo ("assembly-company", '\0', true),
4344 + new OptionInfo ("assembly-copyright", '\0', true),
4345 + new OptionInfo ("assembly-trademark", '\0', true),
4346 + new OptionInfo ("verbose", 'v', false),
4347 + new OptionInfo ("help", 'h', false)
4350 + static string sUsingText =
4352 + "using: climaker <switches> [registry-file-1 registry-file-2 ...]\n" +
4355 + " -O, --out <output-file> output assembly file;\n" +
4356 + " defaults to cli_unotypes.dll if more than one\n" +
4357 + " registry-file is given, else <registry-file>.dll\n" +
4358 + " -T, --types types to be generated (if none is given,\n" +
4359 + " <type1[;type2;...]> then all types of given registries are emitted\n" +
4360 + " -X, --extra <rdb-file> additional rdb to saturate referenced types in\n" +
4361 + " given registry file(s); these types will not be\n" +
4362 + " emitted into the output assembly file\n" +
4363 + " -r, --reference reference metadata from assembly file\n" +
4364 + " <assembly-file>\n" +
4365 + " -k, --keyfile keyfile needed for strong name\n" +
4366 + " --assembly-version <version> sets assembly version\n" +
4367 + " --assembly-description <text> sets assembly description text\n" +
4368 + " --assembly-product <text> sets assembly product name\n" +
4369 + " --assembly-company <text> sets assembly company\n" +
4370 + " --assembly-copyright <text> sets assembly copyright\n" +
4371 + " --assembly-trademark <text> sets assembly trademark\n" +
4372 + " -v, --verbose verbose output to stdout\n" +
4373 + " -h, --help this message\n" +
4375 + "example: climaker --out cli_mytypes.dll \\\n" +
4376 + " --reference cli_uretypes.dll \\\n" +
4377 + " --extra types.rdb \\\n" +
4378 + " mytypes.rdb\n" +
4381 + static OptionInfo GetOptionInfo (string opt)
4383 + return GetOptionInfo (opt, '\0');
4386 + static OptionInfo GetOptionInfo (string opt, char shortOpt)
4390 + for (pos = 0; pos < sOptionInfos.Length; pos ++) {
4391 + if (opt.Length > 0) {
4392 + if (opt.Equals (sOptionInfos [pos].mName))
4393 + return sOptionInfos [pos];
4395 + if (sOptionInfos [pos].mShortOption == shortOpt)
4396 + return sOptionInfos [pos];
4403 + static bool IsOption (OptionInfo optionInfo, ref int pIndex)
4405 + if (sArgs.Length <= pIndex)
4407 + string arg = sArgs [pIndex];
4409 + if (arg.Length < 2 || arg [0] != '-')
4412 + if (arg.Length == 2 && arg[ 1 ] == optionInfo.mShortOption) {
4418 + if (arg [1] == '-' && arg.Substring (2).Equals (optionInfo.mName)) {
4427 + static bool ReadOption (ref bool flag, OptionInfo optionInfo, ref int pIndex)
4429 + bool ret = IsOption (optionInfo, ref pIndex);
4436 + static bool ReadArgument (ref string pValue, OptionInfo optionInfo, ref int pIndex)
4438 + if (IsOption (optionInfo, ref pIndex)) {
4439 + if (pIndex < sArgs.Length) {
4440 + pValue = sArgs [pIndex];
4451 + static string[] sArgs;
4453 + public static int Main (string[] args)
4455 + if (args.Length <= 0) {
4456 + Console.Write (sUsingText);
4464 + Config config = new Config ();
4466 + OptionInfo infoHelp = GetOptionInfo ("help");
4467 + OptionInfo infoVerbose = GetOptionInfo ("verbose");
4468 + OptionInfo infoOut = GetOptionInfo ("out");
4469 + OptionInfo infoTypes = GetOptionInfo ("types");
4470 + OptionInfo infoReference = GetOptionInfo ("reference");
4471 + OptionInfo infoExtra = GetOptionInfo ("extra");
4472 + OptionInfo infoKeyfile = GetOptionInfo ("keyfile");
4473 + OptionInfo infoDelaysign = GetOptionInfo ("delaySign");
4474 + OptionInfo infoVersion = GetOptionInfo ("assembly-version");
4475 + OptionInfo infoProduct = GetOptionInfo ("assembly-product");
4476 + OptionInfo infoDescription = GetOptionInfo ("assembly-description");
4477 + OptionInfo infoCompany = GetOptionInfo ("assembly-company");
4478 + OptionInfo infoCopyright = GetOptionInfo ("assembly-copyright");
4479 + OptionInfo infoTrademark = GetOptionInfo ("assembly-trademark");
4482 + string cmdArg = null;
4484 + for (pos = 0; pos < sArgs.Length; ) {
4486 + if (IsOption (infoHelp, ref pos )) {
4487 + Console.Write (sUsingText);
4489 + } else if (ReadArgument (ref cmdArg, infoTypes, ref pos )) {
4490 + config.mExplicitTypes.AddRange (cmdArg.Split (new char[] {';'}));
4491 + } else if (ReadArgument (ref cmdArg, infoExtra, ref pos )) {
4492 + config.mExtraRegistries.Add (cmdArg);
4493 + } else if (ReadArgument (ref cmdArg, infoReference, ref pos )) {
4494 + config.mExtraAssemblies.Add (cmdArg);
4495 + } else if (!ReadOption (ref config.mVerbose, infoVerbose, ref pos) &&
4496 + !ReadArgument (ref config.mOutput, infoOut, ref pos) &&
4497 + !ReadArgument (ref config.mVersion, infoVersion, ref pos) &&
4498 + !ReadArgument (ref config.mDescription, infoDescription, ref pos) &&
4499 + !ReadArgument (ref config.mProduct, infoProduct, ref pos) &&
4500 + !ReadArgument (ref config.mCompany, infoCompany, ref pos) &&
4501 + !ReadArgument (ref config.mCopyright, infoCopyright, ref pos) &&
4502 + !ReadArgument (ref config.mTrademark, infoTrademark, ref pos) &&
4503 + !ReadArgument (ref config.mKeyfile, infoKeyfile, ref pos) &&
4504 + !ReadArgument (ref config.mDelaySign, infoDelaysign, ref pos)) {
4505 + cmdArg = args [pos];
4507 + cmdArg = cmdArg.Trim();
4509 + if (cmdArg.Length > 0) {
4510 + if (cmdArg [0] == '-') { // is option
4511 + OptionInfo optionInfo = null;
4513 + if (cmdArg.Length > 2 && cmdArg [1] == '-') {
4515 + optionInfo = GetOptionInfo (cmdArg.Substring (2));
4516 + } else if (cmdArg.Length == 2 && cmdArg [1] != '-') {
4518 + optionInfo = GetOptionInfo ("", cmdArg [1]);
4521 + if (optionInfo == null) {
4522 + Console.WriteLine ("unknown option " + cmdArg + "! Use climaker --help\nto print all options.");
4525 + Console.WriteLine ("unhandled valid option?! " + cmdArg);
4526 + if (optionInfo.mHasArgument)
4530 + config.mMandatoryRegistries.Add (cmdArg);
4536 + CliMaker cliMaker = new CliMaker (config);
4538 + cliMaker.OpenRegistries ();
4539 + cliMaker.PrepareAssembly ();
4542 + } catch (Exception e) {
4543 + Console.WriteLine ("\n> error: " + e + "\n> dying abnormally...");