语义,放弃如何强制解析源文件
Semantic, cedet how to force parsing of source files
我一直在我的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
中之外,还有其他方法可以强制解析目录下的全部源文件吗?
谢谢!
在长期忽视这个问题后,我认为我应该花一些时间阅读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
,递归地扫描该buferr访问文件名目录中所有与c/c++相关的文件。
调用函数的另一种可能也是更可取的方法是交互调用lk-parse-dir-c
,这反过来会提示您要解析的目录。
如果任何一位elisp大师有更好的解决方案或建议来改进代码,我很乐意听取他们的意见。
我最近为Python实现了这一点。它可以用于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)))
尝试运行命令"bovate"。这可以通过组合键Meta+X来完成,然后键入"bovate",然后按"Enter"键。在窗口中,"Meta"键被称为"Alt"键。
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 强制转换为引用类型
- 强制调用WM_PAINT
- 如何修复函数样式强制转换或类型构造的预期"("?
- 存储模板类型以强制转换回派生<T>
- Python中的for循环与C++有何不同
- 为测试目标创建具有不同源文件夹的文件
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 函数作为模板参数,是否对返回类型强制约束
- 从成员指针到整个结构/类的强制转换
- 将图像添加到资源文件夹UWP C++
- 为什么g++在未执行的代码处标记强制转换错误
- 为什么在逗号分隔符上下文中将预增量的结果强制转换为void
- 将父类对象强制转换为子类的问题
- 视觉工作室项目.提取源文件夹名称
- enable_if转换构造函数(静态强制转换,is_base_of)
- 生成一个生成文件,该生成文件使用Automake在一个步骤中编译和链接所有源文件
- 语义,放弃如何强制解析源文件