protected virtual CodeFile CreateCodeFile(string @namespace, CppTypeDeclaration decl) { var decls = new CppTypeDeclaration[1]; decls[0] = decl; return(CreateCodeFile(@namespace, decls)); }
public static string GetSourceFile(this CppTypeDeclaration cppType) { if (cppType is CppClass @class) { return(GetSourceFile(@class)); } return(cppType.Span.Start.File); }
public void Format(CppTypeDeclaration typeDecl, TextWriter stream) { var codefile = CreateCodeFile(this.Namespace, typeDecl); var sb = new StringBuilder(); using (var w = new StringWriter(sb)) { var codeGen = new CSharpCodeGen(); codeGen.Directives.Add("#pragma warning disable 0169, 1591, 1573"); codeGen.GenerateCode(codefile, w); w.Flush(); } stream.WriteLine(sb.ToString()); }
public GenerateResult Generate(CppTypeDeclaration cppType) { switch (cppType) { case CppEnum cppEnum: return(GenerateEnum(cppEnum)); case CppTypedef cppTypedef: return(GenerateTypedef(cppTypedef)); case CppClass cppClass: return(GenerateClass(cppClass)); } throw new NotSupportedException(cppType.ToString()); }
private static bool CanBeUsedAsOutput(CppType type, out CppTypeDeclaration elementTypeDeclaration) { if (type is CppPointerType pointerType) { if (pointerType.ElementType is CppTypedef typedef) { elementTypeDeclaration = typedef; return(true); } else if (pointerType.ElementType is CppClass @class && @class.ClassKind != CppClassKind.Class && @class.SizeOf > 0) { elementTypeDeclaration = @class; return(true); } else if (pointerType.ElementType is CppEnum @enum && @enum.SizeOf > 0) { elementTypeDeclaration = @enum; return(true); } }
public GenerateResult(CppTypeDeclaration cppTypeDeclaration) { CppType = cppTypeDeclaration; }