private void GenerateStmt(BindingContext ctx) { var stmtUnit = ctx.ASTContext.TranslationUnits.Find(unit => unit.FileName.Contains("Stmt.h")); var stmtClass = stmtUnit.FindNamespace("clang").FindClass("Stmt"); var stmtClassEnum = stmtClass.FindEnum("StmtClass"); stmtClassEnum.Name = "StmtKind"; stmtClass.Declarations.Remove(stmtClassEnum); CleanupEnumItems(stmtClassEnum); var stmtSubclassVisitor = new SubclassVisitor(stmtClass); stmtUnit.Visit(stmtSubclassVisitor); ctx.Options.GeneratorKind = GeneratorKind.CPlusPlus; var nativeCodeGen = new NativeParserCodeGenerator(ctx); nativeCodeGen.CTypePrinter.ScopeKind = TypePrintScopeKind.Local; nativeCodeGen.GenerateFilePreamble(CommentKind.BCPL); nativeCodeGen.NewLine(); nativeCodeGen.WriteLine("#pragma once"); nativeCodeGen.NewLine(); nativeCodeGen.WriteLine("namespace CppSharp { namespace CppParser { namespace AST {"); nativeCodeGen.NewLine(); stmtClassEnum.Visit(nativeCodeGen); foreach (var @class in stmtSubclassVisitor.Classes) { RemoveNamespace(@class); @class.Visit(nativeCodeGen); } nativeCodeGen.NewLine(); nativeCodeGen.WriteLine("} } }"); WriteFile(nativeCodeGen, "Stmt.h"); }
private void GenerateExpr(BindingContext ctx) { var exprUnit = ctx.ASTContext.TranslationUnits.Find(unit => unit.FileName.Contains("Expr.h")); var exprClass = exprUnit.FindNamespace("clang").FindClass("Expr"); var exprSubclassVisitor = new SubclassVisitor(exprClass); exprUnit.Visit(exprSubclassVisitor); ctx.Options.GeneratorKind = GeneratorKind.CPlusPlus; var nativeCodeGen = new NativeParserCodeGenerator(ctx); nativeCodeGen.CTypePrinter.ScopeKind = TypePrintScopeKind.Local; nativeCodeGen.GenerateFilePreamble(CommentKind.BCPL); nativeCodeGen.NewLine(); nativeCodeGen.WriteLine("#pragma once"); nativeCodeGen.NewLine(); nativeCodeGen.WriteInclude(new CInclude { File = "Stmt.h", Kind = CInclude.IncludeKind.Quoted }); nativeCodeGen.NewLine(); nativeCodeGen.WriteLine("namespace CppSharp { namespace CppParser { namespace AST {"); nativeCodeGen.NewLine(); foreach (var @class in exprSubclassVisitor.Classes) { RemoveNamespace(@class); @class.Visit(nativeCodeGen); } nativeCodeGen.NewLine(); nativeCodeGen.WriteLine("} } }"); WriteFile(nativeCodeGen, "Expr.h"); }