cprover
jsil_parse_tree.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Jsil Language
4 
5 Author: Michael Tautschnig, tautschn@amazon.com
6 
7 \*******************************************************************/
8 
11 
12 #include "jsil_parse_tree.h"
13 
14 #include <util/symbol.h>
15 
16 #include "jsil_types.h"
17 
18 static bool insert_at_label(
19  const codet &code,
20  const irep_idt &label,
21  code_blockt &dest)
22 {
23  Forall_operands(it, dest)
24  {
25  codet &c=to_code(*it);
26 
27  if(c.get_statement()!=ID_label)
28  continue;
29 
31  if(l.get_label()!=label)
32  continue;
33 
34  assert(l.code().get_statement()==ID_skip);
35  l.code()=code;
36 
37  return false;
38  }
39 
40  return true;
41 }
42 
44 {
45  symbol.clear();
46 
48  static_cast<const exprt&>(find(ID_declarator))));
49 
50  code_typet symbol_type=to_code_type(s.type());
51 
52  irep_idt proc_type=s.get("proc_type");
53 
54  if(proc_type=="builtin")
55  symbol_type=jsil_builtin_code_typet(symbol_type);
56  else if(proc_type=="spec")
57  symbol_type=jsil_spec_code_typet(symbol_type);
58 
59  symbol.name=s.get_identifier();
60  symbol.base_name=s.get_identifier();
61  symbol.mode="jsil";
62  symbol.type=symbol_type;
63  symbol.location=s.source_location();
64 
66  static_cast<const codet&>(find(ID_value))));
67 
68  irept returns(find(ID_return));
69  code_returnt r(symbol_exprt(returns.get(ID_value)));
70 
71  irept throws(find(ID_throw));
72  side_effect_expr_throwt t(symbol_exprt(throws.get(ID_value)));
73  code_expressiont ct(t);
74 
75  if(insert_at_label(r, returns.get(ID_label), code))
76  throw "return label "+returns.get_string(ID_label)+" not found";
77  if(insert_at_label(ct, throws.get(ID_label), code))
78  throw "throw label "+throws.get_string(ID_label)+" not found";
79 
80  symbol.value.swap(code);
81 }
82 
83 void jsil_declarationt::output(std::ostream &out) const
84 {
85  out << "Declarator: " << find(ID_declarator).pretty() << "\n";
86  out << "Returns: " << find(ID_return).pretty() << "\n";
87  out << "Throws: " << find(ID_throw).pretty() << "\n";
88  out << "Value: " << find(ID_value).pretty() << "\n";
89 }
90 
91 void jsil_parse_treet::output(std::ostream &out) const
92 {
93  for(itemst::const_iterator
94  it=items.begin();
95  it!=items.end();
96  it++)
97  {
98  it->output(out);
99  out << "\n";
100  }
101 }
const irep_idt & get_statement() const
Definition: std_code.h:37
irep_idt name
The unique identifier.
Definition: symbol.h:46
static int8_t r
Definition: irep_hash.h:59
Base type of functions.
Definition: std_types.h:734
Symbol table entry.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition: irep.cpp:641
irep_idt mode
Language mode.
Definition: symbol.h:55
void clear()
Definition: symbol.h:79
const irep_idt & get_identifier() const
Definition: std_expr.h:120
void to_symbol(symbolt &symbol) const
Jsil Language.
exprt value
Initial value of symbol.
Definition: symbol.h:40
typet & type()
Definition: expr.h:60
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
Definition: symbol.h:33
An expression statement.
Definition: std_code.h:957
A side effect that throws an exception.
Definition: std_code.h:1100
codet & code()
Definition: std_code.h:792
const irep_idt & get(const irep_namet &name) const
Definition: irep.cpp:213
A label for branch targets.
Definition: std_code.h:760
Base class for tree-like data structures with sharing.
Definition: irep.h:87
void output(std::ostream &out) const
static bool insert_at_label(const codet &code, const irep_idt &label, code_blockt &dest)
Jsil Language.
typet type
Type of symbol.
Definition: symbol.h:37
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:43
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:52
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
Definition: std_expr.h:202
const source_locationt & source_location() const
Definition: expr.h:142
const std::string & get_string(const irep_namet &name) const
Definition: irep.h:202
const code_typet & to_code_type(const typet &type)
Cast a generic typet to a code_typet.
Definition: std_types.h:884
void swap(irept &irep)
Definition: irep.h:231
#define Forall_operands(it, expr)
Definition: expr.h:23
Sequential composition.
Definition: std_code.h:63
const codet & to_code(const exprt &expr)
Definition: std_code.h:49
const irep_idt & get_label() const
Definition: std_code.h:782
Expression to hold a symbol (variable)
Definition: std_expr.h:82
const code_blockt & to_code_block(const codet &code)
Definition: std_code.h:120
A statement in a programming language.
Definition: std_code.h:19
Return from a function.
Definition: std_code.h:714
const code_labelt & to_code_label(const codet &code)
Definition: std_code.h:803
void output(std::ostream &) const
const irept & find(const irep_namet &name) const
Definition: irep.cpp:285