Пример #1
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));
            }
        }
Пример #2
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];
            }
        }
Пример #3
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);
            }
        }