Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <idlc/astdeclaration.hxx>
21 : #include <idlc/astscope.hxx>
22 : #include <rtl/strbuf.hxx>
23 :
24 : using namespace ::rtl;
25 :
26 0 : static OString sGlobal("::");
27 :
28 0 : static OString convertName(const OString& name)
29 : {
30 0 : OStringBuffer nameBuffer(name.getLength()+1);
31 0 : sal_Int32 nIndex = 0;
32 0 : do
33 : {
34 0 : OString token( name.getToken( 0, ':', nIndex ) );
35 0 : if( !token.isEmpty() )
36 : {
37 0 : nameBuffer.append('/');
38 0 : nameBuffer.append( token );
39 0 : }
40 0 : } while( nIndex != -1 );
41 0 : return nameBuffer.makeStringAndClear();
42 : }
43 :
44 0 : 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 0 : , m_lineNumber(0)
53 : {
54 0 : if ( m_pScope )
55 : {
56 0 : AstDeclaration* pDecl = scopeAsDecl(m_pScope);
57 0 : if (pDecl)
58 : {
59 0 : m_scopedName = pDecl->getScopedName();
60 0 : if (!m_scopedName.isEmpty())
61 0 : m_scopedName += sGlobal;
62 0 : m_scopedName += m_localName;
63 : }
64 : } else
65 : {
66 0 : m_scopedName = m_localName;
67 : }
68 0 : m_fullName = convertName(m_scopedName);
69 :
70 0 : if ( idlc()->getFileName() == idlc()->getRealFileName() )
71 : {
72 0 : m_fileName = idlc()->getMainFileName();
73 0 : m_bInMainFile = true;
74 : } else
75 : {
76 0 : m_fileName = idlc()->getFileName();
77 0 : m_bImported = true;
78 : }
79 :
80 0 : m_documentation = idlc()->processDocumentation();
81 :
82 0 : m_bPublished = idlc()->isPublished();
83 0 : }
84 :
85 :
86 0 : AstDeclaration::~AstDeclaration()
87 : {
88 :
89 0 : }
90 :
91 0 : void AstDeclaration::setPredefined(bool bPredefined)
92 : {
93 0 : m_bPredefined = bPredefined;
94 0 : if ( m_bPredefined )
95 : {
96 0 : m_fileName = OString();
97 0 : m_bInMainFile = false;
98 : }
99 0 : }
100 :
101 0 : bool AstDeclaration::isType() const {
102 0 : 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 0 : return true;
111 :
112 : default:
113 : OSL_ASSERT(m_nodeType != NT_struct); // see AstStruct::isType
114 0 : return false;
115 : }
116 : }
117 :
118 0 : bool AstDeclaration::hasAncestor(AstDeclaration* pDecl)
119 : {
120 0 : if (this == pDecl)
121 0 : return true;
122 0 : if ( !m_pScope )
123 0 : return false;
124 0 : return scopeAsDecl(m_pScope)->hasAncestor(pDecl);
125 : }
126 :
127 0 : bool AstDeclaration::dump(RegistryKey& rKey)
128 : {
129 0 : AstScope* pScope = declAsScope(this);
130 0 : bool bRet = true;
131 :
132 0 : if ( pScope )
133 : {
134 0 : DeclList::const_iterator iter = pScope->getIteratorBegin();
135 0 : DeclList::const_iterator end = pScope->getIteratorEnd();
136 0 : AstDeclaration* pDecl = NULL;
137 0 : while ( iter != end && bRet)
138 : {
139 0 : pDecl = *iter;
140 0 : if ( pDecl->isInMainfile() )
141 : {
142 0 : switch ( pDecl->getNodeType() )
143 : {
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 0 : bRet = pDecl->dump(rKey);
154 0 : break;
155 : default:
156 0 : break;
157 : }
158 : }
159 :
160 0 : ++iter;
161 : }
162 : }
163 0 : return bRet;
164 0 : }
165 :
166 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|