Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
109k
                                        SourceLocation EndLoc) {
24
109k
  unsigned NumSelArgs = Sel.getNumArgs();
25
109k
  if (NumSelArgs == 0) {
26
34.2k
    assert(Index == 0);
27
34.2k
    if (EndLoc.isInvalid())
28
0
      return SourceLocation();
29
34.2k
    IdentifierInfo *II = Sel.getIdentifierInfoForSlot(0);
30
34.2k
    unsigned Len = II ? II->getLength() : 
00
;
31
34.2k
    return EndLoc.getLocWithOffset(-Len);
32
34.2k
  }
33
75.3k
34
75.3k
  assert(Index < NumSelArgs);
35
75.3k
  if (ArgLoc.isInvalid())
36
11
    return SourceLocation();
37
75.3k
  IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Index);
38
75.3k
  unsigned Len = /* selector id */ (II ? 
II->getLength()75.0k
:
0260
) + /* ':' */ 1;
39
75.3k
  if (WithArgSpace)
40
8.93k
    ++Len;
41
75.3k
  return ArgLoc.getLocWithOffset(-Len);
42
75.3k
}
43
44
namespace {
45
46
template <typename T>
47
SourceLocation getArgLoc(T* Arg);
48
49
template <>
50
6.99k
SourceLocation getArgLoc<Expr>(Expr *Arg) {
51
6.99k
  return Arg->getBeginLoc();
52
6.99k
}
53
54
template <>
55
68.3k
SourceLocation getArgLoc<ParmVarDecl>(ParmVarDecl *Arg) {
56
68.3k
  SourceLocation Loc = Arg->getBeginLoc();
57
68.3k
  if (Loc.isInvalid())
58
0
    return Loc;
59
68.3k
  // -1 to point to left paren of the method parameter's type.
60
68.3k
  return Loc.getLocWithOffset(-1);
61
68.3k
}
62
63
template <typename T>
64
109k
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
109k
  return Index < Args.size() ? 
getArgLoc(Args[Index])75.3k
:
SourceLocation()34.2k
;
66
109k
}
SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::Expr>(unsigned int, llvm::ArrayRef<clang::Expr*>)
Line
Count
Source
64
14.9k
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
14.9k
  return Index < Args.size() ? 
getArgLoc(Args[Index])6.99k
:
SourceLocation()7.98k
;
66
14.9k
}
SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::ParmVarDecl>(unsigned int, llvm::ArrayRef<clang::ParmVarDecl*>)
Line
Count
Source
64
94.6k
SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
65
94.6k
  return Index < Args.size() ? 
getArgLoc(Args[Index])68.3k
:
SourceLocation()26.2k
;
66
94.6k
}
67
68
template <typename T>
69
SelectorLocationsKind hasStandardSelLocs(Selector Sel,
70
                                         ArrayRef<SourceLocation> SelLocs,
71
                                         ArrayRef<T *> Args,
72
68.2k
                                         SourceLocation EndLoc) {
73
68.2k
  // Are selector locations in standard position with no space between args ?
74
68.2k
  unsigned i;
75
145k
  for (i = 0; i != SelLocs.size(); 
++i76.9k
) {
76
92.0k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
92.0k
                                             Args, EndLoc))
78
15.0k
      break;
79
92.0k
  }
80
68.2k
  if (i == SelLocs.size())
81
53.1k
    return SelLoc_StandardNoSpace;
82
15.0k
83
15.0k
  // Are selector locations in standard position with space between args ?
84
16.4k
  
for (i = 0; 15.0k
i != SelLocs.size();
++i1.39k
) {
85
15.3k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
15.3k
                                             Args, EndLoc))
87
13.9k
      return SelLoc_NonStandard;
88
15.3k
  }
89
15.0k
90
15.0k
  
return SelLoc_StandardWithSpace1.06k
;
91
15.0k
}
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
11.0k
                                         SourceLocation EndLoc) {
73
11.0k
  // Are selector locations in standard position with no space between args ?
74
11.0k
  unsigned i;
75
22.4k
  for (i = 0; i != SelLocs.size(); 
++i11.3k
) {
76
12.5k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
12.5k
                                             Args, EndLoc))
78
1.14k
      break;
79
12.5k
  }
80
11.0k
  if (i == SelLocs.size())
81
9.95k
    return SelLoc_StandardNoSpace;
82
1.14k
83
1.14k
  // Are selector locations in standard position with space between args ?
84
1.92k
  
for (i = 0; 1.14k
i != SelLocs.size();
++i785
) {
85
1.35k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
1.35k
                                             Args, EndLoc))
87
570
      return SelLoc_NonStandard;
88
1.35k
  }
89
1.14k
90
1.14k
  
return SelLoc_StandardWithSpace571
;
91
1.14k
}
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
57.1k
                                         SourceLocation EndLoc) {
73
57.1k
  // Are selector locations in standard position with no space between args ?
74
57.1k
  unsigned i;
75
122k
  for (i = 0; i != SelLocs.size(); 
++i65.6k
) {
76
79.4k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
77
79.4k
                                             Args, EndLoc))
78
13.8k
      break;
79
79.4k
  }
80
57.1k
  if (i == SelLocs.size())
81
43.2k
    return SelLoc_StandardNoSpace;
82
13.8k
83
13.8k
  // Are selector locations in standard position with space between args ?
84
14.4k
  
for (i = 0; 13.8k
i != SelLocs.size();
++i606
) {
85
13.9k
    if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
86
13.9k
                                             Args, EndLoc))
87
13.3k
      return SelLoc_NonStandard;
88
13.9k
  }
89
13.8k
90
13.8k
  
return SelLoc_StandardWithSpace497
;
91
13.8k
}
92
93
} // anonymous namespace
94
95
SelectorLocationsKind
96
clang::hasStandardSelectorLocs(Selector Sel,
97
                               ArrayRef<SourceLocation> SelLocs,
98
                               ArrayRef<Expr *> Args,
99
11.0k
                               SourceLocation EndLoc) {
100
11.0k
  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
101
11.0k
}
102
103
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
104
                                             Selector Sel,
105
                                             bool WithArgSpace,
106
                                             ArrayRef<Expr *> Args,
107
14.9k
                                             SourceLocation EndLoc) {
108
14.9k
  return getStandardSelLoc(Index, Sel, WithArgSpace,
109
14.9k
                           getArgLoc(Index, Args), EndLoc);
110
14.9k
}
111
112
SelectorLocationsKind
113
clang::hasStandardSelectorLocs(Selector Sel,
114
                               ArrayRef<SourceLocation> SelLocs,
115
                               ArrayRef<ParmVarDecl *> Args,
116
57.1k
                               SourceLocation EndLoc) {
117
57.1k
  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
118
57.1k
}
119
120
SourceLocation clang::getStandardSelectorLoc(unsigned Index,
121
                                             Selector Sel,
122
                                             bool WithArgSpace,
123
                                             ArrayRef<ParmVarDecl *> Args,
124
94.6k
                                             SourceLocation EndLoc) {
125
94.6k
  return getStandardSelLoc(Index, Sel, WithArgSpace,
126
94.6k
                           getArgLoc(Index, Args), EndLoc);
127
94.6k
}