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

Class Nominal

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

Represents a nominal type, which is of the form: NominalType ::= Identifier ('.' Identifier) A nominal type specifies the name of a type defined elsewhere. In some cases, this type can be expanded (or "inlined"). However, visibility modifiers can prevent this and, thus, give rise to

Source from the content-addressed store, hash-verified

6011 * @return
6012 */
6013 public static class Nominal extends AbstractItem implements Type, Linkable {
6014
6015 public Nominal(Decl.Link<Decl.Type> name, WyilFile.Tuple<Type> parameters) {
6016 super(TYPE_nominal, name, parameters);
6017 if(parameters != null) {
6018 for(Type t : parameters) {
6019 if(t == null) {
6020 throw new IllegalArgumentException("invalid parameter types");
6021 }
6022 }
6023 }
6024 }
6025
6026 @Override
6027 public int shape() {
6028 // NOTE: Don't believe we need to use the concrete type here as shape is not
6029 // affected by substitution.
6030 return getLink().getTarget().getType().shape();
6031 }
6032
6033 @Override
6034 public Type dimension(int nth) {
6035 if(shape() == 1) {
6036 // In the special case we have unit shape, then return ourself. This gives
6037 // better error messages by retaining the nominal name.
6038 return this;
6039 } else {
6040 // NOTE: Don't believe we need to use the concrete type here as shape is not
6041 // affected by substitution.
6042 return getLink().getTarget().getType().dimension(nth);
6043 }
6044 }
6045
6046 public boolean isAlias() {
6047 return getLink().getTarget().getInvariant().size() == 0;
6048 }
6049
6050 @Override
6051 public boolean isWriteable() {
6052 return getConcreteType().isWriteable();
6053 }
6054
6055 @Override
6056 public boolean isReadable() {
6057 return getConcreteType().isReadable();
6058 }
6059
6060 @Override
6061 public Decl.Link<Decl.Type> getLink() {
6062 return (Decl.Link<Decl.Type>) get(0);
6063 }
6064
6065 public WyilFile.Tuple<Type> getParameters() {
6066 return (WyilFile.Tuple<Type>) get(1);
6067 }
6068
6069 @Override
6070 public <T extends Type> T as(Class<T> kind) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected