protected boolean isNonNilReturnable() { // All functions are now considered as returnable. So in here, what we check is whether the function actually // returns a value other than nil. if (this.responseTypes.length == 1 && this.responseTypes[0].getTag() == TypeTags.NULL_TAG) { return false; } return this.responseTypes.length > 0; }
@Override public BType getErrorType(BType reasonType, BType detailsType) { if (reasonType == BTypes.typeString && detailsType == BTypes.typeMap) { return BTypes.typeError; } return new BErrorType(reasonType, detailsType); } }
private static boolean checkIsArrayType(BType sourceType, BArrayType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.ARRAY_TAG) { return false; } BArrayType sourceArrayType = (BArrayType) sourceType; if (sourceArrayType.getState() != targetType.getState() || sourceArrayType.getSize() != targetType.getSize()) { return false; } return checkIsType(sourceArrayType.getElementType(), targetType.getElementType(), unresolvedTypes); }
private static BType getElementType(BType type) { if (type.getTag() != TypeTags.ARRAY_TAG) { return type; } return getElementType(((BArrayType) type).getElementType()); }
private BType getActualNonNilArrayElementType(BType actualArrayElementType) { if (actualArrayElementType.getTag() == TypeTags.UNION_TAG) { return (((BUnionType) actualArrayElementType).getMemberTypes()).get(0); } else { return actualArrayElementType; } }
private static boolean checkIsTableType(BType sourceType, BTableType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.TABLE_TAG) { return false; } return checkTableConstraints(((BTableType) sourceType).getConstrainedType(), targetType.getConstrainedType(), unresolvedTypes); }
private static boolean checkIsFutureType(BType sourceType, BFutureType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.FUTURE_TAG) { return false; } return checkContraints(((BFutureType) sourceType).getConstrainedType(), targetType.getConstrainedType(), unresolvedTypes); }
private static boolean checkIsMapType(BType sourceType, BMapType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.MAP_TAG) { return false; } return checkContraints(((BMapType) sourceType).getConstrainedType(), targetType.getConstrainedType(), unresolvedTypes); }
public static BType fromString(String typeName) { if (typeName.endsWith("[]")) { String elementTypeName = typeName.substring(0, typeName.length() - 2); BType elemType = fromString(elementTypeName); return new BArrayType(elemType); } return getTypeFromName(typeName); } }
public BDecimalArray(BigDecimal[] values) { this.values = values; this.size = values.length; super.arrayType = new BArrayType(BTypes.typeDecimal); }
@Override public BType getCollectionType(char typeChar, List<BType> memberTypes) { switch (typeChar) { case 'O': return new BUnionType(memberTypes); case 'P': return new BTupleType(memberTypes); default: throw new IllegalArgumentException("unsupported collection type char: " + typeChar); } }
private static boolean isDeepStampingRequiredForMap(BType sourceType) { BType constrainedType = ((BMapType) sourceType).getConstrainedType(); if (constrainedType != null) { if (BTypes.isValueType(constrainedType)) { return false; } else if (constrainedType instanceof BMapType) { return isDeepStampingRequiredForMap(constrainedType); } return true; } return true; }
public BArrayType(BType elemType, int size) { super(null, null, BNewArray.class); this.elementType = elemType; if (elementType instanceof BArrayType) { dimensions = ((BArrayType) elementType).getDimensions() + 1; } if (size != -1) { state = BArrayState.CLOSED_SEALED; this.size = size; } }
protected String getNameWithArray(String name) { if (isArrayType) { String arrayName = name; for (int i = 0; i < getDimensions(); i++) { arrayName = arrayName + TypeConstants.ARRAY_TNAME; } return arrayName; } else { return name; } }
public static String getTypeName(BType[] parameterType, BType[] returnParameterType) { return "function (" + (parameterType != null ? getBTypeListAsString(parameterType) : "") + ")" + (returnParameterType != null ? " returns (" + getBTypeListAsString(returnParameterType) + ")" : ""); }