File indexing completed on 2024-04-21 15:24:17

0001 /*
0002     SPDX-FileCopyrightText: 2008 David Nolden <david.nolden.kdevelop@art-master.de>
0003     SPDX-FileCopyrightText: 2008 Niko Sams <niko.sams@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #include "expressionevaluationresult.h"
0009 #include <language/duchain/identifier.h>
0010 #include <QString>
0011 #include <language/duchain/duchainlock.h>
0012 #include <serialization/itemrepository.h>
0013 #include <language/duchain/duchain.h>
0014 #include <language/duchain/types/identifiedtype.h>
0015 #include <language/duchain/declaration.h>
0016 
0017 #include "duchaindebug.h"
0018 
0019 #define ifDebug(x)
0020 
0021 using namespace KDevelop;
0022 namespace Php
0023 {
0024 
0025 ExpressionEvaluationResult::~ExpressionEvaluationResult()
0026 {
0027 }
0028 
0029 ExpressionEvaluationResult::ExpressionEvaluationResult()
0030     : m_hadUnresolvedIdentifiers(false)/*, isInstance(false)*/
0031 {
0032 }
0033 
0034 void ExpressionEvaluationResult::setDeclaration( Declaration* declaration )
0035 {
0036     ENSURE_CHAIN_READ_LOCKED
0037     setDeclaration(DeclarationPointer(declaration));
0038 }
0039 
0040 void ExpressionEvaluationResult::setDeclaration( DeclarationPointer declaration)
0041 {
0042     QList<DeclarationPointer> decs;
0043     if (declaration) {
0044         decs << declaration;
0045     }
0046     setDeclarations(decs);
0047 }
0048 
0049 void ExpressionEvaluationResult::setDeclarations( QList< Declaration* > declarations )
0050 {
0051     ENSURE_CHAIN_READ_LOCKED
0052     QList<DeclarationPointer> decs;
0053     decs.reserve(declarations.size());
0054     foreach(Declaration* dec, declarations) {
0055         decs << DeclarationPointer(dec);
0056     }
0057     setDeclarations(decs);
0058 }
0059 
0060 void ExpressionEvaluationResult::setDeclarations(QList<DeclarationPointer> declarations)
0061 {
0062     ifDebug(qCDebug(DUCHAIN) << "setting declarations" << declarations.size();)
0063 
0064     m_allDeclarations = declarations;
0065     if (!m_allDeclarations.isEmpty()) {
0066         setType(m_allDeclarations.last()->abstractType());
0067     } else {
0068         setType(AbstractType::Ptr());
0069     }
0070     m_allDeclarationIds.clear();
0071     DUChainReadLocker lock(DUChain::lock());
0072     foreach(const DeclarationPointer& dec, m_allDeclarations) {
0073         m_allDeclarationIds << dec->id();
0074         ifDebug(qCDebug(DUCHAIN) << dec->toString();)
0075     }
0076 }
0077 
0078 AbstractType::Ptr ExpressionEvaluationResult::type() const
0079 {
0080     return m_type;
0081 }
0082 
0083 QList<DeclarationPointer> ExpressionEvaluationResult::allDeclarations() const
0084 {
0085     return m_allDeclarations;
0086 }
0087 
0088 QList<DeclarationId> ExpressionEvaluationResult::allDeclarationIds() const
0089 {
0090     return m_allDeclarationIds;
0091 }
0092 
0093 void ExpressionEvaluationResult::setType(AbstractType::Ptr type)
0094 {
0095     ifDebug(qCDebug(DUCHAIN) << "setting type" << (type ? type->toString() : QString("no type"));)
0096 
0097     m_type = type;
0098 }
0099 
0100 void ExpressionEvaluationResult::setHadUnresolvedIdentifiers(bool v)
0101 {
0102     m_hadUnresolvedIdentifiers = v;
0103 }
0104 
0105 bool ExpressionEvaluationResult::hadUnresolvedIdentifiers() const
0106 {
0107     return m_hadUnresolvedIdentifiers;
0108 }
0109 
0110 
0111 }