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 "rtl/strbuf.hxx"
30 : #include "rtl/string.hxx"
31 : #include "rtl/ustring.hxx"
32 : #include "sal/types.h"
33 :
34 : #include <vector>
35 :
36 : namespace codemaker { namespace cpp {
37 :
38 70258 : OString scopedCppName(OString const & type, bool ns_alias)
39 : {
40 70258 : char c('/');
41 70258 : sal_Int32 nPos = type.lastIndexOf( c );
42 70258 : if (nPos == -1) {
43 70258 : nPos = type.lastIndexOf( '.' );
44 70258 : if (nPos == -1)
45 134 : return type;
46 :
47 70124 : c = '.';
48 : }
49 :
50 70124 : OStringBuffer tmpBuf(type.getLength()*2);
51 70124 : nPos = 0;
52 355412 : do
53 : {
54 355412 : tmpBuf.append("::" + type.getToken(0, c, nPos));
55 355412 : } while( nPos != -1 );
56 :
57 140248 : OString s(tmpBuf.makeStringAndClear());
58 70124 : if (ns_alias && s.startsWith("::com::sun::star::", &s))
59 : {
60 67714 : s = "::css::" + s; // nicer shorthand
61 : }
62 :
63 140248 : return s;
64 : }
65 :
66 :
67 0 : OString translateUnoToCppType(
68 : codemaker::UnoType::Sort sort, OUString const & nucleus)
69 : {
70 0 : OStringBuffer buf;
71 0 : if (sort <= codemaker::UnoType::SORT_ANY) {
72 : static char const * const cppTypes[codemaker::UnoType::SORT_ANY + 1] = {
73 : "void", "::sal_Bool", "::sal_Int8", "::sal_Int16", "::sal_uInt16",
74 : "::sal_Int32", "::sal_uInt32", "::sal_Int64", "::sal_uInt64",
75 : "float", "double", "::sal_Unicode", "rtl::OUString",
76 : "::css::uno::Type", "::css::uno::Any" };
77 0 : buf.append(cppTypes[sort]);
78 : } else {
79 0 : if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE
80 0 : && nucleus == "com.sun.star.uno.XInterface")
81 : {
82 0 : buf.append("::css::uno::XInterface");
83 : } else {
84 : //TODO: check that nucleus is a valid (UTF-8) identifier
85 0 : buf.append(u2b(nucleus));
86 : }
87 : }
88 0 : return buf.makeStringAndClear();
89 : }
90 :
91 3581 : OString translateUnoToCppIdentifier(
92 : OString const & unoIdentifier, OString const & prefix,
93 : IdentifierTranslationMode transmode, OString const * forbidden)
94 : {
95 3581 : if (// Keywords:
96 3581 : unoIdentifier == "asm"
97 3576 : || unoIdentifier == "auto"
98 3571 : || unoIdentifier == "bool"
99 3566 : || unoIdentifier == "break"
100 3561 : || unoIdentifier == "case"
101 3561 : || unoIdentifier == "catch"
102 3556 : || unoIdentifier == "char"
103 3556 : || unoIdentifier == "class"
104 3551 : || unoIdentifier == "const"
105 : /* unoIdentifier == "const_cast" */
106 3551 : || unoIdentifier == "continue"
107 3546 : || unoIdentifier == "default"
108 3546 : || unoIdentifier == "delete"
109 3541 : || unoIdentifier == "do"
110 3536 : || unoIdentifier == "double"
111 : /* unoIdentifier == "dynamic_cast" */
112 3536 : || unoIdentifier == "else"
113 3531 : || unoIdentifier == "enum"
114 3531 : || unoIdentifier == "explicit"
115 3526 : || unoIdentifier == "export"
116 3521 : || unoIdentifier == "extern"
117 3516 : || unoIdentifier == "false"
118 3511 : || unoIdentifier == "float"
119 3511 : || unoIdentifier == "for"
120 3506 : || unoIdentifier == "friend"
121 3501 : || unoIdentifier == "goto"
122 3496 : || unoIdentifier == "if"
123 3491 : || unoIdentifier == "inline"
124 3486 : || unoIdentifier == "int"
125 3481 : || unoIdentifier == "long"
126 3481 : || unoIdentifier == "mutable"
127 3476 : || unoIdentifier == "namespace"
128 3471 : || unoIdentifier == "new"
129 3466 : || unoIdentifier == "operator"
130 3461 : || unoIdentifier == "private"
131 3456 : || unoIdentifier == "protected"
132 3451 : || unoIdentifier == "public"
133 3446 : || unoIdentifier == "register"
134 : /* unoIdentifier == "reinterpret_cast" */
135 3441 : || unoIdentifier == "return"
136 3436 : || unoIdentifier == "short"
137 3436 : || unoIdentifier == "signed"
138 3431 : || unoIdentifier == "sizeof"
139 3426 : || unoIdentifier == "static"
140 : /* unoIdentifier == "static_cast" */
141 3421 : || unoIdentifier == "struct"
142 3421 : || unoIdentifier == "switch"
143 3421 : || unoIdentifier == "template"
144 3416 : || unoIdentifier == "this"
145 3411 : || unoIdentifier == "throw"
146 3406 : || unoIdentifier == "true"
147 3401 : || unoIdentifier == "try"
148 3396 : || unoIdentifier == "typedef"
149 3396 : || unoIdentifier == "typeid"
150 3391 : || unoIdentifier == "typename"
151 3386 : || unoIdentifier == "union"
152 3386 : || unoIdentifier == "unsigned"
153 3386 : || unoIdentifier == "using"
154 3381 : || unoIdentifier == "virtual"
155 3376 : || unoIdentifier == "void"
156 3376 : || unoIdentifier == "volatile"
157 : /* unoIdentifier == "wchar_t" */
158 3371 : || unoIdentifier == "while"
159 : // Alternative representations:
160 3366 : || unoIdentifier == "and"
161 : /* unoIdentifier == "and_eq" */
162 3361 : || unoIdentifier == "bitand"
163 3356 : || unoIdentifier == "bitor"
164 3351 : || unoIdentifier == "compl"
165 3346 : || unoIdentifier == "not"
166 : /* unoIdentifier == "not_eq" */
167 3341 : || unoIdentifier == "or"
168 : /* unoIdentifier == "or_eq" */
169 3336 : || unoIdentifier == "xor"
170 : /* unoIdentifier == "xor_eq" */
171 : // Standard macros:
172 3331 : || (transmode != ITM_KEYWORDSONLY
173 3331 : && (unoIdentifier == "BUFSIZ"
174 3326 : || unoIdentifier == "CLOCKS_PER_SEC"
175 3321 : || unoIdentifier == "EDOM"
176 3316 : || unoIdentifier == "EOF"
177 3311 : || unoIdentifier == "ERANGE"
178 3306 : || unoIdentifier == "EXIT_FAILURE"
179 3301 : || unoIdentifier == "EXIT_SUCCESS"
180 3296 : || unoIdentifier == "FILENAME_MAX"
181 3291 : || unoIdentifier == "FOPEN_MAX"
182 3286 : || unoIdentifier == "HUGE_VAL"
183 3281 : || unoIdentifier == "LC_ALL"
184 3276 : || unoIdentifier == "LC_COLLATE"
185 3271 : || unoIdentifier == "LC_CTYPE"
186 3266 : || unoIdentifier == "LC_MONETARY"
187 3261 : || unoIdentifier == "LC_NUMERIC"
188 3256 : || unoIdentifier == "LC_TIME"
189 3251 : || unoIdentifier == "L_tmpnam"
190 3246 : || unoIdentifier == "MB_CUR_MAX"
191 3241 : || unoIdentifier == "NULL"
192 3236 : || unoIdentifier == "RAND_MAX"
193 3231 : || unoIdentifier == "SEEK_CUR"
194 3226 : || unoIdentifier == "SEEK_END"
195 3221 : || unoIdentifier == "SEEK_SET"
196 3216 : || unoIdentifier == "SIGABRT"
197 3211 : || unoIdentifier == "SIGFPE"
198 3206 : || unoIdentifier == "SIGILL"
199 3201 : || unoIdentifier == "SIGINT"
200 3196 : || unoIdentifier == "SIGSEGV"
201 3191 : || unoIdentifier == "SIGTERM"
202 3186 : || unoIdentifier == "SIG_DFL"
203 3181 : || unoIdentifier == "SIG_ERR"
204 3176 : || unoIdentifier == "SIG_IGN"
205 3171 : || unoIdentifier == "TMP_MAX"
206 3166 : || unoIdentifier == "WCHAR_MAX"
207 3161 : || unoIdentifier == "WCHAR_MIN"
208 3156 : || unoIdentifier == "WEOF"
209 : /* unoIdentifier == "_IOFBF" */
210 : /* unoIdentifier == "_IOLBF" */
211 : /* unoIdentifier == "_IONBF" */
212 3151 : || unoIdentifier == "assert"
213 3146 : || unoIdentifier == "errno"
214 3141 : || unoIdentifier == "offsetof"
215 3136 : || unoIdentifier == "setjmp"
216 3131 : || unoIdentifier == "stderr"
217 3126 : || unoIdentifier == "stdin"
218 3121 : || unoIdentifier == "stdout"
219 : /* unoIdentifier == "va_arg" */
220 : /* unoIdentifier == "va_end" */
221 : /* unoIdentifier == "va_start" */
222 : // Standard values:
223 3116 : || unoIdentifier == "CHAR_BIT"
224 3111 : || unoIdentifier == "CHAR_MAX"
225 3106 : || unoIdentifier == "CHAR_MIN"
226 3101 : || unoIdentifier == "DBL_DIG"
227 3096 : || unoIdentifier == "DBL_EPSILON"
228 3091 : || unoIdentifier == "DBL_MANT_DIG"
229 3086 : || unoIdentifier == "DBL_MAX"
230 3081 : || unoIdentifier == "DBL_MAX_10_EXP"
231 3076 : || unoIdentifier == "DBL_MAX_EXP"
232 3071 : || unoIdentifier == "DBL_MIN"
233 3066 : || unoIdentifier == "DBL_MIN_10_EXP"
234 3061 : || unoIdentifier == "DBL_MIN_EXP"
235 3056 : || unoIdentifier == "FLT_DIG"
236 3051 : || unoIdentifier == "FLT_EPSILON"
237 3046 : || unoIdentifier == "FLT_MANT_DIG"
238 3041 : || unoIdentifier == "FLT_MAX"
239 3036 : || unoIdentifier == "FLT_MAX_10_EXP"
240 3031 : || unoIdentifier == "FLT_MAX_EXP"
241 3026 : || unoIdentifier == "FLT_MIN"
242 3021 : || unoIdentifier == "FLT_MIN_10_EXP"
243 3016 : || unoIdentifier == "FLT_MIN_EXP"
244 3011 : || unoIdentifier == "FLT_RADIX"
245 3006 : || unoIdentifier == "FLT_ROUNDS"
246 3001 : || unoIdentifier == "INT_MAX"
247 2996 : || unoIdentifier == "INT_MIN"
248 2991 : || unoIdentifier == "LDBL_DIG"
249 2986 : || unoIdentifier == "LDBL_EPSILON"
250 2981 : || unoIdentifier == "LDBL_MANT_DIG"
251 2976 : || unoIdentifier == "LDBL_MAX"
252 2971 : || unoIdentifier == "LDBL_MAX_10_EXP"
253 2966 : || unoIdentifier == "LDBL_MAX_EXP"
254 2961 : || unoIdentifier == "LDBL_MIN"
255 2956 : || unoIdentifier == "LDBL_MIN_10_EXP"
256 2951 : || unoIdentifier == "LDBL_MIN_EXP"
257 2946 : || unoIdentifier == "LONG_MAX"
258 2941 : || unoIdentifier == "LONG_MIN"
259 2936 : || unoIdentifier == "MB_LEN_MAX"
260 2931 : || unoIdentifier == "SCHAR_MAX"
261 2926 : || unoIdentifier == "SCHAR_MIN"
262 2921 : || unoIdentifier == "SHRT_MAX"
263 2916 : || unoIdentifier == "SHRT_MIN"
264 2911 : || unoIdentifier == "UCHAR_MAX"
265 2906 : || unoIdentifier == "UINT_MAX"
266 2901 : || unoIdentifier == "ULONG_MAX"
267 2896 : || unoIdentifier == "USHRT_MAX"))
268 2891 : || (transmode == ITM_GLOBAL
269 4 : && (// Standard types:
270 : /* unoIdentifier == "clock_t" */
271 : /* unoIdentifier == "div_t" */
272 4 : unoIdentifier == "FILE"
273 : /* unoIdentifier == "fpos_t" */
274 : /* unoIdentifier == "jmp_buf" */
275 3 : || unoIdentifier == "lconv"
276 : /* unoIdentifier == "ldiv_t" */
277 : /* unoIdentifier == "mbstate_t" */
278 : /* unoIdentifier == "ptrdiff_t" */
279 : /* unoIdentifier == "sig_atomic_t" */
280 : /* unoIdentifier == "size_t" */
281 : /* unoIdentifier == "time_t" */
282 2 : || unoIdentifier == "tm"
283 : /* unoIdentifier == "va_list" */
284 : /* unoIdentifier == "wctrans_t" */
285 : /* unoIdentifier == "wctype_t" */
286 : /* unoIdentifier == "wint_t" */
287 : // Standard namespaces:
288 1 : || unoIdentifier == "std"))
289 : // Others:
290 2887 : || unoIdentifier == "NDEBUG"
291 6463 : || (forbidden != 0 && unoIdentifier == *forbidden) )
292 : {
293 705 : return prefix + "_" + unoIdentifier;
294 : } else {
295 2876 : return unoIdentifier;
296 : }
297 : }
298 :
299 : } }
300 :
301 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|