/src/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 | 0 | SourceLocation EndLoc) { |
24 | 0 | unsigned NumSelArgs = Sel.getNumArgs(); |
25 | 0 | if (NumSelArgs == 0) { |
26 | 0 | assert(Index == 0); |
27 | 0 | if (EndLoc.isInvalid()) |
28 | 0 | return SourceLocation(); |
29 | 0 | IdentifierInfo *II = Sel.getIdentifierInfoForSlot(0); |
30 | 0 | unsigned Len = II ? II->getLength() : 0; |
31 | 0 | return EndLoc.getLocWithOffset(-Len); |
32 | 0 | } |
33 | | |
34 | 0 | assert(Index < NumSelArgs); |
35 | 0 | if (ArgLoc.isInvalid()) |
36 | 0 | return SourceLocation(); |
37 | 0 | IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Index); |
38 | 0 | unsigned Len = /* selector id */ (II ? II->getLength() : 0) + /* ':' */ 1; |
39 | 0 | if (WithArgSpace) |
40 | 0 | ++Len; |
41 | 0 | return ArgLoc.getLocWithOffset(-Len); |
42 | 0 | } |
43 | | |
44 | | namespace { |
45 | | |
46 | | template <typename T> |
47 | | SourceLocation getArgLoc(T* Arg); |
48 | | |
49 | | template <> |
50 | 0 | SourceLocation getArgLoc<Expr>(Expr *Arg) { |
51 | 0 | return Arg->getBeginLoc(); |
52 | 0 | } |
53 | | |
54 | | template <> |
55 | 0 | SourceLocation getArgLoc<ParmVarDecl>(ParmVarDecl *Arg) { |
56 | 0 | SourceLocation Loc = Arg->getBeginLoc(); |
57 | 0 | if (Loc.isInvalid()) |
58 | 0 | return Loc; |
59 | | // -1 to point to left paren of the method parameter's type. |
60 | 0 | return Loc.getLocWithOffset(-1); |
61 | 0 | } |
62 | | |
63 | | template <typename T> |
64 | 0 | SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) { |
65 | 0 | return Index < Args.size() ? getArgLoc(Args[Index]) : SourceLocation(); |
66 | 0 | } Unexecuted instantiation: SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::Expr>(unsigned int, llvm::ArrayRef<clang::Expr*>) Unexecuted instantiation: SelectorLocationsKind.cpp:clang::SourceLocation (anonymous namespace)::getArgLoc<clang::ParmVarDecl>(unsigned int, llvm::ArrayRef<clang::ParmVarDecl*>) |
67 | | |
68 | | template <typename T> |
69 | | SelectorLocationsKind hasStandardSelLocs(Selector Sel, |
70 | | ArrayRef<SourceLocation> SelLocs, |
71 | | ArrayRef<T *> Args, |
72 | 0 | SourceLocation EndLoc) { |
73 | | // Are selector locations in standard position with no space between args ? |
74 | 0 | unsigned i; |
75 | 0 | for (i = 0; i != SelLocs.size(); ++i) { |
76 | 0 | if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false, |
77 | 0 | Args, EndLoc)) |
78 | 0 | break; |
79 | 0 | } |
80 | 0 | if (i == SelLocs.size()) |
81 | 0 | return SelLoc_StandardNoSpace; |
82 | | |
83 | | // Are selector locations in standard position with space between args ? |
84 | 0 | for (i = 0; i != SelLocs.size(); ++i) { |
85 | 0 | if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true, |
86 | 0 | Args, EndLoc)) |
87 | 0 | return SelLoc_NonStandard; |
88 | 0 | } |
89 | | |
90 | 0 | return SelLoc_StandardWithSpace; |
91 | 0 | } Unexecuted instantiation: SelectorLocationsKind.cpp:clang::SelectorLocationsKind (anonymous namespace)::hasStandardSelLocs<clang::Expr>(clang::Selector, llvm::ArrayRef<clang::SourceLocation>, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation) Unexecuted instantiation: SelectorLocationsKind.cpp:clang::SelectorLocationsKind (anonymous namespace)::hasStandardSelLocs<clang::ParmVarDecl>(clang::Selector, llvm::ArrayRef<clang::SourceLocation>, llvm::ArrayRef<clang::ParmVarDecl*>, clang::SourceLocation) |
92 | | |
93 | | } // anonymous namespace |
94 | | |
95 | | SelectorLocationsKind |
96 | | clang::hasStandardSelectorLocs(Selector Sel, |
97 | | ArrayRef<SourceLocation> SelLocs, |
98 | | ArrayRef<Expr *> Args, |
99 | 0 | SourceLocation EndLoc) { |
100 | 0 | return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc); |
101 | 0 | } |
102 | | |
103 | | SourceLocation clang::getStandardSelectorLoc(unsigned Index, |
104 | | Selector Sel, |
105 | | bool WithArgSpace, |
106 | | ArrayRef<Expr *> Args, |
107 | 0 | SourceLocation EndLoc) { |
108 | 0 | return getStandardSelLoc(Index, Sel, WithArgSpace, |
109 | 0 | getArgLoc(Index, Args), EndLoc); |
110 | 0 | } |
111 | | |
112 | | SelectorLocationsKind |
113 | | clang::hasStandardSelectorLocs(Selector Sel, |
114 | | ArrayRef<SourceLocation> SelLocs, |
115 | | ArrayRef<ParmVarDecl *> Args, |
116 | 0 | SourceLocation EndLoc) { |
117 | 0 | return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc); |
118 | 0 | } |
119 | | |
120 | | SourceLocation clang::getStandardSelectorLoc(unsigned Index, |
121 | | Selector Sel, |
122 | | bool WithArgSpace, |
123 | | ArrayRef<ParmVarDecl *> Args, |
124 | 0 | SourceLocation EndLoc) { |
125 | 0 | return getStandardSelLoc(Index, Sel, WithArgSpace, |
126 | 0 | getArgLoc(Index, Args), EndLoc); |
127 | 0 | } |