aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/cplusplus
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/3rdparty/cplusplus')
-rw-r--r--src/libs/3rdparty/cplusplus/TranslationUnit.cpp28
-rw-r--r--src/libs/3rdparty/cplusplus/TranslationUnit.h6
2 files changed, 25 insertions, 9 deletions
diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
index e680ee2660..8505deb0bd 100644
--- a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
+++ b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
@@ -27,7 +27,7 @@
#include "Literals.h"
#include "DiagnosticClient.h"
-#include "cppassert.h"
+#include <utils/qtcassert.h>
#include <utils/textutils.h>
#include <stack>
@@ -88,7 +88,7 @@ int TranslationUnit::sourceLength() const
void TranslationUnit::setSource(const char *source, int size)
{
- CPP_CHECK(source);
+ QTC_ASSERT(source, return);
_firstSourceChar = source;
_lastSourceChar = source + size;
}
@@ -191,6 +191,8 @@ void TranslationUnit::tokenize()
int lineColumnIdx = 0;
Token tk;
+ int macroOffset = -1;
+ int macroLength = -1;
do {
lex(&tk);
@@ -209,17 +211,12 @@ recognize:
lex(&tk);
// Gather where the expansion happens and its length.
- //int macroOffset = static_cast<int>(strtoul(tk.spell(), 0, 0));
+ macroOffset = static_cast<int>(strtoul(tk.spell(), 0, 0));
lex(&tk);
lex(&tk); // Skip the separating comma
- //int macroLength = static_cast<int>(strtoul(tk.spell(), 0, 0));
+ macroLength = static_cast<int>(strtoul(tk.spell(), 0, 0));
lex(&tk);
- // NOTE: We are currently not using the macro offset and length. They
- // are kept here for now because of future use.
- //Q_UNUSED(macroOffset)
- //Q_UNUSED(macroLength)
-
// Now we need to gather the real line and columns from the upcoming
// tokens. But notice this is only relevant for tokens which are expanded
// but not generated.
@@ -307,6 +304,11 @@ recognize:
tk.f.generated = currentGenerated;
_tokens->push_back(tk);
+
+ if (currentExpanded) {
+ QTC_ASSERT(macroOffset != -1 && macroLength != -1, continue);
+ _expansionPositions[_tokens->size() - 1] = std::make_pair(macroOffset, macroLength);
+ }
} while (tk.kind());
for (; ! braces.empty(); braces.pop()) {
@@ -462,6 +464,14 @@ int TranslationUnit::getTokenEndPositionInDocument(const Token &token,
return Utils::Text::positionInText(doc, line, column);
}
+std::pair<int, int> TranslationUnit::getExpansionPosition(int tokenIndex) const
+{
+ QTC_ASSERT(tokenIndex < int(_tokens->size()) && tokenAt(tokenIndex).generated(), return {});
+ const auto it = _expansionPositions.find(tokenIndex);
+ QTC_ASSERT(it != _expansionPositions.end(), return {});
+ return it->second;
+}
+
void TranslationUnit::getPosition(int utf16charOffset,
int *line,
int *column,
diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.h b/src/libs/3rdparty/cplusplus/TranslationUnit.h
index 40f79d0091..1332549ffd 100644
--- a/src/libs/3rdparty/cplusplus/TranslationUnit.h
+++ b/src/libs/3rdparty/cplusplus/TranslationUnit.h
@@ -133,6 +133,7 @@ public:
const StringLiteral **fileName = nullptr) const;
int getTokenPositionInDocument(const Token token, const QTextDocument *doc) const;
int getTokenEndPositionInDocument(const Token &token, const QTextDocument *doc) const;
+ std::pair<int, int> getExpansionPosition(int tokenIndex) const;
void pushLineOffset(int offset);
void pushPreprocessorLine(int utf16charOffset,
@@ -183,6 +184,11 @@ private:
std::vector<Token> *_comments;
std::vector<int> _lineOffsets;
std::vector<PPLine> _ppLines;
+
+ // Offset and length. Note that in contrast to token offsets, this is a raw file offset
+ // with no preprocessor prefix.
+ std::unordered_map<int, std::pair<int, int>> _expansionPositions;
+
typedef std::unordered_map<unsigned, std::pair<int, int> > TokenLineColumn;
TokenLineColumn _expandedLineColumn;
MemoryPool *_pool;