1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include "fulltokeninfo.h"
29 #include "tokenprocessor.h"
30 
31 #include <clangsupport/codecompletion.h>
32 
33 #include <clang-c/Index.h>
34 
35 namespace ClangBackEnd {
36 
37 class Cursor;
38 class DiagnosticContainer;
39 class DiagnosticSet;
40 class FollowSymbolResult;
41 class ReferencesResult;
42 class SkippedSourceRanges;
43 class SourceLocation;
44 class SourceRange;
45 class SourceRangeContainer;
46 class ToolTipInfo;
47 class TranslationUnitUpdateInput;
48 class TranslationUnitUpdateResult;
49 class UnsavedFiles;
50 class CommandLineArguments;
51 
52 class TranslationUnit
53 {
54 public:
55     TranslationUnit(const Utf8String &id,
56                     const Utf8String &filePath,
57                     CXIndex &cxIndex,
58                     CXTranslationUnit &cxTranslationUnit);
59 
60     bool isNull() const;
61 
62     Utf8String id() const;
63 
64     Utf8String filePath() const;
65     CXIndex &cxIndex() const;
66     CXTranslationUnit &cxTranslationUnit() const;
67 
68     bool suspend() const;
69 
70     TranslationUnitUpdateResult update(const TranslationUnitUpdateInput &parseInput) const;
71     TranslationUnitUpdateResult parse(const TranslationUnitUpdateInput &parseInput) const;
72     TranslationUnitUpdateResult reparse(const TranslationUnitUpdateInput &parseInput) const;
73 
74     CodeCompletions complete(UnsavedFiles &unsavedFiles, uint line, uint column,
75                              int funcNameStartLine, int funcNameStartColumn) const;
76 
77     void extractDiagnostics(DiagnosticContainer &firstHeaderErrorDiagnostic,
78                             QVector<DiagnosticContainer> &mainFileDiagnostics) const;
79     void extractAnnotations(DiagnosticContainer &firstHeaderErrorDiagnostic,
80                             QVector<DiagnosticContainer> &mainFileDiagnostics,
81                             QVector<TokenInfoContainer> &tokenInfos,
82                             QVector<SourceRangeContainer> &skippedSourceRanges) const;
83 
84     ReferencesResult references(uint line, uint column, bool localReferences = false) const;
85     ToolTipInfo tooltip(UnsavedFiles &unsavedFiles,
86                         const Utf8String &textCodecName,
87                         uint line,
88                         uint column) const;
89     DiagnosticSet diagnostics() const;
90 
91     SourceLocation sourceLocationAt(uint line, uint column) const;
92     SourceLocation sourceLocationAt(const Utf8String &filePath, uint line, uint column) const;
93     SourceRange sourceRange(uint fromLine, uint fromColumn, uint toLine, uint toColumn) const;
94 
95     Cursor cursorAt(uint line, uint column) const;
96     Cursor cursorAt(const Utf8String &filePath, uint line, uint column) const;
97     Cursor cursor() const;
98 
99     TokenProcessor<TokenInfo> tokenInfos() const;
100     TokenProcessor<TokenInfo> tokenInfosInRange(const SourceRange &range) const;
101 
102     TokenProcessor<FullTokenInfo> fullTokenInfos() const;
103     TokenProcessor<FullTokenInfo> fullTokenInfosInRange(const SourceRange &range) const;
104 
105     SkippedSourceRanges skippedSourceRanges() const;
106     FollowSymbolResult followSymbol(uint line, uint column) const;
107 
108 private:
109     const Utf8String m_id;
110     const Utf8String m_filePath;
111     CXIndex &m_cxIndex;
112     CXTranslationUnit &m_cxTranslationUnit;
113 };
114 
115 } // namespace ClangBackEnd
116