use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangStruct structNode) {
BSymbol structSymbol = Symbols.createStructSymbol(Flags.asMask(structNode.flagSet), names.fromIdNode(structNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
structNode.symbol = structSymbol;
// Create struct type
structNode.symbol.type = new BStructType((BTypeSymbol) structNode.symbol);
defineSymbol(structNode.pos, structSymbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType in project ballerina by ballerina-lang.
the class SymbolEnter method defineStructFields.
private void defineStructFields(List<BLangStruct> structNodes, SymbolEnv pkgEnv) {
structNodes.forEach(struct -> {
// Create struct type
SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(struct, struct.symbol.scope, pkgEnv);
BStructType structType = (BStructType) struct.symbol.type;
structType.fields = struct.fields.stream().peek(field -> defineNode(field, structEnv)).map(field -> new BStructField(names.fromIdNode(field.name), field.symbol)).collect(Collectors.toList());
});
// define init function
structNodes.forEach(struct -> {
SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(struct, struct.symbol.scope, pkgEnv);
defineStructInitFunction(struct, structEnv);
});
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangObject objectNode) {
BSymbol objectSymbol = Symbols.createObjectSymbol(Flags.asMask(objectNode.flagSet), names.fromIdNode(objectNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
objectNode.symbol = objectSymbol;
// Create struct type
objectNode.symbol.type = new BStructType((BTypeSymbol) objectNode.symbol);
defineSymbol(objectNode.pos, objectSymbol);
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType in project ballerina by ballerina-lang.
the class TypeChecker method validateStructInitalizer.
private void validateStructInitalizer(DiagnosticPos pos) {
BStructType bStructType = (BStructType) expTypes.get(0);
BStructSymbol bStructSymbol = (BStructSymbol) bStructType.tsymbol;
if (bStructSymbol.initializerFunc == null) {
return;
}
boolean samePkg = this.env.enclPkg.symbol.pkgID == bStructSymbol.pkgID;
if (!samePkg && Symbols.isPrivate(bStructSymbol.initializerFunc.symbol)) {
dlog.error(pos, DiagnosticCode.ATTEMPT_CREATE_NON_PUBLIC_INITIALIZER);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BStructType in project ballerina by ballerina-lang.
the class Types method checkStructEquivalency.
public boolean checkStructEquivalency(BType rhsType, BType lhsType) {
if (rhsType.tag != TypeTags.STRUCT || lhsType.tag != TypeTags.STRUCT) {
return false;
}
// The public bit is on means, one is public, and the other one is private.
if (Symbols.isFlagOn(lhsType.tsymbol.flags ^ rhsType.tsymbol.flags, Flags.PUBLIC)) {
return false;
}
// If both structs are private, they should be in the same package.
if (Symbols.isPrivate(lhsType.tsymbol) && rhsType.tsymbol.pkgID != lhsType.tsymbol.pkgID) {
return false;
}
// RHS type should have at least all the fields as well attached functions of LHS type.
BStructType lhsStructType = (BStructType) lhsType;
BStructType rhsStructType = (BStructType) rhsType;
if (lhsStructType.fields.size() > rhsStructType.fields.size()) {
return false;
}
return Symbols.isPrivate(lhsType.tsymbol) && rhsType.tsymbol.pkgID == lhsType.tsymbol.pkgID ? checkEquivalencyOfTwoPrivateStructs(lhsStructType, rhsStructType) : checkEquivalencyOfPublicStructs(lhsStructType, rhsStructType);
}
Aggregations