internal static extern ErrorCode clang_parseTranslationUnit2FullArgv(CXIndex index, string source_filename, [MarshalAs(UnmanagedType.LPArray)] string[] command_line_args, int num_command_line_args, [MarshalAs(UnmanagedType.LPArray)] CXUnsavedFile[] unsaved_files, uint num_unsaved_files, TranslationUnitFlags options, out CXTranslationUnit out_tu);
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); }
internal static extern ErrorCode clang_indexSourceFileFullArgv(CXIndexAction index_action, 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, int num_command_line_args, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 9)] CXUnsavedFile[] unsaved_files, uint num_unsaved_files, out CXTranslationUnit out_tu, TranslationUnitFlags tu_options);
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)); }
/// <summary> /// Execute Translation Unit Handler /// </summary> /// <param name="src_path">Source Path</param> /// <param name="command_line_args">Command Line Arguments</param> /// <param name="options">Parse Options</param> /// <param name="display_diag">Display Diagnostics Flag</param> public void Execute(string src_path, string[] command_line_args, TranslationUnitFlags options = TranslationUnitFlags.None, bool display_diag = false) { this.SourcePath = src_path; this.CommandLineArgs = command_line_args; this.ParseOptions = options; this.DisplayDiagnostic = display_diag; using (var index = Clang.CreateIndex(false, display_diag)) { using (var tu = index.ParseTranslationUnit(src_path, command_line_args, new ClangUnsavedFile[0], options)) { this.ExecuteCore(index, tu); } } }
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))); }
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)); }
public static extern IntPtr clang_parseTranslationUnit( IntPtr index, string filename, string[] args, int numArgs, UnsavedFile[] unsavedFiles, uint numUnsavedFiles, TranslationUnitFlags options);
internal static extern CXTranslationUnit clang_parseTranslationUnit(CXIndex cIdx, string source_filename, [MarshalAs(UnmanagedType.LPArray)] string[] command_line_args, int num_command_line_args, [MarshalAs(UnmanagedType.LPArray)] CXUnsavedFile[] unsaved_files, uint num_unsaved_files, TranslationUnitFlags options);
/// <summary> /// Parse Clang Translation Unit /// </summary> /// <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="options">Translation Unit Parse Options</param> /// <returns>Clang Translation Unit</returns> public ClangTranslationUnit ParseTranslationUnit(string source_filename, string[] command_line_args, ClangUnsavedFile[] unsaved_files, TranslationUnitFlags options) { return(LibClang.clang_parseTranslationUnit(this.Handle, source_filename, command_line_args, command_line_args.Length, unsaved_files.ToNativeArray(), (uint)unsaved_files.Length, options).ToManaged <ClangTranslationUnit>()); }
/// <summary> /// Execute Cursor Visitor Sample /// </summary> /// <param name="src_path">Source Path</param> /// <param name="command_line_args">Command Line Arguments</param> /// <param name="options">Translation Unit Parse Options</param> /// <param name="display_diag">Display Diagnostics</param> public static void Execute(string src_path, string[] command_line_args, TranslationUnitFlags options = TranslationUnitFlags.None, bool display_diag = false) { var impl = new CursorVisitorImpl(); impl.Execute(src_path, command_line_args, options, display_diag); }
/// <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> /// Parse the given source file and the translation unit corresponding /// to that file. /// </summary> /// <remarks> /// This routine is the main entry point for the Clang C API, providing the /// ability to parse a source file into a translation unit that can then be /// queried by other functions in the API. This routine accepts a set of /// command-line arguments so that the compilation can be configured in the same /// way that the compiler is configured on the command line. /// </remarks> /// <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="options"> /// 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> /// A new translation unit describing the parsed code and containing /// any diagnostics produced by the compiler. If there is a failure from which /// the compiler cannot recover, returns <c>null</c>. /// </returns> public ClangTranslationUnit ParseTranslationUnit(string sourceFilename, string [] commandLineArgs, ClangUnsavedFile [] unsavedFiles, TranslationUnitFlags options) { var files = (unsavedFiles ?? new ClangUnsavedFile [0]).Select(u => new CXUnsavedFile(u.FileName, u.Contents)).ToArray(); return(new ClangTranslationUnit(LibClang.clang_parseTranslationUnit(Handle, sourceFilename, commandLineArgs, (commandLineArgs ?? new string [0]).Length, files, (uint)files.Length, options))); }
public static extern IntPtr clang_parseTranslationUnit( IntPtr index, string filename, string[] args, int numArgs, UnsavedFile[] unsavedFiles, uint numUnsavedFiles, TranslationUnitFlags options);
/// <summary> /// Parse the given source file and the translation unit corresponding /// to that file. /// </summary> /// <remarks> /// This routine is the main entry point for the Clang C API, providing the /// ability to parse a source file into a translation unit that can then be /// queried by other functions in the API. This routine accepts a set of /// command-line arguments so that the compilation can be configured in the same /// way that the compiler is configured on the command line. /// </remarks> /// <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="options"> /// 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> /// <param name="translationUnit"> /// A new translation unit describing the parsed code and containing /// any diagnostics produced by the compiler. If there is a failure from which /// the compiler cannot recover, returns <c>null</c>. /// </param> /// <returns>An <seealso cref="ErrorCode"/>.</returns> public ErrorCode ParseTranslationUnit(string sourceFilename, string [] commandLineArgs, ClangUnsavedFile [] unsavedFiles, TranslationUnitFlags options, out ClangTranslationUnit translationUnit) { var files = (unsavedFiles ?? new ClangUnsavedFile [0]).Select(u => new CXUnsavedFile(u.FileName, u.Contents)).ToArray(); IntPtr tuptr; ErrorCode error = LibClang.clang_parseTranslationUnit2(Handle, sourceFilename, commandLineArgs, commandLineArgs.Length, files, (uint)files.Length, options, out tuptr); translationUnit = error == ErrorCode.Success ? new ClangTranslationUnit(tuptr) : null; return(error); }
/// <summary> /// Parse Clang Translation Unit with Full Argument Variables /// </summary> /// <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="options">Translation Unit Parse Options</param> /// <param name="out_tu">Clang Translation Unit</param> /// <returns>Error Code</returns> public ErrorCode ParseTranslationUnitFullArgv(string source_filename, string[] command_line_args, ClangUnsavedFile[] unsaved_files, TranslationUnitFlags options, out ClangTranslationUnit out_tu) { var error_code = LibClang.clang_parseTranslationUnit2FullArgv(this.Handle, source_filename, command_line_args, command_line_args.Length, unsaved_files.ToNativeArray(), (uint)unsaved_files.Length, options, out var native_tu); out_tu = (error_code == ErrorCode.Success) ? native_tu.ToManaged <ClangTranslationUnit>() : null; return(error_code); }