LCOV - code coverage report
Current view: top level - idlc/source - astdump.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 148 193 76.7 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.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 <idlc/astmodule.hxx>
      21             : #include <idlc/asttypedef.hxx>
      22             : #include <idlc/astservice.hxx>
      23             : #include <idlc/astconstant.hxx>
      24             : #include <idlc/astattribute.hxx>
      25             : #include <idlc/astinterfacemember.hxx>
      26             : #include <idlc/astservicemember.hxx>
      27             : #include <idlc/astobserves.hxx>
      28             : #include <idlc/astneeds.hxx>
      29             : #include <idlc/astsequence.hxx>
      30             : #include "idlc/astoperation.hxx"
      31             : 
      32             : #include <osl/diagnose.h>
      33             : 
      34             : #include <registry/version.h>
      35             : #include <registry/writer.hxx>
      36             : 
      37         240 : bool AstModule::dump(RegistryKey& rKey)
      38             : {
      39         240 :     OUString emptyStr;
      40         480 :     RegistryKey localKey;
      41         240 :     if ( getNodeType() == NT_root )
      42             :     {
      43         144 :         localKey = rKey;
      44             :     }else
      45             :     {
      46          96 :         if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey) != RegError::NO_ERROR)
      47             :         {
      48             :             fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
      49           0 :                     idlc()->getOptions()->getProgramName().getStr(),
      50           0 :                     getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
      51           0 :             return false;
      52             :         }
      53             :     }
      54             : 
      55         240 :     sal_uInt16          nConst = getNodeCount(NT_const);
      56             : 
      57         240 :     if ( nConst > 0 )
      58             :     {
      59          15 :         RTTypeClass typeClass = RT_TYPE_MODULE;
      60          15 :         if ( getNodeType() == NT_constants )
      61          15 :             typeClass = RT_TYPE_CONSTANTS;
      62             : 
      63             :         typereg::Writer aBlob(
      64             :             m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
      65          15 :             getDocumentation(), emptyStr, typeClass,
      66             :             m_bPublished,
      67          15 :             OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
      68          45 :             nConst, 0, 0);
      69             : 
      70          15 :         DeclList::const_iterator iter = getIteratorBegin();
      71          15 :         DeclList::const_iterator end = getIteratorEnd();
      72          15 :         sal_uInt16 index = 0;
      73          96 :         while ( iter != end )
      74             :         {
      75          66 :             AstDeclaration* pDecl = *iter;
      76         132 :             if ( pDecl->getNodeType() == NT_const &&
      77          66 :                  pDecl->isInMainfile() )
      78             :             {
      79             :                 static_cast<AstConstant*>(pDecl)->dumpBlob(
      80             :                     aBlob, index++,
      81          66 :                     getNodeType() == NT_module && pDecl->isPublished());
      82             :             }
      83          66 :             ++iter;
      84             :         }
      85             : 
      86             :         sal_uInt32 aBlobSize;
      87          15 :         void const * pBlob = aBlob.getBlob(&aBlobSize);
      88             : 
      89          15 :         if (localKey.setValue(emptyStr, RegValueType::BINARY,
      90          15 :                                 const_cast<RegValue>(pBlob), aBlobSize) != RegError::NO_ERROR)
      91             :         {
      92             :             fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
      93           0 :                     idlc()->getOptions()->getProgramName().getStr(),
      94           0 :                     getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
      95           0 :             return false;
      96          15 :         }
      97             :     } else
      98             :     {
      99         225 :         RTTypeClass typeClass = RT_TYPE_MODULE;
     100         225 :         if ( getNodeType() == NT_constants )
     101           1 :             typeClass = RT_TYPE_CONSTANTS;
     102             : 
     103             :         typereg::Writer aBlob(
     104             :             m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
     105         225 :             getDocumentation(), emptyStr, typeClass, m_bPublished,
     106         225 :             OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0, 0, 0,
     107         450 :             0);
     108             : 
     109             :         sal_uInt32 aBlobSize;
     110         225 :         void const * pBlob = aBlob.getBlob(&aBlobSize);
     111             : 
     112         225 :         if ( getNodeType() != NT_root )
     113             :         {
     114          81 :             if (localKey.setValue(emptyStr, RegValueType::BINARY,
     115          81 :                                     const_cast<RegValue>(pBlob), aBlobSize) != RegError::NO_ERROR)
     116             :             {
     117             :                 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
     118           0 :                         idlc()->getOptions()->getProgramName().getStr(),
     119           0 :                         getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
     120           0 :                 return false;
     121             :             }
     122         225 :         }
     123             :     }
     124         240 :     if ( getNodeType() == NT_root )
     125             :     {
     126         144 :         localKey.releaseKey();
     127             :     }
     128         480 :     return AstDeclaration::dump(rKey);
     129             : }
     130             : 
     131          16 : bool AstTypeDef::dump(RegistryKey& rKey)
     132             : {
     133          16 :     OUString emptyStr;
     134          32 :     RegistryKey localKey;
     135          16 :     if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey) != RegError::NO_ERROR)
     136             :     {
     137             :         fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
     138           0 :                 idlc()->getOptions()->getProgramName().getStr(),
     139           0 :                 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
     140           0 :         return false;
     141             :     }
     142             : 
     143             :     typereg::Writer aBlob(
     144             :         m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
     145          16 :         getDocumentation(), emptyStr, RT_TYPE_TYPEDEF, m_bPublished,
     146          48 :         OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 1, 0, 0, 0);
     147             :     aBlob.setSuperTypeName(
     148             :         0,
     149             :         OStringToOUString(
     150          16 :             getBaseType()->getRelativName(), RTL_TEXTENCODING_UTF8));
     151             : 
     152             :     sal_uInt32 aBlobSize;
     153          16 :     void const * pBlob = aBlob.getBlob(&aBlobSize);
     154             : 
     155          16 :     if (localKey.setValue(emptyStr, RegValueType::BINARY, const_cast<RegValue>(pBlob), aBlobSize) != RegError::NO_ERROR)
     156             :     {
     157             :         fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
     158           0 :                 idlc()->getOptions()->getProgramName().getStr(),
     159           0 :                 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
     160           0 :         return false;
     161             :     }
     162             : 
     163          32 :     return true;
     164             : }
     165             : 
     166          46 : bool AstService::dump(RegistryKey& rKey)
     167             : {
     168          46 :     OUString emptyStr;
     169             :     typereg_Version version = m_bPublished
     170          46 :         ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0;
     171          92 :     OString superName;
     172          46 :     sal_uInt16 constructors = 0;
     173          46 :     sal_uInt16 properties = 0;
     174          46 :     sal_uInt16 references = 0;
     175         102 :     for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
     176             :          ++i)
     177             :     {
     178          56 :         switch ((*i)->getNodeType()) {
     179             :         case NT_interface:
     180             :         case NT_typedef:
     181          24 :             version = TYPEREG_VERSION_1;
     182             :             OSL_ASSERT(superName.isEmpty());
     183          24 :             superName = (*i)->getRelativName();
     184          24 :             break;
     185             : 
     186             :         case NT_operation:
     187             :             OSL_ASSERT(getNodeType() == NT_service);
     188          18 :             ++constructors;
     189          18 :             break;
     190             : 
     191             :         case NT_property:
     192             :             OSL_ASSERT(getNodeType() == NT_service);
     193           0 :             ++properties;
     194           0 :             break;
     195             : 
     196             :         case NT_service_member:
     197           9 :             if (getNodeType() == NT_singleton) {
     198             :                 OSL_ASSERT(superName.isEmpty());
     199          15 :                 superName = (static_cast<AstServiceMember *>(*i))->
     200          10 :                     getRealService()->getRelativName();
     201           5 :                 break;
     202             :             }
     203             :         case NT_interface_member:
     204             :         case NT_observes:
     205             :         case NT_needs:
     206             :             OSL_ASSERT(getNodeType() == NT_service);
     207           9 :             ++references;
     208           9 :             break;
     209             : 
     210             :         default:
     211             :             OSL_ASSERT(false);
     212           0 :             break;
     213             :         }
     214             :     }
     215             :     OSL_ASSERT(constructors == 0 || !m_defaultConstructor);
     216          46 :     if (m_defaultConstructor) {
     217           4 :         constructors = 1;
     218             :     }
     219          46 :     RegistryKey localKey;
     220          92 :     if (rKey.createKey(
     221          46 :             OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8),
     222          92 :             localKey) != RegError::NO_ERROR) {
     223             :         fprintf(
     224             :             stderr, "%s: warning, could not create key '%s' in '%s'\n",
     225           0 :             idlc()->getOptions()->getProgramName().getStr(),
     226           0 :             getFullName().getStr(),
     227             :             OUStringToOString(
     228           0 :                 rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
     229           0 :         return false;
     230             :     }
     231             :     typereg::Writer writer(
     232          46 :         version, getDocumentation(), emptyStr,
     233          46 :         getNodeType() == NT_singleton ? RT_TYPE_SINGLETON : RT_TYPE_SERVICE,
     234             :         m_bPublished,
     235          46 :         OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
     236          46 :         superName.isEmpty() ? 0 : 1, properties, constructors,
     237         276 :         references);
     238          46 :     if (!superName.isEmpty()) {
     239             :         writer.setSuperTypeName(
     240          29 :             0, OStringToOUString(superName, RTL_TEXTENCODING_UTF8));
     241             :     }
     242          46 :     sal_uInt16 constructorIndex = 0;
     243          46 :     sal_uInt16 propertyIndex = 0;
     244          46 :     sal_uInt16 referenceIndex = 0;
     245         102 :     for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd(); ++i)
     246             :     {
     247          56 :         switch ((*i)->getNodeType()) {
     248             :         case NT_operation:
     249          18 :             static_cast<AstOperation *>(*i)->dumpBlob(writer, constructorIndex++);
     250          18 :             break;
     251             : 
     252             :         case NT_property:
     253           0 :             static_cast<AstAttribute *>(*i)->dumpBlob(writer, propertyIndex++, 0);
     254           0 :             break;
     255             : 
     256             :         case NT_interface_member:
     257             :         {
     258           5 :             AstInterfaceMember * decl = static_cast<AstInterfaceMember *>(*i);
     259             :             writer.setReferenceData(
     260           5 :                 referenceIndex++, decl->getDocumentation(), RTReferenceType::SUPPORTS,
     261           5 :                 (decl->isOptional() ? RTFieldAccess::OPTIONAL : RTFieldAccess::INVALID),
     262           5 :                 OStringToOUString( decl->getRealInterface()->getRelativName(),
     263          15 :                                         RTL_TEXTENCODING_UTF8));
     264           5 :             break;
     265             :         }
     266             : 
     267             :         case NT_service_member:
     268           9 :             if (getNodeType() == NT_service)
     269             :             {
     270           4 :                 AstServiceMember * decl = static_cast<AstServiceMember *>(*i);
     271           4 :                 writer.setReferenceData(referenceIndex++, decl->getDocumentation(), RTReferenceType::EXPORTS,
     272           4 :                     (decl->isOptional() ? RTFieldAccess::OPTIONAL : RTFieldAccess::INVALID),
     273           4 :                     OStringToOUString(decl->getRealService()->getRelativName(),
     274          12 :                                            RTL_TEXTENCODING_UTF8));
     275             :             }
     276           9 :             break;
     277             : 
     278             :         case NT_observes:
     279             :             {
     280           0 :                 AstObserves * decl = static_cast<AstObserves *>(*i);
     281           0 :                 writer.setReferenceData(referenceIndex++, decl->getDocumentation(), RTReferenceType::OBSERVES,
     282             :                     RTFieldAccess::INVALID,
     283           0 :                     OStringToOUString( decl->getRealInterface()->getRelativName(),
     284           0 :                                             RTL_TEXTENCODING_UTF8));
     285           0 :                 break;
     286             :             }
     287             : 
     288             :         case NT_needs:
     289             :             {
     290           0 :                 AstNeeds * decl = static_cast<AstNeeds *>(*i);
     291           0 :                 writer.setReferenceData( referenceIndex++, decl->getDocumentation(), RTReferenceType::NEEDS,
     292             :                     RTFieldAccess::INVALID,
     293           0 :                     OStringToOUString( decl->getRealService()->getRelativName(),
     294           0 :                                             RTL_TEXTENCODING_UTF8));
     295           0 :                 break;
     296             :             }
     297             : 
     298             :         default:
     299             :             OSL_ASSERT( (*i)->getNodeType() == NT_interface || (*i)->getNodeType() == NT_typedef);
     300          24 :             break;
     301             :         }
     302             :     }
     303          46 :     if (m_defaultConstructor) {
     304             :         writer.setMethodData(
     305             :             constructorIndex++, emptyStr, RTMethodMode::TWOWAY,
     306             :             emptyStr, OUString("void"),
     307           4 :             0, 0);
     308             :     }
     309             :     sal_uInt32 size;
     310          46 :     void const * blob = writer.getBlob(&size);
     311          46 :     if (localKey.setValue(
     312             :             emptyStr, RegValueType::BINARY, const_cast< void * >(blob),
     313          46 :             size) != RegError::NO_ERROR)
     314             :     {
     315             :         fprintf(
     316             :             stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
     317           0 :             idlc()->getOptions()->getProgramName().getStr(),
     318           0 :             getFullName().getStr(),
     319             :             OUStringToOString(
     320           0 :                 localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
     321           0 :         return false;
     322             :     }
     323         138 :     return true;
     324             : }
     325             : 
     326          23 : bool AstAttribute::dumpBlob(
     327             :     typereg::Writer & rBlob, sal_uInt16 index, sal_uInt16 * methodIndex)
     328             : {
     329          23 :     RTFieldAccess accessMode = RTFieldAccess::INVALID;
     330             : 
     331          23 :     if (isReadonly())
     332             :     {
     333           3 :         accessMode |= RTFieldAccess::READONLY;
     334             :     } else
     335             :     {
     336          20 :         accessMode |= RTFieldAccess::READWRITE;
     337             :     }
     338          23 :     if (isOptional())
     339             :     {
     340           0 :         accessMode |= RTFieldAccess::OPTIONAL;
     341             :     }
     342          23 :     if (isBound())
     343             :     {
     344           4 :         accessMode |= RTFieldAccess::BOUND;
     345             :     }
     346          23 :     if (isMayBeVoid())
     347             :     {
     348           0 :         accessMode |= RTFieldAccess::MAYBEVOID;
     349             :     }
     350          23 :     if (isConstrained())
     351             :     {
     352           0 :         accessMode |= RTFieldAccess::CONSTRAINED;
     353             :     }
     354          23 :     if (isTransient())
     355             :     {
     356           0 :         accessMode |= RTFieldAccess::TRANSIENT;
     357             :     }
     358          23 :     if (isMayBeAmbiguous())
     359             :     {
     360           0 :         accessMode |= RTFieldAccess::MAYBEAMBIGUOUS;
     361             :     }
     362          23 :     if (isMayBeDefault())
     363             :     {
     364           0 :         accessMode |= RTFieldAccess::MAYBEDEFAULT;
     365             :     }
     366          23 :     if (isRemoveable())
     367             :     {
     368           0 :         accessMode |= RTFieldAccess::REMOVABLE;
     369             :     }
     370             : 
     371          23 :     OUString name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8));
     372             :     rBlob.setFieldData(
     373          23 :         index, getDocumentation(), OUString(), accessMode, name,
     374          23 :         OStringToOUString(getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
     375          69 :         RTConstValue());
     376             :     dumpExceptions(
     377             :         rBlob, m_getDocumentation, m_getExceptions, RTMethodMode::ATTRIBUTE_GET,
     378          23 :         methodIndex);
     379             :     dumpExceptions(
     380             :         rBlob, m_setDocumentation, m_setExceptions, RTMethodMode::ATTRIBUTE_SET,
     381          23 :         methodIndex);
     382             : 
     383          23 :     return true;
     384             : }
     385             : 
     386          46 : void AstAttribute::dumpExceptions(
     387             :     typereg::Writer & writer, OUString const & documentation,
     388             :     DeclList const & exceptions, RTMethodMode flags, sal_uInt16 * methodIndex)
     389             : {
     390          46 :     if (!exceptions.empty()) {
     391             :         OSL_ASSERT(methodIndex != 0);
     392          13 :         sal_uInt16 idx = (*methodIndex)++;
     393             :         // exceptions.size() <= SAL_MAX_UINT16 already checked in
     394             :         // AstInterface::dump:
     395             :         writer.setMethodData(
     396             :             idx, documentation, flags,
     397          13 :             OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8),
     398             :             OUString("void"), 0,
     399          26 :             static_cast< sal_uInt16 >(exceptions.size()));
     400          13 :         sal_uInt16 exceptionIndex = 0;
     401          81 :         for (DeclList::const_iterator i(exceptions.begin());
     402          54 :              i != exceptions.end(); ++i)
     403             :         {
     404             :             writer.setMethodExceptionTypeName(
     405             :                 idx, exceptionIndex++,
     406             :                 OStringToOUString(
     407          14 :                     (*i)->getRelativName(), RTL_TEXTENCODING_UTF8));
     408             :         }
     409             :     }
     410          46 : }
     411             : 
     412           8 : const sal_Char* AstSequence::getRelativName() const
     413             : {
     414           8 :     if ( !m_pRelativName )
     415             :     {
     416           8 :         m_pRelativName = new OString("[]");
     417           8 :         AstDeclaration const * pType = resolveTypedefs( m_pMemberType );
     418           8 :         *m_pRelativName += pType->getRelativName();
     419             :     }
     420             : 
     421           8 :     return m_pRelativName->getStr();
     422             : }
     423             : 
     424             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11