~ubuntu-branches/ubuntu/utopic/kdevelop-php/utopic

« back to all changes in this revision

Viewing changes to parser/generated/kdevelop-pg-qt/kdev-pg-token-stream.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2010-01-17 17:10:22 UTC
  • Revision ID: james.westby@ubuntu.com-20100117171022-q2xlgd9ekewo2ijx
Tags: upstream-1.0.0~beta2
ImportĀ upstreamĀ versionĀ 1.0.0~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This file is part of kdev-pg
 
3
  Copyright 2005, 2006 Roberto Raggi <roberto@kdevelop.org>
 
4
 
 
5
  Permission to use, copy, modify, distribute, and sell this software and its
 
6
  documentation for any purpose is hereby granted without fee, provided that
 
7
  the above copyright notice appear in all copies and that both that
 
8
  copyright notice and this permission notice appear in supporting
 
9
  documentation.
 
10
 
 
11
  The above copyright notice and this permission notice shall be included in
 
12
  all copies or substantial portions of the Software.
 
13
 
 
14
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
15
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
17
  KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
18
  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
19
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
20
*/
 
21
 
 
22
//krazy:exclude-all=inline
 
23
#ifndef KDEV_PG_TOKEN_STREAM_H
 
24
#define KDEV_PG_TOKEN_STREAM_H
 
25
 
 
26
#include <QtCore/QtGlobal>
 
27
 
 
28
#include "kdev-pg-location-table.h"
 
29
 
 
30
namespace KDevPG
 
31
{
 
32
 
 
33
class Token {
 
34
  public:
 
35
    int kind;
 
36
    qint64 begin;
 
37
    qint64 end;
 
38
};
 
39
template<class T>
 
40
class TokenStreamBase
 
41
{
 
42
public:
 
43
  typedef T Token;
 
44
  TokenStreamBase()
 
45
    : mTokenBuffer(0),
 
46
      mTokenBufferSize(0),
 
47
      mIndex(0),
 
48
      mTokenCount(0),
 
49
      mLocationTable(0)
 
50
  {
 
51
    reset();
 
52
  }
 
53
 
 
54
  ~TokenStreamBase()
 
55
  {
 
56
    if (mTokenBuffer)
 
57
      ::free(mTokenBuffer);
 
58
    if (mLocationTable)
 
59
      delete mLocationTable;
 
60
  }
 
61
 
 
62
  inline void reset()
 
63
  {
 
64
    mIndex = 0;
 
65
    mTokenCount = 0;
 
66
  }
 
67
 
 
68
  inline qint64 size() const
 
69
  {
 
70
    return mTokenCount;
 
71
  }
 
72
 
 
73
  inline qint64 index() const
 
74
  {
 
75
    return mIndex;
 
76
  }
 
77
 
 
78
  inline qint64 tokenIndex() const
 
79
  {
 
80
    if( mIndex )
 
81
      return mIndex - 1;
 
82
    return mIndex;
 
83
  }
 
84
 
 
85
  inline void rewind(qint64 index)
 
86
  {
 
87
    mIndex = index;
 
88
  }
 
89
 
 
90
  inline T const &token(qint64 index) const
 
91
  {
 
92
    return mTokenBuffer[index];
 
93
  }
 
94
 
 
95
  inline T &token(qint64 index)
 
96
  {
 
97
    return mTokenBuffer[index];
 
98
  }
 
99
 
 
100
  inline int nextToken()
 
101
  {
 
102
    return mTokenBuffer[mIndex++].kind;
 
103
  }
 
104
 
 
105
  inline T &next()
 
106
  {
 
107
    if (mTokenCount == mTokenBufferSize)
 
108
      {
 
109
        if (mTokenBufferSize == 0)
 
110
          mTokenBufferSize = 1024;
 
111
 
 
112
        mTokenBufferSize <<= 2;
 
113
 
 
114
        mTokenBuffer = reinterpret_cast<T*>
 
115
          (::realloc(mTokenBuffer, mTokenBufferSize * sizeof(T)));
 
116
      }
 
117
 
 
118
    return mTokenBuffer[mTokenCount++];
 
119
  }
 
120
 
 
121
  inline LocationTable *locationTable()
 
122
  {
 
123
    if (!mLocationTable)
 
124
      mLocationTable = new LocationTable();
 
125
 
 
126
    return mLocationTable;
 
127
  }
 
128
 
 
129
  inline void startPosition(qint64 index, qint64 *line, qint64 *column)
 
130
  {
 
131
    if (!mLocationTable)
 
132
      {
 
133
        *line = 0; *column = 0;
 
134
      }
 
135
    else
 
136
      mLocationTable->positionAt(token(index).begin, line, column);
 
137
  }
 
138
 
 
139
  inline void endPosition(qint64 index, qint64 *line, qint64 *column)
 
140
  {
 
141
    if (!mLocationTable)
 
142
      {
 
143
        *line = 0; *column = 0;
 
144
      }
 
145
    else
 
146
      mLocationTable->positionAt(token(index).end, line, column);
 
147
  }
 
148
 
 
149
private:
 
150
  T *mTokenBuffer;
 
151
  qint64 mTokenBufferSize;
 
152
  qint64 mIndex;
 
153
  qint64 mTokenCount;
 
154
  LocationTable *mLocationTable;
 
155
 
 
156
private:
 
157
  TokenStreamBase(TokenStreamBase const &other);
 
158
  void operator = (TokenStreamBase const &other);
 
159
};
 
160
 
 
161
 
 
162
class TokenStream : public TokenStreamBase<Token>
 
163
{
 
164
};
 
165
 
 
166
 
 
167
}
 
168
 
 
169
#endif // KDEV_PG_TOKEN_STREAM_H
 
170