0
|
1 ;;!emacs
|
|
2 ;;
|
|
3 ;; FILE: br-c++-ft.el
|
|
4 ;; SUMMARY: C++ OO-Browser class and member functions.
|
|
5 ;; USAGE: GNU Emacs Lisp Library
|
|
6 ;; KEYWORDS: c, oop, tools
|
|
7 ;;
|
|
8 ;; AUTHOR: Bob Weiner
|
100
|
9 ;; ORG: InfoDock Associates
|
0
|
10 ;;
|
|
11 ;; ORIG-DATE: 03-Oct-90
|
100
|
12 ;; LAST-MOD: 11-Nov-96 at 17:29:58 by Bob Weiner
|
0
|
13 ;;
|
100
|
14 ;; Copyright (C) 1990-1996 Free Software Foundation, Inc.
|
0
|
15 ;; See the file BR-COPY for license information.
|
|
16 ;;
|
|
17 ;; This file is part of the OO-Browser.
|
|
18 ;;
|
|
19 ;; DESCRIPTION:
|
|
20 ;; DESCRIP-END.
|
|
21
|
|
22 ;;; ************************************************************************
|
|
23 ;;; Other required Elisp libraries
|
|
24 ;;; ************************************************************************
|
|
25
|
|
26 (require 'br-c++)
|
|
27
|
|
28 ;;; ************************************************************************
|
|
29 ;;; Public variables
|
|
30 ;;; ************************************************************************
|
|
31
|
|
32 (defvar c++-cpp-include-dirs '("/usr/include/")
|
|
33 "*Ordered list of include directories by default searched by C preprocessor.
|
|
34 Each directory must end with a directory separator. See also
|
|
35 'c++-include-dirs'.")
|
|
36
|
|
37 (defvar c++-include-dirs nil
|
|
38 "*Ordered list of directories to search for C++ include files.
|
|
39 Each directory must end with a directory separator. Directories normally
|
|
40 searched by the C++ pre-processor should be set instead in
|
|
41 'c++-cpp-include-dirs'.")
|
|
42
|
|
43 ;; Modified on 3/28/95 to handle C++ names with multiple template
|
|
44 ;; parameters, e.g. class<T1,T2,T3>. Unfortunately for our pattern matcher,
|
|
45 ;; we also have to allow spaces within the template parameters section. We
|
|
46 ;; consciously do not allow newlines within the parameters section to avoid
|
|
47 ;; grabbing too much of the expression that follows.
|
|
48 (defconst c++-return-type-identifier
|
|
49 (concat "[\[<a-zA-Z]"
|
|
50 "[]" c++-template-identifier-chars "]*"
|
|
51 "\\(::[]" c++-template-identifier-chars "]+\\)?"
|
|
52 "[ \t\n\^M]*<[" c++-return-type-chars " ,]+>[ \t\n\^M]*[*&]*"
|
|
53 "\\|[\[<a-zA-Z][]" c++-return-type-chars "]*"
|
|
54 "\\(::[\[<a-zA-Z][]" c++-return-type-chars "]+\\)?"
|
|
55 "[ \t\n\^M]*[*&]*"))
|
|
56
|
|
57 (defconst c++-type-identifier
|
|
58 (concat "\\(::\\|[\[<a-zA-Z][]" c++-template-identifier-chars "]*"
|
|
59 "[ \t\n\^M]*<[^>;{}]+>[ \t\n\^M]*[*&]*::"
|
|
60 "\\|[\[<a-zA-Z][]" c++-identifier-chars "]*[ \t\n\^M]*[*&]*::\\)"))
|
|
61
|
|
62 (defconst c++-type-tag-separator "@"
|
|
63 "String that separates a tag's type from its normalized definition form.
|
|
64 This should be a single character which is unchanged when quoted for use as a
|
|
65 literal in a regular expression.")
|
|
66
|
|
67 (defconst c++-tag-fields-regexp
|
|
68 ;; The \\\\? below is necessary because we sometimes use this expression to
|
|
69 ;; test against a string that has ben regexp-quoted and some of the
|
|
70 ;; characters in br-feature-type-regexp will then be preceded by \\.
|
|
71 (format "\\`\\([^%s \n]+\\)%s\\\\?\\(%s \\)\\([^%s\n]+\\)%s"
|
|
72 c++-type-tag-separator c++-type-tag-separator br-feature-type-regexp
|
|
73 c++-type-tag-separator c++-type-tag-separator)
|
|
74 "Regexp matching the fields of a C++ feature tag line.
|
|
75 Group 1 is the class of the feature. Group 2 is the prefix preceding the
|
|
76 feature when displayed within a listing buffer. Group 3 is the feature name.
|
|
77 The feature definition signature begins at the end of the regexp match,
|
|
78 i.e. (match-end 0), and goes to the end of the string or line.")
|
|
79
|
|
80 ;;; ************************************************************************
|
|
81 ;;; Public functions
|
|
82 ;;; ************************************************************************
|
|
83
|
|
84 (defun c++-add-default-classes ()
|
|
85 ;; Add to 'system' class table.
|
|
86 (if br-c-tags-flag
|
|
87 (c-add-default-classes)
|
|
88 ;; Even if this flag is nil, the Environment still contains C function
|
|
89 ;; tag entries, so add this default class.
|
|
90 (br-add-class "[function]" br-null-path nil)))
|
|
91
|
|
92 (defun c++-member-p ()
|
|
93 "Prints whether entity at point is a C++ member definition or declaration."
|
|
94 (interactive)
|
|
95 (let ((name))
|
|
96 (save-excursion
|
|
97 (message
|
|
98 (concat
|
|
99 "Is " (if (c++-feature-def-p)
|
|
100 (progn (setq name
|
|
101 (buffer-substring (match-beginning
|
|
102 c++-feature-name-grpn)
|
|
103 (match-end
|
|
104 c++-feature-name-grpn)))
|
|
105 "")
|
|
106 "not ")
|
|
107 "a def. "
|
|
108 "Is " (if (and (c++-skip-to-statement) (c++-feature-decl))
|
|
109 (progn (setq name
|
|
110 (buffer-substring (match-beginning
|
|
111 c++-feature-name-grpn)
|
|
112 (match-end
|
|
113 c++-feature-name-grpn)))
|
|
114 "")
|
|
115 "not ")
|
|
116 "a member decl. "
|
|
117 (if name (concat " Name = " name)))))))
|
|
118
|
|
119 (defun c++-feature-implementors (name)
|
|
120 "Return unsorted list of C++ feature tags which implement feature NAME.
|
|
121 This includes classes which define the interface for NAME as a pure virtual
|
|
122 function."
|
|
123 (c++-feature-matches (concat "^" (regexp-quote name) "$")))
|
|
124
|
|
125 (defun c++-feature-locate-p (feature-tag &optional regexp-flag)
|
|
126 "Leaves point at the start of FEATURE-TAG's definition in the current buffer.
|
|
127 Assumes caller has moved point to the beginning of the buffer or to the point
|
|
128 of desired search start.
|
|
129 Optional REGEXP-FLAG means FEATURE-TAG is a regular expression."
|
|
130 ;; Match to function definitions, not declarations, except for pure virtual
|
|
131 ;; functions and friends which are declared, not defined, and so end with a
|
|
132 ;; ';'.
|
|
133 ;;
|
|
134 ;; First move to the proper class implementation if feature-tag does not
|
|
135 ;; include a <class>:: part and this is not a [default-class], so that if
|
|
136 ;; two classes in the same file have the same feature signature, we still
|
|
137 ;; end up at the right one.
|
|
138 (if (string-match c++-tag-fields-regexp feature-tag)
|
|
139 (let ((class (substring feature-tag (match-beginning 1) (match-end 1))))
|
|
140 (setq feature-tag (substring feature-tag (match-end 0)))
|
|
141 (if regexp-flag
|
|
142 (if (not (string-match "\\`\\\\\\[\\|::" feature-tag))
|
|
143 (re-search-forward (c++-class-definition-regexp class t)
|
|
144 nil t))
|
|
145 (if (not (string-match "\\`\\[\\|::" feature-tag))
|
|
146 (re-search-forward (c++-class-definition-regexp class)
|
|
147 nil t)))))
|
|
148 (let ((found) (start))
|
|
149 ;; Now look for feature expression.
|
|
150 (or regexp-flag (setq feature-tag
|
|
151 (c++-feature-signature-to-regexp feature-tag)))
|
|
152 (while (and (re-search-forward feature-tag nil t)
|
|
153 (setq start (match-beginning 0))
|
|
154 (not (setq found (not
|
|
155 (if (c-within-comment-p)
|
|
156 (progn (search-forward "*/" nil t)
|
|
157 t)))))))
|
|
158 (if found
|
|
159 (progn (goto-char start)
|
|
160 (skip-chars-forward " \t\n")
|
|
161 (c++-to-comments-begin)
|
|
162 (recenter 0)
|
|
163 (goto-char start)
|
|
164 t))))
|
|
165
|
100
|
166 (defun c++-feature-map-class-tags (function class)
|
|
167 "Apply FUNCTION to all feature tags from CLASS and return a list of the results.
|
|
168 Feature tags come from the file named by br-feature-tags-file."
|
|
169 (let ((obuf (current-buffer))
|
|
170 (class-tag (concat "\n" class c++-type-tag-separator))
|
|
171 (results))
|
|
172 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file))
|
|
173 (goto-char 1)
|
|
174 (while (search-forward class-tag nil t)
|
|
175 (setq results (cons (funcall function) results))
|
|
176 ;; Might have deleted current tag and would miss next tag unless point
|
|
177 ;; is moved backwards.
|
|
178 (backward-char))
|
|
179 (set-buffer obuf)
|
|
180 results))
|
|
181
|
0
|
182 (defun c++-feature-name-to-regexp (name)
|
|
183 "Converts routine NAME into a regular expression matching the routine's name tag."
|
|
184 (setq name (c++-feature-signature-to-regexp name))
|
|
185 (aset name (1- (length name)) ?\() ;; Match only to functions
|
|
186 name)
|
|
187
|
|
188 (defun c++-feature-signature-to-name (signature &optional with-class for-display)
|
|
189 "Extracts the feature name from SIGNATURE.
|
|
190 The feature's class name is dropped from signature unless optional WITH-CLASS
|
|
191 is non-nil. If optional FOR-DISPLAY is non-nil, a feature type character is
|
|
192 prepended to the name for display in a browser listing."
|
|
193 (let ((name))
|
|
194 (cond
|
|
195 ;; member
|
|
196 ((string-match c++-tag-fields-regexp signature)
|
|
197 (setq name (substring signature (match-beginning (if for-display 2 3))
|
|
198 (match-end 3)))
|
|
199 (if with-class
|
|
200 (setq name (concat
|
|
201 (substring signature (match-beginning 1) (match-end 1))
|
|
202 "::" name)))
|
|
203 ;; Remove any trailing whitespace.
|
|
204 (br-delete-space name))
|
|
205 ;;
|
|
206 ;; unknown
|
|
207 (t ;; Remove any trailing whitespace and add display prefix.
|
|
208 (setq name (br-delete-space signature))
|
|
209 (if for-display (c++-feature-add-prefix name "" signature) name)))))
|
|
210
|
|
211 (defun c++-feature-signature-to-regexp (signature)
|
|
212 "Given a C++ SIGNATURE, return regexp used to match to its definition."
|
|
213 (setq signature (regexp-quote signature))
|
|
214 (let ((prefix-info
|
|
215 (if (string-match c++-tag-fields-regexp signature)
|
|
216 (prog1 (substring signature (match-beginning 0) (match-end 0))
|
|
217 (setq signature (substring signature (match-end 0)))))))
|
|
218 (if (string-match "[^<>*& \t]+\\(<[^>]+>\\)::" signature)
|
|
219 ;; Method from a template class. Match to a method with the same
|
|
220 ;; number of template parameters, regardless of parameter names.
|
|
221 (let ((pre (substring signature 0 (match-beginning 1)))
|
|
222 (mid (substring signature (match-beginning 1) (match-end 1)))
|
|
223 (post (substring signature (match-end 1))))
|
|
224 (setq signature (concat pre (c++-template-args-regexp mid) post))))
|
|
225 (let ((pat) (i 0) (c) (len (length signature)))
|
|
226 (while (< i len)
|
|
227 (setq c (aref signature i)
|
|
228 pat (cond ((= c ? )
|
|
229 ;; Allow for possible single line comment
|
|
230 ;; following any whitespace, e.g. following
|
|
231 ;; each routine argument.
|
|
232 (concat pat "[ \t\n\^M]*\\(//.*\\)?"))
|
|
233 (t
|
|
234 (concat pat (char-to-string c))))
|
|
235 i (1+ i)))
|
|
236 (setq pat (concat prefix-info pat)))))
|
|
237
|
100
|
238 (defun c++-feature-tag-regexp (class feature-name)
|
|
239 "Return a regexp that matches to the feature tag entry for CLASS' FEATURE-NAME."
|
|
240 (concat "^" (regexp-quote class) c++-type-tag-separator
|
|
241 br-feature-type-regexp " "
|
|
242 (regexp-quote feature-name) c++-type-tag-separator))
|
|
243
|
0
|
244 (defun c++-feature-tree-command-p (class-or-signature)
|
|
245 "Display definition of CLASS-OR-SIGNATURE if a signature and return t, else return nil."
|
|
246 (if (c++-routine-p class-or-signature)
|
|
247 (progn
|
|
248 (if (br-in-browser) (br-to-view-window))
|
|
249 (br-feature-found-p (br-feature-file class-or-signature)
|
|
250 class-or-signature))))
|
|
251
|
|
252 (defun c++-list-features (class &optional indent)
|
100
|
253 "Return sorted list of C++ feature tags lexically defined in CLASS.
|
|
254 Optional INDENT if > 2 indicates that this is a listing of inherited
|
|
255 features, in which case, friend features, which are never inherited, are
|
|
256 omitted from the returned list."
|
0
|
257 (let ((obuf (current-buffer))
|
|
258 (features)
|
|
259 (class-tag (concat "\n" class c++-type-tag-separator))
|
|
260 feature)
|
|
261 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file))
|
|
262 (goto-char 1)
|
|
263 (if (or (null indent) (<= indent 2))
|
|
264 ;; Include all features.
|
|
265 (while (search-forward class-tag nil t)
|
|
266 (setq features (cons (br-feature-current) features)))
|
|
267 ;; Omit friend features which are not inherited since indent > 2.
|
|
268 (let ((friend-regexp (format "%s%% " c++-type-tag-separator)))
|
|
269 (while (search-forward class-tag nil t)
|
|
270 (setq feature (br-feature-current))
|
|
271 (or (string-match friend-regexp feature)
|
|
272 (setq features (cons feature features))))))
|
|
273 (set-buffer obuf)
|
100
|
274 ;; Use nreverse here so that stable sort ends up leaving same named
|
|
275 ;; features in the order they were defined in the source file.
|
0
|
276 (c++-sort-features (nreverse features))))
|
|
277
|
|
278 (defun c++-routine-p (str)
|
|
279 (string-match "([^\)]*)" str))
|
|
280
|
|
281 (defun c++-scan-features ()
|
|
282 "Return reverse ordered list of C++ routine definitions in current buffer.
|
|
283 Assume point is at beginning of widened buffer."
|
|
284 (save-excursion
|
|
285 (let ((routines) class name rout)
|
|
286 (while (re-search-forward c++-routine-def nil t)
|
|
287 (setq class ""
|
|
288 name (buffer-substring (match-beginning c++-feature-name-grpn)
|
|
289 (match-end c++-feature-name-grpn)))
|
|
290 ;;
|
|
291 ;; This code is very subtle but it does the right thing so don't
|
|
292 ;; change it unless you know exactly what you are doing.
|
|
293 (if (not (match-beginning c++-feature-scope-grpn))
|
|
294 ;; This is a non-class function since we did not find a ::
|
|
295 ;; scoping operator.
|
|
296 (setq class "[function]")
|
|
297 ;; Is a member function, but this may set class = "" since prior
|
|
298 ;; regexp grouping may have grabbed the type. Be careful to
|
|
299 ;; handle this.
|
|
300 (setq class (buffer-substring
|
|
301 (match-beginning c++-feature-scope-grpn)
|
|
302 (- (match-end c++-feature-scope-grpn) 2)))
|
|
303 (if (and (string-equal class "")
|
|
304 (match-beginning c++-feature-type-grpn))
|
|
305 (setq class (buffer-substring
|
|
306 (match-beginning c++-feature-type-grpn)
|
|
307 (match-end c++-feature-type-grpn)))))
|
|
308
|
|
309 (setq rout (buffer-substring (match-beginning 0) (match-end 0)))
|
|
310 (if (c-within-comment-p)
|
|
311 (search-forward "*/" nil t)
|
|
312 ;; Move point to precede feature opening brace or pure virtual
|
|
313 ;; function declaration semicolon.
|
|
314 (backward-char)
|
|
315 (if (= (following-char) ?\{)
|
|
316 (condition-case ()
|
|
317 ;; Move to end of feature but ignore any error if braces are
|
|
318 ;; unbalanced. Let the compiler tell the user about this.
|
|
319 (forward-sexp)
|
|
320 (error nil)))
|
|
321 ;; Ignore matches to class constructs.
|
|
322 (if (string-match c++-class-name-before rout)
|
|
323 nil
|
|
324 (setq rout (c++-feature-normalize rout class name)
|
|
325 routines (cons rout routines)))))
|
|
326 routines)))
|
|
327
|
|
328 (defun c++-sort-features (routine-list)
|
|
329 (sort routine-list 'c++-feature-lessp))
|
|
330
|
|
331 (defun c++-to-definition (&optional other-win)
|
|
332 "If point is within a declaration, try to move to its definition.
|
|
333 With OTHER-WIN non-nil, show it in another window."
|
|
334 (interactive)
|
|
335 (let ((opoint (point)))
|
|
336 (cond
|
|
337 ((c++-include-file other-win))
|
|
338 ((br-check-for-class (c++-class-decl-p) other-win))
|
|
339 ((c++-feature other-win))
|
|
340 ((and (goto-char opoint)
|
|
341 (br-check-for-class (c++-find-class-name) other-win)))
|
|
342 (t (beep)
|
|
343 (message
|
|
344 "(OO-Browser): Select a C++ declaration to move to its definition.")
|
|
345 nil))))
|
|
346
|
|
347 ;;; ************************************************************************
|
|
348 ;;; Private functions
|
|
349 ;;; ************************************************************************
|
|
350
|
|
351 (defun c++-class-decl-p ()
|
|
352 "Return nil unless point is within a class declaration, referenced by another
|
|
353 class. Commented declarations also return nil. When value is non-nil, it is
|
|
354 the class name from the declaration. Leave point at start of statement for
|
|
355 visual clarity."
|
|
356 (c++-skip-to-statement)
|
|
357 (save-excursion
|
|
358 (let ((class))
|
|
359 (and (looking-at c++-class-decl)
|
|
360 (setq class (buffer-substring
|
|
361 (match-beginning c++-class-name-grpn)
|
|
362 (match-end c++-class-name-grpn)))
|
|
363 (if (match-beginning c++-decl-template-grpn)
|
|
364 (setq class
|
|
365 (c++-get-class-name
|
|
366 class (buffer-substring
|
|
367 (match-beginning c++-decl-template-grpn)
|
|
368 (match-end c++-decl-template-grpn))
|
|
369 t))
|
|
370 t)
|
|
371 (not (c-within-comment-p))
|
|
372 (progn (beginning-of-line)
|
|
373 (not (looking-at "[ \t]*//")))
|
|
374 class))))
|
|
375
|
|
376 (defun c++-feature (&optional other-win)
|
|
377 "Move point to definition of member given by declaration at point.
|
|
378 Return nil if point is not within a member declaration."
|
|
379 ;; If '{' follows the feature declaration, then feature is defined right
|
|
380 ;; here, within the class definition.
|
|
381 (interactive)
|
|
382 (let ((feature-def) (ftr) (class) (ftr-pat))
|
|
383 (cond ((c++-feature-def-p)
|
|
384 (recenter 0)
|
|
385 t)
|
|
386 ((c++-view-friend other-win t))
|
|
387 ;; Now look for feature definition in code (non-header) files.
|
|
388 ((progn (setq feature-def (c++-feature-def-pat)
|
|
389 ftr (car (cdr (cdr feature-def)))
|
|
390 class (car (cdr feature-def))
|
|
391 ftr-pat (car feature-def))
|
|
392 (c++-locate-feature ftr class ftr-pat other-win)))
|
|
393 ((c++-feature-decl)
|
|
394 (beep)
|
|
395 (message "(OO-Browser): '%s' feature definition not found." ftr)
|
|
396 t))))
|
|
397
|
|
398 (defun c++-view-friend (&optional other-win sig-at-point-flag)
|
|
399 "With point on a friend listing entry, view its source code definition.
|
|
400 With optional OTHER-WIN non-nil, display in another window.
|
|
401 With optional SIG-AT-POINT-FLAG non-nil, assume point is within a friend
|
|
402 signature in a source buffer."
|
|
403 (interactive)
|
|
404 (let ((tag
|
|
405 (if (not sig-at-point-flag)
|
|
406 (br-feature-get-signature)
|
|
407 (beginning-of-line)
|
|
408 (and (looking-at c++-friend-regexp)
|
|
409 (looking-at c++-friend-in-class)
|
|
410 (let ((friend (buffer-substring (match-beginning 0)
|
|
411 (match-end 0)))
|
|
412 (class (c++-get-class-name-from-source)))
|
|
413 (c++-feature-normalize
|
|
414 friend class
|
|
415 (c++-feature-signature-to-name friend) t))))))
|
|
416 (cond ((or (null tag)
|
|
417 ;; Not a friend entry.
|
|
418 (/= ?% (aref (c++-feature-signature-to-name tag nil t) 0)))
|
|
419 nil)
|
|
420 ((= ?\{ (aref tag (1- (length tag))))
|
|
421 ;; Friend is defined where declared.
|
|
422 (br-feature nil 'view tag)
|
|
423 t)
|
|
424 ((string-match (format " class \\(%s\\) ?;$"
|
|
425 c++-return-type-identifier) tag)
|
|
426 ;; friend class
|
|
427 (br-view nil nil
|
|
428 (c++-normalize-template-arguments
|
|
429 (substring tag (match-beginning 1) (match-end 1))))
|
|
430 t)
|
|
431 (t
|
|
432 (if sig-at-point-flag
|
|
433 nil ;; Other feature location code will handle this.
|
|
434 (br-feature nil t tag) ;; Move point to friend declaration.
|
|
435 (c++-feature other-win))))))
|
|
436
|
|
437 (defun c++-feature-add-prefix (feature-name class signature &optional friend-flag)
|
|
438 "Add a browser listing display prefix to FEATURE-NAME from CLASS based on feature's SIGNATURE."
|
|
439 (concat (cond (friend-flag "% ")
|
|
440 ((string-match c++-pure-virtual-function-regexp signature)
|
|
441 "> ")
|
|
442 ((or (= ?~ (aref feature-name 0))
|
|
443 (equal feature-name (c++-class-non-template-name class))
|
|
444 (br-member feature-name
|
|
445 '("operator new" "operator delete")))
|
|
446 "+ ")
|
|
447 (t "- "))
|
|
448 feature-name))
|
|
449
|
|
450 (defun c++-feature-decl ()
|
|
451 (if (looking-at c++-class-decl)
|
|
452 nil
|
|
453 (looking-at c++-feature-decl)))
|
|
454
|
|
455 (defun c++-feature-def-p ()
|
|
456 "Return nil unless point is within a member definition.
|
|
457 Commented member definitions also return nil.
|
|
458 Leaves point at start of statement for visual clarity."
|
|
459 (c++-skip-to-statement)
|
100
|
460 (and (not (c-within-comment-p))
|
|
461 (save-excursion (beginning-of-line)
|
|
462 (not (looking-at "[ \t]*//")))
|
|
463 (not (looking-at c++-class-decl))
|
|
464 (looking-at (concat c++-at-feature-regexp "[{;,]"))
|
|
465 (let ((end-punct))
|
|
466 (or (= ?\{ (setq end-punct (char-after (1- (match-end 0)))))
|
|
467 ;; If ends with a '[;,]' then must not have func parens
|
|
468 ;; nor simply be a scoped name in order to be a def.
|
|
469 ;; If it begins with 'virtual', ends with "= 0" and has
|
|
470 ;; parens, then is a deferred virtual function declaration.
|
|
471 (if (match-end c++-feature-parens-grpn)
|
|
472 (save-restriction
|
|
473 (narrow-to-region (match-beginning 0) (match-end 0))
|
|
474 (if (looking-at
|
|
475 "\\s *\\<virtual\\>[^;{}]+=[ \t]*0[ \t]*[,;]")
|
|
476 (progn (message "(OO-Browser): Pure virtual function, definition deferred to descendants.")
|
|
477 t)))
|
|
478 (or (null (match-end c++-feature-scope-grpn))
|
|
479 (not (equal (concat
|
|
480 (buffer-substring
|
|
481 (match-beginning c++-feature-scope-grpn)
|
|
482 (match-end c++-feature-name-grpn))
|
|
483 (char-to-string end-punct))
|
|
484 (buffer-substring (match-beginning 0)
|
|
485 (match-end 0))))))))))
|
0
|
486
|
|
487 (defun c++-feature-def-pat ()
|
|
488 "Return (list <feature-def-pat> <feature-class> <feature-name>) associated with declaration at point."
|
|
489 (and (c++-skip-to-statement)
|
|
490 (c++-feature-decl)
|
|
491 ;; Don't regexp-quote member-name yet
|
|
492 (let* ((member-name (buffer-substring
|
|
493 (match-beginning c++-feature-name-grpn)
|
|
494 (match-end c++-feature-name-grpn)))
|
|
495 (member-modifiers (if (match-end c++-feature-mod-grpn)
|
|
496 (br-quote-match c++-feature-mod-grpn)))
|
|
497 (scoped-name)
|
|
498 (class)
|
|
499 (member-type
|
|
500 (concat (and (match-end c++-feature-type-grpn)
|
|
501 ;; Handle possible regexp bug
|
|
502 (not
|
|
503 (equal
|
|
504 (match-beginning c++-feature-type-grpn)
|
|
505 (match-beginning c++-feature-name-grpn)))
|
|
506 (concat (br-quote-match
|
|
507 c++-feature-type-grpn)))
|
|
508 (if (match-end c++-feature-scope-grpn)
|
|
509 (progn (setq scoped-name t
|
|
510 class (buffer-substring
|
|
511 (match-beginning
|
|
512 c++-feature-scope-grpn)
|
|
513 (- (match-end
|
|
514 c++-feature-scope-grpn)
|
|
515 2)))
|
|
516 (if (equal class "")
|
|
517 (setq class nil))
|
|
518 nil))))
|
|
519 (func-args (if (match-end c++-feature-parens-grpn)
|
|
520 (cons (match-beginning c++-feature-parens-grpn)
|
|
521 (match-end c++-feature-parens-grpn))))
|
|
522 (base-cl-args (match-end c++-feature-parens-grpn))
|
|
523 (friend)
|
|
524 )
|
|
525 (and member-type (string-match "[ \t]+$" member-type)
|
|
526 (setq member-type (substring member-type 0
|
|
527 (match-beginning 0))))
|
|
528 ;;
|
|
529 ;; Allow for different whitespace between declaration and definition
|
|
530 ;; when * or & is part of name and/or type, e.g. "char* id" and "char
|
|
531 ;; *id".
|
|
532 (if (and (stringp member-type)
|
|
533 (string-match "[*&]+$" member-type))
|
|
534 (setq member-type
|
|
535 (concat (substring member-type 0 (match-beginning 0))
|
|
536 "[ \t\n]*" (regexp-quote
|
|
537 (substring member-type
|
|
538 (match-beginning 0))))))
|
|
539 (if (string-match "^[*&]+" member-name)
|
|
540 (setq member-name (substring member-name (match-end 0))
|
|
541 member-type (concat member-type "[ \t\n]*"
|
|
542 (regexp-quote
|
|
543 (substring member-name 0
|
|
544 (match-end 0)))
|
|
545 "[ \t\n]*"))
|
|
546 (and (stringp member-type)
|
|
547 (not (equal member-type ""))
|
|
548 (setq member-type (concat member-type "[ \t\n]*"))))
|
|
549
|
|
550 (let ((pre-member-regexp
|
|
551 (concat
|
|
552 c++-template-prefix
|
|
553 "\\(\\(auto\\|inline\\|overload\\|static\\|virtual\\)[ \t\n]+\\)?"
|
|
554 (if member-modifiers
|
|
555 (let ((def-mods "") (mod))
|
|
556 (while (string-match "\\([a-z]+\\)[ \t\n]+"
|
|
557 member-modifiers)
|
|
558 (setq mod (substring member-modifiers
|
|
559 (match-beginning 1)
|
|
560 (match-end 1))
|
|
561 member-modifiers (substring member-modifiers
|
|
562 (match-end 0)))
|
|
563 (if (not friend)
|
|
564 (setq friend (string-equal mod "friend")))
|
|
565 (if (equal (string-match
|
|
566 c++-type-def-modifier mod) 0)
|
|
567 (setq def-mods (concat def-mods "\\(" mod
|
|
568 "[ \t\n]+\\)?"))))
|
|
569 def-mods))
|
|
570 (if (equal (string-match "virtual" member-type) 0)
|
|
571 nil member-type)))
|
|
572 (post-member-regexp
|
|
573 (concat
|
|
574 ;; Point at beginning of line may imply a non-member func.
|
|
575 (if (or scoped-name (not (bolp))) "::")
|
|
576 (progn (cond (scoped-name)
|
|
577 (friend
|
|
578 (progn
|
|
579 (if member-type
|
|
580 (progn
|
|
581 (setq class
|
|
582 (string-match c++-identifier
|
|
583 member-type))
|
|
584 (if class (setq class
|
|
585 (substring
|
|
586 member-type
|
|
587 class
|
|
588 (match-end 0))))))))
|
|
589 ;; Class name is not part of declaration
|
|
590 ;; nor a 'friend' declaration, so look
|
|
591 ;; for declaration within a class
|
|
592 ;; definition and locate the class name.
|
|
593 ;; If not within a class, assume
|
|
594 ;; declaration is global.
|
|
595 (t
|
|
596 (setq class (c++-get-class-name-from-source))))
|
|
597 (br-regexp-quote member-name))
|
|
598 "[ \t\n]*"
|
|
599 (if func-args
|
|
600 (concat "\\(" (c++-func-args-regexp func-args)
|
|
601 "\\|" (c++-func-args-string func-args)
|
|
602 "\\)"))
|
|
603 ;; If is a constructor member function, then can have some
|
|
604 ;; arguments for base class constructors after a ':'
|
|
605 ;; but preceding the '{'.
|
|
606 "[ \t\n]*"
|
|
607 (and base-cl-args
|
|
608 (equal member-name class)
|
|
609 "\\(:[^;{}]*\\)?")
|
|
610 c++-comment-regexp)))
|
|
611 (list
|
|
612 (` (lambda (class)
|
|
613 (concat "^" (br-regexp-quote class)
|
|
614 (, (concat
|
|
615 c++-type-tag-separator
|
|
616 br-feature-type-regexp " "
|
|
617 (br-regexp-quote member-name)
|
|
618 c++-type-tag-separator
|
|
619 pre-member-regexp))
|
|
620 (br-regexp-quote class)
|
|
621 (, post-member-regexp))))
|
|
622 class member-name)))))
|
|
623
|
100
|
624 (defun c++-feature-display (class-list ftr-pat &optional other-win)
|
|
625 "Display routine definition derived from CLASS-LIST, matching FTR-PAT.
|
|
626 Use routine tags table to locate a match. Caller must use 'set-buffer'
|
|
627 to restore prior buffer when a match is not found."
|
|
628 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file))
|
|
629 (let ((classes class-list)
|
|
630 (found-ftr)
|
|
631 (ftr-regexp)
|
|
632 (class)
|
|
633 (ftr-path))
|
|
634 (if (or (null class-list) (equal class-list '(nil)))
|
|
635 nil
|
|
636 (while (and (not found-ftr) classes)
|
|
637 (setq class (car classes)
|
|
638 ftr-regexp (funcall ftr-pat class)
|
|
639 ftr-path (br-feature-def-file ftr-regexp)
|
|
640 found-ftr (if ftr-path
|
|
641 (br-edit-feature-from-tag (br-feature-current)
|
|
642 ftr-path other-win))
|
|
643 classes (if found-ftr nil (cdr classes))))
|
|
644 (if found-ftr
|
|
645 (or class t)
|
|
646 (c++-feature-display
|
|
647 (apply 'append (mapcar (function (lambda (cl) (br-get-parents cl)))
|
|
648 class-list))
|
|
649 ftr-pat)))))
|
|
650
|
0
|
651 (defun c++-feature-lessp (routine1 routine2)
|
|
652 (string-lessp (c++-feature-signature-to-name routine1)
|
|
653 (c++-feature-signature-to-name routine2)))
|
|
654
|
100
|
655 (defun c++-feature-map-tags (function regexp)
|
|
656 "Apply FUNCTION to all current feature tags that match REGEXP and return a list of the results.
|
|
657 Feature tags come from the file named by br-feature-tags-file."
|
|
658 (let ((identifier-chars (concat "[" c++-identifier-chars "]*"))
|
|
659 (results))
|
|
660 ;; Ensure match to feature names only; also handle "^" and "$" meta-chars
|
|
661 (setq regexp
|
|
662 (concat (format "^[^%s \n]+%s%s "
|
|
663 c++-type-tag-separator c++-type-tag-separator
|
|
664 br-feature-type-regexp)
|
|
665 (if (equal (substring regexp 0 1) "^")
|
|
666 (progn (setq regexp (substring regexp 1)) nil)
|
|
667 identifier-chars)
|
|
668 (if (equal (substring regexp -1) "$")
|
|
669 (substring regexp 0 -1)
|
|
670 (concat regexp identifier-chars))
|
|
671 c++-type-tag-separator))
|
|
672 (save-excursion
|
|
673 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file))
|
|
674 (goto-char 1)
|
|
675 (while (re-search-forward regexp nil t)
|
|
676 (setq results (cons (funcall function) results))))
|
|
677 results))
|
|
678
|
70
|
679 (defun c++-feature-matches (regexp)
|
100
|
680 "Return an unsorted list of feature tags whose names match in part or whole to REGEXP.
|
|
681 ^ and $ characters may be used to match to the beginning and end of a feature name,
|
|
682 respectively."
|
|
683 (c++-feature-map-tags 'br-feature-current regexp))
|
0
|
684
|
|
685 (defun c++-feature-normalize (routine class name &optional friend-flag)
|
|
686 (setq class (br-delete-space class)
|
|
687 name (c++-feature-add-prefix name class routine friend-flag)
|
|
688 routine (concat class c++-type-tag-separator
|
|
689 name c++-type-tag-separator
|
|
690 (br-delete-space routine)))
|
|
691 (let* ((len (length routine))
|
|
692 (normal-feature (make-string len ?\ ))
|
|
693 (n 0) (i 0)
|
|
694 (space-list '(?\ ?\t ?\n ?\^M))
|
|
695 (space-regexp "[ \t\n\^M]+")
|
|
696 chr)
|
|
697 (while (< i len)
|
|
698 (setq chr (aref routine i))
|
|
699 (cond
|
|
700 ;; Convert sequences of space characters to a single space.
|
|
701 ((memq chr space-list)
|
|
702 (aset normal-feature n ?\ )
|
|
703 (if (string-match space-regexp routine i)
|
|
704 (setq i (match-end 0)
|
|
705 n (1+ n))
|
|
706 (setq i (1+ i)
|
|
707 n (1+ n))))
|
|
708 ;;
|
|
709 ;; Remove // style comments
|
|
710 ((and (= chr ?/)
|
|
711 (< (1+ i) len)
|
|
712 (= (aref routine (1+ i)) ?/))
|
|
713 (setq i (+ i 2))
|
|
714 (while (and (< i len) (/= (aref routine i) ?\n))
|
|
715 (setq i (1+ i))))
|
|
716 (t ;; Normal character
|
|
717 (aset normal-feature n chr)
|
|
718 (setq i (1+ i)
|
|
719 n (1+ n)))))
|
|
720 (substring normal-feature 0 n)))
|
|
721
|
|
722 (defun c++-feature-tag-class (signature)
|
|
723 "Extract the class name from SIGNATURE."
|
|
724 (cond ((string-match c++-type-tag-separator signature)
|
|
725 (substring signature 0 (match-beginning 0)))
|
|
726 ((string-match "\\([^ \t]+\\)::" signature)
|
|
727 (substring signature (match-beginning 1) (match-end 1)))
|
|
728 (t "")))
|
|
729
|
|
730 (defun c++-files-with-source (class)
|
|
731 "Use CLASS to compute set of files that match to a C++ source file regexp.
|
|
732 Return as a list."
|
|
733 (let ((file (if class (br-class-path class) buffer-file-name)))
|
|
734 (and file
|
|
735 (let* ((src-file-regexp (concat "^" (br-filename-head file)
|
|
736 c++-code-file-regexp))
|
|
737 (dir (file-name-directory file))
|
|
738 (files (directory-files dir nil src-file-regexp)))
|
|
739 (mapcar (function (lambda (f) (concat dir f)))
|
|
740 files)))))
|
|
741
|
|
742 (defun c++-find-ancestors-feature (class-list ftr-pat &optional other-win)
|
|
743 "Scan ancestors of CLASS-LIST and show routine definition matching FTR-PAT."
|
|
744 ;; If no class, search for non-member function.
|
|
745 (or class-list (setq class-list '(nil)))
|
|
746 (let ((obuf (current-buffer)))
|
|
747 (prog1
|
|
748 (if (and br-feature-tags-file
|
|
749 (file-exists-p br-feature-tags-file)
|
|
750 (file-readable-p br-feature-tags-file))
|
100
|
751 (c++-feature-display class-list ftr-pat other-win)
|
0
|
752 ;; Only works if features are in same directory as class def.
|
|
753 (c++-scan-ancestors-feature class-list ftr-pat other-win))
|
|
754 (set-buffer obuf))))
|
|
755
|
|
756 (defun c++-find-class-name ()
|
|
757 "Return current word as a potential class name."
|
|
758 (save-excursion
|
|
759 (let* ((start)
|
|
760 (ignore "\]\[ \t\n;,.\(\){}*&-")
|
|
761 (pat (concat "^" ignore)))
|
|
762 (forward-char 1)
|
|
763 (skip-chars-backward ignore)
|
|
764 (skip-chars-backward pat)
|
|
765 (setq start (point))
|
|
766 (skip-chars-forward (concat pat ":"))
|
|
767 (buffer-substring start (point)))))
|
|
768
|
|
769 (defun c++-func-args-regexp (func-args)
|
|
770 (let* ((space "\\\\\\s-*")
|
|
771 (obuf (current-buffer))
|
|
772 (tmp-buf-nm "*br-c++-tmp*")
|
|
773 (tmp-buf (progn (if (get-buffer tmp-buf-nm)
|
|
774 (kill-buffer tmp-buf-nm))
|
|
775 (get-buffer-create tmp-buf-nm))))
|
|
776 (or tmp-buf (error "OO-Browser: (c++-func-args-regexp) - Can't create tmp-buf."))
|
|
777 ;; Fill tmp-buffer with all func-args, including parens.
|
|
778 (copy-to-buffer tmp-buf (car func-args) (cdr func-args))
|
|
779
|
|
780 (set-buffer tmp-buf)
|
|
781 (let ((quoted-args (br-regexp-quote (buffer-substring
|
|
782 (point-min) (point-max)))))
|
|
783 (erase-buffer)
|
|
784 (insert quoted-args))
|
|
785
|
|
786 (goto-char (point-min))
|
|
787 (if (looking-at "(\\s-*)")
|
|
788 (replace-match "(\\\\s-*)" t)
|
|
789
|
|
790 ;; Replace all "\( +" with "\(" temporarily
|
|
791 (br-buffer-replace "\\(^\\|[^\\]\\)\([ \t\n]+" "\\1\(")
|
|
792
|
|
793 ;; Replace all "+ \)" with "\)" temporarily
|
|
794 (br-buffer-replace "[ \t\n]+\)" "\)")
|
|
795
|
|
796 ;; Replace all "...\)" with "...@" temporarily
|
|
797 (br-buffer-replace "\\\\\\.\\\\\\.\\\\\\.\)" "@@@")
|
|
798
|
|
799 ;; Optionalize right hand side of argument assignments.
|
|
800 (br-buffer-replace "\\([^=,\( \t\n]+\\)\\([ \t\n]*=[^,\)]+\\)"
|
|
801 (concat "\\1\\\\( "
|
|
802 (br-regexp-quote c++-arg-identifier)
|
|
803 "\\\\)? \\\\(\\2\\\\)?"))
|
|
804
|
|
805 ;; Replace all "\)" with "optional <c++-identifier> \)"
|
|
806 (br-buffer-replace
|
|
807 "\\([\(,][^=\)]+\\)\)"
|
|
808 (concat "\\1\\\\( " (br-regexp-quote c++-arg-identifier)
|
|
809 "\\\\)?\)"))
|
|
810
|
|
811 ;; Replace all "," with "optional <c++-identifier>,"
|
|
812 (br-buffer-replace
|
|
813 "\\([\(,][^=,]+\\),"
|
|
814 (concat "\\1\\\\( " (br-regexp-quote c++-arg-identifier) "\\\\)?,"))
|
|
815
|
|
816 ;; Replace all " *, *" with "<spc>,<spc>"
|
|
817 (br-buffer-replace "[ \t\n]*,[ \t\n]*" (concat space "," space))
|
|
818
|
|
819 ;; Replace all " +" with "<spc>"
|
|
820 (br-buffer-replace "[ \t\n]+" space)
|
|
821
|
|
822 ;; Replace all "\(" with "\(<spc>"
|
|
823 (br-buffer-replace "\\(^\\|[^\\]\\)\(" (concat "\\1\(" space))
|
|
824
|
|
825 ;; Replace all "\)" with "<spc>\)"
|
|
826 (br-buffer-replace "\\([^\\]\\)\)" (concat "\\1" space "\)"))
|
|
827
|
|
828 ;; Replace all & and quoted \\* with "<spc>[*&]+<spc>"
|
|
829 (br-buffer-replace "\\(&\\|\\\\\\*\\)+" (concat space "\\1" space))
|
|
830
|
|
831 ;; Replace all "<spc>" with "[ \t\n]*"
|
|
832 (br-buffer-replace "\\\\s-\\*" "[ \t\n]*")
|
|
833
|
|
834 ;; Replace all "@@@" with any # of args
|
|
835 (br-buffer-replace "@@@" "[^\)]*\)")
|
|
836 )
|
|
837
|
|
838 ;; Return final buffer as a string.
|
|
839 (prog1 (buffer-substring (point-min) (point-max))
|
|
840 (kill-buffer tmp-buf-nm)
|
|
841 (set-buffer obuf))))
|
|
842
|
|
843 (defun c++-func-args-string (func-args)
|
|
844 (let* ((space "\\\\\\s-*")
|
|
845 (obuf (current-buffer))
|
|
846 (tmp-buf-nm "*br-c++-tmp*")
|
|
847 (tmp-buf (progn (if (get-buffer tmp-buf-nm)
|
|
848 (kill-buffer tmp-buf-nm))
|
|
849 (get-buffer-create tmp-buf-nm))))
|
|
850 (or tmp-buf (error "OO-Browser: (c++-func-args-string) - Can't create tmp-buf."))
|
|
851 ;; Fill tmp-buffer with all func-args, including parens.
|
|
852 (copy-to-buffer tmp-buf (car func-args) (cdr func-args))
|
|
853
|
|
854 (set-buffer tmp-buf)
|
|
855 (let ((quoted-args (br-regexp-quote (buffer-substring
|
|
856 (point-min) (point-max)))))
|
|
857 (erase-buffer)
|
|
858 (insert quoted-args))
|
|
859
|
|
860 (goto-char (point-min))
|
|
861 (if (looking-at "(\\s-*)")
|
|
862 (replace-match "(\\\\s-*)" t)
|
|
863
|
|
864 ;; Replace all "\( +" with "\(" temporarily
|
|
865 (br-buffer-replace "\\(^\\|[^\\]\\)\([ \t\n]+" "\\1\(")
|
|
866
|
|
867 ;; Replace all "+ \)" with "\)" temporarily
|
|
868 (br-buffer-replace "[ \t\n]+\)" "\)")
|
|
869
|
|
870 ;; Replace all "...\)" with "@@@" temporarily
|
|
871 (br-buffer-replace "\\\\\\.\\\\\\.\\\\\\.\)" "@@@")
|
|
872
|
|
873 ;; Optionalize right hand side of argument assignments.
|
|
874 (br-buffer-replace "\\([^=,\( \t\n]+\\)\\([ \t\n]+=[^,\)]+\\)"
|
|
875 (concat "\\1\\\\(\\2\\\\)?"))
|
|
876
|
|
877 ;; If an arg consists of 2 or more words, replace last with <identifier>
|
|
878 (br-buffer-replace
|
|
879 "\\([\(,][^=,\)]*[^ \t\n=,\)]+[ \t\n]+\\)[^ \t\n=,\)]+\\([ \t\n]*[,\)]\\)"
|
|
880 (concat "\\1" (br-regexp-quote c++-arg-identifier) "\\2"))
|
|
881
|
|
882 ;; If an arg consists of only 1 word, add a second
|
|
883 (br-buffer-replace
|
|
884 "\\([\(,][ \t\n]*\\)\\([^ \t\n=,\)]+\\)\\([ \t\n]*[,\)]\\)"
|
|
885 (concat "\\1\\2 " (br-regexp-quote c++-arg-identifier) "\\3"))
|
|
886
|
|
887 ;; Replace all " *, *" with "<spc>,<spc>"
|
|
888 (br-buffer-replace "[ \t\n]*,[ \t\n]*" (concat space "," space))
|
|
889
|
|
890 ;; Replace all " +" with "<spc>"
|
|
891 (br-buffer-replace "[ \t\n]+" space)
|
|
892
|
|
893 ;; Replace all "\(" with "\(<spc>"
|
|
894 (br-buffer-replace "\\(^\\|[^\\]\\)\(" (concat "\\1\(" space))
|
|
895
|
|
896 ;; Replace all "\)" with "<spc>\)"
|
|
897 (br-buffer-replace "\\([^\\]\\)\)" (concat "\\1" space "\)"))
|
|
898
|
|
899 ;; Replace all & and quoted \\* with "<spc>[*&]+<spc>"
|
|
900 (br-buffer-replace "\\(&\\|\\\\\\*\\)+" (concat space "\\1" space))
|
|
901
|
|
902 ;; Replace all "<spc>" with "[ \t\n]*"
|
|
903 (br-buffer-replace "\\\\s-\\*" "[ \t\n]*")
|
|
904
|
|
905 ;; Replace all "@@@" with any # of args
|
|
906 (br-buffer-replace "@@@" "[^\)]*\)")
|
|
907 )
|
|
908
|
|
909 ;; Return final buffer as a string.
|
|
910 (prog1 (buffer-substring (point-min) (point-max))
|
|
911 (kill-buffer tmp-buf-nm)
|
|
912 (set-buffer obuf))))
|
|
913
|
|
914 (defun c++-get-class-name-from-source ()
|
|
915 "Return class name from closest class definition preceding point or nil."
|
|
916 (let ((opoint (point))
|
|
917 (class))
|
|
918 (save-excursion
|
|
919 (if (re-search-backward c++-class-def-regexp nil t)
|
|
920 (progn (goto-char (match-beginning c++-class-def-derived-grpn))
|
|
921 (setq class (c++-normalize-class-match nil))
|
|
922 ;; Ensure that declaration occurs within class definition.
|
|
923 (forward-list)
|
|
924 (and (> (point) opoint)
|
|
925 class))))))
|
|
926
|
|
927 (defun c++-get-feature-tags (routine-file &optional routine-list)
|
|
928 "Scan C++ ROUTINE-FILE and hold routine tags in 'br-feature-tags-file'.
|
|
929 Assume ROUTINE-FILE has already been read into a buffer and that
|
|
930 'br-feature-tags-init' has been called. Optional ROUTINE-LIST can be
|
|
931 provided so that a non-standard scan function can be used before calling
|
|
932 this function."
|
|
933 (interactive)
|
|
934 (let ((obuf (current-buffer)))
|
|
935 (or routine-list
|
|
936 (setq routine-list (c++-sort-features (nreverse
|
|
937 (c++-scan-features)))))
|
|
938 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file))
|
|
939 (goto-char 1)
|
|
940 ;; Delete any prior routine tags associated with routine-file
|
|
941 (if (search-forward routine-file nil 'end)
|
|
942 (progn (forward-line -1)
|
|
943 (let ((start (point)))
|
|
944 (search-forward "\^L" nil 'end 2)
|
|
945 (backward-char 1)
|
|
946 (delete-region start (point))
|
|
947 )))
|
|
948 (if routine-list
|
|
949 (progn (insert "\^L\n" routine-file "\n")
|
|
950 (mapcar (function (lambda (tag) (insert tag "\n")))
|
|
951 routine-list)
|
|
952 ))
|
|
953 (set-buffer obuf)))
|
|
954
|
|
955 (defun c++-include-file (&optional other-win)
|
|
956 "If point is on an include file line, try to display file.
|
|
957 Return non-nil iff an include file line, even if file is not found.
|
|
958 Look for include file in 'c++-cpp-include-dirs' and in directory list
|
|
959 'c++-include-dirs'."
|
|
960 (let ((opoint (point)))
|
|
961 (beginning-of-line)
|
|
962 (if (looking-at c++-include-regexp)
|
|
963 (let ((incl-type (string-to-char
|
|
964 (buffer-substring (match-beginning 1)
|
|
965 (1+ (match-beginning 1)))))
|
|
966 (file (buffer-substring (match-beginning 2) (match-end 2)))
|
|
967 (path)
|
|
968 (dir-list c++-include-dirs)
|
|
969 (found))
|
|
970 (goto-char opoint)
|
|
971 (setq dir-list (if (= incl-type ?<)
|
|
972 (append dir-list c++-cpp-include-dirs)
|
|
973 (cons (file-name-directory buffer-file-name)
|
|
974 dir-list)))
|
|
975 (while dir-list
|
|
976 (setq path (concat (car dir-list) file)
|
|
977 dir-list (if (setq found (file-exists-p path))
|
|
978 nil
|
|
979 (cdr dir-list))))
|
|
980 ;;
|
|
981 ;; If not found in normal include dirs, check all Env paths also.
|
|
982 ;;
|
|
983 (if (not found)
|
|
984 (let ((paths (delq nil (hash-map 'cdr br-paths-htable))))
|
|
985 (while paths
|
|
986 (setq path (car paths))
|
|
987 (if (string-equal (file-name-nondirectory path) file)
|
|
988 (setq found t paths nil)
|
|
989 (setq paths (cdr paths))))))
|
|
990 ;;
|
|
991 ;; If found, display file
|
|
992 ;;
|
|
993 (if found
|
|
994 (if (file-readable-p path)
|
|
995 (progn
|
|
996 (funcall br-edit-file-function path other-win)
|
|
997 (if (not (fboundp 'br-lang-mode))
|
|
998 (c++-mode-setup))
|
|
999 (br-major-mode))
|
|
1000 (beep)
|
|
1001 (message "(OO-Browser): Include file '%s' unreadable." path))
|
|
1002 (beep)
|
|
1003 (message "(OO-Browser): Include file '%s' not found." file))
|
|
1004 path)
|
|
1005 (goto-char opoint)
|
|
1006 nil)))
|
|
1007
|
|
1008 (defun c++-locate-feature (ftr class ftr-pat &optional other-win)
|
|
1009 ;; 'class' may = nil, implying non-member function
|
|
1010 (or class (setq class "[function]"))
|
|
1011 (let ((def-class))
|
|
1012 (if (and ftr-pat
|
|
1013 (setq def-class
|
|
1014 (c++-find-ancestors-feature (list class)
|
|
1015 ftr-pat other-win)))
|
|
1016 (progn (if (and class (not (equal class def-class)))
|
|
1017 (message
|
|
1018 "Member `%s` of class '%s' inherited from class '%s'."
|
|
1019 ftr class def-class))
|
|
1020 t))))
|
|
1021
|
|
1022 (defun c++-scan-ancestors-feature (class-list ftr-pat &optional other-win)
|
|
1023 "Display routine definition derived from CLASS-LIST, matching FTR-PAT.
|
|
1024 Scan files with same base name as class file."
|
|
1025 (let ((classes class-list)
|
|
1026 (found-ftr)
|
|
1027 (code-def-files)
|
|
1028 (file)
|
|
1029 (ftr-regexp)
|
|
1030 (class))
|
|
1031 (if (null class-list)
|
|
1032 nil
|
|
1033 (while (and (not found-ftr) classes)
|
|
1034 (setq class (car classes)
|
|
1035 code-def-files (c++-files-with-source class)
|
|
1036 ftr-regexp (funcall ftr-pat class))
|
|
1037 (while (and (setq file (car code-def-files))
|
|
1038 (not (setq found-ftr
|
|
1039 (br-feature-found-p file ftr-regexp
|
|
1040 nil other-win t))))
|
|
1041 (setq code-def-files (cdr code-def-files)))
|
|
1042 (setq classes (if found-ftr nil (cdr classes))))
|
|
1043 (if found-ftr
|
|
1044 (or class t)
|
|
1045 (c++-scan-ancestors-feature
|
|
1046 (apply 'append (mapcar (function (lambda (cl) (br-get-parents cl)))
|
|
1047 class-list))
|
|
1048 ftr-pat)))))
|
|
1049
|
|
1050 (defun c++-scan-features-in-class (class start end)
|
|
1051 "Return reverse ordered list of C++ routine definitions within CLASS def.
|
|
1052 START and END give buffer region to search."
|
|
1053 (setq class (br-delete-space class))
|
|
1054 (save-excursion
|
|
1055 (save-restriction
|
|
1056 (narrow-to-region start end)
|
|
1057 (goto-char start)
|
|
1058 (let ((routines) rout name type)
|
|
1059 ;;
|
|
1060 ;; Get member definitions and pure virtual declarations.
|
|
1061 ;;
|
|
1062 (while (re-search-forward c++-routine-def-in-class nil t)
|
|
1063 (setq start (match-beginning 0)
|
|
1064 name (buffer-substring
|
|
1065 (match-beginning c++-feature-name-grpn)
|
|
1066 (match-end c++-feature-name-grpn))
|
|
1067 type (if (match-beginning c++-feature-type-grpn)
|
|
1068 (buffer-substring
|
|
1069 (match-beginning c++-feature-type-grpn)
|
|
1070 (match-end c++-feature-type-grpn)))
|
|
1071 rout (buffer-substring (match-beginning 0) (match-end 0))
|
|
1072 ;; Do this after done getting groupings from the search.
|
|
1073 type (if type (br-delete-space type)))
|
|
1074 ;; This is necessary to remove a possible double expression match
|
|
1075 ;; where there is a blank line within the match.
|
|
1076 (if (string-match "[\n\^M]\\([ \t]*[\n\^M]\\)+" rout)
|
|
1077 (progn (setq rout (substring rout (match-end 0)))
|
|
1078 (goto-char (+ start (match-end 0))))
|
|
1079 (if (c-within-comment-p)
|
|
1080 (search-forward "*/" nil t)
|
|
1081 ;; Move point to precede feature opening brace or pure virtual
|
|
1082 ;; function declaration semicolon.
|
|
1083 (backward-char)
|
|
1084 (if (= (following-char) ?\{)
|
|
1085 (condition-case ()
|
|
1086 ;; Move to end of feature but ignore any error if braces
|
|
1087 ;; are unbalanced. Let the compiler tell the user about
|
|
1088 ;; this.
|
|
1089 (forward-sexp)
|
|
1090 (error nil)))
|
|
1091 (if (string-match c++-friend-regexp rout)
|
|
1092 ;; skip friends until later
|
|
1093 nil
|
|
1094 ;; Handle type conversion ops: operator int() { return i; }
|
|
1095 (if (equal type "operator") (setq name (concat type " " name)
|
|
1096 type nil))
|
|
1097 (setq rout (c++-feature-normalize rout class name)
|
|
1098 routines (cons rout routines))))))
|
|
1099 ;;
|
|
1100 ;; Get friend declarations.
|
|
1101 ;;
|
|
1102 (goto-char (point-min))
|
|
1103 (while (re-search-forward c++-friend-regexp nil t)
|
|
1104 (beginning-of-line)
|
|
1105 (if (not (looking-at c++-friend-in-class))
|
|
1106 nil
|
|
1107 (setq start (match-beginning 0)
|
|
1108 name (buffer-substring
|
|
1109 (match-beginning c++-feature-name-grpn)
|
|
1110 (match-end c++-feature-name-grpn))
|
|
1111 type (if (match-beginning c++-feature-type-grpn)
|
|
1112 (buffer-substring
|
|
1113 (match-beginning c++-feature-type-grpn)
|
|
1114 (match-end c++-feature-type-grpn)))
|
|
1115 rout (buffer-substring (match-beginning 0) (match-end 0))
|
|
1116 ;; Do this after done getting groupings from the search.
|
|
1117 type (if type (br-delete-space type)))
|
|
1118 ;; This is necessary to remove a possible double expression match
|
|
1119 ;; where there is a blank line within the match.
|
|
1120 (if (string-match "[\n\^M]\\([ \t]*[\n\^M]\\)+" rout)
|
|
1121 (progn (setq rout (substring rout (match-end 0)))
|
|
1122 (goto-char (+ start (match-end 0))))
|
|
1123 (if (c-within-comment-p)
|
|
1124 (search-forward "*/" nil t)
|
|
1125 ;; Handle type conversion ops: operator int() { return i; }
|
|
1126 (if (equal type "operator") (setq name (concat type " " name)
|
|
1127 type nil))
|
|
1128 (setq rout (c++-feature-normalize rout class name t)
|
|
1129 routines (cons rout routines)))))
|
|
1130 ;; Move to next entry.
|
|
1131 (or (= (forward-line 1) 0) (end-of-line)))
|
|
1132 routines))))
|
|
1133
|
|
1134 (defun c++-skip-past-comments ()
|
|
1135 "Skip over comments immediately following point."
|
|
1136 (skip-chars-forward " \t\n")
|
|
1137 (while
|
|
1138 (cond ((looking-at "//")
|
|
1139 (equal (forward-line 1) 0))
|
|
1140 ((looking-at "/\\*")
|
|
1141 (re-search-forward "\\*/" nil t))
|
|
1142 (t nil))))
|
|
1143
|
|
1144 (defun c++-skip-to-statement ()
|
|
1145 (if (re-search-backward "\\(^\\|[;{}]\\)[ \t]*" nil t)
|
|
1146 (progn (goto-char (match-end 0))
|
|
1147 (skip-chars-forward " \t")
|
|
1148 t)))
|
|
1149
|
|
1150 ;;; ************************************************************************
|
|
1151 ;;; Private variables
|
|
1152 ;;; ************************************************************************
|
|
1153
|
|
1154 (defconst c++-code-file-regexp "\\.\\(cxx\\|[cC][cC]?P?\\)$"
|
|
1155 "Regular expression matching a unique part of C++ source (non-header) file name and no others.")
|
|
1156
|
|
1157 (defconst c++-include-regexp
|
|
1158 "[ \t/*]*#[ \t]*include[ \t]+\\([\"<]\\)\\([^\">]+\\)[\">]"
|
|
1159 "Regexp to match to C++ include file lines. File name is grouping 2. Type
|
|
1160 of include, user-specified via double quote, or system-related starting with
|
|
1161 '<' is given by grouping 1.")
|
|
1162
|
|
1163 (defconst c++-type-def-modifier
|
|
1164 "\\(auto\\|const\\|inline\\|mutable\\|register\\|static\\|typedef\\)")
|
|
1165
|
|
1166 (defconst c++-type-modifier-keyword
|
|
1167 (concat "\\(\\(auto\\|const\\|explicit\\|extern[ \t\n\^M]+\"[^\"]+\"\\|"
|
|
1168 "extern\\|friend\\|inline\\|mutable\\|overload\\|"
|
|
1169 "register\\|static\\|typedef\\|virtual\\)[ \t\n\^M]+\\)"))
|
|
1170
|
|
1171 (defconst c++-member-modifier-keyword
|
|
1172 "\\(\\([ \t\n\^M]+const\\|[ \t\n\^M]+mutable\\)?\\([ \t\n\^M]*[=:][^;{]+\\)?\\)")
|
|
1173
|
|
1174 (defconst c++-type-identifier-group
|
|
1175 ;; It is critical that the final part of this expression, [*& \t\n\^M]+,
|
|
1176 ;; stay exactly as it is or certain feature definitions may be missed or
|
|
1177 ;; segmented improperly.
|
|
1178 ;; If you remove the '*&', "Int &operator=(int j) {}", will not be found
|
|
1179 ;; because the & will be missed. If you change the '+' to a '*', "main()"
|
|
1180 ;; will show up as "- n" in listing buffers.
|
|
1181 (concat "\\(\\(" c++-return-type-identifier "\\)[*& \t\n\^M]+\\)"))
|
|
1182
|
|
1183 (defconst c++-function-identifier (concat
|
|
1184 "[_~<a-zA-Z][^][ \t:;.,~{}()]*")
|
|
1185 "Regular expression matching a C++ or G++ function name.")
|
|
1186
|
|
1187 ;; Old def = "operator[ \t]*[^]) \t:;.,?~{}][^[( \t:;.,~^!|?{}]?[=*]?"
|
|
1188 ;; Final optional expression is to handle new C++ array operators, e.g.
|
|
1189 ;; void operator delete [] (void*);
|
|
1190 (defconst c++-operator-identifier "operator[ \t\n\^M]*[^ \t\n\^M:;.,?~{}]+\\([ \t\n\^M]*\\[\\]\\)?"
|
|
1191 "Regular expression matching a C++ or G++ operator name.")
|
|
1192
|
|
1193 (defconst c++-feature-decl-or-def
|
|
1194 (concat c++-template-prefix
|
|
1195 "\\(" c++-type-modifier-keyword "*"
|
|
1196 c++-type-identifier-group "\\)?"
|
|
1197 "\\(" c++-type-identifier "[ \t\n\^M]*\\)?"
|
|
1198 "\\(" c++-operator-identifier "\\|" c++-function-identifier "\\|"
|
|
1199 "[*&]?" c++-identifier "\\)"
|
|
1200 ;; This old version of the next line matched to things such as:
|
|
1201 ;; enum name {};. Since we don't deal with attributes yet and
|
|
1202 ;; since such matches improperly end up in the [function] default
|
|
1203 ;; class, we only accept matches with () in them.
|
|
1204 ;; "[ \t\n\^M]*\\(\\[[^{;]+\\|([^{;]*)"
|
|
1205 "[ \t\n\^M]*\\(([^{;]*)"
|
|
1206 c++-member-modifier-keyword "?\\)")
|
|
1207 "Regexp matching a C++ member declaration or definition.
|
|
1208 Member modifier keywords are grouped expression 'c++-feature-mode-grpn'.
|
|
1209 Member type is grouped expression 'c++-feature-type-grpn', unless scoping
|
|
1210 type name, grouped expression 'c++-feature-scope-grpn' is non-nil, in which
|
|
1211 case, grouping 'c++-feature-scope-grpn' is the type plus \"::\".
|
|
1212 Member name is group 'c++-feature-name-grpn'. Function parentheses, if any,
|
|
1213 are group 'c++-feature-parens-grpn'.")
|
|
1214
|
|
1215 (defconst c++-feature-mod-grpn 3)
|
|
1216 (defconst c++-feature-type-grpn 6)
|
|
1217 (defconst c++-feature-scope-grpn 10)
|
|
1218 (defconst c++-feature-name-grpn 11)
|
|
1219 (defconst c++-feature-parens-grpn 14)
|
|
1220
|
|
1221 (defconst c++-at-feature-regexp
|
|
1222 (concat c++-feature-decl-or-def c++-comment-regexp)
|
|
1223 "See documentation of 'c++-feature-decl-or-def' for grouping expressions.")
|
|
1224
|
|
1225 (defconst c++-feature-decl
|
|
1226 (concat c++-at-feature-regexp ";")
|
|
1227 "See documentation of 'c++-feature-decl-or-def' for grouping expressions.")
|
|
1228
|
|
1229 (defconst c++-friend-in-class
|
|
1230 (concat "[ \t]*" c++-at-feature-regexp "[{;]")
|
|
1231 "See documentation of 'c++-feature-decl-or-def' for grouping expressions.
|
|
1232 This doesn't limit matches to friends. See 'c++-friend-regexp' for that.")
|
|
1233
|
|
1234 (defconst c++-friend-regexp "^[^(){}\n\^M]*[ \t]friend[ \t\n\^M]"
|
|
1235 "Regexp matching a C++ friend declaration or definition at the start of a line or the start of a string.")
|
|
1236
|
|
1237 (defconst c++-routine-def-terminator-regexp
|
|
1238 ;; Also matches to pure virtual function declarations.
|
|
1239 "\\({\\|[ \t\n\^M]*=[ \t]*0[ \t]*;\\)")
|
|
1240
|
|
1241 (defconst c++-routine-def
|
|
1242 (concat "^" c++-at-feature-regexp c++-routine-def-terminator-regexp)
|
|
1243 "See documentation of 'c++-feature-decl-or-def' for grouping expressions.")
|
|
1244
|
|
1245 (defconst c++-routine-def-in-class
|
|
1246 (concat "^[ \t]*" c++-at-feature-regexp c++-routine-def-terminator-regexp)
|
|
1247 "See documentation of 'c++-feature-decl-or-def' for grouping expressions.")
|
|
1248
|
|
1249 (defconst c++-class-modifier-keyword
|
|
1250 "\\(\\(friend\\|public\\|protected\\)[ \t\n\^M]+\\)")
|
|
1251
|
|
1252 (defconst c++-class-decl
|
|
1253 (concat c++-class-modifier-keyword "?"
|
|
1254 c++-template-prefix
|
|
1255 c++-class-keyword c++-identifier "[ \t]*[;,]")
|
|
1256 "Regexp matching a C++ class declaration.
|
|
1257 Template match, if any, is grouping 'c++-decl-template-grpn'.
|
|
1258 Class name is grouping 'c++-class-name-grpn'.")
|
|
1259
|
|
1260 (defconst c++-decl-template-grpn 3)
|
|
1261 (defconst c++-class-name-grpn 5)
|
|
1262
|
|
1263 (defconst c++-arg-identifier
|
|
1264 (concat "[_a-zA-Z][" c++-identifier-chars "]*")
|
|
1265 "Regular expression matching a C++ or G++ function argument identifier.")
|
|
1266
|
|
1267 (defconst c++-pure-virtual-function-regexp "\)[^=]*=[ \t]*0[ \t]*;\\'"
|
|
1268 "Regexp matching the trailing part of a C++ pure virtual function signature.")
|
|
1269
|
|
1270 (provide 'br-c++-ft)
|