Exemplo n.º 1
0
        public static void GenerateCode(string inputDir, string outputDir)
        {
            List <string> files = GetInputFileList();

            Overrides.XmlBindings.Settings overridesXmlData = XmlBindings.Utilities.LoadXmlData <Overrides.XmlBindings.Settings>(inputDir, "Settings.xml");
            Formatter.Prefix       = overridesXmlData.Prefix.Value;
            Formatter.Subnamespace = overridesXmlData.Subnamespace.Value;

            var filenameBase = overridesXmlData.FilenameBase.Value;

            List <D2DTypes> typeDocuments = new List <D2DTypes>();
            Dictionary <string, QualifiableType> typeDictionary = new Dictionary <string, QualifiableType>();
            OutputDataTypes outputDataTypes = new OutputDataTypes();

            foreach (string fileName in files)
            {
                XmlBindings.D2DTypes xmlDocument = XmlBindings.Utilities.LoadXmlData <XmlBindings.D2DTypes>(inputDir, fileName);
                typeDocuments.Add(new D2DTypes(xmlDocument, overridesXmlData, typeDictionary, outputDataTypes));
            }

            Directory.CreateDirectory(outputDir);
            OutputFiles outputFiles = new OutputFiles();

            using (Formatter cppStreamWriter = new Formatter(Path.Combine(outputDir, filenameBase + ".codegen.cpp")),
                   idlStreamWriter = new Formatter(Path.Combine(outputDir, filenameBase + ".codegen.idl")))
            {
                outputFiles.CppFile = cppStreamWriter;
                outputFiles.IdlFile = idlStreamWriter;

                outputDataTypes.OutputCode(typeDictionary, outputFiles);
            }
        }
Exemplo n.º 2
0
        public D2DTypes(XmlBindings.D2DTypes xmlData, Overrides.XmlBindings.Settings overrides, Dictionary<string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes)
        {
            const Namespace globalNamespace = null; // Using null as the namespace parameter indicates the global namespace.

            m_primitiveList = new List<Primitive>();
            foreach(XmlBindings.Primitive p in xmlData.Primitives)
            {
                Overrides.XmlBindings.Primitive overridePrimitive = null;
                if (overrides != null) overridePrimitive = overrides.Primitives.Find(x => x.Name == p.Name);

                m_primitiveList.Add(new Primitive(p, overridePrimitive, typeDictionary));
            }

            m_structList = new List<Struct>();
            foreach (XmlBindings.Struct s in xmlData.Structs)
            {
                Overrides.XmlBindings.Struct overrideStruct = null;
                if (overrides != null) overrideStruct = overrides.Structs.Find(x => x.Name == s.Name);

                m_structList.Add(new Struct(globalNamespace, s, overrideStruct, typeDictionary, outputDataTypes));
            }

            m_namespaceList = new List<Namespace>();
            foreach (XmlBindings.Namespace n in xmlData.Namespaces)
            {
                Overrides.XmlBindings.Namespace overrideNamespace = null;
                if (overrides != null) overrideNamespace = overrides.Namespaces.Find(x => x.Name == n.Name);

                m_namespaceList.Add(new Namespace(n, overrideNamespace, overrides.RootNamespace.Value, typeDictionary, outputDataTypes));
            }
        }
Exemplo n.º 3
0
        public static void OutputEffectCpp(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            bool isInputSizeFixed = !EffectHasVariableNumberOfInputs(effect);
            int  inputsCount      = isInputSizeFixed ? effect.Inputs.InputsList.Count : 0;

            output.WriteLine("#include \"pch.h\"");
            output.WriteLine("#include \"" + effect.ClassName + ".h\"");
            output.WriteLine();
            output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine(effect.ClassName + "::" + effect.ClassName + "()");
            output.WriteIndent();
            output.WriteLine(": CanvasEffect(CLSID_D2D1"
                             + EffectGenerator.FormatClassName(effect.Properties[0].Value) + ", "
                             + (effect.Properties.Count(p => !p.IsHandCoded) - 4) + ", "
                             + inputsCount + ", "
                             + isInputSizeFixed.ToString().ToLower() + ")");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("// Set default values");

            foreach (var property in effect.Properties)
            {
                WritePropertyInitialization(output, property);
            }
            output.Unindent();
            output.WriteLine("}");
            output.WriteLine();
            foreach (var property in effect.Properties)
            {
                WritePropertyImplementation(effect, output, property);
            }

            if (EffectHasVariableNumberOfInputs(effect))
            {
                output.WriteLine("IMPLEMENT_EFFECT_SOURCES_PROPERTY(" + effect.ClassName + ")");
                output.WriteLine();
            }
            else
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];
                    output.WriteLine("IMPLEMENT_EFFECT_SOURCE_PROPERTY(" + effect.ClassName + ",");
                    output.Indent();
                    output.WriteLine(input.Name + ",");
                    output.WriteLine(i.ToString() + ")");
                    output.Unindent();
                    output.WriteLine();
                }
            }

            output.WriteLine("ActivatableClass(" + effect.ClassName + ");");

            output.Unindent();
            output.WriteLine("}}}}}");
        }
Exemplo n.º 4
0
        public static void OutputCommonEnums(List <Effects.Effect> effects, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("namespace Microsoft.Graphics.Canvas.Effects");
            output.WriteLine("{");
            output.Indent();
            bool isFirstOutput = true;

            foreach (var effect in effects)
            {
                foreach (var property in effect.Properties)
                {
                    // Check if property represent enum that is common to some group of effects
                    if (property.Type == "enum" && property.EnumFields.IsRepresentative && property.ShouldProject)
                    {
                        // Check if any registred property need this enum
                        if (effects.Any(e => e.Properties.Any(p => p.TypeNameIdl == property.TypeNameIdl)))
                        {
                            if (isFirstOutput)
                            {
                                isFirstOutput = false;
                            }
                            else
                            {
                                output.WriteLine();
                            }
                            OutputEnum(property, output);
                        }
                    }
                }
            }
            output.Unindent();
            output.WriteLine("}");
        }
