25#include <QtCore/qdebug.h>
26#include <QtCore/qdir.h>
27#include <QtCore/qelapsedtimer.h>
28#include <QtCore/qfile.h>
29#include <QtCore/qregularexpression.h>
30#include <QtCore/qscopedvaluerollback.h>
31#include <QtCore/qtemporarydir.h>
32#include <QtCore/qtextstream.h>
33#include <QtCore/qvarlengtharray.h>
35#include <clang-c/Index.h>
37#include <clang/AST/ASTConcept.h>
38#include <clang/AST/Decl.h>
39#include <clang/AST/DeclFriend.h>
40#include <clang/AST/DeclTemplate.h>
41#include <clang/AST/Expr.h>
42#include <clang/AST/ExprConcepts.h>
43#include <clang/AST/Type.h>
44#include <clang/AST/TypeLoc.h>
45#include <clang/Basic/SourceLocation.h>
46#include <clang/Frontend/ASTUnit.h>
47#include <clang/Lex/Lexer.h>
48#include <llvm/Support/Casting.h>
50#include "clang/AST/QualTypeNames.h"
60using namespace Qt::Literals::StringLiterals;
70 clang_disposeIndex(
index);
75 CXTranslationUnit
tu =
nullptr;
86 clang_disposeTranslationUnit(
tu);
94static CXTranslationUnit_Flags
flags_ =
static_cast<CXTranslationUnit_Flags>(0);
98#ifndef QT_NO_DEBUG_STREAM
102 QDebugStateSaver saver(debug);
105 const size_t size = v.size();
106 debug <<
"std::vector<>[" << size <<
"](";
107 for (size_t i = 0; i < size; ++i) {
119 if (!lcQdocClang().isDebugEnabled())
122 static const auto displayOptions = CXDiagnosticDisplayOptions::CXDiagnostic_DisplaySourceLocation
123 | CXDiagnosticDisplayOptions::CXDiagnostic_DisplayColumn
124 | CXDiagnosticDisplayOptions::CXDiagnostic_DisplayOption;
126 for (
unsigned i = 0, numDiagnostics = clang_getNumDiagnostics(translationUnit); i < numDiagnostics; ++i) {
127 auto diagnostic = clang_getDiagnostic(translationUnit, i);
128 auto formattedDiagnostic = clang_formatDiagnostic(diagnostic, displayOptions);
129 qCDebug(lcQdocClang) << clang_getCString(formattedDiagnostic);
130 clang_disposeString(formattedDiagnostic);
131 clang_disposeDiagnostic(diagnostic);
136
137
138
139
140
141
142
143
144
145
146
147
149 assert(clang_isDeclaration(clang_getCursorKind(cursor)));
151 return static_cast<
const clang::Decl*>(cursor.data[0]);
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
205 const clang::RecordType *rt = type->getAs<
clang::RecordType>();
210 std::vector<std::string> keywords;
211 const clang::RecordDecl *decl = rt->getDecl();
213 if (decl->getDeclName().isEmpty())
214 keywords.emplace_back(decl->getKindName());
215 const auto *parent = llvm::dyn_cast<
clang::RecordDecl>(decl->getDeclContext());
220 std::reverse(keywords.begin(), keywords.end());
226 static constexpr std::string_view prefixes[] = {
"(unnamed",
"(anonymous" };
227 size_t keywordIndex = 0;
229 while (pos < typeName.size() && keywordIndex < keywords.size()) {
230 std::string_view foundPrefix;
231 size_t foundPos = std::string::npos;
232 for (
auto prefix : prefixes) {
233 size_t p = typeName.find(prefix, pos);
236 foundPrefix = prefix;
239 if (foundPos == std::string::npos)
242 size_t afterPrefix = foundPos + foundPrefix.size();
243 if (afterPrefix < typeName.size() && typeName[afterPrefix] ==
')') {
245 typeName.insert(afterPrefix,
" " + keywords[keywordIndex]);
246 pos = afterPrefix + 1 + keywords[keywordIndex].size() + 1;
249 size_t closePos = typeName.find(
')', afterPrefix);
250 pos = (closePos != std::string::npos) ? closePos + 1 : afterPrefix;
258 auto policy = declaration_context.getPrintingPolicy();
259#if LIBCLANG_VERSION_MAJOR >= 23
260 policy.AnonymousTagNameStyle = llvm::to_underlying(clang::PrintingPolicy::AnonymousTagMode::Plain);
262 policy.AnonymousTagLocations =
false;
265 return ensureAnonymousTagKeyword(
std::move(result), type);
269
270
271
272
273
274
275
276
277
279 if (!typeName.contains(
"(unnamed "_L1) && !typeName.contains(
"(anonymous "_L1))
282 static const QRegularExpression pattern(
283 R"(\((unnamed|anonymous)(\s+\w+)\s+at\s+[^)]+\))"
285 QString cleaned = typeName;
286 cleaned.replace(pattern,
"(\\1\\2)"_L1);
291
292
293
294
295
296
297
298
299
301 QString default_value = QString::fromStdString(clang::Lexer::getSourceText(
302 clang::CharSourceRange::getTokenRange(expression->getSourceRange()),
303 declaration_context.getSourceManager(),
304 declaration_context.getLangOpts()
307 if (default_value.startsWith(
"="))
308 default_value.remove(0, 1);
310 default_value = default_value.trimmed();
312 return default_value.toStdString();
316
317
318
319
320
321
322
323
325 std::vector<std::string> &out)
329 if (
const auto *cse = llvm::dyn_cast<clang::ConceptSpecializationExpr>(node)) {
330 if (
const auto *concept_decl = cse->getNamedConcept())
331 out.push_back(concept_decl->getQualifiedNameAsString());
333 for (
const clang::Stmt *child : node->children())
334 collect_concept_references(child, out);
338
339
340
341
342
343
344
345
347 return (parameter && parameter->hasDefaultArgument()) ?
348 get_fully_qualified_type_name(parameter->getDefaultArgument().getArgument().getAsType(), parameter->getASTContext()) :
353
354
355
356
357
358
359
360
362 return (parameter && parameter->hasDefaultArgument()) ?
363 get_expression_as_string(parameter->getDefaultArgument().getSourceExpression(), parameter->getASTContext()) :
"";
367
368
369
370
371
372
373
374
376 std::string default_value{};
378 if (parameter && parameter->hasDefaultArgument()) {
379 const clang::TemplateName template_name = parameter->getDefaultArgument().getArgument().getAsTemplate();
381 llvm::raw_string_ostream ss{default_value};
382 template_name.print(ss, parameter->getASTContext().getPrintingPolicy(),
clang::TemplateName::Qualified::AsWritten);
385 return default_value;
389
390
391
392
393
394
395
396
397
398
400 if (!parameter || !parameter->hasDefaultArg() || parameter->hasUnparsedDefaultArg())
403 return get_expression_as_string(
404 parameter->hasUninstantiatedDefaultArg() ? parameter->getUninstantiatedDefaultArg() : parameter->getDefaultArg(),
405 parameter->getASTContext()
410
411
412
413
414
415
416
418 if (!declaration)
return "";
420 if (
auto type_template_parameter = llvm::dyn_cast<clang::TemplateTypeParmDecl>(declaration))
421 return get_default_value_initializer_as_string(type_template_parameter);
423 if (
auto non_type_template_parameter = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(declaration))
424 return get_default_value_initializer_as_string(non_type_template_parameter);
426 if (
auto template_template_parameter = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(declaration)) {
427 return get_default_value_initializer_as_string(template_template_parameter);
430 if (
auto function_parameter = llvm::dyn_cast<clang::ParmVarDecl>(declaration)) {
431 return get_default_value_initializer_as_string(function_parameter);
438
439
440
441
445 CXCursorVisitor visitor = [](CXCursor c, CXCursor,
446 CXClientData client_data) -> CXChildVisitResult {
447 return (*
static_cast<T *>(client_data))(c);
449 return clang_visitChildren(cursor, visitor, &lambda);
453
454
457 QString ret = QString::fromUtf8(clang_getCString(string));
458 clang_disposeString(string);
463
464
465
466
467
468
469
471 const clang::Type *type)
475 for (
int depth = 0; depth < 10 && type; ++depth) {
476 if (
auto *tst = llvm::dyn_cast<clang::TemplateSpecializationType>(type))
479#if LIBCLANG_VERSION_MAJOR < 22
481 if (
auto *elaborated = llvm::dyn_cast<clang::ElaboratedType>(type)) {
482 type = elaborated->getNamedType().getTypePtr();
495
496
497
500 auto ends_with = [](
const std::string &str,
const std::string &suffix) {
501 return str.size() >= suffix.size()
502 && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
505 return ends_with(qualified_name,
"enable_if_t")
506 || ends_with(qualified_name,
"enable_if");
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
534 const clang::NonTypeTemplateParmDecl *param)
536 if (!param->getName().empty())
539 auto policy = param->getASTContext().getPrintingPolicy();
541 const clang::Type *type = param->getType().getTypePtr();
560 if (!param->hasDefaultArgument())
563 std::string type_name = param->getType().getAsString(policy);
564 if (type_name.find(
'<') != std::string::npos)
570 auto *alias_decl = alias_type->getTemplateName().getAsTemplateDecl();
575 bool found_enable_if =
false;
576 const clang::Type *sugar = alias_type->desugar().getTypePtr();
578 for (
int depth = 0; depth < 10 && sugar; ++depth) {
583 if (
auto *decl = tst->getTemplateName().getAsTemplateDecl()) {
584 if (is_enable_if_name(decl->getQualifiedNameAsString())) {
585 found_enable_if =
true;
590 sugar = tst->desugar().getTypePtr();
593 if (!found_enable_if)
602 param->getType().getAsString(policy)
607
608
609
611 assert(template_declaration);
615 auto template_parameters = template_declaration->getTemplateParameters();
616 for (
auto template_parameter : template_parameters->asArray()) {
617 auto kind{RelaxedTemplateParameter::Kind::TypeTemplateParameter};
620 std::optional<SfinaeConstraint> sfinae{};
622 if (
auto non_type_template_parameter = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(template_parameter)) {
623 kind = RelaxedTemplateParameter::Kind::NonTypeTemplateParameter;
624 type = get_fully_qualified_type_name(non_type_template_parameter->getType(), non_type_template_parameter->getASTContext());
656 if (QString::fromStdString(type).startsWith(
"typename ")) type.erase(0, std::string(
"typename ").size());
658 sfinae = detect_sfinae_constraint(non_type_template_parameter);
661 auto template_template_parameter = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(template_parameter);
662 if (template_template_parameter) kind = RelaxedTemplateParameter::Kind::TemplateTemplateParameter;
664 template_declaration_ir.parameters.push_back({
666 template_parameter->isTemplateParameterPack(),
669 template_parameter->getNameAsString(),
670 get_default_value_initializer_as_string(template_parameter)
672 (template_template_parameter ?
673 std::optional<TemplateDeclarationStorage>(TemplateDeclarationStorage{
674 get_template_declaration(template_template_parameter).parameters
690 if (
const auto *type_template_parameter =
691 llvm::dyn_cast<clang::TemplateTypeParmDecl>(template_parameter)) {
692 if (type_template_parameter->hasTypeConstraint()) {
693 if (
const clang::TypeConstraint *constraint =
694 type_template_parameter->getTypeConstraint()) {
695 if (
const clang::NamedDecl *concept_decl =
696 constraint->getNamedConcept()) {
697 template_declaration_ir.referenced_concepts.push_back(
698 concept_decl->getQualifiedNameAsString());
699 template_declaration_ir.parameters.back().concept_name =
700 concept_decl->getQualifiedNameAsString();
708 std::string explicit_requires;
709 if (
const clang::Expr *requires_clause = template_parameters->getRequiresClause()) {
710 explicit_requires = QString::fromStdString(get_expression_as_string(
711 requires_clause, template_declaration->getASTContext())).simplified().toStdString();
712 collect_concept_references(requires_clause,
713 template_declaration_ir.referenced_concepts);
723 std::string synthesized;
724 const auto ¶ms = template_declaration_ir.parameters;
726 for (
const auto ¶m : params) {
727 if (param.sfinae_constraint) {
728 if (!synthesized.empty())
729 synthesized +=
" && ";
730 synthesized += param.sfinae_constraint->alias_with_args;
737 if (!synthesized.empty() && !explicit_requires.empty())
738 template_declaration_ir.requires_clause = synthesized +
" && (" + explicit_requires +
")";
739 else if (!synthesized.empty())
740 template_declaration_ir.requires_clause =
std::move(synthesized);
741 else if (!explicit_requires.empty())
742 template_declaration_ir.requires_clause =
std::move(explicit_requires);
746 auto &refs = template_declaration_ir.referenced_concepts;
747 std::sort(refs.begin(), refs.end());
748 refs.erase(
std::unique(refs.begin(), refs.end()), refs.end());
751 return template_declaration_ir;
755
756
759 unsigned int line, column;
761 clang_getPresumedLocation(location, &file, &line, &column);
769
770
775 return Access::Private;
776 case CX_CXXProtected:
777 return Access::Protected;
779 return Access::Public;
781 return Access::Public;
786
787
796 unsigned int offset1,
unsigned int offset2)
798 return QString::fromUtf8(cache.mid(offset1, offset2 - offset1));
801static QString
readFile(CXFile cxFile,
unsigned int offset1,
unsigned int offset2)
803 using FileCache = QList<FileCacheEntry>;
804 static FileCache cache;
806 CXString cxFileName = clang_getFileName(cxFile);
807 const QByteArray fileName = clang_getCString(cxFileName);
808 clang_disposeString(cxFileName);
810 for (
const auto &entry : std::as_const(cache)) {
811 if (fileName == entry.fileName)
812 return fromCache(entry.content, offset1, offset2);
815 QFile file(QString::fromUtf8(fileName));
816 if (file.open(QIODeviceBase::ReadOnly)) {
818 cache.prepend(entry);
819 while (cache.size() > 5)
821 return fromCache(entry.content, offset1, offset2);
828 auto start = clang_getRangeStart(range);
829 auto end = clang_getRangeEnd(range);
831 unsigned int offset1, offset2;
832 clang_getFileLocation(start, &file1,
nullptr,
nullptr, &offset1);
833 clang_getFileLocation(end, &file2,
nullptr,
nullptr, &offset2);
835 if (file1 != file2 || offset2 <= offset1)
838 return readFile(file1, offset1, offset2);
842
843
844
845
848 if (clang_getCursorKind(cursor) == CXCursor_ConversionFunction) {
852 auto conversion_declaration =
853 static_cast<
const clang::CXXConversionDecl*>(get_cursor_declaration(cursor));
855 return QLatin1String(
"operator ") + QString::fromStdString(get_fully_qualified_type_name(
856 conversion_declaration->getConversionType(),
857 conversion_declaration->getASTContext()
861 QString name = fromCXString(clang_getCursorSpelling(cursor));
864 auto ltLoc = name.indexOf(
'<');
865 if (ltLoc > 0 && !name.startsWith(
"operator<"))
866 name = name.left(ltLoc);
871
872
873
877 auto kind = clang_getCursorKind(cur);
878 while (!clang_isInvalid(kind) && kind != CXCursor_TranslationUnit) {
880 case CXCursor_Namespace:
881 case CXCursor_StructDecl:
882 case CXCursor_ClassDecl:
883 case CXCursor_UnionDecl:
884 case CXCursor_ClassTemplate:
886 path.prepend(fromCXString(clang_getCursorSpelling(cur)));
888 case CXCursor_FunctionDecl:
889 case CXCursor_FunctionTemplate:
890 case CXCursor_CXXMethod:
891 case CXCursor_Constructor:
892 case CXCursor_Destructor:
893 case CXCursor_ConversionFunction:
894 path = functionName(cur);
899 cur = clang_getCursorSemanticParent(cur);
900 kind = clang_getCursorKind(cur);
906
907
908
909
910
911
914 param_type = param_type.getNonReferenceType();
915 while (param_type->isPointerType())
916 param_type = param_type->getPointeeType();
917 param_type = param_type.getUnqualifiedType();
919 if (param_type->isBuiltinType())
922 if (
const auto *record_type = param_type->getAs<clang::RecordType>()) {
923 if (
const auto *record_decl = record_type->getDecl())
924 return QString::fromStdString(record_decl->getQualifiedNameAsString());
929 QString class_name = QString::fromStdString(param_type.getAsString());
930 class_name.remove(
"const "_L1).remove(
"volatile "_L1);
931 class_name.remove(
"class "_L1).remove(
"struct "_L1);
932 class_name = class_name.trimmed();
934 if (class_name.isEmpty() || class_name.contains(
'('_L1) || class_name.contains(
'['_L1))
939 if (
auto angle = class_name.indexOf(
'<'_L1); angle > 0)
940 class_name.truncate(angle);
946
947
948
949
950
951
952
953
954
955
956
960 QSet<ClassNode *> searched_classes;
961 for (
const auto *param : func_decl->parameters()) {
962 auto class_name = classNameFromParameterType(param->getType());
966 auto *class_node = qdb->findClassNode(class_name->split(
"::"_L1));
967 if (!class_node || searched_classes.contains(class_node))
970 searched_classes.insert(class_node);
971 NodeVector class_candidates;
972 class_node->findChildren(funcName, class_candidates);
974 for (Node *candidate : class_candidates) {
975 if (!candidate->isFunction(Genus::CPP))
977 if (
static_cast<FunctionNode *>(candidate)->isHiddenFriend())
978 candidates.append(candidate);
984
985
996
997
1019
1020
1021
1022
1023
1024
1025
1026
1029 const clang::QualType type = parameter->getOriginalType();
1030 return type->isArrayType() ? type : type.getUnqualifiedType();
1049 if (argumentSpellings.size() <= index)
1050 argumentSpellings.resize(index + 1);
1051 if (argumentSpellings.at(index).isEmpty()) {
1052 argumentSpellings[index] = QString::fromStdString(get_fully_qualified_type_name(
1053 declaration->getParamDecl(index)->getOriginalType(), declaration->getASTContext()));
1055 return argumentSpellings.at(index);
1060 if (canonicalSpellings.size() <= index)
1061 canonicalSpellings.resize(index + 1);
1062 if (canonicalSpellings.at(index).isEmpty()) {
1063 canonicalSpellings[index] = QString::fromStdString(get_fully_qualified_type_name(
1064 parameterLookupType(declaration->getParamDecl(index)).getCanonicalType(),
1065 declaration->getASTContext()));
1067 return canonicalSpellings.at(index);
1072
1073
1074
1075
1076
1077
1078
1079
1080
1084 const auto cur = signature
.cursor;
1085 const auto *function_declaration = signature
.declaration;
1088 const auto &relaxed_template_declaration = signature.templateDeclaration;
1091 && !fn->templateParameterKey().isEmpty() && !signature.templateParameterKey.isEmpty();
1092 if (compareTemplateTypes && fn->templateParameterKey() != signature.templateParameterKey)
1094 bool compareHiddenFriendTypes =
false;
1100 if (!enclosing || !enclosing->isClassNode())
1103 if (!classTemplateDecl || fn->templateParameterKey().isEmpty()
1104 || fn->templateParameterKey() != signature.templateParameterKey)
1107 compareHiddenFriendTypes =
true;
1108 }
else if (fn
->templateDecl() && !relaxed_template_declaration) {
1111 if (!compareTemplateTypes
1112 && !are_template_declarations_substitutable(*fn
->templateDecl(), *relaxed_template_declaration))
1118 if (parameters
.count() != numArg + isVariadic) {
1122 "QPrivateSignal"_L1))) {
1123 if (parameters
.count() != --numArg + isVariadic)
1130 if (fn
->isConst() !=
bool(clang_CXXMethod_isConst(cur)))
1133 if (isVariadic && parameters.last().type() !=
"..."_L1)
1136 if (fn
->isRef() != (clang_Type_getCXXRefQualifier(clang_getCursorType(cur)) == CXRefQualifier_LValue))
1139 if (fn
->isRefRef() != (clang_Type_getCXXRefQualifier(clang_getCursorType(cur)) == CXRefQualifier_RValue))
1142 bool typesDiffer =
false;
1143 for (
int i = 0; i < numArg; ++i) {
1144 auto *paramDecl = function_declaration->getParamDecl(i);
1145 auto paramType = paramDecl->getOriginalType();
1147 if (compareHiddenFriendTypes || compareTemplateTypes) {
1148#if LIBCLANG_VERSION_MAJOR >= 21
1149 if (compareHiddenFriendTypes && function_declaration->getTrailingRequiresClause().ConstraintExpr)
1151 if (compareHiddenFriendTypes && function_declaration->getTrailingRequiresClause())
1154 const auto &recordedKeys = fn->templateParameterTypeKeys();
1155 if (i < recordedKeys.size() && i < signature.templateTypeKeys.size()
1156 && !recordedKeys.at(i).isEmpty() && !signature.templateTypeKeys.at(i).isEmpty()) {
1157 if (recordedKeys.at(i) != signature.templateTypeKeys.at(i))
1163 if (compareHiddenFriendTypes)
1167 QString recordedType = parameters.at(i).type();
1168 QString typeSpelling = signature.typeSpelling(i);
1170 typesDiffer = recordedType != typeSpelling;
1180 const bool isBareTemplateTypeParm =
1181 paramType.getTypePtrOrNull()
1182 && llvm::isa<
clang::TemplateTypeParmType>(paramType.getTypePtr());
1183 if (!isBareTemplateTypeParm) {
1184 QStringView canonicalType = parameters
.at(i
).canonicalType();
1187 if (canonicalType.isEmpty())
1188 canonicalType = recordedType;
1189 typesDiffer = canonicalType != signature.canonicalTypeSpelling(i);
1198 return !typesDiffer;
1210 auto *parent =
static_cast<Aggregate *>(p);
1212 parent->findChildren(functionName(cur), candidates);
1215 if (candidates.isEmpty() && cur_decl && cur_decl->getFriendObjectKind() !=
clang::Decl::FOK_None) {
1216 if (
auto *lexical_parent = findNodeForCursor(qdb, clang_getCursorLexicalParent(cur));
1217 lexical_parent && lexical_parent->isAggregate() && lexical_parent != parent)
1218 static_cast<Aggregate *>(lexical_parent)->findChildren(functionName(cur), candidates);
1222 const bool hasHiddenFriend =
std::any_of(candidates.cbegin(), candidates.cend(), [](
const Node *n) {
1223 return n->isFunction(Genus::CPP) &&
static_cast<
const FunctionNode *>(n)->isHiddenFriend();
1225 const auto *function_declaration = cur_decl ? cur_decl->getAsFunction() :
nullptr;
1226 if (!hasHiddenFriend && function_declaration)
1227 findHiddenFriendCandidates(qdb, functionName(cur), function_declaration, candidates);
1228 if (candidates.isEmpty() || !function_declaration)
1231 const auto funcType = clang_getCursorType(cur);
1233 bool(clang_isFunctionTypeVariadic(funcType)), {}, {}, {}, {}, {} };
1234 if (clang_getCursorKind(cur) == CXCursor_FunctionTemplate) {
1235 const auto *functionTemplate = function_declaration->getDescribedFunctionTemplate();
1236 signature.templateDeclaration = get_template_declaration(functionTemplate);
1238 signature.templateParameterKey = templateParameterKey(*functionTemplate->getTemplateParameters());
1239 for (
const auto *param : function_declaration->parameters())
1240 signature.templateTypeKeys.append(hiddenFriendTypeKey(
1241 parameterLookupType(param), *functionTemplate->getTemplateParameters()));
1245 return resolveFnLookupCandidates(candidates, [&](
Node *candidate) {
1246 return candidate->isFunction(Genus::CPP)
1247 && functionSignatureMatches(
static_cast<FunctionNode *>(candidate), signature,
1248 FnSignatureMatchMode::Ordinary);
1249 }, [&](
Node *candidate) {
1250 return mode == NodeLookupMode::FnCommand && candidate->isFunction(Genus::CPP)
1251 && functionSignatureMatches(
static_cast<FunctionNode *>(candidate), signature,
1252 FnSignatureMatchMode::FnCommand);
1253 }, [&](
Node *candidate) {
1254 return mode == NodeLookupMode::FnCommand && signature.templateDeclaration
1255 && candidate->isFunction(Genus::CPP)
1256 && functionSignatureMatches(
static_cast<FunctionNode *>(candidate), signature,
1257 FnSignatureMatchMode::HiddenFriendInClassTemplate);
1262
1263
1264
1267 auto kind = clang_getCursorKind(cur);
1268 if (clang_isInvalid(kind))
1270 if (kind == CXCursor_TranslationUnit)
1274 case CXCursor_FunctionDecl:
1275 case CXCursor_FunctionTemplate:
1276 case CXCursor_CXXMethod:
1277 case CXCursor_Constructor:
1278 case CXCursor_Destructor:
1279 case CXCursor_ConversionFunction:
1280 return findFunctionForCursor(qdb, cur, NodeLookupMode::Declaration).node();
1290 case CXCursor_TemplateTypeParameter:
1291 case CXCursor_NonTypeTemplateParameter:
1292 case CXCursor_TemplateTemplateParameter:
1302 auto parent =
static_cast<Aggregate *>(p);
1305 if (clang_Cursor_isAnonymous(cur)) {
1308 QLatin1String(
"anonymous"));
1310 name = fromCXString(clang_getCursorSpelling(cur));
1313 case CXCursor_Namespace:
1315 case CXCursor_StructDecl:
1316 case CXCursor_ClassDecl:
1317 case CXCursor_UnionDecl:
1318 case CXCursor_ClassTemplate:
1320 case CXCursor_EnumDecl:
1321 return parent->findNonfunctionChild(name, &
Node::isEnumType);
1322 case CXCursor_FieldDecl:
1323 case CXCursor_VarDecl:
1325 case CXCursor_TypedefDecl:
1334 CXCursor *overridden;
1335 unsigned int numOverridden = 0;
1336 clang_getOverriddenCursors(cursor, &overridden, &numOverridden);
1337 for (uint i = 0; i < numOverridden; ++i) {
1338 QString path = reconstructQualifiedPathForCursor(overridden[i]);
1339 if (!path.isEmpty()) {
1341 fn->setOverridesThis(path);
1345 clang_disposeOverriddenCursors(overridden);
1354 internalFilePatterns_(internalFilePatterns)
1356 std::transform(allHeaders.cbegin(), allHeaders.cend(),
std::inserter(allHeaders_, allHeaders_.begin()),
1357 [](
const auto& header_file_path) ->
const QString& {
return header_file_path.filename; });
1364 auto ret = visitChildrenLambda(cursor, [&](CXCursor cur) {
1365 auto loc = clang_getCursorLocation(cur);
1366 if (clang_Location_isFromMainFile(loc))
1367 return visitSource(cur, loc);
1370 clang_getFileLocation(loc, &file,
nullptr,
nullptr,
nullptr);
1371 bool isInteresting =
false;
1372 auto it = isInterestingCache_.find(file);
1373 if (it != isInterestingCache_.end()) {
1374 isInteresting = *it;
1376 QFileInfo fi(fromCXString(clang_getFileName(file)));
1378 isInteresting = allHeaders_.find(fi.fileName()) != allHeaders_.end();
1379 isInterestingCache_[file] = isInteresting;
1381 if (isInteresting) {
1382 return visitHeader(cur, loc);
1385 return CXChildVisit_Continue;
1387 return ret ? CXChildVisit_Break : CXChildVisit_Continue;
1391
1392
1393
1397 visitChildrenLambda(cursor, [&](CXCursor cur) {
1398 auto loc = clang_getCursorLocation(cur);
1399 if (clang_Location_isFromMainFile(loc))
1400 return visitFnSignature(cur, loc, result);
1401 return CXChildVisit_Continue;
1411
1412
1413
1416 unsigned int line {}, column {};
1417 friend bool operator<(
const SimpleLoc &a,
const SimpleLoc &b)
1419 return a.line != b.line ? a.line < b.line : a.column < b.column;
1423
1424
1425
1426
1427 QMap<SimpleLoc, CXCursor> declMap_;
1431 std::set<QString> allHeaders_;
1432 QHash<CXFile,
bool> isInterestingCache_;
1436
1437
1438 bool ignoredSymbol(
const QString &symbolName)
1440 if (symbolName == QLatin1String(
"QPrivateSignal"))
1443 if (symbolName.startsWith(
"_qt_property_"))
1446 if (symbolName.startsWith(
"<deduction guide"))
1451 CXChildVisitResult visitSource(CXCursor cursor, CXSourceLocation loc);
1452 CXChildVisitResult visitHeader(CXCursor cursor, CXSourceLocation loc);
1453 CXChildVisitResult visitFnSignature(CXCursor cursor, CXSourceLocation loc,
1455 void processFunction(
FunctionNode *fn, CXCursor cursor);
1456 bool parseProperty(
const QString &spelling,
const Location &loc);
1457 void readParameterNamesAndAttributes(
FunctionNode *fn, CXCursor cursor);
1458 Aggregate *getSemanticParent(CXCursor cursor);
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1492 visitChildrenLambda(cursor, [&attr](CXCursor child) -> CXChildVisitResult {
1494 if (clang_getCursorKind(child) == CXCursor_CallExpr) {
1495 CXSourceRange range = clang_getCursorExtent(child);
1496 QString sourceText = getSpelling(range);
1497 static const QRegularExpression qmlClassInfoPattern(
1498 R"(Q_CLASSINFO\s*\(\s*["\']QML\.(Singleton|Creatable)["\']\s*,\s*["\'](true|false)["\']\s*\))");
1499 const auto match = qmlClassInfoPattern.match(sourceText);
1500 if (match.hasMatch()) {
1501 if (match.captured(1) ==
"Singleton"_L1 && match.captured(2) ==
"true"_L1) {
1503 return CXChildVisit_Break;
1504 }
else if (match.captured(1) ==
"Creatable"_L1 && match.captured(2) ==
"false"_L1) {
1506 return CXChildVisit_Break;
1512 if (clang_getCursorKind(child) == CXCursor_EnumDecl) {
1513 QString spelling = fromCXString(clang_getCursorSpelling(child));
1514 if (spelling ==
"QmlIsSingleton"_L1) {
1516 return CXChildVisit_Break;
1517 }
else if (spelling ==
"QmlIsUncreatable"_L1) {
1519 return CXChildVisit_Break;
1523 return CXChildVisit_Continue;
1530
1531
1532
1533CXChildVisitResult
ClangVisitor::visitSource(CXCursor cursor, CXSourceLocation loc)
1535 auto kind = clang_getCursorKind(cursor);
1536 if (clang_isDeclaration(kind)) {
1538 clang_getPresumedLocation(loc,
nullptr, &l.line, &l.column);
1539 declMap_.insert(l, cursor);
1540 return CXChildVisit_Recurse;
1542 return CXChildVisit_Continue;
1546
1547
1548
1549
1552 CXCursor sp = clang_getCursorSemanticParent(cursor);
1553 CXCursor lp = clang_getCursorLexicalParent(cursor);
1554 if (!clang_equalCursors(sp, lp) && clang_isDeclaration(clang_getCursorKind(sp))) {
1557 return static_cast<Aggregate *>(spn);
1563CXChildVisitResult
ClangVisitor::visitFnSignature(CXCursor cursor, CXSourceLocation,
1566 switch (clang_getCursorKind(cursor)) {
1567 case CXCursor_Namespace:
1568 return CXChildVisit_Recurse;
1569 case CXCursor_FunctionDecl:
1570 case CXCursor_FunctionTemplate:
1571 case CXCursor_CXXMethod:
1572 case CXCursor_Constructor:
1573 case CXCursor_Destructor:
1574 case CXCursor_ConversionFunction: {
1576 if (ignoredSymbol(functionName(cursor))) {
1577 result.setIgnored();
1579 result = findFunctionForCursor(qdb_, cursor, NodeLookupMode::FnCommand);
1580 if (result.hasMatch()) {
1581 if (result.node()->isFunction(Genus::CPP)) {
1583 readParameterNamesAndAttributes(fn, cursor);
1587 if (
const auto function_declaration = declaration->getAsFunction()) {
1588 auto declaredReturnType = function_declaration->getDeclaredReturnType();
1589 if (llvm::dyn_cast_if_present<
clang::AutoType>(declaredReturnType.getTypePtrOrNull()))
1590 fn->setDeclaredReturnType(QString::fromStdString(declaredReturnType.getAsString()));
1593 }
else if (!result.isAmbiguous()) {
1594 QString name = functionName(cursor);
1595 if (ignoredSymbol(name))
1596 return CXChildVisit_Continue;
1597 Aggregate *semanticParent = getSemanticParent(cursor);
1598 if (semanticParent && semanticParent
->isClass()) {
1600 processFunction(candidate, cursor);
1601 if (!candidate->isSpecialMemberFunction()
1602 || (candidate->isCtor() && !candidate->parameters().isEmpty())) {
1604 return CXChildVisit_Continue;
1606 candidate->setImplicitlyGenerated(
true);
1608 result.setMatched(candidate);
1617 return CXChildVisit_Continue;
1620CXChildVisitResult
ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation loc)
1622 auto kind = clang_getCursorKind(cursor);
1625 case CXCursor_TypeAliasTemplateDecl:
1626 case CXCursor_TypeAliasDecl: {
1627 const QString aliasName = fromCXString(clang_getCursorSpelling(cursor));
1628 QString aliasedType;
1630 const auto *templateDecl = (kind == CXCursor_TypeAliasTemplateDecl)
1634 if (kind == CXCursor_TypeAliasTemplateDecl) {
1636 if (
const auto *aliasTemplate = llvm::dyn_cast<clang::TypeAliasTemplateDecl>(templateDecl)) {
1637 if (
const auto *aliasDecl = aliasTemplate->getTemplatedDecl()) {
1638 clang::QualType underlyingType = aliasDecl->getUnderlyingType();
1639 aliasedType = QString::fromStdString(underlyingType.getAsString());
1644 const CXType aliasedCXType = clang_getTypedefDeclUnderlyingType(cursor);
1645 if (aliasedCXType.kind != CXType_Invalid) {
1646 aliasedType = fromCXString(clang_getTypeSpelling(aliasedCXType));
1650 if (!aliasedType.isEmpty()) {
1651 auto *ta =
new TypeAliasNode(parent_, aliasName, aliasedType);
1656 ta->setTemplateDecl(get_template_declaration(templateDecl));
1658 return CXChildVisit_Continue;
1660 case CXCursor_StructDecl:
1661 case CXCursor_UnionDecl:
1662 if (fromCXString(clang_getCursorSpelling(cursor)).isEmpty())
1663 return CXChildVisit_Continue;
1665 case CXCursor_ClassTemplate:
1667 case CXCursor_ClassDecl: {
1668 if (!clang_isCursorDefinition(cursor))
1669 return CXChildVisit_Continue;
1672 return CXChildVisit_Continue;
1674 QString className = cleanAnonymousTypeName(fromCXString(clang_getCursorSpelling(cursor)));
1676 Aggregate *semanticParent = getSemanticParent(cursor);
1677 if (semanticParent && semanticParent->findNonfunctionChild(className, &
Node::isClassNode)) {
1678 return CXChildVisit_Continue;
1681 CXCursorKind actualKind = (kind == CXCursor_ClassTemplate) ?
1682 clang_getTemplateCursorKind(cursor) : kind;
1685 if (actualKind == CXCursor_StructDecl)
1687 else if (actualKind == CXCursor_UnionDecl)
1690 auto *classe =
new ClassNode(type, semanticParent, className);
1694 classe->setLocation(location);
1696 if (!internalFilePatterns_.exactMatches.isEmpty() || !internalFilePatterns_.globPatterns.isEmpty()
1697 || !internalFilePatterns_.regexPatterns.isEmpty()) {
1698 if (
Config::matchesInternalFilePattern(location.filePath(), internalFilePatterns_))
1702 classe->setAnonymous(clang_Cursor_isAnonymous(cursor));
1703 classe->setQmlNativeTypeAttribute(detectQmlNativeTypeAttribute(cursor));
1705 if (kind == CXCursor_ClassTemplate) {
1707 classe->setTemplateDecl(get_template_declaration(template_declaration));
1710 QScopedValueRollback<Aggregate *> setParent(parent_, classe);
1713 case CXCursor_CXXBaseSpecifier: {
1715 return CXChildVisit_Continue;
1717 auto type = clang_getCursorType(cursor);
1718 auto baseCursor = clang_getTypeDeclaration(type);
1720 auto classe =
static_cast<ClassNode *>(parent_);
1722 QString bcName = reconstructQualifiedPathForCursor(baseCursor);
1723 classe->addUnresolvedBaseClass(access,
1724 bcName.split(QLatin1String(
"::"), Qt::SkipEmptyParts));
1725 return CXChildVisit_Continue;
1727 auto baseClasse =
static_cast<ClassNode *>(baseNode);
1728 classe->addResolvedBaseClass(access, baseClasse);
1729 return CXChildVisit_Continue;
1731 case CXCursor_Namespace: {
1732 QString namespaceName = fromCXString(clang_getCursorDisplayName(cursor));
1742 QScopedValueRollback<Aggregate *> setParent(parent_, ns);
1745 case CXCursor_LinkageSpec:
1747 case CXCursor_FunctionTemplate:
1749 case CXCursor_FunctionDecl:
1750 case CXCursor_CXXMethod:
1751 case CXCursor_Constructor:
1752 case CXCursor_Destructor:
1753 case CXCursor_ConversionFunction: {
1760 declaration && declaration->isTemplateInstantiation())
1761 return CXChildVisit_Continue;
1764 return CXChildVisit_Continue;
1765 QString name = functionName(cursor);
1766 if (ignoredSymbol(name))
1767 return CXChildVisit_Continue;
1770 return CXChildVisit_Continue;
1773 CXSourceRange range = clang_Cursor_getCommentRange(cursor);
1774 if (!clang_Range_isNull(range)) {
1775 QString comment = getSpelling(range);
1776 if (comment.startsWith(
"//!")) {
1777 qsizetype tag = comment.indexOf(QChar(
'['));
1779 qsizetype end = comment.indexOf(QChar(
']'), ++tag);
1781 fn->setTag(comment.mid(tag, end - tag));
1786 processFunction(fn, cursor);
1788 if (kind == CXCursor_FunctionTemplate) {
1790 fn->setTemplateDecl(get_template_declaration(template_declaration));
1793 if (!clang_Location_isInSystemHeader(loc))
1794 fn->autoGenerateSmfDoc(parent_->name());
1796 return CXChildVisit_Continue;
1798#if CINDEX_VERSION
>= 36
1799 case CXCursor_FriendDecl: {
1803 case CXCursor_EnumDecl: {
1804 auto *en =
static_cast<EnumNode *>(findNodeForCursor(qdb_, cursor));
1805 if (en && en->items().size())
1806 return CXChildVisit_Continue;
1808 QString enumTypeName = fromCXString(clang_getCursorSpelling(cursor));
1810 if (clang_Cursor_isAnonymous(cursor)) {
1811 enumTypeName =
"anonymous";
1817 Node *n = parent_->findNonfunctionChild(enumTypeName, &
Node::isEnumType);
1819 en =
static_cast<EnumNode *>(n);
1823 en =
new EnumNode(parent_, enumTypeName, clang_EnumDecl_isScoped(cursor));
1826 en->setAnonymous(clang_Cursor_isAnonymous(cursor));
1830 visitChildrenLambda(cursor, [&](CXCursor cur) {
1831 if (clang_getCursorKind(cur) != CXCursor_EnumConstantDecl)
1832 return CXChildVisit_Continue;
1835 visitChildrenLambda(cur, [&](CXCursor cur) {
1836 if (clang_isExpression(clang_getCursorKind(cur))) {
1837 value = getSpelling(clang_getCursorExtent(cur));
1838 return CXChildVisit_Break;
1840 return CXChildVisit_Continue;
1842 if (value.isEmpty()) {
1843 QLatin1String hex(
"0x");
1844 if (!en->items().isEmpty() && en->items().last().value().startsWith(hex)) {
1845 value = hex + QString::number(clang_getEnumConstantDeclValue(cur), 16);
1847 value = QString::number(clang_getEnumConstantDeclValue(cur));
1851 en->addItem(EnumItem(fromCXString(clang_getCursorSpelling(cur)), std::move(value)));
1852 return CXChildVisit_Continue;
1854 return CXChildVisit_Continue;
1856 case CXCursor_FieldDecl:
1857 case CXCursor_VarDecl: {
1859 return CXChildVisit_Continue;
1861 auto value_declaration =
1863 assert(value_declaration);
1866 auto var =
new VariableNode(parent_, fromCXString(clang_getCursorSpelling(cursor)));
1868 var->setAccess(access);
1870 var->setLeftType(QString::fromStdString(get_fully_qualified_type_name(
1871 value_declaration->getType(),
1872 value_declaration->getASTContext()
1874 var->setStatic(kind == CXCursor_VarDecl && parent_
->isClassNode());
1876 return CXChildVisit_Continue;
1878 case CXCursor_TypedefDecl: {
1880 return CXChildVisit_Continue;
1881 auto *td =
new TypedefNode(parent_, fromCXString(clang_getCursorSpelling(cursor)));
1885 visitChildrenLambda(cursor, [&](CXCursor cur) {
1886 if (clang_getCursorKind(cur) != CXCursor_TemplateRef
1887 || fromCXString(clang_getCursorSpelling(cur)) != QLatin1String(
"QFlags"))
1888 return CXChildVisit_Continue;
1890 visitChildrenLambda(cursor, [&](CXCursor cur) {
1891 if (clang_getCursorKind(cur) != CXCursor_TypeRef)
1892 return CXChildVisit_Continue;
1895 if (en && en->isEnumType())
1896 static_cast<EnumNode *>(en)->setFlagsType(td);
1897 return CXChildVisit_Break;
1899 return CXChildVisit_Break;
1901 return CXChildVisit_Continue;
1907 parseProperty(getSpelling(clang_getCursorExtent(cursor)),
1910 return CXChildVisit_Continue;
1919 visitChildrenLambda(cursor, [&](CXCursor cur) {
1920 auto kind = clang_getCursorKind(cur);
1921 if (kind == CXCursor_AnnotateAttr) {
1922 QString annotation = fromCXString(clang_getCursorDisplayName(cur));
1923 if (annotation == QLatin1String(
"qt_slot")) {
1925 }
else if (annotation == QLatin1String(
"qt_signal")) {
1928 if (annotation == QLatin1String(
"qt_invokable"))
1930 }
else if (kind == CXCursor_CXXOverrideAttr) {
1932 }
else if (kind == CXCursor_ParmDecl) {
1934 return CXChildVisit_Break;
1936 if (QString name = fromCXString(clang_getCursorSpelling(cur)); !name.isEmpty())
1937 parameters
[i
].setName(name);
1940 Q_ASSERT(parameter_declaration);
1944 if (!default_value.empty())
1945 parameters
[i
].setDefaultValue(QString::fromStdString(default_value));
1949 return CXChildVisit_Continue;
1954
1955
1956
1957
1959 clang::SourceLocation location)
1961 while (sourceManager.isMacroArgExpansion(location))
1962 location = sourceManager.getImmediateExpansionRange(location).getBegin();
1967
1968
1969
1970
1971
1972
1973
1975 clang::SourceLocation end,
clang::SourceLocation readMacro)
1977 const clang::SourceManager &sourceManager = context.getSourceManager();
1978 const auto [fileId, offset] = sourceManager.getDecomposedLoc(location);
1979 if (end.isValid() && sourceManager.getFileID(end) != fileId)
1982 const llvm::StringRef buffer = sourceManager.getBufferData(fileId);
1983 clang::Lexer lexer(sourceManager.getLocForStartOfFile(fileId), context.getLangOpts(),
1984 buffer.begin(), buffer.begin() + offset, buffer.end());
1986 for (
bool first =
true; !lexer.LexFromRawLexer(token); first =
false) {
1987 if (end.isValid() ? !(token.getLocation() < end) : (!first && token.isAtStartOfLine()))
1989 if (!token.is(
clang::tok::raw_identifier) || token.getLocation() == readMacro)
1991 const llvm::StringRef spelling = token.getRawIdentifier();
1992 if (spelling ==
"constexpr" || spelling ==
"consteval"
1993 || context.Idents.get(spelling).hasMacroDefinition()) {
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2015 if (!declaration->isConstexpr())
2017 if (!declaration->isExplicitlyDefaulted())
2020 const clang::ASTContext &context = declaration->getASTContext();
2021 const clang::SourceManager &sourceManager = context.getSourceManager();
2022 clang::SourceLocation begin = declaration->getBeginLoc();
2023 const clang::SourceLocation name = declaration->getLocation();
2024 if (name.isMacroID()) {
2027 if (sourceManager.getFileID(begin) != sourceManager.getFileID(nameInBody))
2030 sourceManager.getSpellingLoc(nameInBody)
, {}
);
2035 clang::SourceLocation readMacro;
2036 while (begin.isMacroID()) {
2037 if (sourceManager.isMacroArgExpansion(begin))
2043 begin = sourceManager.getImmediateExpansionRange(begin).getBegin();
2044 readMacro = sourceManager.getImmediateSpellingLoc(begin);
2051 CXCursorKind kind = clang_getCursorKind(cursor);
2052 CXType funcType = clang_getCursorType(cursor);
2059 : clang_CXXMethod_isPureVirtual(cursor)
2076 const clang::FunctionDecl* function_declaration = declaration->getAsFunction();
2078 if (kind == CXCursor_Constructor
2080 || (kind == CXCursor_FunctionTemplate && fn->name() == parent_->name()))
2082 else if (kind == CXCursor_Destructor)
2084 else if (kind != CXCursor_ConversionFunction)
2085 fn->setReturnType(QString::fromStdString(get_fully_qualified_type_name(
2086 function_declaration->getReturnType(),
2087 function_declaration->getASTContext()
2090 const clang::CXXConstructorDecl* constructor_declaration = llvm::dyn_cast<
const clang::CXXConstructorDecl>(function_declaration);
2095 const clang::CXXConversionDecl* conversion_declaration = llvm::dyn_cast<
const clang::CXXConversionDecl>(function_declaration);
2101 (constructor_declaration && constructor_declaration->isExplicit()) ||
2102 (conversion_declaration && conversion_declaration->isExplicit())
2105 const clang::CXXMethodDecl* method_declaration = llvm::dyn_cast<
const clang::CXXMethodDecl>(function_declaration);
2110 const clang::FunctionType* function_type = function_declaration->getFunctionType();
2111 const clang::FunctionProtoType* function_prototype =
static_cast<
const clang::FunctionProtoType*>(function_type);
2113 if (function_prototype) {
2114 clang::FunctionProtoType::ExceptionSpecInfo exception_specification = function_prototype->getExceptionSpecInfo();
2116 if (exception_specification.Type !=
clang::ExceptionSpecificationType::EST_None) {
2117 const std::string exception_specification_spelling =
2118 exception_specification.NoexceptExpr ? get_expression_as_string(
2119 exception_specification.NoexceptExpr,
2120 function_declaration->getASTContext()
2123 if (exception_specification_spelling !=
"false")
2124 fn->markNoexcept(QString::fromStdString(exception_specification_spelling));
2133 QStringList referenced_concepts;
2134#if LIBCLANG_VERSION_MAJOR >= 21
2135 if (
const auto trailing_requires = function_declaration->getTrailingRequiresClause();
2136 trailing_requires.ConstraintExpr) {
2137 QString requires_str = QString::fromStdString(
2138 get_expression_as_string(trailing_requires.ConstraintExpr,
2139 function_declaration->getASTContext()));
2140 fn->setTrailingRequiresClause(requires_str.simplified());
2141 std::vector<std::string> refs;
2142 collect_concept_references(trailing_requires.ConstraintExpr, refs);
2143 for (
const auto &ref : refs)
2144 referenced_concepts << QString::fromStdString(ref);
2147 if (
const clang::Expr *trailing_requires = function_declaration->getTrailingRequiresClause()) {
2148 QString requires_str = QString::fromStdString(
2149 get_expression_as_string(trailing_requires,
2150 function_declaration->getASTContext()));
2151 fn->setTrailingRequiresClause(requires_str.simplified());
2152 std::vector<std::string> refs;
2153 collect_concept_references(trailing_requires, refs);
2154 for (
const auto &ref : refs)
2155 referenced_concepts << QString::fromStdString(ref);
2159 CXRefQualifierKind refQualKind = clang_Type_getCXXRefQualifier(funcType);
2160 if (refQualKind == CXRefQualifier_LValue)
2162 else if (refQualKind == CXRefQualifier_RValue)
2171 parameters
.reserve(function_declaration->getNumParams()
);
2173 for (clang::ParmVarDecl*
const parameter_declaration : function_declaration->parameters()) {
2174 clang::QualType parameter_type = parameter_declaration->getOriginalType();
2176 parameters.append(QString::fromStdString(get_fully_qualified_type_name(
2178 parameter_declaration->getASTContext()
2181 if (
const clang::QualType lookup_type =
2182 parameterLookupType(parameter_declaration).getCanonicalType();
2183 lookup_type != parameter_type)
2184 parameters.last().setCanonicalType(QString::fromStdString(get_fully_qualified_type_name(
2186 parameter_declaration->getASTContext()
2190 if (
const clang::AutoType *auto_type = parameter_type->getContainedAutoType()) {
2191 if (auto_type->isConstrained()) {
2192 if (
const clang::NamedDecl *concept_decl =
2193 auto_type->getTypeConstraintConcept()) {
2194 referenced_concepts << QString::fromStdString(
2195 concept_decl->getQualifiedNameAsString());
2201 if (!referenced_concepts.isEmpty()) {
2202 referenced_concepts.sort();
2203 referenced_concepts.removeDuplicates();
2204 fn->setReferencedConcepts(
std::move(referenced_concepts));
2208 if (parameters
.last().type().endsWith(QLatin1String(
"QPrivateSignal"))) {
2214 if (clang_isFunctionTypeVariadic(funcType))
2215 parameters.append(QStringLiteral(
"..."));
2216 readParameterNamesAndAttributes(fn, cursor);
2218 if (declaration && declaration->getFriendObjectKind() !=
clang::Decl::FOK_None) {
2220 Q_ASSERT(function_declaration);
2222 const bool hasNamespaceScopeRedeclaration =
2223 std::any_of(function_declaration->redecls_begin(),
2224 function_declaration->redecls_end(),
2225 [](
const clang::FunctionDecl *r) {
2226 return r->getFriendObjectKind() == clang::Decl::FOK_None;
2228 if (!hasNamespaceScopeRedeclaration)
2234 const clang::TemplateParameterList *binders =
nullptr;
2235 if (
const auto *functionTemplate = function_declaration->getDescribedFunctionTemplate()) {
2236 binders = functionTemplate->getTemplateParameters();
2238 const auto *record = llvm::dyn_cast<
clang::CXXRecordDecl>(function_declaration->getLexicalDeclContext());
2239 if (
const auto *classTemplate = record ? record->getDescribedClassTemplate() :
nullptr)
2240 binders = classTemplate->getTemplateParameters();
2243 fn->setTemplateParameterKey(templateParameterKey(*binders));
2244 QList<QByteArray> typeKeys;
2245 for (
int i = 0; i < parameters
.count() && i <
int(function_declaration->getNumParams()); ++i)
2248 fn->setTemplateParameterTypeKeys(
std::move(typeKeys));
2254 if (!spelling.startsWith(QLatin1String(
"Q_PROPERTY"))
2255 && !spelling.startsWith(QLatin1String(
"QDOC_PROPERTY"))
2256 && !spelling.startsWith(QLatin1String(
"Q_OVERRIDE")))
2259 qsizetype lpIdx = spelling.indexOf(QChar(
'('));
2260 qsizetype rpIdx = spelling.lastIndexOf(QChar(
')'));
2261 if (lpIdx <= 0 || rpIdx <= lpIdx)
2264 QString signature = spelling.mid(lpIdx + 1, rpIdx - lpIdx - 1);
2265 signature = signature.simplified();
2266 QStringList parts = signature.split(QChar(
' '), Qt::SkipEmptyParts);
2268 static const QStringList attrs =
2269 QStringList() <<
"READ" <<
"MEMBER" <<
"WRITE"
2270 <<
"NOTIFY" <<
"CONSTANT" <<
"FINAL"
2271 <<
"REQUIRED" <<
"BINDABLE" <<
"DESIGNABLE"
2272 <<
"RESET" <<
"REVISION" <<
"SCRIPTABLE"
2273 <<
"STORED" <<
"USER";
2277 auto it =
std::find_if(parts.cbegin(), parts.cend(),
2278 [](
const QString &attr) ->
bool {
2279 return attrs.contains(attr);
2282 if (it == parts.cend() ||
std::distance(parts.cbegin(), it) < 2)
2285 QStringList typeParts;
2286 std::copy(parts.cbegin(), it,
std::back_inserter(typeParts));
2287 parts.erase(parts.cbegin(), it);
2288 QString name = typeParts.takeLast();
2291 while (!name.isEmpty() && name.front() == QChar(
'*')) {
2292 typeParts.last().push_back(name.front());
2297 if (parts.size() < 2 || name.isEmpty())
2301 property->setAccess(Access::Public);
2302 property->setLocation(loc);
2303 property->setDataType(typeParts.join(QChar(
' ')));
2306 while (i < parts.size()) {
2307 const QString &key = parts.at(i++);
2309 if (key ==
"CONSTANT") {
2310 property->setConstant();
2311 }
else if (key ==
"REQUIRED") {
2312 property->setRequired();
2314 if (i < parts.size()) {
2315 QString value = parts.at(i++);
2316 if (key ==
"READ") {
2318 }
else if (key ==
"WRITE") {
2320 property->setWritable(
true);
2321 }
else if (key ==
"MEMBER") {
2322 property->setWritable(
true);
2323 }
else if (key ==
"STORED") {
2324 property->setStored(value.toLower() ==
"true");
2325 }
else if (key ==
"BINDABLE") {
2328 }
else if (key ==
"RESET") {
2330 }
else if (key ==
"NOTIFY") {
2339
2340
2341
2342
2343
2347 clang_getPresumedLocation(loc,
nullptr, &docloc.line, &docloc.column);
2348 auto decl_it = declMap_.upperBound(docloc);
2349 if (decl_it == declMap_.end())
2352 unsigned int declLine = decl_it.key().line;
2353 unsigned int nextCommentLine;
2354 clang_getPresumedLocation(nextCommentLoc,
nullptr, &nextCommentLine,
nullptr);
2355 if (nextCommentLine < declLine)
2359 if (decl_it != declMap_.begin()) {
2360 CXSourceLocation prevDeclEnd = clang_getRangeEnd(clang_getCursorExtent(*(
std::prev(decl_it))));
2361 unsigned int prevDeclLine;
2362 clang_getPresumedLocation(prevDeclEnd,
nullptr, &prevDeclLine,
nullptr);
2363 if (prevDeclLine >= docloc.line) {
2366 auto parent = clang_getCursorLexicalParent(*decl_it);
2367 if (!clang_equalCursors(parent, *(
std::prev(decl_it))))
2371 auto *node = findNodeForCursor(qdb_, *decl_it);
2373 if (node && node->isFunction(Genus::CPP))
2374 readParameterNamesAndAttributes(
static_cast<
FunctionNode *>(node), *decl_it);
2381 const std::vector<QByteArray>& include_paths,
2382 const QList<QByteArray>& defines,
2389 m_allHeaders = config.getHeaderFiles();
2390 m_internalFilePatterns = config.getInternalFilePatternsCompiled();
2398 "-fms-compatibility-version=19",
2402 "-DQT_DISABLE_DEPRECATED_UP_TO=0",
2403 "-DQT_ANNOTATE_CLASS(type,...)=static_assert(sizeof(#__VA_ARGS__),#type);",
2404 "-DQT_ANNOTATE_CLASS2(type,a1,a2)=static_assert(sizeof(#a1,#a2),#type);",
2405 "-DQT_ANNOTATE_FUNCTION(a)=__attribute__((annotate(#a)))",
2406 "-DQT_ANNOTATE_ACCESS_SPECIFIER(a)=__attribute__((annotate(#a)))",
2407 "-Wno-constant-logical-operand",
2408 "-Wno-macro-redefined",
2409 "-Wno-nullability-completeness",
2410 "-fvisibility=default",
2417 std::vector<
const char *> pointers;
2418 pointers.reserve(args.size());
2419 for (
const auto &arg : args)
2420 pointers.push_back(arg.constData());
2425
2426
2427
2432 args.emplace_back(arg);
2435 for (
const auto &p : std::as_const(defines))
2440
2441
2443 const std::vector<QByteArray>& include_paths,
2444 std::vector<QByteArray>& args
2446 if (include_paths.empty()) {
2447 qCWarning(lcQdoc) <<
"No include paths provided."
2448 <<
"Set 'includepaths' in the qdocconf file"
2449 <<
"or pass -I flags on the command line."
2450 <<
"C++ parsing may produce incomplete results.";
2452 args.insert(args.end(), include_paths.begin(), include_paths.end());
2457
2458
2459
2460
2463 QString module_header,
2464 const std::set<Config::HeaderFilePath>& all_headers,
2465 const std::vector<QByteArray>& include_paths,
2466 const QList<QByteArray>& defines,
2467 const InclusionPolicy& policy
2469 static std::vector<QByteArray> arguments{};
2471 if (module_header.isEmpty())
return std::nullopt;
2473 getDefaultArgs(defines, arguments);
2474 getMoreArgs(include_paths, arguments);
2476 flags_ =
static_cast<CXTranslationUnit_Flags>(CXTranslationUnit_Incomplete
2477 | CXTranslationUnit_SkipFunctionBodies
2478 | CXTranslationUnit_KeepGoing);
2482 QTemporaryDir pch_directory{QDir::tempPath() + QLatin1String(
"/qdoc_pch")};
2483 if (!pch_directory.isValid())
return std::nullopt;
2485 const QByteArray module = module_header.toUtf8();
2488 qCDebug(lcQdoc) <<
"Build and visit PCH for" << module_header;
2491 struct FindPredicate
2493 enum SearchType { Any, Module };
2494 QByteArray &candidate_;
2495 const QByteArray &module_;
2497 FindPredicate(QByteArray &candidate,
const QByteArray &module,
2498 SearchType type = Any)
2499 : candidate_(candidate), module_(module), type_(type)
2503 bool operator()(
const QByteArray &p)
const
2505 if (type_ != Any && !p.endsWith(module_))
2507 candidate_ = p +
"/";
2508 candidate_.append(module_);
2509 if (p.startsWith(
"-I"))
2510 candidate_ = candidate_.mid(2);
2511 return QFile::exists(QString::fromUtf8(candidate_));
2517 auto it =
std::find_if(include_paths.begin(), include_paths.end(),
2518 FindPredicate(candidate, module, FindPredicate::Module));
2519 if (it == include_paths.end())
2520 it =
std::find_if(include_paths.begin(), include_paths.end(),
2521 FindPredicate(candidate, module, FindPredicate::Any));
2522 if (it != include_paths.end())
2523 header = std::move(candidate);
2525 if (header.isEmpty()) {
2526 qWarning() <<
"(qdoc) Could not find the module header in include paths for module"
2527 << module <<
" (include paths: " << include_paths <<
")";
2528 qWarning() <<
" Artificial module header built from header dirs in qdocconf "
2531 arguments.push_back(
"-xc++");
2535 QString tmpHeader = pch_directory.path() +
"/" + module;
2536 if (QFile tmpHeaderFile(tmpHeader); tmpHeaderFile.open(QIODevice::Text | QIODevice::WriteOnly)) {
2537 QTextStream out(&tmpHeaderFile);
2538 if (header.isEmpty()) {
2539 for (
const auto& [header_path, header_name] : all_headers) {
2540 bool shouldInclude = !header_name.startsWith(
"moc_"_L1);
2543 if (header_name.endsWith(
"_p.h"_L1))
2544 shouldInclude = shouldInclude && policy.showInternal;
2546 if (shouldInclude) {
2547 out <<
"#include \"" << header_path <<
"/" << header_name <<
"\"\n";
2551 QFileInfo headerFile(header);
2552 if (!headerFile.exists()) {
2553 qWarning() <<
"Could not find module header file" << header;
2554 return std::nullopt;
2557 out <<
"#include \"" << header <<
"\"\n";
2559 if (policy.showInternal) {
2560 for (
const auto& [header_path, header_name] : all_headers) {
2561 bool shouldInclude = !header_name.startsWith(
"moc_"_L1);
2562 if (header_name.endsWith(
"_p.h"_L1) && shouldInclude)
2563 out <<
"#include \"" << header_path <<
"/" << header_name <<
"\"\n";
2569 const auto argPointers = toConstCharPointers(arguments);
2570 const QByteArray tmpHeaderLocal = tmpHeader.toLatin1();
2572 clang_parseTranslationUnit2(index, tmpHeaderLocal.constData(), argPointers.data(),
2573 static_cast<
int>(argPointers.size()),
nullptr, 0,
2574 flags_ | CXTranslationUnit_ForSerialization, &tu
.tu);
2575 qCDebug(lcQdoc) <<
__FUNCTION__ <<
"clang_parseTranslationUnit2(" << tmpHeader << arguments
2576 <<
") returns" << err;
2581 qCCritical(lcQdoc) <<
"Could not create PCH file for " << module_header;
2582 return std::nullopt;
2585 QByteArray pch_name = pch_directory.path().toUtf8() +
"/" + module +
".pch";
2586 auto error = clang_saveTranslationUnit(tu, pch_name.constData(),
2587 clang_defaultSaveOptions(tu));
2589 qCCritical(lcQdoc) <<
"Could not save PCH file for" << module_header;
2590 return std::nullopt;
2595 CXCursor cur = clang_getTranslationUnitCursor(tu);
2596 auto &config = Config::instance();
2597 ClangVisitor visitor(qdb, all_headers, config.getInternalFilePatternsCompiled());
2599 qCDebug(lcQdoc) <<
"PCH built and visited for" << module_header;
2601 return std::make_optional(
PCHFile{
std::move(pch_directory),
std::move(pch_name)});
2606 if (t.count(QChar(
'.')) > 1)
2607 t.truncate(t.lastIndexOf(QChar(
'.')));
2612
2613
2614
2615
2616
2617
2618
2619
2622 flags_ =
static_cast<CXTranslationUnit_Flags>(CXTranslationUnit_Incomplete
2623 | CXTranslationUnit_SkipFunctionBodies
2624 | CXTranslationUnit_KeepGoing);
2628 getDefaultArgs(m_defines, m_args);
2629 if (m_pch && !filePath.endsWith(
".mm")
2630 && !std::holds_alternative<CppHeaderSourceFile>(tag_source_file(filePath).second)) {
2631 m_args.push_back(
"-w");
2632 m_args.push_back(
"-include-pch");
2633 m_args.push_back((*m_pch).get().name);
2635 getMoreArgs(m_includePaths, m_args);
2638 const auto argPointers = toConstCharPointers(m_args);
2639 const QByteArray filePathLocal = filePath.toLocal8Bit();
2641 clang_parseTranslationUnit2(index, filePathLocal.constData(), argPointers.data(),
2642 static_cast<
int>(argPointers.size()),
nullptr, 0,
flags_, &tu
.tu);
2643 qCDebug(lcQdoc) <<
__FUNCTION__ <<
"clang_parseTranslationUnit2(" << filePath << m_args
2644 <<
") returns" << err;
2648 qWarning() <<
"(qdoc) Could not parse source file" << filePath <<
" error code:" << err;
2652 ParsedCppFileIR parse_result{};
2654 CXCursor tuCur = clang_getTranslationUnitCursor(tu);
2655 ClangVisitor visitor(m_qdb, m_allHeaders, m_internalFilePatterns);
2659 unsigned int numTokens = 0;
2660 const QSet<QString> &commands = CppCodeParser::topic_commands + CppCodeParser::meta_commands;
2661 clang_tokenize(tu, clang_getCursorExtent(tuCur), &tokens, &numTokens);
2663 for (
unsigned int i = 0; i < numTokens; ++i) {
2664 if (clang_getTokenKind(tokens[i]) != CXToken_Comment)
2666 QString comment = fromCXString(clang_getTokenSpelling(tu, tokens[i]));
2667 if (!comment.startsWith(
"/*!"))
2670 auto commentLoc = clang_getTokenLocation(tu, tokens[i]);
2673 Doc::trimCStyleComment(loc, comment);
2676 Doc doc(loc, end_loc, comment, commands, CppCodeParser::topic_commands);
2682 if (i + 1 < numTokens) {
2684 CXSourceLocation nextCommentLoc = commentLoc;
2685 while (i + 2 < numTokens && clang_getTokenKind(tokens[i + 1]) != CXToken_Comment)
2687 nextCommentLoc = clang_getTokenLocation(tu, tokens[i + 1]);
2694 bool future =
false;
2696 QString sinceVersion = doc.metaCommandArgs(
COMMAND_SINCE).at(0).first;
2697 if (getUnpatchedVersion(
std::move(sinceVersion)) >
2698 getUnpatchedVersion(Config::instance().get(
CONFIG_VERSION).asString()))
2703 QStringLiteral(
"Cannot tie this documentation to anything"),
2704 QStringLiteral(
"qdoc found a /*! ... */ comment, but there was no "
2705 "topic command (e.g., '\\%1', '\\%2') in the "
2706 "comment and qdoc could not associate the "
2707 "declaration or definition following the "
2708 "comment with a documented entity.")
2715 CXCursor cur = clang_getCursor(tu, commentLoc);
2717 CXCursorKind kind = clang_getCursorKind(cur);
2718 if (clang_isTranslationUnit(kind) || clang_isInvalid(kind))
2720 if (kind == CXCursor_Namespace) {
2721 parse_result.untied.back().context << fromCXString(clang_getCursorSpelling(cur));
2723 cur = clang_getCursorLexicalParent(cur);
2728 clang_disposeTokens(tu, tokens, numTokens);
2729 m_namespaceScope.clear();
2732 return parse_result;
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2748 const QString &idTag, QStringList context)
2750 Node *fnNode =
nullptr;
2752
2753
2754
2755
2756
2757 if (!idTag.isEmpty()) {
2758 fnNode = m_qdb->findFunctionNodeForTag(idTag);
2761 QStringLiteral(
"tag \\fn [%1] not used in any include file in current module").arg(idTag));
2764
2765
2766
2767
2768 auto *fn =
static_cast<FunctionNode *>(fnNode);
2769 QStringList leftParenSplit = fnSignature.mid(fnSignature.indexOf(fn->name())).split(
'(');
2770 if (leftParenSplit.size() > 1) {
2771 QStringList rightParenSplit = leftParenSplit[1].split(
')');
2772 if (!rightParenSplit.empty()) {
2773 QString params = rightParenSplit[0];
2774 if (!params.isEmpty()) {
2775 QStringList commaSplit = params.split(
',');
2777 if (parameters
.count() == commaSplit.size()) {
2778 for (
int i = 0; i < parameters
.count(); ++i) {
2779 QStringList blankSplit = commaSplit[i].split(
' ', Qt::SkipEmptyParts);
2780 if (blankSplit.size() > 1) {
2781 QString pName = blankSplit.last();
2783 auto it =
std::find_if(
std::begin(pName),
std::end(pName),
2784 [](
const QChar &c) {
return c.isLetter(); });
2785 parameters
[i
].setName(
2786 pName.remove(0,
std::distance(
std::begin(pName), it)));
2796 auto flags =
static_cast<CXTranslationUnit_Flags>(CXTranslationUnit_Incomplete
2797 | CXTranslationUnit_SkipFunctionBodies
2798 | CXTranslationUnit_KeepGoing);
2802 getDefaultArgs(m_defines, m_args);
2805 m_args.push_back(
"-w");
2806 m_args.push_back(
"-include-pch");
2807 m_args.push_back((*m_pch).get().name);
2812 for (
const auto &ns : std::as_const(context))
2813 s_fn.prepend(
"namespace " + ns.toUtf8() +
" {");
2814 s_fn += fnSignature.toUtf8();
2815 if (!s_fn.endsWith(
";"))
2817 s_fn.append(context.size(),
'}');
2820 CXUnsavedFile unsavedFile { dummyFileName, s_fn.constData(),
2821 static_cast<
unsigned long>(s_fn.size()) };
2822 const auto argPointers = toConstCharPointers(m_args);
2823 CXErrorCode err = clang_parseTranslationUnit2(index, dummyFileName, argPointers.data(),
2824 int(argPointers.size()), &unsavedFile, 1, flags, &tu
.tu);
2825 qCDebug(lcQdoc) <<
__FUNCTION__ <<
"clang_parseTranslationUnit2(" << dummyFileName << m_args
2826 <<
") returns" << err;
2829 location.error(QStringLiteral(
"clang could not parse \\fn %1").arg(fnSignature));
2833
2834
2835
2836
2837
2838 CXCursor cur = clang_getTranslationUnitCursor(tu);
2839 auto &config = Config::instance();
2840 ClangVisitor visitor(m_qdb, m_allHeaders, config.getInternalFilePatternsCompiled());
2842 const auto phase = config.preparing() && !config.singleExec()
2844 if (shouldDiagnoseFnLookup(fnLookup, phase))
2845 return FnMatchError{ fnSignature, location };
2846 fnNode = fnLookup.node();
static const clang::Decl * get_cursor_declaration(CXCursor cursor)
Returns the underlying Decl that cursor represents.
static QString reconstructQualifiedPathForCursor(CXCursor cur)
Reconstruct the qualified path name of a function that is being overridden.
static void findHiddenFriendCandidates(QDocDatabase *qdb, const QString &funcName, const clang::FunctionDecl *func_decl, NodeVector &candidates)
static std::optional< QString > classNameFromParameterType(clang::QualType param_type)
QString functionName(CXCursor cursor)
Returns the function name from a given cursor representing a function declaration.
static std::string get_default_value_initializer_as_string(const clang::TemplateTemplateParmDecl *parameter)
static QString fromCXString(CXString &&string)
convert a CXString to a QString, and dispose the CXString
static QDebug operator<<(QDebug debug, const std::vector< T > &v)
static QString getSpelling(CXSourceRange range)
static void setOverridesForFunction(FunctionNode *fn, CXCursor cursor)
static bool mayDeclareConstexpr(const clang::ASTContext &context, clang::SourceLocation location, clang::SourceLocation end, clang::SourceLocation readMacro)
static const auto kClangDontDisplayDiagnostics
static const clang::TemplateSpecializationType * find_template_specialization_through_sugar(const clang::Type *type)
static std::string get_default_value_initializer_as_string(const clang::ParmVarDecl *parameter)
static FnLookupResult findFunctionForCursor(QDocDatabase *qdb, CXCursor cur, NodeLookupMode mode)
static void collect_concept_references(const clang::Stmt *node, std::vector< std::string > &out)
static std::optional< SfinaeConstraint > detect_sfinae_constraint(const clang::NonTypeTemplateParmDecl *param)
static std::string get_expression_as_string(const clang::Expr *expression, const clang::ASTContext &declaration_context)
static clang::QualType parameterLookupType(const clang::ParmVarDecl *parameter)
bool visitChildrenLambda(CXCursor cursor, T &&lambda)
Call clang_visitChildren on the given cursor with the lambda as a callback T can be any functor that ...
static std::string get_default_value_initializer_as_string(const clang::NamedDecl *declaration)
static RelaxedTemplateDeclaration get_template_declaration(const clang::TemplateDecl *template_declaration)
static std::vector< const char * > toConstCharPointers(const std::vector< QByteArray > &args)
static std::string get_default_value_initializer_as_string(const clang::NonTypeTemplateParmDecl *parameter)
static QString fromCache(const QByteArray &cache, unsigned int offset1, unsigned int offset2)
static clang::SourceLocation macroBodyLocation(const clang::SourceManager &sourceManager, clang::SourceLocation location)
static bool is_enable_if_name(const std::string &qualified_name)
static bool isConstexprAsDeclared(const clang::FunctionDecl *declaration)
static float getUnpatchedVersion(QString t)
void getMoreArgs(const std::vector< QByteArray > &include_paths, std::vector< QByteArray > &args)
Load the include paths into args.
static Location fromCXSourceLocation(CXSourceLocation location)
convert a CXSourceLocation to a qdoc Location
static QString cleanAnonymousTypeName(const QString &typeName)
static Access fromCX_CXXAccessSpecifier(CX_CXXAccessSpecifier spec)
convert a CX_CXXAccessSpecifier to Node::Access
static std::string get_default_value_initializer_as_string(const clang::TemplateTypeParmDecl *parameter)
static bool functionSignatureMatches(FunctionNode *fn, FunctionCursorSignature &signature, FnSignatureMatchMode matchMode)
void getDefaultArgs(const QList< QByteArray > &defines, std::vector< QByteArray > &args)
Load the default arguments and the defines into args.
constexpr const char fnDummyFileName[]
static CXTranslationUnit_Flags flags_
static Node * findNodeForCursor(QDocDatabase *qdb, CXCursor cur)
static std::string get_fully_qualified_type_name(clang::QualType type, const clang::ASTContext &declaration_context)
@ HiddenFriendInClassTemplate
static void printDiagnostics(const CXTranslationUnit &translationUnit)
static const char * defaultArgs_[]
std::optional< PCHFile > buildPCH(QDocDatabase *qdb, QString module_header, const std::set< Config::HeaderFilePath > &all_headers, const std::vector< QByteArray > &include_paths, const QList< QByteArray > &defines, const InclusionPolicy &policy)
Building the PCH must be possible when there are no .cpp files, so it is moved here to its own member...
static QString readFile(CXFile cxFile, unsigned int offset1, unsigned int offset2)
static std::string ensureAnonymousTagKeyword(std::string typeName, clang::QualType type)
Returns a string representing the name of type as if it was referred to at the end of the translation...
void addChild(Node *child)
Adds the child to this node's child list and sets the child's parent pointer to this Aggregate.
ParsedCppFileIR parse_cpp_file(const QString &filePath)
Get ready to parse the C++ cpp file identified by filePath and add its parsed contents to the databas...
ClangCodeParser(QDocDatabase *qdb, Config &, const std::vector< QByteArray > &include_paths, const QList< QByteArray > &defines, std::optional< std::reference_wrapper< const PCHFile > > pch)
Node * nodeForCommentAtLocation(CXSourceLocation loc, CXSourceLocation nextCommentLoc)
Given a comment at location loc, return a Node for this comment nextCommentLoc is the location of the...
CXChildVisitResult visitChildren(CXCursor cursor)
ClangVisitor(QDocDatabase *qdb, const std::set< Config::HeaderFilePath > &allHeaders, const Config::InternalFilePatterns &internalFilePatterns)
FnLookupResult visitFnArg(CXCursor cursor)
The ClassNode represents a C++ class.
static bool isWorthWarningAbout(const Doc &doc)
Test for whether a doc comment warrants warnings.
The Config class contains the configuration variables for controlling how qdoc produces documentation...
const Location & location() const
Returns the starting location of a qdoc comment.
TopicList topicsUsed() const
Returns a reference to the list of topic commands used in the current qdoc comment.
This node is used to represent any kind of function being documented.
void markDeletedAsWritten()
void setVirtualness(Virtualness virtualness)
bool isNonvirtual() const
void setInvokable(bool b)
bool isHiddenFriend() const
void markExplicitlyDefaulted()
void setMetaness(Metaness metaness)
const std::optional< QString > & trailingRequiresClause() const
Parameters & parameters()
void setHiddenFriend(bool b)
The Location class provides a way to mark a location in a file.
This class represents a C++ namespace.
This class describes one instance of using the Q_PROPERTY macro.
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
NamespaceNode * primaryTreeRoot()
Returns a pointer to the root node of the primary tree.
Status
Specifies the status of the QQmlIncubator.
#define CONFIG_DOCUMENTATIONINHEADERS
bool hasTooManyTopics(const Doc &doc)
Checks if there are too many topic commands in doc.
FnLookupResultFor< Node > FnLookupResult
QmlNativeTypeAttribute
Defines QML-specific attributes affecting QmlTypeNode instances.
Metaness
Specifies the kind of function a FunctionNode represents.
This namespace holds QDoc-internal utility methods.
std::string getFullyQualifiedName(QualType QT, const ASTContext &Ctx, const PrintingPolicy &Policy, bool WithGlobalNsPrefix=false)
QList< Node * > NodeVector
Returns the spelling in the file for a source range.
std::variant< Node *, FnMatchError > operator()(const Location &location, const QString &fnSignature, const QString &idTag, QStringList context)
Use clang to parse the function signature from a function command.
Encapsulates information about.
QVarLengthArray< QString, 20 > canonicalSpellings
QString typeSpelling(int index)
QVarLengthArray< QString, 20 > argumentSpellings
std::optional< RelaxedTemplateDeclaration > templateDeclaration
QString canonicalTypeSpelling(int index)
QByteArray templateParameterKey
QList< QByteArray > templateTypeKeys
const clang::FunctionDecl * declaration
The Node class is the base class for all the nodes in QDoc's parse tree.
void setAccess(Access t)
Sets the node's access type to t.
bool isNamespace() const
Returns true if the node type is Namespace.
bool isTypedef() const
Returns true if the node type is Typedef.
Aggregate * parent() const
Returns the node's parent pointer, that is, the aggregate under which the node is documented.
bool isVariable() const
Returns true if the node type is Variable.
void setLocation(const Location &t)
Sets the node's declaration location, its definition location, or both, depending on the suffix of th...
virtual bool isAggregate() const
Returns true if this node is an aggregate, which means it inherits Aggregate and can therefore have c...
virtual void setRelatedNonmember(bool b)
Sets a flag in the node indicating whether this node is a related nonmember of something.
const std::optional< RelaxedTemplateDeclaration > & templateDecl() const
bool isFunction(Genus g=Genus::DontCare) const
Returns true if this is a FunctionNode and its Genus is set to g.
bool isClass() const
Returns true if the node type is Class.
virtual bool isClassNode() const
Returns true if this is an instance of ClassNode.
A class for parsing and managing a function parameter list.
Parameter & operator[](int index)
bool isPrivateSignal() const
const Parameter & at(int i) const
const Parameter & last() const
Holds the source-level alias with its template arguments for a SFINAE constraint detected in a non-ty...
operator CXTranslationUnit()