The CPG is based on a profile metric which is designed to compute complexity at various levels of granularity based on the underlying source language. We will call these various levels of granularity measurable units of software. The fundamental idea of the profile concept is that software can be partitioned into a set of measurable units in such a way that each token belongs to exactly one such unit. For example, an Ada 95 program is grammatically partitioned into statements, etc. Theoretically, complexity can be calculated for any level of granularity defined by the grammar of the source language. Currently, complexity is calculated at the production level in the source grammar.
The CPG is a visualisation of the complexity of a program unit, divided into a set of measurable units of software called segments. CPG segments consist of simple statements and clauses in the underlying source language. A program unit is parsed into a set of non-overlapping segments such that each token is included in exactly one segment.
While simple statements and declarations correspond to only one segment, compound statements such as loops and selection structures are partitioned into two or more CPG segments for measurement. For example, the Ada 95 while loop, shown below, is partitioned into four CPG segments.
1. while (A < B) loop 2. Do_Something (To => B); 3. A := A + 1; 4. end loop; |
while (A < B) loop Do_Something (To => B); A := A + 1; end loop; |
This partitioning is advantageous for at least two reasons: these segments are the constructs which readers would generally comprehend as single units; the natural link between the CPG segments for Ada 95, except for tasking and object-oriented constructs, are shown in the table below. Notice that the statements and constructs which are partitioned into multiple segments may have other CPG segments between their own. For example, an if statement could have a CPG segment for an assignment between its "IF condition THEN" segment and its "ELSIF condition THEN" segment.
Statements Having Only One Segment | Statements Having Multiple Segments | Other Constructs Partitioned into Multiple Segments |
---|---|---|
assignment statement | IF condition THEN ELSIF condition THEN ELSE END IF; |
TYPE...IS RECORD END RECORD; |
delay statement | ||
exit statement | ||
goto statement | [GENERIC] PROCEDURE...IS BEGIN END [Name]; | |
null statement | CASE expression IS WHEN choices => END CASE; |
|
procedure call | ||
raise statement | ||
return statement | [Name][Itr] LOOP END LOOP [Name]; |
[GENERIC] FUNCTION...IS BEGIN END [Name]; |
declarations | ||
[Name][DECLARE] BEGIN END [Name]; |