In this section, you create a simple Coverity Extend SDK checker (hello.cpp) designed to print every Abstract Syntax Tree (AST) that is passed into the ANALYZE_TREE function. In subsequent sections, you will compile and run this checker, then commit the issues that it finds in a code sample to Coverity Connect.
To create the Hello checker:
Type or copy the following source code into a text editor:
/* (c) 2017, Black Duck Software, Inc.. All rights reserved worldwide. The information contained in this file is the proprietary and confidential information of Black Duck Software, Inc.. and its licensors, and is supplied subject to, and may be used only by Black Duck customers in accordance with the terms and conditions of a previously executed license agreement between Black Duck and that customer. */ // hello.c // trivial Extend checker #include "extend-lang.hpp" // Extend API START_EXTEND_CHECKER( hello, simple ); ANALYZE_TREE() { cout << "ANALYZE_TREE: " << CURRENT_TREE << endl; OUTPUT_ERROR("ANALYZE_TREE: " << CURRENT_TREE); ReturnPat ret; if( MATCH(ret) ) print_tree(CURRENT_TREE); } END_EXTEND_CHECKER(); MAKE_MAIN( hello ) // EOFThe source code and makefile for this checker are located in the <install_dir>/sdk/samples/hello directory.
Unlike the print_tree checker (see Examining nodes in the AST with print_tree), this checker restricts the level of information that is returned by using an
ifstatement before callingprint_tree.Save this file as hello.cpp in a directory that is outside of the Coverity Extend SDK installation directory.
For example: HELLO so that your checker source file is now called HELLO/hello.cpp
Note: Saving the file inside of the installation directory can make the upgrade process for Coverity Extend SDK more difficult.