Coverage Report

Created: 2020-02-25 14:32

/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.47M
                                        SourceLocation EndLoc) {
24
1.47M
  unsigned NumSelArgs = Sel.getNumArgs();
25
1.47M
  if (NumSelArgs == 0) {
26
198k
    assert(Index == 0);
27
198k
    if (EndLoc.isInvalid())
28
0
      return SourceLocation();
29
198k
    IdentifierInfo *II = Sel.getIdentifierInfoForSlot(0);
30
198k
    unsigned Len = II ? II->getLength() : 
00
;
31
198k
    return EndLoc.getLocWithOffset(-Len);
32
198k
  }
33
1.27M
34
1.27M
  assert(Index < NumSelArgs);
35
1.27M
  if (ArgLoc.isInvalid())
36
11
    return SourceLocation();
37
1.27M
  IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Index);
38
1.27M
  unsigned Len = /* selector id */ (II ? 
II->getLength()1.27M
:
0280
) + /* ':' */ 1;
39
1.27M
  if (WithArgSpace)
40
147k
    ++Len;
41
1.27M
  return ArgLoc.getLocWithOffset(-Len);
42
1.27M
}
43
44
namespace {
45
46
template <typename T>
47
SourceLocation getArgLoc(T* Arg);
48
49
template <>
50
18.7k
SourceLocation getArgLoc<Expr>(Expr *Arg) {
51
18.7k
  return Arg->getBeginLoc();
52
18.7k
}
53
54
template <>
55
1.26M
SourceLocation getArgLoc<ParmVarDecl>(ParmVarDecl *Arg) {
56
1.26M
  SourceLocation Loc = Arg->getBeginLoc();
57
1.26M
  if (Loc.isInvalid())
58
0
    return Loc;
59
1.26M
  // -1 to point to left paren of the method parameter's type.
60
1.26M
  return Loc.getLocWithOffset(-1);
61
1.26M
}
62
63
template <typename T>
64
1.47M
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
1.47M
  return Index < Args.size() ? 
getArgLoc(Args[Index])1.27M
:
SourceLocation()198k
;
66
1.47M
}
SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::Expr>(unsigned int, llvm::ArrayRef<clang::Expr*>)
Line
Count
Source
64
31.0k
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
31.0k
  return Index < Args.size() ? 
getArgLoc(Args[Index])18.7k
:
SourceLocation()12.2k
;
66
31.0k
}
SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::ParmVarDecl>(unsigned int, llvm::ArrayRef<clang::ParmVarDecl*>)
Line
Count
Source
64
1.44M
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
1.44M
  return Index < Args.size() ? 
getArgLoc(Args[Index])1.26M
:
SourceLocation()185k
;
66
1.44M
}
67
68
template <typename T>
69
SelectorLocationsKind hasStandardSelLocs(Selector Sel,
70
                                         ArrayRef<SourceLocation> SelLocs,
71
                                         ArrayRef<T *> Args,
72
843k
                                         SourceLocation EndLoc) {
73
843k
  // Are selector locations in standard position with no space between args ?
74
843k
  unsigned i;
75
1.92M
  for (i = 0; i != SelLocs.size(); 
++i1.08M
) {
76
1.27M
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
1.27M
                                             Args, EndLoc))
78
194k
      break;
79
1.27M
  }
80
843k
  if (i == SelLocs.size())
81
649k
    return SelLoc_StandardNoSpace;
82
194k
83
194k
  // Are selector locations in standard position with space between args ?
84
196k
  
for (i = 0; 194k
i != SelLocs.size();
++i2.85k
) {
85
194k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
194k
                                             Args, EndLoc))
87
192k
      return SelLoc_NonStandard;
88
194k
  }
89
194k
90
194k
  
return SelLoc_StandardWithSpace2.06k
;
91
194k
}
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.7k
                                         SourceLocation EndLoc) {
73
22.7k
  // Are selector locations in standard position with no space between args ?
74
22.7k
  unsigned i;
75
46.3k
  for (i = 0; i != SelLocs.size(); 
++i23.5k
) {
76
26.4k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
26.4k
                                             Args, EndLoc))
78
2.94k
      break;
79
26.4k
  }
80
22.7k
  if (i == SelLocs.size())
81
19.8k
    return SelLoc_StandardNoSpace;
82
2.94k
83
2.94k
  // Are selector locations in standard position with space between args ?
84
4.85k
  
for (i = 0; 2.94k
i != SelLocs.size();
++i1.91k
) {
85
3.44k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
3.44k
                                             Args, EndLoc))
87
1.52k
      return SelLoc_NonStandard;
88
3.44k
  }
89
2.94k
90
2.94k
  
return SelLoc_StandardWithSpace1.41k
;
91
2.94k
}
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
821k
                                         SourceLocation EndLoc) {
73
821k
  // Are selector locations in standard position with no space between args ?
74
821k
  unsigned i;
75
1.88M
  for (i = 0; i != SelLocs.size(); 
++i1.06M
) {
76
1.25M
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
1.25M
                                             Args, EndLoc))
78
191k
      break;
79
1.25M
  }
80
821k
  if (i == SelLocs.size())
81
629k
    return SelLoc_StandardNoSpace;
82
191k
83
191k
  // Are selector locations in standard position with space between args ?
84
192k
  
for (i = 0; 191k
i != SelLocs.size();
++i936
) {
85
191k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
191k
                                             Args, EndLoc))
87
190k
      return SelLoc_NonStandard;
88
191k
  }
89
191k
90
191k
  
return SelLoc_StandardWithSpace650
;
91
191k
}
92
93
} // anonymous namespace
94
95
SelectorLocationsKind
96
clang::hasStandardSelectorLocs(Selector Sel,
97
                               ArrayRef<SourceLocation> SelLocs,
98
                               ArrayRef<Expr *> Args,
99
22.7k
                               SourceLocation EndLoc) {
100
22.7k
  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
101
22.7k
}
102
103
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
104
                                             Selector Sel,
105
                                             bool WithArgSpace,
106
                                             ArrayRef<Expr *> Args,
107
31.0k
                                             SourceLocation EndLoc) {
108
31.0k
  return getStandardSelLoc(Index, Sel, WithArgSpace,
109
31.0k
                           getArgLoc(Index, Args), EndLoc);
110
31.0k
}
111
112
SelectorLocationsKind
113
clang::hasStandardSelectorLocs(Selector Sel,
114
                               ArrayRef<SourceLocation> SelLocs,
115
                               ArrayRef<ParmVarDecl *> Args,
116
821k
                               SourceLocation EndLoc) {
117
821k
  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
118
821k
}
119
120
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
121
                                             Selector Sel,
122
                                             bool WithArgSpace,
123
                                             ArrayRef<ParmVarDecl *> Args,
124
1.44M
                                             SourceLocation EndLoc) {
125
1.44M
  return getStandardSelLoc(Index, Sel, WithArgSpace,
126
1.44M
                           getArgLoc(Index, Args), EndLoc);
127
1.44M
}