1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_idlc.hxx" 30 #include <idlc/astdeclaration.hxx> 31 #include <idlc/astscope.hxx> 32 #include <rtl/strbuf.hxx> 33 34 using namespace ::rtl; 35 36 static OString sGlobal("::"); 37 38 static OString convertName(const OString& name) 39 { 40 OStringBuffer nameBuffer(name.getLength()+1); 41 sal_Int32 nIndex = 0; 42 do 43 { 44 OString token( name.getToken( 0, ':', nIndex ) ); 45 if( token.getLength() ) 46 { 47 nameBuffer.append('/'); 48 nameBuffer.append( token ); 49 } 50 } while( nIndex != -1 ); 51 return nameBuffer.makeStringAndClear(); 52 } 53 54 AstDeclaration::AstDeclaration(NodeType type, const OString& name, AstScope* pScope) 55 : m_localName(name) 56 , m_pScope(pScope) 57 , m_nodeType(type) 58 , m_bImported(sal_False) 59 , m_bIsAdded(sal_False) 60 , m_bInMainFile(sal_False) 61 , m_bPredefined(false) 62 { 63 if ( m_pScope ) 64 { 65 AstDeclaration* pDecl = scopeAsDecl(m_pScope); 66 if (pDecl) 67 { 68 m_scopedName = pDecl->getScopedName(); 69 if (m_scopedName.getLength() > 0) 70 m_scopedName += sGlobal; 71 m_scopedName += m_localName; 72 } 73 } else 74 { 75 m_scopedName = m_localName; 76 } 77 m_fullName = convertName(m_scopedName); 78 79 if ( idlc()->getFileName() == idlc()->getRealFileName() ) 80 { 81 m_fileName = idlc()->getMainFileName(); 82 m_bInMainFile = sal_True; 83 } else 84 { 85 m_fileName = idlc()->getFileName(); 86 m_bImported = sal_True; 87 } 88 89 if ( idlc()->isDocValid() ) 90 m_documentation = OStringToOUString(idlc()->getDocumentation(), RTL_TEXTENCODING_UTF8); 91 92 m_bPublished = idlc()->isPublished(); 93 } 94 95 96 AstDeclaration::~AstDeclaration() 97 { 98 99 } 100 101 void AstDeclaration::setPredefined(bool bPredefined) 102 { 103 m_bPredefined = bPredefined; 104 if ( m_bPredefined ) 105 { 106 m_fileName = OString(); 107 m_bInMainFile = sal_False; 108 } 109 } 110 111 void AstDeclaration::setName(const ::rtl::OString& name) 112 { 113 m_scopedName = name; 114 sal_Int32 nIndex = name.lastIndexOf( ':' ); 115 m_localName = name.copy( nIndex+1 ); 116 117 // Huh ? There is always at least one token 118 119 // sal_Int32 count = name.getTokenCount(':'); 120 121 // if ( count > 0 ) 122 // { 123 // m_localName = name.getToken(count-1, ':'); 124 // m_scopedName = name; 125 // } else if ( m_pScope ) 126 // { 127 // m_localName = name; 128 // AstDeclaration* pDecl = scopeAsDecl(m_pScope); 129 // if (pDecl) 130 // { 131 // m_scopedName = pDecl->getScopedName(); 132 // if (m_scopedName.getLength() > 0) 133 // m_scopedName += sGlobal; 134 // m_scopedName += m_localName; 135 // } 136 // } else 137 // { 138 // m_localName = name; 139 // m_scopedName = name; 140 // } 141 m_fullName = convertName(m_scopedName); 142 } 143 144 bool AstDeclaration::isType() const { 145 switch (m_nodeType) { 146 case NT_interface: 147 case NT_instantiated_struct: 148 case NT_union: 149 case NT_enum: 150 case NT_sequence: 151 case NT_array: 152 case NT_typedef: 153 case NT_predefined: 154 case NT_type_parameter: 155 return true; 156 157 default: 158 OSL_ASSERT(m_nodeType != NT_struct); // see AstStruct::isType 159 return false; 160 } 161 } 162 163 sal_Bool AstDeclaration::hasAncestor(AstDeclaration* pDecl) 164 { 165 if (this == pDecl) 166 return sal_True; 167 if ( !m_pScope ) 168 return sal_False; 169 return scopeAsDecl(m_pScope)->hasAncestor(pDecl); 170 } 171 172 sal_Bool AstDeclaration::dump(RegistryKey& rKey) 173 { 174 AstScope* pScope = declAsScope(this); 175 sal_Bool bRet = sal_True; 176 177 if ( pScope ) 178 { 179 DeclList::const_iterator iter = pScope->getIteratorBegin(); 180 DeclList::const_iterator end = pScope->getIteratorEnd(); 181 AstDeclaration* pDecl = NULL; 182 while ( iter != end && bRet) 183 { 184 pDecl = *iter; 185 if ( pDecl->isInMainfile() ) 186 { 187 switch ( pDecl->getNodeType() ) 188 { 189 case NT_module: 190 case NT_constants: 191 case NT_interface: 192 case NT_struct: 193 case NT_exception: 194 case NT_enum: 195 case NT_union: 196 case NT_typedef: 197 case NT_service: 198 case NT_singleton: 199 bRet = pDecl->dump(rKey); 200 break; 201 default: 202 break; 203 } 204 } 205 206 ++iter; 207 } 208 } 209 return bRet; 210 } 211 212