cprover
xml_symbol.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Compile and link source and object files.
4 
5 Author: CM Wintersteiger
6 
7 Date: June 2006
8 
9 \*******************************************************************/
10 
13 
14 #include "xml_symbol.h"
15 
16 #include "xml_irep.h"
17 
21 void convert(const symbolt &sym, xmlt &root)
22 {
23  xmlt &xmlsym = root.new_element("symbol");
24  xmlsym.set_attribute("name", id2string(sym.name));
25 
26  xmlt &xmltype = xmlsym.new_element("type");
27  convert(sym.type, xmltype);
28 
29  xmlt &xmlval = xmlsym.new_element("value");
30  if(!sym.is_type && sym.type.id() == "code" && !sym.value.is_nil())
31  xmlval.data = "compiled"; // only for implemented functions
32  else
33  convert(sym.value, xmlval);
34 
35  xmlt &flags = xmlsym.new_element("flags");
36 
37  flags.set_attribute_bool("lvalue", sym.is_lvalue);
38  flags.set_attribute_bool("static_lifetime", sym.is_static_lifetime);
39  flags.set_attribute_bool("file_local", sym.is_file_local);
40  flags.set_attribute_bool("theorem", sym.is_property);
41  flags.set_attribute_bool("thread_local", sym.is_thread_local);
42  flags.set_attribute_bool("type", sym.is_type);
43  flags.set_attribute_bool("extern", sym.is_extern);
44  flags.set_attribute_bool("input", sym.is_input);
45  flags.set_attribute_bool("output", sym.is_output);
46  flags.set_attribute_bool("macro", sym.is_macro);
47  // flags.set_attribute_bool("actual", sym.is_actual);
48  // flags.set_attribute_bool("binding", sym.binding);
49  // flags.set_attribute_bool("free_var", sym.free_var);
50  flags.set_attribute_bool("statevar", sym.is_state_var);
51 
52  xmlt &mode = flags.new_element("mode");
53  mode.data = id2string(sym.mode);
54 
55  flags.new_element("base_name").data=id2string(sym.base_name);
56  flags.new_element("module").data=id2string(sym.module);
57 
58  if(!sym.pretty_name.empty())
59  flags.new_element("pretty_name").data=id2string(sym.pretty_name);
60 
61  xmlt &xmlloc = xmlsym.new_element("location");
62  convert(sym.location, xmlloc);
63  xmlloc.name = "location"; // convert overwrote this
64 }
65 
69 void convert(const xmlt &xmlsym, symbolt &symbol)
70 {
71  symbol.name=xmlsym.get_attribute("name");
72 
73  for(xmlt::elementst::const_iterator
74  it=xmlsym.elements.begin();
75  it!=xmlsym.elements.end();
76  it++)
77  {
78  if(it->name=="type")
79  {
80  convert(*it, symbol.type);
81  }
82  else if(it->name=="value")
83  {
84  if(it->data=="compiled")
85  {
86  symbol.value.id("code");
87  }
88  else
89  {
90  convert(*it, symbol.value);
91  }
92  }
93  else if(it->name=="flags")
94  {
95  symbol.is_lvalue = it->get_attribute_bool("lvalue");
96  symbol.is_static_lifetime = it->get_attribute_bool("static_lifetime");
97  symbol.is_file_local = it->get_attribute_bool("file_local");
98  symbol.is_property = it->get_attribute_bool("theorem");
99  symbol.is_thread_local = it->get_attribute_bool("thread_local");
100  symbol.is_type = it->get_attribute_bool("type");
101  symbol.is_extern = it->get_attribute_bool("extern");
102  symbol.is_input = it->get_attribute_bool("input");
103  symbol.is_output = it->get_attribute_bool("output");
104  symbol.is_macro = it->get_attribute_bool("macro");
105  // symbol.is_actual = it->get_attribute_bool("actual");
106  // symbol.binding = it->get_attribute_bool("binding");
107  // symbol.free_var = it->get_attribute_bool("free_var");
108  symbol.is_state_var = it->get_attribute_bool("statevar");
109 
110  for(xmlt::elementst::const_iterator
111  fit=it->elements.begin();
112  fit!=it->elements.end();
113  fit++)
114  {
115  if(fit->name=="mode")
116  symbol.mode=fit->data;
117  else if(fit->name=="base_name")
118  symbol.base_name=fit->data;
119  else if(fit->name=="module")
120  symbol.module=fit->data;
121  }
122  }
123  else if(it->name=="location")
124  {
125  convert(*it, symbol.location);
126  }
127  }
128 }
irep_idt name
The unique identifier.
Definition: symbol.h:46
void set_attribute_bool(const std::string &attribute, bool value)
Definition: xml.h:63
bool is_output
Definition: symbol.h:66
bool is_nil() const
Definition: irep.h:103
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
bool is_thread_local
Definition: symbol.h:70
irep_idt mode
Language mode.
Definition: symbol.h:55
exprt value
Initial value of symbol.
Definition: symbol.h:40
std::string name
Definition: xml.h:30
irep_idt module
Name of module the symbol belongs to.
Definition: symbol.h:49
irep_idt pretty_name
Language-specific display name.
Definition: symbol.h:58
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:33
bool is_static_lifetime
Definition: symbol.h:70
bool is_input
Definition: symbol.h:66
std::string get_attribute(const std::string &attribute) const
Definition: xml.h:54
Converts symbols to xml structures and back.
const irep_idt & id() const
Definition: irep.h:189
elementst elements
Definition: xml.h:33
void set_attribute(const std::string &attribute, unsigned value)
Definition: xml.cpp:174
Definition: xml.h:18
void convert(const symbolt &sym, xmlt &root)
converts a symbol to an xml symbol node
Definition: xml_symbol.cpp:21
std::string data
Definition: xml.h:30
xmlt & new_element(const std::string &name)
Definition: xml.h:86
bool is_extern
Definition: symbol.h:71
typet type
Type of symbol.
Definition: symbol.h:37
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:43
bool is_state_var
Definition: symbol.h:66
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:52
bool is_file_local
Definition: symbol.h:71
bool is_type
Definition: symbol.h:66
bool is_property
Definition: symbol.h:66
bool empty() const
Definition: dstring.h:61
bool is_macro
Definition: symbol.h:66
bool is_lvalue
Definition: symbol.h:71