Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/SelectorLocationsKind.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- SelectorLocationsKind.cpp - Kind of selector locations -*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// Describes whether the identifier locations for a selector are "standard"
10
// or not.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/AST/SelectorLocationsKind.h"
15
#include "clang/AST/Expr.h"
16
17
using namespace clang;
18
19
static SourceLocation getStandardSelLoc(unsigned Index,
20
                                        Selector Sel,
21
                                        bool WithArgSpace,
22
                                        SourceLocation ArgLoc,
23
1.18M
                                        SourceLocation EndLoc) {
24
1.18M
  unsigned NumSelArgs = Sel.getNumArgs();
25
1.18M
  if (NumSelArgs == 0) {
26
175k
    assert(Index == 0);
27
175k
    if (EndLoc.isInvalid())
28
0
      return SourceLocation();
29
175k
    IdentifierInfo *II = Sel.getIdentifierInfoForSlot(0);
30
175k
    unsigned Len = II ? II->getLength() : 
00
;
31
175k
    return EndLoc.getLocWithOffset(-Len);
32
175k
  }
33
34
1.00M
  assert(Index < NumSelArgs);
35
1.00M
  if (ArgLoc.isInvalid())
36
0
    return SourceLocation();
37
1.00M
  IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Index);
38
1.00M
  unsigned Len = /* selector id */ (II ? 
II->getLength()1.00M
:
0445
) + /* ':' */ 1;
39
1.00M
  if (WithArgSpace)
40
116k
    ++Len;
41
1.00M
  return ArgLoc.getLocWithOffset(-Len);
42
1.00M
}
43
44
namespace {
45
46
template <typename T>
47
SourceLocation getArgLoc(T* Arg);
48
49
template <>
50
17.9k
SourceLocation getArgLoc<Expr>(Expr *Arg) {
51
17.9k
  return Arg->getBeginLoc();
52
17.9k
}
53
54
template <>
55
988k
SourceLocation getArgLoc<ParmVarDecl>(ParmVarDecl *Arg) {
56
988k
  SourceLocation Loc = Arg->getBeginLoc();
57
988k
  if (Loc.isInvalid())
58
0
    return Loc;
59
  // -1 to point to left paren of the method parameter's type.
60
988k
  return Loc.getLocWithOffset(-1);
61
988k
}
62
63
template <typename T>
64
1.18M
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
1.18M
  return Index < Args.size() ? 
getArgLoc(Args[Index])1.00M
:
SourceLocation()175k
;
66
1.18M
}
SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::Expr>(unsigned int, llvm::ArrayRef<clang::Expr*>)
Line
Count
Source
64
30.2k
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
30.2k
  return Index < Args.size() ? 
getArgLoc(Args[Index])17.9k
:
SourceLocation()12.2k
;
66
30.2k
}
SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::ParmVarDecl>(unsigned int, llvm::ArrayRef<clang::ParmVarDecl*>)
Line
Count
Source
64
1.15M
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
1.15M
  return Index < Args.size() ? 
getArgLoc(Args[Index])988k
:
SourceLocation()163k
;
66
1.15M
}
67
68
template <typename T>
69
SelectorLocationsKind hasStandardSelLocs(Selector Sel,
70
                                         ArrayRef<SourceLocation> SelLocs,
71
                                         ArrayRef<T *> Args,
72
674k
                                         SourceLocation EndLoc) {
73
  // Are selector locations in standard position with no space between args ?
74
674k
  unsigned i;
75
1.52M
  for (i = 0; i != SelLocs.size(); 
++i852k
) {
76
1.01M
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
1.01M
                                             Args, EndLoc))
78
161k
      break;
79
1.01M
  }
80
674k
  if (i == SelLocs.size())
81
513k
    return SelLoc_StandardNoSpace;
82
83
  // Are selector locations in standard position with space between args ?
84
163k
  
for (i = 0; 161k
i != SelLocs.size();
++i2.02k
) {
85
162k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
162k
                                             Args, EndLoc))