Exemplo n.º 5
0
        public static void OutputEffectHeader(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("#pragma once");
            output.WriteLine();
            output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects ");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("using namespace ::Microsoft::WRL;");
            output.WriteLine("using namespace ABI::Microsoft::Graphics::Canvas;");
            output.WriteLine();
            output.WriteLine("class " + effect.ClassName + " : public RuntimeClass<");
            output.Indent();
            output.WriteLine(effect.InterfaceName + ",");
            output.WriteLine("MixIn<" + effect.ClassName + ", CanvasEffect>>,");
            output.WriteLine("public CanvasEffect");
            output.Unindent();
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("InspectableClass(RuntimeClass_Microsoft_Graphics_Canvas_Effects_" + effect.ClassName + ", BaseTrust);");
            output.WriteLine();
            output.Unindent();
            output.WriteLine("public:");
            output.Indent();
            output.WriteLine(effect.ClassName + "();");
            output.WriteLine();

            foreach (var property in effect.Properties)
            {
                // Property with type string describes
                // name/author/category/description of effect but not input type
                if (property.Type == "string" || property.IsHidden)
                {
                    continue;
                }

                var propertyMacro = property.IsArray ? "EFFECT_ARRAY_PROPERTY" : "EFFECT_PROPERTY";

                output.WriteLine(propertyMacro + "(" + property.Name + ", " + property.TypeNameCpp + ");");
            }

            if (EffectHasVariableNumberOfInputs(effect))
            {
                output.WriteLine("EFFECT_SOURCES_PROPERTY();");
            }
            else
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];
                    output.WriteLine("EFFECT_PROPERTY(" + input.Name + ", IGraphicsEffectSource*);");
                }
            }
            output.Unindent();
            output.WriteLine("};");
            output.Unindent();
            output.WriteLine("}}}}}");
        }
Exemplo n.º 6
0
        public static void OutputEffectMakers(List <Effects.Effect> effects, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("#include \"pch.h\"");
            output.WriteLine();

            var enabledEffects = from effect in effects
                                 where EffectGenerator.IsEffectEnabled(effect)
                                 select effect;

            var effectsByVersion = from effect in enabledEffects
                                   orderby effect.ClassName
                                   group effect by(effect.Overrides != null?effect.Overrides.WinVer : null) into versionGroup
                                   orderby versionGroup.Key
                                   select versionGroup;

            foreach (var versionGroup in effectsByVersion)
            {
                OutputVersionConditional(versionGroup.Key, output);

                foreach (var effect in versionGroup)
                {
                    output.WriteLine("#include \"" + effect.ClassName + ".h\"");
                }

                EndVersionConditional(versionGroup.Key, output);
                output.WriteLine();
            }

            output.WriteLine();
            output.WriteLine("std::pair<IID, CanvasEffect::MakeEffectFunction> CanvasEffect::m_effectMakers[] =");
            output.WriteLine("{");

            int longestName = enabledEffects.Select(effect => effect.ClassName.Length).Max();

            foreach (var versionGroup in effectsByVersion)
            {
                OutputVersionConditional(versionGroup.Key, output);
                output.Indent();

                foreach (var effect in versionGroup)
                {
                    string padding = new string(' ', longestName - effect.ClassName.Length);

                    output.WriteLine("{ " + effect.ClassName + "::EffectId(), " + padding + "MakeEffect<" + effect.ClassName + "> " + padding + "},");
                }

                output.Unindent();
                EndVersionConditional(versionGroup.Key, output);
                output.WriteLine();
            }

            output.Indent();
            output.WriteLine("{ GUID_NULL, nullptr }");
            output.Unindent();

            output.WriteLine("};");
        }
Exemplo n.º 7
0
        public static void OutputEffectHeader(Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("#pragma once");
            output.WriteLine();
            output.WriteLine("#include <CanvasImage.h>");
            output.WriteLine();
            output.WriteLine("#include \"ClosablePtr.h\"");
            output.WriteLine("#include \"ResourceManager.h\"");
            output.WriteLine("#include \"effects\\CanvasEffect.h\"");
            output.WriteLine();
            output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects ");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("using namespace ::Microsoft::WRL;");
            output.WriteLine("using namespace ABI::Microsoft::Graphics::Canvas;");
            output.WriteLine();
            output.WriteLine("class " + effect.ClassName + " : public RuntimeClass<");
            output.Indent();
            output.WriteLine(effect.InterfaceName + ",");
            output.WriteLine("MixIn<" + effect.ClassName + ", CanvasEffect>>,");
            output.WriteLine("public CanvasEffect");
            output.Unindent();
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("InspectableClass(RuntimeClass_Microsoft_Graphics_Canvas_Effects_" + effect.ClassName + ", BaseTrust);");
            output.WriteLine();
            output.Unindent();
            output.WriteLine("public:");
            output.Indent();
            output.WriteLine(effect.ClassName + "();");
            output.WriteLine();

            foreach (var property in effect.Properties)
            {
                // Property with type string describes
                // name/author/category/description of effect but not input type
                if (property.Type == "string")
                {
                    continue;
                }

                output.WriteLine("PROPERTY(" + property.Name + ", " + property.TypeNameCpp + ");");
            }

            if (!(effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF"))
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];
                    output.WriteLine("PROPERTY(" + input.Name + ", IEffectInput*);");
                }
            }
            output.Unindent();
            output.WriteLine("};");
            output.Unindent();
            output.WriteLine("}}}}}");
        }
