private static void WriteNamespaceOpen(INamedTypeSymbol namedTypeSymbol, CCodeWriterText c) { bool any = false; foreach (var namespaceNode in namedTypeSymbol.ContainingNamespace.EnumNamespaces()) { c.TextSpan("namespace "); c.WriteNamespaceName(namespaceNode); c.TextSpan(" { "); any = true; } if (any) { c.IncrementIndent(); c.NewLine(); } }
private static void WriteNamespaceOpen(INamedTypeSymbol namedTypeSymbol, IndentedTextWriter itw, CCodeWriterText c) { bool any = false; foreach (var namespaceNode in namedTypeSymbol.ContainingNamespace.EnumNamespaces()) { itw.Write("namespace "); c.WriteNamespaceName(namespaceNode); itw.Write(" { "); any = true; } if (any) { itw.Indent++; itw.WriteLine(); } }
private static void WriteForwardDeclarationForUnit(CCodeUnit unit, IndentedTextWriter itw, CCodeWriterText c) { var namedTypeSymbol = (INamedTypeSymbol)unit.Type; foreach (var namespaceNode in namedTypeSymbol.ContainingNamespace.EnumNamespaces()) { itw.Write("namespace "); c.WriteNamespaceName(namespaceNode); itw.Write(" { "); } if (namedTypeSymbol.IsGenericType) { c.WriteTemplateDeclaration(namedTypeSymbol); } itw.Write(namedTypeSymbol.IsValueType ? "struct" : "class"); itw.Write(" "); c.WriteTypeName(namedTypeSymbol, false); itw.Write("; "); if (namedTypeSymbol.TypeKind == TypeKind.Enum) { WriteEnum(itw, c, namedTypeSymbol); } foreach (var namespaceNode in namedTypeSymbol.ContainingNamespace.EnumNamespaces()) { itw.Write("}"); } itw.WriteLine(); if (namedTypeSymbol.SpecialType == SpecialType.System_Object || namedTypeSymbol.SpecialType == SpecialType.System_String) { itw.Write("typedef "); c.WriteType(namedTypeSymbol, suppressReference: true, allowKeywords: false); itw.Write(" "); c.WriteTypeName(namedTypeSymbol); itw.WriteLine(";"); } }
private static void WriteNamespaceOpen(INamedTypeSymbol namedTypeSymbol, CCodeWriterText c) { bool any = false; foreach (var namespaceNode in namedTypeSymbol.ContainingNamespace.EnumNamespaces()) { c.TextSpan("namespace "); c.WriteNamespaceName(namespaceNode); c.TextSpan(" { "); any = true; } if (any) { c.IncrementIndent(); c.NewLine(); } /* * // include using of namespace * c.TextSpan("using"); * c.WhiteSpace(); * c.TextSpan("namespace"); * c.WhiteSpace(); * c.WriteNamespace(namedTypeSymbol.ContainingNamespace); * c.EndStatement(); * c.Separate(); */ // write alias for _ c.TextSpan("namespace"); c.WhiteSpace(); c.TextSpan("_"); c.WhiteSpace(); c.TextSpan("="); c.WhiteSpace(); c.WriteNamespace(namedTypeSymbol.ContainingNamespace); c.EndStatement(); c.Separate(); c.NewLine(); }
private static void WriteFullDeclarationForUnit(CCodeUnit unit, IndentedTextWriter itw, CCodeWriterText c) { var any = false; var namedTypeSymbol = (INamedTypeSymbol)unit.Type; foreach (var namespaceNode in namedTypeSymbol.ContainingNamespace.EnumNamespaces()) { itw.Write("namespace "); c.WriteNamespaceName(namespaceNode); itw.Write(" { "); any = true; } if (any) { itw.Indent++; itw.WriteLine(); } if (namedTypeSymbol.IsGenericType) { c.WriteTemplateDeclaration(namedTypeSymbol); } itw.Write(namedTypeSymbol.IsValueType ? "struct" : "class"); itw.Write(" "); c.WriteTypeName(namedTypeSymbol, false); if (namedTypeSymbol.BaseType != null) { itw.Write(" : public "); c.WriteTypeFullName(namedTypeSymbol.BaseType); } itw.WriteLine(); itw.WriteLine("{"); itw.WriteLine("public:"); itw.Indent++; // base declaration if (namedTypeSymbol.BaseType != null) { itw.Write("typedef "); c.WriteTypeFullName(namedTypeSymbol.BaseType, false); itw.WriteLine(" base;"); } foreach (var method in namedTypeSymbol.IterateAllMethodsWithTheSameNamesTakeOnlyOne()) { c.TextSpan("using"); c.WhiteSpace(); c.WriteType(namedTypeSymbol.BaseType ?? method.ReceiverType, suppressReference: true, allowKeywords: true); c.TextSpan("::"); c.WriteMethodName(method); c.TextSpan(";"); c.NewLine(); } if (namedTypeSymbol.TypeKind == TypeKind.Enum) { // value holder for enum c.WriteType(namedTypeSymbol); itw.WriteLine(" m_value;"); } /* * if (!unit.HasDefaultConstructor) * { * c.WriteTypeName(namedTypeSymbol, false); * itw.WriteLine("() = default;"); * } */ foreach (var declaration in unit.Declarations) { declaration.WriteTo(c); } // write interface wrappers foreach (var iface in namedTypeSymbol.Interfaces) { WriteInterfaceWrapper(c, iface, namedTypeSymbol); } itw.Indent--; itw.WriteLine("};"); if (namedTypeSymbol.TypeKind == TypeKind.Delegate) { itw.WriteLine(); new CCodeDelegateWrapperClass(namedTypeSymbol).WriteTo(c); itw.WriteLine(); } foreach (var namespaceNode in namedTypeSymbol.ContainingNamespace.EnumNamespaces()) { itw.Indent--; itw.Write("}"); } itw.WriteLine(); if (namedTypeSymbol.IsPrimitiveValueType() || namedTypeSymbol.TypeKind == TypeKind.Enum || namedTypeSymbol.SpecialType == SpecialType.System_Void) { // value to class c.TextSpanNewLine("template<>"); c.TextSpan("struct"); c.WhiteSpace(); c.TextSpan("valuetype_to_class<"); c.WriteType(namedTypeSymbol); c.TextSpan(">"); c.WhiteSpace(); c.TextSpan("{ typedef"); c.WhiteSpace(); c.WriteType(namedTypeSymbol, true, false, true); c.WhiteSpace(); c.TextSpan("type; };"); // class to value c.TextSpanNewLine("template<>"); c.TextSpan("struct"); c.WhiteSpace(); c.TextSpan("class_to_valuetype<"); c.WriteType(namedTypeSymbol, true, false, true); c.TextSpan(">"); c.WhiteSpace(); c.TextSpan("{ typedef"); c.WhiteSpace(); c.WriteType(namedTypeSymbol); c.WhiteSpace(); c.TextSpan("type; };"); itw.WriteLine(); if (namedTypeSymbol.SpecialType != SpecialType.System_Void) { new CCodeBoxForPrimitiveValuesOrEnumsDeclaration(namedTypeSymbol).WriteTo(c); itw.WriteLine(); } } }