diff options
| author | Chong Yidong | 2009-09-20 15:06:05 +0000 |
|---|---|---|
| committer | Chong Yidong | 2009-09-20 15:06:05 +0000 |
| commit | acc332318e2c8687a8892b6e2da13e4a49ad9128 (patch) | |
| tree | cbae36249128723cd5e311570623fd1b0aa40d31 /lisp/cedet/ede/cpp-root.el | |
| parent | 48bcb95a906dbbc27a1cd4db3cbde111346cbd87 (diff) | |
| download | emacs-acc332318e2c8687a8892b6e2da13e4a49ad9128.tar.gz emacs-acc332318e2c8687a8892b6e2da13e4a49ad9128.zip | |
* cedet/ede.el, cedet/ede/*.el: New files.
* cedet/cedet.el: Require ede.
* cedet/semantic/symref/filter.el (semantic-symref-hits-in-region):
Require semantic/idle.
Diffstat (limited to 'lisp/cedet/ede/cpp-root.el')
| -rw-r--r-- | lisp/cedet/ede/cpp-root.el | 515 |
1 files changed, 515 insertions, 0 deletions
diff --git a/lisp/cedet/ede/cpp-root.el b/lisp/cedet/ede/cpp-root.el new file mode 100644 index 00000000000..02f86d2c856 --- /dev/null +++ b/lisp/cedet/ede/cpp-root.el | |||
| @@ -0,0 +1,515 @@ | |||
| 1 | ;;; ede/cpp-root.el --- A simple way to wrap a C++ project with a single root | ||
| 2 | |||
| 3 | ;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Eric M. Ludlam <eric@siege-engine.com> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | ;; | ||
| 24 | ;; NOTE: ede-cpp-root.el has been commented so as to also make it | ||
| 25 | ;; useful for learning how to make similar project types. | ||
| 26 | ;; | ||
| 27 | ;; Not everyone can use automake, or an EDE project type. For | ||
| 28 | ;; pre-existing code, it is often helpful jut to be able to wrap the | ||
| 29 | ;; whole thing up in as simple a way as possible. | ||
| 30 | ;; | ||
| 31 | ;; The cpp-root project type will allow you to create a single object | ||
| 32 | ;; with no save-file in your .emacs file that will be recognized, and | ||
| 33 | ;; provide a way to easilly allow EDE to provide Semantic with the | ||
| 34 | ;; ability to find header files, and other various source files | ||
| 35 | ;; quickly. | ||
| 36 | ;; | ||
| 37 | ;; The cpp-root class knows a few things about C++ projects, such as | ||
| 38 | ;; the prevalence of "include" directories, and typical file-layout | ||
| 39 | ;; stuff. If this isn't sufficient, you can subclass | ||
| 40 | ;; `ede-cpp-root-project' and add your own tweaks in just a few lines. | ||
| 41 | ;; See the end of this file for an example. | ||
| 42 | ;; | ||
| 43 | ;;; EXAMPLE | ||
| 44 | ;; | ||
| 45 | ;; Add this to your .emacs file, modifying apropriate bits as needed. | ||
| 46 | ;; | ||
| 47 | ;; (ede-cpp-root-project "SOMENAME" :file "/dir/to/some/file") | ||
| 48 | ;; | ||
| 49 | ;; Replace SOMENAME with whatever name you want, and the filename to | ||
| 50 | ;; an actual file at the root of your project. It might be a | ||
| 51 | ;; Makefile, a README file. Whatever. It doesn't matter. It's just | ||
| 52 | ;; a key to hang the rest of EDE off of. | ||
| 53 | ;; | ||
| 54 | ;; The most likely reason to create this project, is to help make | ||
| 55 | ;; finding files within the project faster. In conjunction with | ||
| 56 | ;; Semantic completion, having a short include path is key. You can | ||
| 57 | ;; override the include path like this: | ||
| 58 | ;; | ||
| 59 | ;; (ede-cpp-root-project "NAME" :file "FILENAME" | ||
| 60 | ;; :include-path '( "/include" "../include" "/c/include" ) | ||
| 61 | ;; :system-include-path '( "/usr/include/c++/3.2.2/" ) | ||
| 62 | ;; :spp-table '( ("MOOSE" . "") | ||
| 63 | ;; ("CONST" . "const") ) | ||
| 64 | ;; :spp-files '( "include/config.h" ) | ||
| 65 | ;; ) | ||
| 66 | ;; | ||
| 67 | ;; In this case each item in the include path list is searched. If | ||
| 68 | ;; the directory starts with "/", then that expands to the project | ||
| 69 | ;; root directory. If a directory does not start with "/", then it | ||
| 70 | ;; is relative to the default-directory of the current buffer when | ||
| 71 | ;; the file name is expanded. | ||
| 72 | ;; | ||
| 73 | ;; The include path only affects C/C++ header files. Use the slot | ||
| 74 | ;; :header-match-regexp to change it. | ||
| 75 | ;; | ||
| 76 | ;; The :system-include-path allows you to specify full directory | ||
| 77 | ;; names to include directories where system header files can be | ||
| 78 | ;; found. These will be applied to files in this project only. | ||
| 79 | ;; | ||
| 80 | ;; The :spp-table provides a list of project specific #define style | ||
| 81 | ;; macros that are unique to this project, passed in to the compiler | ||
| 82 | ;; on the command line, or are in special headers. | ||
| 83 | ;; | ||
| 84 | ;; The :spp-files option is like :spp-table, except you can provide a | ||
| 85 | ;; file name for a header in your project where most of your CPP | ||
| 86 | ;; macros reside. Doing this can be easier than listing everything in | ||
| 87 | ;; the :spp-table option. The files listed in :spp-files should not | ||
| 88 | ;; start with a /, and are relative to something in :include-path.;; | ||
| 89 | ;; | ||
| 90 | ;; If you want to override the file-finding tool with your own | ||
| 91 | ;; function you can do this: | ||
| 92 | ;; | ||
| 93 | ;; (ede-cpp-root-project "NAME" :file "FILENAME" :locate-fcn 'MYFCN) | ||
| 94 | ;; | ||
| 95 | ;; Where FILENAME is a file in the root directory of the project. | ||
| 96 | ;; Where MYFCN is a symbol for a function. See: | ||
| 97 | ;; | ||
| 98 | ;; M-x describe-class RET ede-cpp-root-project RET | ||
| 99 | ;; | ||
| 100 | ;; for documentation about the locate-fcn extension. | ||
| 101 | ;; | ||
| 102 | ;;; ADVANCED EXAMPLE | ||
| 103 | ;; | ||
| 104 | ;; If the cpp-root project style is right for you, but you want a | ||
| 105 | ;; dynamic loader, instead of hard-coding values in your .emacs, you | ||
| 106 | ;; can do that too, but you will need to write some lisp code. | ||
| 107 | ;; | ||
| 108 | ;; To do that, you need to add an entry to the | ||
| 109 | ;; `ede-project-class-files' list, and also provide two functions to | ||
| 110 | ;; teach EDE how to load your project pattern | ||
| 111 | ;; | ||
| 112 | ;; It would oook like this: | ||
| 113 | ;; | ||
| 114 | ;; (defun MY-FILE-FOR-DIR (&optional dir) | ||
| 115 | ;; "Return a full file name to the project file stored in DIR." | ||
| 116 | ;; <write your code here, or return nil> | ||
| 117 | ;; ) | ||
| 118 | ;; | ||
| 119 | ;; (defun MY-ROOT-FCN () | ||
| 120 | ;; "Return the root directory for `default-directory'" | ||
| 121 | ;; ;; You might be able to use `ede-cpp-root-project-root'. | ||
| 122 | ;; ) | ||
| 123 | ;; | ||
| 124 | ;; (defun MY-LOAD (dir) | ||
| 125 | ;; "Load a project of type `cpp-root' for the directory DIR. | ||
| 126 | ;; Return nil if there isn't one." | ||
| 127 | ;; (ede-cpp-root-project "NAME" :file (expand-file-name "FILE" dir) | ||
| 128 | ;; :locate-fcn 'MYFCN) | ||
| 129 | ;; ) | ||
| 130 | ;; | ||
| 131 | ;; (add-to-list 'ede-project-class-files | ||
| 132 | ;; (ede-project-autoload "cpp-root" | ||
| 133 | ;; :name "CPP ROOT" | ||
| 134 | ;; :file 'ede-cpp-root | ||
| 135 | ;; :proj-file 'MY-FILE-FOR-DIR | ||
| 136 | ;; :proj-root 'MY-ROOT-FCN | ||
| 137 | ;; :load-type 'MY-LOAD | ||
| 138 | ;; :class-sym 'ede-cpp-root) | ||
| 139 | ;; t) | ||
| 140 | ;; | ||
| 141 | ;;; TODO | ||
| 142 | ;; | ||
| 143 | ;; Need a way to reconfigure a project, and have it affect all open buffers. | ||
| 144 | ;; From Tobias Gerdin: | ||
| 145 | ;; | ||
| 146 | ;; >>3) Is there any way to refresh a ede-cpp-root-project dynamically? I have | ||
| 147 | ;; >>some file open part of the project, fiddle with the include paths and would | ||
| 148 | ;; >>like the open buffer to notice this when I re-evaluate the | ||
| 149 | ;; >>ede-cpp-root-project constructor. | ||
| 150 | ;; > | ||
| 151 | ;; > Another good idea. The easy way is to "revert-buffer" as needed. The | ||
| 152 | ;; > ede "project local variables" does this already, so it should be easy | ||
| 153 | ;; > to adapt something. | ||
| 154 | ;; | ||
| 155 | ;; I actually tried reverting the buffer but Semantic did not seem to pick | ||
| 156 | ;; up the differences (the "include summary" reported the same include paths). | ||
| 157 | |||
| 158 | (require 'ede) | ||
| 159 | |||
| 160 | (defvar semantic-lex-spp-project-macro-symbol-obarray) | ||
| 161 | (declare-function semantic-lex-make-spp-table "semantic/lex-spp") | ||
| 162 | (declare-function semanticdb-file-table-object "semantic/db") | ||
| 163 | (declare-function semanticdb-needs-refresh-p "semantic/db") | ||
| 164 | (declare-function semanticdb-refresh-table "semantic/db") | ||
| 165 | |||
| 166 | ;;; Code: | ||
| 167 | |||
| 168 | ;;; PROJECT CACHE: | ||
| 169 | ;; | ||
| 170 | ;; cpp-root projects are created in a .emacs or other config file, but | ||
| 171 | ;; there still needs to be a way for a particular file to be | ||
| 172 | ;; identified against it. The cache is where we look to map a file | ||
| 173 | ;; against a project. | ||
| 174 | ;; | ||
| 175 | ;; Setting up a simple in-memory cache of active projects allows the | ||
| 176 | ;; user to re-load their configuration file several times without | ||
| 177 | ;; messing up the active project set. | ||
| 178 | ;; | ||
| 179 | (defvar ede-cpp-root-project-list nil | ||
| 180 | "List of projects created by option `ede-cpp-root-project'.") | ||
| 181 | |||
| 182 | (defun ede-cpp-root-file-existing (dir) | ||
| 183 | "Find a cpp-root project in the list of cpp-root projects. | ||
| 184 | DIR is the directory to search from." | ||
| 185 | (let ((projs ede-cpp-root-project-list) | ||
| 186 | (ans nil)) | ||
| 187 | (while (and projs (not ans)) | ||
| 188 | (let ((root (ede-project-root-directory (car projs)))) | ||
| 189 | (when (string-match (concat "^" (regexp-quote root)) dir) | ||
| 190 | (setq ans (car projs)))) | ||
| 191 | (setq projs (cdr projs))) | ||
| 192 | ans)) | ||
| 193 | |||
| 194 | ;;; PROJECT AUTOLOAD CONFIG | ||
| 195 | ;; | ||
| 196 | ;; Each project type registers itself into the project-class list. | ||
| 197 | ;; This way, each time a file is loaded, EDE can map that file to a | ||
| 198 | ;; project. This project type checks files against the internal cache | ||
| 199 | ;; of projects created by the user. | ||
| 200 | ;; | ||
| 201 | ;; EDE asks two kinds of questions. One is, does this DIR belong to a | ||
| 202 | ;; project. If it does, it then asks, what is the ROOT directory to | ||
| 203 | ;; the project in DIR. This is easy for cpp-root projects, but more | ||
| 204 | ;; complex for multiply nested projects. | ||
| 205 | ;; | ||
| 206 | ;; If EDE finds out that a project exists for DIR, it then loads that | ||
| 207 | ;; project. The LOAD routine can either create a new project object | ||
| 208 | ;; (if it needs to load it off disk) or more likely can return an | ||
| 209 | ;; existing object for the discovered directory. cpp-root always uses | ||
| 210 | ;; the second case. | ||
| 211 | |||
| 212 | (defun ede-cpp-root-project-file-for-dir (&optional dir) | ||
| 213 | "Return a full file name to the project file stored in DIR." | ||
| 214 | (let ((proj (ede-cpp-root-file-existing dir))) | ||
| 215 | (when proj (oref proj :file)))) | ||
| 216 | |||
| 217 | (defvar ede-cpp-root-count 0 | ||
| 218 | "Count number of hits to the cpp root thing. | ||
| 219 | This is a debugging variable to test various optimizations in file | ||
| 220 | lookup in the main EDE logic.") | ||
| 221 | |||
| 222 | ;;;###autoload | ||
| 223 | (defun ede-cpp-root-project-root (&optional dir) | ||
| 224 | "Get the root directory for DIR." | ||
| 225 | (let ((projfile (ede-cpp-root-project-file-for-dir | ||
| 226 | (or dir default-directory)))) | ||
| 227 | (setq ede-cpp-root-count (1+ ede-cpp-root-count)) | ||
| 228 | ;(debug) | ||
| 229 | (when projfile | ||
| 230 | (file-name-directory projfile)))) | ||
| 231 | |||
| 232 | (defun ede-cpp-root-load (dir &optional rootproj) | ||
| 233 | "Return a CPP root object if you created one. | ||
| 234 | Return nil if there isn't one. | ||
| 235 | Argument DIR is the directory it is created for. | ||
| 236 | ROOTPROJ is nil, since there is only one project." | ||
| 237 | ;; Snoop through our master list. | ||
| 238 | (ede-cpp-root-file-existing dir)) | ||
| 239 | |||
| 240 | ;;; CLASSES | ||
| 241 | ;; | ||
| 242 | ;; EDE sets up projects with two kinds of objects. | ||
| 243 | ;; | ||
| 244 | ;; The PROJECT is a class that represents everything under a directory | ||
| 245 | ;; hierarchy. A TARGET represents a subset of files within a project. | ||
| 246 | ;; A project can have multiple targets, and multiple sub-projects. | ||
| 247 | ;; Sub projects should map to sub-directories. | ||
| 248 | ;; | ||
| 249 | ;; The CPP-ROOT project maps any file in C or C++ mode to a target for | ||
| 250 | ;; C files. | ||
| 251 | ;; | ||
| 252 | ;; When creating a custom project the project developer an opportunity | ||
| 253 | ;; to run code to setup various tools whenever an associated buffer is | ||
| 254 | ;; loaded. The CPP-ROOT project spends most of its time setting up C | ||
| 255 | ;; level include paths, and PreProcessor macro tables. | ||
| 256 | |||
| 257 | (defclass ede-cpp-root-target (ede-target) | ||
| 258 | () | ||
| 259 | "EDE cpp-root project target. | ||
| 260 | All directories need at least one target.") | ||
| 261 | |||
| 262 | (defclass ede-cpp-root-project (ede-project eieio-instance-tracker) | ||
| 263 | ((tracking-symbol :initform 'ede-cpp-root-project-list) | ||
| 264 | (include-path :initarg :include-path | ||
| 265 | :initform '( "/include" "../include/" ) | ||
| 266 | :type list | ||
| 267 | :documentation | ||
| 268 | "The default locate function expands filenames within a project. | ||
| 269 | If a header file (.h, .hh, etc) name is expanded, and | ||
| 270 | the :locate-fcn slot is nil, then the include path is checked | ||
| 271 | first, and other directories are ignored. For very large | ||
| 272 | projects, this optimization can save a lot of time. | ||
| 273 | |||
| 274 | Directory names in the path can be relative to the current | ||
| 275 | buffer's `default-directory' (not starting with a /). Directories | ||
| 276 | that are relative to the project's root should start with a /, such | ||
| 277 | as \"/include\", meaning the directory `include' off the project root | ||
| 278 | directory.") | ||
| 279 | (system-include-path :initarg :system-include-path | ||
| 280 | :initform nil | ||
| 281 | :type list | ||
| 282 | :documentation | ||
| 283 | "The system include path for files in this project. | ||
| 284 | C files initialized in an ede-cpp-root-project have their semantic | ||
| 285 | system include path set to this value. If this is nil, then the | ||
| 286 | semantic path is not modified.") | ||
| 287 | (spp-table :initarg :spp-table | ||
| 288 | :initform nil | ||
| 289 | :type list | ||
| 290 | :documentation | ||
| 291 | "C Preprocessor macros for your files. | ||
| 292 | Preprocessor symbols will be used while parsing your files. | ||
| 293 | These macros might be passed in through the command line compiler, or | ||
| 294 | are critical symbols derived from header files. Providing header files | ||
| 295 | macro values through this slot improves accuracy and performance. | ||
| 296 | Use `:spp-files' to use these files directly.") | ||
| 297 | (spp-files :initarg :spp-files | ||
| 298 | :initform nil | ||
| 299 | :type list | ||
| 300 | :documentation | ||
| 301 | "C header file with Preprocessor macros for your files. | ||
| 302 | The PreProcessor symbols appearing in these files will be used while | ||
| 303 | parsing files in this project. | ||
| 304 | See `semantic-lex-c-preprocessor-symbol-map' for more on how this works.") | ||
| 305 | (header-match-regexp :initarg :header-match-regexp | ||
| 306 | :initform | ||
| 307 | "\\.\\(h\\(h\\|xx\\|pp\\|\\+\\+\\)?\\|H\\)$\\|\\<\\w+$" | ||
| 308 | :type string | ||
| 309 | :documentation | ||
| 310 | "Regexp used to identify C/C++ header files.") | ||
| 311 | (locate-fcn :initarg :locate-fcn | ||
| 312 | :initform nil | ||
| 313 | :type (or null function) | ||
| 314 | :documentation | ||
| 315 | "The locate function can be used in place of | ||
| 316 | `ede-expand-filename' so you can quickly customize your custom target | ||
| 317 | to use specialized local routines instead of the EDE routines. | ||
| 318 | The function symbol must take two arguments: | ||
| 319 | NAME - The name of the file to find. | ||
| 320 | DIR - The directory root for this cpp-root project. | ||
| 321 | |||
| 322 | It should return the fully qualified file name passed in from NAME. If that file does not | ||
| 323 | exist, it should return nil." | ||
| 324 | ) | ||
| 325 | ) | ||
| 326 | "EDE cpp-root project class. | ||
| 327 | Each directory needs a a project file to control it.") | ||
| 328 | |||
| 329 | ;;; INIT | ||
| 330 | ;; | ||
| 331 | ;; Most projects use `initialize-instance' to do special setup | ||
| 332 | ;; on the object when it is created. In this case, EDE-CPP-ROOT can | ||
| 333 | ;; find previous copies of this project, and make sure that one of the | ||
| 334 | ;; objects is deleted. | ||
| 335 | |||
| 336 | (defmethod initialize-instance ((this ede-cpp-root-project) | ||
| 337 | &rest fields) | ||
| 338 | "Make sure the :file is fully expanded." | ||
| 339 | ;; Add ourselves to the master list | ||
| 340 | (call-next-method) | ||
| 341 | (let ((f (expand-file-name (oref this :file)))) | ||
| 342 | ;; Remove any previous entries from the main list. | ||
| 343 | (let ((old (eieio-instance-tracker-find (file-name-directory f) | ||
| 344 | :directory 'ede-cpp-root-project-list))) | ||
| 345 | ;; This is safe, because :directory isn't filled in till later. | ||
| 346 | (when (and old (not (eq old this))) | ||
| 347 | (delete-instance old))) | ||
| 348 | ;; Basic initialization. | ||
| 349 | (when (or (not (file-exists-p f)) | ||
| 350 | (file-directory-p f)) | ||
| 351 | (delete-instance this) | ||
| 352 | (error ":file for ede-cpp-root must be a file.")) | ||
| 353 | (oset this :file f) | ||
| 354 | (oset this :directory (file-name-directory f)) | ||
| 355 | (ede-project-directory-remove-hash (file-name-directory f)) | ||
| 356 | (ede-add-project-to-global-list this) | ||
| 357 | (unless (slot-boundp this 'targets) | ||
| 358 | (oset this :targets nil)) | ||
| 359 | ;; We need to add ourselves to the master list. | ||
| 360 | ;;(setq ede-projects (cons this ede-projects)) | ||
| 361 | )) | ||
| 362 | |||
| 363 | ;;; SUBPROJ Management. | ||
| 364 | ;; | ||
| 365 | ;; This is a way to allow a subdirectory to point back to the root | ||
| 366 | ;; project, simplifying authoring new single-point projects. | ||
| 367 | |||
| 368 | (defmethod ede-find-subproject-for-directory ((proj ede-cpp-root-project) | ||
| 369 | dir) | ||
| 370 | "Return PROJ, for handling all subdirs below DIR." | ||
| 371 | proj) | ||
| 372 | |||
| 373 | ;;; TARGET MANAGEMENT | ||
| 374 | ;; | ||
| 375 | ;; Creating new targets on a per directory basis is a good way to keep | ||
| 376 | ;; files organized. See ede-emacs for an example with multiple file | ||
| 377 | ;; types. | ||
| 378 | (defmethod ede-find-target ((proj ede-cpp-root-project) buffer) | ||
| 379 | "Find an EDE target in PROJ for BUFFER. | ||
| 380 | If one doesn't exist, create a new one for this directory." | ||
| 381 | (let* ((targets (oref proj targets)) | ||
| 382 | (dir default-directory) | ||
| 383 | (ans (object-assoc dir :path targets)) | ||
| 384 | ) | ||
| 385 | (when (not ans) | ||
| 386 | (setq ans (ede-cpp-root-target dir | ||
| 387 | :name (file-name-nondirectory | ||
| 388 | (directory-file-name dir)) | ||
| 389 | :path dir | ||
| 390 | :source nil)) | ||
| 391 | (object-add-to-list proj :targets ans) | ||
| 392 | ) | ||
| 393 | ans)) | ||
| 394 | |||
| 395 | ;;; FILE NAMES | ||
| 396 | ;; | ||
| 397 | ;; One of the more important jobs of EDE is to find files in a | ||
| 398 | ;; directory structure. cpp-root has tricks it knows about how most C | ||
| 399 | ;; projects are set up with include paths. | ||
| 400 | ;; | ||
| 401 | ;; This tools also uses the ede-locate setup for augmented file name | ||
| 402 | ;; lookup using external tools. | ||
| 403 | (defmethod ede-expand-filename-impl ((proj ede-cpp-root-project) name) | ||
| 404 | "Within this project PROJ, find the file NAME. | ||
| 405 | This knows details about or source tree." | ||
| 406 | ;; The slow part of the original is looping over subprojects. | ||
| 407 | ;; This version has no subprojects, so this will handle some | ||
| 408 | ;; basic cases. | ||
| 409 | (let ((ans (call-next-method))) | ||
| 410 | (unless ans | ||
| 411 | (let* ((lf (oref proj locate-fcn)) | ||
| 412 | (dir (file-name-directory (oref proj file)))) | ||
| 413 | (if lf | ||
| 414 | (setq ans (funcall lf name dir)) | ||
| 415 | (if (ede-cpp-root-header-file-p proj name) | ||
| 416 | ;; Else, use our little hack. | ||
| 417 | (let ((ip (oref proj include-path)) | ||
| 418 | (tmp nil)) | ||
| 419 | (while ip | ||
| 420 | ;; Translate | ||
| 421 | (setq tmp (ede-cpp-root-translate-file proj (car ip))) | ||
| 422 | ;; Test this name. | ||
| 423 | (setq tmp (expand-file-name name tmp)) | ||
| 424 | (if (file-exists-p tmp) | ||
| 425 | (setq ans tmp)) | ||
| 426 | (setq ip (cdr ip)) )) | ||
| 427 | ;; Else, do the usual. | ||
| 428 | (setq ans (call-next-method))) | ||
| 429 | ))) | ||
| 430 | (or ans (call-next-method)))) | ||
| 431 | |||
| 432 | (defmethod ede-project-root ((this ede-cpp-root-project)) | ||
| 433 | "Return my root." | ||
| 434 | this) | ||
| 435 | |||
| 436 | (defmethod ede-project-root-directory ((this ede-cpp-root-project)) | ||
| 437 | "Return my root." | ||
| 438 | (file-name-directory (oref this file))) | ||
| 439 | |||
| 440 | ;;; C/CPP SPECIFIC CODE | ||
| 441 | ;; | ||
| 442 | ;; The following code is specific to setting up header files, | ||
| 443 | ;; include lists, and Preprocessor symbol tables. | ||
| 444 | |||
| 445 | (defmethod ede-cpp-root-header-file-p ((proj ede-cpp-root-project) name) | ||
| 446 | "Non nil if in PROJ the filename NAME is a header." | ||
| 447 | (save-match-data | ||
| 448 | (string-match (oref proj header-match-regexp) name))) | ||
| 449 | |||
| 450 | (defmethod ede-cpp-root-translate-file ((proj ede-cpp-root-project) filename) | ||
| 451 | "For PROJ, translate a user specified FILENAME. | ||
| 452 | This is for project include paths and spp source files." | ||
| 453 | ;; Step one: Root of this project. | ||
| 454 | (let ((dir (file-name-directory (oref proj file)))) | ||
| 455 | |||
| 456 | ;; Step two: Analyze first char, and rehost | ||
| 457 | (if (and (not (string= filename "")) (= (aref filename 0) ?/)) | ||
| 458 | ;; Check relative to root of project | ||
| 459 | (setq filename (expand-file-name (substring filename 1) | ||
| 460 | dir)) | ||
| 461 | ;; Relative to current directory. | ||
| 462 | (setq filename (expand-file-name filename))) | ||
| 463 | |||
| 464 | filename)) | ||
| 465 | |||
| 466 | (defmethod ede-set-project-variables ((project ede-cpp-root-project) &optional buffer) | ||
| 467 | "Set variables local to PROJECT in BUFFER. | ||
| 468 | Also set up the lexical preprocessor map." | ||
| 469 | (call-next-method) | ||
| 470 | (when (and (featurep 'semantic-c) (featurep 'semantic-lex-spp)) | ||
| 471 | (setq semantic-lex-spp-project-macro-symbol-obarray | ||
| 472 | (semantic-lex-make-spp-table (oref project spp-table))) | ||
| 473 | )) | ||
| 474 | |||
| 475 | (defmethod ede-system-include-path ((this ede-cpp-root-project)) | ||
| 476 | "Get the system include path used by project THIS." | ||
| 477 | (oref this system-include-path)) | ||
| 478 | |||
| 479 | (defmethod ede-preprocessor-map ((this ede-cpp-root-project)) | ||
| 480 | "Get the pre-processor map for project THIS." | ||
| 481 | (require 'semantic/db) | ||
| 482 | (let ((spp (oref this spp-table)) | ||
| 483 | (root (ede-project-root this)) | ||
| 484 | ) | ||
| 485 | (mapc | ||
| 486 | (lambda (F) | ||
| 487 | (let* ((expfile (ede-expand-filename root F)) | ||
| 488 | (table (when expfile | ||
| 489 | (semanticdb-file-table-object expfile))) | ||
| 490 | ) | ||
| 491 | (when (not table) | ||
| 492 | (message "Cannot find file %s in project." F)) | ||
| 493 | (when (and table (semanticdb-needs-refresh-p table)) | ||
| 494 | (semanticdb-refresh-table table)) | ||
| 495 | (setq spp (append spp (oref table lexical-table))))) | ||
| 496 | (oref this spp-files)) | ||
| 497 | spp)) | ||
| 498 | |||
| 499 | (defmethod ede-system-include-path ((this ede-cpp-root-target)) | ||
| 500 | "Get the system include path used by project THIS." | ||
| 501 | (ede-system-include-path (ede-target-parent this))) | ||
| 502 | |||
| 503 | (defmethod ede-preprocessor-map ((this ede-cpp-root-target)) | ||
| 504 | "Get the pre-processor map for project THIS." | ||
| 505 | (ede-preprocessor-map (ede-target-parent this))) | ||
| 506 | |||
| 507 | (provide 'ede/cpp-root) | ||
| 508 | |||
| 509 | ;; Local variables: | ||
| 510 | ;; generated-autoload-file: "loaddefs.el" | ||
| 511 | ;; generated-autoload-feature: ede/loaddefs | ||
| 512 | ;; generated-autoload-load-name: "ede/cpp-root" | ||
| 513 | ;; End: | ||
| 514 | |||
| 515 | ;;; ede/cpp-root.el ends here | ||