Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/util/clangutils.cpp
Show First 20 Lines • Show All 238 Lines • ▼ Show 20 Line(s) | 222 | { | |||
---|---|---|---|---|---|
239 | if (functionName.contains(QLatin1Char('<'))) { | 239 | if (functionName.contains(QLatin1Char('<'))) { | ||
240 | stream << functionName.left(functionName.indexOf(QLatin1Char('<'))); | 240 | stream << functionName.left(functionName.indexOf(QLatin1Char('<'))); | ||
241 | } else { | 241 | } else { | ||
242 | stream << functionName; | 242 | stream << functionName; | ||
243 | } | 243 | } | ||
244 | 244 | | |||
245 | //Add the parameters and such | 245 | //Add the parameters and such | ||
246 | stream << '('; | 246 | stream << '('; | ||
247 | int numArgs = clang_Cursor_getNumArguments(cursor); | 247 | int numArgs ; | ||
248 | QVector<CXCursor> args; | ||||
249 | | ||||
250 | // SEE https://bugs.kde.org/show_bug.cgi?id=368544 | ||||
251 | // clang_Cursor_getNumArguments returns -1 for FunctionTemplate | ||||
252 | // clang checks if cursor's Decl is ObjCMethodDecl or FunctionDecl | ||||
253 | // CXCursor_FunctionTemplate is neither of them instead it has a FunctionTemplateDecl | ||||
254 | // HACK Get function template arguments by visiting children | ||||
255 | if (kind == CXCursor_FunctionTemplate) { | ||||
256 | clang_visitChildren(cursor, [] (CXCursor cursor, CXCursor /*parent*/, CXClientData data) { | ||||
257 | if (clang_getCursorKind(cursor) == CXCursor_ParmDecl) { | ||||
258 | (static_cast<QVector<CXCursor>*>(data))->push_back(cursor); | ||||
259 | } | ||||
260 | return CXChildVisit_Continue; | ||||
261 | }, &args); | ||||
262 | numArgs = args.size(); | ||||
263 | } else { | ||||
264 | numArgs = clang_Cursor_getNumArguments(cursor); | ||||
265 | args.reserve(numArgs); | ||||
248 | for (int i = 0; i < numArgs; i++) { | 266 | for (int i = 0; i < numArgs; i++) { | ||
249 | CXCursor arg = clang_Cursor_getArgument(cursor, i); | 267 | CXCursor arg = clang_Cursor_getArgument(cursor, i); | ||
268 | args.push_back(arg); | ||||
269 | } | ||||
270 | } | ||||
271 | | ||||
272 | for (int i = 0; i < numArgs; i++) { | ||||
273 | CXCursor arg = args[i]; | ||||
250 | 274 | | |||
251 | //Clang formats pointer types as "t *x" and reference types as "t &x", while | 275 | //Clang formats pointer types as "t *x" and reference types as "t &x", while | ||
252 | //KDevelop formats them as "t* x" and "t& x". Make that adjustment. | 276 | //KDevelop formats them as "t* x" and "t& x". Make that adjustment. | ||
253 | const QString type = ClangString(clang_getTypeSpelling(clang_getCursorType(arg))).toString(); | 277 | const QString type = ClangString(clang_getTypeSpelling(clang_getCursorType(arg))).toString(); | ||
254 | if (type.endsWith(QLatin1String(" *")) || type.endsWith(QLatin1String(" &"))) { | 278 | if (type.endsWith(QLatin1String(" *")) || type.endsWith(QLatin1String(" &"))) { | ||
255 | stream << type.left(type.length() - 2) << type.at(type.length() - 1); | 279 | stream << type.left(type.length() - 2) << type.at(type.length() - 1); | ||
256 | } else { | 280 | } else { | ||
257 | stream << type; | 281 | stream << type; | ||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |