LCOV - code coverage report
Current view: top level - libreoffice/codemaker/source/commoncpp - commoncpp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 182 197 92.4 %
Date: 2012-12-27 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          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       64409 : rtl::OString scopedCppName(rtl::OString const & type, bool ns_alias)
      41             : {
      42       64409 :     char c('/');
      43       64409 :     sal_Int32 nPos = type.lastIndexOf( c );
      44       64409 :     if (nPos == -1) {
      45         134 :         nPos = type.lastIndexOf( '.' );
      46         134 :         if (nPos == -1)
      47         134 :             return type;
      48             : 
      49           0 :         c = '.';
      50             :     }
      51             : 
      52       64275 :     rtl::OStringBuffer tmpBuf(type.getLength()*2);
      53       64275 :     nPos = 0;
      54      325916 :     do
      55             :     {
      56      325916 :         tmpBuf.append("::");
      57      325916 :         tmpBuf.append(type.getToken(0, c, nPos));
      58             :     } while( nPos != -1 );
      59             : 
      60       64275 :     rtl::OString s(tmpBuf.makeStringAndClear());
      61       64275 :     if (ns_alias && s.indexOf("::com::sun::star::") == 0)
      62             :     {
      63       61893 :         return s.replaceAt(0, 18, "css::"); // nicer shorthand
      64             :     }
      65             : 
      66        2382 :     return s;
      67             : }
      68             : 
      69             : 
      70           0 : rtl::OString translateUnoToCppType(
      71             :     codemaker::UnoType::Sort sort, RTTypeClass typeClass,
      72             :     rtl::OString const & nucleus, bool shortname)
      73             : {
      74           0 :     rtl::OStringBuffer buf;
      75           0 :     if (sort == codemaker::UnoType::SORT_COMPLEX) {
      76           0 :         if (typeClass == RT_TYPE_INTERFACE
      77           0 :             && nucleus == rtl::OString("com/sun/star/uno/XInterface"))
      78             :         {
      79           0 :             buf.append(RTL_CONSTASCII_STRINGPARAM("::com::sun::star::uno::XInterface"));
      80             :         } else {
      81             :             //TODO: check that nucleus is a valid (UTF-8) identifier
      82           0 :             buf.append(nucleus);
      83             :         }
      84             :     } else {
      85             :         static char const * const cppTypes[codemaker::UnoType::SORT_ANY + 1] = {
      86             :             "void", "::sal_Bool", "::sal_Int8", "::sal_Int16", "::sal_uInt16",
      87             :             "::sal_Int32", "::sal_uInt32", "::sal_Int64", "::sal_uInt64",
      88             :             "float", "double", "::sal_Unicode", "::rtl::OUString",
      89             :             "::com::sun::star::uno::Type", "::com::sun::star::uno::Any" };
      90           0 :         buf.append(cppTypes[sort]);
      91             :     }
      92             : 
      93           0 :     if (shortname) {
      94           0 :         rtl::OString s(buf.makeStringAndClear());
      95           0 :         if (s.indexOf("::com::sun::star") == 0)
      96           0 :             return s.replaceAt(0, 16, "css");
      97             :         else
      98           0 :             return s;
      99             :     }
     100             : 
     101           0 :     return buf.makeStringAndClear();
     102             : }
     103             : 
     104        2770 : rtl::OString translateUnoToCppIdentifier(
     105             :     rtl::OString const & unoIdentifier, rtl::OString const & prefix,
     106             :     IdentifierTranslationMode transmode, rtl::OString const * forbidden)
     107             : {
     108      377699 :     if (// Keywords:
     109        2770 :         unoIdentifier == "asm"
     110        2765 :         || unoIdentifier == "auto"
     111        2760 :         || unoIdentifier == "bool"
     112        2755 :         || unoIdentifier == "break"
     113        2750 :         || unoIdentifier == "case"
     114        2750 :         || unoIdentifier == "catch"
     115        2745 :         || unoIdentifier == "char"
     116        2745 :         || unoIdentifier == "class"
     117        2740 :         || unoIdentifier == "const"
     118             :         /* unoIdentifier == "const_cast" */
     119        2740 :         || unoIdentifier == "continue"
     120        2735 :         || unoIdentifier == "default"
     121        2735 :         || unoIdentifier == "delete"
     122        2730 :         || unoIdentifier == "do"
     123        2725 :         || unoIdentifier == "double"
     124             :         /* unoIdentifier == "dynamic_cast" */
     125        2725 :         || unoIdentifier == "else"
     126        2720 :         || unoIdentifier == "enum"
     127        2720 :         || unoIdentifier == "explicit"
     128        2715 :         || unoIdentifier == "export"
     129        2710 :         || unoIdentifier == "extern"
     130        2705 :         || unoIdentifier == "false"
     131        2700 :         || unoIdentifier == "float"
     132        2700 :         || unoIdentifier == "for"
     133        2695 :         || unoIdentifier == "friend"
     134        2690 :         || unoIdentifier == "goto"
     135        2685 :         || unoIdentifier == "if"
     136        2680 :         || unoIdentifier == "inline"
     137        2675 :         || unoIdentifier == "int"
     138        2670 :         || unoIdentifier == "long"
     139        2670 :         || unoIdentifier == "mutable"
     140        2665 :         || unoIdentifier == "namespace"
     141        2660 :         || unoIdentifier == "new"
     142        2655 :         || unoIdentifier == "operator"
     143        2650 :         || unoIdentifier == "private"
     144        2645 :         || unoIdentifier == "protected"
     145        2640 :         || unoIdentifier == "public"
     146        2635 :         || unoIdentifier == "register"
     147             :         /* unoIdentifier == "reinterpret_cast" */
     148        2630 :         || unoIdentifier == "return"
     149        2625 :         || unoIdentifier == "short"
     150        2625 :         || unoIdentifier == "signed"
     151        2620 :         || unoIdentifier == "sizeof"
     152        2615 :         || unoIdentifier == "static"
     153             :         /* unoIdentifier == "static_cast" */
     154        2610 :         || unoIdentifier == "struct"
     155        2610 :         || unoIdentifier == "switch"
     156        2610 :         || unoIdentifier == "template"
     157        2605 :         || unoIdentifier == "this"
     158        2600 :         || unoIdentifier == "throw"
     159        2595 :         || unoIdentifier == "true"
     160        2590 :         || unoIdentifier == "try"
     161        2585 :         || unoIdentifier == "typedef"
     162        2585 :         || unoIdentifier == "typeid"
     163        2580 :         || unoIdentifier == "typename"
     164        2575 :         || unoIdentifier == "union"
     165        2575 :         || unoIdentifier == "unsigned"
     166        2575 :         || unoIdentifier == "using"
     167        2570 :         || unoIdentifier == "virtual"
     168        2565 :         || unoIdentifier == "void"
     169        2565 :         || unoIdentifier == "volatile"
     170             :         /* unoIdentifier == "wchar_t" */
     171        2560 :         || unoIdentifier == "while"
     172             :         // Alternative representations:
     173        2555 :         || unoIdentifier == "and"
     174             :         /* unoIdentifier == "and_eq" */
     175        2550 :         || unoIdentifier == "bitand"
     176        2545 :         || unoIdentifier == "bitor"
     177        2540 :         || unoIdentifier == "compl"
     178        2535 :         || unoIdentifier == "not"
     179             :         /* unoIdentifier == "not_eq" */
     180        2530 :         || unoIdentifier == "or"
     181             :         /* unoIdentifier == "or_eq" */
     182        2525 :         || unoIdentifier == "xor"
     183             :         /* unoIdentifier == "xor_eq" */
     184             :         // Standard macros:
     185             :         || (transmode != ITM_KEYWORDSONLY
     186        2520 :             && (unoIdentifier == "BUFSIZ"
     187        2515 :                 || unoIdentifier == "CLOCKS_PER_SEC"
     188        2510 :                 || unoIdentifier == "EDOM"
     189        2505 :                 || unoIdentifier == "EOF"
     190        2500 :                 || unoIdentifier == "ERANGE"
     191        2495 :                 || unoIdentifier == "EXIT_FAILURE"
     192        2490 :                 || unoIdentifier == "EXIT_SUCCESS"
     193        2485 :                 || unoIdentifier == "FILENAME_MAX"
     194        2480 :                 || unoIdentifier == "FOPEN_MAX"
     195        2475 :                 || unoIdentifier == "HUGE_VAL"
     196        2470 :                 || unoIdentifier == "LC_ALL"
     197        2465 :                 || unoIdentifier == "LC_COLLATE"
     198        2460 :                 || unoIdentifier == "LC_CTYPE"
     199        2455 :                 || unoIdentifier == "LC_MONETARY"
     200        2450 :                 || unoIdentifier == "LC_NUMERIC"
     201        2445 :                 || unoIdentifier == "LC_TIME"
     202        2440 :                 || unoIdentifier == "L_tmpnam"
     203        2435 :                 || unoIdentifier == "MB_CUR_MAX"
     204        2430 :                 || unoIdentifier == "NULL"
     205        2425 :                 || unoIdentifier == "RAND_MAX"
     206        2420 :                 || unoIdentifier == "SEEK_CUR"
     207        2415 :                 || unoIdentifier == "SEEK_END"
     208        2410 :                 || unoIdentifier == "SEEK_SET"
     209        2405 :                 || unoIdentifier == "SIGABRT"
     210        2400 :                 || unoIdentifier == "SIGFPE"
     211        2395 :                 || unoIdentifier == "SIGILL"
     212        2390 :                 || unoIdentifier == "SIGINT"
     213        2385 :                 || unoIdentifier == "SIGSEGV"
     214        2380 :                 || unoIdentifier == "SIGTERM"
     215        2375 :                 || unoIdentifier == "SIG_DFL"
     216        2370 :                 || unoIdentifier == "SIG_ERR"
     217        2365 :                 || unoIdentifier == "SIG_IGN"
     218        2360 :                 || unoIdentifier == "TMP_MAX"
     219        2355 :                 || unoIdentifier == "WCHAR_MAX"
     220        2350 :                 || unoIdentifier == "WCHAR_MIN"
     221        2345 :                 || unoIdentifier == "WEOF"
     222             :                 /* unoIdentifier == "_IOFBF" */
     223             :                 /* unoIdentifier == "_IOLBF" */
     224             :                 /* unoIdentifier == "_IONBF" */
     225        2340 :                 || unoIdentifier == "assert"
     226        2335 :                 || unoIdentifier == "errno"
     227        2330 :                 || unoIdentifier == "offsetof"
     228        2325 :                 || unoIdentifier == "setjmp"
     229        2320 :                 || unoIdentifier == "stderr"
     230        2315 :                 || unoIdentifier == "stdin"
     231        2310 :                 || unoIdentifier == "stdout"
     232             :                 /* unoIdentifier == "va_arg" */
     233             :                 /* unoIdentifier == "va_end" */
     234             :                 /* unoIdentifier == "va_start" */
     235             :                 // Standard values:
     236        2305 :                 || unoIdentifier == "CHAR_BIT"
     237        2300 :                 || unoIdentifier == "CHAR_MAX"
     238        2295 :                 || unoIdentifier == "CHAR_MIN"
     239        2290 :                 || unoIdentifier == "DBL_DIG"
     240        2285 :                 || unoIdentifier == "DBL_EPSILON"
     241        2280 :                 || unoIdentifier == "DBL_MANT_DIG"
     242        2275 :                 || unoIdentifier == "DBL_MAX"
     243        2270 :                 || unoIdentifier == "DBL_MAX_10_EXP"
     244        2265 :                 || unoIdentifier == "DBL_MAX_EXP"
     245        2260 :                 || unoIdentifier == "DBL_MIN"
     246        2255 :                 || unoIdentifier == "DBL_MIN_10_EXP"
     247        2250 :                 || unoIdentifier == "DBL_MIN_EXP"
     248        2245 :                 || unoIdentifier == "FLT_DIG"
     249        2240 :                 || unoIdentifier == "FLT_EPSILON"
     250        2235 :                 || unoIdentifier == "FLT_MANT_DIG"
     251        2230 :                 || unoIdentifier == "FLT_MAX"
     252        2225 :                 || unoIdentifier == "FLT_MAX_10_EXP"
     253        2220 :                 || unoIdentifier == "FLT_MAX_EXP"
     254        2215 :                 || unoIdentifier == "FLT_MIN"
     255        2210 :                 || unoIdentifier == "FLT_MIN_10_EXP"
     256        2205 :                 || unoIdentifier == "FLT_MIN_EXP"
     257        2200 :                 || unoIdentifier == "FLT_RADIX"
     258        2195 :                 || unoIdentifier == "FLT_ROUNDS"
     259        2190 :                 || unoIdentifier == "INT_MAX"
     260        2185 :                 || unoIdentifier == "INT_MIN"
     261        2180 :                 || unoIdentifier == "LDBL_DIG"
     262        2175 :                 || unoIdentifier == "LDBL_EPSILON"
     263        2170 :                 || unoIdentifier == "LDBL_MANT_DIG"
     264        2165 :                 || unoIdentifier == "LDBL_MAX"
     265        2160 :                 || unoIdentifier == "LDBL_MAX_10_EXP"
     266        2155 :                 || unoIdentifier == "LDBL_MAX_EXP"
     267        2150 :                 || unoIdentifier == "LDBL_MIN"
     268        2145 :                 || unoIdentifier == "LDBL_MIN_10_EXP"
     269        2140 :                 || unoIdentifier == "LDBL_MIN_EXP"
     270        2135 :                 || unoIdentifier == "LONG_MAX"
     271        2130 :                 || unoIdentifier == "LONG_MIN"
     272        2125 :                 || unoIdentifier == "MB_LEN_MAX"
     273        2120 :                 || unoIdentifier == "SCHAR_MAX"
     274        2115 :                 || unoIdentifier == "SCHAR_MIN"
     275        2110 :                 || unoIdentifier == "SHRT_MAX"
     276        2105 :                 || unoIdentifier == "SHRT_MIN"
     277        2100 :                 || unoIdentifier == "UCHAR_MAX"
     278        2095 :                 || unoIdentifier == "UINT_MAX"
     279        2090 :                 || unoIdentifier == "ULONG_MAX"
     280        2085 :                 || unoIdentifier == "USHRT_MAX"))
     281             :             || (transmode == ITM_GLOBAL
     282             :                 && (// Standard types:
     283             :                     /* unoIdentifier == "clock_t" */
     284             :                     /* unoIdentifier == "div_t" */
     285           4 :                     unoIdentifier == "FILE"
     286             :                     /* unoIdentifier == "fpos_t" */
     287             :                     /* unoIdentifier == "jmp_buf" */
     288           3 :                     || unoIdentifier == "lconv"
     289             :                     /* unoIdentifier == "ldiv_t" */
     290             :                     /* unoIdentifier == "mbstate_t" */
     291             :                     /* unoIdentifier == "ptrdiff_t" */
     292             :                     /* unoIdentifier == "sig_atomic_t" */
     293             :                     /* unoIdentifier == "size_t" */
     294             :                     /* unoIdentifier == "time_t" */
     295           2 :                     || unoIdentifier == "tm"
     296             :                     /* unoIdentifier == "va_list" */
     297             :                     /* unoIdentifier == "wctrans_t" */
     298             :                     /* unoIdentifier == "wctype_t" */
     299             :                     /* unoIdentifier == "wint_t" */
     300             :                     // Standard namespaces:
     301           1 :                     || unoIdentifier == "std"))
     302             :             // Others:
     303        2076 :             || unoIdentifier == "NDEBUG"
     304         688 :             || (forbidden != 0 && unoIdentifier == *forbidden) )
     305             :     {
     306         705 :         rtl::OStringBuffer buf(prefix);
     307         705 :         buf.append('_');
     308         705 :         buf.append(unoIdentifier);
     309         705 :         return buf.makeStringAndClear();
     310             :     } else {
     311        2065 :         return unoIdentifier;
     312             :     }
     313             : }
     314             : 
     315             : } }
     316             : 
     317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10