31 #include "llvm/Support/Unicode.h" 33 using namespace clang;
37 struct LocalizedState {
39 enum Kind { NonLocalized, Localized } K;
40 LocalizedState(
Kind InK) : K(InK) {}
43 bool isLocalized()
const {
return K == Localized; }
44 bool isNonLocalized()
const {
return K == NonLocalized; }
46 static LocalizedState getLocalized() {
return LocalizedState(Localized); }
47 static LocalizedState getNonLocalized() {
48 return LocalizedState(NonLocalized);
52 bool operator==(
const LocalizedState &
X)
const {
return K == X.K; }
55 void Profile(llvm::FoldingSetNodeID &
ID)
const { ID.AddInteger(K); }
58 class NonLocalizedStringChecker
59 :
public Checker<check::PreCall, check::PostCall, check::PreObjCMessage,
60 check::PostObjCMessage,
61 check::PostStmt<ObjCStringLiteral>> {
63 mutable std::unique_ptr<BugType> BT;
67 llvm::DenseMap<Selector, uint8_t>> UIMethods;
69 mutable llvm::SmallSet<std::pair<const IdentifierInfo *, Selector>, 12> LSM;
71 mutable llvm::SmallSet<const IdentifierInfo *, 5> LSF;
74 void initLocStringsMethods(
ASTContext &Ctx)
const;
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;
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;
86 int getLocalizedArgumentForSelector(
const IdentifierInfo *Receiver,
90 NonLocalizedStringChecker();
95 DefaultBool IsAggressive;
97 void checkPreObjCMessage(
const ObjCMethodCall &msg, CheckerContext &C)
const;
98 void checkPostObjCMessage(
const ObjCMethodCall &msg, CheckerContext &C)
const;
100 void checkPreCall(
const CallEvent &Call, CheckerContext &C)
const;
101 void checkPostCall(
const CallEvent &Call, CheckerContext &C)
const;
109 NonLocalizedStringChecker::NonLocalizedStringChecker() {
110 BT.reset(
new BugType(
this,
"Unlocalizable string",
111 "Localizability Issue (Apple)"));
117 const MemRegion *NonLocalizedString;
121 NonLocalizedStringBRVisitor(
const MemRegion *NonLocalizedString)
122 : NonLocalizedString(NonLocalizedString), Satisfied(
false) {
123 assert(NonLocalizedString);
127 BugReporterContext &BRC,
128 PathSensitiveBugReport &BR)
override;
130 void Profile(llvm::FoldingSetNodeID &
ID)
const override {
131 ID.Add(NonLocalizedString);
136 #define NEW_RECEIVER(receiver) \ 137 llvm::DenseMap<Selector, uint8_t> &receiver##M = \ 138 UIMethods.insert({&Ctx.Idents.get(#receiver), \ 139 llvm::DenseMap<Selector, uint8_t>()}) \ 141 #define ADD_NULLARY_METHOD(receiver, method, argument) \ 142 receiver##M.insert( \ 143 {Ctx.Selectors.getNullarySelector(&Ctx.Idents.get(#method)), argument}); 144 #define ADD_UNARY_METHOD(receiver, method, argument) \ 145 receiver##M.insert( \ 146 {Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(#method)), argument}); 147 #define ADD_METHOD(receiver, method_list, count, argument) \ 148 receiver##M.insert({Ctx.Selectors.getSelector(count, method_list), argument}); 152 void NonLocalizedStringChecker::initUIMethods(
ASTContext &Ctx)
const {
153 if (!UIMethods.empty())
164 ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemTag, 3, 0)
168 ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemImage, 3, 0)
181 ADD_METHOD(UITableViewRowAction, rowActionWithStyleUITableViewRowAction, 3, 1)
193 ADD_METHOD(NSButton, radioButtonWithTitleNSButton, 3, 0)
197 ADD_METHOD(NSButton, buttonWithTitleNSButtonImage, 4, 0)
201 ADD_METHOD(NSButton, checkboxWithTitleNSButton, 3, 0)
205 ADD_METHOD(NSButton, buttonWithTitleNSButtonTarget, 3, 0)
224 ADD_METHOD(NSBrowser, setTitleNSBrowser, 2, 0)
235 ADD_METHOD(UIAlertAction, actionWithTitleUIAlertAction, 3, 0)
241 ADD_METHOD(NSPopUpButton, insertItemWithTitleNSPopUpButton, 2, 0)
250 ADD_METHOD(NSTableViewRowAction, rowActionWithStyleNSTableViewRowAction, 3, 1)
282 ADD_METHOD(NSSegmentedControl, setLabelNSSegmentedControl, 2, 0)
285 ADD_METHOD(NSSegmentedControl, setToolTipNSSegmentedControl, 2, 0)
310 ADD_METHOD(NSMatrix, setToolTipNSMatrix, 2, 0)
326 ADD_METHOD(UIMenuItem, initWithTitleUIMenuItem, 2, 0)
333 ADD_METHOD(UIAlertController, alertControllerWithTitleUIAlertController, 3, 1)
343 initWithTypeUIApplicationShortcutItemIcon, 5, 1)
346 ADD_METHOD(UIApplicationShortcutItem, initWithTypeUIApplicationShortcutItem,
353 &Ctx.
Idents.
get(
"destructiveButtonTitle"),
355 ADD_METHOD(UIActionSheet, initWithTitleUIActionSheet, 5, 0)
364 initWithNameUIAccessibilityCustomAction, 3, 0)
391 ADD_METHOD(NSAttributedString, initWithStringNSAttributedString, 2, 0)
400 ADD_METHOD(UIKeyCommand, keyCommandWithInputUIKeyCommand, 4, 3)
410 &Ctx.
Idents.
get(
"informativeTextWithFormat")};
411 ADD_METHOD(NSAlert, alertWithMessageTextNSAlert, 5, 0)
430 ADD_METHOD(NSWindow, minFrameWidthWithTitleNSWindow, 2, 0)
437 IdentifierInfo *addOptionWithTitleUIDocumentMenuViewController[] = {
441 addOptionWithTitleUIDocumentMenuViewController, 4, 0)
453 ADD_METHOD(UIAlertView, initWithTitleUIAlertView, 5, 0)
483 ADD_METHOD(NSSegmentedCell, setLabelNSSegmentedCell, 2, 0)
486 ADD_METHOD(NSSegmentedCell, setToolTipNSSegmentedCell, 2, 0)
497 ADD_METHOD(NSMenuItem, initWithTitleNSMenuItem, 3, 0)
504 ADD_METHOD(NSPopUpButtonCell, initTextCellNSPopUpButtonCell, 2, 0)
508 ADD_METHOD(NSPopUpButtonCell, insertItemWithTitleNSPopUpButtonCell, 2, 0)
521 ADD_METHOD(NSMenu, insertItemWithTitleNSMenu, 4, 0)
525 ADD_METHOD(NSMenu, addItemWithTitleNSMenu, 3, 0)
541 IdentifierInfo *actionWithIdentifierNSUserNotificationAction[] = {
544 actionWithIdentifierNSUserNotificationAction, 2, 1)
554 ADD_METHOD(UIBarButtonItem, initWithTitleUIBarButtonItem, 4, 0)
563 ADD_METHOD(UISegmentedControl, insertSegmentWithTitleUISegmentedControl, 3, 0)
566 ADD_METHOD(UISegmentedControl, setTitleUISegmentedControl, 2, 0)
570 *initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult[] = {
571 &Ctx.
Idents.
get(
"initWithItemLoadingToken"),
573 ADD_METHOD(NSAccessibilityCustomRotorItemResult,
574 initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult, 2, 1)
581 ADD_METHOD(UIContextualAction, contextualActionWithStyleUIContextualAction, 3,
589 initWithLabelNSAccessibilityCustomRotor, 2, 0)
600 initWithNameNSAccessibilityCustomAction, 2, 0)
601 IdentifierInfo *initWithNameTargetNSAccessibilityCustomAction[] = {
605 initWithNameTargetNSAccessibilityCustomAction, 3, 0)
609 #define LSF_INSERT(function_name) LSF.insert(&Ctx.Idents.get(function_name)); 610 #define LSM_INSERT_NULLARY(receiver, 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) \ 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) \ 617 LSM.insert({&Ctx.Idents.get(receiver), \ 618 Ctx.Selectors.getSelector(arguments, method_list)}); 621 void NonLocalizedStringChecker::initLocStringsMethods(
ASTContext &Ctx)
const {
639 LSF_INSERT(
"CFDateFormatterCreateStringWithDate");
640 LSF_INSERT(
"CFDateFormatterCreateStringWithAbsoluteTime");
641 LSF_INSERT(
"CFNumberFormatterCreateStringWithNumber");
646 bool NonLocalizedStringChecker::isAnnotatedAsReturningLocalized(
647 const Decl *D)
const {
653 return Ann->getAnnotation() ==
"returns_localized_nsstring";
659 bool NonLocalizedStringChecker::isAnnotatedAsTakingLocalized(
660 const Decl *D)
const {
666 return Ann->getAnnotation() ==
"takes_localized_nsstring";
671 bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
672 CheckerContext &C)
const {
673 const MemRegion *mt = S.getAsRegion();
675 const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);
676 if (LS && LS->isLocalized())
684 bool NonLocalizedStringChecker::hasNonLocalizedState(SVal S,
685 CheckerContext &C)
const {
686 const MemRegion *mt = S.getAsRegion();
688 const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);
689 if (LS && LS->isNonLocalized())
696 void NonLocalizedStringChecker::setLocalizedState(
const SVal S,
697 CheckerContext &C)
const {
698 const MemRegion *mt = S.getAsRegion();
701 C.getState()->set<LocalizedMemMap>(mt, LocalizedState::getLocalized());
702 C.addTransition(State);
707 void NonLocalizedStringChecker::setNonLocalizedState(
const SVal S,
708 CheckerContext &C)
const {
709 const MemRegion *mt = S.getAsRegion();
712 mt, LocalizedState::getNonLocalized());
713 C.addTransition(State);
719 return StringRef(name).lower().find(
"debug") != StringRef::npos;
727 const Decl *D = C.getCurrentAnalysisDeclContext()->getDecl();
731 if (
auto *ND = dyn_cast<NamedDecl>(D)) {
738 if (
auto *CD = dyn_cast<ObjCContainerDecl>(DC)) {
748 void NonLocalizedStringChecker::reportLocalizationError(
749 SVal S,
const CallEvent &M, CheckerContext &C,
int argumentNumber)
const {
756 static CheckerProgramPointTag Tag(
"NonLocalizedStringChecker",
757 "UnlocalizedString");
758 ExplodedNode *ErrNode = C.addTransition(C.getState(), C.getPredecessor(), &Tag);
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());
769 R->addRange(M.getSourceRange());
771 R->markInteresting(S);
773 const MemRegion *StringRegion = S.getAsRegion();
775 R->addVisitor(std::make_unique<NonLocalizedStringBRVisitor>(StringRegion));
777 C.emitReport(std::move(R));
782 int NonLocalizedStringChecker::getLocalizedArgumentForSelector(
784 auto method = UIMethods.find(Receiver);
786 if (method == UIMethods.end())
789 auto argumentIterator = method->getSecond().find(S);
791 if (argumentIterator == method->getSecond().end())
794 int argumentNumber = argumentIterator->getSecond();
795 return argumentNumber;
799 void NonLocalizedStringChecker::checkPreObjCMessage(
const ObjCMethodCall &msg,
800 CheckerContext &C)
const {
801 initUIMethods(C.getASTContext());
811 StringRef SelectorName = SelectorString;
812 assert(!SelectorName.empty());
814 if (odInfo->
isStr(
"NSString")) {
818 if (!(SelectorName.startswith(
"drawAtPoint") ||
819 SelectorName.startswith(
"drawInRect") ||
820 SelectorName.startswith(
"drawWithRect")))
825 bool isNonLocalized = hasNonLocalizedState(svTitle, C);
827 if (isNonLocalized) {
828 reportLocalizationError(svTitle, msg, C);
832 int argumentNumber = getLocalizedArgumentForSelector(odInfo, S);
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)
840 if (argumentNumber < 0) {
841 OD = OD->getSuperClass();
842 argumentNumber = getLocalizedArgumentForSelector(OD->getIdentifier(), S);
846 if (argumentNumber < 0) {
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])) {
860 if (argumentNumber < 0)
863 SVal svTitle = msg.getArgSVal(argumentNumber);
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) ||
872 if (!IsAggressive && llvm::sys::unicode::columnWidthUTF8(stringValue) < 2)
876 bool isNonLocalized = hasNonLocalizedState(svTitle, C);
878 if (isNonLocalized) {
879 reportLocalizationError(svTitle, msg, C, argumentNumber + 1);
883 void NonLocalizedStringChecker::checkPreCall(
const CallEvent &Call,
884 CheckerContext &C)
const {
885 const auto *FD = dyn_cast_or_null<FunctionDecl>(Call.getDecl());
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);
914 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
915 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
923 void NonLocalizedStringChecker::checkPostCall(
const CallEvent &Call,
924 CheckerContext &C)
const {
925 initLocStringsMethods(C.getASTContext());
927 if (!Call.getOriginExpr())
933 const QualType RT = Call.getResultType();
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);
945 const Decl *D = Call.getDecl();
951 SVal sv = Call.getReturnValue();
952 if (isAnnotatedAsReturningLocalized(D) || LSF.count(Identifier) != 0) {
953 setLocalizedState(sv, C);
955 !hasLocalizedState(sv, C)) {
957 setNonLocalizedState(sv, C);
959 const SymbolicRegion *SymReg =
960 dyn_cast_or_null<SymbolicRegion>(sv.getAsRegion());
962 setNonLocalizedState(sv, C);
969 void NonLocalizedStringChecker::checkPostObjCMessage(
const ObjCMethodCall &msg,
970 CheckerContext &C)
const {
971 initLocStringsMethods(C.getASTContext());
984 std::pair<const IdentifierInfo *, Selector> MethodDescription = {odInfo, S};
986 if (LSM.count(MethodDescription) ||
987 isAnnotatedAsReturningLocalized(msg.
getDecl())) {
988 SVal sv = msg.getReturnValue();
989 setLocalizedState(sv, C);
995 CheckerContext &C)
const {
996 SVal sv = C.getSVal(SL);
997 setNonLocalizedState(sv, C);
1001 NonLocalizedStringBRVisitor::VisitNode(
const ExplodedNode *Succ,
1002 BugReporterContext &BRC,
1003 PathSensitiveBugReport &BR) {
1008 if (!Point.hasValue())
1015 SVal LiteralSVal = Succ->getSVal(LiteralExpr);
1016 if (LiteralSVal.getAsRegion() != NonLocalizedString)
1021 PathDiagnosticLocation L =
1024 if (!L.isValid() || !L.asLocation().isValid())
1027 auto Piece = std::make_shared<PathDiagnosticEventPiece>(
1028 L,
"Non-localized string literal here");
1029 Piece->addRange(LiteralExpr->getSourceRange());
1031 return std::move(Piece);
1035 class EmptyLocalizationContextChecker
1036 :
public Checker<check::ASTDecl<ObjCImplementationDecl>> {
1042 AnalysisManager &Mgr;
1043 const CheckerBase *Checker;
1048 const CheckerBase *Checker, AnalysisManager &InMgr,
1050 : MD(InMD), BR(InBR), Mgr(InMgr), Checker(Checker), DCtx(InDCtx) {}
1052 void VisitStmt(
const Stmt *S) { VisitChildren(S); }
1058 void VisitChildren(
const Stmt *S) {
1068 BugReporter &BR)
const;
1072 void EmptyLocalizationContextChecker::checkASTDecl(
1074 BugReporter &BR)
const {
1079 const Stmt *Body = M->getBody();
1081 assert(M->isSynthesizedAccessorStub());
1085 MethodCrawler MC(M->getCanonicalDecl(), BR,
this, Mgr, DCtx);
1105 void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
1116 if (!(odInfo->
isStr(
"NSBundle") &&
1118 "localizedStringForKey:value:table:")) {
1130 Mgr.getSourceManager().getImmediateMacroCallerLoc(R.
getBegin());
1131 std::pair<FileID, unsigned> SLInfo =
1132 Mgr.getSourceManager().getDecomposedLoc(SL);
1140 SLInfo = Mgr.getSourceManager().getDecomposedLoc(SL);
1141 SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
1144 bool Invalid =
false;
1145 const llvm::MemoryBuffer *BF =
1146 Mgr.getSourceManager().getBuffer(SLInfo.first, SL, &Invalid);
1151 BF->getBufferStart() + SLInfo.second, BF->getBufferEnd());
1156 while (!TheLexer.LexFromRawLexer(I)) {
1157 if (I.getKind() == tok::l_paren)
1159 if (I.getKind() == tok::r_paren) {
1169 reportEmptyContextError(ME);
1180 if ((Comment.trim().size() == 0 && Comment.size() > 0) ||
1182 reportEmptyContextError(ME);
1186 void EmptyLocalizationContextChecker::MethodCrawler::reportEmptyContextError(
1189 BR.EmitBasicReport(MD, Checker,
"Context Missing",
1190 "Localizability Issue (Apple)",
1191 "Localized string macro should include a non-empty " 1192 "comment for translators",
1193 PathDiagnosticLocation(ME, BR.getSourceManager(), DCtx));
1197 class PluralMisuseChecker :
public Checker<check::ASTCodeBody> {
1202 const CheckerBase *Checker;
1211 bool InMatchingStatement =
false;
1214 explicit MethodCrawler(BugReporter &InBR,
const CheckerBase *Checker,
1216 : BR(InBR), Checker(Checker), AC(InAC) {}
1218 bool VisitIfStmt(
const IfStmt *I);
1219 bool EndVisitIfStmt(
IfStmt *I);
1220 bool TraverseIfStmt(
IfStmt *x);
1223 bool VisitCallExpr(
const CallExpr *CE);
1227 void reportPluralMisuseError(
const Stmt *S)
const;
1228 bool isCheckingPlurality(
const Expr *E)
const;
1232 void checkASTCodeBody(
const Decl *D, AnalysisManager &Mgr,
1233 BugReporter &BR)
const {
1234 MethodCrawler Visitor(BR,
this, Mgr.getAnalysisDeclContext(D));
1235 Visitor.TraverseDecl(const_cast<Decl *>(D));
1244 bool PluralMisuseChecker::MethodCrawler::isCheckingPlurality(
1245 const Expr *Condition)
const {
1248 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Condition)) {
1249 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
1250 const Expr *InitExpr = VD->getInit();
1257 if (VD->getName().lower().find(
"plural") != StringRef::npos ||
1258 VD->getName().lower().find(
"singular") != StringRef::npos) {
1262 }
else if (
const BinaryOperator *B = dyn_cast<BinaryOperator>(Condition)) {
1272 if (Value == 1 || Value == 2) {
1283 bool PluralMisuseChecker::MethodCrawler::VisitCallExpr(
const CallExpr *CE) {
1284 if (InMatchingStatement) {
1286 std::string NormalizedName =
1287 StringRef(FD->getNameInfo().getAsString()).lower();
1288 if (NormalizedName.find(
"loc") != std::string::npos) {
1290 if (isa<ObjCStringLiteral>(Arg))
1291 reportPluralMisuseError(CE);
1304 bool PluralMisuseChecker::MethodCrawler::VisitObjCMessageExpr(
1312 if (odInfo->
isStr(
"NSBundle") &&
1314 if (InMatchingStatement) {
1315 reportPluralMisuseError(ME);
1322 bool PluralMisuseChecker::MethodCrawler::TraverseIfStmt(
IfStmt *I) {
1324 return EndVisitIfStmt(I);
1330 bool PluralMisuseChecker::MethodCrawler::EndVisitIfStmt(
IfStmt *I) {
1331 MatchingStatements.pop_back();
1332 if (!MatchingStatements.empty()) {
1333 if (MatchingStatements.back() !=
nullptr) {
1334 InMatchingStatement =
true;
1338 InMatchingStatement =
false;
1342 bool PluralMisuseChecker::MethodCrawler::VisitIfStmt(
const IfStmt *I) {
1344 if (isCheckingPlurality(Condition)) {
1345 MatchingStatements.push_back(I);
1346 InMatchingStatement =
true;
1348 MatchingStatements.push_back(
nullptr);
1349 InMatchingStatement =
false;
1356 bool PluralMisuseChecker::MethodCrawler::TraverseConditionalOperator(
1359 MatchingStatements.pop_back();
1360 if (!MatchingStatements.empty()) {
1361 if (MatchingStatements.back() !=
nullptr)
1362 InMatchingStatement =
true;
1364 InMatchingStatement =
false;
1366 InMatchingStatement =
false;
1371 bool PluralMisuseChecker::MethodCrawler::VisitConditionalOperator(
1374 if (isCheckingPlurality(Condition)) {
1375 MatchingStatements.push_back(C);
1376 InMatchingStatement =
true;
1378 MatchingStatements.push_back(
nullptr);
1379 InMatchingStatement =
false;
1384 void PluralMisuseChecker::MethodCrawler::reportPluralMisuseError(
1385 const Stmt *S)
const {
1387 BR.EmitBasicReport(AC->getDecl(), Checker,
"Plural Misuse",
1388 "Localizability Issue (Apple)",
1389 "Plural cases are not supported across all languages. " 1390 "Use a .stringsdict file instead",
1391 PathDiagnosticLocation(S, BR.getSourceManager(), AC));
1398 void ento::registerNonLocalizedStringChecker(CheckerManager &mgr) {
1399 NonLocalizedStringChecker *checker =
1400 mgr.registerChecker<NonLocalizedStringChecker>();
1401 checker->IsAggressive =
1402 mgr.getAnalyzerOptions().getCheckerBooleanOption(
1403 checker,
"AggressiveReport");
1406 bool ento::shouldRegisterNonLocalizedStringChecker(
const LangOptions &LO) {
1410 void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {
1411 mgr.registerChecker<EmptyLocalizationContextChecker>();
1414 bool ento::shouldRegisterEmptyLocalizationContextChecker(
1419 void ento::registerPluralMisuseChecker(CheckerManager &mgr) {
1420 mgr.registerChecker<PluralMisuseChecker>();
1423 bool ento::shouldRegisterPluralMisuseChecker(
const LangOptions &LO) {
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...
std::shared_ptr< PathDiagnosticPiece > PathDiagnosticPieceRef
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
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
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...
__DEVICE__ int min(int __a, int __b)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
A reference to a declared variable, function, enum, etc.
#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.