cprover
Loading...
Searching...
No Matches
cover_basic_blocks.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Coverage Instrumentation
4
5Author: Daniel Kroening
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_GOTO_INSTRUMENT_COVER_BASIC_BLOCKS_H
13#define CPROVER_GOTO_INSTRUMENT_COVER_BASIC_BLOCKS_H
14
15#include <unordered_set>
16
17#include <util/optional.h>
18
20
21#include "source_lines.h"
22
24
26{
27public:
28 virtual ~cover_blocks_baset() = default;
31 // part of
32 virtual std::size_t block_of(goto_programt::const_targett t) const = 0;
33
38 instruction_of(std::size_t block_nr) const = 0;
39
43 virtual const source_locationt &
44 source_location_of(std::size_t block_nr) const = 0;
45
47 virtual void output(std::ostream &out) const = 0;
48
54 const irep_idt &function_id,
55 const goto_programt &goto_program,
56 message_handlert &message_handler)
57 {
58 // unused parameters
59 (void)function_id;
60 (void)goto_program;
61 (void)message_handler;
62 }
63};
64
66{
67public:
68 explicit cover_basic_blockst(const goto_programt &goto_program);
69
73 std::size_t block_of(goto_programt::const_targett t) const override;
74
79 instruction_of(std::size_t block_nr) const override;
80
84 const source_locationt &
85 source_location_of(std::size_t block_nr) const override;
86
92 const irep_idt &function_id,
93 const goto_programt &goto_program,
94 message_handlert &message_handler) override;
95
97 void output(std::ostream &out) const override;
98
99private:
100 typedef std::map<goto_programt::const_targett, std::size_t> block_mapt;
101
118
122 std::vector<block_infot> block_infos;
123
125 static void add_block_lines(
127 const goto_programt::instructiont &instruction);
128
132
136
140 const goto_programt::const_targett &instruction,
142};
143
145{
146private:
147 // map block number to first instruction of the block
148 std::vector<goto_programt::const_targett> block_infos;
149 // map block number to its location
150 std::vector<source_locationt> block_locations;
151 // map java indexes to block indexes
152 std::unordered_map<irep_idt, std::size_t> index_to_block;
153 // map block number to its source lines
154 std::vector<source_linest> block_source_lines;
155
156public:
158
161 std::size_t block_of(goto_programt::const_targett t) const override;
162
166 instruction_of(std::size_t block_number) const override;
167
170 const source_locationt &
171 source_location_of(std::size_t block_number) const override;
172
174 void output(std::ostream &out) const override;
175};
176
177#endif // CPROVER_GOTO_INSTRUMENT_COVER_BASIC_BLOCKS_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:564
std::vector< goto_programt::const_targett > block_infos
const source_locationt & source_location_of(std::size_t block_number) const override
std::vector< source_locationt > block_locations
void output(std::ostream &out) const override
Outputs the list of blocks.
std::size_t block_of(goto_programt::const_targett t) const override
std::vector< source_linest > block_source_lines
optionalt< goto_programt::const_targett > instruction_of(std::size_t block_number) const override
std::unordered_map< irep_idt, std::size_t > index_to_block
static void update_source_lines(block_infot &block_info)
create a string representing source lines and set as a property of source location of basic block
std::map< goto_programt::const_targett, std::size_t > block_mapt
void output(std::ostream &out) const override
Outputs the list of blocks.
static optionalt< std::size_t > continuation_of_block(const goto_programt::const_targett &instruction, block_mapt &block_map)
If this block is a continuation of a previous block through unconditional forward gotos,...
optionalt< goto_programt::const_targett > instruction_of(std::size_t block_nr) const override
std::vector< block_infot > block_infos
map block numbers to block information
void report_block_anomalies(const irep_idt &function_id, const goto_programt &goto_program, message_handlert &message_handler) override
Output warnings about ignored blocks.
std::size_t block_of(goto_programt::const_targett t) const override
static void add_block_lines(cover_basic_blockst::block_infot &block, const goto_programt::instructiont &instruction)
Adds the lines which instruction spans to block.
static void update_covered_lines(block_infot &block_info)
create list of covered lines as CSV string and set as property of source location of basic block,...
const source_locationt & source_location_of(std::size_t block_nr) const override
block_mapt block_map
map program locations to block numbers
virtual void report_block_anomalies(const irep_idt &function_id, const goto_programt &goto_program, message_handlert &message_handler)
Output warnings about ignored blocks.
virtual void output(std::ostream &out) const =0
Outputs the list of blocks.
virtual optionalt< goto_programt::const_targett > instruction_of(std::size_t block_nr) const =0
virtual ~cover_blocks_baset()=default
virtual const source_locationt & source_location_of(std::size_t block_nr) const =0
virtual std::size_t block_of(goto_programt::const_targett t) const =0
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:37
This class represents an instruction in the GOTO intermediate representation.
A generic container class for the GOTO intermediate representation of one function.
instructionst::const_iterator const_targett
Concrete Goto Program.
Set of source code lines contributing to a basic block.
std::unordered_set< std::size_t > lines
the set of lines belonging to this block
source_locationt source_location
the source location representative for this block (we need a separate copy of source locations becaus...
source_linest source_lines
the set of source code lines belonging to this block
optionalt< goto_programt::const_targett > representative_inst
the program location to instrument for this block