Skip to content

Commit

Permalink
A bug in the invalid access to local methods of other actors is fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehsan Khamespanah committed Feb 8, 2024
1 parent 69fa8e9 commit be751d4
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 17 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.rebecalang</groupId>
<artifactId>compiler</artifactId>
<version>2.18</version>
<version>2.19</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springframework.version>6.1.1</springframework.version>
<springframework.version>6.1.2</springframework.version>
<junit.jupiter.version>5.10.1</junit.jupiter.version>
<org.apache.maven.plugins.surefire.version>3.2.2</org.apache.maven.plugins.surefire.version>
<org.apache.maven.plugins.compiler.version>3.11.0</org.apache.maven.plugins.compiler.version>
<org.projectlombok.version>1.18.30</org.projectlombok.version>
<compilerversion>21</compilerversion>
<compilerversion>17</compilerversion>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public List<String> getArgumentsNames() {
public void setArgumentsNames(List<String> argumentsNames) {
this.argumentsNames = argumentsNames;
}

public Type getRebecType() { return rebecType; }

public void setRebecType(Type rebecType) { this.rebecType = rebecType; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ private String createCheckMainBindingsExceptionMessage(
+ " is not applicable for the arguments (" + actual + ")";
}

@SafeVarargs
protected final void addMethodToSymbolTable(Label methodLabel, Type base, String name, Type returnType,
Pair<Type, String>... arguments) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ public Pair<Type, Object> check(Expression expression, Type baseType) {
return returnValue;
///
MethodInSymbolTableSpecifier methodInSymbolTableSpecifier = null;
Type selfType = scopeHandler.retreiveVariableFromScope("self").getType();
if (baseType == AbstractTypeSystem.NO_TYPE) {
Type selfType = scopeHandler.retreiveVariableFromScope("self").getType();
try {
// methodInSymbolTableSpecifier = symbolTable.getMethodSpecification(selfType,
// termName, argumentTypes);
methodInSymbolTableSpecifier = checkMethodInParents(selfType, termName, argumentTypes);

} catch (SymbolTableException se) {
Expand All @@ -128,13 +126,23 @@ public Pair<Type, Object> check(Expression expression, Type baseType) {

}
if (methodInSymbolTableSpecifier.getLabel() == CoreRebecaLabelUtility.CONSTRUCTOR) {
exceptionContainer.addException(new CodeCompilationException(
exceptionContainer.addException(new SymbolTableException(
"The method " + termName + SymbolTable.convertMethodArgumentsToString(argumentTypes)
+ " is undefined"
+ (baseType == null || baseType == AbstractTypeSystem.NO_TYPE ? ""
: " for the type " + baseType.getTypeName()),
termPrimary.getLineNumber(), termPrimary.getCharacter()));
}
if (methodInSymbolTableSpecifier.getLabel() == CoreRebecaLabelUtility.SYNCH_METHOD) {
if(methodInSymbolTableSpecifier.getRebecType() != selfType) {
exceptionContainer.addException(new SymbolTableException(
"The method " + termName + SymbolTable.convertMethodArgumentsToString(argumentTypes)
+ " is not visible"
+ (baseType == null || baseType == AbstractTypeSystem.NO_TYPE ? ""
: " for the type " + baseType.getTypeName()),
termPrimary.getLineNumber(), termPrimary.getCharacter()));
}
}
termPrimary.setLabel(methodInSymbolTableSpecifier.getLabel());
returnValue.setFirst(methodInSymbolTableSpecifier.getReturnValue());
termPrimary.setType(methodInSymbolTableSpecifier.getReturnValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ protected void updateSymbolTable(RebecaModel rebecaModel) {
weakUntilMethod.setReturnType(CoreRebecaTypeSystem.BOOLEAN_TYPE);

modelSymbolTable.addMethod(null, globallyMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
modelSymbolTable.addMethod(null, finallyMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
modelSymbolTable.addMethod(null, nextMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
modelSymbolTable.addMethod(null, untilMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
modelSymbolTable.addMethod(null, weakUntilMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ protected void updateSymbolTable(RebecaModel rebecaModel) {
AFMethod.setReturnType(CoreRebecaTypeSystem.BOOLEAN_TYPE);

modelSymbolTable.addMethod(null, EUMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
modelSymbolTable.addMethod(null, AUMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
modelSymbolTable.addMethod(null, AGMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
modelSymbolTable.addMethod(null, AFMethod,
CoreRebecaLabelUtility.SYNCH_METHOD);
CoreRebecaLabelUtility.BUILT_IN_METHOD);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.rebecalang.compiler.modelcompiler;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.rebecalang.compiler.CompilerConfig;
import org.rebecalang.compiler.utils.CompilerExtension;
import org.rebecalang.compiler.utils.CoreVersion;
import org.rebecalang.compiler.utils.ExceptionContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

@ContextConfiguration(classes = CompilerConfig.class)
@SpringJUnitConfig
public class AccessControlTest {

public static final String MODEL_FILES_BASE = "src/test/resources/org/rebecalang/compiler/modelcompiler/";

@Autowired
public RebecaModelCompiler compiler;
@Autowired
public ExceptionContainer exceptionContainer;

@Test
public void GIVEN_RebecaModelWithTwoReactiveclasses_WHEN_AccessToConstructorTHEN_TwoErrors() {
File model = new File(MODEL_FILES_BASE + "accesscontrol/InvalidAccessToConstructor.rebeca");
Set<CompilerExtension> extension = new HashSet<CompilerExtension>();
compiler.compileRebecaFile(model, extension, CoreVersion.CORE_2_3);

ExceptionContainer expectedExceptionContainer = new ExceptionContainer();
expectedExceptionContainer.setCorrespondingResource(model);
expectedExceptionContainer.addException(new SymbolTableException("The method A() is not visible for the type A", 6, 7));
expectedExceptionContainer.addException(new SymbolTableException("The method f() is not visible for the type A", 15, 4));

Assertions.assertEquals(expectedExceptionContainer, exceptionContainer);
}

@Test
public void GIVEN_RebecaModelWithTwoReactiveclasses_WHEN_AccessToLocalMethodOfOtherActorTHEN_OneError() {
File model = new File(MODEL_FILES_BASE + "accesscontrol/InvalidAccessToSynchMethod.rebeca");
Set<CompilerExtension> extension = new HashSet<CompilerExtension>();
compiler.compileRebecaFile(model, extension, CoreVersion.CORE_2_3);

ExceptionContainer expectedExceptionContainer = new ExceptionContainer();
expectedExceptionContainer.setCorrespondingResource(model);
expectedExceptionContainer.addException(new SymbolTableException("The method f() is not visible for the type A", 12, 4));

Assertions.assertEquals(expectedExceptionContainer, exceptionContainer);
}

@Test
public void GIVEN_RebecaModelWithTwoReactiveclasses_WHEN_ValidAccessToMsgsrvsTHEN_NoError() {
File model = new File(MODEL_FILES_BASE + "accesscontrol/ValidAccessToMsgsrvs.rebeca");
Set<CompilerExtension> extension = new HashSet<CompilerExtension>();
compiler.compileRebecaFile(model, extension, CoreVersion.CORE_2_3);

ExceptionContainer expectedExceptionContainer = new ExceptionContainer();
expectedExceptionContainer.setCorrespondingResource(model);

Assertions.assertEquals(expectedExceptionContainer, exceptionContainer);
}




@Test
public void GIVEN_ManyTests_WHEN_AllAreCorrect_THEN_NoError() {
GIVEN_RebecaModelWithTwoReactiveclasses_WHEN_AccessToLocalMethodOfOtherActorTHEN_OneError();
GIVEN_RebecaModelWithTwoReactiveclasses_WHEN_AccessToConstructorTHEN_TwoErrors();
GIVEN_RebecaModelWithTwoReactiveclasses_WHEN_ValidAccessToMsgsrvsTHEN_NoError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
reactiveclass A(1) {
A() {

}
void f() {
self.A();
}
}

reactiveclass B(1) {
knownrebecs {
A a;
}
msgsrv g() {
a.A();
}
}

main {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
reactiveclass A(1) {
void f() {

}
}

reactiveclass B(1) {
knownrebecs {
A a;
}
msgsrv g() {
a.f();
}
}

main {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
reactiveclass A(1) {
msgsrv x() {

}
}

reactiveclass B(1) {
knownrebecs {
A a;
}
msgsrv y() {
self.y();
y();
z();
a.x();
}
msgsrv z() {

}
}

main {
A a():();
B b(a):();
}

0 comments on commit be751d4

Please sign in to comment.