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