Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "sal/config.h"
21 : :
22 : : #include "codemaker/commoncpp.hxx"
23 : :
24 : : #include "codemaker/options.hxx"
25 : : #include "codemaker/typemanager.hxx"
26 : : #include "codemaker/unotype.hxx"
27 : :
28 : : #include "osl/diagnose.h"
29 : : #include "registry/reader.hxx"
30 : : #include "registry/types.h"
31 : : #include "rtl/strbuf.hxx"
32 : : #include "rtl/string.hxx"
33 : : #include "rtl/ustring.hxx"
34 : : #include "sal/types.h"
35 : :
36 : : #include <vector>
37 : :
38 : : namespace codemaker { namespace cpp {
39 : :
40 : 139392 : rtl::OString scopedCppName(rtl::OString const & type, bool bNoNameSpace,
41 : : bool shortname)
42 : : {
43 : 139392 : char c('/');
44 : 139392 : sal_Int32 nPos = type.lastIndexOf( c );
45 [ + + ]: 139392 : if (nPos == -1) {
46 : 268 : nPos = type.lastIndexOf( '.' );
47 [ + - ]: 268 : if (nPos == -1)
48 : 268 : return type;
49 : :
50 : 0 : c = '.';
51 : : }
52 [ - + ]: 139124 : if (bNoNameSpace)
53 : 0 : return type.copy(nPos+1);
54 : :
55 : 139124 : rtl::OStringBuffer tmpBuf(type.getLength()*2);
56 : 139124 : nPos = 0;
57 [ + + ]: 706422 : do
58 : : {
59 [ + - ]: 706422 : tmpBuf.append("::");
60 [ + - ]: 706422 : tmpBuf.append(type.getToken(0, c, nPos));
61 : : } while( nPos != -1 );
62 : :
63 [ - + ]: 139124 : if (shortname) {
64 : 0 : rtl::OString s(tmpBuf.makeStringAndClear());
65 [ # # ]: 0 : if (s.indexOf("::com::sun::star") == 0)
66 : 0 : return s.replaceAt(0, 16, "css");
67 : : else
68 : 0 : return s;
69 : : }
70 : :
71 : 139392 : return tmpBuf.makeStringAndClear();
72 : : }
73 : :
74 : :
75 : 0 : rtl::OString translateUnoToCppType(
76 : : codemaker::UnoType::Sort sort, RTTypeClass typeClass,
77 : : rtl::OString const & nucleus, bool shortname)
78 : : {
79 : 0 : rtl::OStringBuffer buf;
80 [ # # ]: 0 : if (sort == codemaker::UnoType::SORT_COMPLEX) {
81 [ # # # # ]: 0 : if (typeClass == RT_TYPE_INTERFACE
[ # # ]
82 [ # # ][ # # ]: 0 : && nucleus == rtl::OString("com/sun/star/uno/XInterface"))
83 : : {
84 [ # # ]: 0 : buf.append(RTL_CONSTASCII_STRINGPARAM("::com::sun::star::uno::XInterface"));
85 : : } else {
86 : : //TODO: check that nucleus is a valid (UTF-8) identifier
87 [ # # ]: 0 : buf.append(nucleus);
88 : : }
89 : : } else {
90 : : static char const * const cppTypes[codemaker::UnoType::SORT_ANY + 1] = {
91 : : "void", "::sal_Bool", "::sal_Int8", "::sal_Int16", "::sal_uInt16",
92 : : "::sal_Int32", "::sal_uInt32", "::sal_Int64", "::sal_uInt64",
93 : : "float", "double", "::sal_Unicode", "::rtl::OUString",
94 : : "::com::sun::star::uno::Type", "::com::sun::star::uno::Any" };
95 [ # # ]: 0 : buf.append(cppTypes[sort]);
96 : : }
97 : :
98 [ # # ]: 0 : if (shortname) {
99 : 0 : rtl::OString s(buf.makeStringAndClear());
100 [ # # ]: 0 : if (s.indexOf("::com::sun::star") == 0)
101 : 0 : return s.replaceAt(0, 16, "css");
102 : : else
103 : 0 : return s;
104 : : }
105 : :
106 : 0 : return buf.makeStringAndClear();
107 : : }
108 : :
109 : 4862 : rtl::OString translateUnoToCppIdentifier(
110 : : rtl::OString const & unoIdentifier, rtl::OString const & prefix,
111 : : IdentifierTranslationMode transmode, rtl::OString const * forbidden)
112 : : {
113 [ + - + + : 650698 : if (// Keywords:
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + ]
[ + + + +
+ + + + -
+ + + ]
[ + + + + ]
[ + + ][ + +
+ + + + +
+ + - + +
+ - + + +
- + + + -
+ + + + +
- + + + -
+ + + + +
+ + + + -
+ + + + +
+ + + + +
+ + + - +
+ + + + +
+ + + + +
+ + + + +
+ + + - +
+ + + + +
+ - + - +
+ + + + +
+ + + + +
- + + + +
+ - + - +
+ + + + -
+ + + + +
+ + + + +
+ + + + +
+ + + ]
114 : 4862 : unoIdentifier == "asm"
115 : 4852 : || unoIdentifier == "auto"
116 : 4842 : || unoIdentifier == "bool"
117 : 4832 : || unoIdentifier == "break"
118 : 4822 : || unoIdentifier == "case"
119 : 4822 : || unoIdentifier == "catch"
120 : 4812 : || unoIdentifier == "char"
121 : 4812 : || unoIdentifier == "class"
122 : 4802 : || unoIdentifier == "const"
123 : : /* unoIdentifier == "const_cast" */
124 : 4802 : || unoIdentifier == "continue"
125 : 4792 : || unoIdentifier == "default"
126 : 4792 : || unoIdentifier == "delete"
127 : 4782 : || unoIdentifier == "do"
128 : 4772 : || unoIdentifier == "double"
129 : : /* unoIdentifier == "dynamic_cast" */
130 : 4772 : || unoIdentifier == "else"
131 : 4762 : || unoIdentifier == "enum"
132 : 4762 : || unoIdentifier == "explicit"
133 : 4752 : || unoIdentifier == "export"
134 : 4742 : || unoIdentifier == "extern"
135 : 4732 : || unoIdentifier == "false"
136 : 4722 : || unoIdentifier == "float"
137 : 4722 : || unoIdentifier == "for"
138 : 4712 : || unoIdentifier == "friend"
139 : 4702 : || unoIdentifier == "goto"
140 : 4692 : || unoIdentifier == "if"
141 : 4682 : || unoIdentifier == "inline"
142 : 4672 : || unoIdentifier == "int"
143 : 4662 : || unoIdentifier == "long"
144 : 4662 : || unoIdentifier == "mutable"
145 : 4652 : || unoIdentifier == "namespace"
146 : 4642 : || unoIdentifier == "new"
147 : 4632 : || unoIdentifier == "operator"
148 : 4622 : || unoIdentifier == "private"
149 : 4612 : || unoIdentifier == "protected"
150 : 4602 : || unoIdentifier == "public"
151 : 4592 : || unoIdentifier == "register"
152 : : /* unoIdentifier == "reinterpret_cast" */
153 : 4582 : || unoIdentifier == "return"
154 : 4572 : || unoIdentifier == "short"
155 : 4572 : || unoIdentifier == "signed"
156 : 4562 : || unoIdentifier == "sizeof"
157 : 4552 : || unoIdentifier == "static"
158 : : /* unoIdentifier == "static_cast" */
159 : 4542 : || unoIdentifier == "struct"
160 : 4542 : || unoIdentifier == "switch"
161 : 4542 : || unoIdentifier == "template"
162 : 4532 : || unoIdentifier == "this"
163 : 4522 : || unoIdentifier == "throw"
164 : 4512 : || unoIdentifier == "true"
165 : 4502 : || unoIdentifier == "try"
166 : 4492 : || unoIdentifier == "typedef"
167 : 4492 : || unoIdentifier == "typeid"
168 : 4482 : || unoIdentifier == "typename"
169 : 4472 : || unoIdentifier == "union"
170 : 4472 : || unoIdentifier == "unsigned"
171 : 4472 : || unoIdentifier == "using"
172 : 4462 : || unoIdentifier == "virtual"
173 : 4452 : || unoIdentifier == "void"
174 : 4452 : || unoIdentifier == "volatile"
175 : : /* unoIdentifier == "wchar_t" */
176 : 4442 : || unoIdentifier == "while"
177 : : // Alternative representations:
178 : 4432 : || unoIdentifier == "and"
179 : : /* unoIdentifier == "and_eq" */
180 : 4422 : || unoIdentifier == "bitand"
181 : 4412 : || unoIdentifier == "bitor"
182 : 4402 : || unoIdentifier == "compl"
183 : 4392 : || unoIdentifier == "not"
184 : : /* unoIdentifier == "not_eq" */
185 : 4382 : || unoIdentifier == "or"
186 : : /* unoIdentifier == "or_eq" */
187 : 4372 : || unoIdentifier == "xor"
188 : : /* unoIdentifier == "xor_eq" */
189 : : // Standard macros:
190 : : || (transmode != ITM_KEYWORDSONLY
191 : 4362 : && (unoIdentifier == "BUFSIZ"
192 : 4352 : || unoIdentifier == "CLOCKS_PER_SEC"
193 : 4342 : || unoIdentifier == "EDOM"
194 : 4332 : || unoIdentifier == "EOF"
195 : 4322 : || unoIdentifier == "ERANGE"
196 : 4312 : || unoIdentifier == "EXIT_FAILURE"
197 : 4302 : || unoIdentifier == "EXIT_SUCCESS"
198 : 4292 : || unoIdentifier == "FILENAME_MAX"
199 : 4282 : || unoIdentifier == "FOPEN_MAX"
200 : 4272 : || unoIdentifier == "HUGE_VAL"
201 : 4262 : || unoIdentifier == "LC_ALL"
202 : 4252 : || unoIdentifier == "LC_COLLATE"
203 : 4242 : || unoIdentifier == "LC_CTYPE"
204 : 4232 : || unoIdentifier == "LC_MONETARY"
205 : 4222 : || unoIdentifier == "LC_NUMERIC"
206 : 4212 : || unoIdentifier == "LC_TIME"
207 : 4202 : || unoIdentifier == "L_tmpnam"
208 : 4192 : || unoIdentifier == "MB_CUR_MAX"
209 : 4182 : || unoIdentifier == "NULL"
210 : 4172 : || unoIdentifier == "RAND_MAX"
211 : 4162 : || unoIdentifier == "SEEK_CUR"
212 : 4152 : || unoIdentifier == "SEEK_END"
213 : 4142 : || unoIdentifier == "SEEK_SET"
214 : 4132 : || unoIdentifier == "SIGABRT"
215 : 4122 : || unoIdentifier == "SIGFPE"
216 : 4112 : || unoIdentifier == "SIGILL"
217 : 4102 : || unoIdentifier == "SIGINT"
218 : 4092 : || unoIdentifier == "SIGSEGV"
219 : 4082 : || unoIdentifier == "SIGTERM"
220 : 4072 : || unoIdentifier == "SIG_DFL"
221 : 4062 : || unoIdentifier == "SIG_ERR"
222 : 4052 : || unoIdentifier == "SIG_IGN"
223 : 4042 : || unoIdentifier == "TMP_MAX"
224 : 4032 : || unoIdentifier == "WCHAR_MAX"
225 : 4022 : || unoIdentifier == "WCHAR_MIN"
226 : 4012 : || unoIdentifier == "WEOF"
227 : : /* unoIdentifier == "_IOFBF" */
228 : : /* unoIdentifier == "_IOLBF" */
229 : : /* unoIdentifier == "_IONBF" */
230 : 4002 : || unoIdentifier == "assert"
231 : 3992 : || unoIdentifier == "errno"
232 : 3982 : || unoIdentifier == "offsetof"
233 : 3972 : || unoIdentifier == "setjmp"
234 : 3962 : || unoIdentifier == "stderr"
235 : 3952 : || unoIdentifier == "stdin"
236 : 3942 : || unoIdentifier == "stdout"
237 : : /* unoIdentifier == "va_arg" */
238 : : /* unoIdentifier == "va_end" */
239 : : /* unoIdentifier == "va_start" */
240 : : // Standard values:
241 : 3932 : || unoIdentifier == "CHAR_BIT"
242 : 3922 : || unoIdentifier == "CHAR_MAX"
243 : 3912 : || unoIdentifier == "CHAR_MIN"
244 : 3902 : || unoIdentifier == "DBL_DIG"
245 : 3892 : || unoIdentifier == "DBL_EPSILON"
246 : 3882 : || unoIdentifier == "DBL_MANT_DIG"
247 : 3872 : || unoIdentifier == "DBL_MAX"
248 : 3862 : || unoIdentifier == "DBL_MAX_10_EXP"
249 : 3852 : || unoIdentifier == "DBL_MAX_EXP"
250 : 3842 : || unoIdentifier == "DBL_MIN"
251 : 3832 : || unoIdentifier == "DBL_MIN_10_EXP"
252 : 3822 : || unoIdentifier == "DBL_MIN_EXP"
253 : 3812 : || unoIdentifier == "FLT_DIG"
254 : 3802 : || unoIdentifier == "FLT_EPSILON"
255 : 3792 : || unoIdentifier == "FLT_MANT_DIG"
256 : 3782 : || unoIdentifier == "FLT_MAX"
257 : 3772 : || unoIdentifier == "FLT_MAX_10_EXP"
258 : 3762 : || unoIdentifier == "FLT_MAX_EXP"
259 : 3752 : || unoIdentifier == "FLT_MIN"
260 : 3742 : || unoIdentifier == "FLT_MIN_10_EXP"
261 : 3732 : || unoIdentifier == "FLT_MIN_EXP"
262 : 3722 : || unoIdentifier == "FLT_RADIX"
263 : 3712 : || unoIdentifier == "FLT_ROUNDS"
264 : 3702 : || unoIdentifier == "INT_MAX"
265 : 3692 : || unoIdentifier == "INT_MIN"
266 : 3682 : || unoIdentifier == "LDBL_DIG"
267 : 3672 : || unoIdentifier == "LDBL_EPSILON"
268 : 3662 : || unoIdentifier == "LDBL_MANT_DIG"
269 : 3652 : || unoIdentifier == "LDBL_MAX"
270 : 3642 : || unoIdentifier == "LDBL_MAX_10_EXP"
271 : 3632 : || unoIdentifier == "LDBL_MAX_EXP"
272 : 3622 : || unoIdentifier == "LDBL_MIN"
273 : 3612 : || unoIdentifier == "LDBL_MIN_10_EXP"
274 : 3602 : || unoIdentifier == "LDBL_MIN_EXP"
275 : 3592 : || unoIdentifier == "LONG_MAX"
276 : 3582 : || unoIdentifier == "LONG_MIN"
277 : 3572 : || unoIdentifier == "MB_LEN_MAX"
278 : 3562 : || unoIdentifier == "SCHAR_MAX"
279 : 3552 : || unoIdentifier == "SCHAR_MIN"
280 : 3542 : || unoIdentifier == "SHRT_MAX"
281 : 3532 : || unoIdentifier == "SHRT_MIN"
282 : 3522 : || unoIdentifier == "UCHAR_MAX"
283 : 3512 : || unoIdentifier == "UINT_MAX"
284 : 3502 : || unoIdentifier == "ULONG_MAX"
285 : 3492 : || unoIdentifier == "USHRT_MAX"))
286 : : || (transmode == ITM_GLOBAL
287 : : && (// Standard types:
288 : : /* unoIdentifier == "clock_t" */
289 : : /* unoIdentifier == "div_t" */
290 : 8 : unoIdentifier == "FILE"
291 : : /* unoIdentifier == "fpos_t" */
292 : : /* unoIdentifier == "jmp_buf" */
293 : 6 : || unoIdentifier == "lconv"
294 : : /* unoIdentifier == "ldiv_t" */
295 : : /* unoIdentifier == "mbstate_t" */
296 : : /* unoIdentifier == "ptrdiff_t" */
297 : : /* unoIdentifier == "sig_atomic_t" */
298 : : /* unoIdentifier == "size_t" */
299 : : /* unoIdentifier == "time_t" */
300 : 4 : || unoIdentifier == "tm"
301 : : /* unoIdentifier == "va_list" */
302 : : /* unoIdentifier == "wctrans_t" */
303 : : /* unoIdentifier == "wctype_t" */
304 : : /* unoIdentifier == "wint_t" */
305 : : // Standard namespaces:
306 : 2 : || unoIdentifier == "std"))
307 : : // Others:
308 : 3474 : || unoIdentifier == "NDEBUG"
309 : 1088 : || (forbidden != 0 && unoIdentifier == *forbidden) )
310 : : {
311 [ + - ]: 1410 : rtl::OStringBuffer buf(prefix);
312 [ + - ]: 1410 : buf.append('_');
313 [ + - ]: 1410 : buf.append(unoIdentifier);
314 : 1410 : return buf.makeStringAndClear();
315 : : } else {
316 : 4862 : return unoIdentifier;
317 : : }
318 : : }
319 : :
320 : : } }
321 : :
322 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|