@@ -96,13 +96,6 @@ static SourceLocation findPreviousTokenKind(SourceLocation Start,
96
96
}
97
97
}
98
98
99
- static SourceLocation findOpenParen (const CallExpr &E, const SourceManager &SM,
100
- const LangOptions &LangOpts) {
101
- SourceLocation EndLoc =
102
- E.getNumArgs () == 0 ? E.getRParenLoc () : E.getArg (0 )->getBeginLoc ();
103
- return findPreviousTokenKind (EndLoc, SM, LangOpts, tok::TokenKind::l_paren);
104
- }
105
-
106
99
RangeSelector transformer::before (RangeSelector Selector) {
107
100
return [Selector](const MatchResult &Result) -> Expected<CharSourceRange> {
108
101
Expected<CharSourceRange> SelectedRange = Selector (Result);
@@ -287,18 +280,50 @@ RangeSelector transformer::statements(std::string ID) {
287
280
}
288
281
289
282
namespace {
290
- // Returns the range of the source between the call's parentheses.
291
- CharSourceRange getCallArgumentsRange (const MatchResult &Result,
292
- const CallExpr &CE) {
283
+
284
+ SourceLocation getRLoc (const CallExpr &E) { return E.getRParenLoc (); }
285
+
286
+ SourceLocation getRLoc (const CXXConstructExpr &E) {
287
+ return E.getParenOrBraceRange ().getEnd ();
288
+ }
289
+
290
+ tok::TokenKind getStartToken (const CallExpr &E) {
291
+ return tok::TokenKind::l_paren;
292
+ }
293
+
294
+ tok::TokenKind getStartToken (const CXXConstructExpr &E) {
295
+ return isa<CXXTemporaryObjectExpr>(E) ? tok::TokenKind::l_paren
296
+ : tok::TokenKind::l_brace;
297
+ }
298
+
299
+ template <typename ExprWithArgs>
300
+ SourceLocation findArgStartDelimiter (const ExprWithArgs &E, SourceLocation RLoc,
301
+ const SourceManager &SM,
302
+ const LangOptions &LangOpts) {
303
+ SourceLocation Loc = E.getNumArgs () == 0 ? RLoc : E.getArg (0 )->getBeginLoc ();
304
+ return findPreviousTokenKind (Loc, SM, LangOpts, getStartToken (E));
305
+ }
306
+ // Returns the range of the source between the call's or construct expr's
307
+ // parentheses/braces.
308
+ template <typename ExprWithArgs>
309
+ CharSourceRange getArgumentsRange (const MatchResult &Result,
310
+ const ExprWithArgs &CE) {
311
+ const SourceLocation RLoc = getRLoc (CE);
293
312
return CharSourceRange::getCharRange (
294
- findOpenParen (CE, *Result.SourceManager , Result.Context ->getLangOpts ())
313
+ findArgStartDelimiter (CE, RLoc, *Result.SourceManager ,
314
+ Result.Context ->getLangOpts ())
295
315
.getLocWithOffset (1 ),
296
- CE. getRParenLoc () );
316
+ RLoc );
297
317
}
298
318
} // namespace
299
319
300
320
RangeSelector transformer::callArgs (std::string ID) {
301
- return RelativeSelector<CallExpr, getCallArgumentsRange>(std::move (ID));
321
+ return RelativeSelector<CallExpr, getArgumentsRange<CallExpr>>(std::move (ID));
322
+ }
323
+
324
+ RangeSelector transformer::constructExprArgs (std::string ID) {
325
+ return RelativeSelector<CXXConstructExpr,
326
+ getArgumentsRange<CXXConstructExpr>>(std::move (ID));
302
327
}
303
328
304
329
namespace {
0 commit comments