Text and Comment Counting

Text and comment counting is defined in counting.xml file(s) of Squore Analyzer Data Provider configuration.

Counting can be defined per languages, for all languages or both. Below are the folders where counting.xml file(s) must be stored for each scenario:

  • One file per language in "<SQUORE_HOME>/configuration/tools/SQuORE/Analyzer/measures/<language>" folders.

  • One file for all languages in "<SQUORE_HOME>/configuration/tools/SQuORE/Analyzer/measures/shared" folder.

Your modifications to the default configuration should never be made directly in <SQUORE_HOME>/configuration folder. But instead in your own configuration folder , of which you will make Squore aware by editing <SQUORE_HOME>/config.xml file.

This allows you to create only the files that are needed for your modifications and minimize the amount of files to be added to version control.

By overloading this file in your custom configuration, it is possible to adapt and complete the counting mechanism in order to best fit your internal requirements.

The file syntax is the following:

<configuration>
   <!-- Measures -->
   <!-- Count the number of times the pattern is matched in CODE -->
   <measure measureId="GTO" pattern="\bgoto\b" scope="CODE"/>

   <!-- Count the number of times the pattern is matched in COMMENT -->
   <measure measureId="DUMMY" pattern="DUMMY COUNTING\s" scope="COMMENT"/>

   <!-- Rules -->
   <!-- Rules on text recognition specification -->
   <!-- Each time some text on a line matches the pattern, a finding is reported on the line -->
   <rule ruleId="R_NOTODO" pattern="\bTODO\b" scope="COMMENT"/>

   <!-- Call Graph Measures - available only for C language -->
   <!-- Count the number of calls made for all functions matching the pattern, indistinctly -->
   <measure measureId="MEMORY" pattern="calloc|malloc|realloc|free" scope="CALL"/>

   <!-- Call Graph Measures - available only for C language -->
   <!-- Count the number of calls for each individual function matching the pattern -->
   <measure measureId="MEMORY" pattern="calloc|malloc|realloc|free" scope="CALL" distinct="true"/>

   <!-- Call Graph Rules - available only for C language -->
   <!-- Each time a function call matches the pattern a finding is reported on the line of the call -->
   <rule ruleId="R_DYNMEMALLOC" pattern="free|calloc|malloc|realloc" scope="CALL"/>

   <!-- Call Graph Filters - available only for C language -->
   <!-- Functions calls matching the pattern are ignored from the call graph metrics computation-->
   <callGraphFilter pattern="SET_.*|GET_.*"/>

   <!-- Special comments filters -->
   <!-- When a comment matching the pattern is found on a line, all other line counting metrics are set to 0 and the metric SKLC is incremented by 1 -->
   <commentFilter pattern="~[A-Z+-]"/>
</configuration>

The configuration element accepts any number of measure, rule, commentFilter and callGraphFilter sub-elements.

The measure element allows to define counting operations for which the result will be stored in measures. It accepts the following attributes:

  • measureId, the measure identifier of the measure that will store the counting result.

  • pattern, the regular expression pattern used to perform the match with.

  • scope (mandatory), the perimeter of the counting operation. Accepted values are:

    • CALL, to only consider functions calls. When used, the following additional attribute can be used:

      • distinct (optional, default: false), to specify whether the count must be performed for each function defined in the pattern distinctively (true), or if it must be common to all functions without any discrimination (false).

    • COMMENT, to only consider comments.

    • CODE, to only consider source code.

The rule element allows to trigger the creation of findings attached to a given rule. It accepts the following attributes:

  • ruleId, the rule identifier of the rule the findings will be attached to.

  • pattern, the regular expression pattern used to perform the match with.

  • scope (mandatory), the perimeter of the counting operation. Accepted values are:

    • CALL, to only consider functions calls. When used, the following additional attribute can be used:

      • distinct (optional, default: false), to specify whether the count must be performed for each function defined in the pattern distinctively (true), or if it must be common to all functions without any discrimination (false).

    • COMMENT, to only consider comments.

    • CODE, to only consider source code.

The callGraphFilter element allows to specify functions that should be excluded from the call graph metrics computation (only available for C language). It accepts the following attributes:

  • pattern, the regular expression pattern used to perform the match with.

The commentFilter element allows to define a comment pattern that will disable all line counting metrics while incrementing the SKLC measure. It accepts the following attributes:

  • pattern, the regular expression pattern used to perform the match with.