Skip to content

Commit 49fc50e

Browse files
authored
Merge pull request #1586 from polgreen/get_source_location_for_property
Find source location from a property irep_idt
2 parents 14f6721 + 134c77d commit 49fc50e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/goto-programs/show_properties.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ Author: Daniel Kroening, [email protected]
2323
#include "goto_functions.h"
2424
#include "goto_model.h"
2525

26+
27+
optionalt<source_locationt> find_property(
28+
const irep_idt &property,
29+
const goto_functionst & goto_functions)
30+
{
31+
for(const auto &fct : goto_functions.function_map)
32+
{
33+
const goto_programt &goto_program = fct.second.body;
34+
35+
for(const auto &ins : goto_program.instructions)
36+
{
37+
if(ins.is_assert())
38+
{
39+
if(ins.source_location.get_property_id() == property)
40+
{
41+
return ins.source_location;
42+
}
43+
}
44+
}
45+
}
46+
return { };
47+
}
48+
49+
2650
void show_properties(
2751
const namespacet &ns,
2852
const irep_idt &identifier,

src/goto-programs/show_properties.h

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#define CPROVER_GOTO_PROGRAMS_SHOW_PROPERTIES_H
1414

1515
#include <util/ui_message.h>
16+
#include <util/optional.h>
1617

1718
class namespacet;
1819
class goto_modelt;
@@ -28,4 +29,15 @@ void show_properties(
2829
ui_message_handlert::uit ui,
2930
const goto_functionst &goto_functions);
3031

32+
/// \brief Returns a source_locationt that corresponds
33+
/// to the property given by an irep_idt.
34+
/// \param property irep_idt that identifies property
35+
/// \param goto_functions program in which to search for
36+
/// the property
37+
/// \return optional<source_locationt> the location of the
38+
/// property, if found.
39+
optionalt<source_locationt> find_property(
40+
const irep_idt &property,
41+
const goto_functionst &goto_functions);
42+
3143
#endif // CPROVER_GOTO_PROGRAMS_SHOW_PROPERTIES_H

0 commit comments

Comments
 (0)