~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to debuggers/gdb/mi/milexer.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2004 by Roberto Raggi                                   *
 
3
 *   roberto@kdevelop.org                                                  *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU Library General Public License as       *
 
7
 *   published by the Free Software Foundation; either version 2 of the    *
 
8
 *   License, or (at your option) any later version.                       *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU Library General Public     *
 
16
 *   License along with this program; if not, write to the                 *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
#ifndef MILEXER_H
 
21
#define MILEXER_H
 
22
 
 
23
#include <QMap>
 
24
#include <QString>
 
25
#include <QVector>
 
26
 
 
27
class MILexer;
 
28
class TokenStream;
 
29
 
 
30
typedef void (MILexer::*scan_fun_ptr)(int *kind);
 
31
 
 
32
struct Token
 
33
{
 
34
    int kind;
 
35
    int position;
 
36
    int length;
 
37
};
 
38
 
 
39
struct FileSymbol
 
40
{
 
41
    QByteArray contents;
 
42
    TokenStream *tokenStream;
 
43
 
 
44
    inline FileSymbol()
 
45
        : tokenStream(0) {}
 
46
 
 
47
    inline ~FileSymbol();
 
48
};
 
49
 
 
50
struct TokenStream
 
51
{
 
52
    inline int lookAhead(int n = 0) const
 
53
    { return (m_currentToken + n)->kind; }
 
54
 
 
55
    inline int currentToken() const
 
56
    { return m_currentToken->kind; }
 
57
 
 
58
    inline QByteArray currentTokenText() const
 
59
    { return tokenText(-1); }
 
60
 
 
61
    QByteArray tokenText(int index = 0) const;
 
62
 
 
63
    inline int lineOffset(int line) const
 
64
    { return m_lines.at(line); }
 
65
 
 
66
    void positionAt(int position, int *line, int *column) const;
 
67
 
 
68
    inline void getTokenStartPosition(int index, int *line, int *column) const
 
69
    { positionAt((m_firstToken + index)->position, line, column); }
 
70
 
 
71
    inline void getTokenEndPosition(int index, int *line, int *column) const
 
72
    {
 
73
        Token *tk = m_firstToken + index;
 
74
        positionAt(tk->position + tk->length, line, column);
 
75
    }
 
76
 
 
77
    inline void rewind(int index)
 
78
    { m_currentToken = m_firstToken + index; }
 
79
 
 
80
    inline int cursor() const
 
81
    { return m_currentToken - m_firstToken; }
 
82
 
 
83
    inline void nextToken()
 
84
    { m_currentToken++; m_cursor++; }
 
85
 
 
86
//private:
 
87
    QByteArray m_contents;
 
88
 
 
89
    QVector<int> m_lines;
 
90
    int m_line;
 
91
 
 
92
    QVector<Token> m_tokens;
 
93
    int m_tokensCount;
 
94
 
 
95
    Token *m_firstToken;
 
96
    Token *m_currentToken;
 
97
 
 
98
    int m_cursor;
 
99
};
 
100
 
 
101
class MILexer
 
102
{
 
103
public:
 
104
    MILexer();
 
105
    ~MILexer();
 
106
 
 
107
    TokenStream *tokenize(const FileSymbol *fileSymbol);
 
108
 
 
109
private:
 
110
    int nextToken(int &position, int &len);
 
111
 
 
112
    void scanChar(int *kind);
 
113
    void scanUnicodeChar(int *kind);
 
114
    void scanNewline(int *kind);
 
115
    void scanWhiteSpaces(int *kind);
 
116
    void scanStringLiteral(int *kind);
 
117
    void scanNumberLiteral(int *kind);
 
118
    void scanIdentifier(int *kind);
 
119
 
 
120
    void setupScanTable();
 
121
 
 
122
private:
 
123
    static bool s_initialized;
 
124
    static scan_fun_ptr s_scan_table[128 + 1];
 
125
 
 
126
    QByteArray m_contents;
 
127
    int m_ptr;
 
128
    // Cached 'm_contents.length()'
 
129
    int m_length;
 
130
 
 
131
    QVector<int> m_lines;
 
132
    int m_line;
 
133
 
 
134
    QVector<Token> m_tokens;
 
135
    int m_tokensCount;
 
136
 
 
137
    int m_cursor;
 
138
};
 
139
 
 
140
inline FileSymbol::~FileSymbol()
 
141
{
 
142
    delete tokenStream;
 
143
    tokenStream = 0;
 
144
}
 
145
 
 
146
 
 
147
#endif