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); }
public bool ParseCode() { foreach (var header in Options.Headers) { var source = Project.AddFile(header); source.Options = BuildParseOptions(source); } #if !OLD_PARSER var parser = new ClangParser(new Parser.AST.ASTContext()); #else var parser = new ClangParser(ASTContext); #endif parser.SourceParsed += OnSourceFileParsed; parser.ParseProject(Project, Options); TargetInfo = parser.GetTargetInfo(Options); #if !OLD_PARSER ASTContext = ClangParser.ConvertASTContext(parser.ASTContext); #endif return(true); }
private ASTContext ParseInternal(string[] sourceFiles) { var parserOptions = new ParserOptions { Verbose = true, ASTContext = new CppSharp.Parser.AST.ASTContext(), LanguageVersion = LanguageVersion.GNUC }; parserOptions.SetupIncludes(); foreach (var includeDir in IncludeDirs) { parserOptions.AddIncludeDirs(includeDir); } foreach (var define in Defines) { parserOptions.AddDefines(define); } var project = new Project(); foreach (var filePath in sourceFiles) { var sourceFile = project.AddFile(filePath); sourceFile.Options = parserOptions; } var clangParser = new ClangParser(new CppSharp.Parser.AST.ASTContext()); clangParser.SourcesParsed += OnSourceFileParsed; clangParser.ParseProject(project, false); return(ClangParser.ConvertASTContext(clangParser.ASTContext)); }
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 static bool ParseSourceFile(string file) { // Lets setup the options for parsing the file. var parserOptions = new ParserOptions { LanguageVersion = LanguageVersion.CPP11, // Verbose here will make sure the parser outputs some extra debugging // information regarding include directories, which can be helpful when // tracking down parsing issues. Verbose = true }; // This will setup the necessary system include paths and arguments for parsing. // It will probe into the registry (on Windows) and filesystem to find the paths // of the system toolchains and necessary include directories. parserOptions.Setup(); // We create the Clang parser and parse the source code. var parser = new ClangParser(); var parserResult = parser.ParseSourceFile(file, parserOptions); // If there was some kind of error parsing, then lets print some diagnostics. if (parserResult.Kind != ParserResultKind.Success) { if (parserResult.Kind == ParserResultKind.FileNotFound) { Console.Error.WriteLine($"{file} was not found."); } for (uint i = 0; i < parserResult.DiagnosticsCount; i++) { var diag = parserResult.GetDiagnostics(i); Console.WriteLine("{0}({1},{2}): {3}: {4}", diag.FileName, diag.LineNumber, diag.ColumnNumber, diag.Level.ToString().ToLower(), diag.Message); } parserResult.Dispose(); return(false); } // Now we can consume the output of the parser (syntax tree). // First we will convert the output, bindings for the native Clang AST, // to CppSharp's managed AST representation. var astContext = ClangParser.ConvertASTContext(parserResult.ASTContext); // After its converted, we can dispose of the native AST bindings. parserResult.Dispose(); // Now we can finally do what we please with the syntax tree. foreach (var sourceUnit in astContext.TranslationUnits) { Console.WriteLine(sourceUnit.FileName); } return(true); }
public bool ParseCode() { var parser = new ClangParser(new Parser.AST.ASTContext()); parser.SourcesParsed += OnSourceFileParsed; parser.ParseProject(Project, Options.UnityBuild); Context.TargetInfo = parser.GetTargetInfo(ParserOptions); Context.ASTContext = ClangParser.ConvertASTContext(parser.ASTContext); 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) { 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() { var parser = new ClangParser(new Parser.AST.ASTContext()); parser.SourceParsed += OnSourceFileParsed; parser.ParseProject(Project); TargetInfo = parser.GetTargetInfo(Options); ASTContext = ClangParser.ConvertASTContext(parser.ASTContext); return(true); }
public bool ParseCode() { var parser = new ClangParser(new Parser.AST.ASTContext()); parser.SourcesParsed += OnSourceFileParsed; parser.ParseProject(Project, Options.UnityBuild); foreach (var source in Project.Sources.Where(s => s.Options != null)) { source.Options.Dispose(); } Context.TargetInfo = parser.GetTargetInfo(ParserOptions); Context.ASTContext = ClangParser.ConvertASTContext(parser.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); }