Spectra
|
#include <monitorCreator.h>
Public Member Functions | |
monitorCreator (std::string) | |
bool | printMonitor (const std::string &defsFile) |
void | generateHeaderFile (const std::string &defsFile, const std::string &comment) const |
void | generateMonitorImplementation (formulaAnalyser &analyser, const std::string &comment) |
void | printVarNamesEnum (std::set< std::string > varNames, FILE *monitor) |
void | printMonitorStructure (FILE *monitor, std::vector< formula > formulae, std::vector< std::string > contents, std::vector< std::string > varsDefinitions, int childrenCnt) |
void | printPreparation (FILE *monitor, std::vector< formula > formulae) |
void | printProcessing (FILE *monitor, std::vector< formula > formulae) |
std::string | getCommentForGeneratedFiles (const std::string &defsFile) |
void | replaceLabelsInFileWithMonitorCalls (const std::string &filename) |
void | replaceInstrumentationComments (const std::vector< std::string > &srcList) |
void | setFormulaFile (const std::string &formulaFile) |
A class constructing a code of monitor for run-time evaluation of specified temporal properties.
|
explicit |
A constructor initializing the formula filename attribute.
A constructor initializing the formula filename.
void monitorCreator::generateHeaderFile | ( | const std::string & | defsFile, |
const std::string & | comment | ||
) | const |
Generates a header file with the passed comment, #include "defsFile" and declaration of the functions monitorVerify() and reset().
defsFile | A path to header file containing declarations of all variables and functions used given formulae. |
comment | A comment generated by getCommentForGeneratedFiles. |
Print monitor header file
See monitorCreator.h:112-123
void monitorCreator::generateMonitorImplementation | ( | formulaAnalyser & | analyser, |
const std::string & | comment | ||
) |
Generates the monitor.c file with definitions of needed structures and functions for verification of the specified temporal properties.
analyser | A formulaAnalyser that has successfully parsed a specification file. |
comment | A comment generated by getCommentForGeneratedFiles. |
Print the implementation
Define functions for evaluation
Print the monitor structure
Print fail reporting method
Print method encoding formulae values preparation
Print method encoding formulae one evaluation step
Print reset method
std::string monitorCreator::getCommentForGeneratedFiles | ( | const std::string & | defsFile | ) |
Creates a comment header for generated files informing how and when were these files generated.
defsFile | The name of given definitions header file. |
bool monitorCreator::printMonitor | ( | const std::string & | defsFile | ) |
Creates a C-language program consisting of two source files: monitor.h and monitor.c. The created header contains declaration of functions named monitorVerify() and reset(). Function monitorVerify() should be called by the SUT on every change of it's state to trigger the verification. The function reset() can be used by the SUT to erase the monitor's memory of errors. The file monitor.c defines monitor structure according to the input formulae, initializes it and also provides definition of the monitorVerify() and reset() functions along with other needed functions.
defsFile | A path to header file containing declarations of all variables and functions used given formulae. |
Parse formulae
Replace instrumentation comments in given list of source files
Generate the monitor implementation
void monitorCreator::printMonitorStructure | ( | FILE * | monitor, |
std::vector< formula > | formulae, | ||
std::vector< std::string > | contents, | ||
std::vector< std::string > | varsDefinitions, | ||
int | childrenCnt | ||
) |
Prints definition of a monitor structure into given file. First defines functions for evaluation of the variables' values, then prints the structure, creates it's instance M and initializes all it's needed values.
monitor | A file to write into. |
formulae | The vector of monitored formulae. |
contents | Strings representing the contents of monitored formulae. |
varsDefinitions | Code segments defining how to evaluate used variables in order given by enumeration created by printVarNamesEnum(). |
Declare the monitor struct
Define the monitor struct values
Get list of state variables' values
Get list of formulae contents strings
Get lists of formulae children
Get list of formulae children counts
Print the monitor structure definition
void monitorCreator::printPreparation | ( | FILE * | monitor, |
std::vector< formula > | formulae | ||
) |
Prints method initiating the boolean values of all formulae from 'previous step' for the evaluation in the first round of evaluation.
monitor | A file to write into. |
formulae | A list of formulae sorted so, that the subformula always comes before the formula that contains it. |
Perform initialization of the pre formula states vector values
Set flag that prev values are prepared
void monitorCreator::printProcessing | ( | FILE * | monitor, |
std::vector< formula > | formulae | ||
) |
Prints method performing processing of evaluation of the formulae encoded in the created program using values from the last step of evaluation.
monitor | A file to write into. |
formulae | A list of formulae sorted so, that the subformula always comes before the formula that contains it. |
Update the variables' values and swap now and pre vector values if already initialized, else call prepare()
Perform one step of evaluation for each formula
Update since vector values and check if state valid
void monitorCreator::printVarNamesEnum | ( | std::set< std::string > | varNames, |
FILE * | monitor | ||
) |
Prints enumeration of variable names used in evaluated formulae for easier access to their values while evaluating.
varNames | A formulaAnalyser object filled with parsed formulae, etc. |
monitor | A stream pointing to the file to write into. |
void monitorCreator::replaceInstrumentationComments | ( | const std::vector< std::string > & | srcList | ) |
Calls replaceLabelsInFileWithMonitorCalls for each file on srcList.
srcList | A list of source files paths where the instrumentation comments can be placed and should be replaced. |
void monitorCreator::replaceLabelsInFileWithMonitorCalls | ( | const std::string & | filename | ) |
Replaces all occurrences of '// T-Props Checker verify' (case insensitive) in given file with calls of function monitorVerify() of the generated monitor.
filename | A name of file where these labels should be replaced. |
Copy given file with replaced labels into temporary file named 'tmp'
Insert the #include "monitor.h" line if not included before
wrap in extern "C" { ... } if the source is a C++ code to make the compiler understand the compiled monitor code
If any changes made, save previous version with '.old' extension and rewrite