Exemplo n.º 8
0
        public Namespace(XmlBindings.Namespace xmlData, Overrides.XmlBindings.Namespace overrides, string rootProjectedNamespace, Dictionary<string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes)
        {
            m_rawName = xmlData.Name;

            if (overrides != null && overrides.NameOverride != null)
            {
                m_apiName = overrides.NameOverride;
            }
            else
            {
                m_apiName = xmlData.Name;
            }

            m_enums = new List<Enum>();
            foreach (XmlBindings.Enum enumXml in xmlData.Enums)
            {
                Overrides.XmlBindings.Enum overridesEnum = null;
                if (overrides != null) overridesEnum = overrides.Enums.Find(x => x.Name == enumXml.Name);

                m_enums.Add(new Enum(this, rootProjectedNamespace, enumXml, overridesEnum, typeDictionary, outputDataTypes));
            }

            m_structs = new List<Struct>();
            foreach (XmlBindings.Struct structXml in xmlData.Structs)
            {
                Overrides.XmlBindings.Struct overridesStruct = null;
                if (overrides != null) overridesStruct = overrides.Structs.Find(x => x.Name == structXml.Name);

                m_structs.Add(new Struct(this, structXml, overridesStruct, typeDictionary, outputDataTypes));
            }

            m_interfaces = new List<Interface>();
            foreach (XmlBindings.Interface interfaceXml in xmlData.Interfaces)
            {
                Overrides.XmlBindings.Interface overridesInterface = null;
                if (overrides != null) overridesInterface = overrides.Interfaces.Find(x => x.Name == interfaceXml.Name);

                m_interfaces.Add(new Interface(this, interfaceXml, overridesInterface, typeDictionary));
            }

            foreach (XmlBindings.Typedef t in xmlData.Typedefs)
            {
                // In the types XML, often times types are declared as one type,
                // then typedefs to something else, and referenced thereafter
                // as that second type. And so, typedefs must be handled here.
                //
                // In the XML, the 'Name' field in each typedef is unqualified,
                // but the 'From' field is qualified.
                // For example, <Typedef Name="COLOR_F" From="D2D::COLOR_F"/>
                //
                // So, the entries are added to the type dictionary here
                // under the qualified name.
                //
                string qualified = xmlData.Name + "::" + t.Name;
                typeDictionary[qualified] = typeDictionary[t.From];
            }
        }
Exemplo n.º 9
0
        public static void OutputEffectCpp(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            bool isInputSizeFixed = !EffectHasVariableNumberOfInputs(effect);
            int  inputsCount      = isInputSizeFixed ? effect.Inputs.InputsList.Count : 0;

            output.WriteLine("#include \"pch.h\"");
            output.WriteLine("#include \"" + effect.ClassName + ".h\"");
            output.WriteLine();

            OutputVersionConditional(effect, output);

            output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine(effect.ClassName + "::" + effect.ClassName + "(ICanvasDevice* device, ID2D1Effect* effect)");
            output.WriteIndent();
            output.WriteLine(": CanvasEffect(EffectId(), "
                             + (effect.Properties.Count(p => (!p.IsHandCoded && !p.IsHdrAlias)) - 4) + ", "
                             + inputsCount + ", "
                             + isInputSizeFixed.ToString().ToLower() + ", "
                             + "device, effect, static_cast<" + effect.InterfaceName + "*>(this))");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("if (!effect)");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("// Set default values");

            foreach (var property in effect.Properties)
            {
                WritePropertyInitialization(output, property);
            }
            output.Unindent();
            output.WriteLine("}");
            output.Unindent();
            output.WriteLine("}");
            output.WriteLine();
            foreach (var property in effect.Properties)
            {
                WritePropertyImplementation(effect, output, property);
            }

            if (EffectHasVariableNumberOfInputs(effect))
            {
                output.WriteLine("IMPLEMENT_EFFECT_SOURCES_PROPERTY(" + effect.ClassName + ")");
                output.WriteLine();
            }
            else
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];
                    output.WriteLine("IMPLEMENT_EFFECT_SOURCE_PROPERTY(" + effect.ClassName + ",");
                    output.Indent();
                    output.WriteLine(input.Name + ",");
                    output.WriteLine(i.ToString() + ")");
                    output.Unindent();
                    output.WriteLine();
                }
            }

            WritePropertyMapping(effect, output);

            if (effect.Overrides == null || !effect.Overrides.HasStatics)
            {
                output.WriteLine("ActivatableClass(" + effect.ClassName + ");");
            }

            output.Unindent();
            output.WriteLine("}}}}}");

            EndVersionConditional(effect, output);
        }
Exemplo n.º 10
0
        public static void OutputEffectHeader(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("#pragma once");
            output.WriteLine();

            OutputVersionConditional(effect, output);

            output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects ");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("using namespace ::Microsoft::WRL;");
            output.WriteLine("using namespace ABI::Microsoft::Graphics::Canvas;");
            output.WriteLine();
            output.WriteLine("class " + effect.ClassName + " : public RuntimeClass<");
            output.Indent();
            output.WriteLine(effect.InterfaceName + ",");
            output.WriteLine("MixIn<" + effect.ClassName + ", CanvasEffect>>,");
            output.WriteLine("public CanvasEffect");
            output.Unindent();
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("InspectableClass(RuntimeClass_Microsoft_Graphics_Canvas_Effects_" + effect.ClassName + ", BaseTrust);");
            output.WriteLine();
            output.Unindent();
            output.WriteLine("public:");
            output.Indent();
            output.WriteLine(effect.ClassName + "(ICanvasDevice* device = nullptr, ID2D1Effect* effect = nullptr);");
            output.WriteLine();
            output.WriteLine("static IID const& EffectId() { return " + GetEffectCLSID(effect) + "; }");
            output.WriteLine();

            foreach (var property in effect.Properties)
            {
                // Property with type string describes
                // name/author/category/description of effect but not input type
                if (property.Type == "string" || property.IsHidden)
                {
                    continue;
                }

                var propertyMacro = property.IsArray ? "EFFECT_ARRAY_PROPERTY" : "EFFECT_PROPERTY";

                output.WriteLine(propertyMacro + "(" + property.Name + ", " + property.TypeNameCpp + ");");
            }

            if (EffectHasVariableNumberOfInputs(effect))
            {
                output.WriteLine("EFFECT_SOURCES_PROPERTY();");
            }
            else
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];
                    output.WriteLine("EFFECT_PROPERTY(" + input.Name + ", IGraphicsEffectSource*);");
                }
            }

            bool hasPropertyMapping          = effect.Properties.Any(IsGeneratablePropertyMapping);
            bool hasHandCodedPropertyMapping = effect.Properties.Any(p => p.IsHandCoded);

            if (hasPropertyMapping || hasHandCodedPropertyMapping)
            {
                output.WriteLine();

                if (hasPropertyMapping)
                {
                    output.WriteLine("EFFECT_PROPERTY_MAPPING();");
                }

                if (hasHandCodedPropertyMapping)
                {
                    output.WriteLine("EFFECT_PROPERTY_MAPPING_HANDCODED();");
                }
            }

            output.Unindent();
            output.WriteLine("};");
            output.Unindent();
            output.WriteLine("}}}}}");

            EndVersionConditional(effect, output);
        }
