LCOV - code coverage report
Current view: top level - codemaker/source/commoncpp - commoncpp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 183 192 95.3 %
Date: 2015-06-13 12:38:46 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 "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       70489 : OString scopedCppName(OString const & type, bool ns_alias)
      39             : {
      40       70489 :     char c('/');
      41       70489 :     sal_Int32 nPos = type.lastIndexOf( c );
      42       70489 :     if (nPos == -1) {
      43       70489 :         nPos = type.lastIndexOf( '.' );
      44       70489 :         if (nPos == -1)
      45         134 :             return type;
      46             : 
      47       70355 :         c = '.';
      48             :     }
      49             : 
      50       70355 :     OStringBuffer tmpBuf(type.getLength()*2);
      51       70355 :     nPos = 0;
      52      356567 :     do
      53             :     {
      54      356567 :         tmpBuf.append("::" + type.getToken(0, c, nPos));
      55      356567 :     } while( nPos != -1 );
      56             : 
      57      140710 :     OString s(tmpBuf.makeStringAndClear());
      58       70355 :     if (ns_alias && s.startsWith("::com::sun::star::", &s))
      59             :     {
      60       67945 :         s = "::css::" + s; // nicer shorthand
      61             :     }
      62             : 
      63      140710 :     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        3585 : OString translateUnoToCppIdentifier(
      92             :     OString const & unoIdentifier, OString const & prefix,
      93             :     IdentifierTranslationMode transmode, OString const * forbidden)
      94             : {
      95        3585 :     if (// Keywords:
      96        3585 :         unoIdentifier == "asm"
      97        3580 :         || unoIdentifier == "auto"
      98        3575 :         || unoIdentifier == "bool"
      99        3570 :         || unoIdentifier == "break"
     100        3565 :         || unoIdentifier == "case"
     101        3565 :         || unoIdentifier == "catch"
     102        3560 :         || unoIdentifier == "char"
     103        3560 :         || unoIdentifier == "class"
     104        3555 :         || unoIdentifier == "const"
     105             :         /* unoIdentifier == "const_cast" */
     106        3555 :         || unoIdentifier == "continue"
     107        3550 :         || unoIdentifier == "default"
     108        3550 :         || unoIdentifier == "delete"
     109        3545 :         || unoIdentifier == "do"
     110        3540 :         || unoIdentifier == "double"
     111             :         /* unoIdentifier == "dynamic_cast" */
     112        3540 :         || unoIdentifier == "else"
     113        3535 :         || unoIdentifier == "enum"
     114        3535 :         || unoIdentifier == "explicit"
     115        3530 :         || unoIdentifier == "export"
     116        3525 :         || unoIdentifier == "extern"
     117        3520 :         || unoIdentifier == "false"
     118        3515 :         || unoIdentifier == "float"
     119        3515 :         || unoIdentifier == "for"
     120        3510 :         || unoIdentifier == "friend"
     121        3505 :         || unoIdentifier == "goto"
     122        3500 :         || unoIdentifier == "if"
     123        3495 :         || unoIdentifier == "inline"
     124        3490 :         || unoIdentifier == "int"
     125        3485 :         || unoIdentifier == "long"
     126        3485 :         || unoIdentifier == "mutable"
     127        3480 :         || unoIdentifier == "namespace"
     128        3475 :         || unoIdentifier == "new"
     129        3470 :         || unoIdentifier == "operator"
     130        3465 :         || unoIdentifier == "private"
     131        3460 :         || unoIdentifier == "protected"
     132        3455 :         || unoIdentifier == "public"
     133        3450 :         || unoIdentifier == "register"
     134             :         /* unoIdentifier == "reinterpret_cast" */
     135        3445 :         || unoIdentifier == "return"
     136        3440 :         || unoIdentifier == "short"
     137        3440 :         || unoIdentifier == "signed"
     138        3435 :         || unoIdentifier == "sizeof"
     139        3430 :         || unoIdentifier == "static"
     140             :         /* unoIdentifier == "static_cast" */
     141        3425 :         || unoIdentifier == "struct"
     142        3425 :         || unoIdentifier == "switch"
     143        3425 :         || unoIdentifier == "template"
     144        3420 :         || unoIdentifier == "this"
     145        3415 :         || unoIdentifier == "throw"
     146        3410 :         || unoIdentifier == "true"
     147        3405 :         || unoIdentifier == "try"
     148        3400 :         || unoIdentifier == "typedef"
     149        3400 :         || unoIdentifier == "typeid"
     150        3395 :         || unoIdentifier == "typename"
     151        3390 :         || unoIdentifier == "union"
     152        3390 :         || unoIdentifier == "unsigned"
     153        3390 :         || unoIdentifier == "using"
     154        3385 :         || unoIdentifier == "virtual"
     155        3380 :         || unoIdentifier == "void"
     156        3380 :         || unoIdentifier == "volatile"
     157             :         /* unoIdentifier == "wchar_t" */
     158        3375 :         || unoIdentifier == "while"
     159             :         // Alternative representations:
     160        3370 :         || unoIdentifier == "and"
     161             :         /* unoIdentifier == "and_eq" */
     162        3365 :         || unoIdentifier == "bitand"
     163        3360 :         || unoIdentifier == "bitor"
     164        3355 :         || unoIdentifier == "compl"
     165        3350 :         || unoIdentifier == "not"
     166             :         /* unoIdentifier == "not_eq" */
     167        3345 :         || unoIdentifier == "or"
     168             :         /* unoIdentifier == "or_eq" */
     169        3340 :         || unoIdentifier == "xor"
     170             :         /* unoIdentifier == "xor_eq" */
     171             :         // Standard macros:
     172        3335 :         || (transmode != ITM_KEYWORDSONLY
     173        3335 :             && (unoIdentifier == "BUFSIZ"
     174        3330 :                 || unoIdentifier == "CLOCKS_PER_SEC"
     175        3325 :                 || unoIdentifier == "EDOM"
     176        3320 :                 || unoIdentifier == "EOF"
     177        3315 :                 || unoIdentifier == "ERANGE"
     178        3310 :                 || unoIdentifier == "EXIT_FAILURE"
     179        3305 :                 || unoIdentifier == "EXIT_SUCCESS"
     180        3300 :                 || unoIdentifier == "FILENAME_MAX"
     181        3295 :                 || unoIdentifier == "FOPEN_MAX"
     182        3290 :                 || unoIdentifier == "HUGE_VAL"
     183        3285 :                 || unoIdentifier == "LC_ALL"
     184        3280 :                 || unoIdentifier == "LC_COLLATE"
     185        3275 :                 || unoIdentifier == "LC_CTYPE"
     186        3270 :                 || unoIdentifier == "LC_MONETARY"
     187        3265 :                 || unoIdentifier == "LC_NUMERIC"
     188        3260 :                 || unoIdentifier == "LC_TIME"
     189        3255 :                 || unoIdentifier == "L_tmpnam"
     190        3250 :                 || unoIdentifier == "MB_CUR_MAX"
     191        3245 :                 || unoIdentifier == "NULL"
     192        3240 :                 || unoIdentifier == "RAND_MAX"
     193        3235 :                 || unoIdentifier == "SEEK_CUR"
     194        3230 :                 || unoIdentifier == "SEEK_END"
     195        3225 :                 || unoIdentifier == "SEEK_SET"
     196        3220 :                 || unoIdentifier == "SIGABRT"
     197        3215 :                 || unoIdentifier == "SIGFPE"
     198        3210 :                 || unoIdentifier == "SIGILL"
     199        3205 :                 || unoIdentifier == "SIGINT"
     200        3200 :                 || unoIdentifier == "SIGSEGV"
     201        3195 :                 || unoIdentifier == "SIGTERM"
     202        3190 :                 || unoIdentifier == "SIG_DFL"
     203        3185 :                 || unoIdentifier == "SIG_ERR"
     204        3180 :                 || unoIdentifier == "SIG_IGN"
     205        3175 :                 || unoIdentifier == "TMP_MAX"
     206        3170 :                 || unoIdentifier == "WCHAR_MAX"
     207        3165 :                 || unoIdentifier == "WCHAR_MIN"
     208        3160 :                 || unoIdentifier == "WEOF"
     209             :                 /* unoIdentifier == "_IOFBF" */
     210             :                 /* unoIdentifier == "_IOLBF" */
     211             :                 /* unoIdentifier == "_IONBF" */
     212        3155 :                 || unoIdentifier == "assert"
     213        3150 :                 || unoIdentifier == "errno"
     214        3145 :                 || unoIdentifier == "offsetof"
     215        3140 :                 || unoIdentifier == "setjmp"
     216        3135 :                 || unoIdentifier == "stderr"
     217        3130 :                 || unoIdentifier == "stdin"
     218        3125 :                 || unoIdentifier == "stdout"
     219             :                 /* unoIdentifier == "va_arg" */
     220             :                 /* unoIdentifier == "va_end" */
     221             :                 /* unoIdentifier == "va_start" */
     222             :                 // Standard values:
     223        3120 :                 || unoIdentifier == "CHAR_BIT"
     224        3115 :                 || unoIdentifier == "CHAR_MAX"
     225        3110 :                 || unoIdentifier == "CHAR_MIN"
     226        3105 :                 || unoIdentifier == "DBL_DIG"
     227        3100 :                 || unoIdentifier == "DBL_EPSILON"
     228        3095 :                 || unoIdentifier == "DBL_MANT_DIG"
     229        3090 :                 || unoIdentifier == "DBL_MAX"
     230        3085 :                 || unoIdentifier == "DBL_MAX_10_EXP"
     231        3080 :                 || unoIdentifier == "DBL_MAX_EXP"
     232        3075 :                 || unoIdentifier == "DBL_MIN"
     233        3070 :                 || unoIdentifier == "DBL_MIN_10_EXP"
     234        3065 :                 || unoIdentifier == "DBL_MIN_EXP"
     235        3060 :                 || unoIdentifier == "FLT_DIG"
     236        3055 :                 || unoIdentifier == "FLT_EPSILON"
     237        3050 :                 || unoIdentifier == "FLT_MANT_DIG"
     238        3045 :                 || unoIdentifier == "FLT_MAX"
     239        3040 :                 || unoIdentifier == "FLT_MAX_10_EXP"
     240        3035 :                 || unoIdentifier == "FLT_MAX_EXP"
     241        3030 :                 || unoIdentifier == "FLT_MIN"
     242        3025 :                 || unoIdentifier == "FLT_MIN_10_EXP"
     243        3020 :                 || unoIdentifier == "FLT_MIN_EXP"
     244        3015 :                 || unoIdentifier == "FLT_RADIX"
     245        3010 :                 || unoIdentifier == "FLT_ROUNDS"
     246        3005 :                 || unoIdentifier == "INT_MAX"
     247        3000 :                 || unoIdentifier == "INT_MIN"
     248        2995 :                 || unoIdentifier == "LDBL_DIG"
     249        2990 :                 || unoIdentifier == "LDBL_EPSILON"
     250        2985 :                 || unoIdentifier == "LDBL_MANT_DIG"
     251        2980 :                 || unoIdentifier == "LDBL_MAX"
     252        2975 :                 || unoIdentifier == "LDBL_MAX_10_EXP"
     253        2970 :                 || unoIdentifier == "LDBL_MAX_EXP"
     254        2965 :                 || unoIdentifier == "LDBL_MIN"
     255        2960 :                 || unoIdentifier == "LDBL_MIN_10_EXP"
     256        2955 :                 || unoIdentifier == "LDBL_MIN_EXP"
     257        2950 :                 || unoIdentifier == "LONG_MAX"
     258        2945 :                 || unoIdentifier == "LONG_MIN"
     259        2940 :                 || unoIdentifier == "MB_LEN_MAX"
     260        2935 :                 || unoIdentifier == "SCHAR_MAX"
     261        2930 :                 || unoIdentifier == "SCHAR_MIN"
     262        2925 :                 || unoIdentifier == "SHRT_MAX"
     263        2920 :                 || unoIdentifier == "SHRT_MIN"
     264        2915 :                 || unoIdentifier == "UCHAR_MAX"
     265        2910 :                 || unoIdentifier == "UINT_MAX"
     266        2905 :                 || unoIdentifier == "ULONG_MAX"
     267        2900 :                 || unoIdentifier == "USHRT_MAX"))
     268        2895 :             || (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        2891 :             || unoIdentifier == "NDEBUG"
     291        6471 :             || (forbidden != 0 && unoIdentifier == *forbidden) )
     292             :     {
     293         705 :         return prefix + "_" + unoIdentifier;
     294             :     } else {
     295        2880 :         return unoIdentifier;
     296             :     }
     297             : }
     298             : 
     299             : } }
     300             : 
     301             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11