1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
/*
Copyright 2008 Hamish Rodda <rodda@kde.org>
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_DUCHAINCHANGESET_H
#define KDEVPLATFORM_DUCHAINCHANGESET_H
#include <QVariant>
#include "../duchain/identifier.h"
#include "../duchain/topducontext.h"
#include "../duchain/declaration.h"
namespace KDevelop {
class DUChainChangeSet;
class DUChainChange;
class DUChainBase;
class DUContextRef;
template <typename AstNode>
class AstNodeRef;
/**
* \short A reference to an existing read-only DUChain object.
*
* This class represents a duchain object (eg, a KDevelop::DUContext),
* and allows changes to be planned for that object.
*
* \todo Evaluate usefulness of changing child contexts - needed?
*
* \warning you must not create cyclic references.
* \author Hamish Rodda <rodda@kde.org>
*/
class KDEVPLATFORMLANGUAGE_EXPORT DUChainRef
{
friend class DUChainChangeSet;
public:
/*virtual ~DUChainRef();
virtual const DUChainBase* object() const;
virtual const DUContext* context() const;
virtual const Declaration* declaration() const;
virtual DUChainRef* objectRef() const;
virtual DUChainBase* newObject() const;
virtual DUContext* newContext() const;
virtual Declaration* newDeclaration() const;
const QList<DUChainChange*>& changes() const;
/// Rename this object, if applicable
void renameObject(const QualifiedIdentifier& newIdentifier);
/// Change the access policy
void setAccessPolicy(Declaration::AccessPolicy newPolicy);
void deleteChildContext(DUContext* child);
void insertChildContext(DUContextRef* newChild);
void deleteDeclaration(Declaration* declaration);
void insertDeclaration(Declaration* declaration, DUChainBase* afterObject);
void appendDeclaration(Declaration* declaration);
AbstractType::Ptr currentType() const;
void changeType(AbstractType::Ptr newType);
*/
/**
* Rewrite the AST which created this duchain object. Eg:
* - for declarations, the entire declaration.
* - for contexts, the contents of the context.
* - for types, the type declaration.
*
* \returns a reference to the AST which represents this object as it currently
* exists (after any existing duchain changes are applied). Changes
* made to the AST will be applied along with the duchain change set.
*/
/* template <typename AstNode>
AstNodeRef<AstNode> * rewriteAst();
/// Removes a change from this object reference, and deletes it.
void deleteChange(DUChainChange* change);
protected:
/// Constructor. Either takes an existing \a object (\a newObject = false), or a newly created \a object (\a newObject = true)
DUChainRef(DUChainChangeSet* set, DUChainBase* object, bool newObject);
/// Constructor. Takes another object reference.
DUChainRef(DUChainChangeSet* set, DUChainRef* original);
/// Adds a change to this object reference. Takes ownership of the \a change.
DUChainChange* addChange(DUChainChange* change);
private:
DUChainChangeSet* m_changeSet;
DUChainBase* m_object;
DUChainRef* m_objectRef;
bool m_newObject;
QList<DUChainChange*> m_changes;*/
};
using DUChainBaseList = QList<DUChainRef*>;
/**
* \short Container class for a change to a duchain object.
*
* \author Hamish Rodda <rodda@kde.org>
*/
class KDEVPLATFORMLANGUAGE_EXPORT DUChainChange
{
public:
enum ChangeTypes {
Rename,
ListInsert,
ListRemove,
ListClear,
ItemReplace,
ItemMove,
TypeChange
} type;
explicit DUChainChange(ChangeTypes t) : type(t) {}
enum ItemToChange {
ContextChildren,
ContextDeclarations
} itemToChange;
/// New local identifier (eg. for contexts, the new DUContext::localScopeIdentifier() )
QualifiedIdentifier newIdentifier;
/// The new object to occupy this position, if relevant
DUChainRef* newObject;
/// The list of objects to occupy this position, if relevant
DUChainBaseList newList;
/// The position to apply the object(s) in the list, if relevant
int listOffset;
/// The value of the position, if relevant
QVariant newValue;
AbstractType::Ptr newType;
};
/**
* \short A set of changes to a DUChain.
*
* This class holds a set of all changes to a DU Chain, and provides an interface
* to convenience functions provided by the specific language support involved.
*
* \author Hamish Rodda <rodda@kde.org>
*/
class KDEVPLATFORMLANGUAGE_EXPORT DUChainChangeSet
{
public:
/**
* Constructor.
*
* \param topContext the top context of the read-only DUChain to modify, or set to null if creating
* a new DUChain from scratch.
*/
explicit DUChainChangeSet(const ReferencedTopDUContext& topContext);
/**
* Destructor, deletes all objects, references and changes owned by this change set.
*/
virtual ~DUChainChangeSet();
/**
* Create a new declaration to be managed by this change set.
*
* \returns the new declaration reference
*/
virtual DUChainRef* newDeclaration() = 0;
/**
* Create a new class to be managed by this change set.
*
* \returns the new declaration reference
*/
virtual DUChainRef* newClass() = 0;
/**
* Create a new function to be managed by this change set.
*
* \returns the new declaration reference
*/
virtual DUChainRef* newFunction() = 0;
/**
* Copy an existing object from a change set.
*
* This change set takes ownership, so that
* the new object will be deleted when the change set is no longer needed.
*
* \returns the new object reference
*/
DUChainRef* copyRef(DUChainRef* ref);
/**
* Merge another changeset with this one. This changeset
* takes ownership of all the objects in the other changeset.
* After the merge, the merged object becomes empty.
*
* Both changesets must reference the same TopDuContext.
*/
DUChainChangeSet& operator<<(DUChainChangeSet& rhs);
/**
* Produce a reference to an existing object in this chain, and replace the
* object with the reference so that modifications to the reference are already
* integrated into the change set.
*
* You may then modify this reference, and the modifications will be applied
* to the chain when the change set is finalised.
*
* \returns a reference to \a source, which you may modify directly.
*/
DUChainRef* modifyObject(DUChainBase* source);
/**
* Copy an existing object (whether from the DUChain or from the change set).
* Does not insert the object into the chain.
*
* You may then modify this reference, and the modifications will be applied to the object when the change set is finalised.
*
* \returns a copy of \a source, which you may modify directly.
*/
DUChainRef* copyObject(DUChainBase* source);
/**
* Retrieve the list of object references and changes.
*/
QList<DUChainRef*> objectRefs() const;
const ReferencedTopDUContext& topDuContext() const;
private:
ReferencedTopDUContext m_topContext;
QList<DUChainRef*> m_objectRefs;
};
}
#endif // KDEVPLATFORM_DUCHAINCHANGESET_H
|