Пример #1
0
        /// <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);
        }
Пример #2
0
        internal SyntaxTree Generate(NativeSymbolBag bag, ErrorProvider 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
            var transform   = new CodeTransform(_langaugeType, bag);
            var marshalUtil = new MarshalTransform(_langaugeType, bag, TransformKindFlags.All);
            var col         = new CodeTypeDeclarationCollection();

            // Only output the constants if there are actually any
            var constList = bag.FindResolvedConstants().ToList();

            if (constList.Count > 0)
            {
                var constCtd = transform.GenerateConstants(constList);
                if (constCtd.Members.Count > 0)
                {
                    col.Add(constCtd);
                }
            }

            foreach (var definedNt in bag.FindResolvedDefinedTypes())
            {
                var ctd = transform.GenerateDeclaration(definedNt);
                marshalUtil.Process(ctd);
                col.Add(ctd);
            }

            var procList = bag.FindResolvedProcedures().ToList();

            if (procList.Count > 0)
            {
                var 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
            var prettyLister = new CodeDomPrettyList(bag);

            prettyLister.PerformRename(col);

            var code = BasicConverter.ConvertCodeDomToPInvokeCodeImpl(_langaugeType, col, ep);

            return(CSharpSyntaxTree.ParseText(code));
        }