Beispiel #1
0
 public TranslationUnit CreateTranslationUnit(string filename, Options[] clangArgs, UnsavedFile[] unsavedFiles = null, TranslationUnitFlags options = TranslationUnitFlags.None) {
     var args = clangArgs.Select(arg => "-" + arg.ToString().Replace("_", "-")).ToArray();
     return CreateTranslationUnit(
         filename,
         args,
         unsavedFiles,
         options);
 }
Beispiel #2
0
		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);
		}
Beispiel #3
0
 public void TestMemberCompletion() {
     const string completionLine = "instance.";
     const string edited = "#include <iostream>\n" +
                           "#include \"fake-class.h\"\n" +
                           "int main() {\n" +
                           "FakeClass instance;\n" +
                           completionLine + "\n" +
                           "}\n";
     var unsavedFile = new UnsavedFile(edited, MainCpp, edited.Length);
     uint line = (uint)edited.Substring(0, edited.IndexOf(completionLine)).Count(character => character == '\n') + 1;
     uint column = (uint)completionLine.Length + 1;
     var completions = Main.CodeCompleteAt(line, column, new[] { unsavedFile }, CodeCompletion.Options.IncludeBriefComments).OrderBy(completion => completion.Priority).Take(10);
     Assert.AreEqual(5, completions.Count());
 }
Beispiel #4
0
 public TranslationUnit CreateTranslationUnit(string filename, string[] clangArgs = null, UnsavedFile[] unsavedFiles = null, TranslationUnitFlags options = TranslationUnitFlags.None) {
     if (!System.IO.File.Exists(filename)) {
         throw new System.IO.FileNotFoundException("Couldn't find input file.", filename);
     }
     clangArgs = clangArgs ?? new string[0];
     unsavedFiles = unsavedFiles ?? new UnsavedFile[0];
     return new TranslationUnit(
         filename,
         Interop.clang_parseTranslationUnit(
             Native,
             filename,
             clangArgs,
             clangArgs.Length,
             unsavedFiles.Select(f => f.Native).ToArray(),
             (uint)unsavedFiles.Length,
             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);
        }
Beispiel #6
0
 public unsafe static extern CodeCompleteResults* clang_codeCompleteAt(
     IntPtr translationUnit, string filename, uint line, uint column,
     UnsavedFile[] unsavedFiles, uint numUnsavedFiles, uint options);
Beispiel #7
0
 public static extern IntPtr clang_parseTranslationUnit(
     IntPtr index, string filename, string[] args, int numArgs,
     UnsavedFile[] unsavedFiles, uint numUnsavedFiles, TranslationUnitFlags options);
Beispiel #8
0
 public static extern IntPtr clang_createTranslationUnitFromSourceFile(
     IntPtr index, string sourceFilename, int numClangCommandLineArgs,
     string[] clangCommandLineArgs, uint numUnsavedFiles, UnsavedFile[] unsavedFiles);
        void ReadHeader(string headerFile)
        {
            Console.Write('.');

            var unsavedFiles = new UnsavedFile[] { };
            if (headerFile.EndsWith("PosixThreadSupport.h"))
            {
                List<string> clangOptionsPThread = new List<string>(clangOptions);
                clangOptionsPThread.Add("-DUSE_PTHREADS");
                currentTU = index.CreateTranslationUnit(headerFile, clangOptionsPThread.ToArray(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies);
            }
            else
            {
                currentTU = index.CreateTranslationUnit(headerFile, clangOptions.ToArray(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies);
            }
            var cur = currentTU.Cursor;
            cur.VisitChildren(HeaderVisitor);
            currentTU.Dispose();
            currentTU = null;
            headerQueue.Remove(headerFile);
        }
        void ReadHeader(string headerFile)
        {
            Console.Write('.');

            var unsavedFiles = new UnsavedFile[] { };
            using (_context.TranslationUnit = index.CreateTranslationUnit(headerFile,
                clangOptions.ToArray(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies))
            {
                var cur = _context.TranslationUnit.Cursor;
                _context.Namespace = "";
                cur.VisitChildren(HeaderVisitor);
            }
            _context.TranslationUnit = null;
            headerQueue.Remove(headerFile);
        }