xref: /AOO41X/main/idlc/source/astdeclaration.cxx (revision 2fe1ca3d80babb7c0b18eb5dd968c2181ca17fa3)
1*2fe1ca3dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2fe1ca3dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2fe1ca3dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2fe1ca3dSAndrew Rist  * distributed with this work for additional information
6*2fe1ca3dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2fe1ca3dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2fe1ca3dSAndrew Rist  * "License"); you may not use this file except in compliance
9*2fe1ca3dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2fe1ca3dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2fe1ca3dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2fe1ca3dSAndrew Rist  * software distributed under the License is distributed on an
15*2fe1ca3dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2fe1ca3dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2fe1ca3dSAndrew Rist  * specific language governing permissions and limitations
18*2fe1ca3dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2fe1ca3dSAndrew Rist  *************************************************************/
21*2fe1ca3dSAndrew Rist 
22*2fe1ca3dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_idlc.hxx"
26cdf0e10cSrcweir #include <idlc/astdeclaration.hxx>
27cdf0e10cSrcweir #include <idlc/astscope.hxx>
28cdf0e10cSrcweir #include <rtl/strbuf.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ::rtl;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir static OString sGlobal("::");
33cdf0e10cSrcweir 
convertName(const OString & name)34cdf0e10cSrcweir static OString convertName(const OString& name)
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 	OStringBuffer nameBuffer(name.getLength()+1);
37cdf0e10cSrcweir     sal_Int32 nIndex = 0;
38cdf0e10cSrcweir     do
39cdf0e10cSrcweir     {
40cdf0e10cSrcweir         OString token( name.getToken( 0, ':', nIndex ) );
41cdf0e10cSrcweir         if( token.getLength() )
42cdf0e10cSrcweir         {
43cdf0e10cSrcweir 			nameBuffer.append('/');
44cdf0e10cSrcweir             nameBuffer.append( token );
45cdf0e10cSrcweir         }
46cdf0e10cSrcweir     } while( nIndex != -1 );
47cdf0e10cSrcweir 	return nameBuffer.makeStringAndClear();
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
AstDeclaration(NodeType type,const OString & name,AstScope * pScope)50cdf0e10cSrcweir AstDeclaration::AstDeclaration(NodeType type, const OString& name, AstScope* pScope)
51cdf0e10cSrcweir 	: m_localName(name)
52cdf0e10cSrcweir 	, m_pScope(pScope)
53cdf0e10cSrcweir 	, m_nodeType(type)
54cdf0e10cSrcweir 	, m_bImported(sal_False)
55cdf0e10cSrcweir 	, m_bIsAdded(sal_False)
56cdf0e10cSrcweir 	, m_bInMainFile(sal_False)
57cdf0e10cSrcweir     , m_bPredefined(false)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	if ( m_pScope )
60cdf0e10cSrcweir 	{
61cdf0e10cSrcweir 		AstDeclaration* pDecl = scopeAsDecl(m_pScope);
62cdf0e10cSrcweir 		if (pDecl)
63cdf0e10cSrcweir 		{
64cdf0e10cSrcweir 			m_scopedName = pDecl->getScopedName();
65cdf0e10cSrcweir 			if (m_scopedName.getLength() > 0)
66cdf0e10cSrcweir 				m_scopedName += sGlobal;
67cdf0e10cSrcweir 			m_scopedName +=	m_localName;
68cdf0e10cSrcweir 		}
69cdf0e10cSrcweir 	} else
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		m_scopedName = m_localName;
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir 	m_fullName = convertName(m_scopedName);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	if ( idlc()->getFileName() == idlc()->getRealFileName() )
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir 		m_fileName = idlc()->getMainFileName();
78cdf0e10cSrcweir 		m_bInMainFile = sal_True;
79cdf0e10cSrcweir 	} else
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		m_fileName = idlc()->getFileName();
82cdf0e10cSrcweir 		m_bImported = sal_True;
83cdf0e10cSrcweir 	}
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	if ( idlc()->isDocValid() )
86cdf0e10cSrcweir 		m_documentation = OStringToOUString(idlc()->getDocumentation(), RTL_TEXTENCODING_UTF8);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     m_bPublished = idlc()->isPublished();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
~AstDeclaration()92cdf0e10cSrcweir AstDeclaration::~AstDeclaration()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
setPredefined(bool bPredefined)97cdf0e10cSrcweir void AstDeclaration::setPredefined(bool bPredefined)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     m_bPredefined = bPredefined;
100cdf0e10cSrcweir     if ( m_bPredefined )
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         m_fileName = OString();
103cdf0e10cSrcweir         m_bInMainFile = sal_False;
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
setName(const::rtl::OString & name)107cdf0e10cSrcweir void AstDeclaration::setName(const ::rtl::OString& name)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     m_scopedName = name;
110cdf0e10cSrcweir     sal_Int32 nIndex = name.lastIndexOf( ':' );
111cdf0e10cSrcweir     m_localName = name.copy( nIndex+1 );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir // Huh ? There is always at least one token
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // 	sal_Int32 count = name.getTokenCount(':');
116cdf0e10cSrcweir 
117cdf0e10cSrcweir // 	if ( count > 0 )
118cdf0e10cSrcweir // 	{
119cdf0e10cSrcweir // 		m_localName = name.getToken(count-1, ':');
120cdf0e10cSrcweir // 		m_scopedName = name;
121cdf0e10cSrcweir // 	} else if ( m_pScope )
122cdf0e10cSrcweir // 	{
123cdf0e10cSrcweir // 		m_localName = name;
124cdf0e10cSrcweir // 		AstDeclaration* pDecl = scopeAsDecl(m_pScope);
125cdf0e10cSrcweir // 		if (pDecl)
126cdf0e10cSrcweir // 		{
127cdf0e10cSrcweir // 			m_scopedName = pDecl->getScopedName();
128cdf0e10cSrcweir // 			if (m_scopedName.getLength() > 0)
129cdf0e10cSrcweir // 				m_scopedName += sGlobal;
130cdf0e10cSrcweir // 			m_scopedName +=	m_localName;
131cdf0e10cSrcweir // 		}
132cdf0e10cSrcweir // 	} else
133cdf0e10cSrcweir // 	{
134cdf0e10cSrcweir // 		m_localName = name;
135cdf0e10cSrcweir // 		m_scopedName = name;
136cdf0e10cSrcweir // 	}
137cdf0e10cSrcweir 	m_fullName = convertName(m_scopedName);
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
isType() const140cdf0e10cSrcweir bool AstDeclaration::isType() const {
141cdf0e10cSrcweir     switch (m_nodeType) {
142cdf0e10cSrcweir     case NT_interface:
143cdf0e10cSrcweir     case NT_instantiated_struct:
144cdf0e10cSrcweir     case NT_union:
145cdf0e10cSrcweir     case NT_enum:
146cdf0e10cSrcweir     case NT_sequence:
147cdf0e10cSrcweir     case NT_array:
148cdf0e10cSrcweir     case NT_typedef:
149cdf0e10cSrcweir     case NT_predefined:
150cdf0e10cSrcweir     case NT_type_parameter:
151cdf0e10cSrcweir         return true;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     default:
154cdf0e10cSrcweir         OSL_ASSERT(m_nodeType != NT_struct); // see AstStruct::isType
155cdf0e10cSrcweir         return false;
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
hasAncestor(AstDeclaration * pDecl)159cdf0e10cSrcweir sal_Bool AstDeclaration::hasAncestor(AstDeclaration* pDecl)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	if (this == pDecl)
162cdf0e10cSrcweir 		return sal_True;
163cdf0e10cSrcweir 	if ( !m_pScope )
164cdf0e10cSrcweir 		return sal_False;
165cdf0e10cSrcweir 	return scopeAsDecl(m_pScope)->hasAncestor(pDecl);
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
dump(RegistryKey & rKey)168cdf0e10cSrcweir sal_Bool AstDeclaration::dump(RegistryKey& rKey)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	AstScope* pScope = declAsScope(this);
171cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	if ( pScope )
174cdf0e10cSrcweir 	{
175cdf0e10cSrcweir         DeclList::const_iterator iter = pScope->getIteratorBegin();
176cdf0e10cSrcweir 		DeclList::const_iterator end = pScope->getIteratorEnd();
177cdf0e10cSrcweir 		AstDeclaration* pDecl = NULL;
178cdf0e10cSrcweir 		while ( iter != end && bRet)
179cdf0e10cSrcweir 		{
180cdf0e10cSrcweir 			pDecl = *iter;
181cdf0e10cSrcweir 			if ( pDecl->isInMainfile() )
182cdf0e10cSrcweir 			{
183cdf0e10cSrcweir 				switch ( pDecl->getNodeType() )
184cdf0e10cSrcweir 				{
185cdf0e10cSrcweir 					case NT_module:
186cdf0e10cSrcweir 					case NT_constants:
187cdf0e10cSrcweir 					case NT_interface:
188cdf0e10cSrcweir 					case NT_struct:
189cdf0e10cSrcweir 					case NT_exception:
190cdf0e10cSrcweir 					case NT_enum:
191cdf0e10cSrcweir 					case NT_union:
192cdf0e10cSrcweir 					case NT_typedef:
193cdf0e10cSrcweir 					case NT_service:
194cdf0e10cSrcweir 					case NT_singleton:
195cdf0e10cSrcweir 						bRet = pDecl->dump(rKey);
196cdf0e10cSrcweir                         break;
197cdf0e10cSrcweir                     default:
198cdf0e10cSrcweir                         break;
199cdf0e10cSrcweir 				}
200cdf0e10cSrcweir 			}
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 			++iter;
203cdf0e10cSrcweir 		}
204cdf0e10cSrcweir 	}
205cdf0e10cSrcweir 	return bRet;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208