1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astdeclaration.cxx,v $
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);
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
)
61 , m_bImported(sal_False
)
62 , m_bIsAdded(sal_False
)
63 , m_bInMainFile(sal_False
)
64 , m_bPredefined(false)
68 AstDeclaration
* pDecl
= scopeAsDecl(m_pScope
);
71 m_scopedName
= pDecl
->getScopedName();
72 if (m_scopedName
.getLength() > 0)
73 m_scopedName
+= sGlobal
;
74 m_scopedName
+= m_localName
;
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
;
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
;
109 m_fileName
= OString();
110 m_bInMainFile
= sal_False
;
114 void AstDeclaration::setName(const ::rtl::OString
& 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(':');
126 // m_localName = name.getToken(count-1, ':');
127 // m_scopedName = name;
128 // } else if ( m_pScope )
130 // m_localName = name;
131 // AstDeclaration* pDecl = scopeAsDecl(m_pScope);
134 // m_scopedName = pDecl->getScopedName();
135 // if (m_scopedName.getLength() > 0)
136 // m_scopedName += sGlobal;
137 // m_scopedName += m_localName;
141 // m_localName = name;
142 // m_scopedName = name;
144 m_fullName
= convertName(m_scopedName
);
147 bool AstDeclaration::isType() const {
148 switch (m_nodeType
) {
150 case NT_instantiated_struct
:
157 case NT_type_parameter
:
161 OSL_ASSERT(m_nodeType
!= NT_struct
); // see AstStruct::isType
166 sal_Bool
AstDeclaration::hasAncestor(AstDeclaration
* pDecl
)
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
;
182 DeclList::const_iterator iter
= pScope
->getIteratorBegin();
183 DeclList::const_iterator end
= pScope
->getIteratorEnd();
184 AstDeclaration
* pDecl
= NULL
;
185 while ( iter
!= end
&& bRet
)
188 if ( pDecl
->isInMainfile() )
190 switch ( pDecl
->getNodeType() )
202 bRet
= pDecl
->dump(rKey
);