forked from qt-creator/qt-creator
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:
@@ -247,22 +247,22 @@ void HighlightingMark::collectOutputArguments(const Cursor &cursor)
|
|||||||
|
|
||||||
namespace {
|
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()
|
void HighlightingMark::filterOutPreviousOutputArguments()
|
||||||
{
|
{
|
||||||
auto isAfterLocation = [this] (CXSourceRange outputRange) {
|
auto isAfterLocation = [this] (CXSourceRange outputRange) {
|
||||||
return getStart(outputRange) > m_offset;
|
return getEnd(outputRange) > m_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto precedingBegin = std::partition(m_currentOutputArgumentRanges->begin(),
|
auto precedingBegin = std::partition(m_currentOutputArgumentRanges->begin(),
|
||||||
@@ -279,6 +279,9 @@ void HighlightingMark::functionKind(const Cursor &cursor, Recursion recursion)
|
|||||||
else
|
else
|
||||||
m_types.mainHighlightingType = HighlightingType::Function;
|
m_types.mainHighlightingType = HighlightingType::Function;
|
||||||
|
|
||||||
|
if (isOutputArgument())
|
||||||
|
m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument);
|
||||||
|
|
||||||
addExtraTypeIfFirstPass(HighlightingType::Declaration, recursion);
|
addExtraTypeIfFirstPass(HighlightingType::Declaration, recursion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +387,9 @@ HighlightingType HighlightingMark::punctuationKind(const Cursor &cursor)
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isOutputArgument())
|
||||||
|
m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument);
|
||||||
|
|
||||||
return highlightingType;
|
return highlightingType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -109,4 +109,16 @@ HighlightingMark HighlightingMarks::operator[](size_t index) const
|
|||||||
currentOutputArgumentRanges);
|
currentOutputArgumentRanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const HighlightingMarks &marks)
|
||||||
|
{
|
||||||
|
out << "[";
|
||||||
|
|
||||||
|
for (const HighlightingMark entry : marks)
|
||||||
|
out << entry;
|
||||||
|
|
||||||
|
out << "]";
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
@@ -69,4 +69,6 @@ private:
|
|||||||
std::vector<CXCursor> cxCursor;
|
std::vector<CXCursor> cxCursor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const HighlightingMarks &marks);
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
@@ -565,3 +565,17 @@ void g(OtherOperator o, int var)
|
|||||||
{
|
{
|
||||||
o(var);
|
o(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NonConstPointerArgument(int &argument);
|
||||||
|
|
||||||
|
struct PointerGetterClass
|
||||||
|
{
|
||||||
|
int &getter();
|
||||||
|
};
|
||||||
|
|
||||||
|
void f32()
|
||||||
|
{
|
||||||
|
PointerGetterClass x;
|
||||||
|
|
||||||
|
NonConstPointerArgument(x.getter());
|
||||||
|
}
|
||||||
|
@@ -60,6 +60,8 @@ using testing::IsNull;
|
|||||||
using testing::NotNull;
|
using testing::NotNull;
|
||||||
using testing::Gt;
|
using testing::Gt;
|
||||||
using testing::Contains;
|
using testing::Contains;
|
||||||
|
using testing::ElementsAre;
|
||||||
|
using testing::_;
|
||||||
using testing::EndsWith;
|
using testing::EndsWith;
|
||||||
using testing::AllOf;
|
using testing::AllOf;
|
||||||
using testing::Not;
|
using testing::Not;
|
||||||
@@ -96,6 +98,14 @@ MATCHER_P2(HasTwoTypes, firstType, secondType,
|
|||||||
return arg.hasMainType(firstType) && arg.hasMixinType(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 {
|
struct Data {
|
||||||
Data()
|
Data()
|
||||||
{
|
{
|
||||||
@@ -1021,6 +1031,23 @@ TEST_F(HighlightingMarks, ConstPointerArgument)
|
|||||||
HasOnlyType(HighlightingType::LocalVariable));
|
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)
|
TEST_F(HighlightingMarks, NonConstReferenceArgumentCallInsideCall)
|
||||||
{
|
{
|
||||||
const auto infos = translationUnit.highlightingMarksInRange(sourceRange(501, 64));
|
const auto infos = translationUnit.highlightingMarksInRange(sourceRange(501, 64));
|
||||||
|
Reference in New Issue
Block a user