Mercurial > hg > xemacs-beta
comparison lisp/oobr/br-c++-ft.el @ 100:4be1180a9e89 r20-1b2
Import from CVS: tag r20-1b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:15:11 +0200 |
parents | 131b0175ea99 |
children |
comparison
equal
deleted
inserted
replaced
99:2d83cbd90d8d | 100:4be1180a9e89 |
---|---|
4 ;; SUMMARY: C++ OO-Browser class and member functions. | 4 ;; SUMMARY: C++ OO-Browser class and member functions. |
5 ;; USAGE: GNU Emacs Lisp Library | 5 ;; USAGE: GNU Emacs Lisp Library |
6 ;; KEYWORDS: c, oop, tools | 6 ;; KEYWORDS: c, oop, tools |
7 ;; | 7 ;; |
8 ;; AUTHOR: Bob Weiner | 8 ;; AUTHOR: Bob Weiner |
9 ;; ORG: Motorola Inc. | 9 ;; ORG: InfoDock Associates |
10 ;; | 10 ;; |
11 ;; ORIG-DATE: 03-Oct-90 | 11 ;; ORIG-DATE: 03-Oct-90 |
12 ;; LAST-MOD: 5-May-95 at 15:59:53 by Bob Weiner | 12 ;; LAST-MOD: 11-Nov-96 at 17:29:58 by Bob Weiner |
13 ;; | 13 ;; |
14 ;; Copyright (C) 1990-1995 Free Software Foundation, Inc. | 14 ;; Copyright (C) 1990-1996 Free Software Foundation, Inc. |
15 ;; See the file BR-COPY for license information. | 15 ;; See the file BR-COPY for license information. |
16 ;; | 16 ;; |
17 ;; This file is part of the OO-Browser. | 17 ;; This file is part of the OO-Browser. |
18 ;; | 18 ;; |
19 ;; DESCRIPTION: | 19 ;; DESCRIPTION: |
161 (c++-to-comments-begin) | 161 (c++-to-comments-begin) |
162 (recenter 0) | 162 (recenter 0) |
163 (goto-char start) | 163 (goto-char start) |
164 t)))) | 164 t)))) |
165 | 165 |
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 | |
166 (defun c++-feature-name-to-regexp (name) | 182 (defun c++-feature-name-to-regexp (name) |
167 "Converts routine NAME into a regular expression matching the routine's name tag." | 183 "Converts routine NAME into a regular expression matching the routine's name tag." |
168 (setq name (c++-feature-signature-to-regexp name)) | 184 (setq name (c++-feature-signature-to-regexp name)) |
169 (aset name (1- (length name)) ?\() ;; Match only to functions | 185 (aset name (1- (length name)) ?\() ;; Match only to functions |
170 name) | 186 name) |
217 (t | 233 (t |
218 (concat pat (char-to-string c)))) | 234 (concat pat (char-to-string c)))) |
219 i (1+ i))) | 235 i (1+ i))) |
220 (setq pat (concat prefix-info pat))))) | 236 (setq pat (concat prefix-info pat))))) |
221 | 237 |
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 | |
222 (defun c++-feature-tree-command-p (class-or-signature) | 244 (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." | 245 "Display definition of CLASS-OR-SIGNATURE if a signature and return t, else return nil." |
224 (if (c++-routine-p class-or-signature) | 246 (if (c++-routine-p class-or-signature) |
225 (progn | 247 (progn |
226 (if (br-in-browser) (br-to-view-window)) | 248 (if (br-in-browser) (br-to-view-window)) |
227 (br-feature-found-p (br-feature-file class-or-signature) | 249 (br-feature-found-p (br-feature-file class-or-signature) |
228 class-or-signature)))) | 250 class-or-signature)))) |
229 | 251 |
230 (defun c++-list-features (class &optional indent) | 252 (defun c++-list-features (class &optional indent) |
231 "Return sorted list of C++ feature tags lexically defined in CLASS." | 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." | |
232 (let ((obuf (current-buffer)) | 257 (let ((obuf (current-buffer)) |
233 (features) | 258 (features) |
234 (class-tag (concat "\n" class c++-type-tag-separator)) | 259 (class-tag (concat "\n" class c++-type-tag-separator)) |
235 feature) | 260 feature) |
236 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file)) | 261 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file)) |
244 (while (search-forward class-tag nil t) | 269 (while (search-forward class-tag nil t) |
245 (setq feature (br-feature-current)) | 270 (setq feature (br-feature-current)) |
246 (or (string-match friend-regexp feature) | 271 (or (string-match friend-regexp feature) |
247 (setq features (cons feature features)))))) | 272 (setq features (cons feature features)))))) |
248 (set-buffer obuf) | 273 (set-buffer obuf) |
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. | |
249 (c++-sort-features (nreverse features)))) | 276 (c++-sort-features (nreverse features)))) |
250 | 277 |
251 (defun c++-routine-p (str) | 278 (defun c++-routine-p (str) |
252 (string-match "([^\)]*)" str)) | 279 (string-match "([^\)]*)" str)) |
253 | 280 |
428 (defun c++-feature-def-p () | 455 (defun c++-feature-def-p () |
429 "Return nil unless point is within a member definition. | 456 "Return nil unless point is within a member definition. |
430 Commented member definitions also return nil. | 457 Commented member definitions also return nil. |
431 Leaves point at start of statement for visual clarity." | 458 Leaves point at start of statement for visual clarity." |
432 (c++-skip-to-statement) | 459 (c++-skip-to-statement) |
433 (save-excursion | 460 (and (not (c-within-comment-p)) |
434 (and (not (c-within-comment-p)) | 461 (save-excursion (beginning-of-line) |
435 (save-excursion (beginning-of-line) | 462 (not (looking-at "[ \t]*//"))) |
436 (not (looking-at "[ \t]*//"))) | 463 (not (looking-at c++-class-decl)) |
437 (not (looking-at c++-class-decl)) | 464 (looking-at (concat c++-at-feature-regexp "[{;,]")) |
438 (looking-at (concat c++-at-feature-regexp "[{;,]")) | 465 (let ((end-punct)) |
439 (let ((end-punct)) | 466 (or (= ?\{ (setq end-punct (char-after (1- (match-end 0))))) |
440 (or (= ?{ | 467 ;; If ends with a '[;,]' then must not have func parens |
441 (setq end-punct (save-excursion (goto-char (match-end 0)) | 468 ;; nor simply be a scoped name in order to be a def. |
442 (preceding-char)))) | 469 ;; If it begins with 'virtual', ends with "= 0" and has |
443 ;; If ends with a '[;,]' then must not have func parens | 470 ;; parens, then is a deferred virtual function declaration. |
444 ;; nor simply be a scoped name in order to be a def. | 471 (if (match-end c++-feature-parens-grpn) |
445 ;; If it begins with 'virtual', ends with "= 0" and has | 472 (save-restriction |
446 ;; parens, then is a deferred virtual function declaration. | 473 (narrow-to-region (match-beginning 0) (match-end 0)) |
447 (if (match-end c++-feature-parens-grpn) | 474 (if (looking-at |
448 (save-restriction | 475 "\\s *\\<virtual\\>[^;{}]+=[ \t]*0[ \t]*[,;]") |
449 (narrow-to-region (match-beginning 0) (match-end 0)) | 476 (progn (message "(OO-Browser): Pure virtual function, definition deferred to descendants.") |
450 (if (looking-at | 477 t))) |
451 "\\(^\\|[ \t]+\\)virtual[ \t].*=[ \t]*0[ \t]*[,;]") | 478 (or (null (match-end c++-feature-scope-grpn)) |
452 (progn (message "(OO-Browser): Pure virtual function, definition deferred to descendants.") | 479 (not (equal (concat |
453 t))) | 480 (buffer-substring |
454 (or (null (match-end c++-feature-scope-grpn)) | 481 (match-beginning c++-feature-scope-grpn) |
455 (not (equal (concat | 482 (match-end c++-feature-name-grpn)) |
456 (buffer-substring | 483 (char-to-string end-punct)) |
457 (match-beginning c++-feature-scope-grpn) | 484 (buffer-substring (match-beginning 0) |
458 (match-end c++-feature-name-grpn)) | 485 (match-end 0)))))))))) |
459 (char-to-string end-punct)) | |
460 (buffer-substring (match-beginning 0) | |
461 (match-end 0))))))))))) | |
462 | 486 |
463 (defun c++-feature-def-pat () | 487 (defun c++-feature-def-pat () |
464 "Return (list <feature-def-pat> <feature-class> <feature-name>) associated with declaration at point." | 488 "Return (list <feature-def-pat> <feature-class> <feature-name>) associated with declaration at point." |
465 (and (c++-skip-to-statement) | 489 (and (c++-skip-to-statement) |
466 (c++-feature-decl) | 490 (c++-feature-decl) |
595 pre-member-regexp)) | 619 pre-member-regexp)) |
596 (br-regexp-quote class) | 620 (br-regexp-quote class) |
597 (, post-member-regexp)))) | 621 (, post-member-regexp)))) |
598 class member-name))))) | 622 class member-name))))) |
599 | 623 |
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 | |
600 (defun c++-feature-lessp (routine1 routine2) | 651 (defun c++-feature-lessp (routine1 routine2) |
601 (string-lessp (c++-feature-signature-to-name routine1) | 652 (string-lessp (c++-feature-signature-to-name routine1) |
602 (c++-feature-signature-to-name routine2))) | 653 (c++-feature-signature-to-name routine2))) |
603 | 654 |
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 | |
604 (defun c++-feature-matches (regexp) | 679 (defun c++-feature-matches (regexp) |
605 "Return an unsorted list of feature tags whose names match in part or whole to REGEXP." | 680 "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 | 681 ^ and $ characters may be used to match to the beginning and end of a feature name, |
607 (setq regexp | 682 respectively." |
608 (concat (format "^[^%s \n]+%s%s " | 683 (c++-feature-map-tags 'br-feature-current regexp)) |
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 | 684 |
626 (defun c++-feature-normalize (routine class name &optional friend-flag) | 685 (defun c++-feature-normalize (routine class name &optional friend-flag) |
627 (setq class (br-delete-space class) | 686 (setq class (br-delete-space class) |
628 name (c++-feature-add-prefix name class routine friend-flag) | 687 name (c++-feature-add-prefix name class routine friend-flag) |
629 routine (concat class c++-type-tag-separator | 688 routine (concat class c++-type-tag-separator |
666 (substring signature 0 (match-beginning 0))) | 725 (substring signature 0 (match-beginning 0))) |
667 ((string-match "\\([^ \t]+\\)::" signature) | 726 ((string-match "\\([^ \t]+\\)::" signature) |
668 (substring signature (match-beginning 1) (match-end 1))) | 727 (substring signature (match-beginning 1) (match-end 1))) |
669 (t ""))) | 728 (t ""))) |
670 | 729 |
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) | 730 (defun c++-files-with-source (class) |
699 "Use CLASS to compute set of files that match to a C++ source file regexp. | 731 "Use CLASS to compute set of files that match to a C++ source file regexp. |
700 Return as a list." | 732 Return as a list." |
701 (let ((file (if class (br-class-path class) buffer-file-name))) | 733 (let ((file (if class (br-class-path class) buffer-file-name))) |
702 (and file | 734 (and file |
714 (let ((obuf (current-buffer))) | 746 (let ((obuf (current-buffer))) |
715 (prog1 | 747 (prog1 |
716 (if (and br-feature-tags-file | 748 (if (and br-feature-tags-file |
717 (file-exists-p br-feature-tags-file) | 749 (file-exists-p br-feature-tags-file) |
718 (file-readable-p br-feature-tags-file)) | 750 (file-readable-p br-feature-tags-file)) |
719 (c++-feature-tags-lookup class-list ftr-pat other-win) | 751 (c++-feature-display class-list ftr-pat other-win) |
720 ;; Only works if features are in same directory as class def. | 752 ;; Only works if features are in same directory as class def. |
721 (c++-scan-ancestors-feature class-list ftr-pat other-win)) | 753 (c++-scan-ancestors-feature class-list ftr-pat other-win)) |
722 (set-buffer obuf)))) | 754 (set-buffer obuf)))) |
723 | 755 |
724 (defun c++-find-class-name () | 756 (defun c++-find-class-name () |