簡體   English   中英

語義,cedet如何強制解析源文件

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

我在我的emacs c / c ++開發設置中一直在嘗試使用cedet和semantic,除了一個小細節之外我對它非常滿意。

我使用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") Mx lk-parse-curdir-c (my-semantic-parse-dir "path/to/dir/root/" ".*regex")或者從緩沖區按Mx lk-parse-curdir-c遞歸從該buferr的訪問文件名目錄中掃描所有與c / c ++相關的文件。

調用函數的另一種可能的優選方法是通過交互方式調用lk-parse-dir-c ,這反過來會提示您解析一個目錄。

如果任何elisp guru有更好的解決方案或改進代碼的建議,我很樂意聽到它們。

我最近為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)))

嘗試運行命令“bovinate”。 這可以使用組合鍵Meta + X完成,然后鍵入“bovinate”,然后按“Enter”鍵。 “Meta”鍵在windows中稱為“Alt”鍵。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM