/// <summary> /// Core conversion routine. All code should just go through this /// </summary> /// <param name="bag"></param> /// <param name="ep"></param> /// <returns></returns> /// <remarks></remarks> private CodeTypeDeclarationCollection ConvertBagToCodeDom(NativeSymbolBag bag, ErrorProvider ep) { ThrowIfNull(bag); ThrowIfNull(ep); // Make sure than all of the referenced NativeDefinedType instances are in the correct // portion of the bag ChaseReferencedDefinedTypes(bag); // First step is to resolve the symbols bag.TryResolveSymbolsAndValues(ep); // Create the codedom transform CodeTransform transform = new CodeTransform(LanguageType, bag); MarshalTransform marshalUtil = new MarshalTransform(LanguageType, bag, TransformKindFlags); CodeTypeDeclarationCollection col = new CodeTypeDeclarationCollection(); // Only output the constants if there are actually any List <NativeConstant> list = new List <NativeConstant>(bag.FindResolvedConstants()); if (list.Count > 0) { CodeTypeDeclaration constCtd = transform.GenerateConstants(list); if (constCtd.Members.Count > 0) { col.Add(constCtd); } } foreach (NativeDefinedType definedNt in bag.FindResolvedDefinedTypes()) { CodeTypeDeclaration ctd = transform.GenerateDeclaration(definedNt); marshalUtil.Process(ctd); col.Add(ctd); } List <NativeProcedure> procList = new List <NativeProcedure>(bag.FindResolvedProcedures()); if (procList.Count > 0) { CodeTypeDeclaration procType = transform.GenerateProcedures(procList); marshalUtil.Process(procType); col.Add(procType); } // Add the helper types that we need AddHelperTypes(col); // Next step is to run the pretty lister on it CodeDomPrettyList prettyLister = new CodeDomPrettyList(bag); prettyLister.PerformRename(col); return(col); }
public MarshalTransform(LanguageType lang, NativeSymbolBag bag, TransformKindFlags kind) { _trans = new CodeTransform(lang, bag); Kind = kind; // Method Parameters _list.Add(new BooleanTypesTransformPlugin()); // Process BSTR types before any other string. BSTR can techinally be used as other String types // such as LPWSTR and the other string matching code will flag them as such. Therefore we will // process them first since the reverse is not true _list.Add(new BstrTransformPlugin()); _list.Add(new MutableStringBufferTransformPlugin()); _list.Add(new ConstantStringTransformPlugin()); _list.Add(new ArrayParameterTransformPlugin(_trans)); _list.Add(new BetterManagedTypesTransformPlugin()); _list.Add(new PointerToKnownTypeTransformPlugin(_trans)); _list.Add(new SystemIntTransformPlugin()); _list.Add(new RawStringTransformPlugin()); // Very low on the list as it's a last ditch effort _list.Add(new DoublePointerOutTransformPlugin()); _list.Add(new PointerPointerTransformPlugin()); _list.Add(new DirectionalModifiersTransformPlugin()); // Struct Member _list.Add(new StringBufferStructMemberTransformPlugin()); _list.Add(new StringPointerStructMemberTransformPlugin()); _list.Add(new BoolStructMemberTransformPlugin()); // Union Members _list.Add(new BoolUnionMemberTransformPlugin()); // Mainly wrapper generators _list.Add(new OneWayStringBufferTransformPlugin()); _list.Add(new TwoWayStringBufferTransformPlugin()); _list.Add(new TwoWayViaReturnStringBufferTransformPlugin()); _list.Add(new PInvokePointerTransformPlugin()); foreach (TransformPlugin cur in _list) { cur.LanguageType = lang; } }