Use Checker Studio to find KAST nodes of interest
Now that you have a simple test case, the next step is to open Checker Studio.
- Double-click the Checker Studio icon on your desktop, or at the command line, type:
kwstudio
- Paste your testcase code snippet into the Source Code section of Checker Studio to view the KAST node names, example code and hierarchy information. These will form the building blocks of your KAST expression, which will trace a path to the issue you are identifying with your checker. Don't forget to set the language button in the upper right corner of the window.
(Optional): Choose your C++ standard from the Default drop-down. Checker Studio supports C++03 (default), C++98, and C++11 or higher.
- Click "if" in the snippet in the Source Code pane.
The IfStmt node in the AST is highlighted. This is the first node of interest in your KAST expression.
- View context-sensitive help for the expression by selecting a tree node and pressing F1, or clicking View > Context Help Window. Context-sensitive help displays below the Source Code pane, providing more node information, such as supertypes and subtypes, and applicable functions. (For reasons of image clarity, the illustrations in this tutorial don't show the Context Help panel.)
- In the AST, expand IfStmt.
It has children Cond, Then and Else. This checker deals with the if statement's condition expression.
- Expand the Cond: :AnyExpr node.
Condhas one child BinaryExpr, indicating that IfStmt contains a condition clause (Cond) that is a binary expression (BinaryExpr).
- Click '=' in the Source Code pane.
This will highlight the BinaryExpr and shows its attributes in the Attributes table to the lower left.
If you don't see the attributes, click the
Show Attributes icon. Attributes are only displayed for the currently-selected node.
- Make a note of its Value (KTC_OPCODE_ASSIGN).
Now that we have the AST nodes, it's time to draft the KAST expression.