Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / idlc / source / astdeclaration.cxx
blobef099632315392bcb416647e723ed28cc13b7fab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <idlc/astdeclaration.hxx>
21 #include <idlc/astscope.hxx>
22 #include <rtl/strbuf.hxx>
24 using namespace ::rtl;
26 static OString sGlobal("::");
28 static OString convertName(const OString& name)
30 OStringBuffer nameBuffer(name.getLength()+1);
31 sal_Int32 nIndex = 0;
34 OString token( name.getToken( 0, ':', nIndex ) );
35 if( !token.isEmpty() )
37 nameBuffer.append('/');
38 nameBuffer.append( token );
40 } while( nIndex != -1 );
41 return nameBuffer.makeStringAndClear();
44 AstDeclaration::AstDeclaration(NodeType type, const OString& name, AstScope* pScope)
45 : m_localName(name)
46 , m_pScope(pScope)
47 , m_nodeType(type)
48 , m_bImported(sal_False)
49 , m_bIsAdded(sal_False)
50 , m_bInMainFile(sal_False)
51 , m_bPredefined(false)
53 if ( m_pScope )
55 AstDeclaration* pDecl = scopeAsDecl(m_pScope);
56 if (pDecl)
58 m_scopedName = pDecl->getScopedName();
59 if (!m_scopedName.isEmpty())
60 m_scopedName += sGlobal;
61 m_scopedName += m_localName;
63 } else
65 m_scopedName = m_localName;
67 m_fullName = convertName(m_scopedName);
69 if ( idlc()->getFileName() == idlc()->getRealFileName() )
71 m_fileName = idlc()->getMainFileName();
72 m_bInMainFile = sal_True;
73 } else
75 m_fileName = idlc()->getFileName();
76 m_bImported = sal_True;
79 m_documentation = idlc()->processDocumentation();
81 m_bPublished = idlc()->isPublished();
85 AstDeclaration::~AstDeclaration()
90 void AstDeclaration::setPredefined(bool bPredefined)
92 m_bPredefined = bPredefined;
93 if ( m_bPredefined )
95 m_fileName = OString();
96 m_bInMainFile = sal_False;
100 void AstDeclaration::setName(const ::rtl::OString& name)
102 m_scopedName = name;
103 sal_Int32 nIndex = name.lastIndexOf( ':' );
104 m_localName = name.copy( nIndex+1 );
106 // Huh ? There is always at least one token
108 // sal_Int32 count = name.getTokenCount(':');
110 // if ( count > 0 )
111 // {
112 // m_localName = name.getToken(count-1, ':');
113 // m_scopedName = name;
114 // } else if ( m_pScope )
115 // {
116 // m_localName = name;
117 // AstDeclaration* pDecl = scopeAsDecl(m_pScope);
118 // if (pDecl)
119 // {
120 // m_scopedName = pDecl->getScopedName();
121 // if (m_scopedName.getLength() > 0)
122 // m_scopedName += sGlobal;
123 // m_scopedName += m_localName;
124 // }
125 // } else
126 // {
127 // m_localName = name;
128 // m_scopedName = name;
129 // }
130 m_fullName = convertName(m_scopedName);
133 bool AstDeclaration::isType() const {
134 switch (m_nodeType) {
135 case NT_interface:
136 case NT_instantiated_struct:
137 case NT_union:
138 case NT_enum:
139 case NT_sequence:
140 case NT_array:
141 case NT_typedef:
142 case NT_predefined:
143 case NT_type_parameter:
144 return true;
146 default:
147 OSL_ASSERT(m_nodeType != NT_struct); // see AstStruct::isType
148 return false;
152 sal_Bool AstDeclaration::hasAncestor(AstDeclaration* pDecl)
154 if (this == pDecl)
155 return sal_True;
156 if ( !m_pScope )
157 return sal_False;
158 return scopeAsDecl(m_pScope)->hasAncestor(pDecl);
161 sal_Bool AstDeclaration::dump(RegistryKey& rKey)
163 AstScope* pScope = declAsScope(this);
164 sal_Bool bRet = sal_True;
166 if ( pScope )
168 DeclList::const_iterator iter = pScope->getIteratorBegin();
169 DeclList::const_iterator end = pScope->getIteratorEnd();
170 AstDeclaration* pDecl = NULL;
171 while ( iter != end && bRet)
173 pDecl = *iter;
174 if ( pDecl->isInMainfile() )
176 switch ( pDecl->getNodeType() )
178 case NT_module:
179 case NT_constants:
180 case NT_interface:
181 case NT_struct:
182 case NT_exception:
183 case NT_enum:
184 case NT_union:
185 case NT_typedef:
186 case NT_service:
187 case NT_singleton:
188 bRet = pDecl->dump(rKey);
189 break;
190 default:
191 break;
195 ++iter;
198 return bRet;
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */