cprover
xml_irep.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening
6 
7  Date: November 2005
8 
9 \*******************************************************************/
10 
11 #include "xml_irep.h"
12 
13 #include <iostream>
14 #include <string>
15 
16 #include "irep.h"
17 #include "xml.h"
18 
19 void convert(
20  const irept &irep,
21  xmlt &xml)
22 {
23  if(irep.id()!=ID_nil)
24  xml.new_element("id").data=irep.id_string();
25 
26  forall_irep(it, irep.get_sub())
27  {
28  xmlt &x_sub=xml.new_element("sub");
29  convert(*it, x_sub);
30  }
31 
33  {
34  xmlt &x_nsub=xml.new_element("named_sub");
35  x_nsub.set_attribute("name", name2string(it->first));
36  convert(it->second, x_nsub);
37  }
38 
40  {
41  xmlt &x_com = xml.new_element("comment");
42  x_com.set_attribute("name", name2string(it->first));
43  convert(it->second, x_com);
44  }
45 }
46 
47 void convert(
48  const xmlt &xml,
49  irept &irep)
50 {
51  irep.id(ID_nil);
52 
53  xmlt::elementst::const_iterator it = xml.elements.begin();
54  for(; it != xml.elements.end(); it++)
55  {
56  if(it->name=="id")
57  {
58  irep.id(it->data);
59  }
60  else if(it->name=="named_sub")
61  {
62  irept r;
63  convert(*it, r);
64  std::string named_name = it->get_attribute("name");
65  irep.move_to_named_sub(named_name, r);
66  }
67  else if(it->name=="sub")
68  {
69  irept r;
70  convert(*it, r);
71  irep.move_to_sub(r);
72  }
73  else if(it->name=="comment")
74  {
75  irept r;
76  convert(*it, r);
77  std::string named_name = it->get_attribute("name");
78  irep.move_to_named_sub(named_name, r);
79  }
80  else
81  {
82  // Should not happen
83  std::cout << "Unknown sub found (" << it->name << "); malformed xml?";
84  std::cout << "\n";
85  }
86  }
87 }
static int8_t r
Definition: irep_hash.h:59
void move_to_sub(irept &irep)
Definition: irep.cpp:204
void convert(const irept &irep, xmlt &xml)
Definition: xml_irep.cpp:19
#define forall_named_irep(it, irep)
Definition: irep.h:70
xmlt xml(const source_locationt &location)
Definition: xml_expr.cpp:25
subt & get_sub()
Definition: irep.h:317
const irep_idt & id() const
Definition: irep.h:259
elementst elements
Definition: xml.h:33
const std::string & name2string(const irep_namet &n)
Definition: irep.h:53
void set_attribute(const std::string &attribute, unsigned value)
Definition: xml.cpp:174
Definition: xml.h:18
named_subt & get_comments()
Definition: irep.h:321
Base class for tree-like data structures with sharing.
Definition: irep.h:156
std::string data
Definition: xml.h:30
xmlt & new_element(const std::string &name)
Definition: xml.h:86
named_subt & get_named_sub()
Definition: irep.h:319
const std::string & id_string() const
Definition: irep.h:262
void move_to_named_sub(const irep_namet &name, irept &irep)
Definition: irep.cpp:195
#define forall_irep(it, irep)
Definition: irep.h:62