Question about ASTMatcher `typeAliasTemplateDecl` for gsl::owner

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about ASTMatcher `typeAliasTemplateDecl` for gsl::owner

Sumner, Brian via cfe-dev
Hello everybody,

iam working on a clang-tidy-check to handle gsl::owner, at least i try to.
What iam doing right now, is trying to get the Matchers done and here is
what I have as testcode for experimentation.

namespace gsl {
template<typename T> using owner = T;
}

template<typename T> class vector {};
template<typename T> using heap_array = vector<T>;

using file = int;

void f() {
    gsl::owner<int*> owner = new int(10);

    int i = 0;
    int* no_owner = &i;
    int** no_owner_at_all = &no_owner;

    file n = 15;

    heap_array<int> array;
}

// match varDecl(hasType(hasDeclaration(typeAliasDecl())))  # works for file
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl())))  #
works for file
// match varDecl(hasType(hasDeclaration(typedefNameDecl())))  # works
for file
// match
varDecl(hasType(hasDeclaration(typedefNameDecl(hasName("file"))))) #
works as well, matching the declaration
//
// match typeAliasTemplateDecl() # gets all declaration
// match typeAliasTemplateDecl(hasName("::gsl::owner")) # gets the
declaration right
// match typeAliasTemplateDecl(hasName("heap_array"))   # gets the
declaration right
//
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl()))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner<int
*>"))))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array<int>")))))
# nothing

Matching Variables, Parameters and so on for Using-Aliases seems to work
fine, but not for Templated Aliases.
I tested these, with the current clang-query from Trunk.

Is the way, iam approaching the matcher incorrect or is it some kind of
bug in typeAliasTemplateDecl?

Thank you very much for your help :)

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about ASTMatcher `typeAliasTemplateDecl` for gsl::owner

Sumner, Brian via cfe-dev
This is actually a problem with hasDeclaration; I realized that I hadn't submitted https://reviews.llvm.org/D27104 yet; I now adapted it to also solve your problem (as this was simpler than fixing the current code).

On Wed, Jul 26, 2017 at 12:02 PM Jonas Toth via cfe-dev <[hidden email]> wrote:
Hello everybody,

iam working on a clang-tidy-check to handle gsl::owner, at least i try to.
What iam doing right now, is trying to get the Matchers done and here is
what I have as testcode for experimentation.

namespace gsl {
template<typename T> using owner = T;
}

template<typename T> class vector {};
template<typename T> using heap_array = vector<T>;

using file = int;

void f() {
    gsl::owner<int*> owner = new int(10);

    int i = 0;
    int* no_owner = &i;
    int** no_owner_at_all = &no_owner;

    file n = 15;

    heap_array<int> array;
}

// match varDecl(hasType(hasDeclaration(typeAliasDecl())))  # works for file
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl())))  #
works for file
// match varDecl(hasType(hasDeclaration(typedefNameDecl())))  # works
for file
// match
varDecl(hasType(hasDeclaration(typedefNameDecl(hasName("file"))))) #
works as well, matching the declaration
//
// match typeAliasTemplateDecl() # gets all declaration
// match typeAliasTemplateDecl(hasName("::gsl::owner")) # gets the
declaration right
// match typeAliasTemplateDecl(hasName("heap_array"))   # gets the
declaration right
//
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl()))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner<int
*>"))))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array<int>")))))
# nothing

Matching Variables, Parameters and so on for Using-Aliases seems to work
fine, but not for Templated Aliases.
I tested these, with the current clang-query from Trunk.

Is the way, iam approaching the matcher incorrect or is it some kind of
bug in typeAliasTemplateDecl?

Thank you very much for your help :)

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about ASTMatcher `typeAliasTemplateDecl` for gsl::owner

Sumner, Brian via cfe-dev
Great, thanks! 
I will continue the check for owner then.

Regards, Jonas :)

Am 28.07.2017 11:28 vorm. schrieb "Manuel Klimek" <[hidden email]>:
This is actually a problem with hasDeclaration; I realized that I hadn't submitted https://reviews.llvm.org/D27104 yet; I now adapted it to also solve your problem (as this was simpler than fixing the current code).

