Skip to content

Commit

Permalink
Track spans better in the protocol compiler so we can get better erro…
Browse files Browse the repository at this point in the history
…r messages.
  • Loading branch information
eholk committed Aug 17, 2012
1 parent 89c2a9f commit 9260b02
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
39 changes: 25 additions & 14 deletions src/libsyntax/ext/pipes/ast_builder.rs
Expand Up @@ -55,7 +55,7 @@ trait ext_ctxt_ast_builder {
fn arg_mode(name: ident, ty: @ast::ty, mode: ast::rmode) -> ast::arg;
fn expr_block(e: @ast::expr) -> ast::blk;
fn fn_decl(+inputs: ~[ast::arg], output: @ast::ty) -> ast::fn_decl;
fn item(name: ident, +node: ast::item_) -> @ast::item;
fn item(name: ident, span: span, +node: ast::item_) -> @ast::item;
fn item_fn_poly(name: ident,
+inputs: ~[ast::arg],
output: @ast::ty,
Expand All @@ -66,16 +66,19 @@ trait ext_ctxt_ast_builder {
output: @ast::ty,
+body: ast::blk) -> @ast::item;
fn item_enum_poly(name: ident,
span: span,
+enum_definition: ast::enum_def,
+ty_params: ~[ast::ty_param]) -> @ast::item;
fn item_enum(name: ident, +enum_definition: ast::enum_def) -> @ast::item;
fn variant(name: ident, +tys: ~[@ast::ty]) -> ast::variant;
fn item_mod(name: ident, +items: ~[@ast::item]) -> @ast::item;
fn item_enum(name: ident, span: span,
+enum_definition: ast::enum_def) -> @ast::item;
fn variant(name: ident, span: span, +tys: ~[@ast::ty]) -> ast::variant;
fn item_mod(name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
fn ty_path_ast_builder(path: @ast::path) -> @ast::ty;
fn item_ty_poly(name: ident,
span: span,
ty: @ast::ty,
+params: ~[ast::ty_param]) -> @ast::item;
fn item_ty(name: ident, ty: @ast::ty) -> @ast::item;
fn item_ty(name: ident, span: span, ty: @ast::ty) -> @ast::item;
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::ty];
fn ty_field_imm(name: ident, ty: @ast::ty) -> ast::ty_field;
fn ty_rec(+~[ast::ty_field]) -> @ast::ty;
Expand Down Expand Up @@ -208,13 +211,14 @@ impl ext_ctxt: ext_ctxt_ast_builder {
}

fn item(name: ident,
span: span,
+node: ast::item_) -> @ast::item {
@{ident: name,
attrs: ~[],
id: self.next_id(),
node: node,
vis: ast::public,
span: self.empty_span()}
span: span}
}

fn item_fn_poly(name: ident,
Expand All @@ -223,6 +227,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
+ty_params: ~[ast::ty_param],
+body: ast::blk) -> @ast::item {
self.item(name,
self.empty_span(),
ast::item_fn(self.fn_decl(inputs, output),
ty_params,
body))
Expand All @@ -236,16 +241,19 @@ impl ext_ctxt: ext_ctxt_ast_builder {
}

fn item_enum_poly(name: ident,
span: span,
+enum_definition: ast::enum_def,
+ty_params: ~[ast::ty_param]) -> @ast::item {
self.item(name, ast::item_enum(enum_definition, ty_params))
self.item(name, span, ast::item_enum(enum_definition, ty_params))
}

fn item_enum(name: ident, +enum_definition: ast::enum_def) -> @ast::item {
self.item_enum_poly(name, enum_definition, ~[])
fn item_enum(name: ident, span: span,
+enum_definition: ast::enum_def) -> @ast::item {
self.item_enum_poly(name, span, enum_definition, ~[])
}

fn variant(name: ident,
span: span,
+tys: ~[@ast::ty]) -> ast::variant {
let args = tys.map(|ty| {ty: ty, id: self.next_id()});

Expand All @@ -255,12 +263,14 @@ impl ext_ctxt: ext_ctxt_ast_builder {
id: self.next_id(),
disr_expr: none,
vis: ast::public},
span: self.empty_span()}
span: span}
}

fn item_mod(name: ident,
span: span,
+items: ~[@ast::item]) -> @ast::item {
self.item(name,
span,
ast::item_mod({
view_items: ~[],
items: items}))
Expand All @@ -269,7 +279,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
fn ty_path_ast_builder(path: @ast::path) -> @ast::ty {
@{id: self.next_id(),
node: ast::ty_path(path, self.next_id()),
span: self.empty_span()}
span: path.span}
}

fn ty_nil_ast_builder() -> @ast::ty {
Expand All @@ -279,13 +289,14 @@ impl ext_ctxt: ext_ctxt_ast_builder {
}

fn item_ty_poly(name: ident,
span: span,
ty: @ast::ty,
+params: ~[ast::ty_param]) -> @ast::item {
self.item(name, ast::item_ty(ty, params))
self.item(name, span, ast::item_ty(ty, params))
}

fn item_ty(name: ident, ty: @ast::ty) -> @ast::item {
self.item_ty_poly(name, ty, ~[])
fn item_ty(name: ident, span: span, ty: @ast::ty) -> @ast::item {
self.item_ty_poly(name, span, ty, ~[])
}

fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::ty] {
Expand Down
12 changes: 9 additions & 3 deletions src/libsyntax/ext/pipes/pipec.rs
Expand Up @@ -207,7 +207,7 @@ impl state: to_type_decls {
let mut items_msg = ~[];

for self.messages.each |m| {
let message(name, _span, tys, this, next) = m;
let message(name, span, tys, this, next) = m;

let tys = match next {
some({state: next, tys: next_tys}) => {
Expand All @@ -226,12 +226,13 @@ impl state: to_type_decls {
none => tys
};

let v = cx.variant(name, tys);
let v = cx.variant(name, span, tys);

vec::push(items_msg, v);
}

~[cx.item_enum_poly(name,
self.span,
ast::enum_def({ variants: items_msg,
common: none }),
self.ty_params)]
Expand All @@ -255,6 +256,7 @@ impl state: to_type_decls {
vec::push(items,
cx.item_ty_poly(
self.data_name(),
self.span,
cx.ty_path_ast_builder(
(@~"pipes" + @(dir.to_str() + ~"_packet"))
.add_ty(cx.ty_path_ast_builder(
Expand All @@ -266,6 +268,7 @@ impl state: to_type_decls {
vec::push(items,
cx.item_ty_poly(
self.data_name(),
self.span,
cx.ty_path_ast_builder(
(@~"pipes" + @(dir.to_str()
+ ~"_packet_buffered"))
Expand Down Expand Up @@ -384,6 +387,7 @@ impl protocol: gen_init {
cx.item_ty_poly(
@~"__Buffer",
cx.empty_span(),
cx.ty_rec(fields),
params)
}
Expand All @@ -407,12 +411,14 @@ impl protocol: gen_init {

vec::push(items,
cx.item_mod(@~"client",
self.span,
client_states));
vec::push(items,
cx.item_mod(@~"server",
self.span,
server_states));

cx.item_mod(self.name, items)
cx.item_mod(self.name, self.span, items)
}
}

Expand Down

0 comments on commit 9260b02

Please sign in to comment.