public static void Check(this CXErrorCode errorCode) { if (errorCode != CXErrorCode.CXError_Success) { throw new ErrorCodeException((ErrorCode)errorCode); } }
public Span <byte> WriteToBuffer(uint options, out CXErrorCode errorCode) { sbyte *pBuffer; uint size; errorCode = clang.VirtualFileOverlay_writeToBuffer(this, options, &pBuffer, &size); return(new Span <byte>(pBuffer, (int)size)); }
public Span <byte> WriteToBuffer(uint options, out CXErrorCode errorCode) { sbyte *pBuffer; uint size; errorCode = clang.ModuleMapDescriptor_writeToBuffer(this, options, &pBuffer, &size); return(new Span <byte>(pBuffer, (int)size)); }
public void MapError(string vPath, string rPath, CXErrorCode expErr) { vPath = Fix(vPath); rPath = Fix(rPath); var err = VFO.AddFileMapping(vPath, rPath); Assert.AreEqual(expErr, err); }
public void MapError(string vPath, string rPath, CXErrorCode expErr) { vPath = Fix(vPath); rPath = Fix(rPath); var err = clang.VirtualFileOverlay_addFileMapping(VFO, vPath, rPath); Assert.Equal(expErr, err); }
/// <summary> /// The CreateTranslationUnit /// </summary> /// <param name="astFileName">The astFileName<see cref="string"/></param> /// <param name="errorCode">The errorCode<see cref="CXErrorCode"/></param> /// <returns>The <see cref="TranslationUnit"/></returns> public TranslationUnit CreateTranslationUnit(string astFileName, out CXErrorCode errorCode) { IntPtr pTranslationUnit = IntPtr.Zero; errorCode = clang.clang_createTranslationUnit2(this.m_value, astFileName, out pTranslationUnit); if (pTranslationUnit == IntPtr.Zero) { return(null); } return(new TranslationUnit(pTranslationUnit)); }
/// <summary> /// The Reparse /// </summary> /// <param name="unsavedFiles">The unsavedFiles<see cref="UnsavedFile[]"/></param> /// <param name="reparseFlags">The reparseFlags<see cref="CXReparse_Flags"/></param> public CXErrorCode Reparse(UnsavedFile[] unsavedFiles, CXReparse_Flags reparseFlags) { UnsavedFile[] unsavedFilesArray = unsavedFiles; if (unsavedFilesArray == null) { unsavedFilesArray = new UnsavedFile[0]; } CXErrorCode errorCode = (CXErrorCode)clang.clang_reparseTranslationUnit(this.m_value, (uint)unsavedFilesArray.Length, unsavedFilesArray.Select(x => (CXUnsavedFile)x.Value).ToArray(), (uint)reparseFlags); return(errorCode); }
/// <summary> /// The Index /// </summary> /// <param name="translationUnit">The translationUnit<see cref="TranslationUnit"/></param> /// <param name="indexOptFlags">The indexOptFlags<see cref="CXIndexOptFlags"/></param> /// <returns>The <see cref="CXErrorCode"/></returns> public unsafe CXErrorCode Index(TranslationUnit translationUnit, object param, CXIndexOptFlags indexOptFlags) { if (param == null) { throw new ArgumentNullException("param"); } GCHandle paramGCHandle = GCHandle.Alloc(param, GCHandleType.Weak); using (Pointer <IndexerCallbacks> ptrIndexerCallbacks = new Pointer <IndexerCallbacks>(this._indexerCallbacks)) { CXErrorCode errorCode = (CXErrorCode)clang.clang_indexTranslationUnit(this.m_value, GCHandle.ToIntPtr(paramGCHandle), ptrIndexerCallbacks, (uint)(ptrIndexerCallbacks.Size), (uint)indexOptFlags, (IntPtr)translationUnit.Value); paramGCHandle.Free(); return(errorCode); } }
public Span <byte> WriteToBuffer(uint options, out CXErrorCode errorCode) { sbyte *pBuffer; uint size; errorCode = clang.ModuleMapDescriptor_writeToBuffer(this, options, &pBuffer, &size); #if NETSTANDARD var result = new byte[checked ((int)size)]; fixed(byte *pResult = result) { Buffer.MemoryCopy(pBuffer, pResult, size, size); } return(result); #else return(new Span <byte>(pBuffer, (int)size)); #endif }
public CodeEditor() { this._sourceCodeName = @"D:\llvm\tools\clang\tools\driver\driver.cpp"; this.code = System.IO.File.ReadAllText(this._sourceCodeName); this.AppendText(code); //var indexAction = index.CreateIndexAction(new IndexActionEventHandler()); string includes = @"-ID:\llvm\build\tools\clang\tools\driver -ID:\llvm\tools\clang\tools\driver -ID:\llvm\tools\clang\include -ID:\llvm\build\tools\clang\include -ID:\llvm\build\include -ID:\llvm\include -emit-ast"; var splitedStringArrays = includes.Split(' '); string astFileName = "d:\test.ast"; //indexAction.Index(tu, LibClang.Intertop.CXIndexOptFlags.CXIndexOpt_IndexFunctionLocalSymbols); this.task = new Task(() => { this.index = new Index(true, true); this.index.GlobalOptFlags = LibClang.Intertop.CXGlobalOptFlags.CXGlobalOpt_ThreadBackgroundPriorityForEditing; CXErrorCode xErrorCode = CXErrorCode.CXError_Success; if (System.IO.File.Exists(astFileName)) { this.translationUnit = index.CreateTranslationUnit(astFileName); } else { this.translationUnit = index.Parse(this._sourceCodeName, splitedStringArrays, null, CXTranslationUnit_Flags.CXTranslationUnit_DetailedPreprocessingRecord | CXTranslationUnit_Flags.CXTranslationUnit_Incomplete | CXTranslationUnit_Flags.CXTranslationUnit_IncludeBriefCommentsInCodeCompletion | CXTranslationUnit_Flags.CXTranslationUnit_CreatePreambleOnFirstParse | CXTranslationUnit_Flags.CXTranslationUnit_KeepGoing | Clang.DefaultEditingTranslationUnitOptions , out xErrorCode); this.translationUnit.Save(astFileName, CXSaveTranslationUnit_Flags.CXSaveTranslationUnit_None); } while (true) { this.autoResetEvent.WaitOne(); var unsavedFile = new UnsavedFile[] { new UnsavedFile(this._sourceCodeName, this.code) }; this.translationUnit.Reparse(unsavedFile, LibClang.Intertop.CXReparse_Flags.CXReparse_None); CodeCompleteResults codeCompleteResults = this.translationUnit.CodeCompleteAt(this._sourceCodeName, (uint)this.line, (uint)this.column, unsavedFile, Clang.DefaultCodeCompleteFlags | CXCodeComplete_Flags.CXCodeComplete_IncludeBriefComments | CXCodeComplete_Flags.CXCodeComplete_IncludeCodePatterns | CXCodeComplete_Flags.CXCodeComplete_IncludeCompletionsWithFixIts ); codeCompleteResults.Sort(); this.autoResetEvent.Reset(); Application.Current.Dispatcher.BeginInvoke(new Action(() => { this.completions.Clear(); foreach (var item in codeCompleteResults.CompletionResults) { foreach (var chunk in item.Chunks) { this.completions.Add(chunk.CompletionChunkKind + ":" + chunk.Text); foreach (var cChunk in chunk.Chunks) { this.completions.Add(cChunk.Text); } } this.completions.Add("-------------------------------------------------------------------------"); } })); } }); this.task.Start(); }
/// <summary> /// The IndexSourceFile /// </summary> /// <param name="sourceFile">The sourceFile<see cref="string"/></param> /// <param name="commandLineArgs">The commandLineArgs<see cref="string[]"/></param> /// <param name="unsavedFiles">The unsavedFiles<see cref="UnsavedFile[]"/></param> /// <param name="indexOptFlags">The indexOptFlags<see cref="CXIndexOptFlags"/></param> /// <param name="translationUnit_Flags">The translationUnit_Flags<see cref="CXTranslationUnit_Flags"/></param> /// <param name="errorCode">The errorCode<see cref="CXErrorCode"/></param> /// <returns>The <see cref="CXErrorCode"/></returns> public TranslationUnit IndexSourceFile(string sourceFile, string[] commandLineArgs, UnsavedFile[] unsavedFiles, CXIndexOptFlags indexOptFlags, CXTranslationUnit_Flags translationUnit_Flags, out CXErrorCode errorCode) { TranslationUnit translationUnit = null; string[] commandLineArgsArray = commandLineArgs; UnsavedFile[] unsavedFilesArray = unsavedFiles; if (commandLineArgsArray == null) { commandLineArgsArray = new string[0]; } if (unsavedFilesArray == null) { unsavedFilesArray = new UnsavedFile[0]; } using (Pointer <IndexerCallbacks> ptrIndexerCallbacks = new Pointer <IndexerCallbacks>(this._indexerCallbacks)) { IntPtr pTU = IntPtr.Zero; errorCode = (CXErrorCode)clang.clang_indexSourceFile(this.m_value, IntPtr.Zero, ptrIndexerCallbacks, (uint)(ptrIndexerCallbacks.Size), (uint)indexOptFlags, sourceFile, commandLineArgsArray, commandLineArgsArray.Length, unsavedFilesArray.Select(x => (CXUnsavedFile)x.Value).ToArray(), (uint)unsavedFilesArray.Length, out pTU, (uint)translationUnit_Flags ); if (pTU != IntPtr.Zero) { translationUnit = new TranslationUnit(pTU); } return(translationUnit); } }
/// <summary> /// The ParseWithFullArguments /// </summary> /// <param name="sourceFileName">The sourceFileName<see cref="string"/></param> /// <param name="globalOptFlags">The globalOptFlags<see cref="CXGlobalOptFlags"/></param> /// <param name="commandLineArgs">The commandLineArgs<see cref="string[]"/></param> /// <param name="unsavedFiles">The unsavedFiles<see cref="UnsavedFile[]"/></param> /// <param name="errorCode">The errorCode<see cref="CXErrorCode"/></param> /// <returns>The <see cref="TranslationUnit"/></returns> public TranslationUnit Parse(string sourceFileName, string clangExecutablePath, string[] commandLineArgs, UnsavedFile[] unsavedFiles, CXTranslationUnit_Flags globalOptFlags, out CXErrorCode errorCode) { IntPtr pTranslationUnit = IntPtr.Zero; string[] commandLineArgsArray = commandLineArgs; UnsavedFile[] unsavedFilesArray = unsavedFiles; if (string.IsNullOrEmpty(clangExecutablePath) || string.IsNullOrWhiteSpace(clangExecutablePath)) { errorCode = CXErrorCode.CXError_InvalidArguments; return(null); } if (commandLineArgsArray == null || commandLineArgsArray.Length == 0) { commandLineArgsArray = new string[1] { clangExecutablePath }; } else { commandLineArgsArray = Array.CreateInstance(typeof(string), 1 + commandLineArgs.Length) as string[]; commandLineArgsArray[0] = clangExecutablePath; Array.Copy(commandLineArgs, 0, commandLineArgsArray, 1, commandLineArgs.Length); } if (unsavedFilesArray == null) { unsavedFilesArray = new UnsavedFile[0]; } errorCode = clang.clang_parseTranslationUnit2FullArgv(this.m_value, sourceFileName, commandLineArgsArray, commandLineArgsArray.Length, unsavedFiles.Select(x => (CXUnsavedFile)x.Value).ToArray(), (uint)unsavedFiles.Length, (uint)globalOptFlags, out pTranslationUnit); if (pTranslationUnit == IntPtr.Zero) { return(null); } return(new TranslationUnit(pTranslationUnit)); }
/// <summary> /// The Parse /// </summary> /// <param name="sourceFileName">The sourceFileName<see cref="string"/></param> /// <param name="globalOptFlags">The globalOptFlags<see cref="CXGlobalOptFlags"/></param> /// <param name="commandLineArgs">The commandLineArgs<see cref="string[]"/></param> /// <param name="unsavedFiles">The unsavedFiles<see cref="UnsavedFile[]"/></param> /// <param name="errorCode">The errorCode<see cref="CXErrorCode"/></param> /// <returns>The <see cref="TranslationUnit"/></returns> public TranslationUnit Parse(string sourceFileName, string[] commandLineArgs, UnsavedFile[] unsavedFiles, CXTranslationUnit_Flags globalOptFlags, out CXErrorCode errorCode) { IntPtr pTranslationUnit = IntPtr.Zero; string[] commandLineArgsArray = commandLineArgs; UnsavedFile[] unsavedFilesArray = unsavedFiles; if (commandLineArgsArray == null) { commandLineArgsArray = new string[0]; } if (unsavedFilesArray == null) { unsavedFilesArray = new UnsavedFile[0]; } errorCode = clang.clang_parseTranslationUnit2(this.m_value, sourceFileName, commandLineArgsArray, commandLineArgsArray.Length, unsavedFilesArray.Select(x => (CXUnsavedFile)x.Value).ToArray(), (uint)unsavedFilesArray.Length, (uint)globalOptFlags, out pTranslationUnit); if (pTranslationUnit == IntPtr.Zero) { return(null); } return(new TranslationUnit(pTranslationUnit)); }