Mercurial > emacs
annotate lisp/progmodes/mantemp.el @ 78761:4a2bcaea1323
*** empty log message ***
author | Martin Rudalics <rudalics@gmx.at> |
---|---|
date | Wed, 12 Sep 2007 08:25:24 +0000 |
parents | c1ec1c8a8d2e |
children | a1342e6e097a f55f9811f5d7 |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
16879
diff
changeset
|
1 ;;; mantemp.el --- create manual template instantiations from g++ 2.7.2 output |
16878 | 2 |
75347 | 3 ;; Copyright (C) 1996, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
64699
629afbe74e61
Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents:
64085
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
16878 | 5 |
6 ;; Author: Tom Houlder <thoulder@icor.fr> | |
7 ;; Created: 10 Dec 1996 | |
8 ;; Keywords: g++, templates | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published | |
78234
c1ec1c8a8d2e
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77374
diff
changeset
|
14 ;; by the Free Software Foundation; either version 3, or (at your |
16878 | 15 ;; option) any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, but | |
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 ;; General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
16878 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; The following is a typical error message from g++ using STL (here | |
30 ;; with split lines): | |
31 ;; | |
32 ;; AFile.o(.text+0x2d5): undefined reference to | |
33 ;; `vector<double>::begin(void)' | |
34 ;; AFile.o(.text+0x2e7): undefined reference to | |
35 ;; `vector<double>::insert(double *, unsigned int, double const &)' | |
36 ;; AnotherFile.o(.text+0x226b8): undefined reference to | |
37 ;; `operator!=(rb_tree<basic_string<char>, pair<basic_string<char> | |
38 ;; const, AClass *>, select1st<pair<basic_string<char> const, AClass | |
39 ;; *>, basic_string<char> >, less<basic_string<char> > >::iterator | |
40 ;; const &, rb_tree<basic_string<char>, pair<basic_string<char> | |
41 ;; const, AClass *>, select1st<pair<basic_string<char> const, AClass | |
42 ;; *>, basic_string<char> >, less<basic_string<char> > >::iterator | |
43 ;; const &)' | |
44 ;; | |
45 ;; The message means that in the object file AFile.o there is one | |
46 ;; uninstantiated template class, vector<double>, and in AnotherFile.o | |
47 ;; there is one uninstantiated template function, operator!=(...). To | |
48 ;; turn this output into manual template instantiations, copy from the | |
49 ;; first name of an objective file (here this is AFile.o) to right | |
50 ;; after the very last `'' of the output. Put this in a buffer and | |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
51 ;; call `mantemp-make-mantemps-buffer' with the point in the buffer. |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
52 ;; You can also use `mantemp-make-mantemps-region' directly on the |
16878 | 53 ;; region if the output is already in Emacs. |
54 ;; | |
55 ;; The resulting buffer yields (connect the three output lines above | |
56 ;; if you want to try): | |
57 ;; | |
58 ;; template operator!=(rb_tree<basic_string<char>, | |
59 ;; pair<basic_string<char> const, AClass *>, | |
60 ;; select1st<pair<basic_string<char> const, AClass *>, | |
61 ;; basic_string<char> >, less<basic_string<char> > >::iterator const | |
62 ;; &, rb_tree<basic_string<char>, pair<basic_string<char> const, | |
63 ;; AClass *>, select1st<pair<basic_string<char> const, AClass *>, | |
64 ;; basic_string<char> >, less<basic_string<char> > >::iterator const | |
65 ;; &); | |
66 ;; template class vector<double>; | |
67 ;; | |
68 ;; which can be included in your C++ program. However, its probably | |
69 ;; better to include the necessary header files in the buffer and | |
70 ;; compile it as a stand alone implementation file. | |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
71 ;; |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
72 ;; Sometimes, an uninstantiated template may cause a message like the |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
73 ;; following |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
74 ;; |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
75 ;; main.cc:66: invalid use of undefined type |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
76 ;; `struct valarray<double,arrayminusopclass<double,c_array<double> > >' |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
77 ;; |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
78 ;; Follow the same procedure as above and the line is changed to |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
79 ;; |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
80 ;; template struct valarray<double, |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
81 ;; arrayminusopclass<double,c_array<double> > >; |
16878 | 82 |
83 ;; g++ does not output the templates that are needed by the | |
84 ;; uninstantiated templates. Therefore you will often get new error | |
85 ;; messages after the first instantiations have been included and you | |
86 ;; must repeat the operation. | |
87 | |
88 ;;; Code: | |
89 | |
90 (defun mantemp-remove-comments () | |
91 "Remove g++ comments surrounding each function and member function." | |
92 (save-excursion | |
93 (goto-char (point-min)) | |
94 (message "Removing comments") | |
95 (while (re-search-forward "^[A-z\.()+0-9: ]*`\\|'.*$" nil t) | |
96 (replace-match "")))) | |
97 | |
98 (defun mantemp-remove-memfuncs () | |
99 "Remove member function extensions so that only class names remain." | |
100 (save-excursion | |
101 ;; Remove conversion operator extensions. | |
102 (goto-char (point-min)) | |
103 (message "Removing member function extensions") | |
104 (while (re-search-forward | |
105 "^[A-z :&*<>~=,0-9+]*>::operator " nil t nil) | |
106 (progn | |
107 (backward-char 11) | |
77374
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
108 (delete-region (point) (line-end-position)))) |
16878 | 109 ;; Remove other member function extensions. |
110 (goto-char (point-min)) | |
111 (message "Removing member function extensions") | |
112 (while (re-search-forward "^[A-z :&*<>~=,0-9+]*>::" nil t nil) | |
113 (progn | |
114 (backward-char 2) | |
77374
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
115 (delete-region (point) (line-end-position)))))) |
16878 | 116 |
117 (defun mantemp-sort-and-unique-lines () | |
118 "Eliminate all consecutive duplicate lines in the buffer." | |
119 (save-excursion | |
120 (message "Sorting") | |
121 (sort-regexp-fields nil "^.*$" "\\&" | |
122 (point-min) | |
123 (point-max)) | |
124 (goto-char (point-min)) | |
125 (message "Removing consecutive duplicate lines") | |
126 (while (re-search-forward "\\(^.+\\)\n\\1" nil t nil) | |
127 (progn | |
128 (forward-line -1) | |
129 (beginning-of-line) | |
77374
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
130 (delete-region (point) (progn (forward-line 1) (point))))))) |
16878 | 131 |
132 (defun mantemp-insert-cxx-syntax () | |
133 "Insert C++ syntax around each template class and function. | |
134 Insert 'template class' for classes, 'template' for | |
135 functions and add the statement delimiter `;' at the end of | |
136 the lines." | |
137 (save-excursion | |
138 ;; Insert ';' at the end of each nonempty line. | |
139 (goto-char (point-min)) | |
140 (message "Inserting `;' at the ends") | |
141 (while (re-search-forward ".+$" nil t) | |
142 (progn | |
143 (insert ";") | |
144 (if (not (equal (point) (point-max))) | |
145 (forward-char)))) | |
146 ;; We first insert 'template class' at each nonempty line and | |
147 ;; subsequently remove 'class' for functions so we don't need to | |
148 ;; both scan for classes and functions. | |
149 (goto-char (point-min)) | |
150 (message "Inserting 'template class' for classes") | |
151 (while (re-search-forward "^.+" nil t) | |
152 (progn | |
153 (beginning-of-line) | |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
154 (if (looking-at "struct[\\t ]+\\|class[\\t ]+") |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
155 (insert "template ") |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
156 (insert "template class ")))) |
16878 | 157 (goto-char (point-min)) |
158 (message "Inserting 'template' for functions") | |
159 (while (re-search-forward | |
160 "^template class [A-z :&*<>~=,0-9+!]*(" nil t nil) | |
161 (progn | |
162 (beginning-of-line) | |
163 (forward-word 1) | |
77374
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
164 (delete-region (point) (progn (forward-word 1) (point))))))) |
16878 | 165 |
166 (defun mantemp-make-mantemps () | |
167 "Gathering interface to the functions modifying the buffer." | |
168 (mantemp-remove-comments) | |
169 (mantemp-remove-memfuncs) | |
170 (mantemp-sort-and-unique-lines) | |
171 (mantemp-insert-cxx-syntax)) | |
172 | |
173 (defun mantemp-make-mantemps-buffer () | |
174 "Make manual template instantiations from g++ error messages in the buffer. | |
175 Scan the output of g++ describing uninstantiated template | |
176 classes and functions and generate the corresponding C++ | |
177 manual template instantiations. The output is supposed to | |
178 have been placed in the current buffer and the current buffer | |
179 should otherwise be empty. | |
180 | |
181 See the commentary in file mantemp.el for an example of use." | |
182 (interactive) | |
183 (mantemp-make-mantemps) | |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
184 (message "Done")) |
16878 | 185 |
186 (defun mantemp-make-mantemps-region () | |
187 "Make manual template instantiations from g++ error messages in the region. | |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
188 This function does the same thing as `mantemp-make-mantemps-buffer', |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
189 but operates on the region." |
16878 | 190 (interactive) |
191 (let ((cur-buf (current-buffer)) | |
77374
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
192 (mantemp-buffer (generate-new-buffer "*mantemp*")) |
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
193 (str (buffer-substring (mark) (point)))) |
16878 | 194 ;; Copy the region to a temporary buffer, make the C++ code there |
195 ;; and copy the result back to the current buffer. | |
196 (set-buffer mantemp-buffer) | |
77374
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
197 (insert str) |
16878 | 198 (mantemp-make-mantemps) |
77374
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
199 (setq str (buffer-string)) |
16878 | 200 (set-buffer cur-buf) |
77374
74462e953a2c
(mantemp-make-mantemps-region)
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
201 (insert str) |
16878 | 202 (kill-buffer mantemp-buffer)) |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
203 (message "Done")) |
16878 | 204 |
205 (provide 'mantemp) | |
206 | |
52401 | 207 ;;; arch-tag: 49794712-3b1b-4baa-9785-39556cb52c94 |
16878 | 208 ;;; mantemp.el ends here |