Coverage Report

Created: 2020-09-19 12:23

/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.54M
                                        SourceLocation EndLoc) {
24
1.54M
  unsigned NumSelArgs = Sel.getNumArgs();
25
1.54M
  if (NumSelArgs == 0) {
26
218k
    assert(Index == 0);
27
218k
    if (EndLoc.isInvalid())
28
0
      return SourceLocation();
29
218k
    IdentifierInfo *II = Sel.getIdentifierInfoForSlot(0);
30
218k
    unsigned Len = II ? II->getLength() : 
00
;
31
218k
    return EndLoc.getLocWithOffset(-Len);
32
218k
  }
33
1.33M
34
1.33M
  assert(Index < NumSelArgs);
35
1.33M
  if (ArgLoc.isInvalid())
36
0
    return SourceLocation();
37
1.33M
  IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Index);
38
1.32M
  unsigned Len = /* selector id */ (II ? II->getLength() : 
0445
) + /* ':' */ 1;
39
1.33M
  if (WithArgSpace)
40
154k
    ++Len;
41
1.33M
  return ArgLoc.getLocWithOffset(-Len);
42
1.33M
}
43
44
namespace {
45
46
template <typename T>
47
SourceLocation getArgLoc(T* Arg);
48
49
template <>
50
18.6k
SourceLocation getArgLoc<Expr>(Expr *Arg) {
51
18.6k
  return Arg->getBeginLoc();
52
18.6k
}
53
54
template <>
55
1.31M
SourceLocation getArgLoc<ParmVarDecl>(ParmVarDecl *Arg) {
56
1.31M
  SourceLocation Loc = Arg->getBeginLoc();
57
1.31M
  if (Loc.isInvalid())
58
0
    return Loc;
59
  // -1 to point to left paren of the method parameter's type.
60
1.31M
  return Loc.getLocWithOffset(-1);
61
1.31M
}
62
63
template <typename T>
64
1.54M
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
1.33M
  return Index < Args.size() ? getArgLoc(Args[Index]) : 
SourceLocation()218k
;
66
1.54M
}
SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::Expr>(unsigned int, llvm::ArrayRef<clang::Expr*>)
Line
Count
Source
64
31.1k
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
18.6k
  return Index < Args.size() ? getArgLoc(Args[Index]) : 
SourceLocation()12.4k
;
66
31.1k
}
SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::ParmVarDecl>(unsigned int, llvm::ArrayRef<clang::ParmVarDecl*>)
Line
Count
Source
64
1.51M
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
1.31M
  return Index < Args.size() ? getArgLoc(Args[Index]) : 
SourceLocation()206k
;
66
1.51M
}
67
68
template <typename T>
69
SelectorLocationsKind hasStandardSelLocs(Selector Sel,
70
                                         ArrayRef<SourceLocation> SelLocs,
71
                                         ArrayRef<T *> Args,
72
880k
                                         SourceLocation EndLoc) {
73
  // Are selector locations in standard position with no space between args ?
74
880k
  unsigned i;
75
2.00M
  for (i = 0; i != SelLocs.size(); 
++i1.12M
) {
76
1.33M
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
1.33M
                                             Args, EndLoc))
78
211k
      break;
79
1.33M
  }
80
880k
  if (i == SelLocs.size())
81
669k
    return SelLoc_StandardNoSpace;
82
211k
83
  // Are selector locations in standard position with space between args ?
84
213k
  
for (i = 0; 211k
i != SelLocs.size();
++i2.01k
) {
85
211k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
211k
                                             Args, EndLoc))
87
209k
      return SelLoc_NonStandard;
88
211k
  }
89
211k
90
1.62k
  return SelLoc_StandardWithSpace;
91
211k
}
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
23.1k
                                         SourceLocation EndLoc) {
73
  // Are selector locations in standard position with no space between args ?
74
23.1k
  unsigned i;
75
47.7k
  for (i = 0; i != SelLocs.size(); 
++i24.5k
) {
76
27.1k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
27.1k
                                             Args, EndLoc))
78
2.59k
      break;
79
27.1k
  }
80
23.1k
  if (i == SelLocs.size())
81
20.5k
    return SelLoc_StandardNoSpace;
82
2.59k
83
  // Are selector locations in standard position with space between args ?
84
3.85k
  
for (i = 0; 2.59k
i != SelLocs.size();
++i1.26k
) {
85
2.82k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
2.82k
                                             Args, EndLoc))
87
1.56k
      return SelLoc_NonStandard;
88
2.82k
  }
89
2.59k
90
1.02k
  return SelLoc_StandardWithSpace;
91
2.59k
}
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
857k
                                         SourceLocation EndLoc) {
73
  // Are selector locations in standard position with no space between args ?
74
857k
  unsigned i;
75
1.95M
  for (i = 0; i != SelLocs.size(); 
++i1.09M
) {
76
1.30M
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
1.30M
                                             Args, EndLoc))
78
208k
      break;
79
1.30M
  }
80
857k
  if (i == SelLocs.size())
81
649k
    return SelLoc_StandardNoSpace;
82
208k
83
  // Are selector locations in standard position with space between args ?
84
209k
  
for (i = 0; 208k
i != SelLocs.size();
++i757
) {
85
208k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
208k
                                             Args, EndLoc))
87
207k
      return SelLoc_NonStandard;
88
208k
  }
89
208k
90
596
  return SelLoc_StandardWithSpace;
91
208k
}
92
93
} // anonymous namespace
94
95
SelectorLocationsKind
96
clang::hasStandardSelectorLocs(Selector Sel,
97
                               ArrayRef<SourceLocation> SelLocs,
98
                               ArrayRef<Expr *> Args,
99
23.1k
                               SourceLocation EndLoc) {
100
23.1k
  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
101
23.1k
}
102
103
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
104
                                             Selector Sel,
105
                                             bool WithArgSpace,
106
                                             ArrayRef<Expr *> Args,
107
31.1k
                                             SourceLocation EndLoc) {
108
31.1k
  return getStandardSelLoc(Index, Sel, WithArgSpace,
109
31.1k
                           getArgLoc(Index, Args), EndLoc);
110
31.1k
}
111
112
SelectorLocationsKind
113
clang::hasStandardSelectorLocs(Selector Sel,
114
                               ArrayRef<SourceLocation> SelLocs,
115
                               ArrayRef<ParmVarDecl *> Args,
116
857k
                               SourceLocation EndLoc) {
117
857k
  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
118
857k
}
119
120
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
121
                                             Selector Sel,
122
                                             bool WithArgSpace,
123
                                             ArrayRef<ParmVarDecl *> Args,
124
1.51M
                                             SourceLocation EndLoc) {
125
1.51M
  return getStandardSelLoc(Index, Sel, WithArgSpace,
126
1.51M
                           getArgLoc(Index, Args), EndLoc);
127
1.51M
}