diff --git a/language/duchain/classmemberdeclaration.cpp b/language/duchain/classmemberdeclaration.cpp index 2df5b3d4b2..6b01748023 100644 --- a/language/duchain/classmemberdeclaration.cpp +++ b/language/duchain/classmemberdeclaration.cpp @@ -1,202 +1,190 @@ /* This is part of KDevelop Copyright 2002-2005 Roberto Raggi Copyright 2006 Adam Treat Copyright 2006 Hamish Rodda Copyright 2007-2008 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "classmemberdeclaration.h" #include "classmemberdeclarationdata.h" #include "duchainregister.h" #include namespace KDevelop { ClassMemberDeclarationData::ClassMemberDeclarationData() : m_accessPolicy(Declaration::Public) , m_isStatic(false) , m_isAuto(false) , m_isFriend(false) , m_isRegister(false) , m_isExtern(false) , m_isMutable(false) , m_isNative(false) , m_isSynchronized(false) , m_isStrictFP(false) - , m_isAbstract(false) { } ClassMemberDeclaration::ClassMemberDeclaration(const ClassMemberDeclaration& rhs) : Declaration(*new ClassMemberDeclarationData(*rhs.d_func())) { } REGISTER_DUCHAIN_ITEM(ClassMemberDeclaration); Declaration* ClassMemberDeclaration::clonePrivate() const { return new ClassMemberDeclaration(*this); } ClassMemberDeclaration::ClassMemberDeclaration(const RangeInRevision& range, DUContext* context) : Declaration(*new ClassMemberDeclarationData, range ) { d_func_dynamic()->setClassId(this); if( context ) setContext( context ); } ClassMemberDeclaration::ClassMemberDeclaration(ClassMemberDeclarationData& dd, const RangeInRevision& range ) : Declaration(dd, range) { } ClassMemberDeclaration::ClassMemberDeclaration(ClassMemberDeclarationData& dd) : Declaration(dd) { } ClassMemberDeclaration::~ClassMemberDeclaration() { } bool ClassMemberDeclaration::isStatic() const { return d_func()->m_isStatic; } void ClassMemberDeclaration::setStatic(bool isStatic) { d_func_dynamic()->m_isStatic = isStatic; } bool ClassMemberDeclaration::isAuto() const { return d_func()->m_isAuto; } void ClassMemberDeclaration::setAuto(bool isAuto) { d_func_dynamic()->m_isAuto = isAuto; } bool ClassMemberDeclaration::isFriend() const { return d_func()->m_isFriend; } void ClassMemberDeclaration::setFriend(bool isFriend) { d_func_dynamic()->m_isFriend = isFriend; } bool ClassMemberDeclaration::isRegister() const { return d_func()->m_isRegister; } void ClassMemberDeclaration::setRegister(bool isRegister) { d_func_dynamic()->m_isRegister = isRegister; } bool ClassMemberDeclaration::isExtern() const { return d_func()->m_isExtern; } void ClassMemberDeclaration::setExtern(bool isExtern) { d_func_dynamic()->m_isExtern = isExtern; } bool ClassMemberDeclaration::isMutable() const { return d_func()->m_isMutable; } void ClassMemberDeclaration::setMutable(bool isMutable) { d_func_dynamic()->m_isMutable = isMutable; } Declaration::AccessPolicy ClassMemberDeclaration::accessPolicy() const { return d_func()->m_accessPolicy; } void ClassMemberDeclaration::setAccessPolicy(Declaration::AccessPolicy accessPolicy) { d_func_dynamic()->m_accessPolicy = accessPolicy; } bool ClassMemberDeclaration::isNative() const { return d_func()->m_isNative; } void ClassMemberDeclaration::setNative(bool native) { d_func_dynamic()->m_isNative = native; } bool ClassMemberDeclaration::isStrictFP() const { return d_func()->m_isStrictFP; } void ClassMemberDeclaration::setStrictFP(bool strictFP) { d_func_dynamic()->m_isStrictFP = strictFP; } bool ClassMemberDeclaration::isSynchronized() const { return d_func()->m_isSynchronized; } void ClassMemberDeclaration::setSynchronized(bool synchronized) { d_func_dynamic()->m_isSynchronized = synchronized; } -bool ClassMemberDeclaration::isAbstract() const -{ - return d_func()->m_isAbstract; -} - -void ClassMemberDeclaration::setAbstract(bool abstract) -{ - d_func_dynamic()->m_isAbstract = abstract; -} - void ClassMemberDeclaration::setStorageSpecifiers(StorageSpecifiers specifiers) { DUCHAIN_D_DYNAMIC(ClassMemberDeclaration); d->m_isStatic = specifiers & StaticSpecifier; d->m_isAuto = specifiers & AutoSpecifier; d->m_isFriend = specifiers & FriendSpecifier; d->m_isRegister = specifiers & RegisterSpecifier; d->m_isExtern = specifiers & ExternSpecifier; d->m_isMutable = specifiers & MutableSpecifier; d->m_isFinal = specifiers & FinalSpecifier; d->m_isSynchronized = specifiers & SynchronizedSpecifier; d->m_isNative = specifiers & NativeSpecifier; d->m_isStrictFP = specifiers & StrictFPSpecifier; - d->m_isAbstract = specifiers & AbstractSpecifier; } } diff --git a/language/duchain/classmemberdeclaration.h b/language/duchain/classmemberdeclaration.h index 38ebac49de..2ac453a979 100644 --- a/language/duchain/classmemberdeclaration.h +++ b/language/duchain/classmemberdeclaration.h @@ -1,107 +1,103 @@ /* This file is part of KDevelop Copyright 2002-2005 Roberto Raggi Copyright 2006 Adam Treat Copyright 2006 Hamish Rodda Copyright 2007-2008 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_CLASSMEMBERDECLARATION_H #define KDEVPLATFORM_CLASSMEMBERDECLARATION_H #include "declaration.h" namespace KDevelop { class ClassMemberDeclarationData; /** * Represents a single class member definition in a definition-use chain. */ class KDEVPLATFORMLANGUAGE_EXPORT ClassMemberDeclaration : public Declaration { public: ClassMemberDeclaration(const ClassMemberDeclaration& rhs); ClassMemberDeclaration(const RangeInRevision& range, DUContext* context); explicit ClassMemberDeclaration(ClassMemberDeclarationData& dd); ~ClassMemberDeclaration(); AccessPolicy accessPolicy() const; void setAccessPolicy(AccessPolicy accessPolicy); enum StorageSpecifier { StaticSpecifier = 0x1 /**< indicates static member */, AutoSpecifier = 0x2 /**< indicates automatic determination of member access */, FriendSpecifier = 0x4 /**< indicates friend member */, ExternSpecifier = 0x8 /**< indicates external declaration */, RegisterSpecifier = 0x10 /**< indicates register */, MutableSpecifier = 0x20 /**< indicates a mutable member */, FinalSpecifier = 0x40 /**< indicates a final declaration */, NativeSpecifier = 0x80, SynchronizedSpecifier = 0x100, StrictFPSpecifier = 0x200, - AbstractSpecifier = 0x400 }; Q_DECLARE_FLAGS(StorageSpecifiers, StorageSpecifier) void setStorageSpecifiers(StorageSpecifiers specifiers); bool isStatic() const; void setStatic(bool isStatic); bool isAuto() const; void setAuto(bool isAuto); bool isFriend() const; void setFriend(bool isFriend); bool isRegister() const; void setRegister(bool isRegister); bool isExtern() const; void setExtern(bool isExtern); bool isMutable() const; void setMutable(bool isMutable); bool isNative() const; void setNative(bool native); bool isSynchronized() const; void setSynchronized(bool synchronized); bool isStrictFP() const; void setStrictFP(bool strictFP); - bool isAbstract() const; - void setAbstract(bool abstract); - enum { Identity = 9 }; protected: ClassMemberDeclaration(ClassMemberDeclarationData& dd, const RangeInRevision& range); DUCHAIN_DECLARE_DATA(ClassMemberDeclaration) private: Declaration* clonePrivate() const override; }; } Q_DECLARE_OPERATORS_FOR_FLAGS(KDevelop::ClassMemberDeclaration::StorageSpecifiers) #endif // KDEVPLATFORM_CLASSMEMBERDECLARATION_H diff --git a/language/duchain/classmemberdeclarationdata.h b/language/duchain/classmemberdeclarationdata.h index f01f3f5b3c..08fb345ffc 100644 --- a/language/duchain/classmemberdeclarationdata.h +++ b/language/duchain/classmemberdeclarationdata.h @@ -1,53 +1,52 @@ /* This is part of KDevelop Copyright 2002-2005 Roberto Raggi Copyright 2006 Adam Treat Copyright 2006 Hamish Rodda Copyright 2007-2008 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_CLASSMEMBERDECLARATIONDATA_H #define KDEVPLATFORM_CLASSMEMBERDECLARATIONDATA_H #include "declarationdata.h" #include namespace KDevelop { class KDEVPLATFORMLANGUAGE_EXPORT ClassMemberDeclarationData : public DeclarationData { public: ClassMemberDeclarationData(); ClassMemberDeclarationData( const ClassMemberDeclarationData& rhs ) = default; Declaration::AccessPolicy m_accessPolicy; bool m_isStatic: 1; bool m_isAuto: 1; bool m_isFriend: 1; bool m_isRegister: 1; bool m_isExtern: 1; bool m_isMutable: 1; bool m_isFinal: 1; bool m_isNative: 1; bool m_isSynchronized: 1; bool m_isStrictFP: 1; - bool m_isAbstract: 1; }; } #endif diff --git a/tests/json/jsondeclarationtests.h b/tests/json/jsondeclarationtests.h index 2c255870b5..b1ac2cec29 100644 --- a/tests/json/jsondeclarationtests.h +++ b/tests/json/jsondeclarationtests.h @@ -1,346 +1,346 @@ /* This file is part of KDevelop Copyright 2012 Olivier de Gaalon This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_JSONDECLARATIONTESTS_H #define KDEVPLATFORM_JSONDECLARATIONTESTS_H #include "language/duchain/ducontext.h" #include "language/duchain/declaration.h" #include "language/duchain/indexeddeclaration.h" #include "language/duchain/identifier.h" #include "language/duchain/abstractfunctiondeclaration.h" #include "language/duchain/types/typeutils.h" #include "language/duchain/types/identifiedtype.h" #include #include "language/duchain/duchain.h" #include "language/duchain/functiondefinition.h" #include "language/duchain/definitions.h" -#include +#include #include "jsontesthelpers.h" /** * JSON Object Specification: * DeclTestObject: Mapping of (string) declaration test names to values * TypeTestObject: Mapping of (string) type test names to values * CtxtTestObject: Mapping of (string) context test names to values * * Quick Reference: * useCount : int * useRanges : string array * identifier : string * qualifiedIdentifier : string * internalContext : CtxtTestObject * internalFunctionContext : CtxtTestObject * type : TypeTestObject * unaliasedType : TypeTestObject * targetType : TypeTestObject * returnType : TypeTestObject * isAbstract : bool * isMutable : bool * isVirtual : bool * isStatic : bool * declaration : DeclTestObject * definition : DeclTestObject * identifiedTypeDeclaration : DeclTestObject * null : bool * defaultParameter : string * toString : string * range : string * kind : string * isDeprecated : bool * isDefinition : bool */ namespace KDevelop { template<> QString TestSuite::objectInformation(Declaration *decl) { VERIFY_NOT_NULL(decl); return QStringLiteral("(Declaration on line %1 in %2)") .arg(decl->range().start.line + 1) .arg(decl->topContext()->url().str()); } namespace DeclarationTests { using namespace JsonTestHelpers; ///JSON type: int ///@returns whether the declaration's number of uses matches the given value DeclarationTest(useCount) { int uses = 0; foreach(const QList& useRanges, decl->uses()) { uses += useRanges.size(); } return compareValues(uses, value, QStringLiteral("Declaration's use count ")); } ///JSON type: string array ///@returns whether the declaration's ranges match the given value DeclarationTest(useRanges) { QStringList ranges; foreach(const QList& useRanges, decl->uses()) { foreach(const RangeInRevision range, useRanges) { ranges << rangeStr(range); } } const QStringList testValues = value.toStringList(); return ranges == testValues ? SUCCESS() : QStringLiteral("Declaration's use ranges (\"%1\") don't match test data (\"%2\").").arg(ranges.join(QStringLiteral(", ")), testValues.join(QStringLiteral(", "))); } ///JSON type: string ///@returns whether the declaration's identifier matches the given value DeclarationTest(identifier) { VERIFY_NOT_NULL(decl); return compareValues(decl->identifier().toString(), value, QStringLiteral("Declaration's identifier")); } ///JSON type: string ///@returns whether the declaration's qualified identifier matches the given value DeclarationTest(qualifiedIdentifier) { VERIFY_NOT_NULL(decl); return compareValues(decl->qualifiedIdentifier().toString(), value, QStringLiteral("Declaration's qualified identifier")); } ///JSON type: CtxtTestObject ///@returns whether the tests for the declaration's internal context pass DeclarationTest(internalContext) { VERIFY_NOT_NULL(decl); return testObject(decl->internalContext(), value, QStringLiteral("Declaration's internal context")); } ///JSON type: CtxtTestObject ///@returns whether the tests for the declaration's internal function context pass DeclarationTest(internalFunctionContext) { const QString NO_INTERNAL_CTXT = QStringLiteral("%1 has no internal function context."); AbstractFunctionDeclaration *absFuncDecl = dynamic_cast(decl); if (!absFuncDecl || !absFuncDecl->internalFunctionContext()) return NO_INTERNAL_CTXT.arg(decl->qualifiedIdentifier().toString()); return testObject(absFuncDecl->internalFunctionContext(), value, QStringLiteral("Declaration's internal function context")); } /*FIXME: The type functions need some renaming and moving around * Some (all?) functions from cpp's TypeUtils should be moved to the kdevplatform type utils * targetType is exactly like realType except it also tosses pointers * shortenTypeForViewing should go to type utils (and it's broken, it places const to the left of all *'s when it should be left or right of the type) * UnaliasedType seems to be unable to understand aliases involving templates, perhaps a cpp version is in order */ ///JSON type: TypeTestObject ///@returns whether the tests for the declaration's type pass DeclarationTest(type) { VERIFY_NOT_NULL(decl); return testObject(decl->abstractType(), value, QStringLiteral("Declaration's type")); } ///JSON type: TypeTestObject ///@returns whether the tests for the declaration's unaliased type pass (TypeUtils::unaliasedType) DeclarationTest(unaliasedType) { VERIFY_NOT_NULL(decl); return testObject(TypeUtils::unAliasedType(decl->abstractType()), value, QStringLiteral("Declaration's unaliased type")); } ///JSON type: TypeTestObject ///@returns whether the tests for the declaration's target type pass (TypeUtils::targetType) DeclarationTest(targetType) { VERIFY_NOT_NULL(decl); return testObject(TypeUtils::targetType(decl->abstractType(), decl->topContext()), value, QStringLiteral("Declaration's target type")); } ///JSON type: TestTypeObject ///@returns the DeclarationTest(returnType) { FunctionType::Ptr functionType = decl->abstractType().cast(); AbstractType::Ptr returnType; if (functionType) { returnType = functionType->returnType(); } return testObject(returnType, value, QStringLiteral("Declaration's return type")); } ///JSON type: DeclTestObject ///@returns The IdentifiedType's declaration DeclarationTest(identifiedTypeDeclaration) { const QString UN_ID_ERROR = QStringLiteral("Unable to identify declaration of type \"%1\"."); AbstractType::Ptr type = TypeUtils::targetType(decl->abstractType(), decl->topContext()); IdentifiedType* idType = dynamic_cast(type.data()); Declaration* idDecl = idType ? idType->declaration(decl->topContext()) : nullptr; if (!idDecl) return UN_ID_ERROR.arg(type->toString()); return testObject(idDecl, value, QStringLiteral("IdentifiedType's declaration")); } ///JSON type: bool ///@returns whether the (function) declaration's isVirtual matches the given value DeclarationTest(isVirtual) { const QString NOT_A_FUNCTION = QStringLiteral("Non-function declaration cannot be virtual."); AbstractFunctionDeclaration *absFuncDecl = dynamic_cast(decl); if (!absFuncDecl) return NOT_A_FUNCTION; return compareValues(absFuncDecl->isVirtual(), value, QStringLiteral("Declaration's isVirtual")); } ///JSON type: bool ///@returns whether the (function) declaration's isAbstract matches the given value DeclarationTest(isAbstract) { const QString NOT_A_FUNCTION = QStringLiteral("Non-class-member declaration cannot be abstract."); - auto *absFuncDecl = dynamic_cast(decl); + auto *absFuncDecl = dynamic_cast(decl); if (!absFuncDecl) return NOT_A_FUNCTION; return compareValues(absFuncDecl->isAbstract(), value, QStringLiteral("Declaration's isAbstract")); } ///JSON type: bool ///@returns whether the (class-member) declaration's isStatic matches the given value DeclarationTest(isStatic) { const QString NOT_A_MEMBER = QStringLiteral("Non-class-member declaration cannot be static."); auto memberDecl = dynamic_cast(decl); if (!memberDecl) return NOT_A_MEMBER; return compareValues(memberDecl->isStatic(), value, QStringLiteral("Declaration's isStatic")); } ///JSON type: bool ///@returns whether the (class-member) declaration's isMutable matches the given value DeclarationTest(isMutable) { const QString NOT_A_MEMBER = QStringLiteral("Non-class-member declaration cannot be mutable."); auto memberDecl = dynamic_cast(decl); if (!memberDecl) return NOT_A_MEMBER; return compareValues(memberDecl->isMutable(), value, QStringLiteral("Declaration's isMutable")); } ///JSON type: DeclTestObject ///@returns whether the tests for the function declaration's definition pass DeclarationTest(definition) { KDevVarLengthArray definitions = DUChain::definitions()->definitions(decl->id()); Declaration *declDef = nullptr; if (!definitions.isEmpty()) declDef = definitions.at(0).declaration(); return testObject(declDef, value, QStringLiteral("Declaration's definition")); } ///JSON type: DeclTestObject ///@returns whether the tests for the function definition's declaration pass DeclarationTest(declaration) { FunctionDefinition *def = dynamic_cast(decl); Declaration *defDecl = nullptr; if (def) defDecl = def->declaration(decl->topContext()); return testObject(defDecl, value, QStringLiteral("Definition's declaration")); } ///JSON type: bool ///@returns whether the declaration's nullity matches the given value DeclarationTest(null) { return compareValues(decl == nullptr, value, QStringLiteral("Declaration's nullity")); } ///JSON type: bool ///@returns whether the declaration's default parameter matches the given value DeclarationTest(defaultParameter) { const QString NOT_IN_FUNC_CTXT = QStringLiteral("Asked for a default parameter for a declaration outside of a function context."); const QString OWNER_NOT_FUNC = QStringLiteral("Function context not owned by function declaration (what on earth did you do?)."); DUContext *context = decl->context(); if (!context || context->type() != DUContext::Function) return NOT_IN_FUNC_CTXT; AbstractFunctionDeclaration *funcDecl = dynamic_cast(context->owner()); if (!funcDecl) return OWNER_NOT_FUNC; int argIndex = context->localDeclarations().indexOf(decl); return compareValues(funcDecl->defaultParameterForArgument(argIndex).str(), value, QStringLiteral("Declaration's default parameter")); } ///JSON type: string ///@returns stringified declaration DeclarationTest(toString) { VERIFY_NOT_NULL(decl); return compareValues(decl->toString(), value, QStringLiteral("Declaration's toString")); } ///JSON type: string ///@returns stringified declaration range DeclarationTest(range) { VERIFY_NOT_NULL(decl); return compareValues(rangeStr(decl->range()), value, QStringLiteral("Declaration's range")); } ///JSON type: string ///@returns stringified declaration kind DeclarationTest(kind) { VERIFY_NOT_NULL(decl); QString kind; switch (decl->kind()) { case KDevelop::Declaration::Alias: kind = QStringLiteral("Alias"); break; case KDevelop::Declaration::Import: kind = QStringLiteral("Import"); break; case KDevelop::Declaration::Instance: kind = QStringLiteral("Instance"); break; case KDevelop::Declaration::Namespace: kind = QStringLiteral("Namespace"); break; case KDevelop::Declaration::NamespaceAlias: kind = QStringLiteral("NamespaceAlias"); break; case KDevelop::Declaration::Type: kind = QStringLiteral("Type"); break; case KDevelop::Declaration::Macro: kind = QStringLiteral("Macro"); break; } return compareValues(kind, value, QStringLiteral("Declaration's kind")); } ///JSON type: bool ///@returns whether the declaration's isDeprecated matches the given value DeclarationTest(isDeprecated) { VERIFY_NOT_NULL(decl); return compareValues(decl->isDeprecated(), value, QStringLiteral("Declaration's isDeprecated")); } ///JSON type: bool ///@returns whether the declaration's isDefinition matches the given value DeclarationTest(isDefinition) { VERIFY_NOT_NULL(decl); return compareValues(decl->isDefinition(), value, QStringLiteral("Declaration's isDefinition")); } } } #endif //KDEVPLATFORM_JSONDECLARATIONTESTS_H