~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/cppduchain/cppduchain.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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.
 
17
*/
 
18
 
 
19
/**
 
20
 * This files contains common helpers for using the du-chain in the context of c++
 
21
 * */
 
22
 
 
23
#ifndef CPPDUCHAIN_H
 
24
#define CPPDUCHAIN_H
 
25
 
 
26
#include <QList>
 
27
#include <QPair>
 
28
#include "cppduchainexport.h"
 
29
#include <language/duchain/indexedstring.h>
 
30
#include <QSet>
 
31
#include <language/duchain/identifier.h>
 
32
#include <language/duchain/types/abstracttype.h>
 
33
 
 
34
namespace KTextEditor {
 
35
  class Cursor;
 
36
}
 
37
 
 
38
namespace KDevelop {
 
39
  class Declaration;
 
40
  class ClassMemberDeclaration;
 
41
  class DUContext;
 
42
  class TopDUContext;
 
43
  class Identifier;
 
44
  class QualifiedIdentifier;
 
45
  class SimpleCursor;
 
46
  class IndexedString;
 
47
}
 
48
 
 
49
namespace Cpp {
 
50
  class EnvironmentFile;
 
51
  
 
52
KDEVCPPDUCHAIN_EXPORT extern KDevelop::IndexedIdentifier castIdentifier;
 
53
 
 
54
KDEVCPPDUCHAIN_EXPORT extern KDevelop::IndexedIdentifier unnamedNamespaceIdentifier;
 
55
  
 
56
/**
 
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.
 
60
 * */
 
61
KDEVCPPDUCHAIN_EXPORT QList<KDevelop::Declaration*> findLocalDeclarations( KDevelop::DUContext* context, const KDevelop::Identifier& identifier, const KDevelop::TopDUContext* topContext, uint depth = 0 );
 
62
 
 
63
/**
 
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.
 
66
 * */
 
67
QList<KDevelop::Declaration*> findDeclarationsSameLevel(KDevelop::DUContext* context, const KDevelop::Identifier& identifier, const KDevelop::SimpleCursor& position);
 
68
 
 
69
/**
 
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.
 
74
 * */
 
75
KDEVCPPDUCHAIN_EXPORT QList< QPair<KDevelop::Declaration*, int> > hideOverloadedDeclarations( const QList< QPair<KDevelop::Declaration*, int> >& declarations );
 
76
 
 
77
  /**Tries determining the local class that the given code-context belongs to.
 
78
   *
 
79
   * This works within contexts of type DUContext::Other, as well as in argument contexts of type DUContext::Function(also within function definitions).
 
80
   */
 
81
KDEVCPPDUCHAIN_EXPORT KDevelop::Declaration* localClassFromCodeContext(KDevelop::DUContext* context);
 
82
 
 
83
  /**Tries determining the local function that the given code-context belongs to.
 
84
   *
 
85
   * This works within contexts of type DUContext::Other, as well as in argument contexts of type DUContext::Function(also within function definitions).
 
86
   */
 
87
KDEVCPPDUCHAIN_EXPORT KDevelop::Declaration* localFunctionFromCodeContext(KDevelop::DUContext* context);
 
88
 
 
89
  /**
 
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
 
95
   */
 
96
KDEVCPPDUCHAIN_EXPORT KDevelop::QualifiedIdentifier namespaceScopeComponentFromContext(KDevelop::QualifiedIdentifier identifier, const KDevelop::DUContext* context, const KDevelop::TopDUContext* source);
 
97
 
 
98
/**
 
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
 
104
 * */
 
105
KDEVCPPDUCHAIN_EXPORT bool isAccessible(KDevelop::DUContext* fromContext, KDevelop::ClassMemberDeclaration* declaration, KDevelop::TopDUContext* source, KDevelop::DUContext* declarationContext);
 
106
 
 
107
/**
 
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.
 
110
 */
 
111
KDEVCPPDUCHAIN_EXPORT KDevelop::DUContext* logicalParentContext(KDevelop::DUContext* context, KDevelop::TopDUContext* source);
 
112
 
 
113
/**
 
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
 
117
 * */
 
118
KDEVCPPDUCHAIN_EXPORT QString preprocess( const QString& text, EnvironmentFile* file, int line, QSet<KDevelop::IndexedString> disableMacros = QSet<KDevelop::IndexedString>() );
 
119
 
 
120
///Extracts a normalized signature and identifier from a specifier like "mySignal(int)"
 
121
KDEVCPPDUCHAIN_EXPORT QPair<KDevelop::Identifier, QByteArray> qtFunctionSignature(QByteArray fullFunction);
 
122
 
 
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);
 
125
 
 
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);
 
128
 
 
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);
 
131
 
 
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);
 
135
 
 
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());
 
145
 
 
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);
 
148
 
 
149
KDEVCPPDUCHAIN_EXPORT bool isFriend(KDevelop::Declaration* _class, KDevelop::Declaration* _friend);
 
150
 
 
151
///Shortens the type by resolving typedefs that are not useful
 
152
KDEVCPPDUCHAIN_EXPORT KDevelop::AbstractType::Ptr shortenTypeForViewing(KDevelop::AbstractType::Ptr type);
 
153
 
 
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);
 
158
 
 
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);
 
166
}
 
167
 
 
168
#endif