Represents a method declaration in a Whiley source file. For example: method m(int x) -> (int y) // Parameter must be positive requires x > 0 // Return must be negative ensures $ < 0: // body return -x Here, a method m is defined which accepts only posi
| 987 | * |
| 988 | */ |
| 989 | public static class Method extends FunctionOrMethod { |
| 990 | |
| 991 | public Method(Tuple<Modifier> modifiers, Identifier name, Tuple<Template.Variable> template, |
| 992 | Tuple<Decl.Variable> parameters, Tuple<Decl.Variable> returns, Tuple<Expr> requires, |
| 993 | Tuple<Expr> ensures, Stmt.Block body) { |
| 994 | super(DECL_method, modifiers, name, template, parameters, returns, requires, ensures, body); |
| 995 | } |
| 996 | |
| 997 | @Override |
| 998 | public WyilFile.Type.Method getType() { |
| 999 | // FIXME: This just feels wrong as we are throwing away other template |
| 1000 | // variables. The issue is that callable types do not declare template variables |
| 1001 | // as they are compiled away. |
| 1002 | return new WyilFile.Type.Method(project(getParameters()), project(getReturns())); |
| 1003 | } |
| 1004 | |
| 1005 | @SuppressWarnings("unchecked") |
| 1006 | @Override |
| 1007 | public Method clone(Syntactic.Item[] operands) { |
| 1008 | return new Method((Tuple<Modifier>) operands[0], (Identifier) operands[1], |
| 1009 | (Tuple<Template.Variable>) operands[2], (Tuple<Decl.Variable>) operands[3], |
| 1010 | (Tuple<Decl.Variable>) operands[4], (Tuple<Expr>) operands[5], (Tuple<Expr>) operands[6], |
| 1011 | (Stmt.Block) operands[7]); |
| 1012 | } |
| 1013 | |
| 1014 | @Override |
| 1015 | public String toString() { |
| 1016 | return "method " + getName() + " : " + getType(); |
| 1017 | } |
| 1018 | |
| 1019 | public static final Descriptor DESCRIPTOR_0 = new Descriptor(Operands.EIGHT, Data.ZERO, "DECL_method") { |
| 1020 | @SuppressWarnings("unchecked") |
| 1021 | @Override |
| 1022 | public Syntactic.Item construct(int opcode, Syntactic.Item[] operands, byte[] data) { |
| 1023 | return new Method((Tuple<Modifier>) operands[0], (Identifier) operands[1], |
| 1024 | (Tuple<Template.Variable>) operands[2], (Tuple<Decl.Variable>) operands[3], |
| 1025 | (Tuple<Decl.Variable>) operands[4], (Tuple<Expr>) operands[5], (Tuple<Expr>) operands[6], |
| 1026 | (Stmt.Block) operands[7]); |
| 1027 | } |
| 1028 | }; |
| 1029 | } |
| 1030 | |
| 1031 | /** |
| 1032 | * <p> |
nothing calls this directly
no outgoing calls
no test coverage detected