87
160k
      return SelLoc_NonStandard;
88
162k
  }
89
90
1.62k
  return SelLoc_StandardWithSpace;
91
161k
}
SelectorLocationsKind.cpp:clang::SelectorLocationsKind (anonymous namespace)::hasStandardSelLocs<clang::Expr>(clang::Selector, llvm::ArrayRef<clang::SourceLocation>, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation)
Line
Count
Source
72
22.5k
                                         SourceLocation EndLoc) {
73
  // Are selector locations in standard position with no space between args ?
74
22.5k
  unsigned i;
75
46.3k
  for (i = 0; i != SelLocs.size(); 
++i23.7k
) {
76
26.3k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
26.3k
                                             Args, EndLoc))
78
2.56k
      break;
79
26.3k
  }
80
22.5k
  if (i == SelLocs.size())
81
20.0k
    return SelLoc_StandardNoSpace;
82
83
  // Are selector locations in standard position with space between args ?
84
3.82k
  
for (i = 0; 2.56k
i != SelLocs.size();
++i1.26k
) {
85
2.80k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
2.80k
                                             Args, EndLoc))
87
1.53k
      return SelLoc_NonStandard;
88
2.80k
  }
89
90
1.02k
  return SelLoc_StandardWithSpace;
91
2.56k
}
SelectorLocationsKind.cpp:clang::SelectorLocationsKind (anonymous namespace)::hasStandardSelLocs<clang::ParmVarDecl>(clang::Selector, llvm::ArrayRef<clang::SourceLocation>, llvm::ArrayRef<clang::ParmVarDecl*>, clang::SourceLocation)
Line
Count
Source
72
652k
                                         SourceLocation EndLoc) {
73
  // Are selector locations in standard position with no space between args ?
74
652k
  unsigned i;
75
1.48M
  for (i = 0; i != SelLocs.size(); 
++i829k
) {
76
988k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
988k
                                             Args, EndLoc))
78
159k
      break;
79
988k
  }
80
652k
  if (i == SelLocs.size())
81
493k
    return SelLoc_StandardNoSpace;
82
83
  // Are selector locations in standard position with space between args ?
84
159k
  
for (i = 0; 159k
i != SelLocs.size();
++i759
) {
85
159k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
159k
                                             Args, EndLoc))
87
158k
      return SelLoc_NonStandard;
88
159k
  }
89
90
599
  return SelLoc_StandardWithSpace;
91
159k
}
92
93
} // anonymous namespace
94
95
SelectorLocationsKind
96
clang::hasStandardSelectorLocs(Selector Sel,
97
                               ArrayRef<SourceLocation> SelLocs,
98
                               ArrayRef<Expr *> Args,
99
22.5k
                               SourceLocation EndLoc) {
100
22.5k
  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
101
22.5k
}
102
103
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
104
                                             Selector Sel,
105
                                             bool WithArgSpace,
106
                                             ArrayRef<Expr *> Args,
107
30.2k
                                             SourceLocation EndLoc) {
108
30.2k
  return getStandardSelLoc(Index, Sel, WithArgSpace,
109
30.2k
                           getArgLoc(Index, Args), EndLoc);
110
30.2k
}
111
112
SelectorLocationsKind
113
clang::hasStandardSelectorLocs(Selector Sel,
114
                               ArrayRef<SourceLocation> SelLocs,
115
                               ArrayRef<ParmVarDecl *> Args,
116
652k
                               SourceLocation EndLoc) {
117
652k
  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
118
652k
}
119
120
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
121
                                             Selector Sel,
122
                                             bool WithArgSpace,
123
                                             ArrayRef<ParmVarDecl *> Args,
124
1.15M
                                             SourceLocation EndLoc) {
125
1.15M
  return getStandardSelLoc(Index, Sel, WithArgSpace,
126
1.15M
                           getArgLoc(Index, Args), EndLoc);
127
1.15M
}