cprover
jsil_parse_tree.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Jsil Language
4
5Author: Michael Tautschnig, tautschn@amazon.com
6
7\*******************************************************************/
8
11
12#include "jsil_parse_tree.h"
13
14#include <ostream>
15
16#include <util/symbol.h>
17
18#include "jsil_types.h"
19
20static bool insert_at_label(
21 const codet &code,
22 const irep_idt &label,
23 code_blockt &dest)
24{
25 for(auto &c : dest.statements())
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));
70
71 irept throws(find(ID_throw));
73 symbol_exprt::typeless(throws.get(ID_value)), typet(), s.source_location());
74 code_expressiont ct(t);
75
76 if(insert_at_label(r, returns.get(ID_label), code))
77 throw "return label "+returns.get_string(ID_label)+" not found";
78 if(insert_at_label(ct, throws.get(ID_label), code))
79 throw "throw label "+throws.get_string(ID_label)+" not found";
80
81 symbol.value.swap(code);
82}
83
84void jsil_declarationt::output(std::ostream &out) const
85{
86 out << "Declarator: " << find(ID_declarator).pretty() << "\n";
87 out << "Returns: " << find(ID_return).pretty() << "\n";
88 out << "Throws: " << find(ID_throw).pretty() << "\n";
89 out << "Value: " << find(ID_value).pretty() << "\n";
90}
91
92void jsil_parse_treet::output(std::ostream &out) const
93{
94 for(itemst::const_iterator
95 it=items.begin();
96 it!=items.end();
97 it++)
98 {
99 it->output(out);
100 out << "\n";
101 }
102}
A codet representing sequential composition of program statements.
Definition: std_code.h:130
code_operandst & statements()
Definition: std_code.h:138
codet representation of an expression statement.
Definition: std_code.h:1394
codet representation of a "return from a function" statement.
Definition: std_code.h:893
codet representation of a label for branch targets.
Definition: std_code.h:959
const irep_idt & get_label() const
Definition: std_code.h:967
codet & code()
Definition: std_code.h:977
Base type of functions.
Definition: std_types.h:539
Data structure for representing an arbitrary statement in a program.
Definition: std_code_base.h:29
const irep_idt & get_statement() const
Definition: std_code_base.h:65
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
Base class for all expressions.
Definition: expr.h:54
typet & type()
Return the type of the expression.
Definition: expr.h:82
const source_locationt & source_location() const
Definition: expr.h:230
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition: irep.h:372
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition: irep.cpp:495
const irept & find(const irep_idt &name) const
Definition: irep.cpp:106
const irep_idt & get(const irep_idt &name) const
Definition: irep.cpp:45
void swap(irept &irep)
Definition: irep.h:442
const std::string & get_string(const irep_idt &name) const
Definition: irep.h:409
void output(std::ostream &) const
void to_symbol(symbolt &symbol) const
void output(std::ostream &out) const
A side_effect_exprt representation of a side effect that throws an exception.
Definition: std_code.h:1757
Expression to hold a symbol (variable)
Definition: std_expr.h:80
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
Definition: std_expr.h:99
const irep_idt & get_identifier() const
Definition: std_expr.h:109
Symbol table entry.
Definition: symbol.h:28
irep_idt base_name
Base (non-scoped) name.
Definition: symbol.h:46
void clear()
Zero initialise a symbol object.
Definition: symbol.h:75
source_locationt location
Source code location of definition of symbol.
Definition: symbol.h:37
typet type
Type of symbol.
Definition: symbol.h:31
irep_idt name
The unique identifier.
Definition: symbol.h:40
exprt value
Initial value of symbol.
Definition: symbol.h:34
irep_idt mode
Language mode.
Definition: symbol.h:49
The type of an expression, extends irept.
Definition: type.h:29
static int8_t r
Definition: irep_hash.h:60
static bool insert_at_label(const codet &code, const irep_idt &label, code_blockt &dest)
Jsil Language.
Jsil Language.
const code_labelt & to_code_label(const codet &code)
Definition: std_code.h:1004
const code_blockt & to_code_block(const codet &code)
Definition: std_code.h:203
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition: std_expr.h:189
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:744
Symbol table entry.