Represents a binding between a Linkable item and the corresponding declaration. @author David J. Pearce @param
| 1535 | * @param <T> |
| 1536 | */ |
| 1537 | public static class Binding<S extends WyilFile.Type, T extends Decl.Named<S>> extends AbstractItem { |
| 1538 | private S concreteType; |
| 1539 | |
| 1540 | public Binding(Link<T> link, Tuple<WyilFile.Type> arguments) { |
| 1541 | super(DECL_binding, link, arguments); |
| 1542 | } |
| 1543 | |
| 1544 | @SuppressWarnings("unchecked") |
| 1545 | public Link<T> getLink() { |
| 1546 | return (Link<T>) get(0); |
| 1547 | } |
| 1548 | |
| 1549 | public S getConcreteType() { |
| 1550 | if(concreteType == null) { |
| 1551 | T decl = getLink().getTarget(); |
| 1552 | S type = decl.getType(); |
| 1553 | // |
| 1554 | // Substitute type parameters |
| 1555 | if(type instanceof WyilFile.Type.Callable) { |
| 1556 | concreteType = (S) WyilFile.substituteTypeCallable((WyilFile.Type.Callable) type, decl.getTemplate(), |
| 1557 | getArguments()); |
| 1558 | } else { |
| 1559 | concreteType = (S) type.substitute(bindingFunction(decl.getTemplate(), getArguments())); |
| 1560 | } |
| 1561 | } |
| 1562 | return concreteType; |
| 1563 | } |
| 1564 | |
| 1565 | public T getDeclaration() { |
| 1566 | return getLink().getTarget(); |
| 1567 | } |
| 1568 | |
| 1569 | /** |
| 1570 | * Get the provided template arguments. |
| 1571 | * |
| 1572 | * @return |
| 1573 | */ |
| 1574 | public Tuple<WyilFile.Type> getArguments() { |
| 1575 | return (Tuple<WyilFile.Type>) get(1); |
| 1576 | } |
| 1577 | |
| 1578 | public void setArguments(Tuple<WyilFile.Type> arguments) { |
| 1579 | operands[1] = getHeap().allocate(arguments); |
| 1580 | concreteType = null; |
| 1581 | } |
| 1582 | |
| 1583 | @Override |
| 1584 | public Syntactic.Item clone(Syntactic.Item[] operands) { |
| 1585 | return new Binding((Link) operands[0], (Tuple<Type>) operands[1]); |
| 1586 | } |
| 1587 | |
| 1588 | @Override |
| 1589 | public String toString() { |
| 1590 | Identifier name = getDeclaration().getName(); |
| 1591 | String arguments = getArguments().toBareString(); |
| 1592 | return name + "<" + arguments + ">"; |
| 1593 | } |
| 1594 |
nothing calls this directly
no outgoing calls
no test coverage detected