Bug Summary

File:build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/clang/include/clang/Lex/Token.h
Warning:line 92, column 36
Undefined or garbage value returned to caller

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name LocalizationChecker.cpp -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 -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/clang/lib/StaticAnalyzer/Checkers -I /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/clang/lib/StaticAnalyzer/Checkers -I /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/clang/include -I tools/clang/include -I include -I /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/llvm/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm=build-llvm -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm=build-llvm -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -O3 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/build-llvm=build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-10-03-140002-15933-1 -x c++ /build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp

/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp

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

/build/llvm-toolchain-snapshot-16~++20221003111214+1fa2019828ca/clang/include/clang/Lex/Token.h

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