1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_idlc.hxx" 30*cdf0e10cSrcweir #include <idlc/aststruct.hxx> 31*cdf0e10cSrcweir #ifndef _IDLC_ASTMember_HXX_ 32*cdf0e10cSrcweir #include <idlc/astmember.hxx> 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include "registry/version.h" 36*cdf0e10cSrcweir #include "registry/writer.hxx" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using namespace ::rtl; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir AstStruct::AstStruct( 41*cdf0e10cSrcweir const OString& name, std::vector< rtl::OString > const & typeParameters, 42*cdf0e10cSrcweir AstStruct* pBaseType, AstScope* pScope) 43*cdf0e10cSrcweir : AstType(NT_struct, name, pScope) 44*cdf0e10cSrcweir , AstScope(NT_struct) 45*cdf0e10cSrcweir , m_pBaseType(pBaseType) 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir for (std::vector< rtl::OString >::const_iterator i(typeParameters.begin()); 48*cdf0e10cSrcweir i != typeParameters.end(); ++i) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir m_typeParameters.push_back( 51*cdf0e10cSrcweir new AstDeclaration(NT_type_parameter, *i, 0)); 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir AstStruct::AstStruct(const NodeType type, 56*cdf0e10cSrcweir const OString& name, 57*cdf0e10cSrcweir AstStruct* pBaseType, 58*cdf0e10cSrcweir AstScope* pScope) 59*cdf0e10cSrcweir : AstType(type, name, pScope) 60*cdf0e10cSrcweir , AstScope(type) 61*cdf0e10cSrcweir , m_pBaseType(pBaseType) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir AstStruct::~AstStruct() 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir for (DeclList::iterator i(m_typeParameters.begin()); 68*cdf0e10cSrcweir i != m_typeParameters.end(); ++i) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir delete *i; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir AstDeclaration const * AstStruct::findTypeParameter(rtl::OString const & name) 75*cdf0e10cSrcweir const 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir for (DeclList::const_iterator i(m_typeParameters.begin()); 78*cdf0e10cSrcweir i != m_typeParameters.end(); ++i) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir if ((*i)->getLocalName() == name) { 81*cdf0e10cSrcweir return *i; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir return 0; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir bool AstStruct::isType() const { 88*cdf0e10cSrcweir return getNodeType() == NT_struct 89*cdf0e10cSrcweir ? getTypeParameterCount() == 0 : AstDeclaration::isType(); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir sal_Bool AstStruct::dump(RegistryKey& rKey) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir RegistryKey localKey; 95*cdf0e10cSrcweir if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey)) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n", 98*cdf0e10cSrcweir idlc()->getOptions()->getProgramName().getStr(), 99*cdf0e10cSrcweir getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr()); 100*cdf0e10cSrcweir return sal_False; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir if (m_typeParameters.size() > SAL_MAX_UINT16) { 104*cdf0e10cSrcweir fprintf( 105*cdf0e10cSrcweir stderr, 106*cdf0e10cSrcweir ("%s: polymorphic struct type template %s has too many type" 107*cdf0e10cSrcweir " parameters\n"), 108*cdf0e10cSrcweir idlc()->getOptions()->getProgramName().getStr(), 109*cdf0e10cSrcweir getScopedName().getStr()); 110*cdf0e10cSrcweir return false; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir sal_uInt16 nMember = getNodeCount(NT_member); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir RTTypeClass typeClass = RT_TYPE_STRUCT; 116*cdf0e10cSrcweir if ( getNodeType() == NT_exception ) 117*cdf0e10cSrcweir typeClass = RT_TYPE_EXCEPTION; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir OUString emptyStr; 120*cdf0e10cSrcweir typereg::Writer aBlob( 121*cdf0e10cSrcweir (m_typeParameters.empty() && !m_bPublished 122*cdf0e10cSrcweir ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1), 123*cdf0e10cSrcweir getDocumentation(), emptyStr, typeClass, m_bPublished, 124*cdf0e10cSrcweir OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 125*cdf0e10cSrcweir m_pBaseType == 0 ? 0 : 1, nMember, 0, 126*cdf0e10cSrcweir static_cast< sal_uInt16 >(m_typeParameters.size())); 127*cdf0e10cSrcweir if (m_pBaseType != 0) { 128*cdf0e10cSrcweir aBlob.setSuperTypeName( 129*cdf0e10cSrcweir 0, 130*cdf0e10cSrcweir OStringToOUString( 131*cdf0e10cSrcweir m_pBaseType->getRelativName(), RTL_TEXTENCODING_UTF8)); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir if ( nMember > 0 ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir DeclList::const_iterator iter = getIteratorBegin(); 137*cdf0e10cSrcweir DeclList::const_iterator end = getIteratorEnd(); 138*cdf0e10cSrcweir AstDeclaration* pDecl = NULL; 139*cdf0e10cSrcweir AstMember* pMember = NULL; 140*cdf0e10cSrcweir OUString docu; 141*cdf0e10cSrcweir sal_uInt16 index = 0; 142*cdf0e10cSrcweir while ( iter != end ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir pDecl = *iter; 145*cdf0e10cSrcweir if ( pDecl->getNodeType() == NT_member ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir pMember = (AstMember*)pDecl; 148*cdf0e10cSrcweir RTFieldAccess flags = RT_ACCESS_READWRITE; 149*cdf0e10cSrcweir rtl::OString typeName; 150*cdf0e10cSrcweir if (pMember->getType()->getNodeType() == NT_type_parameter) { 151*cdf0e10cSrcweir flags |= RT_ACCESS_PARAMETERIZED_TYPE; 152*cdf0e10cSrcweir typeName = pMember->getType()->getLocalName(); 153*cdf0e10cSrcweir } else { 154*cdf0e10cSrcweir typeName = pMember->getType()->getRelativName(); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir aBlob.setFieldData( 157*cdf0e10cSrcweir index++, pMember->getDocumentation(), emptyStr, flags, 158*cdf0e10cSrcweir OStringToOUString( 159*cdf0e10cSrcweir pMember->getLocalName(), RTL_TEXTENCODING_UTF8), 160*cdf0e10cSrcweir OStringToOUString(typeName, RTL_TEXTENCODING_UTF8), 161*cdf0e10cSrcweir RTConstValue()); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir ++iter; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir sal_uInt16 index = 0; 168*cdf0e10cSrcweir for (DeclList::iterator i(m_typeParameters.begin()); 169*cdf0e10cSrcweir i != m_typeParameters.end(); ++i) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir aBlob.setReferenceData( 172*cdf0e10cSrcweir index++, emptyStr, RT_REF_TYPE_PARAMETER, RT_ACCESS_INVALID, 173*cdf0e10cSrcweir OStringToOUString( 174*cdf0e10cSrcweir (*i)->getLocalName(), RTL_TEXTENCODING_UTF8)); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir sal_uInt32 aBlobSize; 178*cdf0e10cSrcweir void const * pBlob = aBlob.getBlob(&aBlobSize); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY, 181*cdf0e10cSrcweir (RegValue)pBlob, aBlobSize)) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n", 184*cdf0e10cSrcweir idlc()->getOptions()->getProgramName().getStr(), 185*cdf0e10cSrcweir getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr()); 186*cdf0e10cSrcweir return sal_False; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir return sal_True; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192