Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/codegen/adaptsignatureassistant.cpp
Show All 40 Lines | 38 | { | |||
---|---|---|---|---|---|
41 | if (!top) { | 41 | if (!top) { | ||
42 | clangDebug() << "no context found for document" << documentUrl; | 42 | clangDebug() << "no context found for document" << documentUrl; | ||
43 | return nullptr; | 43 | return nullptr; | ||
44 | } | 44 | } | ||
45 | const auto *context = top->findContextAt(top->transformToLocalRevision(cursor), true); | 45 | const auto *context = top->findContextAt(top->transformToLocalRevision(cursor), true); | ||
46 | return context->type() == DUContext::Function ? context->owner() : nullptr; | 46 | return context->type() == DUContext::Function ? context->owner() : nullptr; | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | bool isConstructor(const Declaration *functionDecl) | 49 | bool isConstructor(const Declaration *functionDecl) | ||
mwolff: afaik you can simplify the below by reusing a function from DUChainUtils that gets you the… | |||||
bool isConstructor(const Declaration *functionDecl) { auto classFun = dynamic_cast<const ClassFunctionDeclaration*>(DUChainUtils::declarationForDefinition(functionDecl)); return classFun && classFun->isConstructor(); } mwolff: ```
bool isConstructor(const Declaration *functionDecl)
{
auto classFun =… | |||||
50 | { | 50 | { | ||
51 | auto classFun = dynamic_cast<const ClassFunctionDeclaration*>(functionDecl); | 51 | auto classFun = dynamic_cast<const ClassFunctionDeclaration*>(DUChainUtils::declarationForDefinition(const_cast<Declaration*>(functionDecl))); | ||
52 | return classFun && classFun->isConstructor(); | 52 | return classFun && classFun->isConstructor(); | ||
53 | } | 53 | } | ||
mwolff: here and below: space after keywords (`if (...`) | |||||
54 | 54 | | |||
55 | Signature getDeclarationSignature(const Declaration *functionDecl, const DUContext *functionCtxt, bool includeDefaults) | 55 | Signature getDeclarationSignature(const Declaration *functionDecl, const DUContext *functionCtxt, bool includeDefaults) | ||
56 | { | 56 | { | ||
57 | ENSURE_CHAIN_READ_LOCKED | 57 | ENSURE_CHAIN_READ_LOCKED | ||
58 | int pos = 0; | 58 | int pos = 0; | ||
59 | Signature signature; | 59 | Signature signature; | ||
apol: Only need to lock here, no? Or at least after the if. | |||||
Yeah but the macro is not a lock, just an assert. If you expect the function to be called with the lock, it IMO makes sense to put it on the top. brauch: Yeah but the macro is not a lock, just an assert. If you expect the function to be called with… | |||||
60 | const AbstractFunctionDeclaration* abstractFunDecl = dynamic_cast<const AbstractFunctionDeclaration*>(functionDecl); | 60 | const AbstractFunctionDeclaration* abstractFunDecl = dynamic_cast<const AbstractFunctionDeclaration*>(functionDecl); | ||
61 | foreach(Declaration * parameter, functionCtxt->localDeclarations()) { | 61 | foreach(Declaration * parameter, functionCtxt->localDeclarations()) { | ||
62 | signature.defaultParams << (includeDefaults ? abstractFunDecl->defaultParameterForArgument(pos).str() : QString()); | 62 | signature.defaultParams << (includeDefaults ? abstractFunDecl->defaultParameterForArgument(pos).str() : QString()); | ||
63 | signature.parameters << qMakePair(parameter->indexedType(), parameter->identifier().identifier().str()); | 63 | signature.parameters << qMakePair(parameter->indexedType(), parameter->identifier().identifier().str()); | ||
64 | ++pos; | 64 | ++pos; | ||
65 | } | 65 | } | ||
66 | signature.isConst = functionDecl->abstractType() && functionDecl->abstractType()->modifiers() & AbstractType::ConstModifier; | 66 | signature.isConst = functionDecl->abstractType() && functionDecl->abstractType()->modifiers() & AbstractType::ConstModifier; | ||
67 | 67 | | |||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |
afaik you can simplify the below by reusing a function from DUChainUtils that gets you the declaration for a definition. always cast that at the start and then cast the return result