public bool ParseCode() { var astContext = new Parser.AST.ASTContext(); var parser = new ClangParser(astContext); parser.SourcesParsed += OnSourceFileParsed; var sourceFiles = Options.Modules.SelectMany(m => m.Headers); using (ParserOptions parserOptions = ParserOptions.BuildForSourceFile( Options.Modules)) { using (ParserResult result = parser.ParseSourceFiles( sourceFiles, parserOptions)) Context.TargetInfo = result.TargetInfo; if (string.IsNullOrEmpty(ParserOptions.TargetTriple)) { ParserOptions.TargetTriple = parserOptions.TargetTriple; } } Context.ASTContext = ClangParser.ConvertASTContext(astContext); return(!hasParsingErrors); }
private ASTContext ParseInternal(string[] sourceFiles) { var parserOptions = new ParserOptions { Verbose = true, ASTContext = new CppSharp.Parser.AST.ASTContext(), LanguageVersion = LanguageVersion.C99_GNU }; parserOptions.SetupMSVC(VisualStudioVersion.Latest); foreach (var includeDir in IncludeDirs) { parserOptions.AddIncludeDirs(includeDir); } foreach (var define in Defines) { parserOptions.AddDefines(define); } var clangParser = new ClangParser(new CppSharp.Parser.AST.ASTContext()); clangParser.SourcesParsed += OnSourceFileParsed; clangParser.ParseSourceFiles(sourceFiles, parserOptions); return(ClangParser.ConvertASTContext(clangParser.ASTContext)); }
public bool ParseCode() { var astContext = new Parser.AST.ASTContext(); var parser = new ClangParser(astContext); parser.SourcesParsed += OnSourceFileParsed; var sourceFiles = Options.Modules.SelectMany(m => m.Headers); if (Options.UnityBuild) { using (var parserOptions = ParserOptions.BuildForSourceFile( Options.Modules)) { using (var result = parser.ParseSourceFiles( sourceFiles, parserOptions)) Context.TargetInfo = result.TargetInfo; if (string.IsNullOrEmpty(ParserOptions.TargetTriple)) { ParserOptions.TargetTriple = parserOptions.TargetTriple; } } } else { foreach (var sourceFile in sourceFiles) { using (var parserOptions = ParserOptions.BuildForSourceFile( Options.Modules, sourceFile)) { using (ParserResult result = parser.ParseSourceFile( sourceFile, parserOptions)) if (Context.TargetInfo == null) { Context.TargetInfo = result.TargetInfo; } else if (result.TargetInfo != null) { result.TargetInfo.Dispose(); } if (string.IsNullOrEmpty(ParserOptions.TargetTriple)) { ParserOptions.TargetTriple = parserOptions.TargetTriple; } } } } Context.ASTContext = ClangParser.ConvertASTContext(astContext); return(!hasParsingErrors); }
public bool ParseCode() { ClangParser.SourcesParsed += OnSourceFileParsed; var sourceFiles = Options.Modules.SelectMany(m => m.Headers); ParserOptions.BuildForSourceFile(Options.Modules); using (ParserResult result = ClangParser.ParseSourceFiles( sourceFiles, ParserOptions)) Context.TargetInfo = result.TargetInfo; Context.ASTContext = ClangParser.ConvertASTContext(ParserOptions.ASTContext); ClangParser.SourcesParsed -= OnSourceFileParsed; return(!hasParsingErrors); }
public bool ParseCode() { var astContext = new Parser.AST.ASTContext(); var parser = new ClangParser(astContext); parser.SourcesParsed += OnSourceFileParsed; var sourceFiles = Options.Modules.SelectMany(m => m.Headers); if (Options.UnityBuild) { var parserOptions = BuildParserOptions(); var result = parser.ParseSourceFiles(sourceFiles, parserOptions); result.Dispose(); } else { var results = new List <ParserResult>(); foreach (var sourceFile in sourceFiles) { var parserOptions = BuildParserOptions(sourceFile); results.Add(parser.ParseSourceFile(sourceFile, parserOptions)); } foreach (var result in results) { result.Dispose(); } } Context.TargetInfo = parser.GetTargetInfo(ParserOptions); Context.ASTContext = ClangParser.ConvertASTContext(astContext); return(!hasParsingErrors); }