aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2014-06-24 17:25:20 -0400
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-07-04 14:03:44 +0200
commit04d655dee0c2c5d4b1b8e6ac15c75a17776298fc (patch)
treeb7d10a7282c42c2bc6593e780c067137558e7e03 /src/libs/3rdparty/cplusplus/TranslationUnit.cpp
parentfa24266972fc8a824b451c1bd58b7acd427b46c0 (diff)
C++: Fix preprocessor line offsets
In TranslationUnit, the "normal" lines are based on utf16char offsets, but the preprocessor lines were based on byte/latin1 offsets. The preprocessor lines are now based on utf16char offsets, too. Task-number: QTCREATORBUG-7356 Change-Id: I3c41d1dcee8e9e487210f36da806b0229d3f4cd0 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/libs/3rdparty/cplusplus/TranslationUnit.cpp')
-rw-r--r--src/libs/3rdparty/cplusplus/TranslationUnit.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
index 9bc8edecfd..df9c2151a4 100644
--- a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
+++ b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp
@@ -164,7 +164,7 @@ void TranslationUnit::tokenize()
_Lrecognize:
if (tk.is(T_POUND) && tk.newline()) {
- unsigned offset = tk.byteOffset;
+ const unsigned utf16CharOffset = tk.utf16charOffset;
lex(&tk);
if (! tk.newline() && tk.is(T_IDENTIFIER) && tk.identifier == expansionId) {
@@ -237,7 +237,7 @@ void TranslationUnit::tokenize()
if (! tk.newline() && tk.is(T_STRING_LITERAL)) {
const StringLiteral *fileName =
control()->stringLiteral(tk.string->chars(), tk.string->size());
- pushPreprocessorLine(offset, line, fileName);
+ pushPreprocessorLine(utf16CharOffset, line, fileName);
lex(&tk);
}
}
@@ -343,10 +343,10 @@ bool TranslationUnit::parse(ParseMode mode)
void TranslationUnit::pushLineOffset(unsigned offset)
{ _lineOffsets.push_back(offset); }
-void TranslationUnit::pushPreprocessorLine(unsigned offset,
+void TranslationUnit::pushPreprocessorLine(unsigned utf16charOffset,
unsigned line,
const StringLiteral *fileName)
-{ _ppLines.push_back(PPLine(offset, line, fileName)); }
+{ _ppLines.push_back(PPLine(utf16charOffset, line, fileName)); }
unsigned TranslationUnit::findLineNumber(unsigned utf16charOffset) const
{
@@ -359,10 +359,10 @@ unsigned TranslationUnit::findLineNumber(unsigned utf16charOffset) const
return it - _lineOffsets.begin();
}
-TranslationUnit::PPLine TranslationUnit::findPreprocessorLine(unsigned offset) const
+TranslationUnit::PPLine TranslationUnit::findPreprocessorLine(unsigned utf16charOffset) const
{
std::vector<PPLine>::const_iterator it =
- std::lower_bound(_ppLines.begin(), _ppLines.end(), PPLine(offset));
+ std::lower_bound(_ppLines.begin(), _ppLines.end(), PPLine(utf16charOffset));
if (it != _ppLines.begin())
--it;
@@ -419,7 +419,7 @@ void TranslationUnit::getPosition(unsigned utf16charOffset,
// Adjust the line in regards to the preprocessing markers.
const PPLine ppLine = findPreprocessorLine(utf16charOffset);
- lineNumber -= findLineNumber(ppLine.offset) + 1;
+ lineNumber -= findLineNumber(ppLine.utf16charOffset) + 1;
lineNumber += ppLine.line;
file = ppLine.fileName;