1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*! Implementation of proto! extension.
This is frequently called the pipe compiler. It handles code such as...
~~~
proto! pingpong (
ping: send {
ping -> pong
}
pong: recv {
pong -> ping
}
)
~~~
There are several components:
* The parser (libsyntax/ext/pipes/parse_proto.rs)
* Responsible for building an AST from a protocol specification.
* The checker (libsyntax/ext/pipes/check.rs)
* Basic correctness checking for protocols (i.e. no undefined states, etc.)
* The analyzer (libsyntax/ext/pipes/liveness.rs)
* Determines whether the protocol is bounded or unbounded.
* The compiler (libsynatx/ext/pipes/pipec.rs)
* Generates a Rust AST from the protocol AST and the results of analysis.
There is more documentation in each of the files referenced above.
FIXME (#3072) - This is still incomplete.
*/
use ast;
use codemap::span;
use ext::base;
use ext::base::ext_ctxt;
use ext::pipes::parse_proto::proto_parser;
use ext::pipes::pipec::gen_init;
use ext::pipes::proto::{visit, protocol};
use parse::lexer::{new_tt_reader, reader};
use parse::parser::Parser;
use core::option::None;
pub mod ast_builder;
pub mod parse_proto;
pub mod pipec;
pub mod proto;
pub mod check;
pub mod liveness;
pub fn expand_proto(cx: @ext_ctxt, _sp: span, id: ast::ident,
tt: ~[ast::token_tree]) -> base::MacResult {
let sess = cx.parse_sess();
let cfg = cx.cfg();
let tt_rdr = new_tt_reader(copy cx.parse_sess().span_diagnostic,
cx.parse_sess().interner,
None,
copy tt);
let rdr = tt_rdr as @reader;
let rust_parser = Parser(sess, cfg, rdr.dup());
let mut proto = rust_parser.parse_proto(cx.str_of(id));
// check for errors
visit(proto, cx);
// do analysis
liveness::analyze(proto, cx);
// compile
base::MRItem(proto.compile(cx))
}
|