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