Lines Matching +full:batch +full:- +full:reduce
1 //===--- Selection.cpp ----------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
53 for (const auto *N = Common; N; N = N->Parent) { in recordMetrics()
54 if (const auto *RE = N->ASTNode.get<RecoveryExpr>()) { in recordMetrics()
56 RecoveryType.record(RE->isTypeDependent() ? 0 : 1, LanguageLabel); in recordMetrics()
71 // [----] MemberExpr, base = A().<anonymous>, member = b in getSourceRange()
72 // [----] MemberExpr: base = A(), member = <anonymous> in getSourceRange()
73 // [-] CXXConstructExpr in getSourceRange()
75 // so we reduce its range to match the CXXConstructExpr. in getSourceRange()
78 if (!ME->getMemberDecl()->getDeclName()) in getSourceRange()
79 return ME->getBase() in getSourceRange()
80 ? getSourceRange(DynTypedNode::create(*ME->getBase())) in getSourceRange()
89 // [-----------------------------------------------------------]
92 // Claim: [--------------------]
93 // after: [----------------] [-------------------]
96 // Claim: [---------------------------------------]
97 // Out: [---------] [------]
98 // After: [-----] [-----------]
102 // The tokens actually removed are associated with that node, and hit-tested
117 // Claim: [-----------------] in erase()
118 // UnclaimedRanges: [-A-] [-B-] [-C-] [-D-] [-E-] [-F-] [-G-] in erase()
126 --Overlap.first; in erase()
128 if (Overlap.first->end() <= Claim.begin()) in erase()
137 // - restrict the returned range to the claimed part in erase()
138 // - save the unclaimed part so it can be reinserted in erase()
140 if (Claim.begin() > OutFirst->begin()) { in erase()
141 RemainingHead = {OutFirst->begin(), Claim.begin()}; in erase()
142 *OutFirst = {Claim.begin(), OutFirst->end()}; in erase()
174 // But Unselected + Complete -> Partial, while NoTokens + Complete --> Complete.
193 // They're not properly claimed as expr-statement is missing from the AST.
200 // We don't have locations for cvr-qualifiers: see QualifiedTypeLoc. in shouldIgnore()
211 // argument whose top-level spelling location is 'SpellingLoc'.
219 // So if we reach the target, target is the first-expansion of the in isFirstExpansion()
220 // first-expansion ... in isFirstExpansion()
234 // SelectionTester can determine whether a range of tokens from the PP-expanded
245 // Non-token text, and tokens not modeled in the AST (comments, semicolons)
273 PPIgnored[&Tok - SelFirst] = true; in SelectionTester()
314 // but it could occur for unmatched-bracket cases. in test()
327 auto Batch = ExpandedTokens.take_while([&](const syntax::Token &T) { in test() local
330 assert(!Batch.empty()); in test()
331 ExpandedTokens = ExpandedTokens.drop_front(Batch.size()); in test()
333 update(Result, testChunk(FID, Batch)); in test()
400 // inclusion (e.g. preamble patch, or command-line -include). in computeMaybeSelectedExpandedTokens()
425 // Hit-test a consecutive range of tokens from a single file ID.
427 testChunk(FileID FID, llvm::ArrayRef<syntax::Token> Batch) const { in testChunk()
428 assert(!Batch.empty()); in testChunk()
429 SourceLocation StartLoc = Batch.front().location(); in testChunk()
433 // We need to identify the main-file tokens that represent Batch, and in testChunk()
439 return testTokenRange(*offsetInSelFile(Batch.front().location()), in testChunk()
440 *offsetInSelFile(Batch.back().location())); in testChunk()
446 for (SourceLocation Loc = Batch.front().location(); Loc.isValid(); in testChunk()
461 SM.getTopMacroCallerLoc(Batch.back().location()); in testChunk()
463 } else { // NOLINT(llvm-else-after-return) in testChunk()
468 // Handle tokens produced by non-argument macro expansion. in testChunk()
471 // FIXME: also check ( and ) for function-like macros? in testChunk()
497 update(Result, It->Selected); in testTokenRange()
510 if (It != SelectedSpelled.end() && It->Offset == Offset) in testToken()
511 return It->Selected; in testToken()
523 return Loc.getRawEncoding() - SelFileBounds.getBegin().getRawEncoding(); in offsetInSelFile()
548 if (TL->getTypeLocClass() == TypeLoc::Qualified) in printNodeKind()
551 OS << TL->getType()->getTypeClassName() << "TypeLoc"; in printNodeKind()
571 S = ICE->getSubExprAsWritten(); in isImplicit()
575 if (CTI->isImplicit()) in isImplicit()
579 if (auto *FD = llvm::dyn_cast<FieldDecl>(ME->getMemberDecl())) in isImplicit()
580 if (FD->isAnonymousStructOrUnion()) in isImplicit()
584 return isImplicit(ME->getBase()); in isImplicit()
588 if (auto *FD = llvm::dyn_cast<FunctionDecl>(DRE->getDecl())) { in isImplicit()
589 switch (FD->getOverloadedOperator()) { in isImplicit()
624 // We traverse all "well-behaved" nodes the same way:
625 // - push the node onto the stack
626 // - traverse its children recursively
627 // - pop it from the stack
628 // - hit testing: is intersection(node, selection) - union(children) empty?
629 // - attach it to the tree if it or any children hit the selection
631 // Two categories of nodes are not "well-behaved":
632 // - those without source range information, we don't record those
633 // - those that can't be stored in DynTypedNode.
638 if (X && X->isImplicit()) { in TraverseDecl()
705 // inside the parens, this causes the range-init expression to not be hit.
709 return TraverseStmt(S->getInit()) && TraverseDecl(S->getLoopVariable()) && in TraverseCXXForRangeStmt()
710 TraverseStmt(S->getRangeInit()) && TraverseStmt(S->getBody()); in TraverseCXXForRangeStmt()
715 return traverseNode(E, [&] { return TraverseStmt(E->getSourceExpr()); }); in TraverseOpaqueValueExpr()
719 return traverseNode(E, [&] { return TraverseStmt(E->getSyntacticForm()); }); in TraversePseudoObjectExpr()
722 if (auto *E = C->getImmediatelyDeclaredConstraint()) { in TraverseTypeConstraint()
778 // fine-grained hit-testing is mostly done on the way back up (in pop()).
809 if (auto AT = TL->getAs<AttributedTypeLoc>()) in canSafelySkipNode()
815 [](const Attr *A) { return !A->isImplicit(); })) in canSafelySkipNode()
852 dlog("{1}pop: {0}", printNodeToString(N.ASTNode, PrintPolicy), indent(-1)); in pop()
858 N.Parent->Children.push_back(&N); in pop()
872 // We want the name in the var-decl to be claimed by the decl itself and in earlySourceRange()
879 // ~~~ |- AutoTypeLoc in earlySourceRange()
880 return VD->getLocation(); in earlySourceRange()
888 return CDD->getNameInfo().getNamedTypeInfo()->getTypeLoc().getBeginLoc(); in earlySourceRange()
890 auto NameInfo = ME->getMemberNameInfo(); in earlySourceRange()
893 return NameInfo.getNamedTypeInfo()->getTypeLoc().getBeginLoc(); in earlySourceRange()
907 claimRange(CCE->getParenOrBraceRange(), Result); in claimTokensFor()
917 // claim the tokens owned by this node and non-declarator children. in claimTokensFor()
920 // Non-declarator types nest normally, and are handled like other nodes. in claimTokensFor()
928 // --------[2]---------- `-Array in claimTokensFor()
929 // -------*------------- `-Pointer in claimTokensFor()
930 // ------(----)--------- `-Paren in claimTokensFor()
931 // ------------(#######) `-Function in claimTokensFor()
932 // R<###> |-TemplateSpecialization R in claimTokensFor()
933 // int | `-Builtin int in claimTokensFor()
934 // A<####> `-TemplateSpecialization A in claimTokensFor()
935 // char `-Builtin char in claimTokensFor()
938 // --- represents unclaimed parts of the SourceRange. in claimTokensFor()
941 if (auto PTL = TL->getAs<ParenTypeLoc>()) { in claimTokensFor()
946 if (auto ATL = TL->getAs<ArrayTypeLoc>()) { in claimTokensFor()
950 if (auto PTL = TL->getAs<PointerTypeLoc>()) { in claimTokensFor()
954 if (auto FTL = TL->getAs<FunctionTypeLoc>()) { in claimTokensFor()
962 // Perform hit-testing of a complete Node against the selection.
1016 OS.indent(Indent - 1) << (N.Selected == SelectionTree::Complete ? '*' in print()
1036 // Always returns at least one range - if no tokens touched, and empty range.
1099 while (Ancestor->Children.size() == 1 && !Ancestor->Selected) in commonAncestor()
1100 Ancestor = Ancestor->Children.front(); in commonAncestor()
1109 CurrentNode = CurrentNode->Parent) { in getDeclContext()
1110 if (const Decl *Current = CurrentNode->ASTNode.get<Decl>()) { in getDeclContext()
1114 return *Current->getLexicalDeclContext(); in getDeclContext()
1116 if (const auto *LE = CurrentNode->ASTNode.get<LambdaExpr>()) in getDeclContext()
1118 return *LE->getCallOperator(); in getDeclContext()
1125 getSourceRange(Children.front()->ASTNode) == getSourceRange(ASTNode)) in ignoreImplicit()
1126 return Children.front()->ignoreImplicit(); in ignoreImplicit()
1131 if (Parent && getSourceRange(Parent->ASTNode) == getSourceRange(ASTNode)) in outerImplicit()
1132 return Parent->outerImplicit(); in outerImplicit()