Exemplo n.º 11
0
        public static void OutputEffectIdl(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            OutputVersionConditional(effect, output);

            output.WriteLine("namespace Microsoft.Graphics.Canvas.Effects");
            output.WriteLine("{");
            output.Indent();

            // Output all enums specific to this effect
            foreach (var property in effect.Properties)
            {
                if (property.Type == "enum" &&
                    property.EnumFields.Usage == Effects.EnumValues.UsageType.UsedByOneEffect &&
                    property.ShouldProject)
                {
                    OutputEnum(property, output);
                    output.WriteLine();
                }
            }

            output.WriteLine("runtimeclass " + effect.ClassName + ";");
            output.WriteLine();
            output.WriteLine("[version(VERSION), uuid(" + effect.Uuid + "), exclusiveto(" + effect.ClassName + ")]");
            output.WriteLine("interface " + effect.InterfaceName + " : IInspectable");
            output.WriteIndent();
            output.WriteLine("requires ICanvasEffect");
            output.WriteLine("{");
            output.Indent();

            foreach (var property in effect.Properties)
            {
                // Property with type string describes
                // name/author/category/description of effect but not input type
                if (property.Type == "string" || property.IsHidden)
                {
                    continue;
                }

                output.WriteLine("[propget]");
                if (property.IsArray)
                {
                    output.WriteLine("HRESULT " + property.Name + "([out] UINT32* valueCount, [out, size_is(, *valueCount), retval] " + property.TypeNameIdl + "** valueElements);");
                }
                else
                {
                    output.WriteLine("HRESULT " + property.Name + "([out, retval] " + property.TypeNameIdl + "* value);");
                }
                output.WriteLine();

                output.WriteLine("[propput]");
                if (property.IsArray)
                {
                    output.WriteLine("HRESULT " + property.Name + "([in] UINT32 valueCount, [in, size_is(valueCount)] " + property.TypeNameIdl + "* valueElements);");
                }
                else
                {
                    output.WriteLine("HRESULT " + property.Name + "([in] " + property.TypeNameIdl + " value);");
                }
                output.WriteLine();
            }

            if (EffectHasVariableNumberOfInputs(effect))
            {
                output.WriteLine("[propget]");
                output.WriteLine("HRESULT Sources([out, retval] Windows.Foundation.Collections.IVector<IGRAPHICSEFFECTSOURCE*>** value);");
                output.WriteLine();
            }
            else
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];

                    output.WriteLine("[propget]");
                    output.WriteLine("HRESULT " + input.Name + "([out, retval] IGRAPHICSEFFECTSOURCE** source);");
                    output.WriteLine();

                    output.WriteLine("[propput]");
                    output.WriteLine("HRESULT " + input.Name + "([in] IGRAPHICSEFFECTSOURCE* source);");
                    output.WriteLine();
                }
            }

            output.Unindent();
            output.WriteLine("};");
            output.WriteLine();

            string statics = "";

            if (effect.Overrides != null && effect.Overrides.HasStatics)
            {
                statics = ", static(" + effect.InterfaceName + "Statics, VERSION)";
            }

            output.WriteLine("[version(VERSION), activatable(VERSION)" + statics + "]");

            output.WriteLine("runtimeclass " + effect.ClassName);
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("[default] interface " + effect.InterfaceName + ";");
            output.Unindent();
            output.WriteLine("}");
            output.Unindent();
            output.WriteLine("}");

            EndVersionConditional(effect, output);
        }
Exemplo n.º 12
0
        public Struct(Namespace parentNamespace, XmlBindings.Struct xmlData, Overrides.XmlBindings.Struct overrideData, Dictionary<string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes)
        {
            if (parentNamespace != null)
            {
                m_rawName = parentNamespace.ApiName + "_" + xmlData.Name;
                typeDictionary[parentNamespace.RawName + "::" + xmlData.Name] = this;
            }
            else
            {
                m_rawName = xmlData.Name;
                typeDictionary[xmlData.Name] = this;
            }

            m_stylizedName = Formatter.Prefix + Formatter.StylizeNameFromUnderscoreSeparators(xmlData.Name);
            
            if(overrideData != null)
            {
                if(overrideData.Guid != null)
                {
                    m_guid = overrideData.Guid;
                }

                if(overrideData.ProjectedNameOverride != null)
                {
                    if (overrideData.ShouldProject)
                        m_stylizedName = Formatter.Prefix + overrideData.ProjectedNameOverride;
                    else
                        m_stylizedName = overrideData.ProjectedNameOverride;
                }

                if(overrideData.IdlNamespaceQualifier != null)
                {
                    m_idlTypeNameQualifier = overrideData.IdlNamespaceQualifier;
                }
            }

            m_idlInterfaceName = "I" + m_stylizedName;

            m_structFields = new List<StructField>();
            foreach(XmlBindings.StructField structXmlData in xmlData.Fields)
            {
                m_structFields.Add(new StructField(structXmlData));
            }
            if (xmlData.Extends != null)
            {
                m_extendsTypeName = xmlData.Extends;

                // Note: the Extends field is already qualified. See D2DTypes.xml. Example: Extends="D2D1::IImage"
                QualifiableType parentType = typeDictionary[m_extendsTypeName];

                Struct parentAsStruct = parentType as Struct; // Structs should only be deriving from struct types
                m_structFields.InsertRange(0, parentAsStruct.Fields);
                Debug.Assert(parentAsStruct.ExtendsTypeName == null); // Multiple levels in the hierarchy are not supported at this time.
            }

            // For the time being, unions are not output (they are very uncommon).
            bool usesUnions = xmlData.Fields == null;

            // Structs in the global namespace are defined as aliases only. By convention, only structs in a namespace are output.
            if (parentNamespace != null && !usesUnions  && (overrideData != null && overrideData.ShouldProject))
            {
                outputDataTypes.AddStruct(this);
            }
        }
