internal static extern ErrorCode clang_indexTranslationUnit(CXIndexAction index_action, CXClientData client_data, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] IndexerCallbacks[] index_callbacks, uint index_callbacks_size, IndexOptionFlags index_options, CXTranslationUnit tu);
internal static extern ErrorCode clang_indexSourceFile(CXIndexAction _, CXClientData client_data, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] IndexerCallbacks [] index_callbacks, uint index_callbacks_size, IndexOptionFlags index_options, string source_filename, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 7)] string [] command_line_args, // const char *const * int num_command_line_args, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 9)] CXUnsavedFile[] unsaved_files, uint num_unsaved_files, out CXTranslationUnit out_TU, TranslationUnitFlags TU_options);
/// <summary> /// Index the given translation unit via callbacks implemented through <see cref="ClangIndexerCallbacks"/>. /// </summary> /// <remarks> /// The order of callback invocations is not guaranteed to be the same as /// when indexing a source file. The high level order will be: /// /// -Preprocessor callbacks invocations /// -Declaration/reference callbacks invocations /// -Diagnostic callback invocations /// </remarks> /// <param name="clientData">data supplied by the client, which will /// be passed to the invoked callbacks.</param> /// <param name="indexCallbacks">Pointer to indexing callbacks that the client /// implements.</param> /// <param name="options">A bitmask of options that affects how indexing is /// performed. This should be a bitwise OR of the <see cref="IndexOptionFlags"/> flags.</param> /// <param name="translationUnit"></param> public void IndexTranslationUnit(IntPtr clientData, ClangIndexerCallbacks [] indexCallbacks, IndexOptionFlags options, ClangTranslationUnit translationUnit) { if (indexCallbacks == null) { throw new ArgumentNullException("indexCallbacks"); } if (translationUnit == null) { throw new ArgumentNullException("translationUnit"); } var cbs = indexCallbacks.Select(ic => ic.ToNative()).ToArray(); var ret = LibClang.clang_indexTranslationUnit(Handle, clientData, cbs, (uint)(cbs.Length * Marshal.SizeOf(typeof(IndexerCallbacks))), options, translationUnit.Handle); if (ret != 0) { throw new ClangServiceException(string.Format("Faied to index translation unit: {0} Reason: {1}", translationUnit.TranslationUnitSpelling, ret)); } }
/// <summary> /// Index the given source file and the translation unit corresponding /// to that file via callbacks implemented through <see cref="ClangIndexerCallbacks"/>. /// </summary> /// <param name="clientData">data supplied by the client, which will /// be passed to the invoked callbacks.</param> /// <param name="indexCallbacks">Pointer to indexing callbacks that the client /// implements.</param> /// <param name="options">A bitmask of options that affects how indexing is /// performed. This should be a bitwise OR of the <see cref="IndexOptionFlags"/> flags.</param> /// <param name="sourceFilename"> /// The name of the source file to load, or NULL if the /// source file is included in \p command_line_args. /// </param> /// <param name="commandLineArgs"> /// The command-line arguments that would be /// passed to the clang executable if it were being invoked out-of-process. /// These command-line options will be parsed and will affect how the translation /// unit is parsed. Note that the following options are ignored: '-c', /// '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'. /// </param> /// <param name="unsavedFiles"> /// the files that have not yet been saved to disk /// but may be required for parsing, including the contents of /// those files. The contents and name of these files (as specified by /// CXUnsavedFile) are copied when necessary, so the client only needs to /// guarantee their validity until the call to this function returns. /// </param> /// <param name="translationUnitOptions"> /// A bitmask of options that affects how the translation unit /// is managed but not its compilation. This should be a bitwise OR of the /// <see cref="TranslationUnitFlags"/> flags. /// </param> /// <returns><see cref="ClangTranslationUnit"/> that can be reused after indexing is finished.</returns> public ClangTranslationUnit IndexSourceFile(IntPtr clientData, ClangIndexerCallbacks [] indexCallbacks, IndexOptionFlags options, string sourceFileName, string [] commandLineArgs, ClangUnsavedFile [] unsavedFiles, TranslationUnitFlags translationUnitOptions) { if (indexCallbacks == null) { throw new ArgumentNullException("indexCallbacks"); } var cbs = indexCallbacks.Select(ic => ic.ToNative()).ToArray(); IntPtr tu; var uf = unsavedFiles.ToNative(); var ret = LibClang.clang_indexSourceFile(Handle, clientData, cbs, (uint)cbs.Length, options, sourceFileName, commandLineArgs, commandLineArgs.Length, uf, (uint)uf.Length, out tu, translationUnitOptions); if (ret != 0) { throw new ClangServiceException("Faied to index source file"); } return(new ClangTranslationUnit(tu)); }
/// <summary> /// Index Source File with Full Argument Variables /// </summary> /// <param name="client_data">Native Client Data Pointer</param> /// <param name="index_callbacks">Clang Indexer Callbacks</param> /// <param name="options">Index Option Flags</param> /// <param name="source_filename">Source File Name</param> /// <param name="command_line_args">Command Line Arguments</param> /// <param name="unsaved_files">Clang Unsaved Files</param> /// <param name="out_tu">Clang Translation Unit</param> /// <param name="tu_options">Translation Unit Parse Options</param> /// <returns>Error Code</returns> public ErrorCode IndexSourceFileFullArgv(IntPtr client_data, ClangIndexerCallbacks[] index_callbacks, IndexOptionFlags options, string source_filename, string[] command_line_args, ClangUnsavedFile[] unsaved_files, out ClangTranslationUnit out_tu, TranslationUnitFlags tu_options) { if (index_callbacks == null) { throw new ArgumentNullException("index_callbacks is null"); } var native_callbacks = index_callbacks.Select(ic => ic.ToNative()).ToArray(); var native_unsaved_files = unsaved_files.Select(uf => uf.ToNative()).ToArray(); var ret = LibClang.clang_indexSourceFileFullArgv(this.Handle, client_data, native_callbacks, (uint)native_callbacks.Length, options, source_filename, command_line_args, command_line_args.Length, native_unsaved_files, (uint)native_unsaved_files.Length, out var native_out_tu, tu_options); out_tu = (ret == ErrorCode.Success) ? native_out_tu.ToManaged <ClangTranslationUnit>() : null; return(ret); }
/// <summary> /// Index Clang Translation Unit /// </summary> /// <param name="client_data">Native Client Data Pointer</param> /// <param name="index_callbacks">Clang Indexer Callbacks</param> /// <param name="options">Index Option Flags</param> /// <param name="tu">Clang Transaltion Unit</param> /// <returns>Error Code</returns> public ErrorCode IndexTranslationUnit(IntPtr client_data, ClangIndexerCallbacks[] index_callbacks, IndexOptionFlags options, ClangTranslationUnit tu) { if (index_callbacks == null) { throw new ArgumentNullException("Indexer Callbacks is null"); } if (tu == null) { throw new ArgumentNullException("Translation Unit is null"); } var native_callbacks = index_callbacks.Select(ic => ic.ToNative()).ToArray(); var ret = LibClang.clang_indexTranslationUnit(this.Handle, client_data, native_callbacks, (uint)native_callbacks.Length, options, tu.Handle); return(ret); }