private void setAttachedFunctions(PackageInfo packageInfo) { TypeDefInfo[] structInfoEntries = packageInfo.getTypeDefInfoEntries(); for (TypeDefInfo structInfo : structInfoEntries) { if (structInfo.typeTag == TypeTags.FINITE_TYPE_TAG) { continue; } StructureTypeInfo structureTypeInfo = (StructureTypeInfo) structInfo.typeInfo; BStructureType structType = structureTypeInfo.getType(); // Resolve attached function signature if (structType.getTag() != TypeTags.OBJECT_TYPE_TAG && structType.getTag() != TypeTags.RECORD_TYPE_TAG) { continue; } int attachedFuncCount = structureTypeInfo.funcInfoEntries.size(); BAttachedFunction[] attachedFunctions = new BAttachedFunction[attachedFuncCount]; int count = 0; for (FunctionInfo attachedFuncInfo : structureTypeInfo.funcInfoEntries.values()) { BAttachedFunction attachedFunction = new BAttachedFunction(attachedFuncInfo.name, attachedFuncInfo.funcType, attachedFuncInfo.flags); attachedFunctions[count++] = attachedFunction; if (structureTypeInfo.initializer == attachedFuncInfo) { structureTypeInfo.getType().initializer = attachedFunction; } } structureTypeInfo.getType().setAttachedFunctions(attachedFunctions); } }
private static StructureTypeInfo getStructureTypeInfo(ProgramFile programFile) { PackageInfo runtimePackage = programFile.getPackageInfo(BALLERINA_RUNTIME_PKG); StructureTypeInfo typeInfo = runtimePackage.getStructInfo(STRUCT_CALL_STACK_ELEMENT); if (typeInfo == null || typeInfo.getType().getTag() != TypeTags.RECORD_TYPE_TAG) { throw new BallerinaConnectorException("record - " + STRUCT_CALL_STACK_ELEMENT + " does not exist"); } return typeInfo; } }
public static BMap<String, BValue> createObject(ProgramFile programFile, String pkgPath, String objectName, BValue... values) { PackageInfo packageInfo = programFile.getPackageInfo(pkgPath); if (packageInfo == null) { throw new BallerinaConnectorException("module - " + pkgPath + " does not exist"); } StructureTypeInfo typeInfo = packageInfo.getStructInfo(objectName); if (typeInfo == null || typeInfo.getType().getTag() != TypeTags.OBJECT_TYPE_TAG) { throw new BallerinaConnectorException("object - " + objectName + " does not exist"); } return BLangVMStructs.createObject((ObjectTypeInfo) typeInfo, values); }
if (structType.getTag() == TypeTags.RECORD_TYPE_TAG && !((BRecordType) structType).sealed) { RecordTypeInfo recTypeInfo = (RecordTypeInfo) structureTypeInfo; String restTypeDesc = recTypeInfo.getRestFieldTypeSignature();