语义,cedet如何强制解析源文件 [英] Semantic, cedet how to force parsing of source files

查看:411
本文介绍了语义,cedet如何强制解析源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的emacs c / c ++开发设置中尝试cedet和语义,我非常满意,除了一个细节。

I have been experimenting with cedet and semantic in my emacs c/c++ development setup and I am quite satisfied with it except for one small detail.

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

I use ede-cpp-root-project to create a project and give the root directory of my project along with the directories where include files reside like below:

(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 ,它会告诉我没有找到合适的实现。

This allows me to easily jump to the declarations of functions with semantic-ia-fast-jump but it does not get me to the definitions of those functions. So it seems to only be dealing with header files and totally ignore source files. Even if I go on the declaration of the function and trigger semantic-analyze-proto-impl-toggle it will tell me that no suitable implementation could be found.

如果我手动打开函数的实现所在的源文件,那么它只有语义解析,所有上面提到的函数工作。

If I manually open the source file where the implementation of the function is located, then and only then it is parsed by semantic and all the above mentioned functions work.

所以我的问题是,手动打开包含在我的项目的根目录下的所有源文件或手动包括在 ede-cpp-root-project 通过:spp-files 参数是否有任何其他方法强制解析目录下的所有源文件?

So my question is, short of manually opening all source files included underneath my project's root directory or manually including them in ede-cpp-root-project via the :spp-files argument is there any other way to force parsing of all source files under a directory?

谢谢!

推荐答案

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

After ignoring this problem for a long time I thought I should spend some quality time reading on elisp and try to figure out a work-around. It is not the prettiest elisp code there is, since I use elisp only for my emacs needs but it does what I need.

(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-dirpath / to / dir / root /。* regex)或者从缓冲区中按 Mx lk-parse-curdir-c 所有来自buferr的访问文件名目录的c / c ++相关文件。

To use it either call the function directly like so: (my-semantic-parse-dir "path/to/dir/root/" ".*regex") or press M-x lk-parse-curdir-c from a buffer to recursively scan all c/c++ related files from that buferr's visiting filename directory.

调用函数的另一个也许是最好的方法是通过调用 lk-parse-dir-c

An alternate and perhaps preferrable way to call the function is by invoking lk-parse-dir-c interactively which in turn will prompt you for a directory to parse.

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

If any elisp guru has a better solution or suggestions to improve the code I would love to hear them.

这篇关于语义,cedet如何强制解析源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