@@ -2939,30 +2939,36 @@ static NumberLiteralExpr *getTrailingNumberLiteral(ResolvedCursorInfo Tok) {
2939
2939
// This cursor must point to the start of an expression.
2940
2940
if (Tok.Kind != CursorInfoKind::ExprStart)
2941
2941
return nullptr ;
2942
- Expr *Parent = Tok.TrailingExpr ;
2943
- assert (Parent);
2944
-
2945
- // Check if an expression is a number literal.
2946
- auto IsLiteralNumber = [&](Expr *E) -> NumberLiteralExpr* {
2947
- if (auto *NL = dyn_cast<NumberLiteralExpr>(E)) {
2948
-
2949
- // The sub-expression must have the same start loc with the outermost
2950
- // expression, i.e. the cursor position.
2951
- if (Parent->getStartLoc ().getOpaquePointerValue () ==
2952
- E->getStartLoc ().getOpaquePointerValue ()) {
2953
- return NL;
2954
- }
2955
- }
2956
- return nullptr ;
2957
- };
2942
+
2958
2943
// For every sub-expression, try to find the literal expression that matches
2959
2944
// our criteria.
2960
- for (auto Pair: Parent->getDepthMap ()) {
2961
- if (auto Result = IsLiteralNumber (Pair.getFirst ())) {
2962
- return Result;
2945
+ class FindLiteralNumber : public ASTWalker {
2946
+ Expr * const parent;
2947
+
2948
+ public:
2949
+ NumberLiteralExpr *found = nullptr ;
2950
+
2951
+ explicit FindLiteralNumber (Expr *parent) : parent(parent) { }
2952
+
2953
+ std::pair<bool , Expr *> walkToExprPre (Expr *expr) override {
2954
+ if (auto *literal = dyn_cast<NumberLiteralExpr>(expr)) {
2955
+ // The sub-expression must have the same start loc with the outermost
2956
+ // expression, i.e. the cursor position.
2957
+ if (!found &&
2958
+ parent->getStartLoc ().getOpaquePointerValue () ==
2959
+ expr->getStartLoc ().getOpaquePointerValue ()) {
2960
+ found = literal;
2961
+ }
2962
+ }
2963
+
2964
+ return { found == nullptr , expr };
2963
2965
}
2964
- }
2965
- return nullptr ;
2966
+ };
2967
+
2968
+ auto parent = Tok.TrailingExpr ;
2969
+ FindLiteralNumber finder (parent);
2970
+ parent->walk (finder);
2971
+ return finder.found ;
2966
2972
}
2967
2973
2968
2974
static std::string insertUnderscore (StringRef Text) {
0 commit comments