Changeset View
Changeset View
Standalone View
Standalone View
duchain/helper.cpp
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Line(s) | |||||
124 | { | 124 | { | ||
125 | /// Qualified identifier for 'self' | 125 | /// Qualified identifier for 'self' | ||
126 | static const QualifiedIdentifier selfQId(QStringLiteral("self")); | 126 | static const QualifiedIdentifier selfQId(QStringLiteral("self")); | ||
127 | /// Qualified identifier for 'parent' | 127 | /// Qualified identifier for 'parent' | ||
128 | static const QualifiedIdentifier parentQId(QStringLiteral("parent")); | 128 | static const QualifiedIdentifier parentQId(QStringLiteral("parent")); | ||
129 | /// Qualified identifier for 'static' | 129 | /// Qualified identifier for 'static' | ||
130 | static const QualifiedIdentifier staticQId(QStringLiteral("static")); | 130 | static const QualifiedIdentifier staticQId(QStringLiteral("static")); | ||
131 | 131 | | |||
132 | QualifiedIdentifier lookup; | ||||
133 | | ||||
134 | if (id.explicitlyGlobal()) { | ||||
132 | ifDebug(qCDebug(DUCHAIN) << id.toString() << declarationType;) | 135 | ifDebug(qCDebug(DUCHAIN) << id.toString() << declarationType;) | ||
136 | | ||||
137 | lookup = id; | ||||
138 | lookup.setExplicitlyGlobal(false); | ||||
139 | } else { | ||||
140 | lookup = identifierWithNamespace(id, currentContext); | ||||
141 | | ||||
142 | ifDebug(qCDebug(DUCHAIN) << lookup.toString() << declarationType;) | ||||
143 | } | ||||
144 | | ||||
133 | if (declarationType == ClassDeclarationType && id == selfQId) { | 145 | if (declarationType == ClassDeclarationType && id == selfQId) { | ||
134 | DUChainReadLocker lock(DUChain::lock()); | 146 | DUChainReadLocker lock(DUChain::lock()); | ||
135 | if (currentContext->type() == DUContext::Class) { | 147 | if (currentContext->type() == DUContext::Class) { | ||
136 | return DeclarationPointer(currentContext->owner()); | 148 | return DeclarationPointer(currentContext->owner()); | ||
137 | } else if (currentContext->parentContext() && currentContext->parentContext()->type() == DUContext::Class) { | 149 | } else if (currentContext->parentContext() && currentContext->parentContext()->type() == DUContext::Class) { | ||
138 | return DeclarationPointer(currentContext->parentContext()->owner()); | 150 | return DeclarationPointer(currentContext->parentContext()->owner()); | ||
139 | } else { | 151 | } else { | ||
140 | return DeclarationPointer(); | 152 | return DeclarationPointer(); | ||
Show All 22 Lines | 173 | foreach(const DUContext::Import &i, classCtx->importedParentContexts()) { | |||
163 | if (ctx && ctx->type() == DUContext::Class) { | 175 | if (ctx && ctx->type() == DUContext::Class) { | ||
164 | return DeclarationPointer(ctx->owner()); | 176 | return DeclarationPointer(ctx->owner()); | ||
165 | } | 177 | } | ||
166 | } | 178 | } | ||
167 | } | 179 | } | ||
168 | return DeclarationPointer(); | 180 | return DeclarationPointer(); | ||
169 | } else { | 181 | } else { | ||
170 | DUChainReadLocker lock; | 182 | DUChainReadLocker lock; | ||
171 | QList<Declaration*> foundDeclarations = currentContext->topContext()->findDeclarations(id); | 183 | QList<Declaration*> foundDeclarations = currentContext->topContext()->findDeclarations(lookup); | ||
172 | if (foundDeclarations.isEmpty()) { | | |||
173 | // If it's not in the top context, try the current context (namespaces...) | | |||
174 | // this fixes the bug: https://bugs.kde.org/show_bug.cgi?id=322274 | | |||
175 | foundDeclarations = currentContext->findDeclarations(id); | | |||
176 | } | | |||
177 | if (foundDeclarations.isEmpty()) { | | |||
178 | // If it is neither in the top not the current context it might be defined in a different context | | |||
179 | // Look up with fully qualified identifier | | |||
180 | foundDeclarations = currentContext->topContext()->findDeclarations(identifierWithNamespace(id, currentContext)); | | |||
181 | } | | |||
182 | 184 | | |||
183 | foreach(Declaration *declaration, foundDeclarations) { | 185 | foreach(Declaration *declaration, foundDeclarations) { | ||
184 | if (isMatch(declaration, declarationType)) { | 186 | if (isMatch(declaration, declarationType)) { | ||
185 | return DeclarationPointer(declaration); | 187 | return DeclarationPointer(declaration); | ||
186 | } | 188 | } | ||
187 | } | 189 | } | ||
188 | if ( currentContext->url() == internalFunctionFile() ) { | 190 | if ( currentContext->url() == internalFunctionFile() ) { | ||
189 | // when compiling php internal functions, we don't need to ask the persistent symbol table for anything | 191 | // when compiling php internal functions, we don't need to ask the persistent symbol table for anything | ||
190 | return DeclarationPointer(); | 192 | return DeclarationPointer(); | ||
191 | } | 193 | } | ||
192 | 194 | | |||
193 | lock.unlock(); | 195 | lock.unlock(); | ||
194 | 196 | | |||
195 | if (declarationType != GlobalVariableDeclarationType) { | 197 | if (declarationType != GlobalVariableDeclarationType) { | ||
196 | ifDebug(qCDebug(DUCHAIN) << "No declarations found with findDeclarations, trying through PersistentSymbolTable";) | 198 | ifDebug(qCDebug(DUCHAIN) << "No declarations found with findDeclarations, trying through PersistentSymbolTable";) | ||
197 | DeclarationPointer decl; | 199 | DeclarationPointer decl; | ||
198 | 200 | | |||
199 | decl = findDeclarationInPST(currentContext, id, declarationType); | 201 | decl = findDeclarationInPST(currentContext, lookup, declarationType); | ||
200 | | ||||
201 | if (!decl) | | |||
202 | { | | |||
203 | decl = findDeclarationInPST(currentContext, identifierWithNamespace(id, currentContext), declarationType); | | |||
204 | } | | |||
205 | 202 | | |||
206 | if (decl) { | 203 | if (decl) { | ||
207 | ifDebug(qCDebug(DUCHAIN) << "PST declaration exists";) | 204 | ifDebug(qCDebug(DUCHAIN) << "PST declaration exists";) | ||
208 | } else { | 205 | } else { | ||
209 | ifDebug(qCDebug(DUCHAIN) << "PST declaration does not exist";) | 206 | ifDebug(qCDebug(DUCHAIN) << "PST declaration does not exist";) | ||
210 | } | 207 | } | ||
211 | return decl; | 208 | return decl; | ||
212 | } | 209 | } | ||
▲ Show 20 Lines • Show All 390 Lines • Show Last 20 Lines |