On Wed, Jul 26, 2017 at 12:02 PM Jonas Toth via cfe-dev <[hidden email]> wrote:
Hello everybody,

iam working on a clang-tidy-check to handle gsl::owner, at least i try to.
What iam doing right now, is trying to get the Matchers done and here is
what I have as testcode for experimentation.

namespace gsl {
template<typename T> using owner = T;
}

template<typename T> class vector {};
template<typename T> using heap_array = vector<T>;

using file = int;

void f() {
    gsl::owner<int*> owner = new int(10);

    int i = 0;
    int* no_owner = &i;
    int** no_owner_at_all = &no_owner;

    file n = 15;

    heap_array<int> array;
}

// match varDecl(hasType(hasDeclaration(typeAliasDecl())))  # works for file
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl())))  #
works for file
// match varDecl(hasType(hasDeclaration(typedefNameDecl())))  # works
for file
// match
varDecl(hasType(hasDeclaration(typedefNameDecl(hasName("file"))))) #
works as well, matching the declaration
//
// match typeAliasTemplateDecl() # gets all declaration
// match typeAliasTemplateDecl(hasName("::gsl::owner")) # gets the
declaration right
// match typeAliasTemplateDecl(hasName("heap_array"))   # gets the
declaration right
//
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl()))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner<int
*>"))))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array<int>")))))
# nothing

Matching Variables, Parameters and so on for Using-Aliases seems to work
fine, but not for Templated Aliases.
I tested these, with the current clang-query from Trunk.

Is the way, iam approaching the matcher incorrect or is it some kind of
bug in typeAliasTemplateDecl?

Thank you very much for your help :)

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about ASTMatcher `typeAliasTemplateDecl` for gsl::owner

Sumner, Brian via cfe-dev
In reply to this post by Sumner, Brian via cfe-dev
The fixes are now in as of https://reviews.llvm.org/rL309809.

Cheers,
/Manuel

On Fri, Jul 28, 2017 at 11:27 AM Manuel Klimek <[hidden email]> wrote:
This is actually a problem with hasDeclaration; I realized that I hadn't submitted https://reviews.llvm.org/D27104 yet; I now adapted it to also solve your problem (as this was simpler than fixing the current code).

On Wed, Jul 26, 2017 at 12:02 PM Jonas Toth via cfe-dev <[hidden email]> wrote:
Hello everybody,

iam working on a clang-tidy-check to handle gsl::owner, at least i try to.
What iam doing right now, is trying to get the Matchers done and here is
what I have as testcode for experimentation.

namespace gsl {
template<typename T> using owner = T;
}

template<typename T> class vector {};
template<typename T> using heap_array = vector<T>;

using file = int;

void f() {
    gsl::owner<int*> owner = new int(10);

    int i = 0;
    int* no_owner = &i;
    int** no_owner_at_all = &no_owner;

    file n = 15;

    heap_array<int> array;
}

// match varDecl(hasType(hasDeclaration(typeAliasDecl())))  # works for file
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl())))  #
works for file
// match varDecl(hasType(hasDeclaration(typedefNameDecl())))  # works
for file
// match
varDecl(hasType(hasDeclaration(typedefNameDecl(hasName("file"))))) #
works as well, matching the declaration
//
// match typeAliasTemplateDecl() # gets all declaration
// match typeAliasTemplateDecl(hasName("::gsl::owner")) # gets the
declaration right
// match typeAliasTemplateDecl(hasName("heap_array"))   # gets the
declaration right
//
// match varDecl(hasType(hasDeclaration(typeAliasTemplateDecl()))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("owner")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("::gsl::owner<int
*>"))))) # nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array")))))
# nothing
// match
varDecl(hasType(hasDeclaration(typeAliasTemplateDecl(hasName("heap_array<int>")))))
# nothing

Matching Variables, Parameters and so on for Using-Aliases seems to work
fine, but not for Templated Aliases.
I tested these, with the current clang-query from Trunk.

Is the way, iam approaching the matcher incorrect or is it some kind of
bug in typeAliasTemplateDecl?

Thank you very much for your help :)

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...