32 #include "llvm/Support/Unicode.h" 34 using namespace clang;
38 struct LocalizedState {
40 enum Kind { NonLocalized, Localized } K;
41 LocalizedState(
Kind InK) : K(InK) {}
44 bool isLocalized()
const {
return K == Localized; }
45 bool isNonLocalized()
const {
return K == NonLocalized; }
47 static LocalizedState getLocalized() {
return LocalizedState(Localized); }
48 static LocalizedState getNonLocalized() {
49 return LocalizedState(NonLocalized);
53 bool operator==(
const LocalizedState &
X)
const {
return K == X.K; }
56 void Profile(llvm::FoldingSetNodeID &
ID)
const { ID.AddInteger(K); }
59 class NonLocalizedStringChecker
60 :
public Checker<check::PreCall, check::PostCall, check::PreObjCMessage,
61 check::PostObjCMessage,
62 check::PostStmt<ObjCStringLiteral>> {
64 mutable std::unique_ptr<BugType> BT;
68 llvm::DenseMap<Selector, uint8_t>> UIMethods;
70 mutable llvm::SmallSet<std::pair<const IdentifierInfo *, Selector>, 12> LSM;
72 mutable llvm::SmallSet<const IdentifierInfo *, 5> LSF;
75 void initLocStringsMethods(
ASTContext &Ctx)
const;
77 bool hasNonLocalizedState(SVal S, CheckerContext &C)
const;
78 bool hasLocalizedState(SVal S, CheckerContext &C)
const;
79 void setNonLocalizedState(SVal S, CheckerContext &C)
const;
80 void setLocalizedState(SVal S, CheckerContext &C)
const;
82 bool isAnnotatedAsReturningLocalized(
const Decl *D)
const;
83 bool isAnnotatedAsTakingLocalized(
const Decl *D)
const;
84 void reportLocalizationError(SVal S,
const CallEvent &M, CheckerContext &C,
85 int argumentNumber = 0)
const;
87 int getLocalizedArgumentForSelector(
const IdentifierInfo *Receiver,
91 NonLocalizedStringChecker();
96 DefaultBool IsAggressive;
98 void checkPreObjCMessage(
const ObjCMethodCall &msg, CheckerContext &C)
const;
99 void checkPostObjCMessage(
const ObjCMethodCall &msg, CheckerContext &C)
const;
101 void checkPreCall(
const CallEvent &Call, CheckerContext &C)
const;
102 void checkPostCall(
const CallEvent &Call, CheckerContext &C)
const;
110 NonLocalizedStringChecker::NonLocalizedStringChecker() {
111 BT.reset(
new BugType(
this,
"Unlocalizable string",
112 "Localizability Issue (Apple)"));
118 const MemRegion *NonLocalizedString;
122 NonLocalizedStringBRVisitor(
const MemRegion *NonLocalizedString)
123 : NonLocalizedString(NonLocalizedString), Satisfied(
false) {
124 assert(NonLocalizedString);
127 std::shared_ptr<PathDiagnosticPiece> VisitNode(
const ExplodedNode *Succ,
128 BugReporterContext &BRC,
129 BugReport &BR)
override;
131 void Profile(llvm::FoldingSetNodeID &
ID)
const override {
132 ID.Add(NonLocalizedString);
137 #define NEW_RECEIVER(receiver) \ 138 llvm::DenseMap<Selector, uint8_t> &receiver##M = \ 139 UIMethods.insert({&Ctx.Idents.get(#receiver), \ 140 llvm::DenseMap<Selector, uint8_t>()}) \ 142 #define ADD_NULLARY_METHOD(receiver, method, argument) \ 143 receiver##M.insert( \ 144 {Ctx.Selectors.getNullarySelector(&Ctx.Idents.get(#method)), argument}); 145 #define ADD_UNARY_METHOD(receiver, method, argument) \ 146 receiver##M.insert( \ 147 {Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(#method)), argument}); 148 #define ADD_METHOD(receiver, method_list, count, argument) \ 149 receiver##M.insert({Ctx.Selectors.getSelector(count, method_list), argument}); 153 void NonLocalizedStringChecker::initUIMethods(
ASTContext &Ctx)
const {
154 if (!UIMethods.empty())
165 ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemTag, 3, 0)
169 ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemImage, 3, 0)
182 ADD_METHOD(UITableViewRowAction, rowActionWithStyleUITableViewRowAction, 3, 1)
194 ADD_METHOD(NSButton, radioButtonWithTitleNSButton, 3, 0)
198 ADD_METHOD(NSButton, buttonWithTitleNSButtonImage, 4, 0)
202 ADD_METHOD(NSButton, checkboxWithTitleNSButton, 3, 0)
206 ADD_METHOD(NSButton, buttonWithTitleNSButtonTarget, 3, 0)
225 ADD_METHOD(NSBrowser, setTitleNSBrowser, 2, 0)
236 ADD_METHOD(UIAlertAction, actionWithTitleUIAlertAction, 3, 0)
242 ADD_METHOD(NSPopUpButton, insertItemWithTitleNSPopUpButton, 2, 0)
251 ADD_METHOD(NSTableViewRowAction, rowActionWithStyleNSTableViewRowAction, 3, 1)
283 ADD_METHOD(NSSegmentedControl, setLabelNSSegmentedControl, 2, 0)
286 ADD_METHOD(NSSegmentedControl, setToolTipNSSegmentedControl, 2, 0)
311 ADD_METHOD(NSMatrix, setToolTipNSMatrix, 2, 0)
327 ADD_METHOD(UIMenuItem, initWithTitleUIMenuItem, 2, 0)
334 ADD_METHOD(UIAlertController, alertControllerWithTitleUIAlertController, 3, 1)
344 initWithTypeUIApplicationShortcutItemIcon, 5, 1)
347 ADD_METHOD(UIApplicationShortcutItem, initWithTypeUIApplicationShortcutItem,
354 &Ctx.
Idents.
get(
"destructiveButtonTitle"),
356 ADD_METHOD(UIActionSheet, initWithTitleUIActionSheet, 5, 0)
365 initWithNameUIAccessibilityCustomAction, 3, 0)
392 ADD_METHOD(NSAttributedString, initWithStringNSAttributedString, 2, 0)
401 ADD_METHOD(UIKeyCommand, keyCommandWithInputUIKeyCommand, 4, 3)
411 &Ctx.
Idents.
get(
"informativeTextWithFormat")};
412 ADD_METHOD(NSAlert, alertWithMessageTextNSAlert, 5, 0)
431 ADD_METHOD(NSWindow, minFrameWidthWithTitleNSWindow, 2, 0)
438 IdentifierInfo *addOptionWithTitleUIDocumentMenuViewController[] = {
442 addOptionWithTitleUIDocumentMenuViewController, 4, 0)
454 ADD_METHOD(UIAlertView, initWithTitleUIAlertView, 5, 0)
484 ADD_METHOD(NSSegmentedCell, setLabelNSSegmentedCell, 2, 0)
487 ADD_METHOD(NSSegmentedCell, setToolTipNSSegmentedCell, 2, 0)
498 ADD_METHOD(NSMenuItem, initWithTitleNSMenuItem, 3, 0)
505 ADD_METHOD(NSPopUpButtonCell, initTextCellNSPopUpButtonCell, 2, 0)
509 ADD_METHOD(NSPopUpButtonCell, insertItemWithTitleNSPopUpButtonCell, 2, 0)
522 ADD_METHOD(NSMenu, insertItemWithTitleNSMenu, 4, 0)
526 ADD_METHOD(NSMenu, addItemWithTitleNSMenu, 3, 0)
542 IdentifierInfo *actionWithIdentifierNSUserNotificationAction[] = {
545 actionWithIdentifierNSUserNotificationAction, 2, 1)
555 ADD_METHOD(UIBarButtonItem, initWithTitleUIBarButtonItem, 4, 0)
564 ADD_METHOD(UISegmentedControl, insertSegmentWithTitleUISegmentedControl, 3, 0)
567 ADD_METHOD(UISegmentedControl, setTitleUISegmentedControl, 2, 0)
571 *initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult[] = {
572 &Ctx.
Idents.
get(
"initWithItemLoadingToken"),
574 ADD_METHOD(NSAccessibilityCustomRotorItemResult,
575 initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult, 2, 1)
582 ADD_METHOD(UIContextualAction, contextualActionWithStyleUIContextualAction, 3,
590 initWithLabelNSAccessibilityCustomRotor, 2, 0)
601 initWithNameNSAccessibilityCustomAction, 2, 0)
602 IdentifierInfo *initWithNameTargetNSAccessibilityCustomAction[] = {
606 initWithNameTargetNSAccessibilityCustomAction, 3, 0)
610 #define LSF_INSERT(function_name) LSF.insert(&Ctx.Idents.get(function_name)); 611 #define LSM_INSERT_NULLARY(receiver, method_name) \ 612 LSM.insert({&Ctx.Idents.get(receiver), Ctx.Selectors.getNullarySelector( \ 613 &Ctx.Idents.get(method_name))}); 614 #define LSM_INSERT_UNARY(receiver, method_name) \ 615 LSM.insert({&Ctx.Idents.get(receiver), \ 616 Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(method_name))}); 617 #define LSM_INSERT_SELECTOR(receiver, method_list, arguments) \ 618 LSM.insert({&Ctx.Idents.get(receiver), \ 619 Ctx.Selectors.getSelector(arguments, method_list)}); 622 void NonLocalizedStringChecker::initLocStringsMethods(
ASTContext &Ctx)
const {
640 LSF_INSERT(
"CFDateFormatterCreateStringWithDate");
641 LSF_INSERT(
"CFDateFormatterCreateStringWithAbsoluteTime");
642 LSF_INSERT(
"CFNumberFormatterCreateStringWithNumber");
647 bool NonLocalizedStringChecker::isAnnotatedAsReturningLocalized(
648 const Decl *D)
const {
654 return Ann->getAnnotation() ==
"returns_localized_nsstring";
660 bool NonLocalizedStringChecker::isAnnotatedAsTakingLocalized(
661 const Decl *D)
const {
667 return Ann->getAnnotation() ==
"takes_localized_nsstring";
672 bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
673 CheckerContext &C)
const {
674 const MemRegion *mt = S.getAsRegion();
676 const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);
677 if (LS && LS->isLocalized())
685 bool NonLocalizedStringChecker::hasNonLocalizedState(SVal S,
686 CheckerContext &C)
const {
687 const MemRegion *mt = S.getAsRegion();
689 const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);
690 if (LS && LS->isNonLocalized())
697 void NonLocalizedStringChecker::setLocalizedState(
const SVal S,
698 CheckerContext &C)
const {
699 const MemRegion *mt = S.getAsRegion();
702 C.getState()->set<LocalizedMemMap>(mt, LocalizedState::getLocalized());
703 C.addTransition(State);
708 void NonLocalizedStringChecker::setNonLocalizedState(
const SVal S,
709 CheckerContext &C)
const {
710 const MemRegion *mt = S.getAsRegion();
713 mt, LocalizedState::getNonLocalized());
714 C.addTransition(State);
720 return StringRef(name).lower().find(
"debug") != StringRef::npos;
728 const Decl *D = C.getCurrentAnalysisDeclContext()->getDecl();
732 if (
auto *ND = dyn_cast<NamedDecl>(D)) {
739 if (
auto *CD = dyn_cast<ObjCContainerDecl>(DC)) {
749 void NonLocalizedStringChecker::reportLocalizationError(
750 SVal S,
const CallEvent &M, CheckerContext &C,
int argumentNumber)
const {
757 ExplodedNode *ErrNode = C.getPredecessor();
758 static CheckerProgramPointTag Tag(
"NonLocalizedStringChecker",
759 "UnlocalizedString");
760 ErrNode = C.addTransition(C.getState(), C.getPredecessor(), &Tag);
766 std::unique_ptr<BugReport> R(
new BugReport(
767 *BT,
"User-facing text should use localized string macro", ErrNode));
768 if (argumentNumber) {
769 R->addRange(M.getArgExpr(argumentNumber - 1)->getSourceRange());
771 R->addRange(M.getSourceRange());
773 R->markInteresting(S);
775 const MemRegion *StringRegion = S.getAsRegion();
777 R->addVisitor(llvm::make_unique<NonLocalizedStringBRVisitor>(StringRegion));
779 C.emitReport(std::move(R));
784 int NonLocalizedStringChecker::getLocalizedArgumentForSelector(
786 auto method = UIMethods.find(Receiver);
788 if (method == UIMethods.end())
791 auto argumentIterator = method->getSecond().find(S);
793 if (argumentIterator == method->getSecond().end())
796 int argumentNumber = argumentIterator->getSecond();
797 return argumentNumber;
801 void NonLocalizedStringChecker::checkPreObjCMessage(
const ObjCMethodCall &msg,
802 CheckerContext &C)
const {
803 initUIMethods(C.getASTContext());
813 StringRef SelectorName = SelectorString;
814 assert(!SelectorName.empty());
816 if (odInfo->
isStr(
"NSString")) {
820 if (!(SelectorName.startswith(
"drawAtPoint") ||
821 SelectorName.startswith(
"drawInRect") ||
822 SelectorName.startswith(
"drawWithRect")))
827 bool isNonLocalized = hasNonLocalizedState(svTitle, C);
829 if (isNonLocalized) {
830 reportLocalizationError(svTitle, msg, C);
834 int argumentNumber = getLocalizedArgumentForSelector(odInfo, S);
836 while (argumentNumber < 0 && OD->getSuperClass() !=
nullptr) {
837 for (
const auto *
P : OD->all_referenced_protocols()) {
838 argumentNumber = getLocalizedArgumentForSelector(
P->getIdentifier(), S);
839 if (argumentNumber >= 0)
842 if (argumentNumber < 0) {
843 OD = OD->getSuperClass();
844 argumentNumber = getLocalizedArgumentForSelector(OD->getIdentifier(), S);
848 if (argumentNumber < 0) {
850 if (
const ObjCMethodDecl *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
851 auto formals = OMD->parameters();
852 for (
unsigned i = 0, ei = formals.size(); i != ei; ++i) {
853 if (isAnnotatedAsTakingLocalized(formals[i])) {
862 if (argumentNumber < 0)
865 SVal svTitle = msg.getArgSVal(argumentNumber);
867 if (
const ObjCStringRegion *SR =
868 dyn_cast_or_null<ObjCStringRegion>(svTitle.getAsRegion())) {
869 StringRef stringValue =
870 SR->getObjCStringLiteral()->getString()->getString();
871 if ((stringValue.trim().size() == 0 && stringValue.size() > 0) ||
874 if (!IsAggressive && llvm::sys::unicode::columnWidthUTF8(stringValue) < 2)
878 bool isNonLocalized = hasNonLocalizedState(svTitle, C);
880 if (isNonLocalized) {
881 reportLocalizationError(svTitle, msg, C, argumentNumber + 1);
885 void NonLocalizedStringChecker::checkPreCall(
const CallEvent &Call,
886 CheckerContext &C)
const {
887 const Decl *D = Call.getDecl();
888 if (D && isa<FunctionDecl>(D)) {
892 ei =
std::min(
unsigned(formals.size()), Call.getNumArgs());
894 if (isAnnotatedAsTakingLocalized(formals[i])) {
895 auto actual = Call.getArgSVal(i);
896 if (hasNonLocalizedState(actual, C)) {
897 reportLocalizationError(actual, Call, C, i + 1);
917 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
918 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
926 void NonLocalizedStringChecker::checkPostCall(
const CallEvent &Call,
927 CheckerContext &C)
const {
928 initLocStringsMethods(C.getASTContext());
930 if (!Call.getOriginExpr())
936 const QualType RT = Call.getResultType();
938 for (
unsigned i = 0; i < Call.getNumArgs(); ++i) {
939 SVal argValue = Call.getArgSVal(i);
940 if (hasLocalizedState(argValue, C)) {
941 SVal sv = Call.getReturnValue();
942 setLocalizedState(sv, C);
948 const Decl *D = Call.getDecl();
954 SVal sv = Call.getReturnValue();
955 if (isAnnotatedAsReturningLocalized(D) || LSF.count(Identifier) != 0) {
956 setLocalizedState(sv, C);
958 !hasLocalizedState(sv, C)) {
960 setNonLocalizedState(sv, C);
962 const SymbolicRegion *SymReg =
963 dyn_cast_or_null<SymbolicRegion>(sv.getAsRegion());
965 setNonLocalizedState(sv, C);
972 void NonLocalizedStringChecker::checkPostObjCMessage(
const ObjCMethodCall &msg,
973 CheckerContext &C)
const {
974 initLocStringsMethods(C.getASTContext());
987 std::pair<const IdentifierInfo *, Selector> MethodDescription = {odInfo, S};
989 if (LSM.count(MethodDescription) ||
990 isAnnotatedAsReturningLocalized(msg.
getDecl())) {
991 SVal sv = msg.getReturnValue();
992 setLocalizedState(sv, C);
998 CheckerContext &C)
const {
999 SVal sv = C.getSVal(SL);
1000 setNonLocalizedState(sv, C);
1003 std::shared_ptr<PathDiagnosticPiece>
1004 NonLocalizedStringBRVisitor::VisitNode(
const ExplodedNode *Succ,
1005 BugReporterContext &BRC, BugReport &BR) {
1010 if (!Point.hasValue())
1017 SVal LiteralSVal = Succ->getSVal(LiteralExpr);
1018 if (LiteralSVal.getAsRegion() != NonLocalizedString)
1023 PathDiagnosticLocation L =
1026 if (!L.isValid() || !L.asLocation().isValid())
1029 auto Piece = std::make_shared<PathDiagnosticEventPiece>(
1030 L,
"Non-localized string literal here");
1031 Piece->addRange(LiteralExpr->getSourceRange());
1033 return std::move(Piece);
1037 class EmptyLocalizationContextChecker
1038 :
public Checker<check::ASTDecl<ObjCImplementationDecl>> {
1044 AnalysisManager &Mgr;
1045 const CheckerBase *Checker;
1050 const CheckerBase *Checker, AnalysisManager &InMgr,
1052 : MD(InMD), BR(InBR), Mgr(InMgr), Checker(Checker), DCtx(InDCtx) {}
1054 void VisitStmt(
const Stmt *S) { VisitChildren(S); }
1060 void VisitChildren(
const Stmt *S) {
1070 BugReporter &BR)
const;
1074 void EmptyLocalizationContextChecker::checkASTDecl(
1076 BugReporter &BR)
const {
1081 const Stmt *Body = M->getBody();
1084 MethodCrawler MC(M->getCanonicalDecl(), BR,
this, Mgr, DCtx);
1104 void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
1115 if (!(odInfo->
isStr(
"NSBundle") &&
1117 "localizedStringForKey:value:table:")) {
1129 Mgr.getSourceManager().getImmediateMacroCallerLoc(R.
getBegin());
1130 std::pair<FileID, unsigned> SLInfo =
1131 Mgr.getSourceManager().getDecomposedLoc(SL);
1139 SLInfo = Mgr.getSourceManager().getDecomposedLoc(SL);
1140 SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
1143 bool Invalid =
false;
1144 llvm::MemoryBuffer *BF =
1145 Mgr.getSourceManager().getBuffer(SLInfo.first, SL, &Invalid);
1150 BF->getBufferStart() + SLInfo.second, BF->getBufferEnd());
1155 while (!TheLexer.LexFromRawLexer(I)) {
1156 if (I.getKind() == tok::l_paren)
1158 if (I.getKind() == tok::r_paren) {
1168 reportEmptyContextError(ME);
1179 if ((Comment.trim().size() == 0 && Comment.size() > 0) ||
1181 reportEmptyContextError(ME);
1185 void EmptyLocalizationContextChecker::MethodCrawler::reportEmptyContextError(
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));
1196 class PluralMisuseChecker :
public Checker<check::ASTCodeBody> {
1201 const CheckerBase *Checker;
1210 bool InMatchingStatement =
false;
1213 explicit MethodCrawler(BugReporter &InBR,
const CheckerBase *Checker,
1215 : BR(InBR), Checker(Checker), AC(InAC) {}
1217 bool VisitIfStmt(
const IfStmt *I);
1218 bool EndVisitIfStmt(
IfStmt *I);
1219 bool TraverseIfStmt(
IfStmt *x);
1222 bool VisitCallExpr(
const CallExpr *CE);
1226 void reportPluralMisuseError(
const Stmt *S)
const;
1227 bool isCheckingPlurality(
const Expr *E)
const;
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));
1243 bool PluralMisuseChecker::MethodCrawler::isCheckingPlurality(
1244 const Expr *Condition)
const {
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();
1256 if (VD->getName().lower().find(
"plural") != StringRef::npos ||
1257 VD->getName().lower().find(
"singular") != StringRef::npos) {
1261 }
else if (
const BinaryOperator *B = dyn_cast<BinaryOperator>(Condition)) {
1270 llvm::APInt
Value = IL->getValue();
1271 if (Value == 1 || Value == 2) {
1282 bool PluralMisuseChecker::MethodCrawler::VisitCallExpr(
const CallExpr *CE) {
1283 if (InMatchingStatement) {
1285 std::string NormalizedName =
1286 StringRef(FD->getNameInfo().getAsString()).lower();
1287 if (NormalizedName.find(
"loc") != std::string::npos) {
1289 if (isa<ObjCStringLiteral>(Arg))
1290 reportPluralMisuseError(CE);
1303 bool PluralMisuseChecker::MethodCrawler::VisitObjCMessageExpr(
1311 if (odInfo->
isStr(
"NSBundle") &&
1313 if (InMatchingStatement) {
1314 reportPluralMisuseError(ME);
1321 bool PluralMisuseChecker::MethodCrawler::TraverseIfStmt(
IfStmt *I) {
1323 return EndVisitIfStmt(I);
1329 bool PluralMisuseChecker::MethodCrawler::EndVisitIfStmt(
IfStmt *I) {
1330 MatchingStatements.pop_back();
1331 if (!MatchingStatements.empty()) {
1332 if (MatchingStatements.back() !=
nullptr) {
1333 InMatchingStatement =
true;
1337 InMatchingStatement =
false;
1341 bool PluralMisuseChecker::MethodCrawler::VisitIfStmt(
const IfStmt *I) {
1343 if (isCheckingPlurality(Condition)) {
1344 MatchingStatements.push_back(I);
1345 InMatchingStatement =
true;
1347 MatchingStatements.push_back(
nullptr);
1348 InMatchingStatement =
false;
1355 bool PluralMisuseChecker::MethodCrawler::TraverseConditionalOperator(
1358 MatchingStatements.pop_back();
1359 if (!MatchingStatements.empty()) {
1360 if (MatchingStatements.back() !=
nullptr)
1361 InMatchingStatement =
true;
1363 InMatchingStatement =
false;
1365 InMatchingStatement =
false;
1370 bool PluralMisuseChecker::MethodCrawler::VisitConditionalOperator(
1373 if (isCheckingPlurality(Condition)) {
1374 MatchingStatements.push_back(C);
1375 InMatchingStatement =
true;
1377 MatchingStatements.push_back(
nullptr);
1378 InMatchingStatement =
false;
1383 void PluralMisuseChecker::MethodCrawler::reportPluralMisuseError(
1384 const Stmt *S)
const {
1386 BR.EmitBasicReport(AC->getDecl(), Checker,
"Plural Misuse",
1387 "Localizability Issue (Apple)",
1388 "Plural cases are not supported across all languages. " 1389 "Use a .stringsdict file instead",
1390 PathDiagnosticLocation(S, BR.getSourceManager(), AC));
1397 void ento::registerNonLocalizedStringChecker(CheckerManager &mgr) {
1398 NonLocalizedStringChecker *checker =
1399 mgr.registerChecker<NonLocalizedStringChecker>();
1400 checker->IsAggressive =
1401 mgr.getAnalyzerOptions().getCheckerBooleanOption(
"AggressiveReport",
1405 void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {
1406 mgr.registerChecker<EmptyLocalizationContextChecker>();
1409 void ento::registerPluralMisuseChecker(CheckerManager &mgr) {
1410 mgr.registerChecker<PluralMisuseChecker>();
SVal getReceiverSVal() const
Returns the value of the receiver at the time of this call.
#define NEW_RECEIVER(receiver)
Represents a function declaration or definition.
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Smart pointer class that efficiently represents Objective-C method names.
This is a discriminated union of FileInfo and ExpansionInfo.
A (possibly-)qualified type.
Selector getSelector() const
SourceLocation getSpellingLoc() const
bool operator==(CanQual< T > x, CanQual< U > y)
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
specific_attr_iterator< T > specific_attr_begin() const
Stmt - This represents one statement.
#define ADD_METHOD(receiver, method_list, count, argument)
IfStmt - This represents an if/then/else.
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
Decl - This represents one declaration (or definition), e.g.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
REGISTER_MAP_WITH_PROGRAMSTATE(LocalizedMemMap, const MemRegion *, LocalizedState) NonLocalizedStringChecker
static bool isDebuggingName(std::string name)
static bool isDebuggingContext(CheckerContext &C)
Returns true when, heuristically, the analyzer may be analyzing debugging code.
Represents a variable declaration or definition.
const T * getAs() const
Member-template getAs<specific type>'.
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token...
ObjCMethodDecl - Represents an instance or class method declaration.
tok::TokenKind getKind() const
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
AnalysisDeclContext contains the context data for the function or method under analysis.
method_range methods() const
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Token - This structure provides full information about a lexed token.
specific_attr_iterator< T > specific_attr_end() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
ArrayRef< ParmVarDecl * > parameters() const
Represents any expression that calls an Objective-C method.
A builtin binary operation expression such as "x + y" or "x <= y".
ObjCStringLiteral, used for Objective-C string literals i.e.
static PathDiagnosticLocation create(const Decl *D, const SourceManager &SM)
Create a location corresponding to the given declaration.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Represents an ObjC class declaration.
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
ConditionalOperator - The ?: ternary operator.
#define LSM_INSERT_NULLARY(receiver, method_name)
This represents one expression.
DeclContext * getDeclContext()
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
llvm::PointerUnion< const LocationContext *, AnalysisDeclContext * > LocationOrAnalysisDeclContext
An expression that sends a message to the given Objective-C object or class.
const ExpansionInfo & getExpansion() const
#define ADD_UNARY_METHOD(receiver, method, argument)
std::string getAsString() const
Derive the full selector name (e.g.
static bool isNSStringType(QualType T, ASTContext &Ctx)
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
#define LSF_INSERT(function_name)
const ObjCMethodDecl * getDecl() const override
Selector getSelector() const
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
unsigned getLength() const
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
Represents a pointer to an Objective C object.
bool isInstanceMessage() const
const char * getLiteralData() const
getLiteralData - For a literal token (numeric constant, string, etc), this returns a pointer to the s...
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
#define LSM_INSERT_UNARY(receiver, method_name)
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode), returns a reference to the text substring in the buffer if known.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
A reference to a declared variable, function, enum, etc.
__DEVICE__ int min(int __a, int __b)
#define LSM_INSERT_SELECTOR(receiver, method_list, arguments)
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
bool isAnyIdentifier(TokenKind K)
Return true if this is a raw identifier or an identifier kind.