comparison lisp/oobr/br-c++-ft.el @ 0:376386a54a3c r19-14

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