clang  6.0.0svn
SelectorLocationsKind.cpp
Go to the documentation of this file.
1 //===--- SelectorLocationsKind.cpp - Kind of selector locations -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Describes whether the identifier locations for a selector are "standard"
11 // or not.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "clang/AST/Expr.h"
17 
18 using namespace clang;
19 
20 static SourceLocation getStandardSelLoc(unsigned Index,
21  Selector Sel,
22  bool WithArgSpace,
23  SourceLocation ArgLoc,
24  SourceLocation EndLoc) {
25  unsigned NumSelArgs = Sel.getNumArgs();
26  if (NumSelArgs == 0) {
27  assert(Index == 0);
28  if (EndLoc.isInvalid())
29  return SourceLocation();
31  unsigned Len = II ? II->getLength() : 0;
32  return EndLoc.getLocWithOffset(-Len);
33  }
34 
35  assert(Index < NumSelArgs);
36  if (ArgLoc.isInvalid())
37  return SourceLocation();
39  unsigned Len = /* selector id */ (II ? II->getLength() : 0) + /* ':' */ 1;
40  if (WithArgSpace)
41  ++Len;
42  return ArgLoc.getLocWithOffset(-Len);
43 }
44 
45 namespace {
46 
47 template <typename T>
48 SourceLocation getArgLoc(T* Arg);
49 
50 template <>
51 SourceLocation getArgLoc<Expr>(Expr *Arg) {
52  return Arg->getLocStart();
53 }
54 
55 template <>
56 SourceLocation getArgLoc<ParmVarDecl>(ParmVarDecl *Arg) {
57  SourceLocation Loc = Arg->getLocStart();
58  if (Loc.isInvalid())
59  return Loc;
60  // -1 to point to left paren of the method parameter's type.
61  return Loc.getLocWithOffset(-1);
62 }
63 
64 template <typename T>
65 SourceLocation getArgLoc(unsigned Index, ArrayRef<T*> Args) {
66  return Index < Args.size() ? getArgLoc(Args[Index]) : SourceLocation();
67 }
68 
69 template <typename T>
70 SelectorLocationsKind hasStandardSelLocs(Selector Sel,
72  ArrayRef<T *> Args,
73  SourceLocation EndLoc) {
74  // Are selector locations in standard position with no space between args ?
75  unsigned i;
76  for (i = 0; i != SelLocs.size(); ++i) {
77  if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/false,
78  Args, EndLoc))
79  break;
80  }
81  if (i == SelLocs.size())
83 
84  // Are selector locations in standard position with space between args ?
85  for (i = 0; i != SelLocs.size(); ++i) {
86  if (SelLocs[i] != getStandardSelectorLoc(i, Sel, /*WithArgSpace=*/true,
87  Args, EndLoc))
88  return SelLoc_NonStandard;
89  }
90 
92 }
93 
94 } // anonymous namespace
95 
99  ArrayRef<Expr *> Args,
100  SourceLocation EndLoc) {
101  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
102 }
103 
105  Selector Sel,
106  bool WithArgSpace,
107  ArrayRef<Expr *> Args,
108  SourceLocation EndLoc) {
109  return getStandardSelLoc(Index, Sel, WithArgSpace,
110  getArgLoc(Index, Args), EndLoc);
111 }
112 
115  ArrayRef<SourceLocation> SelLocs,
117  SourceLocation EndLoc) {
118  return hasStandardSelLocs(Sel, SelLocs, Args, EndLoc);
119 }
120 
122  Selector Sel,
123  bool WithArgSpace,
125  SourceLocation EndLoc) {
126  return getStandardSelLoc(Index, Sel, WithArgSpace,
127  getArgLoc(Index, Args), EndLoc);
128 }
For nullary selectors, immediately before the end: "[foo release]" / "-(void)release;" Or with a spac...
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Smart pointer class that efficiently represents Objective-C method names.
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1514
One of these records is kept for each identifier that is lexed.
static SourceLocation getStandardSelLoc(unsigned Index, Selector Sel, bool WithArgSpace, SourceLocation ArgLoc, SourceLocation EndLoc)
SelectorLocationsKind
Whether all locations of the selector identifiers are in a "standard" position.
unsigned getLength() const
Efficiently return the length of this identifier info.
Expr - This represents one expression.
Definition: Expr.h:106
const FunctionProtoType * T
SourceLocation getStandardSelectorLoc(unsigned Index, Selector Sel, bool WithArgSpace, ArrayRef< Expr *> Args, SourceLocation EndLoc)
Get the "standard" location of a selector identifier, e.g: For nullary selectors, immediately before ...
unsigned getNumArgs() const
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
Encodes a location in the source.
Dataflow Directional Tag Classes.
For nullary selectors, immediately before the end: "[foo release]" / "-(void)release;" Or immediately...
SelectorLocationsKind hasStandardSelectorLocs(Selector Sel, ArrayRef< SourceLocation > SelLocs, ArrayRef< Expr *> Args, SourceLocation EndLoc)
Returns true if all SelLocs are in a "standard" location.