Ejemplo n.º 1
0
 public void addField(int index, RType fieldType) {
   String name = null;
   if (index >= 0 && index < myPositionalTypes.size()) {
     name = myPositionalTypes.get(index).myName;
   }
   addField(name, index, fieldType);
 }
Ejemplo n.º 2
0
 @Override
 public RType getSubscriptionType(List<RExpression> indices, boolean isSingleBracket) {
   if (indices.isEmpty()) {
     return this;
   }
   if (indices.size() > 1) {
     return RUnknownType.INSTANCE;
   }
   RExpression index = indices.get(0);
   RType type = RUnknownType.INSTANCE;
   String indexName = null;
   if (index instanceof RStringLiteralExpression) {
     String quoted = index.getText();
     indexName = quoted.substring(1, quoted.length() - 1);
     type = getFieldType(indexName);
   }
   if (index instanceof RNumericLiteralExpression) {
     try {
       int i = Integer.parseInt(index.getText());
       TypeDescriptor descriptor = getFieldDescriptor(i - 1);
       indexName = descriptor.myName;
       type = descriptor.myType;
     } catch (NumberFormatException e) {
       // Do nothing
     }
   }
   if (!RNullType.class.isInstance(type)
       && !RUnknownType.class.isInstance(type)
       && isSingleBracket) {
     RListType listType = new RListType();
     listType.addField(indexName, type);
     type = listType;
   }
   return type;
 }
Ejemplo n.º 3
0
 // handles assignment to subscription expression
 @Override
 public RType afterSubscriptionType(
     List<RExpression> indices, RType valueType, boolean isSingleBracket) {
   if (indices.isEmpty()) {
     return this;
   }
   if (indices.size() > 1) {
     return RUnknownType.INSTANCE;
   }
   if (isSingleBracket && valueType instanceof RListType) {
     RListType list = (RListType) valueType;
     if (!list.myPrecise) {
       return RUnknownType.INSTANCE;
     }
     if (list.myPositionalTypes.isEmpty()) {
       return RUnknownType.INSTANCE;
     }
     valueType = list.myPositionalTypes.get(0).myType;
   }
   RExpression index = indices.get(0);
   RListType resultType = new RListType(this);
   if (index instanceof RStringLiteralExpression) {
     String quoted = index.getText();
     String indexName = quoted.substring(1, quoted.length() - 1);
     if (valueType instanceof RNullType) {
       resultType.removeField(indexName);
     } else {
       resultType.addField(indexName, valueType);
     }
   }
   if (index instanceof RNumericLiteralExpression) {
     try {
       int i = Integer.parseInt(index.getText());
       if (valueType instanceof RNullType) {
         resultType.removeField(i - 1);
       } else {
         resultType.addField(i - 1, valueType);
       }
     } catch (NumberFormatException e) {
       // do nothing
     }
   }
   return resultType;
 }
Ejemplo n.º 4
0
 @Override
 public RType afterMemberType(String tag, RType valueType) {
   RListType clone = clone();
   if (valueType instanceof RNullType) {
     clone.removeField(tag);
   } else {
     clone.addField(tag, valueType);
   }
   return clone;
 }
Ejemplo n.º 5
0
 public void addField(String name, RType fieldType) {
   int index = myPositionalTypes.size();
   if (name != null && myPrecise) {
     for (int i = 0; i < myPositionalTypes.size(); i++) {
       if (name.equals(myPositionalTypes.get(i).myName)) {
         index = i;
         break;
       }
     }
   }
   addField(name, index, fieldType);
 }
Ejemplo n.º 6
0
 public void addField(RType fieldType) {
   addField(null, fieldType);
 }