Exemplo n.º 13
0
        public Enum(Namespace parentNamespace, string rootProjectedNamespace, XmlBindings.Enum xmlData, Overrides.XmlBindings.Enum overrides, Dictionary <string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes)
        {
            m_stylizedName = Formatter.Prefix + Formatter.StylizeNameFromUnderscoreSeparators(xmlData.Name);

            if (parentNamespace != null)
            {
                m_rawName = parentNamespace.ApiName + "_" + xmlData.Name;
                typeDictionary[parentNamespace.RawName + "::" + xmlData.Name] = this;
            }
            else
            {
                //
                // Namespace of NULL indicates the global namespace.
                // These types aren't D2D types, and their full native name is
                // exactly what's in the name field (no need to prepend anything).
                //
                m_rawName = xmlData.Name;
                typeDictionary[xmlData.Name] = this;
            }

            m_isFlags = xmlData.IsFlags;

            m_enumValues = new List <EnumValue>();
            foreach (XmlBindings.EnumValue valueXml in xmlData.EnumValues)
            {
                Overrides.XmlBindings.EnumValue overridesEnumValue = null;
                if (overrides != null)
                {
                    overridesEnumValue = overrides.Values.Find(x => x.Name == valueXml.Name);
                }

                m_enumValues.Add(new EnumValue(valueXml, m_rawName, overridesEnumValue));
            }

            Namespace = rootProjectedNamespace;

            bool shouldProject = false;

            if (overrides != null)
            {
                shouldProject = overrides.ShouldProject;

                if (overrides.ProjectedNameOverride != null)
                {
                    m_stylizedName = Formatter.Prefix + overrides.ProjectedNameOverride;
                }

                if (overrides.Namespace != null)
                {
                    Namespace = Namespace + "." + overrides.Namespace;
                }
            }

            // One of the XML files has a mistake where it doesn't properly order its enums.
            if (m_isFlags)
            {
                m_enumValues.Sort(new EnumValueComparer());
            }

            // Enums in the global namespace are defined as aliases only. By convention, only enums in a namespace are output.
            if (parentNamespace != null && shouldProject)
            {
                outputDataTypes.AddEnum(this);
            }
        }
Exemplo n.º 14
0
        public Namespace(XmlBindings.Namespace xmlData, Overrides.XmlBindings.Namespace overrides, Dictionary <string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes)
        {
            m_rawName = xmlData.Name;

            if (overrides != null && overrides.NameOverride != null)
            {
                m_apiName = overrides.NameOverride;
            }
            else
            {
                m_apiName = xmlData.Name;
            }

            m_enums = new List <Enum>();
            foreach (XmlBindings.Enum enumXml in xmlData.Enums)
            {
                Overrides.XmlBindings.Enum overridesEnum = null;
                if (overrides != null)
                {
                    overridesEnum = overrides.Enums.Find(x => x.Name == enumXml.Name);
                }

                m_enums.Add(new Enum(this, enumXml, overridesEnum, typeDictionary, outputDataTypes));
            }

            m_structs = new List <Struct>();
            foreach (XmlBindings.Struct structXml in xmlData.Structs)
            {
                Overrides.XmlBindings.Struct overridesStruct = null;
                if (overrides != null)
                {
                    overridesStruct = overrides.Structs.Find(x => x.Name == structXml.Name);
                }

                m_structs.Add(new Struct(this, structXml, overridesStruct, typeDictionary, outputDataTypes));
            }

            m_interfaces = new List <Interface>();
            foreach (XmlBindings.Interface interfaceXml in xmlData.Interfaces)
            {
                Overrides.XmlBindings.Interface overridesInterface = null;
                if (overrides != null)
                {
                    overridesInterface = overrides.Interfaces.Find(x => x.Name == interfaceXml.Name);
                }

                m_interfaces.Add(new Interface(this, interfaceXml, overridesInterface, typeDictionary));
            }

            foreach (XmlBindings.Typedef t in xmlData.Typedefs)
            {
                // In the types XML, often times types are declared as one type,
                // then typedefs to something else, and referenced thereafter
                // as that second type. And so, typedefs must be handled here.
                //
                // In the XML, the 'Name' field in each typedef is unqualified,
                // but the 'From' field is qualified.
                // For example, <Typedef Name="COLOR_F" From="D2D::COLOR_F"/>
                //
                // So, the entries are added to the type dictionary here
                // under the qualified name.
                //
                string qualified = xmlData.Name + "::" + t.Name;
                typeDictionary[qualified] = typeDictionary[t.From];
            }
        }
