public void OutputCode(bool isLast, bool isFlags, OutputFiles outputFiles) { if (!m_shouldProject) { return; } outputFiles.IdlFile.WriteIndent(); // // The (int) cast is necessary for values such as "0x80000000" which // cannot be stored using a signed int. The default behavior of the // MIDL code generation/C++ compilation process is to treat enum // values as signed ints. // outputFiles.IdlFile.Write(m_stylizedName); outputFiles.IdlFile.Write(" = "); if (!isFlags) { outputFiles.IdlFile.Write("(int)"); } outputFiles.IdlFile.Write(m_valueExpression); string suffix = isLast ? "" : ","; outputFiles.IdlFile.Write(suffix); outputFiles.IdlFile.WriteLine(); }
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); } }
public static void OutputEndingCppCode(OutputFiles outputFiles) { outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("}}}}"); outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("}"); }
private void OutputEndingCode(OutputFiles outputFiles) { outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("}}}}"); outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("}"); }
// Used for code generation. public void OutputCode(Dictionary <string, QualifiableType> typeDictionary, OutputFiles outputFiles) { if (RequiresClassProjection(typeDictionary)) { OutputClassProjectionCode(typeDictionary, outputFiles); } else { OutputValueTypeProjectionCode(typeDictionary, outputFiles); } }
public static void GenerateCode(ProcessedInputFiles inputFiles, string outputDir) { Directory.CreateDirectory(outputDir); OutputFiles outputFiles = new OutputFiles(); using (Formatter cppStreamWriter = new Formatter(Path.Combine(outputDir, inputFiles.FilenameBase + ".codegen.cpp")), idlStreamWriter = new Formatter(Path.Combine(outputDir, inputFiles.FilenameBase + ".codegen.idl"))) { outputFiles.CppFile = cppStreamWriter; outputFiles.IdlFile = idlStreamWriter; inputFiles.OutputDataTypes.OutputCode(inputFiles.TypeDictionary, outputFiles); } }
public void OutputCode(Dictionary<string, QualifiableType> typeDictionary, OutputFiles outputFiles) { OutputLeadingCode(outputFiles); foreach(Enum e in m_enums) { e.OutputCode(outputFiles); } foreach(Struct s in m_structs) { s.OutputCode(typeDictionary, outputFiles); } OutputEndingCode(outputFiles); }
public void OutputCode(Dictionary <string, QualifiableType> typeDictionary, OutputFiles outputFiles) { OutputLeadingCppCode(outputFiles); foreach (Enum e in m_enums) { e.OutputCode(outputFiles); } foreach (Struct s in m_structs) { s.OutputCode(typeDictionary, outputFiles); } OutputEndingCppCode(outputFiles); }
public static void OutputLeadingCppCode(OutputFiles outputFiles) { OutputLeadingComment(outputFiles.CppFile); outputFiles.CppFile.WriteLine("#include \"pch.h\""); outputFiles.CppFile.WriteLine("#include <wrl.h>"); outputFiles.CppFile.WriteLine("using namespace Microsoft::WRL;"); outputFiles.CppFile.WriteLine("using namespace ABI::Microsoft::Graphics::Canvas::Numerics;"); outputFiles.CppFile.WriteLine("using namespace ABI::Windows::Foundation;"); outputFiles.CppFile.WriteLine("using namespace ABI::Windows::UI;"); outputFiles.CppFile.WriteLine(); outputFiles.CppFile.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas"); outputFiles.CppFile.WriteLine("{"); outputFiles.CppFile.Indent(); OutputLeadingComment(outputFiles.IdlFile); outputFiles.IdlFile.WriteLine("namespace Microsoft.Graphics.Canvas"); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); }
private void OutputLeadingCode(OutputFiles outputFiles) { OutputLeadingComment(outputFiles.CppFile); outputFiles.CppFile.WriteLine("#include \"pch.h\""); outputFiles.CppFile.WriteLine("#include <wrl.h>"); outputFiles.CppFile.WriteLine("using namespace Microsoft::WRL;"); outputFiles.CppFile.WriteLine("using namespace ABI::Microsoft::Graphics::Canvas::Numerics;"); outputFiles.CppFile.WriteLine("using namespace ABI::Windows::Foundation;"); outputFiles.CppFile.WriteLine("using namespace ABI::Windows::UI;"); outputFiles.CppFile.WriteLine(); outputFiles.CppFile.WriteLine("namespace ABI { namespace Microsoft { namespace Graphics { namespace Canvas"); outputFiles.CppFile.WriteLine("{"); outputFiles.CppFile.Indent(); OutputLeadingComment(outputFiles.IdlFile); outputFiles.IdlFile.WriteLine("namespace Microsoft.Graphics.Canvas"); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); }
// Used for code generation. public void OutputCode(OutputFiles outputFiles) { outputFiles.IdlFile.WriteIndent(); outputFiles.IdlFile.Write("[version(VERSION)"); if (m_isFlags) { outputFiles.IdlFile.Write(", flags"); } outputFiles.IdlFile.Write("]"); outputFiles.IdlFile.WriteLine(); outputFiles.IdlFile.WriteLine("typedef enum " + m_stylizedName); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); for (int i = 0; i < m_enumValues.Count; i++) { bool isLast = i == m_enumValues.Count - 1; m_enumValues[i].OutputCode(isLast, m_isFlags, outputFiles); } outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("} " + m_stylizedName + ";"); outputFiles.IdlFile.WriteLine(); }
void OutputValueTypeProjectionCode(Dictionary <string, QualifiableType> typeDictionary, OutputFiles outputFiles) { // This outputs to the IDL file only. There is no output to the .cpp file. outputFiles.IdlFile.WriteLine("[version(VERSION)]"); outputFiles.IdlFile.WriteLine("typedef struct " + m_stylizedName); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); foreach (StructField structField in m_structFields) { QualifiableType typeObject = typeDictionary[structField.TypeName]; outputFiles.IdlFile.WriteLine(typeObject.IdlTypeNameQualifier + typeObject.ProjectedName + " " + structField.PropertyName + ";"); } outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("} " + m_stylizedName + ";"); outputFiles.IdlFile.WriteLine(); }
// Used for code generation. public void OutputCode(Dictionary<string, QualifiableType> typeDictionary, OutputFiles outputFiles) { if (RequiresClassProjection(typeDictionary)) { OutputClassProjectionCode(typeDictionary, outputFiles); } else { OutputValueTypeProjectionCode(typeDictionary, outputFiles); } }
void OutputClassProjectionCode(Dictionary<string, QualifiableType> typeDictionary, OutputFiles outputFiles) { // IDL file outputFiles.IdlFile.WriteLine("interface " + m_idlInterfaceName + ";"); outputFiles.IdlFile.WriteLine("runtimeclass " + m_stylizedName + ";"); outputFiles.IdlFile.WriteLine(); outputFiles.IdlFile.WriteLine("[uuid(" + m_guid.ToUpper() + "), version(VERSION), exclusiveto(" + m_stylizedName + ")]"); outputFiles.IdlFile.WriteLine("interface " + m_idlInterfaceName + " : IInspectable"); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); for (int i = 0; i < m_structFields.Count; i++) { QualifiableType typeObject = typeDictionary[m_structFields[i].TypeName]; outputFiles.IdlFile.WriteLine("[propget] HRESULT " + m_structFields[i].PropertyName + "([out, retval] " + typeObject.IdlTypeNameQualifier + typeObject.ProjectedNameIncludingIndirection + "* value);"); outputFiles.IdlFile.WriteLine("[propput] HRESULT " + m_structFields[i].PropertyName + "([in] " + typeObject.IdlTypeNameQualifier + typeObject.ProjectedNameIncludingIndirection + " value);"); if (i < m_structFields.Count - 1) { outputFiles.IdlFile.WriteLine(); } } outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("}"); outputFiles.IdlFile.WriteLine(); outputFiles.IdlFile.WriteLine("[version(VERSION), activatable(VERSION)]"); outputFiles.IdlFile.WriteLine("runtimeclass " + m_stylizedName + ""); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); outputFiles.IdlFile.WriteLine("[default] interface " + m_idlInterfaceName + ";"); outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("}"); outputFiles.IdlFile.WriteLine(); // CPP file outputFiles.CppFile.WriteLine("class " + m_stylizedName + " : public Microsoft::WRL::RuntimeClass<" + m_idlInterfaceName + ">"); outputFiles.CppFile.WriteLine("{"); outputFiles.CppFile.Indent(); outputFiles.CppFile.WriteLine("InspectableClass(L\"Microsoft." + Formatter.Subnamespace + "." + m_stylizedName + "\", BaseTrust);"); outputFiles.CppFile.WriteLine(); outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("public:"); outputFiles.CppFile.Indent(); for (int i = 0; i < m_structFields.Count; i++) { QualifiableType typeObject = typeDictionary[m_structFields[i].TypeName]; outputFiles.CppFile.WriteLine("IFACEMETHOD(get_" + m_structFields[i].PropertyName + ")(_Out_ " + typeObject.ProjectedNameIncludingIndirection + "* value) override"); ; outputFiles.CppFile.WriteLine("{"); outputFiles.CppFile.Indent(); outputFiles.CppFile.WriteLine("if (!value)"); outputFiles.CppFile.Indent(); outputFiles.CppFile.WriteLine("return E_INVALIDARG;"); outputFiles.CppFile.WriteLine(); outputFiles.CppFile.Unindent(); if (typeObject is Interface) outputFiles.CppFile.WriteLine(m_structFields[i].PrivateMemberName + ".CopyTo(value);"); else outputFiles.CppFile.WriteLine("*value = " + m_structFields[i].PrivateMemberName + typeObject.AccessorSuffix + ";"); outputFiles.CppFile.WriteLine("return S_OK;"); outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("}"); outputFiles.CppFile.WriteLine(); outputFiles.CppFile.WriteLine("IFACEMETHOD(put_" + m_structFields[i].PropertyName + ")(" + typeObject.ProjectedNameIncludingIndirection + " value) override"); outputFiles.CppFile.WriteLine("{"); outputFiles.CppFile.Indent(); outputFiles.CppFile.WriteLine(m_structFields[i].PrivateMemberName + " = value;"); outputFiles.CppFile.WriteLine("return S_OK;"); outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("}"); outputFiles.CppFile.WriteLine(); } outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("private:"); outputFiles.CppFile.Indent(); for (int i = 0; i < m_structFields.Count; i++) { QualifiableType typeObject = typeDictionary[m_structFields[i].TypeName]; outputFiles.CppFile.WriteLine(typeObject.RuntimeClassMemberTypeName + " " + m_structFields[i].PrivateMemberName + ";"); } outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("};"); outputFiles.CppFile.WriteLine(); }
void OutputValueTypeProjectionCode(Dictionary<string, QualifiableType> typeDictionary, OutputFiles outputFiles) { // This outputs to the IDL file only. There is no output to the .cpp file. outputFiles.IdlFile.WriteLine("[version(VERSION)]"); outputFiles.IdlFile.WriteLine("typedef struct " + m_stylizedName); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); foreach(StructField structField in m_structFields) { QualifiableType typeObject = typeDictionary[structField.TypeName]; outputFiles.IdlFile.WriteLine(typeObject.IdlTypeNameQualifier + typeObject.ProjectedName + " " + structField.PropertyName + ";"); } outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("} " + m_stylizedName + ";"); outputFiles.IdlFile.WriteLine(); }
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); } }
public void OutputCode(bool isLast, bool isFlags, OutputFiles outputFiles) { if (!m_shouldProject) return; outputFiles.IdlFile.WriteIndent(); // // The (int) cast is necessary for values such as "0x80000000" which // cannot be stored using a signed int. The default behavior of the // MIDL code generation/C++ compilation process is to treat enum // values as signed ints. // outputFiles.IdlFile.Write(m_stylizedName); outputFiles.IdlFile.Write(" = "); if(!isFlags) { outputFiles.IdlFile.Write("(int)"); } outputFiles.IdlFile.Write(m_valueExpression); string suffix = isLast ? "" : ","; outputFiles.IdlFile.Write(suffix); outputFiles.IdlFile.WriteLine(); }
void OutputClassProjectionCode(Dictionary <string, QualifiableType> typeDictionary, OutputFiles outputFiles) { // IDL file outputFiles.IdlFile.WriteLine("interface " + m_idlInterfaceName + ";"); outputFiles.IdlFile.WriteLine("runtimeclass " + m_stylizedName + ";"); outputFiles.IdlFile.WriteLine(); outputFiles.IdlFile.WriteLine("[uuid(" + m_guid.ToUpper() + "), version(VERSION), exclusiveto(" + m_stylizedName + ")]"); outputFiles.IdlFile.WriteLine("interface " + m_idlInterfaceName + " : IInspectable"); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); for (int i = 0; i < m_structFields.Count; i++) { QualifiableType typeObject = typeDictionary[m_structFields[i].TypeName]; outputFiles.IdlFile.WriteLine("[propget] HRESULT " + m_structFields[i].PropertyName + "([out, retval] " + typeObject.IdlTypeNameQualifier + typeObject.ProjectedNameIncludingIndirection + "* value);"); outputFiles.IdlFile.WriteLine("[propput] HRESULT " + m_structFields[i].PropertyName + "([in] " + typeObject.IdlTypeNameQualifier + typeObject.ProjectedNameIncludingIndirection + " value);"); if (i < m_structFields.Count - 1) { outputFiles.IdlFile.WriteLine(); } } outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("}"); outputFiles.IdlFile.WriteLine(); outputFiles.IdlFile.WriteLine("[version(VERSION), activatable(VERSION)]"); outputFiles.IdlFile.WriteLine("runtimeclass " + m_stylizedName + ""); outputFiles.IdlFile.WriteLine("{"); outputFiles.IdlFile.Indent(); outputFiles.IdlFile.WriteLine("[default] interface " + m_idlInterfaceName + ";"); outputFiles.IdlFile.Unindent(); outputFiles.IdlFile.WriteLine("}"); outputFiles.IdlFile.WriteLine(); // CPP file outputFiles.CppFile.WriteLine("class " + m_stylizedName + " : public Microsoft::WRL::RuntimeClass<" + m_idlInterfaceName + ">"); outputFiles.CppFile.WriteLine("{"); outputFiles.CppFile.Indent(); outputFiles.CppFile.WriteLine("InspectableClass(L\"Microsoft." + Formatter.Subnamespace + "." + m_stylizedName + "\", BaseTrust);"); outputFiles.CppFile.WriteLine(); outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("public:"); outputFiles.CppFile.Indent(); for (int i = 0; i < m_structFields.Count; i++) { QualifiableType typeObject = typeDictionary[m_structFields[i].TypeName]; outputFiles.CppFile.WriteLine("IFACEMETHOD(get_" + m_structFields[i].PropertyName + ")(_Out_ " + typeObject.ProjectedNameIncludingIndirection + "* value) override");; outputFiles.CppFile.WriteLine("{"); outputFiles.CppFile.Indent(); outputFiles.CppFile.WriteLine("if (!value)"); outputFiles.CppFile.Indent(); outputFiles.CppFile.WriteLine("return E_INVALIDARG;"); outputFiles.CppFile.WriteLine(); outputFiles.CppFile.Unindent(); if (typeObject is Interface) { outputFiles.CppFile.WriteLine(m_structFields[i].PrivateMemberName + ".CopyTo(value);"); } else { outputFiles.CppFile.WriteLine("*value = " + m_structFields[i].PrivateMemberName + typeObject.AccessorSuffix + ";"); } outputFiles.CppFile.WriteLine("return S_OK;"); outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("}"); outputFiles.CppFile.WriteLine(); outputFiles.CppFile.WriteLine("IFACEMETHOD(put_" + m_structFields[i].PropertyName + ")(" + typeObject.ProjectedNameIncludingIndirection + " value) override"); outputFiles.CppFile.WriteLine("{"); outputFiles.CppFile.Indent(); outputFiles.CppFile.WriteLine(m_structFields[i].PrivateMemberName + " = value;"); outputFiles.CppFile.WriteLine("return S_OK;"); outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("}"); outputFiles.CppFile.WriteLine(); } outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("private:"); outputFiles.CppFile.Indent(); for (int i = 0; i < m_structFields.Count; i++) { QualifiableType typeObject = typeDictionary[m_structFields[i].TypeName]; outputFiles.CppFile.WriteLine(typeObject.RuntimeClassMemberTypeName + " " + m_structFields[i].PrivateMemberName + ";"); } outputFiles.CppFile.Unindent(); outputFiles.CppFile.WriteLine("};"); outputFiles.CppFile.WriteLine(); }