Mercurial > emacs
annotate lisp/progmodes/mantemp.el @ 21930:b84bfe98263d
* progmodes/compile.el (compilation-directory-stack): Doc fix.
(compilation-mode): Accept optional parameter and initialize
mode-name from it.
(compile-internal): Pass name-of-mode to compilation-mode. Don't
set mode-name here.
(compilation-minor-mode): Don't let mode-line-process change.
(compilation-next-error-locus): Use forward-char instead of
move-to-column.
(compilation-parse-errors): Set default-directory from head of
compilation-directory-stack.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Mon, 04 May 1998 08:35:40 +0000 |
parents | b020aae1fa01 |
children | b174db545cfd |
rev | line source |
---|---|
16878 | 1 ;;; mantemp.el --- Create manual template instantiations from g++ 2.7.2 output. |
2 | |
3 ;; Copyright (C) 1996 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Tom Houlder <thoulder@icor.fr> | |
6 ;; Created: 10 Dec 1996 | |
7 ;; Keywords: g++, templates | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published | |
13 ;; by the Free Software Foundation; either version 2, or (at your | |
14 ;; option) any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; The following is a typical error message from g++ using STL (here | |
29 ;; with split lines): | |
30 ;; | |
31 ;; AFile.o(.text+0x2d5): undefined reference to | |
32 ;; `vector<double>::begin(void)' | |
33 ;; AFile.o(.text+0x2e7): undefined reference to | |
34 ;; `vector<double>::insert(double *, unsigned int, double const &)' | |
35 ;; AnotherFile.o(.text+0x226b8): undefined reference to | |
36 ;; `operator!=(rb_tree<basic_string<char>, pair<basic_string<char> | |
37 ;; const, AClass *>, select1st<pair<basic_string<char> const, AClass | |
38 ;; *>, basic_string<char> >, less<basic_string<char> > >::iterator | |
39 ;; const &, rb_tree<basic_string<char>, pair<basic_string<char> | |
40 ;; const, AClass *>, select1st<pair<basic_string<char> const, AClass | |
41 ;; *>, basic_string<char> >, less<basic_string<char> > >::iterator | |
42 ;; const &)' | |
43 ;; | |
44 ;; The message means that in the object file AFile.o there is one | |
45 ;; uninstantiated template class, vector<double>, and in AnotherFile.o | |
46 ;; there is one uninstantiated template function, operator!=(...). To | |
47 ;; turn this output into manual template instantiations, copy from the | |
48 ;; first name of an objective file (here this is AFile.o) to right | |
49 ;; 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
|
50 ;; 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
|
51 ;; You can also use `mantemp-make-mantemps-region' directly on the |
16878 | 52 ;; region if the output is already in Emacs. |
53 ;; | |
54 ;; The resulting buffer yields (connect the three output lines above | |
55 ;; if you want to try): | |
56 ;; | |
57 ;; template operator!=(rb_tree<basic_string<char>, | |
58 ;; pair<basic_string<char> const, AClass *>, | |
59 ;; select1st<pair<basic_string<char> const, AClass *>, | |
60 ;; basic_string<char> >, less<basic_string<char> > >::iterator const | |
61 ;; &, rb_tree<basic_string<char>, pair<basic_string<char> const, | |
62 ;; AClass *>, select1st<pair<basic_string<char> const, AClass *>, | |
63 ;; basic_string<char> >, less<basic_string<char> > >::iterator const | |
64 ;; &); | |
65 ;; template class vector<double>; | |
66 ;; | |
67 ;; which can be included in your C++ program. However, its probably | |
68 ;; better to include the necessary header files in the buffer and | |
69 ;; 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
|
70 ;; |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
71 ;; 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
|
72 ;; following |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
73 ;; |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
74 ;; 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
|
75 ;; `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
|
76 ;; |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
77 ;; 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
|
78 ;; |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
79 ;; template struct valarray<double, |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
80 ;; arrayminusopclass<double,c_array<double> > >; |
16878 | 81 |
82 ;; g++ does not output the templates that are needed by the | |
83 ;; uninstantiated templates. Therefore you will often get new error | |
84 ;; messages after the first instantiations have been included and you | |
85 ;; must repeat the operation. | |
86 | |
87 ;;; Code: | |
88 | |
89 (defun mantemp-remove-comments () | |
90 "Remove g++ comments surrounding each function and member function." | |
91 (save-excursion | |
92 (goto-char (point-min)) | |
93 (message "Removing comments") | |
94 (while (re-search-forward "^[A-z\.()+0-9: ]*`\\|'.*$" nil t) | |
95 (replace-match "")))) | |
96 | |
97 (defun mantemp-remove-memfuncs () | |
98 "Remove member function extensions so that only class names remain." | |
99 (save-excursion | |
100 ;; Remove conversion operator extensions. | |
101 (goto-char (point-min)) | |
102 (message "Removing member function extensions") | |
103 (while (re-search-forward | |
104 "^[A-z :&*<>~=,0-9+]*>::operator " nil t nil) | |
105 (progn | |
106 (backward-char 11) | |
107 (kill-line))) | |
108 ;; Remove other member function extensions. | |
109 (goto-char (point-min)) | |
110 (message "Removing member function extensions") | |
111 (while (re-search-forward "^[A-z :&*<>~=,0-9+]*>::" nil t nil) | |
112 (progn | |
113 (backward-char 2) | |
114 (kill-line))))) | |
115 | |
116 (defun mantemp-sort-and-unique-lines () | |
117 "Eliminate all consecutive duplicate lines in the buffer." | |
118 (save-excursion | |
119 (message "Sorting") | |
120 (sort-regexp-fields nil "^.*$" "\\&" | |
121 (point-min) | |
122 (point-max)) | |
123 (goto-char (point-min)) | |
124 (message "Removing consecutive duplicate lines") | |
125 (while (re-search-forward "\\(^.+\\)\n\\1" nil t nil) | |
126 (progn | |
127 (forward-line -1) | |
128 (beginning-of-line) | |
129 (kill-line 1))))) | |
130 | |
131 (defun mantemp-insert-cxx-syntax () | |
132 "Insert C++ syntax around each template class and function. | |
133 Insert 'template class' for classes, 'template' for | |
134 functions and add the statement delimiter `;' at the end of | |
135 the lines." | |
136 (save-excursion | |
137 ;; Insert ';' at the end of each nonempty line. | |
138 (goto-char (point-min)) | |
139 (message "Inserting `;' at the ends") | |
140 (while (re-search-forward ".+$" nil t) | |
141 (progn | |
142 (insert ";") | |
143 (if (not (equal (point) (point-max))) | |
144 (forward-char)))) | |
145 ;; We first insert 'template class' at each nonempty line and | |
146 ;; subsequently remove 'class' for functions so we don't need to | |
147 ;; both scan for classes and functions. | |
148 (goto-char (point-min)) | |
149 (message "Inserting 'template class' for classes") | |
150 (while (re-search-forward "^.+" nil t) | |
151 (progn | |
152 (beginning-of-line) | |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
153 (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
|
154 (insert "template ") |
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
155 (insert "template class ")))) |
16878 | 156 (goto-char (point-min)) |
157 (message "Inserting 'template' for functions") | |
158 (while (re-search-forward | |
159 "^template class [A-z :&*<>~=,0-9+!]*(" nil t nil) | |
160 (progn | |
161 (beginning-of-line) | |
162 (forward-word 1) | |
163 (kill-word 1))))) | |
164 | |
165 (defun mantemp-make-mantemps () | |
166 "Gathering interface to the functions modifying the buffer." | |
167 (mantemp-remove-comments) | |
168 (mantemp-remove-memfuncs) | |
169 (mantemp-sort-and-unique-lines) | |
170 (mantemp-insert-cxx-syntax)) | |
171 | |
172 (defun mantemp-make-mantemps-buffer () | |
173 "Make manual template instantiations from g++ error messages in the buffer. | |
174 Scan the output of g++ describing uninstantiated template | |
175 classes and functions and generate the corresponding C++ | |
176 manual template instantiations. The output is supposed to | |
177 have been placed in the current buffer and the current buffer | |
178 should otherwise be empty. | |
179 | |
180 See the commentary in file mantemp.el for an example of use." | |
181 (interactive) | |
182 (mantemp-make-mantemps) | |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
183 (message "Done")) |
16878 | 184 |
185 (defun mantemp-make-mantemps-region () | |
186 "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
|
187 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
|
188 but operates on the region." |
16878 | 189 (interactive) |
190 (let ((cur-buf (current-buffer)) | |
191 (mantemp-buffer (generate-new-buffer "*mantemp*"))) | |
192 ;; Copy the region to a temporary buffer, make the C++ code there | |
193 ;; and copy the result back to the current buffer. | |
194 (kill-region (mark) (point)) | |
195 (set-buffer mantemp-buffer) | |
196 (yank) | |
197 (mantemp-make-mantemps) | |
198 (kill-region (point-min) (point-max)) | |
199 (set-buffer cur-buf) | |
200 (yank) | |
201 (kill-buffer mantemp-buffer)) | |
16879
b020aae1fa01
(mantemp-insert-cxx-syntax): Recognize non-class templates.
Richard M. Stallman <rms@gnu.org>
parents:
16878
diff
changeset
|
202 (message "Done")) |
16878 | 203 |
204 (provide 'mantemp) | |
205 | |
206 ;;; mantemp.el ends here |