[PATCH] D19876: Add an AST matcher for string-literal length
Etienne Bergeron via cfe-commits
cfe-commits at lists.llvm.org
Wed May 4 10:52:57 PDT 2016
etienneb added a comment.
Aaron? could you comment on it?
================
Comment at: include/clang/ASTMatchers/ASTMatchers.h:1575
@@ +1574,3 @@
+/// \code
+/// char *s = "abcd"; wchar_t *ws = L"abcd";
+/// char *t = "a";
----------------
aaron.ballman wrote:
> Split these onto two lines?
If I look around, it seems to be more consistent to keep it on the same line (line 1563)
```
/// char *s = "abcd"; wchar_t *ws = L"abcd";
```
```
/// int array[4] = {1}; vector int myvec = (vector int)(1, 2);
```
```
/// char ch = 'a'; wchar_t chw = L'a';
``
================
Comment at: include/clang/ASTMatchers/ASTMatchers.h:1578
@@ +1577,3 @@
+/// \endcode
+AST_MATCHER_P(StringLiteral, lengthIs, unsigned, N) {
+ return Node.getLength() == N;
----------------
etienneb wrote:
> aaron.ballman wrote:
> > Perhaps we can adjust the `hasSize()` matcher instead? It currently works with ConstantArrayType, but it seems reasonable for it to also work with StringLiteral.
> I didn't like the term "size" as it typically refer to the size in bytes.
> Which is not the same for a wide-string.
>
> Now, there is two different convention for naming matchers:
> hasLength and lengthIs ?
>
> Any toughs on that?
>
>
Here is the matcher for hasSize
```
AST_MATCHER_P(ConstantArrayType, hasSize, unsigned, N) {
return Node.getSize() == N;
}
```
It's getting the getSize attribute. I believe we should stick with the name of the attribute.
But, I'm not sure if we should use hasLength, or lengthIs.
http://reviews.llvm.org/D19876
More information about the cfe-commits
mailing list