Skip to content

Commit

Permalink
Issue Andersbakken#781. Store where the actual cursor of the argument…
Browse files Browse the repository at this point in the history
… is located as well.
  • Loading branch information
Andersbakken committed Sep 4, 2016
1 parent c563077 commit ad4dbcc
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.6)
project(rtags)
set(RTAGS_VERSION_MAJOR 2)
set(RTAGS_VERSION_MINOR 5)
set(RTAGS_VERSION_DATABASE 101)
set(RTAGS_VERSION_DATABASE 102)
set(RTAGS_VERSION_SOURCES_FILE 6)
set(RTAGS_VERSION ${RTAGS_VERSION_MAJOR}.${RTAGS_VERSION_MINOR}.${RTAGS_VERSION_DATABASE})

Expand Down
24 changes: 14 additions & 10 deletions src/ClangIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ CXChildVisitResult ClangIndexer::indexVisitor(CXCursor cursor)
break;
case CXCursor_CallExpr: {
// uglehack, see rtags/tests/nestedClassConstructorCallUgleHack/
List<std::pair<Location, int> > arguments;
List<Symbol::Argument> arguments;
extractArguments(&arguments, cursor);
Symbol *old = 0;
Location oldLoc;
Expand All @@ -740,7 +740,7 @@ CXChildVisitResult ClangIndexer::indexVisitor(CXCursor cursor)
} else {
handleReference(cursor, kind, loc, ref);
}
List<std::pair<Location, int> > destArguments;
List<Symbol::Argument> destArguments;
extractArguments(&destArguments, ref);
visit(cursor);
if (mLastCallExprSymbol && !arguments.isEmpty()) {
Expand All @@ -749,14 +749,14 @@ CXChildVisitResult ClangIndexer::indexVisitor(CXCursor cursor)
size_t idx = 0;
for (const auto &arg : arguments) {
const auto destArg = destArguments.value(idx);
if (destArg.first.isNull())
if (destArg.location.isNull())
break;
const Location start = arg.first;
const Location start = arg.location;
Location end;
if (idx + 1 == arguments.size()) {
end = Location(start.fileId(), start.line(), start.column() + arg.second); // this falls apart with multi-line args
end = Location(start.fileId(), start.line(), start.column() + arg.length); // this falls apart with multi-line args
} else {
end = arguments.value(idx + 1).first;
end = arguments.value(idx + 1).location;
}
auto it = u->symbols.lower_bound(start);
while (it != u->symbols.end() && it->first < end) {
Expand Down Expand Up @@ -1382,17 +1382,21 @@ void ClangIndexer::handleBaseClassSpecifier(const CXCursor &cursor)
lastClass.baseClasses << usr;
}

void ClangIndexer::extractArguments(List<std::pair<Location, int> > *arguments, const CXCursor &cursor)
void ClangIndexer::extractArguments(List<Symbol::Argument> *arguments, const CXCursor &cursor)
{
assert(arguments);
const int count = std::max(0, clang_Cursor_getNumArguments(cursor));
arguments->resize(count);
for (int i=0; i<count; ++i) {
CXSourceRange range = clang_getCursorExtent(clang_Cursor_getArgument(cursor, i));
auto &ref = (*arguments)[i];
CXCursor arg = clang_Cursor_getArgument(cursor, i);
CXSourceRange range = clang_getCursorExtent(arg);
unsigned startOffset, endOffset;
(*arguments)[i].first = createLocation(clang_getRangeStart(range), 0, &startOffset);

ref.location = createLocation(clang_getRangeStart(range), 0, &startOffset);
clang_getSpellingLocation(clang_getRangeEnd(range), 0, 0, 0, &endOffset);
(*arguments)[i].second = endOffset - startOffset;
ref.length = endOffset - startOffset;
ref.cursor = createLocation(arg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClangIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ClangIndexer

void addFileSymbol(uint32_t file);
int symbolLength(CXCursorKind kind, const CXCursor &cursor);
void extractArguments(List<std::pair<Location, int> > *arguments, const CXCursor &cursor);
void extractArguments(List<Symbol::Argument> *arguments, const CXCursor &cursor);

inline Location createLocation(const CXSourceLocation &location, bool *blocked = 0, unsigned *offset = 0)
{
Expand Down
14 changes: 8 additions & 6 deletions src/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ String Symbol::toString(Flags<ToStringFlag> cursorInfoFlags,
}
}
for (const auto &arg : arguments) {
const String symbolName = project->findSymbol(arg.first).symbolName;
const String symbolName = project->findSymbol(arg.cursor).symbolName;
if (!symbolName.isEmpty()) {
args << symbolName;
} else {
args << arg.first.toString(locationToStringFlags & ~Location::ShowContext);
args << arg.cursor.toString(locationToStringFlags & ~Location::ShowContext);
}
}
} else {
Expand Down Expand Up @@ -239,8 +239,9 @@ Value Symbol::toValue(const std::shared_ptr<Project> &project,
if (symbol.argumentUsage.index != String::npos) {
ret["invocation"] = symbol.argumentUsage.invocation.toString(locationToStringFlags);
ret["invokedFunction"] = symbol.argumentUsage.invokedFunction.toString(locationToStringFlags);
ret["functionArgumentLocation"] = symbol.argumentUsage.argument.first.toString(locationToStringFlags);
ret["functionArgumentLength"] = symbol.argumentUsage.argument.second;
ret["functionArgumentLocation"] = symbol.argumentUsage.argument.location.toString(locationToStringFlags);
ret["functionArgumentCursor"] = symbol.argumentUsage.argument.cursor.toString(locationToStringFlags);
ret["functionArgumentLength"] = symbol.argumentUsage.argument.length;
ret["argumentIndex"] = symbol.argumentUsage.index;
}
if (!symbol.symbolName.isEmpty())
Expand All @@ -261,8 +262,9 @@ Value Symbol::toValue(const std::shared_ptr<Project> &project,
Value args;
for (const auto &arg : symbol.arguments) {
Value a;
a["location"] = arg.first.toString(locationToStringFlags);
a["length"] = arg.second;
a["location"] = arg.location.toString(locationToStringFlags);
a["cursor"] = arg.cursor.toString(locationToStringFlags);
a["length"] = arg.length;
args.push_back(a);
}
ret["arguments"] = args;
Expand Down
48 changes: 39 additions & 9 deletions src/Symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,39 @@ struct Symbol
{}

Location location;
String symbolName, usr, typeName;
List<String> baseClasses;
struct Argument {
Argument()
: length(0)
{}
Location location, cursor;
size_t length;

void clear()
{
location.clear();
cursor.clear();
length = 0;
}
};
List<Argument> arguments;
struct ArgumentUsage {
ArgumentUsage()
: index(String::npos)
{}
void clear()
{
invocation.clear();
invokedFunction.clear();
argument.clear();
index = String::npos;
}
Location invocation, invokedFunction;
std::pair<Location, int> argument;
Argument argument;
size_t index;
} argumentUsage; // set for arguments only
} argumentUsage; // set for references that are used as an argument only

String symbolName, usr, typeName;
List<String> baseClasses;
List<std::pair<Location, int> > arguments;
uint16_t symbolLength;
CXCursorKind kind;
CXTypeKind type;
Expand Down Expand Up @@ -154,6 +175,18 @@ struct Symbol

RCT_FLAGS(Symbol::ToStringFlag);

template <> inline Serializer &operator<<(Serializer &s, const Symbol::Argument &arg)
{
s << arg.location << arg.cursor << arg.length;
return s;
}

template <> inline Deserializer &operator>>(Deserializer &s, Symbol::Argument &arg)
{
s >> arg.location >> arg.cursor >> arg.length;
return s;
}

template <> inline Serializer &operator<<(Serializer &s, const Symbol::ArgumentUsage &usage)
{
s << usage.index;
Expand All @@ -169,10 +202,7 @@ template <> inline Deserializer &operator>>(Deserializer &s, Symbol::ArgumentUsa
if (usage.index != String::npos) {
s >> usage.invocation >> usage.argument >> usage.invokedFunction;
} else {
usage.invocation.clear();
usage.invokedFunction.clear();
usage.argument.first.clear();
usage.argument.second = 0;
usage.clear();
}
return s;
}
Expand Down
5 changes: 3 additions & 2 deletions src/rtags.el
Original file line number Diff line number Diff line change
Expand Up @@ -4614,8 +4614,9 @@ the user enter missing field manually."
;; (args (mapcar (lambda (arg) (cdr (assoc 'symbolName arg))) (cdr (assoc 'arguments symbol))))
(index 2)
(snippet (concat "/** @Brief ${1:Function description}\n"
(mapconcat #'(lambda (arg)
(let* ((complete-name (cdr (assoc 'symbolName arg)))
(mapconcat #'(lambda (argLoc)
(let* ((arg (rtags-symbol-info-internal :location (cdr (assoc 'cursor argLoc))))
(complete-name (cdr (assoc 'symbolName arg)))
(symbol-type (cdr (assoc 'type arg)))
(symbol-name (substring complete-name (- 0 (cdr (assoc 'symbolLength arg)))))
(ret (format " * @param %s <b>{%s}</b> ${%d:Parameter description}"
Expand Down

0 comments on commit ad4dbcc

Please sign in to comment.