Using CAC++ as a user
List of verifications
- The full list of verifications available in the library can be seen in "caclibrary.h".
-
Each of the verifications includes:
- A description of the utility of the verification.
- The signature of the method to invoke the verification.
- A description of the parameters to configure the verification.
- Examples of different situations that pass and fail the verification.
Shared parameters
There are some parameters that are shared by all or several of the available verifications:
string message- Optionally, you can include a parameter with the message to be shown when the check fails. If this parameter is not included, a default message will be shown.
bool exist- By default, a check validates the existence of an element in the code. With this parameter, this behavior can be inverted to validate that an element does not exist in the code. By default, the parameter is set to "true".
string constant- This parameter can be used to indicate whether a method is constant (in this case, "const") or not (in this case, "noconst").
Considerations
There are also some considerations that should be taken into account when using the library:
-
Methods: a particular method is identified by:
- the class to which it belongs.
- its name.
- the list of types of its parameters (not by their names).
- whether it is constant or not.
- Overloading: if the method is an overloaded operator, the name will be the word "operator" followed by the operator without any spaces in between. For example, "operator+=".
-
Types: regarding the types, the original type has to be indicated, that is, without taking into account typedefs or aliases. For example:
typedef unsigned long myType; int method(myType parameter);The type of "parameter" is "unsigned long" and not "myType".
-
Wildcards: in some parameters of some of these checks, it is allowed to introduce "?" (question mark) to indicate that the parameter does not have to be taken into account. This is mainly useful when that information is not known.
For example, if
{"?"}is set as the list of parameters of a method, the check will not adhere to a particular method, but it will try to match all the methods with the same name in the indicated class (regardless of their parameters). In the descriptions of the checks in "caclibrary.h", this property is indicated with (?).Note: when "?" is set as the list of parameters of a method, the check will not take into account the parameter list. This case must be distinguished from a method without parameters, which is indicated with an empty list
{}. -
Regular expressions: in some parameters of some of these checks, it is allowed to use a regular expression. This is mainly useful when the name of the element to be searched is not fixed.
For example, if "A.*" is set as the name of a class, the check will apply to all the classes whose name starts with "A". In the descriptions of the checks in "caclibrary.h", this property is indicated with (*).
Setup
-
Makefile: copy the Makefile included in
example.tar. Then:
-
Change the variables:
- CHECKSOURCE: user-created file with the invocation of the verifications (teacher's file).
- FILESTOCHECK: list of files to be analyzed with the program (student's files).
- CACDIR: path to the directory of the library.
- Optionally, change the target "check" to include any extra options required to analyze the files. The command "make check" should analyze the source files written by the student with the static analysis program that you have developed.
-
Change the variables:
-
"checkCode" object: the "checkCode" object created to analyze a source file has a constructor that receives:
- argc.
- argv.
- Name of the source file of the student.
- String to display when running the executable with the option --help.
Example:
checkCode c(argc, argv, "student.cpp", "Command: ./example student.cpp");Note that more than one file can be analyzed in the same execution, but a different "checkCode" object has to be created for each of those files (each of them with a different file as the third parameter of the constructor).