[cfe-dev] Where to put upcoming refcatoring tools

Stephen Kelly steveire at gmail.com
Wed Apr 25 09:56:30 PDT 2012


Stephen Kelly wrote:

> Manuel Klimek wrote:
>> 
>> Does
>> Expresssion(AllOf(
>>   HasType(...),
>>   Not(ImplicitCast())
>> work?
>> 
> 
> Unfortunately not. The Not(ImplicitCast()) also makes no difference.
> 
> I tried adding a ConstructorCall() in there too, guessing that would match
> the implicit ctor calls, but that just excluded all matches from the
> result.
> 
> I put a call to Arg->dump() in my MatchCallback implementation. It doesn't
> help me, but maybe you can see how I need to define my match with that? My
> input is this now:
> 
>     Qt::escape("foo");
>     QString foo("bar");
>     Qt::escape(foo);
>     QObject o;
>     Qt::escape(o.objectName());
>     Qt::escape(o.property("foo").toByteArray());

I found that I could use this to not match the Qt::escape(foo); case.

  Finder.addMatcher(
      Id("call",
        Call(
          Callee(Function(HasName("::Qt::escape"))),
          HasArgument(
            0,
            Id("arg", BindTemporaryExpression())
          )
        )
      ),
      &Callback);
  
I eventually figured out how to limit it to only the case without 
temporaries:

  Finder.addMatcher(
      Id("call",
        Call(
          Callee(Function(HasName("::Qt::escape"))),
          Not(HasArgument(
            0,
            Id("arg", BindTemporaryExpression())
          )),
          HasArgument(
            0,
            Id("arg", Expression())
          )
        )
      ),
      &Callback);

I tried many other variations using Not, which I can try to list if you're 
interested in considering the self-documenting nature of the API.

To match the string literal, I used:

  Finder.addMatcher(
      Id("call",
        Call(
          Callee(Function(HasName("::Qt::escape"))),
          HasArgument(
            0,
            Id("arg", BindTemporaryExpression())
          ),
          Not(hasDescendant(MemberExpression()))
        )
      ),
      &Callback);

I could not use this as it gives no results:

  Finder.addMatcher(
      Id("call",
        Call(
          Callee(Function(HasName("::Qt::escape"))),
          HasArgument(
            0,
            Id("arg", BindTemporaryExpression())
          ),
          ast_matchers::StringLiteral()
        )
      ),
      &Callback);


And this one does not build:

  Finder.addMatcher(
      Id("call",
        Call(
          Callee(Function(HasName("::Qt::escape"))),
          HasArgument(
            0,
            Id("arg", BindTemporaryExpression())
          ),
          Not(hasDescendant(ast_matchers::StringLiteral()))
        )
      ),
      &Callback);


Finally this matches the member calls:

  Finder.addMatcher(
      Id("call",
        Call(
          Callee(Function(HasName("::Qt::escape"))),
          HasArgument(
            0,
            BindTemporaryExpression()
          ),
          hasDescendant(Id("arg", MemberExpression()))
        )
      ),
      &Callback);

But I do not get the parentheses or the arguments inside them in the result 
(if any). I aslo presume this would not match a call of a free function, so 
I would need more matchers for those cases? It's already getting quite 
exhaustive and less scalable.

It seems either I'm missing something or the tooling is not ready to handle 
the cases I'm trying to achieve?

Thanks,

Steve.






More information about the cfe-dev mailing list