OSDN Git Service

more cosmetic changes
[qt-creator-jp/qt-creator-jp.git] / src / libs / cplusplus / CppDocument.h
1 /***************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact:  Qt Software Information (qt-info@nokia.com)
8 **
9 ** 
10 ** Non-Open Source Usage  
11 ** 
12 ** Licensees may use this file in accordance with the Qt Beta Version
13 ** License Agreement, Agreement version 2.2 provided with the Software or,
14 ** alternatively, in accordance with the terms contained in a written
15 ** agreement between you and Nokia.  
16 ** 
17 ** GNU General Public License Usage 
18 ** 
19 ** Alternatively, this file may be used under the terms of the GNU General
20 ** Public License versions 2.0 or 3.0 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.GPL included in the packaging
22 ** of this file.  Please review the following information to ensure GNU
23 ** General Public Licensing requirements will be met:
24 **
25 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
26 ** http://www.gnu.org/copyleft/gpl.html.
27 **
28 ** In addition, as a special exception, Nokia gives you certain additional
29 ** rights. These rights are described in the Nokia Qt GPL Exception version
30 ** 1.2, included in the file GPL_EXCEPTION.txt in this package.  
31 ** 
32 ***************************************************************************/
33
34 #ifndef CPPDOCUMENT_H
35 #define CPPDOCUMENT_H
36
37 #include <CPlusPlusForwardDeclarations.h>
38
39 #include <QByteArray>
40 #include <QList>
41 #include <QSet>
42 #include <QSharedPointer>
43 #include <QString>
44 #include <QStringList>
45
46 namespace CPlusPlus {
47
48 class CPLUSPLUS_EXPORT Document
49 {
50     Document(const Document &other);
51     void operator =(const Document &other);
52
53     Document(const QString &fileName);
54
55 public:
56     typedef QSharedPointer<Document> Ptr;
57
58 public:
59     ~Document();
60
61     QString fileName() const;
62
63     QStringList includedFiles() const;
64     void addIncludeFile(const QString &fileName);
65
66     QByteArray definedMacros() const;
67     QSet<QByteArray> macroNames() const;
68
69     void appendMacro(const QByteArray &macroName, const QByteArray &text);
70
71     Control *control() const;
72     TranslationUnit *translationUnit() const;
73
74     bool skipFunctionBody() const;
75     void setSkipFunctionBody(bool skipFunctionBody);
76
77     unsigned globalSymbolCount() const;
78     Symbol *globalSymbolAt(unsigned index) const;
79     Scope *globalSymbols() const; // ### deprecate?
80     Namespace *globalNamespace() const;
81
82     Symbol *findSymbolAt(unsigned line, unsigned column) const;
83
84     void setSource(const QByteArray &source);
85     void startSkippingBlocks(unsigned offset);
86     void stopSkippingBlocks(unsigned offset);
87
88     void parse(); // ### remove
89     void check();
90     void releaseTranslationUnit();
91
92     static Ptr create(const QString &fileName);
93
94     class DiagnosticMessage
95     {
96     public:
97         enum Level {
98             Warning,
99             Error,
100             Fatal
101         };
102
103     public:
104         DiagnosticMessage(int level, const QString &fileName,
105                           int line, int column,
106                           const QString &text)
107             : _level(level),
108               _fileName(fileName),
109               _line(line),
110               _column(column),
111               _text(text)
112         { }
113
114         int level() const
115         { return _level; }
116
117         bool isWarning() const
118         { return _level == Warning; }
119
120         bool isError() const
121         { return _level == Error; }
122
123         bool isFatal() const
124         { return _level == Fatal; }
125
126         QString fileName() const
127         { return _fileName; }
128
129         int line() const
130         { return _line; }
131
132         int column() const
133         { return _column; }
134
135         QString text() const
136         { return _text; }
137
138     private:
139         int _level;
140         QString _fileName;
141         int _line;
142         int _column;
143         QString _text;
144     };
145
146     void addDiagnosticMessage(const DiagnosticMessage &d)
147     { _diagnosticMessages.append(d); }
148
149     QList<DiagnosticMessage> diagnosticMessages() const
150     { return _diagnosticMessages; }
151
152     class Block
153     {
154         unsigned _begin;
155         unsigned _end;
156
157     public:
158         inline Block(unsigned begin = 0, unsigned end = 0)
159             : _begin(begin), _end(end)
160         { }
161
162         inline unsigned begin() const
163         { return _begin; }
164
165         inline unsigned end() const
166         { return _end; }
167     };
168
169     QList<Block> skippedBlocks() const
170     { return _skippedBlocks; }
171
172 private:
173     Symbol *findSymbolAt(unsigned line, unsigned column, Scope *scope) const;
174
175 private:
176     QString _fileName;
177     QStringList _includedFiles;
178     Control *_control;
179     TranslationUnit *_translationUnit;
180     Namespace *_globalNamespace;
181     QList<DiagnosticMessage> _diagnosticMessages;
182     QByteArray _definedMacros;
183     QSet<QByteArray> _macroNames;
184     QList<Block> _skippedBlocks;
185 };
186
187 } // end of namespace CPlusPlus
188
189 #endif // CPPDOCUMENT_H