1
/****************************************************************************
3
** Copyright (C) 2004-2005 Trolltech AS. All rights reserved.
4
** Copyright (C) 2001-2004 Roberto Raggi
6
** This file is part of the porting application of the Qt Toolkit.
8
** This file may be distributed under the terms of the Q Public License
9
** as defined by Trolltech AS of Norway and appearing in the file
10
** LICENSE.QPL included in the packaging of this file.
12
** This file may be distributed and/or modified under the terms of the
13
** GNU General Public License version 2 as published by the Free Software
14
** Foundation and appearing in the file LICENSE.GPL included in the
15
** packaging of this file.
17
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
18
** information about Qt Commercial License Agreements.
19
** See http://www.trolltech.com/qpl/ for QPL licensing information.
20
** See http://www.trolltech.com/gpl/ for GPL licensing information.
22
** Contact info@trolltech.com if any conditions of this licensing are
25
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28
****************************************************************************/
29
#ifndef TOKENSTREAMADAPTER_H
30
#define TOKENSTREAMADAPTER_H
34
#include "tokenengine.h"
37
namespace TokenStreamAdapter {
40
TokenStream(TokenEngine::TokenSectionSequence translationUnit, QVector<Type> tokenKindList)
41
:m_translationUnit(translationUnit),
42
m_tokenKindList(tokenKindList),
44
m_numTokens(tokenKindList.count())
46
Q_ASSERT(translationUnit.count() == m_numTokens);
48
// Copy out the container and containerIndex for each token so we can have
49
// constant time random access to it.
50
TokenEngine::TokenSectionSequenceIterator it(translationUnit);
51
while(it.nextToken()) {
52
m_tokenContainers.append(it.tokenContainer());
53
m_containerIndices.append(it.containerIndex());
57
bool isHidden(int index) const
59
if(index >= m_numTokens)
61
::Type type = m_tokenKindList.at(index);
62
return (type == Token_whitespaces || type == 10 /*newline*/ ||
63
type == Token_comment || type == Token_preproc );
66
inline int lookAhead(int n = 0) const
68
if(m_cursor + n >= m_numTokens)
70
return m_tokenKindList.at(m_cursor + n);
73
inline int currentToken() const
74
{ return lookAhead(); }
76
inline QByteArray currentTokenText() const
78
return tokenText(m_cursor);
81
inline TokenEngine::TokenContainer tokenContainer(int index = 0) const
83
if (index < m_numTokens)
84
return m_tokenContainers.at(index);
86
return TokenEngine::TokenContainer();
89
inline int containerIndex(int index = 0) const
91
if (index < m_numTokens)
92
return m_containerIndices.at(index);
97
inline QByteArray tokenText(int index = 0) const
99
if (index < m_numTokens) {
100
const TokenEngine::TokenContainer container = tokenContainer(index);
101
const int cIndex = containerIndex(index);
102
return container.text(cIndex);
108
inline void rewind(int index)
109
{ m_cursor = index; }
111
inline int cursor() const
114
inline void nextToken()
117
inline bool tokenAtEnd()
118
{ return m_cursor >= m_numTokens; }
120
TokenEngine::TokenSectionSequence tokenSections() const
121
{ return m_translationUnit; }
124
TokenEngine::TokenSectionSequence m_translationUnit;
125
QVector<Type> m_tokenKindList;
126
QList<TokenEngine::TokenContainer> m_tokenContainers;
127
QList<int> m_containerIndices;
132
} //namespace TokenStreamAdapter