Details
Diff Detail
- Repository
- rCTE Clang Tools Extra
- Build Status
Buildable 14323 Build 14323: arc lint + arc unit
Event Timeline
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
62–76 | Instead of bool isCategory, how about an enum NamingStyle: enum NamingStyle { StandardProperty = 1, CategoryProperty = 2, } | |
112 | I think this is an off-by-one error, right? Change: i < PropertyName.size() - 1 to i < PropertyName.size() | |
113–115 | Do we really want a leading _ to count? I think this might need to be a regular expression instead, something like: ^[a-zA-Z][a-zA-Z0-9]+_[a-zA-Z0-9][a-zA-Z0-9_]*$ | |
130 | I don't understand what this is doing. Why are we replacing things in a regex? I don't think this is very maintainable. Can you rewrite it for legibility, please? | |
151 | Is a class extension treated as a category? If so, we probably need to treat it specially. e.g.: Foo.h: @interface Foo @end Foo.m: @interface Foo () @property (nonatomic, readonly) int foo_bar; @end should not be allowed. Can you handle this and add tests, please? |
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
112 | I was thinking of not letting go anything that ends with "_" otherwise I have to do more sanity check later. | |
113–115 | Yes it is better to use a regex instead. I would use ^[a-z]+_[a-zA-Z0-9][a-zA-Z0-9_]+$ to make sure we are not having anything like foo_ | |
130 | It is a little awkward here because in the matcher, the regex use "::" to indicate matching start, but in llvm::regex it is the conventional "^". I will add some comments here. |
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
130 | End up using a bool since it is not about naming style but whether we are using it in matcher or normal regex match. |
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
28 | Please add documentation describing what these properties are. | |
57–58 | Do we need to update the documentation here? it seems stale now? | |
81–89 | Also add documentation for the method as well as parameters. It is a bit hard to follow the logic. | |
97 | Does the comment still make sense? Seems you changed the regex below. | |
119 | no need to pass const reference of llvm::StringRef. StringRef is cheap. | |
120 | nit: use llvm::ArrayRef<std::string> would save a lot of keystroke. | |
122 | we can use find_first_not_of or something similar. | |
153 | Consider using const auto* CategoryDecl = dyn_cast<ObjCCategoryDecl*>(DeclContext), we can get rid of this cast, and NodeKind variable. |
update some documents and comments
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
97 | Yes they are actually the same. I am just replacing the prefix "::" with "^" according to the UsedInMatcher param. | |
119 | The original property name I directly get from ast is a const. If I remove the const here, I will have to make a copy of the property name before calling this. | |
153 | Tried that before but I encountered 2 issues:
which are preventing me from using dynamic_cast |
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
67 | I think we save this code by using find_first_of and llvm::StringRef::tolower() function. | |
88 | The same, ArrayRef. | |
114 | The same: llvm::StringRef | |
119 | Why? MatchedDecl->getName() returns llvm::StringRef. As the name indicates, StringRef is a const reference of String, using StringRef is sufficient. The same to ArrayRef. So the function is like bool prefixedPropertyNameMatches(llvm::StringRef PropertyName, llvm::ArrayRef<std::string> Acronyms). | |
153 | Sorry, I mean llvm::dyn_cast here, it should work. | |
156 | Do we need it? I think you can pass SpecialAcronyms directly. |
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
114 | Cannot remove the const for the same reason. | |
119 | If I remove the const in the method, compiler will have error of "candidate function not viable: expects an l-value for 1st argument". I believe it cannot accept a const reference as arg if the definition is var. | |
153 | It is not working either. It says "error: static_cast from 'clang::Decl *' to 'const clang::ObjCCategoryDecl *const *' is not allowed" though I have no idea why it is regarded as a static cast. |
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
119 | I think hokein@ is saying you should change: const llvm::StringRef & to: llvm::StringRef Note removing both const and &, not just removing const. This is because there is no need to pass these by reference, they are already a reference. Same with const llvm::ArrayRef &, it should just be llvm::ArrayRef. | |
125 | No need to construct another llvm::StringRef(), StringRef::substr() returns a StringRef already. | |
153 | You definitely don't want to use a C-style cast. My guess is adding const is not part of what dyn_cast<> does, so you can probably remove that from the dyn_cast<>. (You can of course assign to a const pointer if you want.) |
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
122 | Can you also check that Start + 1 < PropertyName.length() (e.g., the string doesn't end with a _)? I know the regular expression shouldn't match this, so an assert is probably good. (There is logic later which tries to access Start + 1 without checking.) | |
128 | Don't need to explicitly wrap in llvm::StringRef, that class has an implicit constructor from std::string. https://github.com/llvm-mirror/llvm/blob/master/include/llvm/ADT/StringRef.h#L95 | |
test/clang-tidy/objc-property-declaration.m | ||
15–31 | Can we add checks for properties whose names end with _? |
clang-tidy/objc/PropertyDeclarationCheck.cpp | ||
---|---|---|
153 | Finally figured out that I cannot put pointer type in dyn_cast<>. It needs to be "llvm::dyn_cast<ObjCCategoryDecl>(DeclContext)" even though DeclContext is a pointer. I have to say it is weird in C++... | |
156 | It is not about acronyms but determine how to generate the fix. It will save me from checking the naming format again when generating the fix hint. |
Please add documentation describing what these properties are.