Exemplo n.º 15
0
        public static void OutputEffectCpp(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            bool isInputSizeFixed = !EffectHasVariableNumberOfInputs(effect);
            int  inputsCount      = isInputSizeFixed ? effect.Inputs.InputsList.Count : 0;

            output.WriteLine("#include \"pch.h\"");
            output.WriteLine("#include \"" + effect.ClassName + ".h\"");
            output.WriteLine();

            OutputVersionConditional(effect, output);

            output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine(effect.ClassName + "::" + effect.ClassName + "(ICanvasDevice* device, ID2D1Effect* effect)");
            output.WriteIndent();
            output.WriteLine(": CanvasEffect(EffectId(), "
                             + (effect.Properties.Count(p => (!p.IsHandCoded && !p.IsHdrAlias)) - 4) + ", "
                             + inputsCount + ", "
                             + isInputSizeFixed.ToString().ToLower() + ", "
                             + "device, effect, static_cast<" + effect.InterfaceName + "*>(this))");
            output.WriteLine("{");
            output.Indent();

            if (effect.Overrides != null && !string.IsNullOrEmpty(effect.Overrides.IsSupportedCheck))
            {
                output.WriteLine("if (!SharedDeviceState::GetInstance()->Is" + effect.Overrides.IsSupportedCheck + "Supported())");
                output.Indent();
                output.WriteLine("ThrowHR(E_NOTIMPL, Strings::NotSupportedOnThisVersionOfWindows);");
                output.Unindent();
                output.WriteLine();
            }

            output.WriteLine("if (!effect)");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("// Set default values");

            foreach (var property in effect.Properties)
            {
                WritePropertyInitialization(output, property);
            }
            output.Unindent();
            output.WriteLine("}");
            output.Unindent();
            output.WriteLine("}");
            output.WriteLine();
            foreach (var property in effect.Properties)
            {
                WritePropertyImplementation(effect, output, property);
            }

            if (EffectHasVariableNumberOfInputs(effect))
            {
                output.WriteLine("IMPLEMENT_EFFECT_SOURCES_PROPERTY(" + effect.ClassName + ")");
                output.WriteLine();
            }
            else
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];
                    output.WriteLine("IMPLEMENT_EFFECT_SOURCE_PROPERTY(" + effect.ClassName + ",");
                    output.Indent();
                    output.WriteLine(input.Name + ",");
                    output.WriteLine(i.ToString() + ")");
                    output.Unindent();
                    output.WriteLine();
                }
            }

            WritePropertyMapping(effect, output);

            if (HasStatics(effect))
            {
                output.WriteLine("IFACEMETHODIMP " + effect.ClassName + "Factory::ActivateInstance(IInspectable** instance)");
                output.WriteLine("{");
                output.Indent();
                output.WriteLine("return ExceptionBoundary([&]");
                output.WriteLine("{");
                output.Indent();
                output.WriteLine("auto effect = Make<" + effect.ClassName + ">();");
                output.WriteLine("CheckMakeResult(effect);");
                output.WriteLine();
                output.WriteLine("ThrowIfFailed(effect.CopyTo(instance));");
                output.Unindent();
                output.WriteLine("});");
                output.Unindent();
                output.WriteLine("}");
                output.WriteLine();

                if (!string.IsNullOrEmpty(effect.Overrides.IsSupportedCheck))
                {
                    output.WriteLine("IFACEMETHODIMP " + effect.ClassName + "Factory::get_IsSupported(_Out_ boolean* result)");
                    output.WriteLine("{");
                    output.Indent();
                    output.WriteLine("return ExceptionBoundary([&]");
                    output.WriteLine("{");
                    output.Indent();
                    output.WriteLine("CheckInPointer(result);");
                    output.WriteLine("*result = SharedDeviceState::GetInstance()->Is" + effect.Overrides.IsSupportedCheck + "Supported();");
                    output.Unindent();
                    output.WriteLine("});");
                    output.Unindent();
                    output.WriteLine("}");
                    output.WriteLine();
                }

                output.WriteLine("ActivatableClassWithFactory(" + effect.ClassName + ", " + effect.ClassName + "Factory);");
            }
            else
            {
                output.WriteLine("ActivatableClassWithFactory(" + effect.ClassName + ", SimpleAgileActivationFactory<" + effect.ClassName + ">);");
            }

            output.Unindent();
            output.WriteLine("}}}}}");

            EndVersionConditional(effect, output);
        }
Exemplo n.º 16
0
        public static void OutputEffectIdl(Effects.Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            output.WriteLine("namespace Microsoft.Graphics.Canvas.Effects");
            output.WriteLine("{");
            output.Indent();

            // Output all enums specific to this effect
            foreach (var property in effect.Properties)
            {
                if (property.Type == "enum" &&
                    property.EnumFields.Usage == Effects.EnumValues.UsageType.UsedByOneEffect &&
                    property.ShouldProject)
                {
                    OutputEnum(property, output);
                    output.WriteLine();
                }
            }

            output.WriteLine("runtimeclass " + effect.ClassName + ";");
            output.WriteLine();
            output.WriteLine("[version(VERSION), uuid(" + effect.Uuid + "), exclusiveto(" + effect.ClassName + ")]");
            output.WriteLine("interface " + effect.InterfaceName + " : IInspectable");
            output.WriteIndent();
            output.WriteLine("requires Microsoft.Graphics.Canvas.ICanvasImage");
            output.WriteLine("{");
            output.Indent();

            foreach (var property in effect.Properties)
            {
                // Property with type string describes
                // name/author/category/description of effect but not input type
                if (property.Type == "string" || property.IsHidden)
                {
                    continue;
                }

                output.WriteLine("[propget]");
                if (property.IsArray)
                {
                    output.WriteLine("HRESULT " + property.Name + "([out] UINT32* valueCount, [out, size_is(, *valueCount), retval] " + property.TypeNameIdl + "** valueElements);");
                }
                else
                {
                    output.WriteLine("HRESULT " + property.Name + "([out, retval] " + property.TypeNameIdl + "* value);");
                }
                output.WriteLine();

                output.WriteLine("[propput]");
                if (property.IsArray)
                {
                    output.WriteLine("HRESULT " + property.Name + "([in] UINT32 valueCount, [in, size_is(valueCount)] " + property.TypeNameIdl + "* valueElements);");
                }
                else
                {
                    output.WriteLine("HRESULT " + property.Name + "([in] " + property.TypeNameIdl + " value);");
                }
                output.WriteLine();
            }

            // Check if inputs specify maximum attribute in xml and if it is marked as unlimited
            if (!(effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF"))
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];

                    output.WriteLine("[propget]");
                    output.WriteLine("HRESULT " + input.Name + "([out, retval] IEffectInput** input);");
                    output.WriteLine();

                    output.WriteLine("[propput]");
                    output.WriteLine("HRESULT " + input.Name + "([in] IEffectInput* input);");
                    output.WriteLine();
                }
            }

            output.Unindent();
            output.WriteLine("};");
            output.WriteLine();

            output.WriteLine("[version(VERSION), activatable(VERSION)]");
            output.WriteLine("runtimeclass " + effect.ClassName);
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("[default] interface " + effect.InterfaceName + ";");
            output.WriteLine("interface IEffect;");
            output.Unindent();
            output.WriteLine("}");
            output.Unindent();
            output.WriteLine("}");
        }
