1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the porting application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#ifndef TOKENREPLACEMENTS_H
30
#define TOKENREPLACEMENTS_H
32
#include <QStringList>
34
#include "tokenengine.h"
35
#include "textreplacement.h"
37
class TokenReplacement
40
virtual bool doReplace(const TokenEngine::TokenContainer& ,
42
TextReplacements&){return false;};
44
returns the replace key for this replacement. Every time a token matches the replace key,
45
doReplace() will be called for this TokenReplacement.
47
virtual QByteArray getReplaceKey(){return QByteArray();};
48
virtual ~TokenReplacement(){};
50
void addLogSourceEntry(const QString &text, const TokenEngine::TokenContainer&, const int index) const;
51
void addLogWarning(const QString &text) const;
55
A TokenReplacement that changes #include directives
57
class IncludeTokenReplacement : public TokenReplacement
60
IncludeTokenReplacement(QByteArray fromFile, QByteArray toFile);
61
// bool doReplace(QByteArray tokenText, QByteArray &newTokenText);
62
bool doReplace(const TokenEngine::TokenContainer &tokenContainer,
63
int tokenIndex, TextReplacements &textReplacements);
70
A TokenReplacement that change any token
72
class GenericTokenReplacement : public TokenReplacement
75
GenericTokenReplacement(QByteArray oldToken, QByteArray newToken);
76
bool doReplace(const TokenEngine::TokenContainer &tokenContainer,
77
int tokenIndex, TextReplacements &textReplacements);
78
QByteArray getReplaceKey();
85
A TokenReplacement that changes tokens that specify class names.
86
In some cases where the class name token is a part of a qualified name
87
it is not correct to rename it. ex:
91
Here it is wrong to rename QButton -> Q3Button, since there is
92
a rule that says QButton::ToggleState -> QCheckBox::ToggleState,
93
but no rule for Q3Button::ToggleState.
95
class ClassNameReplacement : public TokenReplacement
98
ClassNameReplacement(QByteArray oldToken, QByteArray newToken);
99
bool doReplace(const TokenEngine::TokenContainer &tokenContainer,
100
int tokenIndex, TextReplacements &textReplacements);
101
QByteArray getReplaceKey();
108
Changes scoped tokens:
110
oldToken corresponds to the AA::BB part, newToken corresponds CC::DD.
111
Since this is a token replacement, the AA part of oldToken is typically
112
unknown. This means that we might change tokens named BB that does not belong
113
to the AA scope. Ast replacemnts will fix this.
116
class ScopedTokenReplacement : public TokenReplacement
119
ScopedTokenReplacement(const QByteArray &oldToken, const QByteArray &newToken);
120
bool doReplace(const TokenEngine::TokenContainer &tokenContainer,
121
int tokenIndex, TextReplacements &textReplacements);
122
QByteArray getReplaceKey();
128
QByteArray newScopedName;
131
class QualifiedNameParser
134
QualifiedNameParser(const TokenEngine::TokenContainer &tokenContainer,
135
const int tokenIndex);
136
enum Direction { Left=-1, Right=1 };
137
bool isPartOfQualifiedName();
138
bool isValidIndex(int index);
141
int peek(Direction direction);
142
int move(Direction direction);
144
int nextScopeToken(Direction direction);
145
int findScopeOperator(Direction direction);
146
const TokenEngine::TokenContainer tokenContainer;