use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class Types method checkConnectorEquivalency.
public boolean checkConnectorEquivalency(BType actualType, BType expType) {
if (actualType.tag != TypeTags.CONNECTOR || expType.tag != TypeTags.CONNECTOR) {
return false;
}
if (isSameType(actualType, expType)) {
return true;
}
BConnectorType expConnectorType = (BConnectorType) expType;
BConnectorType actualConnectorType = (BConnectorType) actualType;
// take actions in connectors
List<BInvokableSymbol> expActions = symResolver.getConnectorActionSymbols(expConnectorType.tsymbol.scope);
List<BInvokableSymbol> actActions = symResolver.getConnectorActionSymbols(actualConnectorType.tsymbol.scope);
if (expActions.isEmpty() && actActions.isEmpty()) {
return true;
}
if (expActions.size() != actActions.size()) {
return false;
}
// check every action signatures are matching or not
for (BInvokableSymbol expAction : expActions) {
if (actActions.stream().filter(v -> checkActionTypeEquality(expAction, v)).collect(Collectors.toList()).size() != 1) {
return false;
}
}
return true;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class Types method isAssignableToUnionType.
private boolean isAssignableToUnionType(BType source, BType target) {
Set<BType> sourceTypes = new HashSet<>();
Set<BType> targetTypes = new HashSet<>();
if (source.tag == TypeTags.UNION) {
BUnionType sourceUnionType = (BUnionType) source;
sourceTypes.addAll(sourceUnionType.memberTypes);
} else {
sourceTypes.add(source);
}
if (target.tag == TypeTags.UNION) {
BUnionType targetUnionType = (BUnionType) target;
targetTypes.addAll(targetUnionType.memberTypes);
} else {
targetTypes.add(target);
}
boolean notAssignable = sourceTypes.stream().map(s -> targetTypes.stream().anyMatch(t -> isAssignable(s, t))).anyMatch(assignable -> !assignable);
return !notAssignable;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class Symbols method createConversionOperatorSymbol.
public static BConversionOperatorSymbol createConversionOperatorSymbol(final BType sourceType, final BType targetType, final BType errorType, boolean implicit, boolean safe, int opcode, PackageID pkgID, BSymbol owner) {
List<BType> paramTypes = Lists.of(sourceType, targetType);
List<BType> retTypes = new ArrayList<>(1);
if (safe) {
retTypes.add(targetType);
} else if (targetType.tag == TypeTags.UNION && targetType instanceof BUnionType) {
BUnionType unionType = (BUnionType) targetType;
unionType.memberTypes.add(errorType);
retTypes.add(unionType);
} else {
Set<BType> memberTypes = new HashSet<>(2);
memberTypes.add(targetType);
memberTypes.add(errorType);
BUnionType unionType = new BUnionType(null, memberTypes, false);
retTypes.add(unionType);
}
BInvokableType opType = new BInvokableType(paramTypes, retTypes, null);
BConversionOperatorSymbol symbol = new BConversionOperatorSymbol(pkgID, opType, owner, implicit, safe, opcode);
symbol.kind = SymbolKind.CONVERSION_OPERATOR;
return symbol;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class CodeGenerator method createActionInfoEntry.
private void createActionInfoEntry(BLangAction actionNode, ConnectorInfo connectorInfo) {
BInvokableSymbol actionSymbol = actionNode.symbol;
BInvokableType actionType = (BInvokableType) actionSymbol.type;
// Add action name as an UTFCPEntry to the constant pool
int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionNode.name.value);
ActionInfo actionInfo = new ActionInfo(currentPackageRefCPIndex, actionNameCPIndex);
actionInfo.paramTypes = actionType.paramTypes.toArray(new BType[0]);
actionInfo.retParamTypes = actionType.retTypes.toArray(new BType[0]);
actionInfo.flags = actionSymbol.flags;
// setParameterNames(actionNode, actionInfo);
actionInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(actionInfo.paramTypes, actionInfo.retParamTypes));
// Add worker info
this.addWorkerInfoEntries(actionInfo, actionNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(actionNode, actionInfo);
// Add action info to the connector info
connectorInfo.actionInfoMap.put(actionNode.name.getValue(), actionInfo);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BType in project ballerina by ballerina-lang.
the class CodeGenerator method createFunctionInfoEntry.
/**
* Creates a {@code FunctionInfo} from the given function node in AST.
*
* @param funcNode function node in AST
*/
private void createFunctionInfoEntry(BLangFunction funcNode) {
BInvokableSymbol funcSymbol = funcNode.symbol;
BInvokableType funcType = (BInvokableType) funcSymbol.type;
// Add function name as an UTFCPEntry to the constant pool
int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
funcInfo.flags = funcSymbol.flags;
if (funcNode.receiver != null) {
funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
}
this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
// Add parameter default value info
addParameterDefaultValues(funcNode, funcInfo);
this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
Aggregations