1 ;;; cit-cpp.el --- C++ specific things for our integ test.
3 ;; Copyright (C) 2008, 2009, 2010, 2012 Eric M. Ludlam
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
7 ;; This program is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation; either version 2, or (at
10 ;; your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
24 ;; C++ specific code for the cedet integration tests.
25 ;; Add some C code too!
29 (defvar cit-header-cpp-tags
31 (semantic-tag-new-type
34 (semantic-tag "public" 'label
)
35 (semantic-tag-new-function
36 "foo" '("foo" type
(:type
"class"))
37 (list (semantic-tag-new-variable "f" "int"))
39 :code
" Field1 = f; ")
40 (semantic-tag-new-function
41 "foo" "void" nil
:destructor-flag t
)
42 (semantic-tag-new-function
43 "doSomethingPublic" "void"
44 (list (semantic-tag-new-variable "ctxt" "int")
45 (semantic-tag-new-variable "thing" "char"
49 (semantic-tag-new-function
51 (list (semantic-tag-new-variable "f" "int"))
53 (semantic-tag-new-function
56 (semantic-tag "protected" 'label
)
57 (semantic-tag-new-function
58 "doSomethingProtected" "void"
59 (list (semantic-tag-new-variable "ctxt" "int")
60 (semantic-tag-new-variable "thing" "char"
64 (semantic-tag "private" 'label
)
65 (semantic-tag-new-variable
70 "Tags to be inserted into a header file.")
72 (defvar cit-src-cpp-tags
74 (semantic-tag-new-include "stdio.h" nil
)
75 (semantic-tag-new-include "foo.hpp" nil
)
76 (semantic-tag-new-function
77 "doSomethingPublic" "void"
78 (list (semantic-tag-new-variable "ctxt" "int")
79 (semantic-tag-new-variable "thing" "char"
84 if(getField1() == 1) {
85 // Call doSomethingProtected <== multi-hit for grep, not for global.
86 doSomethingProtected(ctxt,thing);
88 (semantic-tag-new-function
90 (list (semantic-tag-new-variable "f" "int"))
92 :code
" Field1 = f;\n")
93 (semantic-tag-new-function
96 :code
" return Field1;\n")
97 (semantic-tag-new-function
98 "doSomethingProtected" "void"
99 (list (semantic-tag-new-variable "ctxt" "int")
100 (semantic-tag-new-variable "thing" "char"
104 :code
" printf(\"%s\\n\",thing);\n")
106 "Tags to be inserted into a source file.")
108 (defvar cit-plain-c-tags
110 (semantic-tag-new-include "string.h" nil
)
111 (semantic-tag-new-function
113 (list (semantic-tag-new-variable "argc" "int")
114 (semantic-tag-new-variable "argv" "char"
117 :code
" int myInt = 0;
118 char *myStr = strdup(\"MOOSE\");
121 "Tags to be inserted into plain.c.")
123 (defvar cit-main-cpp-tags
125 (semantic-tag-new-include "foo.hpp" nil
)
126 (semantic-tag-new-include "string.h" nil
)
127 (semantic-tag-new-function
129 (list (semantic-tag-new-variable "argc" "int")
130 (semantic-tag-new-variable "argv" "char"
133 :code
" foo myFoo(2);
134 char *myStr = strdup(\"MOOSE\");
135 myFoo.doSomethingPublic(1,myStr);
138 "Tags to be inserted into main.")
140 (defvar cit-symref-operations
141 '( "doSomethingProtected" "renameSomething" )
142 "A set of symref operations based on the tags defined here.
143 The symref test (in cit-symref.el) will use these operations
144 to test they symbol reference system in C++.")
146 (defun cit-srecode-fill-cpp (make-type)
147 "Fill up a base set of files with some base tags.
148 MAKE-TYPE is the type of make process to use."
150 ;; 2 b) Test various templates.
152 (cit-srecode-fill-with-stuff "include/foo.hpp" cit-header-cpp-tags
)
153 (ede-new make-type
"Includes")
154 ;; 1 e) Tell EDE where the srcs are
155 (ede-new-target "Includes" "miscellaneous" "n")
156 (ede-add-file "Includes")
158 (cit-srecode-fill-with-stuff "src/foo.cpp" cit-src-cpp-tags
)
159 (ede-new make-type
"Src")
160 ;; 1 e) Tell EDE where the srcs are
161 (ede-new-target "Prog" "program" "n")
162 (ede-add-file "Prog")
164 (cit-srecode-fill-with-stuff "src/main.cpp" cit-main-cpp-tags
)
165 ;; 1 e) Tell EDE where the srcs are
166 (ede-add-file "Prog")
168 ;; Have some plain C code too to test the C code generator
169 (cit-srecode-fill-with-stuff "src/plain.c" cit-plain-c-tags
)
170 (ede-new-target "Plain" "program" "n")
171 (ede-add-file "Plain")
173 (let ((p (ede-current-project)))
174 (if (string= make-type
"Automake")
175 (oset p
:variables
'( ( "AM_CPPFLAGS" .
"-I../include") ))
176 (oset p
:variables
'( ( "CPPFLAGS" .
"-I../include") )))
177 (ede-commit-project p
)
180 ;; 1 g) build the sources.
181 (cit-compile-and-wait)
183 ;; 1 g.1) Run the compiled program. (Test for MOOSE output.)
184 (find-file (cit-file "src/main.cpp"))
185 (cit-run-target "./Prog")
188 (defun cit-remove-add-to-project-cpp ()
189 "Remve foo.cpp from the current project. Add in a new generated file."
191 (find-file (cit-file "src/foo.cpp"))
194 (kill-buffer (current-buffer))
195 (delete-file (cit-file "src/foo.cpp"))
196 (delete-file (cit-file "src/foo.o"))
199 (cit-srecode-fill-with-stuff "src/bar.cpp" cit-src-cpp-tags
)
200 (ede-add-file "Prog")
202 ;; 1 g) build the sources.
203 ;; Direct compile to test that make fails properly.
204 (compile ede-make-command
)
206 (cit-wait-for-compilation)
207 (cit-check-compilation-for-error t
) ;; That should have errored.
209 (cit-compile-and-wait)
212 (defun cit-remove-and-do-shared-lib (make-type)
213 "Remove bar.cpp from the current project.
214 Create a new shared lib with bar.cpp in it.
215 Argument MAKE-TYPE is the type of make project to create."
216 (find-file (cit-file "src/bar.cpp"))
219 (kill-buffer (current-buffer))
220 (delete-file (cit-file "src/bar.cpp"))
221 (delete-file (cit-file "src/bar.o"))
223 ;; Create a new shared lib target, and add bar.cpp to it.
224 (find-file (cit-file "lib/bar.cpp"))
225 (cit-srecode-fill-with-stuff "lib/bar.cpp" cit-src-cpp-tags
)
226 (ede-new make-type
"Libs")
227 (ede-new-target "testlib" "sharedobject" "n")
228 (ede-add-file "testlib")
229 (let ((mt ede-object
))
230 (oset mt
:compiler
'ede-g
++-libtool-shared-compiler
)
231 (oset mt
:linker
'ede-g
++-linker-libtool
)
235 ;; 1 g) build the sources.
236 ;; Direct compile to test that make fails properly.
237 (compile ede-make-command
)
239 (cit-wait-for-compilation)
240 (cit-check-compilation-for-error t
) ;; that should have errored.
242 (let ((p (ede-current-project)))
243 (if (string= make-type
"Automake")
244 (oset p
:variables
'( ( "AM_CPPFLAGS" .
"-I../include") ))
245 (oset p
:variables
'( ( "CPPFLAGS" .
"-I../include") )))
246 (ede-commit-project p
)
249 ;; Flip back over to main, and add our new testlib.
251 (let* ((buffer (find-file (cit-file "src/main.cpp")))
253 (if (string= make-type
"Automake")
255 (oset mt
:ldflags
'("-L../lib"))
256 (oset mt
:ldlibs
'("testlib")))
258 (oset mt
:ldflags
'("../lib/bar.o"));;HACK for libtool!
260 (cit-compile-and-wait)
262 ;; Use the local libs version also to make sure it works.
263 (pop-to-buffer buffer
))
264 (let ((mt ede-object
))
265 (if (string= make-type
"Automake")
267 (oset mt
:ldlibs-local
'("../lib/libtestlib.la"))
268 (oset mt
:ldflags nil
)
269 (oset mt
:ldlibs nil
))
271 (oset mt
:ldflags
'("../lib/bar.o"));;HACK for libtool!
273 (cit-compile-and-wait)
277 ;;; cit-cpp.el ends here