| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
//! Extract common data from Function/Method/Constructor into Callable |
| 6 |
|
| 7 |
use super::*; |
| 8 |
|
| 9 |
pub fn pass(root: &mut Root) -> Result<()> { |
| 10 |
root.visit_mut(|func: &mut Function| { |
| 11 |
func.callable = Callable { |
| 12 |
name: func.name.clone(), |
| 13 |
is_async: func.is_async, |
| 14 |
kind: CallableKind::Function, |
| 15 |
arguments: func.inputs.clone(), |
| 16 |
return_type: ReturnType { |
| 17 |
ty: func.return_type.clone().map(|ty| TypeNode { |
| 18 |
ty, |
| 19 |
..TypeNode::default() |
| 20 |
}), |
| 21 |
}, |
| 22 |
throws_type: ThrowsType { |
| 23 |
ty: func.throws.clone().map(|ty| TypeNode { |
| 24 |
ty, |
| 25 |
..TypeNode::default() |
| 26 |
}), |
| 27 |
}, |
| 28 |
checksum: func.checksum, |
| 29 |
..Callable::default() |
| 30 |
} |
| 31 |
}); |
| 32 |
root.visit_mut(|module: &mut Module| { |
| 33 |
let module_name = module.name.clone(); |
| 34 |
module.visit_mut(|int: &mut Interface| { |
| 35 |
let interface_name = int.name.clone(); |
| 36 |
let interface_imp = int.imp.clone(); |
| 37 |
int.visit_mut(|cons: &mut Constructor| { |
| 38 |
cons.callable = Callable { |
| 39 |
name: cons.name.clone(), |
| 40 |
is_async: cons.is_async, |
| 41 |
kind: CallableKind::Constructor { |
| 42 |
interface_name: interface_name.clone(), |
| 43 |
primary: cons.name == "new", |
| 44 |
}, |
| 45 |
arguments: cons.inputs.clone(), |
| 46 |
return_type: ReturnType { |
| 47 |
ty: Some(TypeNode { |
| 48 |
ty: Type::Interface { |
| 49 |
module_name: module_name.clone(), |
| 50 |
name: interface_name.clone(), |
| 51 |
imp: interface_imp.clone(), |
| 52 |
}, |
| 53 |
..TypeNode::default() |
| 54 |
}), |
| 55 |
}, |
| 56 |
throws_type: ThrowsType { |
| 57 |
ty: cons.throws.clone().map(|ty| TypeNode { |
| 58 |
ty, |
| 59 |
..TypeNode::default() |
| 60 |
}), |
| 61 |
}, |
| 62 |
checksum: cons.checksum, |
| 63 |
..Callable::default() |
| 64 |
} |
| 65 |
}); |
| 66 |
int.visit_mut(|meth: &mut Method| { |
| 67 |
meth.callable = Callable { |
| 68 |
name: meth.name.clone(), |
| 69 |
is_async: meth.is_async, |
| 70 |
kind: CallableKind::Method { |
| 71 |
interface_name: interface_name.clone(), |
| 72 |
}, |
| 73 |
arguments: meth.inputs.clone(), |
| 74 |
return_type: ReturnType { |
| 75 |
ty: meth.return_type.clone().map(|ty| TypeNode { |
| 76 |
ty, |
| 77 |
..TypeNode::default() |
| 78 |
}), |
| 79 |
}, |
| 80 |
throws_type: ThrowsType { |
| 81 |
ty: meth.throws.clone().map(|ty| TypeNode { |
| 82 |
ty, |
| 83 |
..TypeNode::default() |
| 84 |
}), |
| 85 |
}, |
| 86 |
checksum: meth.checksum, |
| 87 |
..Callable::default() |
| 88 |
} |
| 89 |
}); |
| 90 |
}); |
| 91 |
}); |
| 92 |
root.visit_mut(|cbi: &mut CallbackInterface| { |
| 93 |
let interface_name = cbi.name.clone(); |
| 94 |
cbi.visit_mut(|meth: &mut Method| { |
| 95 |
meth.callable = Callable { |
| 96 |
name: meth.name.clone(), |
| 97 |
is_async: meth.is_async, |
| 98 |
kind: CallableKind::Method { |
| 99 |
interface_name: interface_name.clone(), |
| 100 |
}, |
| 101 |
arguments: meth.inputs.clone(), |
| 102 |
return_type: ReturnType { |
| 103 |
ty: meth.return_type.clone().map(|ty| TypeNode { |
| 104 |
ty, |
| 105 |
..TypeNode::default() |
| 106 |
}), |
| 107 |
}, |
| 108 |
throws_type: ThrowsType { |
| 109 |
ty: meth.throws.clone().map(|ty| TypeNode { |
| 110 |
ty, |
| 111 |
..TypeNode::default() |
| 112 |
}), |
| 113 |
}, |
| 114 |
checksum: meth.checksum, |
| 115 |
..Callable::default() |
| 116 |
} |
| 117 |
}); |
| 118 |
}); |
| 119 |
Ok(()) |
| 120 |
} |