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.
19 #ifndef PARSINGENVIRONMENT_H
20 #define PARSINGENVIRONMENT_H
22 #include <QtCore/QDateTime>
23 #include <QtCore/QString>
25 #include <ksharedptr.h>
28 #include "indexedstring.h"
30 #include "../editor/hashedstring.h"
31 #include "../languageexport.h"
32 #include "duchainbase.h"
33 #include "topducontext.h"
38 class ModificationRevision
; //Can be found in editorintegrator.h
39 class IndexedTopDUContext
;
41 * Just an enumeration of a few parsing-environment types.
42 * Enumerate a few possible future parsing-environment types.
43 * A parsing-environment could also have a type not in this enumeration,
44 * the only important thing is that it's unique for the type.
46 * The type is needed to match ParsingEnvironment, ParsingEnvironmentFile, and ParsingEnvironmentManager together so they fit.
47 * For example the c++-versions would have their specific type.
49 * The type must be unique(no other language may have the same type),
50 * and the type must be persistent.(it must be same after restarting kdevelop)
53 enum ParsingEnvironmentType
55 StandardParsingEnvironment
/**< a basic standard parsing environment */,
56 CppParsingEnvironment
/**< a C++ parsing environment */,
57 PythonParsingEnvironment
/**< a python parsing environment */,
58 CMakeParsingEnvironment
/**< a CMake parsing environment */,
59 CSharpParsingEnvironment
/**< a CSharp parsing environment */,
60 JavaParsingEnvironment
/**< a JAva parsing environment */,
61 RubyParsingEnvironment
/**< a Ruby parsing environment */,
62 PhpParsingEnvironment
/**< a PHP parsing environment */
66 * Use this as base-class to define new parsing-environments.
68 * Parsing-environments are needed for languages that create different
69 * parsing-results depending on the environment. For example in c++,
70 * the environment mainly consists of macros. The include-path can
71 * be considered to be a part of the parsing-environment too, because
72 * different files may be included using another include-path.
74 * The classes have to use the serialization scheme from the duchain.
75 * Each class must be registered using REGISTER_DUCHAIN_ITEM with a unique id.
77 * \warning Access to this class must be serialized through du-chain locking
79 class KDEVPLATFORMLANGUAGE_EXPORT ParsingEnvironment
83 virtual ~ParsingEnvironment();
85 ///@see ParsingEnvironmentType
86 virtual int type() const;
89 ///The data class used for storing. Use this as base-class of your custom data classes for classes derived from
90 ///ParsingEnvironmentFile
91 class KDEVPLATFORMLANGUAGE_EXPORT ParsingEnvironmentFileData
: public DUChainBaseData
{
93 ParsingEnvironmentFileData() : m_isProxyContext(false), m_features(TopDUContext::VisibleDeclarationsAndContexts
) {
95 bool m_isProxyContext
;
96 TopDUContext::Features m_features
;
100 * This represents all information about a specific parsed file that is needed
101 * to match the file to a parsing-environment.
103 * It is KShared because it is embedded into top-du-contexts and at the same time
104 * references may be held by ParsingEnvironmentManager.
106 * \warning Access to this class must be serialized through du-chain locking
108 class KDEVPLATFORMLANGUAGE_EXPORT ParsingEnvironmentFile
: public DUChainBase
, public KShared
111 virtual ~ParsingEnvironmentFile();
112 ParsingEnvironmentFile();
113 ParsingEnvironmentFile(ParsingEnvironmentFileData
& data
);
115 ///@see ParsingEnvironmentType
116 virtual int type() const;
118 ///Convenience-function that returns the top-context
119 virtual TopDUContext
* topContext() const;
121 ///Should return the indexed version of the top-context
122 virtual KDevelop::IndexedTopDUContext
indexedTopContext() const = 0;
124 ///Should return a correctly filled ModificationRevision of the source it was created from.
125 virtual ModificationRevision
modificationRevision() const = 0;
127 ///Should return whether this file matches into the given environment
128 virtual bool matchEnvironment(const ParsingEnvironment
* environment
) const = 0;
130 ///Should use language-specific information to decide whether the top-context that has this data attached needs to be reparsed
131 virtual bool needsUpdate() const = 0;
134 * A language-specific flag used by C++ to mark one context as a proxy of another.
135 * If this flag is set on a context, the first imported context should be used for any computations
136 * like searches, listing, etc. instead of using this context.
138 * The problems should be stored within the proxy-contexts, and optionally there may be
139 * any count of imported proxy-contexts imported behind the content-context(This can be used for tracking problems)
141 * Note: This flag does not directly change the behavior of the language-independent du-chain.
143 bool isProxyContext() const;
146 void setIsProxyContext(bool);
148 ///The features of the attached top-context. They are automatically replicated here by the top-context, so they
149 ///are accessible even without the top-context loaded.
150 TopDUContext::Features
features() const;
152 DUCHAIN_DECLARE_DATA(ParsingEnvironmentFile
)
155 friend class TopDUContext
;
156 void setFeatures(TopDUContext::Features
);
159 typedef KSharedPtr
<ParsingEnvironmentFile
> ParsingEnvironmentFilePointer
;