2
Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
20
* This files contains common helpers for using the du-chain in the context of c++
28
#include "cppduchainexport.h"
29
#include <language/duchain/indexedstring.h>
31
#include <language/duchain/identifier.h>
32
#include <language/duchain/types/abstracttype.h>
34
namespace KTextEditor {
40
class ClassMemberDeclaration;
44
class QualifiedIdentifier;
50
class EnvironmentFile;
52
KDEVCPPDUCHAIN_EXPORT extern KDevelop::IndexedIdentifier castIdentifier;
54
KDEVCPPDUCHAIN_EXPORT extern KDevelop::IndexedIdentifier unnamedNamespaceIdentifier;
57
* Searches context, and if the identifier is not found there, in its base-classes, as it should be in c++(Only if it's a class context).
58
* @param topContext should be the top-context from where the search starts. This is needed to resolve template-parameters.
59
* Du-chain must be locked before.
61
KDEVCPPDUCHAIN_EXPORT QList<KDevelop::Declaration*> findLocalDeclarations( KDevelop::DUContext* context, const KDevelop::Identifier& identifier, const KDevelop::TopDUContext* topContext, uint depth = 0 );
64
* Searches for declarations on the same level, either locally within the context, or namespace. \param identifier that will be declared in a given \param context
65
* Tries to follow the C++ rules, that decide where a type may have been forward-declared.
67
QList<KDevelop::Declaration*> findDeclarationsSameLevel(KDevelop::DUContext* context, const KDevelop::Identifier& identifier, const KDevelop::SimpleCursor& position);
70
* Takes and returns a list of declarations together with inheritance-depth.
71
* Since in c++ one declaration with a name in one depth overloads deeper
72
* declarations, they are hidden here.
73
* This also removes forward-declarations when real declarations with the same identifier are in the list.
75
KDEVCPPDUCHAIN_EXPORT QList< QPair<KDevelop::Declaration*, int> > hideOverloadedDeclarations( const QList< QPair<KDevelop::Declaration*, int> >& declarations );
77
/**Tries determining the local class that the given code-context belongs to.
79
* This works within contexts of type DUContext::Other, as well as in argument contexts of type DUContext::Function(also within function definitions).
81
KDEVCPPDUCHAIN_EXPORT KDevelop::Declaration* localClassFromCodeContext(KDevelop::DUContext* context);
83
/**Tries determining the local function that the given code-context belongs to.
85
* This works within contexts of type DUContext::Other, as well as in argument contexts of type DUContext::Function(also within function definitions).
87
KDEVCPPDUCHAIN_EXPORT KDevelop::Declaration* localFunctionFromCodeContext(KDevelop::DUContext* context);
90
* Returns the logical namespace the given context belongs to, visibility-wise.
91
* @param identifier An ending part of identifier of the given context(May be the full identifier)
92
* @param context A context
93
* @param source The context from where to start searching
94
* @return The part of "identifier" that represents a namespace
96
KDEVCPPDUCHAIN_EXPORT KDevelop::QualifiedIdentifier namespaceScopeComponentFromContext(KDevelop::QualifiedIdentifier identifier, const KDevelop::DUContext* context, const KDevelop::TopDUContext* source);
99
* Returns whether the given declaration can be accessed from the given context. Checks for private/protected and such stuff.
100
* @param fromContext The scope-context from where to check. May be zero.
101
* @param declaration The declaration to check access to. Must not be zero.
102
* @param source Top-context fromw here to start the computations
103
* @param declarationContext The context within which the declaration is visible. This can be a different context than declaration->context() in case of inheritance
105
KDEVCPPDUCHAIN_EXPORT bool isAccessible(KDevelop::DUContext* fromContext, KDevelop::ClassMemberDeclaration* declaration, KDevelop::TopDUContext* source, KDevelop::DUContext* declarationContext);
108
* Returns the logical parent-context of the given context. This may be a different than the physical parent-context
109
* in case of external class-definitions.
111
KDEVCPPDUCHAIN_EXPORT KDevelop::DUContext* logicalParentContext(KDevelop::DUContext* context, KDevelop::TopDUContext* source);
114
* Preprocesses the given string, taking the environment from the given environment-file.
115
* DUChain does not need to be locked.
116
* @param line All macros that are defined before this line are used
118
KDEVCPPDUCHAIN_EXPORT QString preprocess( const QString& text, EnvironmentFile* file, int line, QSet<KDevelop::IndexedString> disableMacros = QSet<KDevelop::IndexedString>() );
120
///Extracts a normalized signature and identifier from a specifier like "mySignal(int)"
121
KDEVCPPDUCHAIN_EXPORT QPair<KDevelop::Identifier, QByteArray> qtFunctionSignature(QByteArray fullFunction);
123
///Exchanges all occurences of @param replace in @param id with @param replaceWith
124
KDEVCPPDUCHAIN_EXPORT KDevelop::Identifier exchangeQualifiedIdentifier(KDevelop::Identifier id, KDevelop::QualifiedIdentifier replace, KDevelop::QualifiedIdentifier replaceWith);
126
///Exchanges all occurences of @param replace in @param id with @param replaceWith
127
KDEVCPPDUCHAIN_EXPORT KDevelop::IndexedTypeIdentifier exchangeQualifiedIdentifier(KDevelop::IndexedTypeIdentifier id, KDevelop::QualifiedIdentifier replace, KDevelop::QualifiedIdentifier replaceWith);
129
///Tries to un-typedef the given type using the uses directly before the given declaration.
130
KDEVCPPDUCHAIN_EXPORT KDevelop::IndexedTypeIdentifier unTypedefType(KDevelop::Declaration* decl, KDevelop::IndexedTypeIdentifier type);
132
///Computes an identifier that represents the given type as well as possible. If the type can not be represented as IndexedTypeIdentifier cleanly,
133
///the qualified identifier will be set to an expression.
134
KDEVCPPDUCHAIN_EXPORT KDevelop::IndexedTypeIdentifier identifierForType(KDevelop::AbstractType::Ptr type, KDevelop::TopDUContext* top);
136
///Returns the type that should be used for shortened printing of the same.
137
KDEVCPPDUCHAIN_EXPORT KDevelop::AbstractType::Ptr typeForShortenedString(KDevelop::Declaration* decl);
138
///Returns a shortened string version of the type attached to the given declaration.
139
///@param desiredLength the desired length. No guarantee that the resulting string will be this short. With the default-value, no shortening will happen in most cases.
140
///@param ctx visibility context to consider. All prefixes of types are shortened to the minimum length while staying visible from here
141
///@param stripPrefix this prefix will be stripped from qualified identifiers. This is useful to remove parts of the current context.
142
KDEVCPPDUCHAIN_EXPORT QString shortenedTypeString(KDevelop::Declaration* decl, KDevelop::DUContext* ctx, int desiredLength = 10000, KDevelop::QualifiedIdentifier stripPrefix = KDevelop::QualifiedIdentifier());
143
KDEVCPPDUCHAIN_EXPORT QString shortenedTypeString(KDevelop::AbstractType::Ptr type, KDevelop::DUContext* ctx, int desiredLength = 10000, KDevelop::QualifiedIdentifier stripPrefix = KDevelop::QualifiedIdentifier());
144
KDEVCPPDUCHAIN_EXPORT KDevelop::IndexedTypeIdentifier shortenedTypeIdentifier(KDevelop::AbstractType::Ptr type, KDevelop::DUContext* ctx, int desiredLength = 10000, KDevelop::QualifiedIdentifier stripPrefix = KDevelop::QualifiedIdentifier());
146
///Returns a simplified string version of the given type: Template default-parameters are stripped away, qualified identifiers are simplified so they are as short as possible, while staying visible from the given context.
147
KDEVCPPDUCHAIN_EXPORT QString simplifiedTypeString(KDevelop::AbstractType::Ptr type, KDevelop::DUContext* visibilityFrom);
149
KDEVCPPDUCHAIN_EXPORT bool isFriend(KDevelop::Declaration* _class, KDevelop::Declaration* _friend);
151
///Shortens the type by resolving typedefs that are not useful
152
KDEVCPPDUCHAIN_EXPORT KDevelop::AbstractType::Ptr shortenTypeForViewing(KDevelop::AbstractType::Ptr type);
154
///Returns a type that has all template types replaced with DelayedType's that have their template default parameters stripped away,
155
///and all scope prefixes removed that are redundant within the given context
156
///The returned type should not actively be used in the type-system, but rather only for displaying.
157
KDevelop::AbstractType::Ptr stripType(KDevelop::AbstractType::Ptr type, KDevelop::DUContext* ctx);
159
///Returns the template context attached to this declaration, if any
160
KDEVCPPDUCHAIN_EXPORT KDevelop::DUContext* getTemplateContext(KDevelop::Declaration* decl, const KDevelop::TopDUContext* source = 0);
161
///Returns the template context import by this context, if any
162
KDEVCPPDUCHAIN_EXPORT KDevelop::DUContext* getTemplateContext(KDevelop::DUContext* ctx, const KDevelop::TopDUContext* source = 0);
163
///Removes all prefixes of the qualified identifier that are not required within the current context
164
///(The returned identifier may be empty if the id identifies a namespace that is imported into the current context)
165
KDEVCPPDUCHAIN_EXPORT KDevelop::QualifiedIdentifier stripPrefixes(KDevelop::DUContext* ctx, KDevelop::QualifiedIdentifier id);