private Scan(IEnumerable<TranslationUnit> sources) { _sources = sources; Sources = new List<SourceFile>(); Headers = new List<HeaderFile>(); Index = new Index(); }
public static void Run(Project project) { using (var index = new ClangSharp.Index()) { var scan = new Scan(project.Sources.AsParallel().Select(s => index.CreateTranslationUnit(s, project.PreprocessorDefines.Select(d => "-D" + d).Concat( project.IncludePaths.Select(p => "-I" + p)).ToArray()))); scan.VisitAll(); scan.BuildIndex(); } }
public static void CreateTestFiles() { System.IO.File.WriteAllText(FakeClassCpp, Resources.fake_class_cpp); System.IO.File.WriteAllText(FakeClassH, Resources.fake_class_h); System.IO.File.WriteAllText(OpaqueClassH, Resources.opaque_class_h); System.IO.File.WriteAllText(MainCpp, Resources.fake_main_cpp); System.IO.File.WriteAllText(KitchenSinkCpp, Resources.kitchen_sink); var args = new[] { Options.Weverything }; var unsavedFiles = new UnsavedFile[] { }; var options = TranslationUnitFlags.IncludeBriefCommentsInCodeCompletion | TranslationUnitFlags.DetailedPreprocessingRecord; Index = new Index(); Main = Index.CreateTranslationUnit(MainCpp, args, unsavedFiles, options); Class = Index.CreateTranslationUnit(FakeClassCpp, args, unsavedFiles, options); KitchenSink = Index.CreateTranslationUnit(KitchenSinkCpp, args, unsavedFiles, options); }
private void ReadHeaders() { using (var index = new Index()) { while (headerQueue.Any()) { _context.HeaderFilename = headerQueue.First(); Console.Write('.'); var unsavedFiles = new UnsavedFile[] {}; using (_context.TranslationUnit = index.CreateTranslationUnit(_context.HeaderFilename, clangOptions.ToArray(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies)) { var cur = _context.TranslationUnit.Cursor; cur.VisitChildren(HeaderVisitor); } _context.TranslationUnit = null; headerQueue.Remove(_context.HeaderFilename); } } Console.WriteLine(); Console.WriteLine("Read complete - headers: {0}, classes: {1}", project.HeaderDefinitions.Count, project.ClassDefinitions.Count); }
public CppReader(string sourceDirectory) { src = Path.GetFullPath(sourceDirectory); src = src.Replace('\\', '/'); string[] commonHeaders; List<string> excludedHeaders = new List<string>(); // Exclude C API excludedHeaders.Add(src + "Bullet-C-Api.h"); // Include directory clangOptions.Add("-I"); clangOptions.Add(src); // WorldImporter include directory clangOptions.Add("-I"); clangOptions.Add(src + "../Extras/Serialize/BulletWorldImporter"); // Specify C++ headers, not C ones clangOptions.Add("-x"); clangOptions.Add("c++-header"); // Exclude irrelevant methods excludedMethods.Add("operator new", null); excludedMethods.Add("operator delete", null); excludedMethods.Add("operator new[]", null); excludedMethods.Add("operator delete[]", null); excludedMethods.Add("operator+=", null); excludedMethods.Add("operator-=", null); excludedMethods.Add("operator*=", null); excludedMethods.Add("operator/=", null); excludedMethods.Add("operator==", null); excludedMethods.Add("operator!=", null); excludedMethods.Add("operator()", null); // Enumerate all header files in the source tree var headerFiles = Directory.EnumerateFiles(src, "*.h", SearchOption.AllDirectories); foreach (string header in headerFiles) { if (header.Contains("GpuSoftBodySolvers") || header.Contains("vectormath")) { continue; } string headerCanonical = header.Replace('\\', '/'); if (!excludedHeaders.Contains(headerCanonical)) { headerQueue.Add(headerCanonical); } } Console.Write("Reading headers"); index = new Index(); // Parse the common headers commonHeaders = new[] { src + "btBulletCollisionCommon.h", src + "btBulletDynamicsCommon.h" }; foreach (string commonHeader in commonHeaders) { if (!headerQueue.Contains(commonHeader)) { Console.WriteLine("Could not find " + commonHeader); return; } ReadHeader(commonHeader); } while (headerQueue.Count != 0) { ReadHeader(headerQueue[0]); } if (Directory.Exists(src + "..\\Extras\\")) { ReadHeader(src + "..\\Extras\\Serialize\\BulletFileLoader\\btBulletFile.h"); ReadHeader(src + "..\\Extras\\Serialize\\BulletWorldImporter\\btBulletWorldImporter.h"); ReadHeader(src + "..\\Extras\\Serialize\\BulletWorldImporter\\btWorldImporter.h"); ReadHeader(src + "..\\Extras\\Serialize\\BulletXmlWorldImporter\\btBulletXmlWorldImporter.h"); ReadHeader(src + "..\\Extras\\HACD\\hacdHACD.h"); } index.Dispose(); Console.WriteLine(); Console.WriteLine("Read complete - headers: " + HeaderDefinitions.Count + ", classes: " + ClassDefinitions.Count); }
public CppReader(WrapperProject project) { this.project = project; foreach (string sourceRelDir in project.SourceRootFoldersFull) { string sourceFullDir = Path.GetFullPath(sourceRelDir).Replace('\\', '/'); // Enumerate all header files in the source tree var headerFiles = Directory.EnumerateFiles(sourceFullDir, "*.h", SearchOption.AllDirectories); foreach (string headerFullDir in headerFiles) { string headerFullDirCanonical = headerFullDir.Replace('\\', '/'); //string headerRelDir = headerFullDirCanonical.Substring(sourceFullDir.Length); HeaderDefinition header; if (project.HeaderDefinitions.TryGetValue(headerFullDirCanonical, out header)) { if (header.IsExcluded) { continue; } } else { Console.WriteLine("New file {0}", headerFullDirCanonical); } headerQueue.Add(headerFullDirCanonical); } // Include directory clangOptions.Add("-I"); clangOptions.Add(sourceFullDir); } // WorldImporter include directory //clangOptions.Add("-I"); //clangOptions.Add(src + "../Extras/Serialize/BulletWorldImporter"); // Specify C++ headers, not C ones clangOptions.Add("-x"); clangOptions.Add("c++-header"); //clangOptions.Add("-DUSE_DOUBLE_PRECISION"); // Exclude irrelevant methods excludedMethods.Add("operator new"); excludedMethods.Add("operator delete"); excludedMethods.Add("operator new[]"); excludedMethods.Add("operator delete[]"); excludedMethods.Add("operator+="); excludedMethods.Add("operator-="); excludedMethods.Add("operator*="); excludedMethods.Add("operator/="); excludedMethods.Add("operator=="); excludedMethods.Add("operator!="); excludedMethods.Add("operator()"); Console.Write("Reading headers"); using (index = new Index()) { while (headerQueue.Count != 0) { ReadHeader(headerQueue[0]); } } Console.WriteLine(); Console.WriteLine("Read complete - headers: {0}, classes: {1}", project.HeaderDefinitions.Count, project.ClassDefinitions.Count); foreach (var @class in project.ClassDefinitions.Values.Where(c => !c.IsParsed)) { Console.WriteLine("Class removed: {0}", @class.FullyQualifiedName); } }