~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/porting/src/tokenreplacements.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the porting application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef TOKENREPLACEMENTS_H
 
30
#define TOKENREPLACEMENTS_H
 
31
 
 
32
#include <QStringList>
 
33
#include <QByteArray>
 
34
#include "tokenengine.h"
 
35
#include "textreplacement.h"
 
36
 
 
37
class TokenReplacement
 
38
{
 
39
public:
 
40
    virtual bool doReplace(const TokenEngine::TokenContainer& ,
 
41
                           int /*tokenIndex*/,
 
42
                           TextReplacements&){return false;};
 
43
    /*
 
44
        returns the replace key for this replacement. Every time a token matches the replace key,
 
45
        doReplace() will be called for this TokenReplacement.
 
46
    */
 
47
    virtual QByteArray getReplaceKey(){return QByteArray();};
 
48
    virtual ~TokenReplacement(){};
 
49
protected:
 
50
    void addLogSourceEntry(const QString &text, const TokenEngine::TokenContainer&, const int index) const;
 
51
    void addLogWarning(const QString &text) const;
 
52
};
 
53
 
 
54
/*
 
55
    A TokenReplacement that changes #include directives
 
56
*/
 
57
class IncludeTokenReplacement : public TokenReplacement
 
58
{
 
59
public:
 
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);
 
64
private:
 
65
    QByteArray fromFile;
 
66
    QByteArray toFile;
 
67
};
 
68
 
 
69
/*
 
70
    A TokenReplacement that change any token
 
71
*/
 
72
class GenericTokenReplacement : public TokenReplacement
 
73
{
 
74
public:
 
75
    GenericTokenReplacement(QByteArray oldToken, QByteArray newToken);
 
76
    bool doReplace(const TokenEngine::TokenContainer &tokenContainer,
 
77
                   int tokenIndex, TextReplacements &textReplacements);
 
78
    QByteArray getReplaceKey();
 
79
private:
 
80
    QByteArray oldToken;
 
81
    QByteArray newToken;
 
82
};
 
83
 
 
84
/*
 
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:
 
88
 
 
89
    QButton::toggleState
 
90
 
 
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.
 
94
*/
 
95
class ClassNameReplacement : public TokenReplacement
 
96
{
 
97
public:
 
98
    ClassNameReplacement(QByteArray oldToken, QByteArray newToken);
 
99
    bool doReplace(const TokenEngine::TokenContainer &tokenContainer,
 
100
                   int tokenIndex, TextReplacements &textReplacements);
 
101
    QByteArray getReplaceKey();
 
102
private:
 
103
    QByteArray oldToken;
 
104
    QByteArray newToken;
 
105
};
 
106
 
 
107
/*
 
108
   Changes scoped tokens:
 
109
   AA::BB -> CC::DD
 
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.
 
114
 
 
115
*/
 
116
class ScopedTokenReplacement : public TokenReplacement
 
117
{
 
118
public:
 
119
    ScopedTokenReplacement(const QByteArray &oldToken, const QByteArray &newToken);
 
120
    bool doReplace(const TokenEngine::TokenContainer &tokenContainer,
 
121
                   int tokenIndex, TextReplacements &textReplacements);
 
122
    QByteArray getReplaceKey();
 
123
private:
 
124
    QByteArray oldName;
 
125
    QByteArray oldScope;
 
126
    QByteArray newName;
 
127
    QByteArray newScope;
 
128
    QByteArray newScopedName;
 
129
};
 
130
 
 
131
class QualifiedNameParser
 
132
{
 
133
public:
 
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);
 
139
    bool isQualifier();
 
140
    bool isName();
 
141
    int peek(Direction direction);
 
142
    int move(Direction direction);
 
143
private:
 
144
    int nextScopeToken(Direction direction);
 
145
    int findScopeOperator(Direction direction);
 
146
    const TokenEngine::TokenContainer tokenContainer;
 
147
    int currentIndex;
 
148
};
 
149
 
 
150
#endif