简体   繁体   English

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

[英]Semantic, cedet how to force parsing of source files

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. 我在我的emacs c / c ++开发设置中一直在尝试使用cedet和semantic,除了一个小细节之外我对它非常满意。

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来创建一个项目,并给出我的项目的根目录以及包含文件所在的目录,如下所示:

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

                )

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. 这使我可以使用semantic-ia-fast-jump轻松跳转到函数的声明,但它不能让我了解这些函数的定义。 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. 即使我继续声明该函数并触发semantic-analyze-proto-impl-toggle它也会告诉我没有找到合适的实现。

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. 如果我手动打开函数实现所在的源文件,那么它只能通过语义进行解析,并且所有上述函数都能正常工作。

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? 所以我的问题是,没有手动打开项目根目录下包含的所有源文件,或者通过:spp-files参数手动将它们包含在ede-cpp-root-project ,还有其他任何方法可以强制解析所有源文件一个目录?

Thanks! 谢谢!

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. 在忽略了这个问题很长一段时间后,我以为我应该花一些时间阅读elisp,并尝试找出解决方法。 It is not the prettiest elisp code there is, since I use elisp only for my emacs needs but it does what I need. 它不是最漂亮的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)

To use it either call the function directly like so: (my-semantic-parse-dir "path/to/dir/root/" ".*regex") or press Mx lk-parse-curdir-c from a buffer to recursively scan all c/c++ related files from that buferr's visiting filename directory. 要使用它,请直接调用函数:( (my-semantic-parse-dir "path/to/dir/root/" ".*regex") Mx lk-parse-curdir-c (my-semantic-parse-dir "path/to/dir/root/" ".*regex")或者从缓冲区按Mx lk-parse-curdir-c递归从该buferr的访问文件名目录中扫描所有与c / 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. 调用函数的另一种可能的优选方法是通过交互方式调用lk-parse-dir-c ,这反过来会提示您解析一个目录。

If any elisp guru has a better solution or suggestions to improve the code I would love to hear them. 如果任何elisp guru有更好的解决方案或改进代码的建议,我很乐意听到它们。

I have implemented this for Python recently. 我最近为Python实现了这个。 It could be adopt for C/C++ with minor changes. 它可以用于C / C ++,只需稍作修改即可。

(defvar python-extention-list (list "py"))

(defun semanticdb-rescan-directory (pathname)
  (dolist (file (cddr (directory-files pathname t)))
    (if (file-directory-p file)
        (semanticdb-rescan-directory file)
      (when (member (file-name-extension file) python-extention-list)
        (message "Parsing %s file." file)
        (ignore-errors
            (semanticdb-file-table-object file))))))

(defun semantic-python-rescan-includes ()
  (interactive)
  (dolist (includes (semantic-python-get-system-include-path))
    (message "Parsing %s" includes)
    (semanticdb-rescan-directory includes)))

Try running the command "bovinate". 尝试运行命令“bovinate”。 This can be done with the key combination Meta + X and then typing "bovinate", and hitting the "Enter" key. 这可以使用组合键Meta + X完成,然后键入“bovinate”,然后按“Enter”键。 The "Meta" key is referred to as the "Alt" key in windows. “Meta”键在windows中称为“Alt”键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何加载cedet,语义等。 仅在打开.cxx,.h .cpp文件时 - How to load cedet, semantic et. al only when .cxx,.h .cpp files are open Emacs,Cedet和语义 - Emacs, Cedet and semantic 解析Linux内核文件“ jiffies.h”时,cedet-semantic错误“空闲服务错误semantic-idle-summary-idle-function-算术错误” - cedet-semantic error “Idle Service Error semantic-idle-summary-idle-function - Arithmetic error” when parsing linux kernel file “jiffies.h” Emacs CEDET关键字this的语义没有自动完成。 (C ++) - Emacs CEDET Semantic no autocomplete for `this` keyword. (C++) 如何在SCons中使用Emacs和CEDET? - How to use Emacs and CEDET with SCons? 使用libclang解析源文件-链接包含文件的问题 - Parsing source file with libclang - problems with linking include files 如何强制clang使用system(ubuntu)STL标头而不是clang的语义检查语义 - How to force clang to check semantic with system(ubuntu) STL header instead of clang's 如何将源文件传递给 gdbserver - How to pass source files to gdbserver 提升语义操作导致解析问题 - Boost Semantic Actions causing parsing issues 语义操作(使用 _val 和 _attr)如何通过 %= 和 x3::rule 的 force_attribute=true 影响规则定义? - How do semantic actions (using _val and _attr) influence rule definition with %= and x3::rule's force_attribute=true?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM