| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-07-05 10:11:06 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-07-05 10:11:06 +0200 | 
| commit | f6cd96ae24b458a5b4875f8e151758c11c45dbcd (patch) | |
| tree | 9b5f943524eae588b4da1ab3e51579dfc44c84d6 /src/core | |
| parent | 9b9958e662d89d2c8c497791072edd25e09ec6de (diff) | |
Adds SetType.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/lang/SetType.java | 92 | 
1 files changed, 92 insertions, 0 deletions
| diff --git a/src/core/src/tonkadur/fate/v1/lang/SetType.java b/src/core/src/tonkadur/fate/v1/lang/SetType.java new file mode 100644 index 0000000..ccb5bf3 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/SetType.java @@ -0,0 +1,92 @@ +package tonkadur.fate.v1.lang; + +import java.util.Iterator; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.DeclaredEntity; + +public class SetType extends Type +{ +   /***************************************************************************/ +   /**** MEMBERS **************************************************************/ +   /***************************************************************************/ +   protected final Type content_type; + +   /***************************************************************************/ +   /**** PUBLIC ***************************************************************/ +   /***************************************************************************/ + +   /**** Constructors *********************************************************/ +   public SetType +   ( +      final Origin origin, +      final Type content_type, +      final String name +   ) +   { +      super(origin, Type.SET, name); + +      this.content_type = content_type; +   } + +   /**** Accessors ************************************************************/ +   public Type get_content_type () +   { +      return true_type; +   } + +   /**** Compatibility ********************************************************/ +   @Override +   public boolean can_be_used_as (final Type t) +   { +      if (t instanceof SetType) +      { +         return content_type.can_be_used_as(((SetType) t).content_type); +      } + +      return false; +   } + +   /* +    * This is for the very special case where a type is used despite not being +    * even a sub-type of the expected one. Using this rather expensive function, +    * the most restrictive shared type will be returned. If no such type exists, +    * the ANY time is returned. +    */ +   @Override +   public DeclaredEntity generate_comparable_to (final DeclaredEntity de) +   { +      if (!(de instanceof SetType)) +      { +         return Type.ANY; +      } + +      return +         new SetType +         ( +            de.get_origin(), +            ( +               (Type) content_type.generate_comparable_to +               ( +                  ((SetType) de).content_type +               ) +            ), +            name +         ); +   } + + +   /**** Misc. ****************************************************************/ +   @Override +   public String toString () +   { +      final StringBuilder sb = new StringBuilder(); + +      sb.append("(Set "); +      sb.append(content_type.toString()); +      sb.append(")"); + +      return sb.toString(); +   } +} | 


