annotate lisp/cedet/srecode/expandproto.el @ 108116:8cf84fb217cc

merge trunk
author Kenichi Handa <handa@etlken>
date Mon, 26 Apr 2010 10:22:02 +0900
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 ;;; srecode/expandproto.el --- Expanding prototypes.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105842
diff changeset
3 ;; Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
4
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
11 ;; the Free Software Foundation, either version 3 of the License, or
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
12 ;; (at your option) any later version.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 ;; GNU General Public License for more details.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
22 ;;; Commentary:
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24 ;; Methods for expanding a prototype into an implementation.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 (require 'ring)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 (require 'semantic)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 (require 'semantic/analyze)
105260
bbd7017a25d9 CEDET (development tools) package merged.
Chong Yidong <cyd@stupidchicken.com>
parents: 104498
diff changeset
29 (require 'semantic/senator)
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 (require 'srecode/insert)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 (require 'srecode/dictionary)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 (declare-function semantic-brute-find-tag-by-attribute-value "semantic/find")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 ;;; Code:
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36 (defcustom srecode-expandproto-template-file-alist
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 '( ( c++-mode . "srecode-expandproto-cpp.srt" )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 ;; @todo - Make this variable auto-generated from the Makefile.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 "Associate template files for expanding prototypes to a major mode."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 :group 'srecode
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 :type '(repeat (cons (sexp :tag "Mode")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 (sexp :tag "Filename"))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44 ))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 ;;;###autoload
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 (defun srecode-insert-prototype-expansion ()
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 "Insert get/set methods for the current class."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 (interactive)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 (srecode-load-tables-for-mode major-mode)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 (srecode-load-tables-for-mode major-mode
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 srecode-expandproto-template-file-alist)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 (if (not (srecode-table))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 (error "No template table found for mode %s" major-mode))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 (let ((proto
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 ;; Step 1: Find the prototype, or prototype list to expand.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 (srecode-find-prototype-for-expansion)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62 (if (not proto)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63 (error "Could not find prototype to expand"))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
65 ;; Step 2: Insert implementations of the prototypes.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 ))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 (defun srecode-find-prototype-for-expansion ()
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 "Find a prototype to use for expanding into an implementation."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 ;; We may find a prototype tag in one of several places.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 ;; Search in order of logical priority.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74 (let ((proto nil)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 ;; 1) A class full of prototypes under point.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 (let ((tag (semantic-current-tag)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79 (when tag
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 (when (not (semantic-tag-of-class-p tag 'type))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81 (setq tag (semantic-current-tag-parent))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 (when (and tag (semantic-tag-of-class-p tag 'type))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 ;; If the current class has prototype members, then
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84 ;; we will do the whole class!
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 (require 'semantic/find)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 (if (semantic-brute-find-tag-by-attribute-value
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87 :prototype t
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 (semantic-tag-type-members tag))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 (setq proto tag)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92 ;; 2) A prototype under point.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 (when (not proto)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 (let ((tag (semantic-current-tag)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95 (when (and tag
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96 (and
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 (semantic-tag-of-class-p tag 'function)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 (semantic-tag-get-attribute tag :prototype)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 (setq proto tag))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101 ;; 3) A tag in the kill ring that is a prototype
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 (when (not proto)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103 (if (ring-empty-p senator-tag-ring)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104 nil ;; Not for us.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 (let ((tag (ring-ref senator-tag-ring 0))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 (when
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 (and tag
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 (or
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 (and
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111 (semantic-tag-of-class-p tag 'function)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 (semantic-tag-get-attribute tag :prototype))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 (and
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 (semantic-tag-of-class-p tag 'type)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115 (require 'semantic/find)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 (semantic-brute-find-tag-by-attribute-value
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 :prototype t
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118 (semantic-tag-type-members tag))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 (setq proto tag))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 )))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 proto))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124
105313
068b13ebb340 * cedet/srecode/expandproto.el: Fix provide statement.
Juanma Barranquero <lekktu@gmail.com>
parents: 105284
diff changeset
125 (provide 'srecode/expandproto)
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127 ;; Local variables:
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128 ;; generated-autoload-file: "loaddefs.el"
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129 ;; generated-autoload-load-name: "srecode/expandproto"
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 ;; End:
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131
105377
7f4c7f5c0eba Add arch tagline
Miles Bader <miles@gnu.org>
parents: 105313
diff changeset
132 ;; arch-tag: f0371b5f-9bec-46a1-9b5d-8dff0e897426
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
133 ;;; srecode/expandproto.el ends here