Choose Between Semantic and Syntactic Classes
The Polyspace Query Language (PQL) supports two kinds of classes — Syntactic classes and Semantic classes. For an overview of these classes, see:
The use cases and the capabilities of these classes are different. This topic explains when to use which class.
When to Use Semantic Classes
The PQL semantic classes represent objects in an abstract syntax tree after the C/C++ code is processed and information such as type, scope, and nature of various objects are known. Because these classes represent code objects that are generated after the actual code is processed, these classes do not have access to the underlying syntax tree but have access to semantic information.
That is, you can query for information related to variables, types, namespaces, or function call sites using the semantic classes. This kind of information is not mutated by simple syntax changes. On the other hand, the relationship between the actual code tokens are not available to these classes. These classes cannot calculate relative position or syntactic relationships between various code tokens.
By using semantic classes, you can analyze:
Data flow
Name, size, type, and other information for variables
Function call site
Examples of issues you can detect using semantic classes include:
When to Use Syntax Classes
The PQL syntax classes represent the nodes of a concrete syntax tree calculated from the code itself. Each class represent a type of syntax tree node. By using the syntax classes, you can query for specific relationship between various syntax node. Because the classes represent syntax nodes, the semantic information such as type or scope or caller/callee relationship is not available for syntax classes.
By using the syntax classes, you can analyze:
Code formatting
Relation between nodes of the syntax tree
Examples of issues you can detect using semantic classes include: