Pour obtenir une clé
d'essai remplissez le formulaire ci-dessous
Demandez des tariffs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
* En cliquant sur ce bouton, vous acceptez notre politique de confidentialité

Free PVS-Studio license for Microsoft MVP specialists
To get the licence for your open-source project, please fill out this form
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

I am interested to try it on the platforms:
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

Votre message a été envoyé.

Nous vous répondrons à

Si vous n'avez toujours pas reçu de réponse, vérifiez votre dossier
Spam/Junk et cliquez sur le bouton "Not Spam".
De cette façon, vous ne manquerez la réponse de notre équipe.

SQL-like queries for C++ code: is this …

SQL-like queries for C++ code: is this the task for static analysis?

21 Nov 2012

Static analysis tools' users often wonder how to fulfill the task of searching for certain code fragments. For instance, how to find a function longer than 1000 lines; or how to find a class containing more than 100 methods; or which functions contain the largest (or the smallest) number of comments. Why do they want to know it?

There are different reasons for that:

  • Choosing methods and classes for further code refactoring.
  • Search of poorly documented or, vice versa, overdocumented functions.
  • Analyzing the changes of the project's statistical characteristics: the number of methods, classes, files.

At first sight, all these tasks seem to be the right target for static analysis: it's the static code analysis technology that can parse the whole code into smallest "bricks".

However, I suppose that static code analysis is intended for detecting errors in software, first of all. To be more exact, to detect fragments in program code to which the programmer should pay more attention to probably find an error. Although static analysis tools can answer SQL-like queries, they probably don't have to: there are tools intended for this particular purpose. For example, the CppDepend tool employs a special query language CQLinq (stands for "Code Query Linq"). As you can see from its name, this language (very much similar to Microsoft LINQ) allows you to create queries to the code base being analyzed.

Which public methods have size larger than 30 lines:

from m in Application.Methods  
where m.NbLinesOfCode >  30  && m.IsPublic
select m

Which classes inherit from a concrete class:

particular from t in Types 
where t.IsClass && t.DeriveFrom ("CBase") 
select t

Which complex methods are poorly commented:

from t in Types 
where t.IsClass && t.DeriveFrom ("CBase") 
select t

You can find a lot of examples of queries like the above mentioned on the webpage with the CQLinq description. They all are quite transparent and comprehensible. That's why when somebody asks me if static analysis can be used to find "methods that contain ...", I answer at once: "Static analysis is not quite the right thing to fulfill such tasks. You'd better try CQLinq in CppDepend".

Comments (0)

Next comments
Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus