MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / Method

Class Method

src/main/java/wyil/lang/WyilFile.java:989–1029  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected