diff options
| author | Nikolai Kosjar <[email protected]> | 2014-05-09 10:04:13 -0400 |
|---|---|---|
| committer | Nikolai Kosjar <[email protected]> | 2014-05-23 14:34:01 +0200 |
| commit | c6358e5d380c18f3ebff148a095ddf3a9d6b266c (patch) | |
| tree | 84fc2fa9919e2d57720ae3944e2d3a94b6c28c68 /src/libs/cplusplus/CppDocument.cpp | |
| parent | bb7da966b801a2884cd7cf47f640bf7ac7d775df (diff) | |
C++: Add utf16 indices to Macro and Document::MacroUse
In most cases we need to work with the utf16 indices. Only in
cppfindreferences the byte interface is still needed since there we read
in files and work on a QByteArray to save memory.
Change-Id: I6ef6a93fc1875a8c9a305c075d51a9ca034c41bb
Reviewed-by: Erik Verbruggen <[email protected]>
Diffstat (limited to 'src/libs/cplusplus/CppDocument.cpp')
| -rw-r--r-- | src/libs/cplusplus/CppDocument.cpp | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp index 61d82d945ed..4fa078d6ee8 100644 --- a/src/libs/cplusplus/CppDocument.cpp +++ b/src/libs/cplusplus/CppDocument.cpp @@ -365,25 +365,31 @@ void Document::appendMacro(const Macro ¯o) _definedMacros.append(macro); } -void Document::addMacroUse(const Macro ¯o, unsigned offset, unsigned length, +void Document::addMacroUse(const Macro ¯o, + unsigned bytesOffset, unsigned bytesLength, + unsigned utf16charsOffset, unsigned utf16charLength, unsigned beginLine, const QVector<MacroArgumentReference> &actuals) { - MacroUse use(macro, offset, offset + length, beginLine); + MacroUse use(macro, + bytesOffset, bytesOffset + bytesLength, + utf16charsOffset, utf16charsOffset + utf16charLength, + beginLine); foreach (const MacroArgumentReference &actual, actuals) { - const Block arg(actual.position(), actual.position() + actual.length()); - + const Block arg(0, 0, actual.utf16charsOffset(), + actual.utf16charsOffset() + actual.utf16charsLength()); use.addArgument(arg); } _macroUses.append(use); } -void Document::addUndefinedMacroUse(const QByteArray &name, unsigned offset) +void Document::addUndefinedMacroUse(const QByteArray &name, + unsigned bytesOffset, unsigned utf16charsOffset) { QByteArray copy(name.data(), name.size()); - UndefinedMacroUse use(copy, offset); + UndefinedMacroUse use(copy, bytesOffset, utf16charsOffset); _undefinedMacroUses.append(use); } @@ -548,19 +554,23 @@ const Macro *Document::findMacroDefinitionAt(unsigned line) const return 0; } -const Document::MacroUse *Document::findMacroUseAt(unsigned offset) const +const Document::MacroUse *Document::findMacroUseAt(unsigned utf16charsOffset) const { foreach (const Document::MacroUse &use, _macroUses) { - if (use.contains(offset) && (offset < use.begin() + use.macro().name().length())) + if (use.containsUtf16charOffset(utf16charsOffset) + && (utf16charsOffset < use.utf16charsBegin() + use.macro().nameToQString().size())) { return &use; + } } return 0; } -const Document::UndefinedMacroUse *Document::findUndefinedMacroUseAt(unsigned offset) const +const Document::UndefinedMacroUse *Document::findUndefinedMacroUseAt(unsigned utf16charsOffset) const { foreach (const Document::UndefinedMacroUse &use, _undefinedMacroUses) { - if (use.contains(offset) && (offset < use.begin() + use.name().length())) + if (use.containsUtf16charOffset(utf16charsOffset) + && (utf16charsOffset < use.utf16charsBegin() + + QString::fromUtf8(use.name(), use.name().size()).length())) return &use; } return 0; @@ -581,21 +591,21 @@ void Document::setUtf8Source(const QByteArray &source) _translationUnit->setSource(_source.constBegin(), _source.size()); } -void Document::startSkippingBlocks(unsigned start) +void Document::startSkippingBlocks(unsigned utf16charsOffset) { - _skippedBlocks.append(Block(start, 0)); + _skippedBlocks.append(Block(0, 0, utf16charsOffset, 0)); } -void Document::stopSkippingBlocks(unsigned stop) +void Document::stopSkippingBlocks(unsigned utf16charsOffset) { if (_skippedBlocks.isEmpty()) return; - unsigned start = _skippedBlocks.back().begin(); - if (start > stop) + unsigned start = _skippedBlocks.back().utf16charsBegin(); + if (start > utf16charsOffset) _skippedBlocks.removeLast(); // Ignore this block, it's invalid. else - _skippedBlocks.back() = Block(start, stop); + _skippedBlocks.back() = Block(0, 0, start, utf16charsOffset); } bool Document::isTokenized() const |