Exemplo n.º 17
0
        public Struct(Namespace parentNamespace, XmlBindings.Struct xmlData, Overrides.XmlBindings.Struct overrideData, Dictionary <string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes)
        {
            if (parentNamespace != null)
            {
                m_rawName = parentNamespace.ApiName + "_" + xmlData.Name;
                typeDictionary[parentNamespace.RawName + "::" + xmlData.Name] = this;
            }
            else
            {
                m_rawName = xmlData.Name;
                typeDictionary[xmlData.Name] = this;
            }

            m_stylizedName = Formatter.Prefix + Formatter.StylizeNameFromUnderscoreSeparators(xmlData.Name);

            if (overrideData != null)
            {
                if (overrideData.Guid != null)
                {
                    m_guid = overrideData.Guid;
                }

                if (overrideData.ProjectedNameOverride != null)
                {
                    if (overrideData.ShouldProject)
                    {
                        m_stylizedName = Formatter.Prefix + overrideData.ProjectedNameOverride;
                    }
                    else
                    {
                        m_stylizedName = overrideData.ProjectedNameOverride;
                    }
                }

                if (overrideData.IdlNamespaceQualifier != null)
                {
                    m_idlTypeNameQualifier = overrideData.IdlNamespaceQualifier;
                }
            }

            m_idlInterfaceName = "I" + m_stylizedName;

            m_structFields = new List <StructField>();
            foreach (XmlBindings.StructField structXmlData in xmlData.Fields)
            {
                m_structFields.Add(new StructField(structXmlData));
            }
            if (xmlData.Extends != null)
            {
                m_extendsTypeName = xmlData.Extends;

                // Note: the Extends field is already qualified. See D2DTypes.xml. Example: Extends="D2D1::IImage"
                QualifiableType parentType = typeDictionary[m_extendsTypeName];

                Struct parentAsStruct = parentType as Struct;         // Structs should only be deriving from struct types
                m_structFields.InsertRange(0, parentAsStruct.Fields);
                Debug.Assert(parentAsStruct.ExtendsTypeName == null); // Multiple levels in the hierarchy are not supported at this time.
            }

            // For the time being, unions are not output (they are very uncommon).
            bool usesUnions = xmlData.Fields == null;

            // Structs in the global namespace are defined as aliases only. By convention, only structs in a namespace are output.
            if (parentNamespace != null && !usesUnions && (overrideData != null && overrideData.ShouldProject))
            {
                outputDataTypes.AddStruct(this);
            }
        }
Exemplo n.º 18
0
        public D2DTypes(XmlBindings.D2DTypes xmlData, Overrides.XmlBindings.Settings overrides, Dictionary <string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes)
        {
            const Namespace globalNamespace = null; // Using null as the namespace parameter indicates the global namespace.

            m_primitiveList = new List <Primitive>();
            foreach (XmlBindings.Primitive p in xmlData.Primitives)
            {
                Overrides.XmlBindings.Primitive overridePrimitive = null;
                if (overrides != null)
                {
                    overridePrimitive = overrides.Primitives.Find(x => x.Name == p.Name);
                }

                m_primitiveList.Add(new Primitive(p, overridePrimitive, typeDictionary));
            }

            m_structList = new List <Struct>();
            foreach (XmlBindings.Struct s in xmlData.Structs)
            {
                Overrides.XmlBindings.Struct overrideStruct = null;
                if (overrides != null)
                {
                    overrideStruct = overrides.Structs.Find(x => x.Name == s.Name);
                }

                m_structList.Add(new Struct(globalNamespace, s, overrideStruct, typeDictionary, outputDataTypes));
            }

            m_namespaceList = new List <Namespace>();
            foreach (XmlBindings.Namespace n in xmlData.Namespaces)
            {
                Overrides.XmlBindings.Namespace overrideNamespace = null;
                if (overrides != null)
                {
                    overrideNamespace = overrides.Namespaces.Find(x => x.Name == n.Name);
                }

                m_namespaceList.Add(new Namespace(n, overrideNamespace, overrides.RootNamespace.Value, typeDictionary, outputDataTypes));
            }
        }
