/** * \brief Return the CXTranslationUnit for a given source file and the provided * command line arguments one would pass to the compiler. * * Note: The 'source_filename' argument is optional. If the caller provides a * NULL pointer, the name of the source file is expected to reside in the * specified command line arguments. * * Note: When encountered in 'clang_command_line_args', the following options * are ignored: * * '-c' * '-emit-ast' * '-fsyntax-only' * '-o <output file>' (both '-o' and '<output file>' are ignored) * * \param CIdx The index object with which the translation unit will be * associated. * * \param source_filename - The name of the source file to load, or NULL if the * source file is included in \p clang_command_line_args. * * \param num_clang_command_line_args The number of command-line arguments in * \p clang_command_line_args. * * \param clang_command_line_args The command-line arguments that would be * passed to the \c 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', '-fsyntex-only' (which is the default), and '-o <output file>'. * * \param num_unsaved_files the number of unsaved file entries in \p * unsaved_files. * * \param unsaved_files the files that have not yet been saved to disk * but may be required for code completion, 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. */ func (idx Index) CreateTranslationUnitFromSourceFile(fname string, args []string, us UnsavedFiles) TranslationUnit { var ( c_fname *C.char = nil c_us = us.to_c() ) defer c_us.Dispose() if fname != "" { c_fname = C.CString(fname) } defer C.free(unsafe.Pointer(c_fname)) c_nargs := C.int(len(args)) c_cmds := make([]*C.char, len(args)) for i, _ := range args { cstr := C.CString(args[i]) defer C.free(unsafe.Pointer(cstr)) c_cmds[i] = cstr } o := C.clang_createTranslationUnitFromSourceFile( idx.c, c_fname, c_nargs, &c_cmds[0], C.uint(len(c_us)), c_us.ptr()) return TranslationUnit{o} }
/* Return the CXTranslationUnit for a given source file and the provided command line arguments one would pass to the compiler. Note: The 'source_filename' argument is optional. If the caller provides a NULL pointer, the name of the source file is expected to reside in the specified command line arguments. Note: When encountered in 'clang_command_line_args', the following options are ignored: '-c' '-emit-ast' '-fsyntax-only' '-o \<output file>' (both '-o' and '\<output file>' are ignored) Parameter CIdx The index object with which the translation unit will be associated. Parameter source_filename The name of the source file to load, or NULL if the source file is included in \p clang_command_line_args. Parameter num_clang_command_line_args The number of command-line arguments in \p clang_command_line_args. Parameter clang_command_line_args 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>'. Parameter num_unsaved_files the number of unsaved file entries in \p unsaved_files. Parameter unsaved_files the files that have not yet been saved to disk but may be required for code completion, 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. */ func (i Index) TranslationUnitFromSourceFile(sourceFilename string, clangCommandLineArgs []string, unsavedFiles []UnsavedFile) TranslationUnit { ca_clangCommandLineArgs := make([]*C.char, len(clangCommandLineArgs)) var cp_clangCommandLineArgs **C.char if len(clangCommandLineArgs) > 0 { cp_clangCommandLineArgs = &ca_clangCommandLineArgs[0] } for i := range clangCommandLineArgs { ci_str := C.CString(clangCommandLineArgs[i]) defer C.free(unsafe.Pointer(ci_str)) ca_clangCommandLineArgs[i] = ci_str } gos_unsavedFiles := (*reflect.SliceHeader)(unsafe.Pointer(&unsavedFiles)) cp_unsavedFiles := (*C.struct_CXUnsavedFile)(unsafe.Pointer(gos_unsavedFiles.Data)) c_sourceFilename := C.CString(sourceFilename) defer C.free(unsafe.Pointer(c_sourceFilename)) return TranslationUnit{C.clang_createTranslationUnitFromSourceFile(i.c, c_sourceFilename, C.int(len(clangCommandLineArgs)), cp_clangCommandLineArgs, C.uint(len(unsavedFiles)), cp_unsavedFiles)} }
//FIXME: handle unsaved-files func (idx Index) CreateTranslationUnitFromSourceFile(fname string, args []string) TranslationUnit { var c_fname *C.char = nil if fname != "" { c_fname = C.CString(fname) } defer C.free(unsafe.Pointer(c_fname)) c_nargs := C.int(len(args)) c_cmds := make([]*C.char, len(args)) for i, _ := range args { cstr := C.CString(args[i]) defer C.free(unsafe.Pointer(cstr)) c_cmds[i] = cstr } o := C.clang_createTranslationUnitFromSourceFile( idx.c, c_fname, c_nargs, &c_cmds[0], C.uint(0), nil) return TranslationUnit{o} }