Bump version to 4.3-4
[LibreOffice.git] / idlc / source / astdeclaration.cxx
blob4840eca74f6a93d978122e90af964e31474910b5
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(false)
49 , m_bIsAdded(false)
50 , m_bInMainFile(false)
51 , m_bPredefined(false)
52 , m_lineNumber(0)
54 if ( m_pScope )
56 AstDeclaration* pDecl = scopeAsDecl(m_pScope);
57 if (pDecl)
59 m_scopedName = pDecl->getScopedName();
60 if (!m_scopedName.isEmpty())
61 m_scopedName += sGlobal;
62 m_scopedName += m_localName;
64 } else
66 m_scopedName = m_localName;
68 m_fullName = convertName(m_scopedName);
70 if ( idlc()->getFileName() == idlc()->getRealFileName() )
72 m_fileName = idlc()->getMainFileName();
73 m_bInMainFile = true;
74 } else
76 m_fileName = idlc()->getFileName();
77 m_bImported = true;
80 m_documentation = idlc()->processDocumentation();
82 m_bPublished = idlc()->isPublished();
86 AstDeclaration::~AstDeclaration()
91 void AstDeclaration::setPredefined(bool bPredefined)
93 m_bPredefined = bPredefined;
94 if ( m_bPredefined )
96 m_fileName = OString();
97 m_bInMainFile = false;
101 bool AstDeclaration::isType() const {
102 switch (m_nodeType) {
103 case NT_interface:
104 case NT_instantiated_struct:
105 case NT_enum:
106 case NT_sequence:
107 case NT_typedef:
108 case NT_predefined:
109 case NT_type_parameter:
110 return true;
112 default:
113 OSL_ASSERT(m_nodeType != NT_struct); // see AstStruct::isType
114 return false;
118 bool AstDeclaration::hasAncestor(AstDeclaration* pDecl)
120 if (this == pDecl)
121 return true;
122 if ( !m_pScope )
123 return false;
124 return scopeAsDecl(m_pScope)->hasAncestor(pDecl);
127 bool AstDeclaration::dump(RegistryKey& rKey)
129 AstScope* pScope = declAsScope(this);
130 bool bRet = true;
132 if ( pScope )
134 DeclList::const_iterator iter = pScope->getIteratorBegin();
135 DeclList::const_iterator end = pScope->getIteratorEnd();
136 AstDeclaration* pDecl = NULL;
137 while ( iter != end && bRet)
139 pDecl = *iter;
140 if ( pDecl->isInMainfile() )
142 switch ( pDecl->getNodeType() )
144 case NT_module:
145 case NT_constants:
146 case NT_interface:
147 case NT_struct:
148 case NT_exception:
149 case NT_enum:
150 case NT_typedef:
151 case NT_service:
152 case NT_singleton:
153 bRet = pDecl->dump(rKey);
154 break;
155 default:
156 break;
160 ++iter;
163 return bRet;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */