Clang: Show all tokens of a getter as output argument

f(x.get()); -> x.get() should be shown as a output argument

Task-number: QTCREATORBUG-18591
Change-Id: I99f5637660bcd0a889338ebfa6737d79de226f87
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Marco Bubke
2017-07-20 17:59:35 +02:00
parent e97ff9f739
commit 99af4ae8e6
5 changed files with 67 additions and 6 deletions

View File

@@ -247,22 +247,22 @@ void HighlightingMark::collectOutputArguments(const Cursor &cursor)
namespace {
uint getStart(CXSourceRange cxSourceRange)
uint getEnd(CXSourceRange cxSourceRange)
{
CXSourceLocation startSourceLocation = clang_getRangeStart(cxSourceRange);
CXSourceLocation startSourceLocation = clang_getRangeEnd(cxSourceRange);
uint startOffset;
uint endOffset;
clang_getFileLocation(startSourceLocation, nullptr, nullptr, nullptr, &startOffset);
clang_getFileLocation(startSourceLocation, nullptr, nullptr, nullptr, &endOffset);
return startOffset;
return endOffset;
}
}
void HighlightingMark::filterOutPreviousOutputArguments()
{
auto isAfterLocation = [this] (CXSourceRange outputRange) {
return getStart(outputRange) > m_offset;
return getEnd(outputRange) > m_offset;
};
auto precedingBegin = std::partition(m_currentOutputArgumentRanges->begin(),
@@ -279,6 +279,9 @@ void HighlightingMark::functionKind(const Cursor &cursor, Recursion recursion)
else
m_types.mainHighlightingType = HighlightingType::Function;
if (isOutputArgument())
m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument);
addExtraTypeIfFirstPass(HighlightingType::Declaration, recursion);
}
@@ -384,6 +387,9 @@ HighlightingType HighlightingMark::punctuationKind(const Cursor &cursor)
default: break;
}
if (isOutputArgument())
m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument);
return highlightingType;
}

View File

@@ -109,4 +109,16 @@ HighlightingMark HighlightingMarks::operator[](size_t index) const
currentOutputArgumentRanges);
}
std::ostream &operator<<(std::ostream &out, const HighlightingMarks &marks)
{
out << "[";
for (const HighlightingMark entry : marks)
out << entry;
out << "]";
return out;
}
} // namespace ClangBackEnd

View File

@@ -69,4 +69,6 @@ private:
std::vector<CXCursor> cxCursor;
};
std::ostream &operator<<(std::ostream &out, const HighlightingMarks &marks);
} // namespace ClangBackEnd

View File

@@ -565,3 +565,17 @@ void g(OtherOperator o, int var)
{
o(var);
}
void NonConstPointerArgument(int &argument);
struct PointerGetterClass
{
int &getter();
};
void f32()
{
PointerGetterClass x;
NonConstPointerArgument(x.getter());
}

View File

@@ -60,6 +60,8 @@ using testing::IsNull;
using testing::NotNull;
using testing::Gt;
using testing::Contains;
using testing::ElementsAre;
using testing::_;
using testing::EndsWith;
using testing::AllOf;
using testing::Not;
@@ -96,6 +98,14 @@ MATCHER_P2(HasTwoTypes, firstType, secondType,
return arg.hasMainType(firstType) && arg.hasMixinType(secondType);
}
MATCHER_P(HasMixin, firstType,
std::string(negation ? "isn't " : "is ")
+ PrintToString(firstType)
)
{
return arg.hasMixinType(firstType);
}
struct Data {
Data()
{
@@ -1021,6 +1031,23 @@ TEST_F(HighlightingMarks, ConstPointerArgument)
HasOnlyType(HighlightingType::LocalVariable));
}
TEST_F(HighlightingMarks, NonConstPointerGetterAsArgument)
{
const auto infos = translationUnit.highlightingMarksInRange(sourceRange(580, 41));
ASSERT_THAT(infos,
ElementsAre(_,
_,
HasMixin(HighlightingType::OutputArgument),
HasMixin(HighlightingType::OutputArgument),
HasMixin(HighlightingType::OutputArgument),
HasMixin(HighlightingType::OutputArgument),
HasMixin(HighlightingType::OutputArgument),
_,
_,
_));
}
TEST_F(HighlightingMarks, NonConstReferenceArgumentCallInsideCall)
{
const auto infos = translationUnit.highlightingMarksInRange(sourceRange(501, 64));