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

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

问题描述

我一直在尝试CEDET,在我的emacs的C / C ++开发设置的语义和我相当满意了,除了一个小细节。

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.

我用义德-CPP-根项目来创建一个项目,给我的项目的根目录中,其中包括文件​​的目录一起居住象下面这样:

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"
                               )

                )

这可以让我轻松地跳到函数的声明与语义-IA-快跳但它不会让我的这些功能​​的定义。因此,它似乎只能是处理头文件和完全忽略源文件。即使我去上的功能和触发语义分析,原IMPL拨动的声明它会告诉我,没有合适的实现可以找到。

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.

所以我的问题是,缺乏手动打开包含我的项目的根目录下的所有源文件或手动它们纳入义德-CPP-根项目通过:SPP-文件的说法是有任何其他方式来强制目录下的所有源文件的解析

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的,并尝试找出一个变通后。它不是prettiest elisp的code有,因为我用的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)

要使用它可以直接调用该函数像这样:(我的语义,语法分析目录路径/要/ DIR /根/*正则表达式)或preSS 的Mx LK-解析-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.

另一种也许preferrable方式调用的函数是通过调用 LK-解析-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的大师有一个更好的解决方案或建议,以提高code我很想听到他们的声音。

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

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

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