| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | /***************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2009-01-13 19:21:51 +01:00
										 |  |  | ** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Contact:  Qt Software Information (qt-info@nokia.com) | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2008-12-02 14:17:16 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Non-Open Source Usage | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | ** Licensees may use this file in accordance with the Qt Beta Version | 
					
						
							|  |  |  | ** License Agreement, Agreement version 2.2 provided with the Software or, | 
					
						
							|  |  |  | ** alternatively, in accordance with the terms contained in a written | 
					
						
							| 
									
										
										
										
											2008-12-02 14:17:16 +01:00
										 |  |  | ** agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | ** Alternatively, this file may be used under the terms of the GNU General | 
					
						
							|  |  |  | ** Public License versions 2.0 or 3.0 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation and appearing in the file LICENSE.GPL included in the packaging | 
					
						
							|  |  |  | ** of this file.  Please review the following information to ensure GNU | 
					
						
							|  |  |  | ** General Public Licensing requirements will be met: | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
 | 
					
						
							|  |  |  | ** http://www.gnu.org/copyleft/gpl.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							| 
									
										
										
										
											2008-12-02 14:17:16 +01:00
										 |  |  | ** rights. These rights are described in the Nokia Qt GPL Exception | 
					
						
							| 
									
										
										
										
											2008-12-16 17:20:00 +01:00
										 |  |  | ** version 1.3, included in the file GPL_EXCEPTION.txt in this package. | 
					
						
							| 
									
										
										
										
											2008-12-02 14:17:16 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ***************************************************************************/ | 
					
						
							| 
									
										
										
										
											2008-12-02 14:09:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | #ifndef CPPDOCUMENT_H
 | 
					
						
							|  |  |  | #define CPPDOCUMENT_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <CPlusPlusForwardDeclarations.h>
 | 
					
						
							| 
									
										
										
										
											2008-12-22 14:10:47 +01:00
										 |  |  | #include "Macro.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-08 12:59:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | #include <QByteArray>
 | 
					
						
							| 
									
										
										
										
											2008-12-02 14:09:21 +01:00
										 |  |  | #include <QList>
 | 
					
						
							| 
									
										
										
										
											2008-12-12 10:07:58 +01:00
										 |  |  | #include <QMap>
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | #include <QSharedPointer>
 | 
					
						
							|  |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QStringList>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace CPlusPlus { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-08 12:59:33 +01:00
										 |  |  | class Macro; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | class CPLUSPLUS_EXPORT Document | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Document(const Document &other); | 
					
						
							|  |  |  |     void operator =(const Document &other); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Document(const QString &fileName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     typedef QSharedPointer<Document> Ptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     ~Document(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString fileName() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QStringList includedFiles() const; | 
					
						
							| 
									
										
										
										
											2008-12-10 17:21:01 +01:00
										 |  |  |     void addIncludeFile(const QString &fileName, unsigned line); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-08 12:59:33 +01:00
										 |  |  |     void appendMacro(const Macro ¯o); | 
					
						
							| 
									
										
										
										
											2008-12-09 15:23:47 +01:00
										 |  |  |     void addMacroUse(const Macro ¯o, unsigned offset, unsigned length); | 
					
						
							| 
									
										
										
										
											2008-12-04 12:05:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     Control *control() const; | 
					
						
							|  |  |  |     TranslationUnit *translationUnit() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool skipFunctionBody() const; | 
					
						
							|  |  |  |     void setSkipFunctionBody(bool skipFunctionBody); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unsigned globalSymbolCount() const; | 
					
						
							|  |  |  |     Symbol *globalSymbolAt(unsigned index) const; | 
					
						
							|  |  |  |     Scope *globalSymbols() const; // ### deprecate?
 | 
					
						
							|  |  |  |     Namespace *globalNamespace() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-08 12:59:33 +01:00
										 |  |  |     QList<Macro> definedMacros() const | 
					
						
							|  |  |  |     { return _definedMacros; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     Symbol *findSymbolAt(unsigned line, unsigned column) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void setSource(const QByteArray &source); | 
					
						
							|  |  |  |     void startSkippingBlocks(unsigned offset); | 
					
						
							|  |  |  |     void stopSkippingBlocks(unsigned offset); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-03 14:01:19 +01:00
										 |  |  |     enum ParseMode { // ### keep in sync with CPlusPlus::TranslationUnit
 | 
					
						
							|  |  |  |         ParseTranlationUnit, | 
					
						
							|  |  |  |         ParseDeclaration, | 
					
						
							|  |  |  |         ParseExpression, | 
					
						
							|  |  |  |         ParseStatement | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-24 11:04:52 +01:00
										 |  |  |     bool isTokenized() const; | 
					
						
							|  |  |  |     void tokenize(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool isParsed() const; | 
					
						
							| 
									
										
										
										
											2008-12-03 14:01:19 +01:00
										 |  |  |     bool parse(ParseMode mode = ParseTranlationUnit); | 
					
						
							| 
									
										
										
										
											2009-02-24 11:04:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     void check(); | 
					
						
							| 
									
										
										
										
											2009-02-24 11:04:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void releaseSource(); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     void releaseTranslationUnit(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static Ptr create(const QString &fileName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class DiagnosticMessage | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         enum Level { | 
					
						
							|  |  |  |             Warning, | 
					
						
							|  |  |  |             Error, | 
					
						
							|  |  |  |             Fatal | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         DiagnosticMessage(int level, const QString &fileName, | 
					
						
							|  |  |  |                           int line, int column, | 
					
						
							|  |  |  |                           const QString &text) | 
					
						
							|  |  |  |             : _level(level), | 
					
						
							|  |  |  |               _fileName(fileName), | 
					
						
							|  |  |  |               _line(line), | 
					
						
							|  |  |  |               _column(column), | 
					
						
							|  |  |  |               _text(text) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int level() const | 
					
						
							|  |  |  |         { return _level; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bool isWarning() const | 
					
						
							|  |  |  |         { return _level == Warning; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bool isError() const | 
					
						
							|  |  |  |         { return _level == Error; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bool isFatal() const | 
					
						
							|  |  |  |         { return _level == Fatal; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QString fileName() const | 
					
						
							|  |  |  |         { return _fileName; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 10:51:25 +01:00
										 |  |  |         unsigned line() const | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |         { return _line; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-18 10:51:25 +01:00
										 |  |  |         unsigned column() const | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |         { return _column; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QString text() const | 
					
						
							|  |  |  |         { return _text; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         int _level; | 
					
						
							|  |  |  |         QString _fileName; | 
					
						
							| 
									
										
										
										
											2008-12-18 10:51:25 +01:00
										 |  |  |         unsigned _line; | 
					
						
							|  |  |  |         unsigned _column; | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |         QString _text; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void addDiagnosticMessage(const DiagnosticMessage &d) | 
					
						
							|  |  |  |     { _diagnosticMessages.append(d); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QList<DiagnosticMessage> diagnosticMessages() const | 
					
						
							|  |  |  |     { return _diagnosticMessages; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class Block | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         unsigned _begin; | 
					
						
							|  |  |  |         unsigned _end; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         inline Block(unsigned begin = 0, unsigned end = 0) | 
					
						
							|  |  |  |             : _begin(begin), _end(end) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         inline unsigned begin() const | 
					
						
							|  |  |  |         { return _begin; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         inline unsigned end() const | 
					
						
							|  |  |  |         { return _end; } | 
					
						
							| 
									
										
										
										
											2008-12-09 15:23:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         bool contains(unsigned pos) const | 
					
						
							|  |  |  |         { return pos >= _begin && pos < _end; } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-10 17:21:01 +01:00
										 |  |  |     class Include { | 
					
						
							|  |  |  |         QString _fileName; | 
					
						
							|  |  |  |         unsigned _line; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         Include(const QString &fileName, unsigned line) | 
					
						
							|  |  |  |             : _fileName(fileName), _line(line) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QString fileName() const | 
					
						
							|  |  |  |         { return _fileName; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         unsigned line() const | 
					
						
							|  |  |  |         { return _line; } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-09 15:23:47 +01:00
										 |  |  |     class MacroUse: public Block { | 
					
						
							|  |  |  |         Macro _macro; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         inline MacroUse(const Macro ¯o, | 
					
						
							|  |  |  |                         unsigned begin = 0, | 
					
						
							|  |  |  |                         unsigned end = 0) | 
					
						
							|  |  |  |             : Block(begin, end), | 
					
						
							|  |  |  |               _macro(macro) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const Macro ¯o() const | 
					
						
							|  |  |  |         { return _macro; } | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-10 17:21:01 +01:00
										 |  |  |     QList<Include> includes() const | 
					
						
							|  |  |  |     { return _includes; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     QList<Block> skippedBlocks() const | 
					
						
							|  |  |  |     { return _skippedBlocks; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-09 15:23:47 +01:00
										 |  |  |     QList<MacroUse> macroUses() const | 
					
						
							| 
									
										
										
										
											2008-12-04 12:05:04 +01:00
										 |  |  |     { return _macroUses; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     Symbol *findSymbolAt(unsigned line, unsigned column, Scope *scope) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     QString _fileName; | 
					
						
							|  |  |  |     Control *_control; | 
					
						
							|  |  |  |     TranslationUnit *_translationUnit; | 
					
						
							|  |  |  |     Namespace *_globalNamespace; | 
					
						
							|  |  |  |     QList<DiagnosticMessage> _diagnosticMessages; | 
					
						
							| 
									
										
										
										
											2008-12-10 17:21:01 +01:00
										 |  |  |     QList<Include> _includes; | 
					
						
							| 
									
										
										
										
											2008-12-08 12:59:33 +01:00
										 |  |  |     QList<Macro> _definedMacros; | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     QList<Block> _skippedBlocks; | 
					
						
							| 
									
										
										
										
											2008-12-09 15:23:47 +01:00
										 |  |  |     QList<MacroUse> _macroUses; | 
					
						
							| 
									
										
										
										
											2009-02-24 11:04:52 +01:00
										 |  |  |     QByteArray _source; | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-12 10:07:58 +01:00
										 |  |  | class CPLUSPLUS_EXPORT Snapshot: public QMap<QString, Document::Ptr> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     Snapshot() | 
					
						
							|  |  |  |     { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ~Snapshot() | 
					
						
							|  |  |  |     { } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } // end of namespace CPlusPlus
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // CPPDOCUMENT_H
 |