Bug Summary

File:tools/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
Warning:line 90, column 36
Undefined or garbage value returned to caller

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name LocalizationChecker.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn326551/build-llvm/tools/clang/lib/StaticAnalyzer/Checkers -I /build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/StaticAnalyzer/Checkers -I /build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn326551/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn326551/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn326551/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn326551/build-llvm/tools/clang/lib/StaticAnalyzer/Checkers -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-03-02-155150-1477-1 -x c++ /build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp

/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp

1//=- LocalizationChecker.cpp -------------------------------------*- 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// This file defines a set of checks for localizability including:
11// 1) A checker that warns about uses of non-localized NSStrings passed to
12// UI methods expecting localized strings
13// 2) A syntactic checker that warns against the bad practice of
14// not including a comment in NSLocalizedString macros.
15//
16//===----------------------------------------------------------------------===//
17
18#include "ClangSACheckers.h"
19#include "clang/AST/Attr.h"
20#include "clang/AST/Decl.h"
21#include "clang/AST/DeclObjC.h"
22#include "clang/AST/RecursiveASTVisitor.h"
23#include "clang/AST/StmtVisitor.h"
24#include "clang/Lex/Lexer.h"
25#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
26#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
27#include "clang/StaticAnalyzer/Core/Checker.h"
28#include "clang/StaticAnalyzer/Core/CheckerManager.h"
29#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
30#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
31#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
32#include "llvm/Support/Unicode.h"
33
34using namespace clang;
35using namespace ento;
36
37namespace {
38struct LocalizedState {
39private:
40 enum Kind { NonLocalized, Localized } K;
41 LocalizedState(Kind InK) : K(InK) {}
42
43public:
44 bool isLocalized() const { return K == Localized; }
45 bool isNonLocalized() const { return K == NonLocalized; }
46
47 static LocalizedState getLocalized() { return LocalizedState(Localized); }
48 static LocalizedState getNonLocalized() {
49 return LocalizedState(NonLocalized);
50 }
51
52 // Overload the == operator
53 bool operator==(const LocalizedState &X) const { return K == X.K; }
54
55 // LLVMs equivalent of a hash function
56 void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); }
57};
58
59class NonLocalizedStringChecker
60 : public Checker<check::PreCall, check::PostCall, check::PreObjCMessage,
61 check::PostObjCMessage,
62 check::PostStmt<ObjCStringLiteral>> {
63
64 mutable std::unique_ptr<BugType> BT;
65
66 // Methods that require a localized string
67 mutable llvm::DenseMap<const IdentifierInfo *,
68 llvm::DenseMap<Selector, uint8_t>> UIMethods;
69 // Methods that return a localized string
70 mutable llvm::SmallSet<std::pair<const IdentifierInfo *, Selector>, 12> LSM;
71 // C Functions that return a localized string
72 mutable llvm::SmallSet<const IdentifierInfo *, 5> LSF;
73
74 void initUIMethods(ASTContext &Ctx) const;
75 void initLocStringsMethods(ASTContext &Ctx) const;
76
77 bool hasNonLocalizedState(SVal S, CheckerContext &C) const;
78 bool hasLocalizedState(SVal S, CheckerContext &C) const;
79 void setNonLocalizedState(SVal S, CheckerContext &C) const;
80 void setLocalizedState(SVal S, CheckerContext &C) const;
81
82 bool isAnnotatedAsReturningLocalized(const Decl *D) const;
83 bool isAnnotatedAsTakingLocalized(const Decl *D) const;
84 void reportLocalizationError(SVal S, const CallEvent &M, CheckerContext &C,
85 int argumentNumber = 0) const;
86
87 int getLocalizedArgumentForSelector(const IdentifierInfo *Receiver,
88 Selector S) const;
89
90public:
91 NonLocalizedStringChecker();
92
93 // When this parameter is set to true, the checker assumes all
94 // methods that return NSStrings are unlocalized. Thus, more false
95 // positives will be reported.
96 DefaultBool IsAggressive;
97
98 void checkPreObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;
99 void checkPostObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;
100 void checkPostStmt(const ObjCStringLiteral *SL, CheckerContext &C) const;
101 void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
102 void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
103};
104
105} // end anonymous namespace
106
107REGISTER_MAP_WITH_PROGRAMSTATE(LocalizedMemMap, const MemRegion *,namespace { class LocalizedMemMap {}; typedef llvm::ImmutableMap
<const MemRegion *, LocalizedState> LocalizedMemMapTy; }
namespace clang { namespace ento { template <> struct ProgramStateTrait
<LocalizedMemMap> : public ProgramStatePartialTrait<
LocalizedMemMapTy> { static void *GDMIndex() { static int Index
; return &Index; } }; } }
108 LocalizedState)namespace { class LocalizedMemMap {}; typedef llvm::ImmutableMap
<const MemRegion *, LocalizedState> LocalizedMemMapTy; }
namespace clang { namespace ento { template <> struct ProgramStateTrait
<LocalizedMemMap> : public ProgramStatePartialTrait<
LocalizedMemMapTy> { static void *GDMIndex() { static int Index
; return &Index; } }; } }
109
110NonLocalizedStringChecker::NonLocalizedStringChecker() {
111 BT.reset(new BugType(this, "Unlocalizable string",
112 "Localizability Issue (Apple)"));
113}
114
115namespace {
116class NonLocalizedStringBRVisitor final
117 : public BugReporterVisitorImpl<NonLocalizedStringBRVisitor> {
118
119 const MemRegion *NonLocalizedString;
120 bool Satisfied;
121
122public:
123 NonLocalizedStringBRVisitor(const MemRegion *NonLocalizedString)
124 : NonLocalizedString(NonLocalizedString), Satisfied(false) {
125 assert(NonLocalizedString)(static_cast <bool> (NonLocalizedString) ? void (0) : __assert_fail
("NonLocalizedString", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp"
, 125, __extension__ __PRETTY_FUNCTION__))
;
126 }
127
128 std::shared_ptr<PathDiagnosticPiece> VisitNode(const ExplodedNode *Succ,
129 const ExplodedNode *Pred,
130 BugReporterContext &BRC,
131 BugReport &BR) override;
132
133 void Profile(llvm::FoldingSetNodeID &ID) const override {
134 ID.Add(NonLocalizedString);
135 }
136};
137} // End anonymous namespace.
138
139#define NEW_RECEIVER(receiver)llvm::DenseMap<Selector, uint8_t> &receiverM = UIMethods
.insert({&Ctx.Idents.get("receiver"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
\
140 llvm::DenseMap<Selector, uint8_t> &receiver##M = \
141 UIMethods.insert({&Ctx.Idents.get(#receiver), \
142 llvm::DenseMap<Selector, uint8_t>()}) \
143 .first->second;
144#define ADD_NULLARY_METHOD(receiver, method, argument)receiverM.insert( {Ctx.Selectors.getNullarySelector(&Ctx.
Idents.get("method")), argument});
\
145 receiver##M.insert( \
146 {Ctx.Selectors.getNullarySelector(&Ctx.Idents.get(#method)), argument});
147#define ADD_UNARY_METHOD(receiver, method, argument)receiverM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("method")), argument});
\
148 receiver##M.insert( \
149 {Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(#method)), argument});
150#define ADD_METHOD(receiver, method_list, count, argument)receiverM.insert({Ctx.Selectors.getSelector(count, method_list
), argument});
\
151 receiver##M.insert({Ctx.Selectors.getSelector(count, method_list), argument});
152
153/// Initializes a list of methods that require a localized string
154/// Format: {"ClassName", {{"selectorName:", LocStringArg#}, ...}, ...}
155void NonLocalizedStringChecker::initUIMethods(ASTContext &Ctx) const {
156 if (!UIMethods.empty())
157 return;
158
159 // UI Methods
160 NEW_RECEIVER(UISearchDisplayController)llvm::DenseMap<Selector, uint8_t> &UISearchDisplayControllerM
= UIMethods.insert({&Ctx.Idents.get("UISearchDisplayController"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
161 ADD_UNARY_METHOD(UISearchDisplayController, setSearchResultsTitle, 0)UISearchDisplayControllerM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setSearchResultsTitle")), 0});
162
163 NEW_RECEIVER(UITabBarItem)llvm::DenseMap<Selector, uint8_t> &UITabBarItemM = UIMethods
.insert({&Ctx.Idents.get("UITabBarItem"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
164 IdentifierInfo *initWithTitleUITabBarItemTag[] = {
165 &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("image"),
166 &Ctx.Idents.get("tag")};
167 ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemTag, 3, 0)UITabBarItemM.insert({Ctx.Selectors.getSelector(3, initWithTitleUITabBarItemTag
), 0});
168 IdentifierInfo *initWithTitleUITabBarItemImage[] = {
169 &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("image"),
170 &Ctx.Idents.get("selectedImage")};
171 ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemImage, 3, 0)UITabBarItemM.insert({Ctx.Selectors.getSelector(3, initWithTitleUITabBarItemImage
), 0});
172
173 NEW_RECEIVER(NSDockTile)llvm::DenseMap<Selector, uint8_t> &NSDockTileM = UIMethods
.insert({&Ctx.Idents.get("NSDockTile"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
174 ADD_UNARY_METHOD(NSDockTile, setBadgeLabel, 0)NSDockTileM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setBadgeLabel")), 0});
175
176 NEW_RECEIVER(NSStatusItem)llvm::DenseMap<Selector, uint8_t> &NSStatusItemM = UIMethods
.insert({&Ctx.Idents.get("NSStatusItem"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
177 ADD_UNARY_METHOD(NSStatusItem, setTitle, 0)NSStatusItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
178 ADD_UNARY_METHOD(NSStatusItem, setToolTip, 0)NSStatusItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setToolTip")), 0});
179
180 NEW_RECEIVER(UITableViewRowAction)llvm::DenseMap<Selector, uint8_t> &UITableViewRowActionM
= UIMethods.insert({&Ctx.Idents.get("UITableViewRowAction"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
181 IdentifierInfo *rowActionWithStyleUITableViewRowAction[] = {
182 &Ctx.Idents.get("rowActionWithStyle"), &Ctx.Idents.get("title"),
183 &Ctx.Idents.get("handler")};
184 ADD_METHOD(UITableViewRowAction, rowActionWithStyleUITableViewRowAction, 3, 1)UITableViewRowActionM.insert({Ctx.Selectors.getSelector(3, rowActionWithStyleUITableViewRowAction
), 1});
185 ADD_UNARY_METHOD(UITableViewRowAction, setTitle, 0)UITableViewRowActionM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setTitle")), 0});
186
187 NEW_RECEIVER(NSBox)llvm::DenseMap<Selector, uint8_t> &NSBoxM = UIMethods
.insert({&Ctx.Idents.get("NSBox"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
188 ADD_UNARY_METHOD(NSBox, setTitle, 0)NSBoxM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setTitle")), 0});
189
190 NEW_RECEIVER(NSButton)llvm::DenseMap<Selector, uint8_t> &NSButtonM = UIMethods
.insert({&Ctx.Idents.get("NSButton"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
191 ADD_UNARY_METHOD(NSButton, setTitle, 0)NSButtonM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setTitle")), 0});
192 ADD_UNARY_METHOD(NSButton, setAlternateTitle, 0)NSButtonM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setAlternateTitle")), 0});
193 IdentifierInfo *radioButtonWithTitleNSButton[] = {
194 &Ctx.Idents.get("radioButtonWithTitle"), &Ctx.Idents.get("target"),
195 &Ctx.Idents.get("action")};
196 ADD_METHOD(NSButton, radioButtonWithTitleNSButton, 3, 0)NSButtonM.insert({Ctx.Selectors.getSelector(3, radioButtonWithTitleNSButton
), 0});
197 IdentifierInfo *buttonWithTitleNSButtonImage[] = {
198 &Ctx.Idents.get("buttonWithTitle"), &Ctx.Idents.get("image"),
199 &Ctx.Idents.get("target"), &Ctx.Idents.get("action")};
200 ADD_METHOD(NSButton, buttonWithTitleNSButtonImage, 4, 0)NSButtonM.insert({Ctx.Selectors.getSelector(4, buttonWithTitleNSButtonImage
), 0});
201 IdentifierInfo *checkboxWithTitleNSButton[] = {
202 &Ctx.Idents.get("checkboxWithTitle"), &Ctx.Idents.get("target"),
203 &Ctx.Idents.get("action")};
204 ADD_METHOD(NSButton, checkboxWithTitleNSButton, 3, 0)NSButtonM.insert({Ctx.Selectors.getSelector(3, checkboxWithTitleNSButton
), 0});
205 IdentifierInfo *buttonWithTitleNSButtonTarget[] = {
206 &Ctx.Idents.get("buttonWithTitle"), &Ctx.Idents.get("target"),
207 &Ctx.Idents.get("action")};
208 ADD_METHOD(NSButton, buttonWithTitleNSButtonTarget, 3, 0)NSButtonM.insert({Ctx.Selectors.getSelector(3, buttonWithTitleNSButtonTarget
), 0});
209
210 NEW_RECEIVER(NSSavePanel)llvm::DenseMap<Selector, uint8_t> &NSSavePanelM = UIMethods
.insert({&Ctx.Idents.get("NSSavePanel"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
211 ADD_UNARY_METHOD(NSSavePanel, setPrompt, 0)NSSavePanelM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setPrompt")), 0});
212 ADD_UNARY_METHOD(NSSavePanel, setTitle, 0)NSSavePanelM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
213 ADD_UNARY_METHOD(NSSavePanel, setNameFieldLabel, 0)NSSavePanelM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setNameFieldLabel")), 0});
214 ADD_UNARY_METHOD(NSSavePanel, setNameFieldStringValue, 0)NSSavePanelM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setNameFieldStringValue")), 0});
215 ADD_UNARY_METHOD(NSSavePanel, setMessage, 0)NSSavePanelM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setMessage")), 0});
216
217 NEW_RECEIVER(UIPrintInfo)llvm::DenseMap<Selector, uint8_t> &UIPrintInfoM = UIMethods
.insert({&Ctx.Idents.get("UIPrintInfo"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
218 ADD_UNARY_METHOD(UIPrintInfo, setJobName, 0)UIPrintInfoM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setJobName")), 0});
219
220 NEW_RECEIVER(NSTabViewItem)llvm::DenseMap<Selector, uint8_t> &NSTabViewItemM =
UIMethods.insert({&Ctx.Idents.get("NSTabViewItem"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
221 ADD_UNARY_METHOD(NSTabViewItem, setLabel, 0)NSTabViewItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setLabel")), 0});
222 ADD_UNARY_METHOD(NSTabViewItem, setToolTip, 0)NSTabViewItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setToolTip")), 0});
223
224 NEW_RECEIVER(NSBrowser)llvm::DenseMap<Selector, uint8_t> &NSBrowserM = UIMethods
.insert({&Ctx.Idents.get("NSBrowser"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
225 IdentifierInfo *setTitleNSBrowser[] = {&Ctx.Idents.get("setTitle"),
226 &Ctx.Idents.get("ofColumn")};
227 ADD_METHOD(NSBrowser, setTitleNSBrowser, 2, 0)NSBrowserM.insert({Ctx.Selectors.getSelector(2, setTitleNSBrowser
), 0});
228
229 NEW_RECEIVER(UIAccessibilityElement)llvm::DenseMap<Selector, uint8_t> &UIAccessibilityElementM
= UIMethods.insert({&Ctx.Idents.get("UIAccessibilityElement"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
230 ADD_UNARY_METHOD(UIAccessibilityElement, setAccessibilityLabel, 0)UIAccessibilityElementM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setAccessibilityLabel")), 0});
231 ADD_UNARY_METHOD(UIAccessibilityElement, setAccessibilityHint, 0)UIAccessibilityElementM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setAccessibilityHint")), 0});
232 ADD_UNARY_METHOD(UIAccessibilityElement, setAccessibilityValue, 0)UIAccessibilityElementM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setAccessibilityValue")), 0});
233
234 NEW_RECEIVER(UIAlertAction)llvm::DenseMap<Selector, uint8_t> &UIAlertActionM =
UIMethods.insert({&Ctx.Idents.get("UIAlertAction"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
235 IdentifierInfo *actionWithTitleUIAlertAction[] = {
236 &Ctx.Idents.get("actionWithTitle"), &Ctx.Idents.get("style"),
237 &Ctx.Idents.get("handler")};
238 ADD_METHOD(UIAlertAction, actionWithTitleUIAlertAction, 3, 0)UIAlertActionM.insert({Ctx.Selectors.getSelector(3, actionWithTitleUIAlertAction
), 0});
239
240 NEW_RECEIVER(NSPopUpButton)llvm::DenseMap<Selector, uint8_t> &NSPopUpButtonM =
UIMethods.insert({&Ctx.Idents.get("NSPopUpButton"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
241 ADD_UNARY_METHOD(NSPopUpButton, addItemWithTitle, 0)NSPopUpButtonM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("addItemWithTitle")), 0});
242 IdentifierInfo *insertItemWithTitleNSPopUpButton[] = {
243 &Ctx.Idents.get("insertItemWithTitle"), &Ctx.Idents.get("atIndex")};
244 ADD_METHOD(NSPopUpButton, insertItemWithTitleNSPopUpButton, 2, 0)NSPopUpButtonM.insert({Ctx.Selectors.getSelector(2, insertItemWithTitleNSPopUpButton
), 0});
245 ADD_UNARY_METHOD(NSPopUpButton, removeItemWithTitle, 0)NSPopUpButtonM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("removeItemWithTitle")), 0});
246 ADD_UNARY_METHOD(NSPopUpButton, selectItemWithTitle, 0)NSPopUpButtonM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("selectItemWithTitle")), 0});
247 ADD_UNARY_METHOD(NSPopUpButton, setTitle, 0)NSPopUpButtonM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
248
249 NEW_RECEIVER(NSTableViewRowAction)llvm::DenseMap<Selector, uint8_t> &NSTableViewRowActionM
= UIMethods.insert({&Ctx.Idents.get("NSTableViewRowAction"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
250 IdentifierInfo *rowActionWithStyleNSTableViewRowAction[] = {
251 &Ctx.Idents.get("rowActionWithStyle"), &Ctx.Idents.get("title"),
252 &Ctx.Idents.get("handler")};
253 ADD_METHOD(NSTableViewRowAction, rowActionWithStyleNSTableViewRowAction, 3, 1)NSTableViewRowActionM.insert({Ctx.Selectors.getSelector(3, rowActionWithStyleNSTableViewRowAction
), 1});
254 ADD_UNARY_METHOD(NSTableViewRowAction, setTitle, 0)NSTableViewRowActionM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setTitle")), 0});
255
256 NEW_RECEIVER(NSImage)llvm::DenseMap<Selector, uint8_t> &NSImageM = UIMethods
.insert({&Ctx.Idents.get("NSImage"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
257 ADD_UNARY_METHOD(NSImage, setAccessibilityDescription, 0)NSImageM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setAccessibilityDescription")), 0});
258
259 NEW_RECEIVER(NSUserActivity)llvm::DenseMap<Selector, uint8_t> &NSUserActivityM =
UIMethods.insert({&Ctx.Idents.get("NSUserActivity"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
260 ADD_UNARY_METHOD(NSUserActivity, setTitle, 0)NSUserActivityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
261
262 NEW_RECEIVER(NSPathControlItem)llvm::DenseMap<Selector, uint8_t> &NSPathControlItemM
= UIMethods.insert({&Ctx.Idents.get("NSPathControlItem")
, llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
263 ADD_UNARY_METHOD(NSPathControlItem, setTitle, 0)NSPathControlItemM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
264
265 NEW_RECEIVER(NSCell)llvm::DenseMap<Selector, uint8_t> &NSCellM = UIMethods
.insert({&Ctx.Idents.get("NSCell"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
266 ADD_UNARY_METHOD(NSCell, initTextCell, 0)NSCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("initTextCell")), 0});
267 ADD_UNARY_METHOD(NSCell, setTitle, 0)NSCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setTitle")), 0});
268 ADD_UNARY_METHOD(NSCell, setStringValue, 0)NSCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setStringValue")), 0});
269
270 NEW_RECEIVER(NSPathControl)llvm::DenseMap<Selector, uint8_t> &NSPathControlM =
UIMethods.insert({&Ctx.Idents.get("NSPathControl"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
271 ADD_UNARY_METHOD(NSPathControl, setPlaceholderString, 0)NSPathControlM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setPlaceholderString")), 0});
272
273 NEW_RECEIVER(UIAccessibility)llvm::DenseMap<Selector, uint8_t> &UIAccessibilityM
= UIMethods.insert({&Ctx.Idents.get("UIAccessibility"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
274 ADD_UNARY_METHOD(UIAccessibility, setAccessibilityLabel, 0)UIAccessibilityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setAccessibilityLabel")), 0});
275 ADD_UNARY_METHOD(UIAccessibility, setAccessibilityHint, 0)UIAccessibilityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setAccessibilityHint")), 0});
276 ADD_UNARY_METHOD(UIAccessibility, setAccessibilityValue, 0)UIAccessibilityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setAccessibilityValue")), 0});
277
278 NEW_RECEIVER(NSTableColumn)llvm::DenseMap<Selector, uint8_t> &NSTableColumnM =
UIMethods.insert({&Ctx.Idents.get("NSTableColumn"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
279 ADD_UNARY_METHOD(NSTableColumn, setTitle, 0)NSTableColumnM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
280 ADD_UNARY_METHOD(NSTableColumn, setHeaderToolTip, 0)NSTableColumnM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setHeaderToolTip")), 0});
281
282 NEW_RECEIVER(NSSegmentedControl)llvm::DenseMap<Selector, uint8_t> &NSSegmentedControlM
= UIMethods.insert({&Ctx.Idents.get("NSSegmentedControl"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
283 IdentifierInfo *setLabelNSSegmentedControl[] = {
284 &Ctx.Idents.get("setLabel"), &Ctx.Idents.get("forSegment")};
285 ADD_METHOD(NSSegmentedControl, setLabelNSSegmentedControl, 2, 0)NSSegmentedControlM.insert({Ctx.Selectors.getSelector(2, setLabelNSSegmentedControl
), 0});
286 IdentifierInfo *setToolTipNSSegmentedControl[] = {
287 &Ctx.Idents.get("setToolTip"), &Ctx.Idents.get("forSegment")};
288 ADD_METHOD(NSSegmentedControl, setToolTipNSSegmentedControl, 2, 0)NSSegmentedControlM.insert({Ctx.Selectors.getSelector(2, setToolTipNSSegmentedControl
), 0});
289
290 NEW_RECEIVER(NSButtonCell)llvm::DenseMap<Selector, uint8_t> &NSButtonCellM = UIMethods
.insert({&Ctx.Idents.get("NSButtonCell"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
291 ADD_UNARY_METHOD(NSButtonCell, setTitle, 0)NSButtonCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
292 ADD_UNARY_METHOD(NSButtonCell, setAlternateTitle, 0)NSButtonCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setAlternateTitle")), 0});
293
294 NEW_RECEIVER(NSDatePickerCell)llvm::DenseMap<Selector, uint8_t> &NSDatePickerCellM
= UIMethods.insert({&Ctx.Idents.get("NSDatePickerCell"),
llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
295 ADD_UNARY_METHOD(NSDatePickerCell, initTextCell, 0)NSDatePickerCellM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("initTextCell")), 0});
296
297 NEW_RECEIVER(NSSliderCell)llvm::DenseMap<Selector, uint8_t> &NSSliderCellM = UIMethods
.insert({&Ctx.Idents.get("NSSliderCell"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
298 ADD_UNARY_METHOD(NSSliderCell, setTitle, 0)NSSliderCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
299
300 NEW_RECEIVER(NSControl)llvm::DenseMap<Selector, uint8_t> &NSControlM = UIMethods
.insert({&Ctx.Idents.get("NSControl"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
301 ADD_UNARY_METHOD(NSControl, setStringValue, 0)NSControlM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setStringValue")), 0});
302
303 NEW_RECEIVER(NSAccessibility)llvm::DenseMap<Selector, uint8_t> &NSAccessibilityM
= UIMethods.insert({&Ctx.Idents.get("NSAccessibility"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
304 ADD_UNARY_METHOD(NSAccessibility, setAccessibilityValueDescription, 0)NSAccessibilityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setAccessibilityValueDescription")), 0});
305 ADD_UNARY_METHOD(NSAccessibility, setAccessibilityLabel, 0)NSAccessibilityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setAccessibilityLabel")), 0});
306 ADD_UNARY_METHOD(NSAccessibility, setAccessibilityTitle, 0)NSAccessibilityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setAccessibilityTitle")), 0});
307 ADD_UNARY_METHOD(NSAccessibility, setAccessibilityPlaceholderValue, 0)NSAccessibilityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setAccessibilityPlaceholderValue")), 0});
308 ADD_UNARY_METHOD(NSAccessibility, setAccessibilityHelp, 0)NSAccessibilityM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setAccessibilityHelp")), 0});
309
310 NEW_RECEIVER(NSMatrix)llvm::DenseMap<Selector, uint8_t> &NSMatrixM = UIMethods
.insert({&Ctx.Idents.get("NSMatrix"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
311 IdentifierInfo *setToolTipNSMatrix[] = {&Ctx.Idents.get("setToolTip"),
312 &Ctx.Idents.get("forCell")};
313 ADD_METHOD(NSMatrix, setToolTipNSMatrix, 2, 0)NSMatrixM.insert({Ctx.Selectors.getSelector(2, setToolTipNSMatrix
), 0});
314
315 NEW_RECEIVER(NSPrintPanel)llvm::DenseMap<Selector, uint8_t> &NSPrintPanelM = UIMethods
.insert({&Ctx.Idents.get("NSPrintPanel"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
316 ADD_UNARY_METHOD(NSPrintPanel, setDefaultButtonTitle, 0)NSPrintPanelM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setDefaultButtonTitle")), 0});
317
318 NEW_RECEIVER(UILocalNotification)llvm::DenseMap<Selector, uint8_t> &UILocalNotificationM
= UIMethods.insert({&Ctx.Idents.get("UILocalNotification"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
319 ADD_UNARY_METHOD(UILocalNotification, setAlertBody, 0)UILocalNotificationM.insert( {Ctx.Selectors.getUnarySelector(
&Ctx.Idents.get("setAlertBody")), 0});
320 ADD_UNARY_METHOD(UILocalNotification, setAlertAction, 0)UILocalNotificationM.insert( {Ctx.Selectors.getUnarySelector(
&Ctx.Idents.get("setAlertAction")), 0});
321 ADD_UNARY_METHOD(UILocalNotification, setAlertTitle, 0)UILocalNotificationM.insert( {Ctx.Selectors.getUnarySelector(
&Ctx.Idents.get("setAlertTitle")), 0});
322
323 NEW_RECEIVER(NSSlider)llvm::DenseMap<Selector, uint8_t> &NSSliderM = UIMethods
.insert({&Ctx.Idents.get("NSSlider"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
324 ADD_UNARY_METHOD(NSSlider, setTitle, 0)NSSliderM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setTitle")), 0});
325
326 NEW_RECEIVER(UIMenuItem)llvm::DenseMap<Selector, uint8_t> &UIMenuItemM = UIMethods
.insert({&Ctx.Idents.get("UIMenuItem"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
327 IdentifierInfo *initWithTitleUIMenuItem[] = {&Ctx.Idents.get("initWithTitle"),
328 &Ctx.Idents.get("action")};
329 ADD_METHOD(UIMenuItem, initWithTitleUIMenuItem, 2, 0)UIMenuItemM.insert({Ctx.Selectors.getSelector(2, initWithTitleUIMenuItem
), 0});
330 ADD_UNARY_METHOD(UIMenuItem, setTitle, 0)UIMenuItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setTitle")), 0});
331
332 NEW_RECEIVER(UIAlertController)llvm::DenseMap<Selector, uint8_t> &UIAlertControllerM
= UIMethods.insert({&Ctx.Idents.get("UIAlertController")
, llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
333 IdentifierInfo *alertControllerWithTitleUIAlertController[] = {
334 &Ctx.Idents.get("alertControllerWithTitle"), &Ctx.Idents.get("message"),
335 &Ctx.Idents.get("preferredStyle")};
336 ADD_METHOD(UIAlertController, alertControllerWithTitleUIAlertController, 3, 1)UIAlertControllerM.insert({Ctx.Selectors.getSelector(3, alertControllerWithTitleUIAlertController
), 1});
337 ADD_UNARY_METHOD(UIAlertController, setTitle, 0)UIAlertControllerM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
338 ADD_UNARY_METHOD(UIAlertController, setMessage, 0)UIAlertControllerM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setMessage")), 0});
339
340 NEW_RECEIVER(UIApplicationShortcutItem)llvm::DenseMap<Selector, uint8_t> &UIApplicationShortcutItemM
= UIMethods.insert({&Ctx.Idents.get("UIApplicationShortcutItem"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
341 IdentifierInfo *initWithTypeUIApplicationShortcutItemIcon[] = {
342 &Ctx.Idents.get("initWithType"), &Ctx.Idents.get("localizedTitle"),
343 &Ctx.Idents.get("localizedSubtitle"), &Ctx.Idents.get("icon"),
344 &Ctx.Idents.get("userInfo")};
345 ADD_METHOD(UIApplicationShortcutItem,UIApplicationShortcutItemM.insert({Ctx.Selectors.getSelector(
5, initWithTypeUIApplicationShortcutItemIcon), 1});
346 initWithTypeUIApplicationShortcutItemIcon, 5, 1)UIApplicationShortcutItemM.insert({Ctx.Selectors.getSelector(
5, initWithTypeUIApplicationShortcutItemIcon), 1});
347 IdentifierInfo *initWithTypeUIApplicationShortcutItem[] = {
348 &Ctx.Idents.get("initWithType"), &Ctx.Idents.get("localizedTitle")};
349 ADD_METHOD(UIApplicationShortcutItem, initWithTypeUIApplicationShortcutItem,UIApplicationShortcutItemM.insert({Ctx.Selectors.getSelector(
2, initWithTypeUIApplicationShortcutItem), 1});
350 2, 1)UIApplicationShortcutItemM.insert({Ctx.Selectors.getSelector(
2, initWithTypeUIApplicationShortcutItem), 1});
351
352 NEW_RECEIVER(UIActionSheet)llvm::DenseMap<Selector, uint8_t> &UIActionSheetM =
UIMethods.insert({&Ctx.Idents.get("UIActionSheet"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
353 IdentifierInfo *initWithTitleUIActionSheet[] = {
354 &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("delegate"),
355 &Ctx.Idents.get("cancelButtonTitle"),
356 &Ctx.Idents.get("destructiveButtonTitle"),
357 &Ctx.Idents.get("otherButtonTitles")};
358 ADD_METHOD(UIActionSheet, initWithTitleUIActionSheet, 5, 0)UIActionSheetM.insert({Ctx.Selectors.getSelector(5, initWithTitleUIActionSheet
), 0});
359 ADD_UNARY_METHOD(UIActionSheet, addButtonWithTitle, 0)UIActionSheetM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("addButtonWithTitle")), 0});
360 ADD_UNARY_METHOD(UIActionSheet, setTitle, 0)UIActionSheetM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
361
362 NEW_RECEIVER(UIAccessibilityCustomAction)llvm::DenseMap<Selector, uint8_t> &UIAccessibilityCustomActionM
= UIMethods.insert({&Ctx.Idents.get("UIAccessibilityCustomAction"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
363 IdentifierInfo *initWithNameUIAccessibilityCustomAction[] = {
364 &Ctx.Idents.get("initWithName"), &Ctx.Idents.get("target"),
365 &Ctx.Idents.get("selector")};
366 ADD_METHOD(UIAccessibilityCustomAction,UIAccessibilityCustomActionM.insert({Ctx.Selectors.getSelector
(3, initWithNameUIAccessibilityCustomAction), 0});
367 initWithNameUIAccessibilityCustomAction, 3, 0)UIAccessibilityCustomActionM.insert({Ctx.Selectors.getSelector
(3, initWithNameUIAccessibilityCustomAction), 0});
368 ADD_UNARY_METHOD(UIAccessibilityCustomAction, setName, 0)UIAccessibilityCustomActionM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setName")), 0});
369
370 NEW_RECEIVER(UISearchBar)llvm::DenseMap<Selector, uint8_t> &UISearchBarM = UIMethods
.insert({&Ctx.Idents.get("UISearchBar"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
371 ADD_UNARY_METHOD(UISearchBar, setText, 0)UISearchBarM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setText")), 0});
372 ADD_UNARY_METHOD(UISearchBar, setPrompt, 0)UISearchBarM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setPrompt")), 0});
373 ADD_UNARY_METHOD(UISearchBar, setPlaceholder, 0)UISearchBarM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setPlaceholder")), 0});
374
375 NEW_RECEIVER(UIBarItem)llvm::DenseMap<Selector, uint8_t> &UIBarItemM = UIMethods
.insert({&Ctx.Idents.get("UIBarItem"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
376 ADD_UNARY_METHOD(UIBarItem, setTitle, 0)UIBarItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setTitle")), 0});
377
378 NEW_RECEIVER(UITextView)llvm::DenseMap<Selector, uint8_t> &UITextViewM = UIMethods
.insert({&Ctx.Idents.get("UITextView"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
379 ADD_UNARY_METHOD(UITextView, setText, 0)UITextViewM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setText")), 0});
380
381 NEW_RECEIVER(NSView)llvm::DenseMap<Selector, uint8_t> &NSViewM = UIMethods
.insert({&Ctx.Idents.get("NSView"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
382 ADD_UNARY_METHOD(NSView, setToolTip, 0)NSViewM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setToolTip")), 0});
383
384 NEW_RECEIVER(NSTextField)llvm::DenseMap<Selector, uint8_t> &NSTextFieldM = UIMethods
.insert({&Ctx.Idents.get("NSTextField"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
385 ADD_UNARY_METHOD(NSTextField, setPlaceholderString, 0)NSTextFieldM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setPlaceholderString")), 0});
386 ADD_UNARY_METHOD(NSTextField, textFieldWithString, 0)NSTextFieldM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("textFieldWithString")), 0});
387 ADD_UNARY_METHOD(NSTextField, wrappingLabelWithString, 0)NSTextFieldM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("wrappingLabelWithString")), 0});
388 ADD_UNARY_METHOD(NSTextField, labelWithString, 0)NSTextFieldM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("labelWithString")), 0});
389
390 NEW_RECEIVER(NSAttributedString)llvm::DenseMap<Selector, uint8_t> &NSAttributedStringM
= UIMethods.insert({&Ctx.Idents.get("NSAttributedString"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
391 ADD_UNARY_METHOD(NSAttributedString, initWithString, 0)NSAttributedStringM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("initWithString")), 0});
392 IdentifierInfo *initWithStringNSAttributedString[] = {
393 &Ctx.Idents.get("initWithString"), &Ctx.Idents.get("attributes")};
394 ADD_METHOD(NSAttributedString, initWithStringNSAttributedString, 2, 0)NSAttributedStringM.insert({Ctx.Selectors.getSelector(2, initWithStringNSAttributedString
), 0});
395
396 NEW_RECEIVER(NSText)llvm::DenseMap<Selector, uint8_t> &NSTextM = UIMethods
.insert({&Ctx.Idents.get("NSText"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
397 ADD_UNARY_METHOD(NSText, setString, 0)NSTextM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setString")), 0});
398
399 NEW_RECEIVER(UIKeyCommand)llvm::DenseMap<Selector, uint8_t> &UIKeyCommandM = UIMethods
.insert({&Ctx.Idents.get("UIKeyCommand"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
400 IdentifierInfo *keyCommandWithInputUIKeyCommand[] = {
401 &Ctx.Idents.get("keyCommandWithInput"), &Ctx.Idents.get("modifierFlags"),
402 &Ctx.Idents.get("action"), &Ctx.Idents.get("discoverabilityTitle")};
403 ADD_METHOD(UIKeyCommand, keyCommandWithInputUIKeyCommand, 4, 3)UIKeyCommandM.insert({Ctx.Selectors.getSelector(4, keyCommandWithInputUIKeyCommand
), 3});
404 ADD_UNARY_METHOD(UIKeyCommand, setDiscoverabilityTitle, 0)UIKeyCommandM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setDiscoverabilityTitle")), 0});
405
406 NEW_RECEIVER(UILabel)llvm::DenseMap<Selector, uint8_t> &UILabelM = UIMethods
.insert({&Ctx.Idents.get("UILabel"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
407 ADD_UNARY_METHOD(UILabel, setText, 0)UILabelM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setText")), 0});
408
409 NEW_RECEIVER(NSAlert)llvm::DenseMap<Selector, uint8_t> &NSAlertM = UIMethods
.insert({&Ctx.Idents.get("NSAlert"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
410 IdentifierInfo *alertWithMessageTextNSAlert[] = {
411 &Ctx.Idents.get("alertWithMessageText"), &Ctx.Idents.get("defaultButton"),
412 &Ctx.Idents.get("alternateButton"), &Ctx.Idents.get("otherButton"),
413 &Ctx.Idents.get("informativeTextWithFormat")};
414 ADD_METHOD(NSAlert, alertWithMessageTextNSAlert, 5, 0)NSAlertM.insert({Ctx.Selectors.getSelector(5, alertWithMessageTextNSAlert
), 0});
415 ADD_UNARY_METHOD(NSAlert, addButtonWithTitle, 0)NSAlertM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("addButtonWithTitle")), 0});
416 ADD_UNARY_METHOD(NSAlert, setMessageText, 0)NSAlertM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setMessageText")), 0});
417 ADD_UNARY_METHOD(NSAlert, setInformativeText, 0)NSAlertM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setInformativeText")), 0});
418 ADD_UNARY_METHOD(NSAlert, setHelpAnchor, 0)NSAlertM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setHelpAnchor")), 0});
419
420 NEW_RECEIVER(UIMutableApplicationShortcutItem)llvm::DenseMap<Selector, uint8_t> &UIMutableApplicationShortcutItemM
= UIMethods.insert({&Ctx.Idents.get("UIMutableApplicationShortcutItem"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
421 ADD_UNARY_METHOD(UIMutableApplicationShortcutItem, setLocalizedTitle, 0)UIMutableApplicationShortcutItemM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setLocalizedTitle")), 0});
422 ADD_UNARY_METHOD(UIMutableApplicationShortcutItem, setLocalizedSubtitle, 0)UIMutableApplicationShortcutItemM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setLocalizedSubtitle")), 0});
423
424 NEW_RECEIVER(UIButton)llvm::DenseMap<Selector, uint8_t> &UIButtonM = UIMethods
.insert({&Ctx.Idents.get("UIButton"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
425 IdentifierInfo *setTitleUIButton[] = {&Ctx.Idents.get("setTitle"),
426 &Ctx.Idents.get("forState")};
427 ADD_METHOD(UIButton, setTitleUIButton, 2, 0)UIButtonM.insert({Ctx.Selectors.getSelector(2, setTitleUIButton
), 0});
428
429 NEW_RECEIVER(NSWindow)llvm::DenseMap<Selector, uint8_t> &NSWindowM = UIMethods
.insert({&Ctx.Idents.get("NSWindow"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
430 ADD_UNARY_METHOD(NSWindow, setTitle, 0)NSWindowM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setTitle")), 0});
431 IdentifierInfo *minFrameWidthWithTitleNSWindow[] = {
432 &Ctx.Idents.get("minFrameWidthWithTitle"), &Ctx.Idents.get("styleMask")};
433 ADD_METHOD(NSWindow, minFrameWidthWithTitleNSWindow, 2, 0)NSWindowM.insert({Ctx.Selectors.getSelector(2, minFrameWidthWithTitleNSWindow
), 0});
434 ADD_UNARY_METHOD(NSWindow, setMiniwindowTitle, 0)NSWindowM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setMiniwindowTitle")), 0});
435
436 NEW_RECEIVER(NSPathCell)llvm::DenseMap<Selector, uint8_t> &NSPathCellM = UIMethods
.insert({&Ctx.Idents.get("NSPathCell"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
437 ADD_UNARY_METHOD(NSPathCell, setPlaceholderString, 0)NSPathCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setPlaceholderString")), 0});
438
439 NEW_RECEIVER(UIDocumentMenuViewController)llvm::DenseMap<Selector, uint8_t> &UIDocumentMenuViewControllerM
= UIMethods.insert({&Ctx.Idents.get("UIDocumentMenuViewController"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
440 IdentifierInfo *addOptionWithTitleUIDocumentMenuViewController[] = {
441 &Ctx.Idents.get("addOptionWithTitle"), &Ctx.Idents.get("image"),
442 &Ctx.Idents.get("order"), &Ctx.Idents.get("handler")};
443 ADD_METHOD(UIDocumentMenuViewController,UIDocumentMenuViewControllerM.insert({Ctx.Selectors.getSelector
(4, addOptionWithTitleUIDocumentMenuViewController), 0});
444 addOptionWithTitleUIDocumentMenuViewController, 4, 0)UIDocumentMenuViewControllerM.insert({Ctx.Selectors.getSelector
(4, addOptionWithTitleUIDocumentMenuViewController), 0});
445
446 NEW_RECEIVER(UINavigationItem)llvm::DenseMap<Selector, uint8_t> &UINavigationItemM
= UIMethods.insert({&Ctx.Idents.get("UINavigationItem"),
llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
447 ADD_UNARY_METHOD(UINavigationItem, initWithTitle, 0)UINavigationItemM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("initWithTitle")), 0});
448 ADD_UNARY_METHOD(UINavigationItem, setTitle, 0)UINavigationItemM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
449 ADD_UNARY_METHOD(UINavigationItem, setPrompt, 0)UINavigationItemM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setPrompt")), 0});
450
451 NEW_RECEIVER(UIAlertView)llvm::DenseMap<Selector, uint8_t> &UIAlertViewM = UIMethods
.insert({&Ctx.Idents.get("UIAlertView"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
452 IdentifierInfo *initWithTitleUIAlertView[] = {
453 &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("message"),
454 &Ctx.Idents.get("delegate"), &Ctx.Idents.get("cancelButtonTitle"),
455 &Ctx.Idents.get("otherButtonTitles")};
456 ADD_METHOD(UIAlertView, initWithTitleUIAlertView, 5, 0)UIAlertViewM.insert({Ctx.Selectors.getSelector(5, initWithTitleUIAlertView
), 0});
457 ADD_UNARY_METHOD(UIAlertView, addButtonWithTitle, 0)UIAlertViewM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("addButtonWithTitle")), 0});
458 ADD_UNARY_METHOD(UIAlertView, setTitle, 0)UIAlertViewM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
459 ADD_UNARY_METHOD(UIAlertView, setMessage, 0)UIAlertViewM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setMessage")), 0});
460
461 NEW_RECEIVER(NSFormCell)llvm::DenseMap<Selector, uint8_t> &NSFormCellM = UIMethods
.insert({&Ctx.Idents.get("NSFormCell"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
462 ADD_UNARY_METHOD(NSFormCell, initTextCell, 0)NSFormCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("initTextCell")), 0});
463 ADD_UNARY_METHOD(NSFormCell, setTitle, 0)NSFormCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setTitle")), 0});
464 ADD_UNARY_METHOD(NSFormCell, setPlaceholderString, 0)NSFormCellM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setPlaceholderString")), 0});
465
466 NEW_RECEIVER(NSUserNotification)llvm::DenseMap<Selector, uint8_t> &NSUserNotificationM
= UIMethods.insert({&Ctx.Idents.get("NSUserNotification"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
467 ADD_UNARY_METHOD(NSUserNotification, setTitle, 0)NSUserNotificationM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
468 ADD_UNARY_METHOD(NSUserNotification, setSubtitle, 0)NSUserNotificationM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setSubtitle")), 0});
469 ADD_UNARY_METHOD(NSUserNotification, setInformativeText, 0)NSUserNotificationM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setInformativeText")), 0});
470 ADD_UNARY_METHOD(NSUserNotification, setActionButtonTitle, 0)NSUserNotificationM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setActionButtonTitle")), 0});
471 ADD_UNARY_METHOD(NSUserNotification, setOtherButtonTitle, 0)NSUserNotificationM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setOtherButtonTitle")), 0});
472 ADD_UNARY_METHOD(NSUserNotification, setResponsePlaceholder, 0)NSUserNotificationM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setResponsePlaceholder")), 0});
473
474 NEW_RECEIVER(NSToolbarItem)llvm::DenseMap<Selector, uint8_t> &NSToolbarItemM =
UIMethods.insert({&Ctx.Idents.get("NSToolbarItem"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
475 ADD_UNARY_METHOD(NSToolbarItem, setLabel, 0)NSToolbarItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setLabel")), 0});
476 ADD_UNARY_METHOD(NSToolbarItem, setPaletteLabel, 0)NSToolbarItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setPaletteLabel")), 0});
477 ADD_UNARY_METHOD(NSToolbarItem, setToolTip, 0)NSToolbarItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setToolTip")), 0});
478
479 NEW_RECEIVER(NSProgress)llvm::DenseMap<Selector, uint8_t> &NSProgressM = UIMethods
.insert({&Ctx.Idents.get("NSProgress"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
480 ADD_UNARY_METHOD(NSProgress, setLocalizedDescription, 0)NSProgressM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setLocalizedDescription")), 0});
481 ADD_UNARY_METHOD(NSProgress, setLocalizedAdditionalDescription, 0)NSProgressM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setLocalizedAdditionalDescription")), 0});
482
483 NEW_RECEIVER(NSSegmentedCell)llvm::DenseMap<Selector, uint8_t> &NSSegmentedCellM
= UIMethods.insert({&Ctx.Idents.get("NSSegmentedCell"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
484 IdentifierInfo *setLabelNSSegmentedCell[] = {&Ctx.Idents.get("setLabel"),
485 &Ctx.Idents.get("forSegment")};
486 ADD_METHOD(NSSegmentedCell, setLabelNSSegmentedCell, 2, 0)NSSegmentedCellM.insert({Ctx.Selectors.getSelector(2, setLabelNSSegmentedCell
), 0});
487 IdentifierInfo *setToolTipNSSegmentedCell[] = {&Ctx.Idents.get("setToolTip"),
488 &Ctx.Idents.get("forSegment")};
489 ADD_METHOD(NSSegmentedCell, setToolTipNSSegmentedCell, 2, 0)NSSegmentedCellM.insert({Ctx.Selectors.getSelector(2, setToolTipNSSegmentedCell
), 0});
490
491 NEW_RECEIVER(NSUndoManager)llvm::DenseMap<Selector, uint8_t> &NSUndoManagerM =
UIMethods.insert({&Ctx.Idents.get("NSUndoManager"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
492 ADD_UNARY_METHOD(NSUndoManager, setActionName, 0)NSUndoManagerM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setActionName")), 0});
493 ADD_UNARY_METHOD(NSUndoManager, undoMenuTitleForUndoActionName, 0)NSUndoManagerM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("undoMenuTitleForUndoActionName")), 0});
494 ADD_UNARY_METHOD(NSUndoManager, redoMenuTitleForUndoActionName, 0)NSUndoManagerM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("redoMenuTitleForUndoActionName")), 0});
495
496 NEW_RECEIVER(NSMenuItem)llvm::DenseMap<Selector, uint8_t> &NSMenuItemM = UIMethods
.insert({&Ctx.Idents.get("NSMenuItem"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
497 IdentifierInfo *initWithTitleNSMenuItem[] = {
498 &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("action"),
499 &Ctx.Idents.get("keyEquivalent")};
500 ADD_METHOD(NSMenuItem, initWithTitleNSMenuItem, 3, 0)NSMenuItemM.insert({Ctx.Selectors.getSelector(3, initWithTitleNSMenuItem
), 0});
501 ADD_UNARY_METHOD(NSMenuItem, setTitle, 0)NSMenuItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setTitle")), 0});
502 ADD_UNARY_METHOD(NSMenuItem, setToolTip, 0)NSMenuItemM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.
Idents.get("setToolTip")), 0});
503
504 NEW_RECEIVER(NSPopUpButtonCell)llvm::DenseMap<Selector, uint8_t> &NSPopUpButtonCellM
= UIMethods.insert({&Ctx.Idents.get("NSPopUpButtonCell")
, llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
505 IdentifierInfo *initTextCellNSPopUpButtonCell[] = {
506 &Ctx.Idents.get("initTextCell"), &Ctx.Idents.get("pullsDown")};
507 ADD_METHOD(NSPopUpButtonCell, initTextCellNSPopUpButtonCell, 2, 0)NSPopUpButtonCellM.insert({Ctx.Selectors.getSelector(2, initTextCellNSPopUpButtonCell
), 0});
508 ADD_UNARY_METHOD(NSPopUpButtonCell, addItemWithTitle, 0)NSPopUpButtonCellM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("addItemWithTitle")), 0});
509 IdentifierInfo *insertItemWithTitleNSPopUpButtonCell[] = {
510 &Ctx.Idents.get("insertItemWithTitle"), &Ctx.Idents.get("atIndex")};
511 ADD_METHOD(NSPopUpButtonCell, insertItemWithTitleNSPopUpButtonCell, 2, 0)NSPopUpButtonCellM.insert({Ctx.Selectors.getSelector(2, insertItemWithTitleNSPopUpButtonCell
), 0});
512 ADD_UNARY_METHOD(NSPopUpButtonCell, removeItemWithTitle, 0)NSPopUpButtonCellM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("removeItemWithTitle")), 0});
513 ADD_UNARY_METHOD(NSPopUpButtonCell, selectItemWithTitle, 0)NSPopUpButtonCellM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("selectItemWithTitle")), 0});
514 ADD_UNARY_METHOD(NSPopUpButtonCell, setTitle, 0)NSPopUpButtonCellM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
515
516 NEW_RECEIVER(NSViewController)llvm::DenseMap<Selector, uint8_t> &NSViewControllerM
= UIMethods.insert({&Ctx.Idents.get("NSViewController"),
llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
517 ADD_UNARY_METHOD(NSViewController, setTitle, 0)NSViewControllerM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
518
519 NEW_RECEIVER(NSMenu)llvm::DenseMap<Selector, uint8_t> &NSMenuM = UIMethods
.insert({&Ctx.Idents.get("NSMenu"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
520 ADD_UNARY_METHOD(NSMenu, initWithTitle, 0)NSMenuM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("initWithTitle")), 0});
521 IdentifierInfo *insertItemWithTitleNSMenu[] = {
522 &Ctx.Idents.get("insertItemWithTitle"), &Ctx.Idents.get("action"),
523 &Ctx.Idents.get("keyEquivalent"), &Ctx.Idents.get("atIndex")};
524 ADD_METHOD(NSMenu, insertItemWithTitleNSMenu, 4, 0)NSMenuM.insert({Ctx.Selectors.getSelector(4, insertItemWithTitleNSMenu
), 0});
525 IdentifierInfo *addItemWithTitleNSMenu[] = {
526 &Ctx.Idents.get("addItemWithTitle"), &Ctx.Idents.get("action"),
527 &Ctx.Idents.get("keyEquivalent")};
528 ADD_METHOD(NSMenu, addItemWithTitleNSMenu, 3, 0)NSMenuM.insert({Ctx.Selectors.getSelector(3, addItemWithTitleNSMenu
), 0});
529 ADD_UNARY_METHOD(NSMenu, setTitle, 0)NSMenuM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("setTitle")), 0});
530
531 NEW_RECEIVER(UIMutableUserNotificationAction)llvm::DenseMap<Selector, uint8_t> &UIMutableUserNotificationActionM
= UIMethods.insert({&Ctx.Idents.get("UIMutableUserNotificationAction"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
532 ADD_UNARY_METHOD(UIMutableUserNotificationAction, setTitle, 0)UIMutableUserNotificationActionM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setTitle")), 0});
533
534 NEW_RECEIVER(NSForm)llvm::DenseMap<Selector, uint8_t> &NSFormM = UIMethods
.insert({&Ctx.Idents.get("NSForm"), llvm::DenseMap<Selector
, uint8_t>()}) .first->second;
535 ADD_UNARY_METHOD(NSForm, addEntry, 0)NSFormM.insert( {Ctx.Selectors.getUnarySelector(&Ctx.Idents
.get("addEntry")), 0});
536 IdentifierInfo *insertEntryNSForm[] = {&Ctx.Idents.get("insertEntry"),
537 &Ctx.Idents.get("atIndex")};
538 ADD_METHOD(NSForm, insertEntryNSForm, 2, 0)NSFormM.insert({Ctx.Selectors.getSelector(2, insertEntryNSForm
), 0});
539
540 NEW_RECEIVER(NSTextFieldCell)llvm::DenseMap<Selector, uint8_t> &NSTextFieldCellM
= UIMethods.insert({&Ctx.Idents.get("NSTextFieldCell"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
541 ADD_UNARY_METHOD(NSTextFieldCell, setPlaceholderString, 0)NSTextFieldCellM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setPlaceholderString")), 0});
542
543 NEW_RECEIVER(NSUserNotificationAction)llvm::DenseMap<Selector, uint8_t> &NSUserNotificationActionM
= UIMethods.insert({&Ctx.Idents.get("NSUserNotificationAction"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
544 IdentifierInfo *actionWithIdentifierNSUserNotificationAction[] = {
545 &Ctx.Idents.get("actionWithIdentifier"), &Ctx.Idents.get("title")};
546 ADD_METHOD(NSUserNotificationAction,NSUserNotificationActionM.insert({Ctx.Selectors.getSelector(2
, actionWithIdentifierNSUserNotificationAction), 1});
547 actionWithIdentifierNSUserNotificationAction, 2, 1)NSUserNotificationActionM.insert({Ctx.Selectors.getSelector(2
, actionWithIdentifierNSUserNotificationAction), 1});
548
549 NEW_RECEIVER(UITextField)llvm::DenseMap<Selector, uint8_t> &UITextFieldM = UIMethods
.insert({&Ctx.Idents.get("UITextField"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
550 ADD_UNARY_METHOD(UITextField, setText, 0)UITextFieldM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setText")), 0});
551 ADD_UNARY_METHOD(UITextField, setPlaceholder, 0)UITextFieldM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setPlaceholder")), 0});
552
553 NEW_RECEIVER(UIBarButtonItem)llvm::DenseMap<Selector, uint8_t> &UIBarButtonItemM
= UIMethods.insert({&Ctx.Idents.get("UIBarButtonItem"), llvm
::DenseMap<Selector, uint8_t>()}) .first->second;
554 IdentifierInfo *initWithTitleUIBarButtonItem[] = {
555 &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("style"),
556 &Ctx.Idents.get("target"), &Ctx.Idents.get("action")};
557 ADD_METHOD(UIBarButtonItem, initWithTitleUIBarButtonItem, 4, 0)UIBarButtonItemM.insert({Ctx.Selectors.getSelector(4, initWithTitleUIBarButtonItem
), 0});
558
559 NEW_RECEIVER(UIViewController)llvm::DenseMap<Selector, uint8_t> &UIViewControllerM
= UIMethods.insert({&Ctx.Idents.get("UIViewController"),
llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
560 ADD_UNARY_METHOD(UIViewController, setTitle, 0)UIViewControllerM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
561
562 NEW_RECEIVER(UISegmentedControl)llvm::DenseMap<Selector, uint8_t> &UISegmentedControlM
= UIMethods.insert({&Ctx.Idents.get("UISegmentedControl"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
563 IdentifierInfo *insertSegmentWithTitleUISegmentedControl[] = {
564 &Ctx.Idents.get("insertSegmentWithTitle"), &Ctx.Idents.get("atIndex"),
565 &Ctx.Idents.get("animated")};
566 ADD_METHOD(UISegmentedControl, insertSegmentWithTitleUISegmentedControl, 3, 0)UISegmentedControlM.insert({Ctx.Selectors.getSelector(3, insertSegmentWithTitleUISegmentedControl
), 0});
567 IdentifierInfo *setTitleUISegmentedControl[] = {
568 &Ctx.Idents.get("setTitle"), &Ctx.Idents.get("forSegmentAtIndex")};
569 ADD_METHOD(UISegmentedControl, setTitleUISegmentedControl, 2, 0)UISegmentedControlM.insert({Ctx.Selectors.getSelector(2, setTitleUISegmentedControl
), 0});
570
571 NEW_RECEIVER(NSAccessibilityCustomRotorItemResult)llvm::DenseMap<Selector, uint8_t> &NSAccessibilityCustomRotorItemResultM
= UIMethods.insert({&Ctx.Idents.get("NSAccessibilityCustomRotorItemResult"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
572 IdentifierInfo
573 *initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult[] = {
574 &Ctx.Idents.get("initWithItemLoadingToken"),
575 &Ctx.Idents.get("customLabel")};
576 ADD_METHOD(NSAccessibilityCustomRotorItemResult,NSAccessibilityCustomRotorItemResultM.insert({Ctx.Selectors.getSelector
(2, initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult
), 1});
577 initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult, 2, 1)NSAccessibilityCustomRotorItemResultM.insert({Ctx.Selectors.getSelector
(2, initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult
), 1});
578 ADD_UNARY_METHOD(NSAccessibilityCustomRotorItemResult, setCustomLabel, 0)NSAccessibilityCustomRotorItemResultM.insert( {Ctx.Selectors.
getUnarySelector(&Ctx.Idents.get("setCustomLabel")), 0});
579
580 NEW_RECEIVER(UIContextualAction)llvm::DenseMap<Selector, uint8_t> &UIContextualActionM
= UIMethods.insert({&Ctx.Idents.get("UIContextualAction"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
581 IdentifierInfo *contextualActionWithStyleUIContextualAction[] = {
582 &Ctx.Idents.get("contextualActionWithStyle"), &Ctx.Idents.get("title"),
583 &Ctx.Idents.get("handler")};
584 ADD_METHOD(UIContextualAction, contextualActionWithStyleUIContextualAction, 3,UIContextualActionM.insert({Ctx.Selectors.getSelector(3, contextualActionWithStyleUIContextualAction
), 1});
585 1)UIContextualActionM.insert({Ctx.Selectors.getSelector(3, contextualActionWithStyleUIContextualAction
), 1});
586 ADD_UNARY_METHOD(UIContextualAction, setTitle, 0)UIContextualActionM.insert( {Ctx.Selectors.getUnarySelector(&
Ctx.Idents.get("setTitle")), 0});
587
588 NEW_RECEIVER(NSAccessibilityCustomRotor)llvm::DenseMap<Selector, uint8_t> &NSAccessibilityCustomRotorM
= UIMethods.insert({&Ctx.Idents.get("NSAccessibilityCustomRotor"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
589 IdentifierInfo *initWithLabelNSAccessibilityCustomRotor[] = {
590 &Ctx.Idents.get("initWithLabel"), &Ctx.Idents.get("itemSearchDelegate")};
591 ADD_METHOD(NSAccessibilityCustomRotor,NSAccessibilityCustomRotorM.insert({Ctx.Selectors.getSelector
(2, initWithLabelNSAccessibilityCustomRotor), 0});
592 initWithLabelNSAccessibilityCustomRotor, 2, 0)NSAccessibilityCustomRotorM.insert({Ctx.Selectors.getSelector
(2, initWithLabelNSAccessibilityCustomRotor), 0});
593 ADD_UNARY_METHOD(NSAccessibilityCustomRotor, setLabel, 0)NSAccessibilityCustomRotorM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setLabel")), 0});
594
595 NEW_RECEIVER(NSWindowTab)llvm::DenseMap<Selector, uint8_t> &NSWindowTabM = UIMethods
.insert({&Ctx.Idents.get("NSWindowTab"), llvm::DenseMap<
Selector, uint8_t>()}) .first->second;
596 ADD_UNARY_METHOD(NSWindowTab, setTitle, 0)NSWindowTabM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setTitle")), 0});
597 ADD_UNARY_METHOD(NSWindowTab, setToolTip, 0)NSWindowTabM.insert( {Ctx.Selectors.getUnarySelector(&Ctx
.Idents.get("setToolTip")), 0});
598
599 NEW_RECEIVER(NSAccessibilityCustomAction)llvm::DenseMap<Selector, uint8_t> &NSAccessibilityCustomActionM
= UIMethods.insert({&Ctx.Idents.get("NSAccessibilityCustomAction"
), llvm::DenseMap<Selector, uint8_t>()}) .first->second
;
600 IdentifierInfo *initWithNameNSAccessibilityCustomAction[] = {
601 &Ctx.Idents.get("initWithName"), &Ctx.Idents.get("handler")};
602 ADD_METHOD(NSAccessibilityCustomAction,NSAccessibilityCustomActionM.insert({Ctx.Selectors.getSelector
(2, initWithNameNSAccessibilityCustomAction), 0});
603 initWithNameNSAccessibilityCustomAction, 2, 0)NSAccessibilityCustomActionM.insert({Ctx.Selectors.getSelector
(2, initWithNameNSAccessibilityCustomAction), 0});
604 IdentifierInfo *initWithNameTargetNSAccessibilityCustomAction[] = {
605 &Ctx.Idents.get("initWithName"), &Ctx.Idents.get("target"),
606 &Ctx.Idents.get("selector")};
607 ADD_METHOD(NSAccessibilityCustomAction,NSAccessibilityCustomActionM.insert({Ctx.Selectors.getSelector
(3, initWithNameTargetNSAccessibilityCustomAction), 0});
608 initWithNameTargetNSAccessibilityCustomAction, 3, 0)NSAccessibilityCustomActionM.insert({Ctx.Selectors.getSelector
(3, initWithNameTargetNSAccessibilityCustomAction), 0});
609 ADD_UNARY_METHOD(NSAccessibilityCustomAction, setName, 0)NSAccessibilityCustomActionM.insert( {Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get("setName")), 0});
610}
611
612#define LSF_INSERT(function_name)LSF.insert(&Ctx.Idents.get(function_name)); LSF.insert(&Ctx.Idents.get(function_name));
613#define LSM_INSERT_NULLARY(receiver, method_name)LSM.insert({&Ctx.Idents.get(receiver), Ctx.Selectors.getNullarySelector
( &Ctx.Idents.get(method_name))});
\
614 LSM.insert({&Ctx.Idents.get(receiver), Ctx.Selectors.getNullarySelector( \
615 &Ctx.Idents.get(method_name))});
616#define LSM_INSERT_UNARY(receiver, method_name)LSM.insert({&Ctx.Idents.get(receiver), Ctx.Selectors.getUnarySelector
(&Ctx.Idents.get(method_name))});
\
617 LSM.insert({&Ctx.Idents.get(receiver), \
618 Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(method_name))});
619#define LSM_INSERT_SELECTOR(receiver, method_list, arguments)LSM.insert({&Ctx.Idents.get(receiver), Ctx.Selectors.getSelector
(arguments, method_list)});
\
620 LSM.insert({&Ctx.Idents.get(receiver), \
621 Ctx.Selectors.getSelector(arguments, method_list)});
622
623/// Initializes a list of methods and C functions that return a localized string
624void NonLocalizedStringChecker::initLocStringsMethods(ASTContext &Ctx) const {
625 if (!LSM.empty())
626 return;
627
628 IdentifierInfo *LocalizedStringMacro[] = {
629 &Ctx.Idents.get("localizedStringForKey"), &Ctx.Idents.get("value"),
630 &Ctx.Idents.get("table")};
631 LSM_INSERT_SELECTOR("NSBundle", LocalizedStringMacro, 3)LSM.insert({&Ctx.Idents.get("NSBundle"), Ctx.Selectors.getSelector
(3, LocalizedStringMacro)});
632 LSM_INSERT_UNARY("NSDateFormatter", "stringFromDate")LSM.insert({&Ctx.Idents.get("NSDateFormatter"), Ctx.Selectors
.getUnarySelector(&Ctx.Idents.get("stringFromDate"))});
633 IdentifierInfo *LocalizedStringFromDate[] = {
634 &Ctx.Idents.get("localizedStringFromDate"), &Ctx.Idents.get("dateStyle"),
635 &Ctx.Idents.get("timeStyle")};
636 LSM_INSERT_SELECTOR("NSDateFormatter", LocalizedStringFromDate, 3)LSM.insert({&Ctx.Idents.get("NSDateFormatter"), Ctx.Selectors
.getSelector(3, LocalizedStringFromDate)});
637 LSM_INSERT_UNARY("NSNumberFormatter", "stringFromNumber")LSM.insert({&Ctx.Idents.get("NSNumberFormatter"), Ctx.Selectors
.getUnarySelector(&Ctx.Idents.get("stringFromNumber"))});
638 LSM_INSERT_NULLARY("UITextField", "text")LSM.insert({&Ctx.Idents.get("UITextField"), Ctx.Selectors
.getNullarySelector( &Ctx.Idents.get("text"))});
639 LSM_INSERT_NULLARY("UITextView", "text")LSM.insert({&Ctx.Idents.get("UITextView"), Ctx.Selectors.
getNullarySelector( &Ctx.Idents.get("text"))});
640 LSM_INSERT_NULLARY("UILabel", "text")LSM.insert({&Ctx.Idents.get("UILabel"), Ctx.Selectors.getNullarySelector
( &Ctx.Idents.get("text"))});
641
642 LSF_INSERT("CFDateFormatterCreateStringWithDate")LSF.insert(&Ctx.Idents.get("CFDateFormatterCreateStringWithDate"
));
;
643 LSF_INSERT("CFDateFormatterCreateStringWithAbsoluteTime")LSF.insert(&Ctx.Idents.get("CFDateFormatterCreateStringWithAbsoluteTime"
));
;
644 LSF_INSERT("CFNumberFormatterCreateStringWithNumber")LSF.insert(&Ctx.Idents.get("CFNumberFormatterCreateStringWithNumber"
));
;
645}
646
647/// Checks to see if the method / function declaration includes
648/// __attribute__((annotate("returns_localized_nsstring")))
649bool NonLocalizedStringChecker::isAnnotatedAsReturningLocalized(
650 const Decl *D) const {
651 if (!D)
652 return false;
653 return std::any_of(
654 D->specific_attr_begin<AnnotateAttr>(),
655 D->specific_attr_end<AnnotateAttr>(), [](const AnnotateAttr *Ann) {
656 return Ann->getAnnotation() == "returns_localized_nsstring";
657 });
658}
659
660/// Checks to see if the method / function declaration includes
661/// __attribute__((annotate("takes_localized_nsstring")))
662bool NonLocalizedStringChecker::isAnnotatedAsTakingLocalized(
663 const Decl *D) const {
664 if (!D)
665 return false;
666 return std::any_of(
667 D->specific_attr_begin<AnnotateAttr>(),
668 D->specific_attr_end<AnnotateAttr>(), [](const AnnotateAttr *Ann) {
669 return Ann->getAnnotation() == "takes_localized_nsstring";
670 });
671}
672
673/// Returns true if the given SVal is marked as Localized in the program state
674bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
675 CheckerContext &C) const {
676 const MemRegion *mt = S.getAsRegion();
677 if (mt) {
678 const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);
679 if (LS && LS->isLocalized())
680 return true;
681 }
682 return false;
683}
684
685/// Returns true if the given SVal is marked as NonLocalized in the program
686/// state
687bool NonLocalizedStringChecker::hasNonLocalizedState(SVal S,
688 CheckerContext &C) const {
689 const MemRegion *mt = S.getAsRegion();
690 if (mt) {
691 const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);
692 if (LS && LS->isNonLocalized())
693 return true;
694 }
695 return false;
696}
697
698/// Marks the given SVal as Localized in the program state
699void NonLocalizedStringChecker::setLocalizedState(const SVal S,
700 CheckerContext &C) const {
701 const MemRegion *mt = S.getAsRegion();
702 if (mt) {
703 ProgramStateRef State =
704 C.getState()->set<LocalizedMemMap>(mt, LocalizedState::getLocalized());
705 C.addTransition(State);
706 }
707}
708
709/// Marks the given SVal as NonLocalized in the program state
710void NonLocalizedStringChecker::setNonLocalizedState(const SVal S,
711 CheckerContext &C) const {
712 const MemRegion *mt = S.getAsRegion();
713 if (mt) {
714 ProgramStateRef State = C.getState()->set<LocalizedMemMap>(
715 mt, LocalizedState::getNonLocalized());
716 C.addTransition(State);
717 }
718}
719
720
721static bool isDebuggingName(std::string name) {
722 return StringRef(name).lower().find("debug") != StringRef::npos;
723}
724
725/// Returns true when, heuristically, the analyzer may be analyzing debugging
726/// code. We use this to suppress localization diagnostics in un-localized user
727/// interfaces that are only used for debugging and are therefore not user
728/// facing.
729static bool isDebuggingContext(CheckerContext &C) {
730 const Decl *D = C.getCurrentAnalysisDeclContext()->getDecl();
731 if (!D)
732 return false;
733
734 if (auto *ND = dyn_cast<NamedDecl>(D)) {
735 if (isDebuggingName(ND->getNameAsString()))
736 return true;
737 }
738
739 const DeclContext *DC = D->getDeclContext();
740
741 if (auto *CD = dyn_cast<ObjCContainerDecl>(DC)) {
742 if (isDebuggingName(CD->getNameAsString()))
743 return true;
744 }
745
746 return false;
747}
748
749
750/// Reports a localization error for the passed in method call and SVal
751void NonLocalizedStringChecker::reportLocalizationError(
752 SVal S, const CallEvent &M, CheckerContext &C, int argumentNumber) const {
753
754 // Don't warn about localization errors in classes and methods that
755 // may be debug code.
756 if (isDebuggingContext(C))
757 return;
758
759 ExplodedNode *ErrNode = C.getPredecessor();
760 static CheckerProgramPointTag Tag("NonLocalizedStringChecker",
761 "UnlocalizedString");
762 ErrNode = C.addTransition(C.getState(), C.getPredecessor(), &Tag);
763
764 if (!ErrNode)
765 return;
766
767 // Generate the bug report.
768 std::unique_ptr<BugReport> R(new BugReport(
769 *BT, "User-facing text should use localized string macro", ErrNode));
770 if (argumentNumber) {
771 R->addRange(M.getArgExpr(argumentNumber - 1)->getSourceRange());
772 } else {
773 R->addRange(M.getSourceRange());
774 }
775 R->markInteresting(S);
776
777 const MemRegion *StringRegion = S.getAsRegion();
778 if (StringRegion)
779 R->addVisitor(llvm::make_unique<NonLocalizedStringBRVisitor>(StringRegion));
780
781 C.emitReport(std::move(R));
782}
783
784/// Returns the argument number requiring localized string if it exists
785/// otherwise, returns -1
786int NonLocalizedStringChecker::getLocalizedArgumentForSelector(
787 const IdentifierInfo *Receiver, Selector S) const {
788 auto method = UIMethods.find(Receiver);
789
790 if (method == UIMethods.end())
791 return -1;
792
793 auto argumentIterator = method->getSecond().find(S);
794
795 if (argumentIterator == method->getSecond().end())
796 return -1;
797
798 int argumentNumber = argumentIterator->getSecond();
799 return argumentNumber;
800}
801
802/// Check if the string being passed in has NonLocalized state
803void NonLocalizedStringChecker::checkPreObjCMessage(const ObjCMethodCall &msg,
804 CheckerContext &C) const {
805 initUIMethods(C.getASTContext());
806
807 const ObjCInterfaceDecl *OD = msg.getReceiverInterface();
808 if (!OD)
809 return;
810 const IdentifierInfo *odInfo = OD->getIdentifier();
811
812 Selector S = msg.getSelector();
813
814 std::string SelectorString = S.getAsString();
815 StringRef SelectorName = SelectorString;
816 assert(!SelectorName.empty())(static_cast <bool> (!SelectorName.empty()) ? void (0) :
__assert_fail ("!SelectorName.empty()", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp"
, 816, __extension__ __PRETTY_FUNCTION__))
;
817
818 if (odInfo->isStr("NSString")) {
819 // Handle the case where the receiver is an NSString
820 // These special NSString methods draw to the screen
821
822 if (!(SelectorName.startswith("drawAtPoint") ||
823 SelectorName.startswith("drawInRect") ||
824 SelectorName.startswith("drawWithRect")))
825 return;
826
827 SVal svTitle = msg.getReceiverSVal();
828
829 bool isNonLocalized = hasNonLocalizedState(svTitle, C);
830
831 if (isNonLocalized) {
832 reportLocalizationError(svTitle, msg, C);
833 }
834 }
835
836 int argumentNumber = getLocalizedArgumentForSelector(odInfo, S);
837 // Go up each hierarchy of superclasses and their protocols
838 while (argumentNumber < 0 && OD->getSuperClass() != nullptr) {
839 for (const auto *P : OD->all_referenced_protocols()) {
840 argumentNumber = getLocalizedArgumentForSelector(P->getIdentifier(), S);
841 if (argumentNumber >= 0)
842 break;
843 }
844 if (argumentNumber < 0) {
845 OD = OD->getSuperClass();
846 argumentNumber = getLocalizedArgumentForSelector(OD->getIdentifier(), S);
847 }
848 }
849
850 if (argumentNumber < 0) { // There was no match in UIMethods
851 if (const Decl *D = msg.getDecl()) {
852 if (const ObjCMethodDecl *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
853 auto formals = OMD->parameters();
854 for (unsigned i = 0, ei = formals.size(); i != ei; ++i) {
855 if (isAnnotatedAsTakingLocalized(formals[i])) {
856 argumentNumber = i;
857 break;
858 }
859 }
860 }
861 }
862 }
863
864 if (argumentNumber < 0) // Still no match
865 return;
866
867 SVal svTitle = msg.getArgSVal(argumentNumber);
868
869 if (const ObjCStringRegion *SR =
870 dyn_cast_or_null<ObjCStringRegion>(svTitle.getAsRegion())) {
871 StringRef stringValue =
872 SR->getObjCStringLiteral()->getString()->getString();
873 if ((stringValue.trim().size() == 0 && stringValue.size() > 0) ||
874 stringValue.empty())
875 return;
876 if (!IsAggressive && llvm::sys::unicode::columnWidthUTF8(stringValue) < 2)
877 return;
878 }
879
880 bool isNonLocalized = hasNonLocalizedState(svTitle, C);
881
882 if (isNonLocalized) {
883 reportLocalizationError(svTitle, msg, C, argumentNumber + 1);
884 }
885}
886
887void NonLocalizedStringChecker::checkPreCall(const CallEvent &Call,
888 CheckerContext &C) const {
889 const Decl *D = Call.getDecl();
890 if (D && isa<FunctionDecl>(D)) {
891 const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
892 auto formals = FD->parameters();
893 for (unsigned i = 0,
894 ei = std::min(unsigned(formals.size()), Call.getNumArgs());
895 i != ei; ++i) {
896 if (isAnnotatedAsTakingLocalized(formals[i])) {
897 auto actual = Call.getArgSVal(i);
898 if (hasNonLocalizedState(actual, C)) {
899 reportLocalizationError(actual, Call, C, i + 1);
900 }
901 }
902 }
903 }
904}
905
906static inline bool isNSStringType(QualType T, ASTContext &Ctx) {
907
908 const ObjCObjectPointerType *PT = T->getAs<ObjCObjectPointerType>();
909 if (!PT)
910 return false;
911
912 ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface();
913 if (!Cls)
914 return false;
915
916 IdentifierInfo *ClsName = Cls->getIdentifier();
917
918 // FIXME: Should we walk the chain of classes?
919 return ClsName == &Ctx.Idents.get("NSString") ||
920 ClsName == &Ctx.Idents.get("NSMutableString");
921}
922
923/// Marks a string being returned by any call as localized
924/// if it is in LocStringFunctions (LSF) or the function is annotated.
925/// Otherwise, we mark it as NonLocalized (Aggressive) or
926/// NonLocalized only if it is not backed by a SymRegion (Non-Aggressive),
927/// basically leaving only string literals as NonLocalized.
928void NonLocalizedStringChecker::checkPostCall(const CallEvent &Call,
929 CheckerContext &C) const {
930 initLocStringsMethods(C.getASTContext());
931
932 if (!Call.getOriginExpr())
933 return;
934
935 // Anything that takes in a localized NSString as an argument
936 // and returns an NSString will be assumed to be returning a
937 // localized NSString. (Counter: Incorrectly combining two LocalizedStrings)
938 const QualType RT = Call.getResultType();
939 if (isNSStringType(RT, C.getASTContext())) {
940 for (unsigned i = 0; i < Call.getNumArgs(); ++i) {
941 SVal argValue = Call.getArgSVal(i);
942 if (hasLocalizedState(argValue, C)) {
943 SVal sv = Call.getReturnValue();
944 setLocalizedState(sv, C);
945 return;
946 }
947 }
948 }
949
950 const Decl *D = Call.getDecl();
951 if (!D)
952 return;
953
954 const IdentifierInfo *Identifier = Call.getCalleeIdentifier();
955
956 SVal sv = Call.getReturnValue();
957 if (isAnnotatedAsReturningLocalized(D) || LSF.count(Identifier) != 0) {
958 setLocalizedState(sv, C);
959 } else if (isNSStringType(RT, C.getASTContext()) &&
960 !hasLocalizedState(sv, C)) {
961 if (IsAggressive) {
962 setNonLocalizedState(sv, C);
963 } else {
964 const SymbolicRegion *SymReg =
965 dyn_cast_or_null<SymbolicRegion>(sv.getAsRegion());
966 if (!SymReg)
967 setNonLocalizedState(sv, C);
968 }
969 }
970}
971
972/// Marks a string being returned by an ObjC method as localized
973/// if it is in LocStringMethods or the method is annotated
974void NonLocalizedStringChecker::checkPostObjCMessage(const ObjCMethodCall &msg,
975 CheckerContext &C) const {
976 initLocStringsMethods(C.getASTContext());
977
978 if (!msg.isInstanceMessage())
979 return;
980
981 const ObjCInterfaceDecl *OD = msg.getReceiverInterface();
982 if (!OD)
983 return;
984 const IdentifierInfo *odInfo = OD->getIdentifier();
985
986 Selector S = msg.getSelector();
987 std::string SelectorName = S.getAsString();
988
989 std::pair<const IdentifierInfo *, Selector> MethodDescription = {odInfo, S};
990
991 if (LSM.count(MethodDescription) ||
992 isAnnotatedAsReturningLocalized(msg.getDecl())) {
993 SVal sv = msg.getReturnValue();
994 setLocalizedState(sv, C);
995 }
996}
997
998/// Marks all empty string literals as localized
999void NonLocalizedStringChecker::checkPostStmt(const ObjCStringLiteral *SL,
1000 CheckerContext &C) const {
1001 SVal sv = C.getSVal(SL);
1002 setNonLocalizedState(sv, C);
1003}
1004
1005std::shared_ptr<PathDiagnosticPiece>
1006NonLocalizedStringBRVisitor::VisitNode(const ExplodedNode *Succ,
1007 const ExplodedNode *Pred,
1008 BugReporterContext &BRC, BugReport &BR) {
1009 if (Satisfied)
1010 return nullptr;
1011
1012 Optional<StmtPoint> Point = Succ->getLocation().getAs<StmtPoint>();
1013 if (!Point.hasValue())
1014 return nullptr;
1015
1016 auto *LiteralExpr = dyn_cast<ObjCStringLiteral>(Point->getStmt());
1017 if (!LiteralExpr)
1018 return nullptr;
1019
1020 SVal LiteralSVal = Succ->getSVal(LiteralExpr);
1021 if (LiteralSVal.getAsRegion() != NonLocalizedString)
1022 return nullptr;
1023
1024 Satisfied = true;
1025
1026 PathDiagnosticLocation L =
1027 PathDiagnosticLocation::create(*Point, BRC.getSourceManager());
1028
1029 if (!L.isValid() || !L.asLocation().isValid())
1030 return nullptr;
1031
1032 auto Piece = std::make_shared<PathDiagnosticEventPiece>(
1033 L, "Non-localized string literal here");
1034 Piece->addRange(LiteralExpr->getSourceRange());
1035
1036 return std::move(Piece);
1037}
1038
1039namespace {
1040class EmptyLocalizationContextChecker
1041 : public Checker<check::ASTDecl<ObjCImplementationDecl>> {
1042
1043 // A helper class, which walks the AST
1044 class MethodCrawler : public ConstStmtVisitor<MethodCrawler> {
1045 const ObjCMethodDecl *MD;
1046 BugReporter &BR;
1047 AnalysisManager &Mgr;
1048 const CheckerBase *Checker;
1049 LocationOrAnalysisDeclContext DCtx;
1050
1051 public:
1052 MethodCrawler(const ObjCMethodDecl *InMD, BugReporter &InBR,
1053 const CheckerBase *Checker, AnalysisManager &InMgr,
1054 AnalysisDeclContext *InDCtx)
1055 : MD(InMD), BR(InBR), Mgr(InMgr), Checker(Checker), DCtx(InDCtx) {}
1056
1057 void VisitStmt(const Stmt *S) { VisitChildren(S); }
1058
1059 void VisitObjCMessageExpr(const ObjCMessageExpr *ME);
1060
1061 void reportEmptyContextError(const ObjCMessageExpr *M) const;
1062
1063 void VisitChildren(const Stmt *S) {
1064 for (const Stmt *Child : S->children()) {
1065 if (Child)
1066 this->Visit(Child);
1067 }
1068 }
1069 };
1070
1071public:
1072 void checkASTDecl(const ObjCImplementationDecl *D, AnalysisManager &Mgr,
1073 BugReporter &BR) const;
1074};
1075} // end anonymous namespace
1076
1077void EmptyLocalizationContextChecker::checkASTDecl(
1078 const ObjCImplementationDecl *D, AnalysisManager &Mgr,
1079 BugReporter &BR) const {
1080
1081 for (const ObjCMethodDecl *M : D->methods()) {
1082 AnalysisDeclContext *DCtx = Mgr.getAnalysisDeclContext(M);
1083
1084 const Stmt *Body = M->getBody();
1085 assert(Body)(static_cast <bool> (Body) ? void (0) : __assert_fail (
"Body", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp"
, 1085, __extension__ __PRETTY_FUNCTION__))
;
1086
1087 MethodCrawler MC(M->getCanonicalDecl(), BR, this, Mgr, DCtx);
1088 MC.VisitStmt(Body);
1089 }
1090}
1091
1092/// This check attempts to match these macros, assuming they are defined as
1093/// follows:
1094///
1095/// #define NSLocalizedString(key, comment) \
1096/// [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
1097/// #define NSLocalizedStringFromTable(key, tbl, comment) \
1098/// [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
1099/// #define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
1100/// [bundle localizedStringForKey:(key) value:@"" table:(tbl)]
1101/// #define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment)
1102///
1103/// We cannot use the path sensitive check because the macro argument we are
1104/// checking for (comment) is not used and thus not present in the AST,
1105/// so we use Lexer on the original macro call and retrieve the value of
1106/// the comment. If it's empty or nil, we raise a warning.
1107void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
1108 const ObjCMessageExpr *ME) {
1109
1110 // FIXME: We may be able to use PPCallbacks to check for empy context
1111 // comments as part of preprocessing and avoid this re-lexing hack.
1112 const ObjCInterfaceDecl *OD = ME->getReceiverInterface();
1113 if (!OD)
1
Assuming 'OD' is non-null
2
Taking false branch
1114 return;
1115
1116 const IdentifierInfo *odInfo = OD->getIdentifier();
1117
1118 if (!(odInfo->isStr("NSBundle") &&
3
Taking false branch
1119 ME->getSelector().getAsString() ==
1120 "localizedStringForKey:value:table:")) {
1121 return;
1122 }
1123
1124 SourceRange R = ME->getSourceRange();
1125 if (!R.getBegin().isMacroID())
4
Taking false branch
1126 return;
1127
1128 // getImmediateMacroCallerLoc gets the location of the immediate macro
1129 // caller, one level up the stack toward the initial macro typed into the
1130 // source, so SL should point to the NSLocalizedString macro.
1131 SourceLocation SL =
1132 Mgr.getSourceManager().getImmediateMacroCallerLoc(R.getBegin());
1133 std::pair<FileID, unsigned> SLInfo =
1134 Mgr.getSourceManager().getDecomposedLoc(SL);
1135
1136 SrcMgr::SLocEntry SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
1137
1138 // If NSLocalizedString macro is wrapped in another macro, we need to
1139 // unwrap the expansion until we get to the NSLocalizedStringMacro.
1140 while (SE.isExpansion()) {
5
Loop condition is false. Execution continues on line 1146
1141 SL = SE.getExpansion().getSpellingLoc();
1142 SLInfo = Mgr.getSourceManager().getDecomposedLoc(SL);
1143 SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
1144 }
1145
1146 bool Invalid = false;
1147 llvm::MemoryBuffer *BF =
1148 Mgr.getSourceManager().getBuffer(SLInfo.first, SL, &Invalid);
1149 if (Invalid)
6
Assuming 'Invalid' is 0
7
Taking false branch
1150 return;
1151
1152 Lexer TheLexer(SL, LangOptions(), BF->getBufferStart(),
1153 BF->getBufferStart() + SLInfo.second, BF->getBufferEnd());
1154
1155 Token I;
1156 Token Result; // This will hold the token just before the last ')'
1157 int p_count = 0; // This is for parenthesis matching
1158 while (!TheLexer.LexFromRawLexer(I)) {
8
Loop condition is false. Execution continues on line 1169
1159 if (I.getKind() == tok::l_paren)
1160 ++p_count;
1161 if (I.getKind() == tok::r_paren) {
1162 if (p_count == 1)
1163 break;
1164 --p_count;
1165 }
1166 Result = I;
1167 }
1168
1169 if (isAnyIdentifier(Result.getKind())) {
9
Calling 'Token::getKind'
1170 if (Result.getRawIdentifier().equals("nil")) {
1171 reportEmptyContextError(ME);
1172 return;
1173 }
1174 }
1175
1176 if (!isStringLiteral(Result.getKind()))
1177 return;
1178
1179 StringRef Comment =
1180 StringRef(Result.getLiteralData(), Result.getLength()).trim('"');
1181
1182 if ((Comment.trim().size() == 0 && Comment.size() > 0) || // Is Whitespace
1183 Comment.empty()) {
1184 reportEmptyContextError(ME);
1185 }
1186}
1187
1188void EmptyLocalizationContextChecker::MethodCrawler::reportEmptyContextError(
1189 const ObjCMessageExpr *ME) const {
1190 // Generate the bug report.
1191 BR.EmitBasicReport(MD, Checker, "Context Missing",
1192 "Localizability Issue (Apple)",
1193 "Localized string macro should include a non-empty "
1194 "comment for translators",
1195 PathDiagnosticLocation(ME, BR.getSourceManager(), DCtx));
1196}
1197
1198namespace {
1199class PluralMisuseChecker : public Checker<check::ASTCodeBody> {
1200
1201 // A helper class, which walks the AST
1202 class MethodCrawler : public RecursiveASTVisitor<MethodCrawler> {
1203 BugReporter &BR;
1204 const CheckerBase *Checker;
1205 AnalysisDeclContext *AC;
1206
1207 // This functions like a stack. We push on any IfStmt or
1208 // ConditionalOperator that matches the condition
1209 // and pop it off when we leave that statement
1210 llvm::SmallVector<const clang::Stmt *, 8> MatchingStatements;
1211 // This is true when we are the direct-child of a
1212 // matching statement
1213 bool InMatchingStatement = false;
1214
1215 public:
1216 explicit MethodCrawler(BugReporter &InBR, const CheckerBase *Checker,
1217 AnalysisDeclContext *InAC)
1218 : BR(InBR), Checker(Checker), AC(InAC) {}
1219
1220 bool VisitIfStmt(const IfStmt *I);
1221 bool EndVisitIfStmt(IfStmt *I);
1222 bool TraverseIfStmt(IfStmt *x);
1223 bool VisitConditionalOperator(const ConditionalOperator *C);
1224 bool TraverseConditionalOperator(ConditionalOperator *C);
1225 bool VisitCallExpr(const CallExpr *CE);
1226 bool VisitObjCMessageExpr(const ObjCMessageExpr *ME);
1227
1228 private:
1229 void reportPluralMisuseError(const Stmt *S) const;
1230 bool isCheckingPlurality(const Expr *E) const;
1231 };
1232
1233public:
1234 void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
1235 BugReporter &BR) const {
1236 MethodCrawler Visitor(BR, this, Mgr.getAnalysisDeclContext(D));
1237 Visitor.TraverseDecl(const_cast<Decl *>(D));
1238 }
1239};
1240} // end anonymous namespace
1241
1242// Checks the condition of the IfStmt and returns true if one
1243// of the following heuristics are met:
1244// 1) The conidtion is a variable with "singular" or "plural" in the name
1245// 2) The condition is a binary operator with 1 or 2 on the right-hand side
1246bool PluralMisuseChecker::MethodCrawler::isCheckingPlurality(
1247 const Expr *Condition) const {
1248 const BinaryOperator *BO = nullptr;
1249 // Accounts for when a VarDecl represents a BinaryOperator
1250 if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Condition)) {
1251 if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
1252 const Expr *InitExpr = VD->getInit();
1253 if (InitExpr) {
1254 if (const BinaryOperator *B =
1255 dyn_cast<BinaryOperator>(InitExpr->IgnoreParenImpCasts())) {
1256 BO = B;
1257 }
1258 }
1259 if (VD->getName().lower().find("plural") != StringRef::npos ||
1260 VD->getName().lower().find("singular") != StringRef::npos) {
1261 return true;
1262 }
1263 }
1264 } else if (const BinaryOperator *B = dyn_cast<BinaryOperator>(Condition)) {
1265 BO = B;
1266 }
1267
1268 if (BO == nullptr)
1269 return false;
1270
1271 if (IntegerLiteral *IL = dyn_cast_or_null<IntegerLiteral>(
1272 BO->getRHS()->IgnoreParenImpCasts())) {
1273 llvm::APInt Value = IL->getValue();
1274 if (Value == 1 || Value == 2) {
1275 return true;
1276 }
1277 }
1278 return false;
1279}
1280
1281// A CallExpr with "LOC" in its identifier that takes in a string literal
1282// has been shown to almost always be a function that returns a localized
1283// string. Raise a diagnostic when this is in a statement that matches
1284// the condition.
1285bool PluralMisuseChecker::MethodCrawler::VisitCallExpr(const CallExpr *CE) {
1286 if (InMatchingStatement) {
1287 if (const FunctionDecl *FD = CE->getDirectCallee()) {
1288 std::string NormalizedName =
1289 StringRef(FD->getNameInfo().getAsString()).lower();
1290 if (NormalizedName.find("loc") != std::string::npos) {
1291 for (const Expr *Arg : CE->arguments()) {
1292 if (isa<ObjCStringLiteral>(Arg))
1293 reportPluralMisuseError(CE);
1294 }
1295 }
1296 }
1297 }
1298 return true;
1299}
1300
1301// The other case is for NSLocalizedString which also returns
1302// a localized string. It's a macro for the ObjCMessageExpr
1303// [NSBundle localizedStringForKey:value:table:] Raise a
1304// diagnostic when this is in a statement that matches
1305// the condition.
1306bool PluralMisuseChecker::MethodCrawler::VisitObjCMessageExpr(
1307 const ObjCMessageExpr *ME) {
1308 const ObjCInterfaceDecl *OD = ME->getReceiverInterface();
1309 if (!OD)
1310 return true;
1311
1312 const IdentifierInfo *odInfo = OD->getIdentifier();
1313
1314 if (odInfo->isStr("NSBundle") &&
1315 ME->getSelector().getAsString() == "localizedStringForKey:value:table:") {
1316 if (InMatchingStatement) {
1317 reportPluralMisuseError(ME);
1318 }
1319 }
1320 return true;
1321}
1322
1323/// Override TraverseIfStmt so we know when we are done traversing an IfStmt
1324bool PluralMisuseChecker::MethodCrawler::TraverseIfStmt(IfStmt *I) {
1325 RecursiveASTVisitor<MethodCrawler>::TraverseIfStmt(I);
1326 return EndVisitIfStmt(I);
1327}
1328
1329// EndVisit callbacks are not provided by the RecursiveASTVisitor
1330// so we override TraverseIfStmt and make a call to EndVisitIfStmt
1331// after traversing the IfStmt
1332bool PluralMisuseChecker::MethodCrawler::EndVisitIfStmt(IfStmt *I) {
1333 MatchingStatements.pop_back();
1334 if (!MatchingStatements.empty()) {
1335 if (MatchingStatements.back() != nullptr) {
1336 InMatchingStatement = true;
1337 return true;
1338 }
1339 }
1340 InMatchingStatement = false;
1341 return true;
1342}
1343
1344bool PluralMisuseChecker::MethodCrawler::VisitIfStmt(const IfStmt *I) {
1345 const Expr *Condition = I->getCond()->IgnoreParenImpCasts();
1346 if (isCheckingPlurality(Condition)) {
1347 MatchingStatements.push_back(I);
1348 InMatchingStatement = true;
1349 } else {
1350 MatchingStatements.push_back(nullptr);
1351 InMatchingStatement = false;
1352 }
1353
1354 return true;
1355}
1356
1357// Preliminary support for conditional operators.
1358bool PluralMisuseChecker::MethodCrawler::TraverseConditionalOperator(
1359 ConditionalOperator *C) {
1360 RecursiveASTVisitor<MethodCrawler>::TraverseConditionalOperator(C);
1361 MatchingStatements.pop_back();
1362 if (!MatchingStatements.empty()) {
1363 if (MatchingStatements.back() != nullptr)
1364 InMatchingStatement = true;
1365 else
1366 InMatchingStatement = false;
1367 } else {
1368 InMatchingStatement = false;
1369 }
1370 return true;
1371}
1372
1373bool PluralMisuseChecker::MethodCrawler::VisitConditionalOperator(
1374 const ConditionalOperator *C) {
1375 const Expr *Condition = C->getCond()->IgnoreParenImpCasts();
1376 if (isCheckingPlurality(Condition)) {
1377 MatchingStatements.push_back(C);
1378 InMatchingStatement = true;
1379 } else {
1380 MatchingStatements.push_back(nullptr);
1381 InMatchingStatement = false;
1382 }
1383 return true;
1384}
1385
1386void PluralMisuseChecker::MethodCrawler::reportPluralMisuseError(
1387 const Stmt *S) const {
1388 // Generate the bug report.
1389 BR.EmitBasicReport(AC->getDecl(), Checker, "Plural Misuse",
1390 "Localizability Issue (Apple)",
1391 "Plural cases are not supported accross all languages. "
1392 "Use a .stringsdict file instead",
1393 PathDiagnosticLocation(S, BR.getSourceManager(), AC));
1394}
1395
1396//===----------------------------------------------------------------------===//
1397// Checker registration.
1398//===----------------------------------------------------------------------===//
1399
1400void ento::registerNonLocalizedStringChecker(CheckerManager &mgr) {
1401 NonLocalizedStringChecker *checker =
1402 mgr.registerChecker<NonLocalizedStringChecker>();
1403 checker->IsAggressive =
1404 mgr.getAnalyzerOptions().getBooleanOption("AggressiveReport", false);
1405}
1406
1407void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {
1408 mgr.registerChecker<EmptyLocalizationContextChecker>();
1409}
1410
1411void ento::registerPluralMisuseChecker(CheckerManager &mgr) {
1412 mgr.registerChecker<PluralMisuseChecker>();
1413}

/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h

1//===--- Token.h - Token interface ------------------------------*- 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// This file defines the Token interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LEX_TOKEN_H
15#define LLVM_CLANG_LEX_TOKEN_H
16
17#include "clang/Basic/SourceLocation.h"
18#include "clang/Basic/TokenKinds.h"
19#include "llvm/ADT/StringRef.h"
20#include <cassert>
21
22namespace clang {
23
24class IdentifierInfo;
25
26/// Token - This structure provides full information about a lexed token.
27/// It is not intended to be space efficient, it is intended to return as much
28/// information as possible about each returned token. This is expected to be
29/// compressed into a smaller form if memory footprint is important.
30///
31/// The parser can create a special "annotation token" representing a stream of
32/// tokens that were parsed and semantically resolved, e.g.: "foo::MyClass<int>"
33/// can be represented by a single typename annotation token that carries
34/// information about the SourceRange of the tokens and the type object.
35class Token {
36 /// The location of the token. This is actually a SourceLocation.
37 unsigned Loc;
38
39 // Conceptually these next two fields could be in a union. However, this
40 // causes gcc 4.2 to pessimize LexTokenInternal, a very performance critical
41 // routine. Keeping as separate members with casts until a more beautiful fix
42 // presents itself.
43
44 /// UintData - This holds either the length of the token text, when
45 /// a normal token, or the end of the SourceRange when an annotation
46 /// token.
47 unsigned UintData;
48
49 /// PtrData - This is a union of four different pointer types, which depends
50 /// on what type of token this is:
51 /// Identifiers, keywords, etc:
52 /// This is an IdentifierInfo*, which contains the uniqued identifier
53 /// spelling.
54 /// Literals: isLiteral() returns true.
55 /// This is a pointer to the start of the token in a text buffer, which
56 /// may be dirty (have trigraphs / escaped newlines).
57 /// Annotations (resolved type names, C++ scopes, etc): isAnnotation().
58 /// This is a pointer to sema-specific data for the annotation token.
59 /// Eof:
60 // This is a pointer to a Decl.
61 /// Other:
62 /// This is null.
63 void *PtrData;
64
65 /// Kind - The actual flavor of token this is.
66 tok::TokenKind Kind;
67
68 /// Flags - Bits we track about this token, members of the TokenFlags enum.
69 unsigned short Flags;
70
71public:
72 // Various flags set per token:
73 enum TokenFlags {
74 StartOfLine = 0x01, // At start of line or only after whitespace
75 // (considering the line after macro expansion).
76 LeadingSpace = 0x02, // Whitespace exists before this token (considering
77 // whitespace after macro expansion).
78 DisableExpand = 0x04, // This identifier may never be macro expanded.
79 NeedsCleaning = 0x08, // Contained an escaped newline or trigraph.
80 LeadingEmptyMacro = 0x10, // Empty macro exists before this token.
81 HasUDSuffix = 0x20, // This string or character literal has a ud-suffix.
82 HasUCN = 0x40, // This identifier contains a UCN.
83 IgnoredComma = 0x80, // This comma is not a macro argument separator (MS).
84 StringifiedInMacro = 0x100, // This string or character literal is formed by
85 // macro stringizing or charizing operator.
86 CommaAfterElided = 0x200, // The comma following this token was elided (MS).
87 IsEditorPlaceholder = 0x400, // This identifier is a placeholder.
88 };
89
90 tok::TokenKind getKind() const { return Kind; }
10
Undefined or garbage value returned to caller
91 void setKind(tok::TokenKind K) { Kind = K; }
92
93 /// is/isNot - Predicates to check if this token is a specific kind, as in
94 /// "if (Tok.is(tok::l_brace)) {...}".
95 bool is(tok::TokenKind K) const { return Kind == K; }
96 bool isNot(tok::TokenKind K) const { return Kind != K; }
97 bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const {
98 return is(K1) || is(K2);
99 }
100 template <typename... Ts>
101 bool isOneOf(tok::TokenKind K1, tok::TokenKind K2, Ts... Ks) const {
102 return is(K1) || isOneOf(K2, Ks...);
103 }
104
105 /// \brief Return true if this is a raw identifier (when lexing
106 /// in raw mode) or a non-keyword identifier (when lexing in non-raw mode).
107 bool isAnyIdentifier() const {
108 return tok::isAnyIdentifier(getKind());
109 }
110
111 /// \brief Return true if this is a "literal", like a numeric
112 /// constant, string, etc.
113 bool isLiteral() const {
114 return tok::isLiteral(getKind());
115 }
116
117 /// \brief Return true if this is any of tok::annot_* kind tokens.
118 bool isAnnotation() const {
119 return tok::isAnnotation(getKind());
120 }
121
122 /// \brief Return a source location identifier for the specified
123 /// offset in the current file.
124 SourceLocation getLocation() const {
125 return SourceLocation::getFromRawEncoding(Loc);
126 }
127 unsigned getLength() const {
128 assert(!isAnnotation() && "Annotation tokens have no length field")(static_cast <bool> (!isAnnotation() && "Annotation tokens have no length field"
) ? void (0) : __assert_fail ("!isAnnotation() && \"Annotation tokens have no length field\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 128, __extension__ __PRETTY_FUNCTION__))
;
129 return UintData;
130 }
131
132 void setLocation(SourceLocation L) { Loc = L.getRawEncoding(); }
133 void setLength(unsigned Len) {
134 assert(!isAnnotation() && "Annotation tokens have no length field")(static_cast <bool> (!isAnnotation() && "Annotation tokens have no length field"
) ? void (0) : __assert_fail ("!isAnnotation() && \"Annotation tokens have no length field\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 134, __extension__ __PRETTY_FUNCTION__))
;
135 UintData = Len;
136 }
137
138 SourceLocation getAnnotationEndLoc() const {
139 assert(isAnnotation() && "Used AnnotEndLocID on non-annotation token")(static_cast <bool> (isAnnotation() && "Used AnnotEndLocID on non-annotation token"
) ? void (0) : __assert_fail ("isAnnotation() && \"Used AnnotEndLocID on non-annotation token\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 139, __extension__ __PRETTY_FUNCTION__))
;
140 return SourceLocation::getFromRawEncoding(UintData ? UintData : Loc);
141 }
142 void setAnnotationEndLoc(SourceLocation L) {
143 assert(isAnnotation() && "Used AnnotEndLocID on non-annotation token")(static_cast <bool> (isAnnotation() && "Used AnnotEndLocID on non-annotation token"
) ? void (0) : __assert_fail ("isAnnotation() && \"Used AnnotEndLocID on non-annotation token\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 143, __extension__ __PRETTY_FUNCTION__))
;
144 UintData = L.getRawEncoding();
145 }
146
147 SourceLocation getLastLoc() const {
148 return isAnnotation() ? getAnnotationEndLoc() : getLocation();
149 }
150
151 SourceLocation getEndLoc() const {
152 return isAnnotation() ? getAnnotationEndLoc()
153 : getLocation().getLocWithOffset(getLength());
154 }
155
156 /// \brief SourceRange of the group of tokens that this annotation token
157 /// represents.
158 SourceRange getAnnotationRange() const {
159 return SourceRange(getLocation(), getAnnotationEndLoc());
160 }
161 void setAnnotationRange(SourceRange R) {
162 setLocation(R.getBegin());
163 setAnnotationEndLoc(R.getEnd());
164 }
165
166 const char *getName() const { return tok::getTokenName(Kind); }
167
168 /// \brief Reset all flags to cleared.
169 void startToken() {
170 Kind = tok::unknown;
171 Flags = 0;
172 PtrData = nullptr;
173 UintData = 0;
174 Loc = SourceLocation().getRawEncoding();
175 }
176
177 IdentifierInfo *getIdentifierInfo() const {
178 assert(isNot(tok::raw_identifier) &&(static_cast <bool> (isNot(tok::raw_identifier) &&
"getIdentifierInfo() on a tok::raw_identifier token!") ? void
(0) : __assert_fail ("isNot(tok::raw_identifier) && \"getIdentifierInfo() on a tok::raw_identifier token!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 179, __extension__ __PRETTY_FUNCTION__))
179 "getIdentifierInfo() on a tok::raw_identifier token!")(static_cast <bool> (isNot(tok::raw_identifier) &&
"getIdentifierInfo() on a tok::raw_identifier token!") ? void
(0) : __assert_fail ("isNot(tok::raw_identifier) && \"getIdentifierInfo() on a tok::raw_identifier token!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 179, __extension__ __PRETTY_FUNCTION__))
;
180 assert(!isAnnotation() &&(static_cast <bool> (!isAnnotation() && "getIdentifierInfo() on an annotation token!"
) ? void (0) : __assert_fail ("!isAnnotation() && \"getIdentifierInfo() on an annotation token!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 181, __extension__ __PRETTY_FUNCTION__))
181 "getIdentifierInfo() on an annotation token!")(static_cast <bool> (!isAnnotation() && "getIdentifierInfo() on an annotation token!"
) ? void (0) : __assert_fail ("!isAnnotation() && \"getIdentifierInfo() on an annotation token!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 181, __extension__ __PRETTY_FUNCTION__))
;
182 if (isLiteral()) return nullptr;
183 if (is(tok::eof)) return nullptr;
184 return (IdentifierInfo*) PtrData;
185 }
186 void setIdentifierInfo(IdentifierInfo *II) {
187 PtrData = (void*) II;
188 }
189
190 const void *getEofData() const {
191 assert(is(tok::eof))(static_cast <bool> (is(tok::eof)) ? void (0) : __assert_fail
("is(tok::eof)", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 191, __extension__ __PRETTY_FUNCTION__))
;
192 return reinterpret_cast<const void *>(PtrData);
193 }
194 void setEofData(const void *D) {
195 assert(is(tok::eof))(static_cast <bool> (is(tok::eof)) ? void (0) : __assert_fail
("is(tok::eof)", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 195, __extension__ __PRETTY_FUNCTION__))
;
196 assert(!PtrData)(static_cast <bool> (!PtrData) ? void (0) : __assert_fail
("!PtrData", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 196, __extension__ __PRETTY_FUNCTION__))
;
197 PtrData = const_cast<void *>(D);
198 }
199
200 /// getRawIdentifier - For a raw identifier token (i.e., an identifier
201 /// lexed in raw mode), returns a reference to the text substring in the
202 /// buffer if known.
203 StringRef getRawIdentifier() const {
204 assert(is(tok::raw_identifier))(static_cast <bool> (is(tok::raw_identifier)) ? void (0
) : __assert_fail ("is(tok::raw_identifier)", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 204, __extension__ __PRETTY_FUNCTION__))
;
205 return StringRef(reinterpret_cast<const char *>(PtrData), getLength());
206 }
207 void setRawIdentifierData(const char *Ptr) {
208 assert(is(tok::raw_identifier))(static_cast <bool> (is(tok::raw_identifier)) ? void (0
) : __assert_fail ("is(tok::raw_identifier)", "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 208, __extension__ __PRETTY_FUNCTION__))
;
209 PtrData = const_cast<char*>(Ptr);
210 }
211
212 /// getLiteralData - For a literal token (numeric constant, string, etc), this
213 /// returns a pointer to the start of it in the text buffer if known, null
214 /// otherwise.
215 const char *getLiteralData() const {
216 assert(isLiteral() && "Cannot get literal data of non-literal")(static_cast <bool> (isLiteral() && "Cannot get literal data of non-literal"
) ? void (0) : __assert_fail ("isLiteral() && \"Cannot get literal data of non-literal\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 216, __extension__ __PRETTY_FUNCTION__))
;
217 return reinterpret_cast<const char*>(PtrData);
218 }
219 void setLiteralData(const char *Ptr) {
220 assert(isLiteral() && "Cannot set literal data of non-literal")(static_cast <bool> (isLiteral() && "Cannot set literal data of non-literal"
) ? void (0) : __assert_fail ("isLiteral() && \"Cannot set literal data of non-literal\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 220, __extension__ __PRETTY_FUNCTION__))
;
221 PtrData = const_cast<char*>(Ptr);
222 }
223
224 void *getAnnotationValue() const {
225 assert(isAnnotation() && "Used AnnotVal on non-annotation token")(static_cast <bool> (isAnnotation() && "Used AnnotVal on non-annotation token"
) ? void (0) : __assert_fail ("isAnnotation() && \"Used AnnotVal on non-annotation token\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 225, __extension__ __PRETTY_FUNCTION__))
;
226 return PtrData;
227 }
228 void setAnnotationValue(void *val) {
229 assert(isAnnotation() && "Used AnnotVal on non-annotation token")(static_cast <bool> (isAnnotation() && "Used AnnotVal on non-annotation token"
) ? void (0) : __assert_fail ("isAnnotation() && \"Used AnnotVal on non-annotation token\""
, "/build/llvm-toolchain-snapshot-7~svn326551/tools/clang/include/clang/Lex/Token.h"
, 229, __extension__ __PRETTY_FUNCTION__))
;
230 PtrData = val;
231 }
232
233 /// \brief Set the specified flag.
234 void setFlag(TokenFlags Flag) {
235 Flags |= Flag;
236 }
237
238 /// \brief Get the specified flag.
239 bool getFlag(TokenFlags Flag) const {
240 return (Flags & Flag) != 0;
241 }
242
243 /// \brief Unset the specified flag.
244 void clearFlag(TokenFlags Flag) {
245 Flags &= ~Flag;
246 }
247
248 /// \brief Return the internal represtation of the flags.
249 ///
250 /// This is only intended for low-level operations such as writing tokens to
251 /// disk.
252 unsigned getFlags() const {
253 return Flags;
254 }
255
256 /// \brief Set a flag to either true or false.
257 void setFlagValue(TokenFlags Flag, bool Val) {
258 if (Val)
259 setFlag(Flag);
260 else
261 clearFlag(Flag);
262 }
263
264 /// isAtStartOfLine - Return true if this token is at the start of a line.
265 ///
266 bool isAtStartOfLine() const { return getFlag(StartOfLine); }
267
268 /// \brief Return true if this token has whitespace before it.
269 ///
270 bool hasLeadingSpace() const { return getFlag(LeadingSpace); }
271
272 /// \brief Return true if this identifier token should never
273 /// be expanded in the future, due to C99 6.10.3.4p2.
274 bool isExpandDisabled() const { return getFlag(DisableExpand); }
275
276 /// \brief Return true if we have an ObjC keyword identifier.
277 bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const;
278
279 /// \brief Return the ObjC keyword kind.
280 tok::ObjCKeywordKind getObjCKeywordID() const;
281
282 /// \brief Return true if this token has trigraphs or escaped newlines in it.
283 bool needsCleaning() const { return getFlag(NeedsCleaning); }
284
285 /// \brief Return true if this token has an empty macro before it.
286 ///
287 bool hasLeadingEmptyMacro() const { return getFlag(LeadingEmptyMacro); }
288
289 /// \brief Return true if this token is a string or character literal which
290 /// has a ud-suffix.
291 bool hasUDSuffix() const { return getFlag(HasUDSuffix); }
292
293 /// Returns true if this token contains a universal character name.
294 bool hasUCN() const { return getFlag(HasUCN); }
295
296 /// Returns true if this token is formed by macro by stringizing or charizing
297 /// operator.
298 bool stringifiedInMacro() const { return getFlag(StringifiedInMacro); }
299
300 /// Returns true if the comma after this token was elided.
301 bool commaAfterElided() const { return getFlag(CommaAfterElided); }
302
303 /// Returns true if this token is an editor placeholder.
304 ///
305 /// Editor placeholders are produced by the code-completion engine and are
306 /// represented as characters between '<#' and '#>' in the source code. The
307 /// lexer uses identifier tokens to represent placeholders.
308 bool isEditorPlaceholder() const { return getFlag(IsEditorPlaceholder); }
309};
310
311/// \brief Information about the conditional stack (\#if directives)
312/// currently active.
313struct PPConditionalInfo {
314 /// \brief Location where the conditional started.
315 SourceLocation IfLoc;
316
317 /// \brief True if this was contained in a skipping directive, e.g.,
318 /// in a "\#if 0" block.
319 bool WasSkipping;
320
321 /// \brief True if we have emitted tokens already, and now we're in
322 /// an \#else block or something. Only useful in Skipping blocks.
323 bool FoundNonSkip;
324
325 /// \brief True if we've seen a \#else in this block. If so,
326 /// \#elif/\#else directives are not allowed.
327 bool FoundElse;
328};
329
330} // end namespace clang
331
332namespace llvm {
333 template <>
334 struct isPodLike<clang::Token> { static const bool value = true; };
335} // end namespace llvm
336
337#endif // LLVM_CLANG_LEX_TOKEN_H