Spectra
Public Member Functions | List of all members
monitorCreator Class Reference

#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)
 

Detailed Description

A class constructing a code of monitor for run-time evaluation of specified temporal properties.

Constructor & Destructor Documentation

◆ monitorCreator()

monitorCreator::monitorCreator ( std::string  f)
explicit

A constructor initializing the formula filename attribute.

A constructor initializing the formula filename.

Member Function Documentation

◆ generateHeaderFile()

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().

Parameters
defsFileA path to header file containing declarations of all variables and functions used given formulae.
commentA comment generated by getCommentForGeneratedFiles.

Print monitor header file

See monitorCreator.h:112-123

◆ generateMonitorImplementation()

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.

Parameters
analyserA formulaAnalyser that has successfully parsed a specification file.
commentA 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

◆ getCommentForGeneratedFiles()

std::string monitorCreator::getCommentForGeneratedFiles ( const std::string &  defsFile)

Creates a comment header for generated files informing how and when were these files generated.

Parameters
defsFileThe name of given definitions header file.
Returns
The string containing created comment

◆ printMonitor()

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.

Parameters
defsFileA path to header file containing declarations of all variables and functions used given formulae.
Returns
True if monitor files generated successfully, false otherwise.

Parse formulae

Replace instrumentation comments in given list of source files

Generate the monitor implementation

◆ printMonitorStructure()

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.

Parameters
monitorA file to write into.
formulaeThe vector of monitored formulae.
contentsStrings representing the contents of monitored formulae.
varsDefinitionsCode 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

◆ printPreparation()

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.

Parameters
monitorA file to write into.
formulaeA 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

◆ printProcessing()

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.

Parameters
monitorA file to write into.
formulaeA 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

◆ printVarNamesEnum()

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.

Parameters
varNamesA formulaAnalyser object filled with parsed formulae, etc.
monitorA stream pointing to the file to write into.

◆ replaceInstrumentationComments()

void monitorCreator::replaceInstrumentationComments ( const std::vector< std::string > &  srcList)

Calls replaceLabelsInFileWithMonitorCalls for each file on srcList.

Parameters
srcListA list of source files paths where the instrumentation comments can be placed and should be replaced.

◆ replaceLabelsInFileWithMonitorCalls()

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.

Parameters
filenameA 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


The documentation for this class was generated from the following files: