c++ - 语义,cedet如何强制解析源文件

标签 c++ c emacs cedet

我一直在我的 emacs c/c++ 开发设置中试验 cedet 和语义,除了一个小细节外,我对它非常满意。

我使用 ede-cpp-root-project 创建一个项目,并给出我的项目的根目录以及包含文件所在的目录,如下所示:

(ede-cpp-root-project "My Project"
                :name "My Project"
                :file "/path/to/rootdir/AFILE"
                :include-path '( 
                "/include2"
                "/include1"
                               )

                )

这使我可以使用 semantic-ia-fast-jump 轻松跳转到函数声明处,但无法让我跳转到这些函数的定义处。所以它似乎只处理头文件而完全忽略源文件。即使我继续声明函数并触发 semantic-analyze-proto-impl-toggle,它也会告诉我找不到合适的实现。

如果我手动打开函数实现所在的源文件,那么并且只有这样它才被语义解析并且所有上述函数都起作用。

所以我的问题是,没有手动打开项目根目录下包含的所有源文件或通过 :spp-files< 手动将它们包含在 ede-cpp-root-project argument 是否有其他方法可以强制解析目录下的所有源文件?

谢谢!

最佳答案

在长期忽略这个问题之后,我认为我应该花一些时间阅读 elisp 并尝试找出解决方法。它不是最漂亮的 elisp 代码,因为我使用 elisp 只是为了满足我的 emacs 需求,但它满足了我的需要。

(defvar c-files-regex ".*\\.\\(c\\|cpp\\|h\\|hpp\\)"
  "A regular expression to match any c/c++ related files under a directory")

(defun my-semantic-parse-dir (root regex)
  "
   This function is an attempt of mine to force semantic to
   parse all source files under a root directory. Arguments:
   -- root: The full path to the root directory
   -- regex: A regular expression against which to match all files in the directory
  "
  (let (
        ;;make sure that root has a trailing slash and is a dir
        (root (file-name-as-directory root))
        (files (directory-files root t ))
       )
    ;; remove current dir and parent dir from list
    (setq files (delete (format "%s." root) files))
    (setq files (delete (format "%s.." root) files))
    (while files
      (setq file (pop files))
      (if (not(file-accessible-directory-p file))
          ;;if it's a file that matches the regex we seek
          (progn (when (string-match-p regex file)
               (save-excursion
                 (semanticdb-file-table-object file))
           ))
          ;;else if it's a directory
          (my-semantic-parse-dir file regex)
      )
     )
  )
)

(defun my-semantic-parse-current-dir (regex)
  "
   Parses all files under the current directory matching regex
  "
  (my-semantic-parse-dir (file-name-directory(buffer-file-name)) regex)
)

(defun lk-parse-curdir-c ()
  "
   Parses all the c/c++ related files under the current directory
   and inputs their data into semantic
  "
  (interactive)
  (my-semantic-parse-current-dir c-files-regex)
)

(defun lk-parse-dir-c (dir)
  "Prompts the user for a directory and parses all c/c++ related files
   under the directory
  "
  (interactive (list (read-directory-name "Provide the directory to search in:")))
  (my-semantic-parse-dir (expand-file-name dir) c-files-regex)
)

(provide 'lk-file-search)

要使用它,可以像这样直接调用函数:(my-semantic-parse-dir "path/to/dir/root/"".*regex") 或按 M-x lk-parse-curdir-c 从缓冲区递归扫描所有 c/c++ 相关文件从该缓冲区的访问文件名目录。

调用该函数的另一种可能更可取的方法是通过交互方式调用 lk-parse-dir-c,这反过来会提示您输入要解析的目录。

如果任何 elisp 大师有更好的解决方案或改进代码的建议,我很乐意听取他们的意见。

关于c++ - 语义,cedet如何强制解析源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18230838/

相关文章:

c++ - sizeof 运算符的问题

c++ - 如何通过地址获取元组中元素的索引?

c++ - 如果我删除其他进程的共享内存会怎样?

带有数据文件的命令行参数

c - 用户输入的字符串转换为 double

emacs - 使用 org-babel 捕获 "diff"的输出

C++|在函数外声明类

c - C 中的定义宏实现

windows-7 - Windows 7 中的主目录和 .emacs 文件

Emacs:如何从当前焦点位置自动选择双引号中的所有文本?