private Property getLeftmostProp(QualifiedName qname) {
   String objName = qname.getLeftmostName();
   Property p = props.get(objName);
   if (p != null) {
     return p;
   }
   if (nominalType != null) {
     return nominalType.getProp(objName);
   }
   return builtinObject == null ? null : builtinObject.getProp(objName);
 }
 private static PersistentMap<String, Property> meetPropsHelper(
     boolean specializeProps1,
     NominalType resultNominalType,
     PersistentMap<String, Property> props1,
     PersistentMap<String, Property> props2) {
   PersistentMap<String, Property> newProps = props1;
   if (resultNominalType != null) {
     for (Map.Entry<String, Property> propsEntry : props1.entrySet()) {
       String pname = propsEntry.getKey();
       Property nomProp = resultNominalType.getProp(pname);
       if (nomProp != null) {
         newProps =
             addOrRemoveProp(specializeProps1, newProps, pname, nomProp, propsEntry.getValue());
         if (newProps == BOTTOM_MAP) {
           return BOTTOM_MAP;
         }
       }
     }
   }
   for (Map.Entry<String, Property> propsEntry : props2.entrySet()) {
     String pname = propsEntry.getKey();
     Property prop2 = propsEntry.getValue();
     Property newProp;
     if (!props1.containsKey(pname)) {
       newProp = prop2;
     } else {
       Property prop1 = props1.get(pname);
       if (prop1.equals(prop2)) {
         continue;
       }
       newProp = specializeProps1 ? prop1.specialize(prop2) : Property.meet(prop1, prop2);
     }
     if (resultNominalType != null && resultNominalType.getProp(pname) != null) {
       Property nomProp = resultNominalType.getProp(pname);
       newProps = addOrRemoveProp(specializeProps1, newProps, pname, nomProp, newProp);
       if (newProps == BOTTOM_MAP) {
         return BOTTOM_MAP;
       }
     } else {
       if (newProp.getType().isBottom()) {
         return BOTTOM_MAP;
       }
       newProps = newProps.with(pname, newProp);
     }
   }
   return newProps;
 }
 private static Property getProp(Map<String, Property> props, NominalType nom, String pname) {
   if (props.containsKey(pname)) {
     return props.get(pname);
   } else if (nom != null) {
     return nom.getProp(pname);
   }
   return null;
 }
示例#4
0
 private boolean isStructuralSubtypeOf(NominalType other, SubtypeCache subSuperMap) {
   Preconditions.checkArgument(other.isStructuralInterface());
   for (String pname : other.getAllPropsOfInterface()) {
     Property prop2 = other.getProp(pname);
     Property prop1 = this.getProp(pname);
     if (prop2.isOptional()) {
       if (prop1 != null && !prop1.getType().isSubtypeOf(prop2.getType(), subSuperMap)) {
         return false;
       }
     } else if (prop1 == null
         || prop1.isOptional()
         || !prop1.getType().isSubtypeOf(prop2.getType(), subSuperMap)) {
       return false;
     }
   }
   return true;
 }