C++ Reference Guide
This document provides some more detailed information about the objects and links that are stored in the Analysis Service. Other technical information may also be available.
Object Types
Objects detected by the analyzer are summarized in the following table:
Class | |
| |
Constructor | |
Destructor | |
Enum | |
Enum Item | |
File | |
Function | |
Global Variable | |
Macro | |
Member | |
Method | |
Project | |
Struct | |
Class Template | |
Class Template Specialization | |
Constructor Template | |
Constructor Template Specialization | |
Function Template | |
Function Template Specialization | |
Method Template | |
Method Template Specialization | |
Template Parameter | |
Typedef | |
Union | |
CLR Event (Managed C++) | |
CLR EventAddon (Managed C++) | |
CLR EventRaise (Managed C++) | |
CLR EventRemoveOn (Managed C++) | |
CLR Property (Managed C++) | |
CLR PropertyGetter (Managed C++) | |
CLR PropertySetter (Managed C++) |
Object modifiers (static, private, public etc.) and signatures (for functions/methods etc...) are retrieved and stored. They are also taken into account when the resolution is carried out.
Display in CAST Enlighten
Files, classes and functions etc can be seen in CAST Enlighten. When each job is successfully completed, the code is displayed as follows:
- the Classes folder containing classes.
- the File Scope Objects folder containing items visible only in the current file: static variables and functions, structures (not classes), enums, C++ constants and typedefs. Where one .H that defines these types of objects is included by various .CPP files, these objects are only represented once to avoid confusion, even if - conceptually - they exist once in each including file.
- the Global Scope Objects folder containing global objects (functions etc.).
- the directory of the root path, which contains the list of files included in the analysis. Under each file, any macros and classes are displayed.
- A pseudo-file may also be displayed called "CAST-System". This component is created by CAST and is used as a parent for functions such as strcpy that are used in certain CAST Quality Rules and metrics. When these functions are identified in the source code during an analysis and if the analyzer has not located the function in other source code, then these functions are placed under this pseudo-file so that links can be correctly created and metric/Quality Rules can be correctly calculated:
Link Types
The following table describes references that are detected by the analyzer and the context in which corresponding links are traced and stored in the Analysis Service:
Link Type | When is this type of link used? | |
ACCESS | READ | Specifies that an object reads a value of another object. For example if a function reads a global variable: int g_nVar1;void f(){int nVar1 = g_nVar1;} C++ Analyzer will generate this Access (Read) link:
|
WRITE | Specifies that an object modifies another one. For example if a function modifies a global variable : int g_nVar1;void f(){g_nVar1 = 1;} C++ Analyzer will generate this Access (Write) link:
| |
EXEC | Specifies that an object executes another object (method or function). For example if a function calls another function: void g(){f();} C++ Analyzer will generate this Access (Exec) link:
Notes
| |
MEMBER | Specifies that an object accesses a member of another object. For example if a function "g()" accesses a global var "g_pVar" and to one of its members: struct { int m_n1; }* g_Var;void g(){g_pVar->m_n1 = 1;} C++ Analyzer will generate this Access (Member) link:
| |
ARRAY | Specifies that an object accesses another using square brackets ([ ]). For example if a function "g()" accesses a character's array at its first position: char g_lpBuffer[256];void g(){g_lpBuffer[0] = '\0';} C++ Analyzer will generate this Access(Array) link (with the write property also):
| |
BELONG | Represents a parent link between two objects. If "Sample.h" contains the following statement:class C1{public:int foo() {}}; C++ Analyzer will generate these Belong links:
Notes
| |
CONTAIN | DECLARE | This link type occurs between a file and a Global object when there is also a declaration (forward declaration or external declaration) in addition to the definition itself. For example, between a file and a:
This link can be seen in the example below (Zc):
|
DEFINE | This link type occurs when a method is defined outside the file containing the class definition. The link is created from the file containing the method definition to the class. For example, using the code below: glob.h extern int theGlobalVariable;class theClass{void method();}; glob.cpp /*header comment.*/#include "glob.h"int theGlobalVariable = 3;void theClass::method(){if(2+2==4);} C++ Analyzer will generate the following link (Zf):
| |
FRIEND | Specifies that a class or a function is a friend of a class. For example if the class "C2" is declared as friend of a new "C3" class: {//...friend class C2;}; C++ Analyzer will generate this Friend link:
| |
INCLUDE | Represents an inclusion link between two files. If the "Sample.cpp" file contains the following statement:#include "Sample.h" C++ Analyzer will generate this Include link: | |
INHERIT | - | Represents an inheritance between two classes or structures. If we define a new class "C2" inheriting from C1 as in following statement:class C2 : public C1{int foo() {}}; C++ Analyzer will generate following Inherit link:
|
OVERRIDE | Specifies that a method redefines another method from an inherited class. For example using the previous sample, "C2::foo()" redefines "C1::foo()". So C++ Analyzer will generate this link: | |
RELY ON | Specifies that an object uses an existing type. If we define a new variable of type "C1" in "Sample.cpp": C1* g_pVar1; C++ Analyzer will generate following Rely On link : ![]() | |
USE | Represents a link between a C/C++ object and a database object. For example, if we define a function "f_ExecSql" containing a ProC statement referencing the "Authors" table : void f_ExecSql(){EXEC SQL EXECUTEselect * from authors where au_id = 0;} C++ Analyzer will generate this Use link:
The following ESQL tags are also supported (non exhaustive list):
In ESQL tags, links to the following objects will be found (non exhaustive list):
|
Support for digraphs and trigraphs
Digraphs and trigraphs are natively supported by the analyzer. The Accept Trigraphs option in the C++ Technology options refers to this support (it is selected by default). Uncheck this option to remove support for digraphs and trigraphs in some rare cases where this could be undesirable (e.g: Using the string '??' in an embedded SQL clause):
- ??= is equivalent to #
- ??) is equivalent to ]
- ??! is equivalent to |
- ??( is equivalent to [
- ??' is equivalent to ^
- ??> is equivalent to }
- ??/ is equivalent to \
- ??< is equivalent to {
- ??- is equivalent to ~
- <: is equivalent to [
- :> is equivalent to ]
- <% is equivalent to {
- %> is equivalent to }
- %: is equivalent to #
- %:%: is equivalent to ##.
Overloaded method resolution
When the C++ Analyzer detects a call to a function, all functions with the same name and having a number of parameters compatible with the number of effective arguments, are searched for in the source code:
- If only one function is found by the C++ Analyzer, a link is created to this function.
- If more than one function is found (so-called overloaded functions) by the C++ Analyzer, the parameter types are compared, following the C++ rules.
If at the end of this comparison process the C++ Analyzer cannot find any corresponding functions, or still finds more than one function, then it will create links to all the functions that have a compatible number of parameters.
K&R function parameter declarations
The so-called Kernighan & Richie syntax for declaring function parameters, e.g.:
int foo (bar)int bar;{ return bar++;}
which is no longer valid in C++ was always accepted by the C++ Analyzer in previous versions. This syntax is only accepted by the analyzer if the option Consider Files As > C is selected (see C++ Technology options).
Using the Force inclusion of file option
Please be aware that when using the Force Include File option in C++ Technology options, a bookmark will be set on the first line of each file towards the file that has been included using this option. In addition, Include type links will be created towards the included file.
The bookmarks are represented as follows in the CAST Enlighten Code Viewer: