Skip to content

Commit

Permalink
Merge pull request #26357 from MaryamZi/isolated-obj-mod-var
Browse files Browse the repository at this point in the history
Introduce support for isolated objects
  • Loading branch information
hasithaa authored Oct 21, 2020
2 parents 2755398 + 3cfdd23 commit 66a1c27
Show file tree
Hide file tree
Showing 15 changed files with 1,761 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,12 @@ private static boolean checkObjectEquivalency(Object sourceVal, Type sourceType,
unresolvedTypes.add(pair);

BObjectType sourceObjectType = (BObjectType) sourceType;

if (Flags.isFlagOn(targetType.flags, Flags.ISOLATED) &&
!Flags.isFlagOn(sourceObjectType.flags, Flags.ISOLATED)) {
return false;
}

Map<String, Field> targetFields = targetType.getFields();
Map<String, Field> sourceFields = sourceObjectType.getFields();
AttachedFunctionType[] targetFuncs = targetType.getAttachedFunctions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,18 @@ public enum DiagnosticCode {
INVALID_FORK_STATEMENT_IN_ISOLATED_FUNCTION("invalid.fork.statement.in.isolated.function"),
FUNCTION_CAN_BE_MARKED_ISOLATED("function.can.be.marked.isolated"),

INVALID_NON_PRIVATE_MUTABLE_FIELD_IN_ISOLATED_OBJECT("invalid.non.private.mutable.field.in.isolated.object"),
INVALID_MUTABLE_FIELD_ACCESS_IN_ISOLATED_OBJECT_OUTSIDE_LOCK(
"invalid.mutable.field.access.in.isolated.object.outside.lock"),
INVALID_REFERENCE_TO_SELF_IN_ISOLATED_OBJECT_OUTSIDE_LOCK(
"invalid.reference.to.self.in.isolated.object.outside.lock"),
INVALID_NON_UNIQUE_EXPRESSION_AS_INITIAL_VALUE_IN_ISOLATED_OBJECT(
"invalid.non.unique.expression.as.initial.value.in.isolated.object"),
INVALID_COPY_OUT_OF_MUTABLE_VALUE_FROM_ISOLATED_OBJECT("invalid.copy.out.of.mutable.value.from.isolated.object"),
INVALID_COPY_IN_OF_MUTABLE_VALUE_INTO_ISOLATED_OBJECT("invalid.copy.in.of.mutable.value.into.isolated.object"),
INVALID_NON_ISOLATED_INVOCATION_IN_ISOLATED_OBJECT_METHOD(
"invalid.non.isolated.invocation.in.isolated.object.method"),

COMPILER_PLUGIN_ERROR("compiler.plugin.crashed"),
;
private String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
import java.util.Stack;
import java.util.regex.Matcher;

import static org.ballerinalang.model.elements.Flag.ISOLATED;
import static org.ballerinalang.model.elements.Flag.SERVICE;
import static org.wso2.ballerinalang.compiler.util.Constants.INFERRED_ARRAY_INDICATOR;
import static org.wso2.ballerinalang.compiler.util.Constants.OPEN_ARRAY_INDICATOR;
Expand Down Expand Up @@ -861,13 +862,23 @@ public BLangNode transform(ObjectTypeDescriptorNode objTypeDescNode) {
BLangObjectTypeNode objectTypeNode = (BLangObjectTypeNode) TreeBuilder.createObjectTypeNode();

for (Token qualifier : objTypeDescNode.objectTypeQualifiers()) {
if (qualifier.kind() == SyntaxKind.CLIENT_KEYWORD) {
SyntaxKind kind = qualifier.kind();
if (kind == SyntaxKind.CLIENT_KEYWORD) {
objectTypeNode.flagSet.add(Flag.CLIENT);
} else if (qualifier.kind() == SyntaxKind.SERVICE_KEYWORD) {
continue;
}

if (kind == SyntaxKind.SERVICE_KEYWORD) {
objectTypeNode.flagSet.add(SERVICE);
} else {
throw new RuntimeException("Syntax kind is not supported: " + qualifier.kind());
continue;
}

if (kind == SyntaxKind.ISOLATED_KEYWORD) {
objectTypeNode.flagSet.add(ISOLATED);
continue;
}

throw new RuntimeException("Syntax kind is not supported: " + kind);
}

NodeList<Node> members = objTypeDescNode.members();
Expand Down Expand Up @@ -3624,20 +3635,26 @@ public BLangNode transform(ClassDefinitionNode classDefinitionNode) {
});

for (Token qualifier : classDefinitionNode.classTypeQualifiers()) {
if (qualifier.kind() == SyntaxKind.DISTINCT_KEYWORD) {
blangClass.flagSet.add(Flag.DISTINCT);
}
SyntaxKind kind = qualifier.kind();

if (qualifier.kind() == SyntaxKind.CLIENT_KEYWORD) {
blangClass.flagSet.add(Flag.CLIENT);
}

if (qualifier.kind() == SyntaxKind.READONLY_KEYWORD) {
blangClass.flagSet.add(Flag.READONLY);
}

if (qualifier.kind() == SyntaxKind.SERVICE_KEYWORD) {
blangClass.flagSet.add(SERVICE);
switch (kind) {
case DISTINCT_KEYWORD:
blangClass.flagSet.add(Flag.DISTINCT);
break;
case CLIENT_KEYWORD:
blangClass.flagSet.add(Flag.CLIENT);
break;
case READONLY_KEYWORD:
blangClass.flagSet.add(Flag.READONLY);
break;
case SERVICE_KEYWORD:
blangClass.flagSet.add(Flag.SERVICE);
break;
case ISOLATED_KEYWORD:
blangClass.flagSet.add(Flag.ISOLATED);
break;
default:
throw new RuntimeException("Syntax kind is not supported: " + kind);
}
}

Expand Down
Loading

0 comments on commit 66a1c27

Please sign in to comment.