LCOV - code coverage report
Current view: top level - libreoffice/codemaker/source/commoncpp - commoncpp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 197 0.0 %
Date: 2012-12-17 Functions: 0 3 0.0 %
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           0 : rtl::OString scopedCppName(rtl::OString const & type, bool ns_alias)
      41             : {
      42           0 :     char c('/');
      43           0 :     sal_Int32 nPos = type.lastIndexOf( c );
      44           0 :     if (nPos == -1) {
      45           0 :         nPos = type.lastIndexOf( '.' );
      46           0 :         if (nPos == -1)
      47           0 :             return type;
      48             : 
      49           0 :         c = '.';
      50             :     }
      51             : 
      52           0 :     rtl::OStringBuffer tmpBuf(type.getLength()*2);
      53           0 :     nPos = 0;
      54           0 :     do
      55             :     {
      56           0 :         tmpBuf.append("::");
      57           0 :         tmpBuf.append(type.getToken(0, c, nPos));
      58             :     } while( nPos != -1 );
      59             : 
      60           0 :     rtl::OString s(tmpBuf.makeStringAndClear());
      61           0 :     if (ns_alias && s.indexOf("::com::sun::star::") == 0)
      62             :     {
      63           0 :         return s.replaceAt(0, 18, "css::"); // nicer shorthand
      64             :     }
      65             : 
      66           0 :     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           0 : rtl::OString translateUnoToCppIdentifier(
     105             :     rtl::OString const & unoIdentifier, rtl::OString const & prefix,
     106             :     IdentifierTranslationMode transmode, rtl::OString const * forbidden)
     107             : {
     108           0 :     if (// Keywords:
     109           0 :         unoIdentifier == "asm"
     110           0 :         || unoIdentifier == "auto"
     111           0 :         || unoIdentifier == "bool"
     112           0 :         || unoIdentifier == "break"
     113           0 :         || unoIdentifier == "case"
     114           0 :         || unoIdentifier == "catch"
     115           0 :         || unoIdentifier == "char"
     116           0 :         || unoIdentifier == "class"
     117           0 :         || unoIdentifier == "const"
     118             :         /* unoIdentifier == "const_cast" */
     119           0 :         || unoIdentifier == "continue"
     120           0 :         || unoIdentifier == "default"
     121           0 :         || unoIdentifier == "delete"
     122           0 :         || unoIdentifier == "do"
     123           0 :         || unoIdentifier == "double"
     124             :         /* unoIdentifier == "dynamic_cast" */
     125           0 :         || unoIdentifier == "else"
     126           0 :         || unoIdentifier == "enum"
     127           0 :         || unoIdentifier == "explicit"
     128           0 :         || unoIdentifier == "export"
     129           0 :         || unoIdentifier == "extern"
     130           0 :         || unoIdentifier == "false"
     131           0 :         || unoIdentifier == "float"
     132           0 :         || unoIdentifier == "for"
     133           0 :         || unoIdentifier == "friend"
     134           0 :         || unoIdentifier == "goto"
     135           0 :         || unoIdentifier == "if"
     136           0 :         || unoIdentifier == "inline"
     137           0 :         || unoIdentifier == "int"
     138           0 :         || unoIdentifier == "long"
     139           0 :         || unoIdentifier == "mutable"
     140           0 :         || unoIdentifier == "namespace"
     141           0 :         || unoIdentifier == "new"
     142           0 :         || unoIdentifier == "operator"
     143           0 :         || unoIdentifier == "private"
     144           0 :         || unoIdentifier == "protected"
     145           0 :         || unoIdentifier == "public"
     146           0 :         || unoIdentifier == "register"
     147             :         /* unoIdentifier == "reinterpret_cast" */
     148           0 :         || unoIdentifier == "return"
     149           0 :         || unoIdentifier == "short"
     150           0 :         || unoIdentifier == "signed"
     151           0 :         || unoIdentifier == "sizeof"
     152           0 :         || unoIdentifier == "static"
     153             :         /* unoIdentifier == "static_cast" */
     154           0 :         || unoIdentifier == "struct"
     155           0 :         || unoIdentifier == "switch"
     156           0 :         || unoIdentifier == "template"
     157           0 :         || unoIdentifier == "this"
     158           0 :         || unoIdentifier == "throw"
     159           0 :         || unoIdentifier == "true"
     160           0 :         || unoIdentifier == "try"
     161           0 :         || unoIdentifier == "typedef"
     162           0 :         || unoIdentifier == "typeid"
     163           0 :         || unoIdentifier == "typename"
     164           0 :         || unoIdentifier == "union"
     165           0 :         || unoIdentifier == "unsigned"
     166           0 :         || unoIdentifier == "using"
     167           0 :         || unoIdentifier == "virtual"
     168           0 :         || unoIdentifier == "void"
     169           0 :         || unoIdentifier == "volatile"
     170             :         /* unoIdentifier == "wchar_t" */
     171           0 :         || unoIdentifier == "while"
     172             :         // Alternative representations:
     173           0 :         || unoIdentifier == "and"
     174             :         /* unoIdentifier == "and_eq" */
     175           0 :         || unoIdentifier == "bitand"
     176           0 :         || unoIdentifier == "bitor"
     177           0 :         || unoIdentifier == "compl"
     178           0 :         || unoIdentifier == "not"
     179             :         /* unoIdentifier == "not_eq" */
     180           0 :         || unoIdentifier == "or"
     181             :         /* unoIdentifier == "or_eq" */
     182           0 :         || unoIdentifier == "xor"
     183             :         /* unoIdentifier == "xor_eq" */
     184             :         // Standard macros:
     185             :         || (transmode != ITM_KEYWORDSONLY
     186           0 :             && (unoIdentifier == "BUFSIZ"
     187           0 :                 || unoIdentifier == "CLOCKS_PER_SEC"
     188           0 :                 || unoIdentifier == "EDOM"
     189           0 :                 || unoIdentifier == "EOF"
     190           0 :                 || unoIdentifier == "ERANGE"
     191           0 :                 || unoIdentifier == "EXIT_FAILURE"
     192           0 :                 || unoIdentifier == "EXIT_SUCCESS"
     193           0 :                 || unoIdentifier == "FILENAME_MAX"
     194           0 :                 || unoIdentifier == "FOPEN_MAX"
     195           0 :                 || unoIdentifier == "HUGE_VAL"
     196           0 :                 || unoIdentifier == "LC_ALL"
     197           0 :                 || unoIdentifier == "LC_COLLATE"
     198           0 :                 || unoIdentifier == "LC_CTYPE"
     199           0 :                 || unoIdentifier == "LC_MONETARY"
     200           0 :                 || unoIdentifier == "LC_NUMERIC"
     201           0 :                 || unoIdentifier == "LC_TIME"
     202           0 :                 || unoIdentifier == "L_tmpnam"
     203           0 :                 || unoIdentifier == "MB_CUR_MAX"
     204           0 :                 || unoIdentifier == "NULL"
     205           0 :                 || unoIdentifier == "RAND_MAX"
     206           0 :                 || unoIdentifier == "SEEK_CUR"
     207           0 :                 || unoIdentifier == "SEEK_END"
     208           0 :                 || unoIdentifier == "SEEK_SET"
     209           0 :                 || unoIdentifier == "SIGABRT"
     210           0 :                 || unoIdentifier == "SIGFPE"
     211           0 :                 || unoIdentifier == "SIGILL"
     212           0 :                 || unoIdentifier == "SIGINT"
     213           0 :                 || unoIdentifier == "SIGSEGV"
     214           0 :                 || unoIdentifier == "SIGTERM"
     215           0 :                 || unoIdentifier == "SIG_DFL"
     216           0 :                 || unoIdentifier == "SIG_ERR"
     217           0 :                 || unoIdentifier == "SIG_IGN"
     218           0 :                 || unoIdentifier == "TMP_MAX"
     219           0 :                 || unoIdentifier == "WCHAR_MAX"
     220           0 :                 || unoIdentifier == "WCHAR_MIN"
     221           0 :                 || unoIdentifier == "WEOF"
     222             :                 /* unoIdentifier == "_IOFBF" */
     223             :                 /* unoIdentifier == "_IOLBF" */
     224             :                 /* unoIdentifier == "_IONBF" */
     225           0 :                 || unoIdentifier == "assert"
     226           0 :                 || unoIdentifier == "errno"
     227           0 :                 || unoIdentifier == "offsetof"
     228           0 :                 || unoIdentifier == "setjmp"
     229           0 :                 || unoIdentifier == "stderr"
     230           0 :                 || unoIdentifier == "stdin"
     231           0 :                 || unoIdentifier == "stdout"
     232             :                 /* unoIdentifier == "va_arg" */
     233             :                 /* unoIdentifier == "va_end" */
     234             :                 /* unoIdentifier == "va_start" */
     235             :                 // Standard values:
     236           0 :                 || unoIdentifier == "CHAR_BIT"
     237           0 :                 || unoIdentifier == "CHAR_MAX"
     238           0 :                 || unoIdentifier == "CHAR_MIN"
     239           0 :                 || unoIdentifier == "DBL_DIG"
     240           0 :                 || unoIdentifier == "DBL_EPSILON"
     241           0 :                 || unoIdentifier == "DBL_MANT_DIG"
     242           0 :                 || unoIdentifier == "DBL_MAX"
     243           0 :                 || unoIdentifier == "DBL_MAX_10_EXP"
     244           0 :                 || unoIdentifier == "DBL_MAX_EXP"
     245           0 :                 || unoIdentifier == "DBL_MIN"
     246           0 :                 || unoIdentifier == "DBL_MIN_10_EXP"
     247           0 :                 || unoIdentifier == "DBL_MIN_EXP"
     248           0 :                 || unoIdentifier == "FLT_DIG"
     249           0 :                 || unoIdentifier == "FLT_EPSILON"
     250           0 :                 || unoIdentifier == "FLT_MANT_DIG"
     251           0 :                 || unoIdentifier == "FLT_MAX"
     252           0 :                 || unoIdentifier == "FLT_MAX_10_EXP"
     253           0 :                 || unoIdentifier == "FLT_MAX_EXP"
     254           0 :                 || unoIdentifier == "FLT_MIN"
     255           0 :                 || unoIdentifier == "FLT_MIN_10_EXP"
     256           0 :                 || unoIdentifier == "FLT_MIN_EXP"
     257           0 :                 || unoIdentifier == "FLT_RADIX"
     258           0 :                 || unoIdentifier == "FLT_ROUNDS"
     259           0 :                 || unoIdentifier == "INT_MAX"
     260           0 :                 || unoIdentifier == "INT_MIN"
     261           0 :                 || unoIdentifier == "LDBL_DIG"
     262           0 :                 || unoIdentifier == "LDBL_EPSILON"
     263           0 :                 || unoIdentifier == "LDBL_MANT_DIG"
     264           0 :                 || unoIdentifier == "LDBL_MAX"
     265           0 :                 || unoIdentifier == "LDBL_MAX_10_EXP"
     266           0 :                 || unoIdentifier == "LDBL_MAX_EXP"
     267           0 :                 || unoIdentifier == "LDBL_MIN"
     268           0 :                 || unoIdentifier == "LDBL_MIN_10_EXP"
     269           0 :                 || unoIdentifier == "LDBL_MIN_EXP"
     270           0 :                 || unoIdentifier == "LONG_MAX"
     271           0 :                 || unoIdentifier == "LONG_MIN"
     272           0 :                 || unoIdentifier == "MB_LEN_MAX"
     273           0 :                 || unoIdentifier == "SCHAR_MAX"
     274           0 :                 || unoIdentifier == "SCHAR_MIN"
     275           0 :                 || unoIdentifier == "SHRT_MAX"
     276           0 :                 || unoIdentifier == "SHRT_MIN"
     277           0 :                 || unoIdentifier == "UCHAR_MAX"
     278           0 :                 || unoIdentifier == "UINT_MAX"
     279           0 :                 || unoIdentifier == "ULONG_MAX"
     280           0 :                 || unoIdentifier == "USHRT_MAX"))
     281             :             || (transmode == ITM_GLOBAL
     282             :                 && (// Standard types:
     283             :                     /* unoIdentifier == "clock_t" */
     284             :                     /* unoIdentifier == "div_t" */
     285           0 :                     unoIdentifier == "FILE"
     286             :                     /* unoIdentifier == "fpos_t" */
     287             :                     /* unoIdentifier == "jmp_buf" */
     288           0 :                     || 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           0 :                     || unoIdentifier == "tm"
     296             :                     /* unoIdentifier == "va_list" */
     297             :                     /* unoIdentifier == "wctrans_t" */
     298             :                     /* unoIdentifier == "wctype_t" */
     299             :                     /* unoIdentifier == "wint_t" */
     300             :                     // Standard namespaces:
     301           0 :                     || unoIdentifier == "std"))
     302             :             // Others:
     303           0 :             || unoIdentifier == "NDEBUG"
     304           0 :             || (forbidden != 0 && unoIdentifier == *forbidden) )
     305             :     {
     306           0 :         rtl::OStringBuffer buf(prefix);
     307           0 :         buf.append('_');
     308           0 :         buf.append(unoIdentifier);
     309           0 :         return buf.makeStringAndClear();
     310             :     } else {
     311           0 :         return unoIdentifier;
     312             :     }
     313             : }
     314             : 
     315             : } }
     316             : 
     317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10