* cedet/ede/system.el (ede-upload-html-documentation)
[bpt/emacs.git] / lisp / cedet / srecode / expandproto.el
CommitLineData
4d902e6f
CY
1;;; srecode/expandproto.el --- Expanding prototypes.
2
3;; Copyright (C) 2007 Free Software Foundation, Inc.
4
5;; Author: Eric M. Ludlam <eric@siege-engine.com>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22;;; Commentary:
23;;
24;; Methods for expanding a prototype into an implementation.
25
26(require 'ring)
27(require 'semantic)
28(require 'semantic/analyze)
29(require 'srecode/insert)
30(require 'srecode/dictionary)
31
32(declare-function semantic-brute-find-tag-by-attribute-value "semantic/find")
33
34;;; Code:
35(defcustom srecode-expandproto-template-file-alist
36 '( ( c++-mode . "srecode-expandproto-cpp.srt" )
37 )
38 ;; @todo - Make this variable auto-generated from the Makefile.
39 "Associate template files for expanding prototypes to a major mode."
40 :group 'srecode
41 :type '(repeat (cons (sexp :tag "Mode")
42 (sexp :tag "Filename"))
43 ))
44
45;;;###autoload
46(defun srecode-insert-prototype-expansion ()
47 "Insert get/set methods for the current class."
48 (interactive)
49
50 (srecode-load-tables-for-mode major-mode)
51 (srecode-load-tables-for-mode major-mode
52 srecode-expandproto-template-file-alist)
53
54 (if (not (srecode-table))
55 (error "No template table found for mode %s" major-mode))
56
57 (let ((proto
58 ;; Step 1: Find the prototype, or prototype list to expand.
59 (srecode-find-prototype-for-expansion)))
60
61 (if (not proto)
62 (error "Could not find prototype to expand"))
63
64 ;; Step 2: Insert implementations of the prototypes.
65
66
67 ))
68
69(defun srecode-find-prototype-for-expansion ()
70 "Find a prototype to use for expanding into an implementation."
71 ;; We may find a prototype tag in one of several places.
72 ;; Search in order of logical priority.
73 (let ((proto nil)
74 )
75
76 ;; 1) A class full of prototypes under point.
77 (let ((tag (semantic-current-tag)))
78 (when tag
79 (when (not (semantic-tag-of-class-p tag 'type))
80 (setq tag (semantic-current-tag-parent))))
81 (when (and tag (semantic-tag-of-class-p tag 'type))
82 ;; If the current class has prototype members, then
83 ;; we will do the whole class!
84 (require 'semantic/find)
85 (if (semantic-brute-find-tag-by-attribute-value
86 :prototype t
87 (semantic-tag-type-members tag))
88 (setq proto tag)))
89 )
90
91 ;; 2) A prototype under point.
92 (when (not proto)
93 (let ((tag (semantic-current-tag)))
94 (when (and tag
95 (and
96 (semantic-tag-of-class-p tag 'function)
97 (semantic-tag-get-attribute tag :prototype)))
98 (setq proto tag))))
99
100 ;; 3) A tag in the kill ring that is a prototype
101 (when (not proto)
102 (if (ring-empty-p senator-tag-ring)
103 nil ;; Not for us.
104 (let ((tag (ring-ref senator-tag-ring 0))
105 )
106 (when
107 (and tag
108 (or
109 (and
110 (semantic-tag-of-class-p tag 'function)
111 (semantic-tag-get-attribute tag :prototype))
112 (and
113 (semantic-tag-of-class-p tag 'type)
114 (require 'semantic/find)
115 (semantic-brute-find-tag-by-attribute-value
116 :prototype t
117 (semantic-tag-type-members tag))))
118 )
119 (setq proto tag))
120 )))
121
122 proto))
123
124(provide 'srecode-expandproto)
125
126;; Local variables:
127;; generated-autoload-file: "loaddefs.el"
128;; generated-autoload-feature: srecode/loaddefs
129;; generated-autoload-load-name: "srecode/expandproto"
130;; End:
131
132;;; srecode/expandproto.el ends here