Exemplo n.º 19
0
        public static void OutputEffectCpp(Effect effect, Formatter output)
        {
            OutputDataTypes.OutputLeadingComment(output);

            bool isInputSizeFixed = true;

            if (effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF")
            {
                isInputSizeFixed = false;
            }

            output.WriteLine("#include \"pch.h\"");
            output.WriteLine("#include \"..\\CanvasEffect.h\"");
            output.WriteLine("#include \"" + effect.ClassName + ".h\"");
            output.WriteLine();
            output.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas { namespace Effects");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine(effect.ClassName + "::" + effect.ClassName + "()");
            output.WriteIndent();
            int inputsCoutn = effect.Inputs.InputsList.Count;

            if (effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF")
            {
                inputsCoutn = 0;
            }
            output.WriteLine(": CanvasEffect(CLSID_D2D1"
                             + effect.Properties[0].Value.Replace(" ", "") + ", "
                             + (effect.Properties.Count - 4) + ", "
                             + inputsCoutn + ", "
                             + isInputSizeFixed.ToString().ToLower() + ")");
            output.WriteLine("{");
            output.Indent();
            output.WriteLine("// Set default values");

            foreach (var property in effect.Properties)
            {
                // Property with type string describes
                // name/author/category/description of effect but not input type
                if (property.Type == "string")
                {
                    continue;
                }

                string defaultValue = property.Properties.Find(internalProperty => internalProperty.Name == "Default").Value;

                if (property.Type == "enum")
                {
                    string d2dDefaultEnum = property.EnumFields.NativeEnum.Enums[Int32.Parse(defaultValue)];
                    output.WriteLine("SetProperty(" + property.NativePropertyName + ", static_cast<uint32_t>(" + d2dDefaultEnum + "), true);");
                }
                else if (property.Type.StartsWith("matrix"))
                {
                    output.WriteLine(property.TypeNameCpp + " default" + property.Name + " = { " + FixSpacing(defaultValue.Substring(1, defaultValue.Length - 2)) + " };");
                    output.WriteLine("SetProperty(" + property.NativePropertyName + ", " + " default" + property.Name + ", true);");
                }
                else
                {
                    string typeExtension = "";
                    if (property.Type == "float")
                    {
                        typeExtension = "f";
                    }
                    output.WriteLine("SetProperty(" + property.NativePropertyName + ", " + defaultValue + typeExtension + ", true);");
                }
            }
            output.Unindent();
            output.WriteLine("}");
            output.WriteLine();
            foreach (var property in effect.Properties)
            {
                // Property with type string describes
                // name/author/category/description of effect but not input type
                if (property.Type == "string")
                {
                    continue;
                }

                bool isValidation = false;
                if (property.Properties.Find(internalProperty => internalProperty.Name == "Min") != null)
                {
                    isValidation = true;
                }

                bool isWithUnsupported = false;
                if (property.ExcludedEnumIndexes != null && property.ExcludedEnumIndexes.Count != 0)
                {
                    isWithUnsupported = true;
                }

                if (property.Type == "enum" && !isWithUnsupported)
                {
                    output.WriteLine("IMPLEMENT_ENUM_PROPERTY(" + effect.ClassName + ",");
                }
                else if (isValidation)
                {
                    output.WriteLine("IMPLEMENT_PROPERTY_WITH_VALIDATION(" + effect.ClassName + ",");
                }
                else if (isWithUnsupported)
                {
                    output.WriteLine("IMPLEMENT_ENUM_PROPERTY_WITH_UNSUPPORTED(" + effect.ClassName + ",");
                }
                else
                {
                    output.WriteLine("IMPLEMENT_PROPERTY(" + effect.ClassName + ",");
                }

                output.Indent();
                output.WriteLine(property.Name + ",");
                output.WriteLine(property.TypeNameCpp + ",");

                if (isValidation)
                {
                    output.WriteLine(property.NativePropertyName + ",");
                    output.WriteLine(property.Properties.Find(internalProperty => internalProperty.Name == "Min").Value + ",");
                    output.WriteLine(property.Properties.Find(internalProperty => internalProperty.Name == "Max").Value + ")");
                }
                else if (isWithUnsupported)
                {
                    output.WriteLine(property.NativePropertyName + ",");
                    var last = property.ExcludedEnumIndexes.Last();
                    foreach (var index in property.ExcludedEnumIndexes)
                    {
                        if (index == last)
                        {
                            output.WriteLine(index + "U)");
                        }
                        else
                        {
                            output.WriteLine(index + "U,");
                        }
                    }
                }
                else
                {
                    output.WriteLine(property.NativePropertyName + ")");
                }

                output.Unindent();
                output.WriteLine();
            }

            if (!(effect.Inputs.Maximum != null && effect.Inputs.Maximum == "0xFFFFFFFF"))
            {
                for (int i = 0; i < effect.Inputs.InputsList.Count; ++i)
                {
                    var input = effect.Inputs.InputsList[i];
                    output.WriteLine("IMPLEMENT_INPUT_PROPERTY(" + effect.ClassName + ",");
                    output.Indent();
                    output.WriteLine(input.Name + ",");
                    output.WriteLine(i.ToString() + ")");
                    output.Unindent();
                    output.WriteLine();
                }
            }

            output.WriteLine("ActivatableClass(" + effect.ClassName + ");");

            output.Unindent();
            output.WriteLine("}}}}}");
        }
Exemplo n.º 20
0
        public static void GenerateCode(string inputDir, string outputDir)
        {
            List<string> files = GetInputFileList();

            Overrides.XmlBindings.Settings overridesXmlData = XmlBindings.Utilities.LoadXmlData<Overrides.XmlBindings.Settings>(inputDir, "Settings.xml");
            Formatter.Prefix = overridesXmlData.Prefix.Value;
            Formatter.Subnamespace = overridesXmlData.Subnamespace.Value;

            var filenameBase = overridesXmlData.FilenameBase.Value;

            List<D2DTypes> typeDocuments = new List<D2DTypes>();
            Dictionary<string, QualifiableType> typeDictionary = new Dictionary<string, QualifiableType>();
            OutputDataTypes outputDataTypes = new OutputDataTypes();
            foreach (string fileName in files)
            {
                XmlBindings.D2DTypes xmlDocument = XmlBindings.Utilities.LoadXmlData<XmlBindings.D2DTypes>(inputDir, fileName);
                typeDocuments.Add(new D2DTypes(xmlDocument, overridesXmlData, typeDictionary, outputDataTypes));
            }

            Directory.CreateDirectory(outputDir);
            OutputFiles outputFiles = new OutputFiles();
            using (Formatter cppStreamWriter = new Formatter(Path.Combine(outputDir, filenameBase + ".codegen.cpp")),
                             idlStreamWriter = new Formatter(Path.Combine(outputDir, filenameBase + ".codegen.idl")))
            {
                outputFiles.CppFile = cppStreamWriter;
                outputFiles.IdlFile = idlStreamWriter;

                outputDataTypes.OutputCode(typeDictionary, outputFiles);
            }
        }
Exemplo n.º 21
0
        public Enum(Namespace parentNamespace, XmlBindings.Enum xmlData, Overrides.XmlBindings.Enum overrides, Dictionary<string, QualifiableType> typeDictionary, OutputDataTypes outputDataTypes)
        {
            m_stylizedName = Formatter.Prefix + Formatter.StylizeNameFromUnderscoreSeparators(xmlData.Name);

            if (parentNamespace != null)
            {
                m_rawName = parentNamespace.ApiName + "_" + xmlData.Name;
                typeDictionary[parentNamespace.RawName + "::" + xmlData.Name] = this;
            }
            else
            {
                //
                // Namespace of NULL indicates the global namespace.
                // These types aren't D2D types, and their full native name is
                // exactly what's in the name field (no need to prepend anything).
                //
                m_rawName = xmlData.Name;
                typeDictionary[xmlData.Name] = this;
            }

            m_isFlags = xmlData.IsFlags;

            m_enumValues = new List<EnumValue>();
            foreach (XmlBindings.EnumValue valueXml in xmlData.EnumValues)
            {
                Overrides.XmlBindings.EnumValue overridesEnumValue = null;
                if (overrides != null) overridesEnumValue = overrides.Values.Find(x => x.Name == valueXml.Name);

                m_enumValues.Add(new EnumValue(valueXml, overridesEnumValue));
            }
            
            bool shouldProject = false;
            if(overrides != null)
            {
                shouldProject = overrides.ShouldProject;

                if(overrides.ProjectedNameOverride != null)
                {
                    m_stylizedName = Formatter.Prefix + overrides.ProjectedNameOverride;
                } 

            }

            // Enums in the global namespace are defined as aliases only. By convention, only enums in a namespace are output.
            if (parentNamespace != null && shouldProject)
            {
                outputDataTypes.AddEnum(this);
            }

        }