Skip to content

Commit

Permalink
Bugs in feature annotation are fixed. This version does not support f…
Browse files Browse the repository at this point in the history
…eatures inside switch-case statement.
  • Loading branch information
Ehsan Khamespanah committed Aug 17, 2023
1 parent 0df8ecc commit d141053
Show file tree
Hide file tree
Showing 17 changed files with 2,791 additions and 2,297 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.rebecalang</groupId>
<artifactId>compiler</artifactId>
<version>2.16</version>
<version>2.17</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springframework.version>6.0.8</springframework.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,11 @@ private boolean evaluateAnnotationExpression(StatementSemanticCheckContainer sta
return true;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
protected boolean includeIfItSatisfiesFeature(LinkedList includedItems, Object item, List<Annotation> annotations) {
includedItems.addLast(item);
protected boolean satisfiesFeatureCondition(List<Annotation> annotations) {
for(Annotation annotation : annotations) {
if (!annotation.getIdentifier().equals(FEATURES_LABEL))
continue;
if(!evaluateAnnotationExpression(getStatementSemanticCheckContainer(), annotation.getValue())) {
includedItems.removeLast();
return false;
}
}
Expand All @@ -125,8 +122,8 @@ protected void removeStatementsBasedOnTheRequiredFeature(Statement givenStatemen

LinkedList<Statement> remaindStatements = new LinkedList<Statement>();
for(Statement statement : blockStatement.getStatements()) {
boolean included = includeIfItSatisfiesFeature(remaindStatements, statement, statement.getAnnotations());
if(included) {
if(satisfiesFeatureCondition(statement.getAnnotations())) {
remaindStatements.add(statement);
if(statement instanceof ConditionalStatement) {
removeStatementsBasedOnTheRequiredFeature(((ConditionalStatement)statement).getStatement());
removeStatementsBasedOnTheRequiredFeature(((ConditionalStatement)statement).getElseStatement());
Expand All @@ -140,8 +137,8 @@ protected void removeStatementsBasedOnTheRequiredFeature(Statement givenStatemen
for(SwitchStatementGroup switchStatementGroups : ((SwitchStatement)statement).getSwitchStatementGroups()) {
LinkedList<Statement> remaindSelectorStatements = new LinkedList<Statement>();
for(Statement selectorStatement : switchStatementGroups.getStatements()) {
if(includeIfItSatisfiesFeature(remaindSelectorStatements,
remaindSelectorStatements, selectorStatement.getAnnotations())) {
if(satisfiesFeatureCondition(selectorStatement.getAnnotations())) {
remaindSelectorStatements.add(selectorStatement);
removeStatementsBasedOnTheRequiredFeature(selectorStatement);
}
}
Expand All @@ -157,13 +154,12 @@ protected void removeStatementsBasedOnTheRequiredFeature(Statement givenStatemen

protected <T extends MethodDeclaration> List<T> removeMethods(List<T> methodDeclarations) {
LinkedList<T> included = new LinkedList<T>();
for(MethodDeclaration methodDeclaration : methodDeclarations) {
boolean methodIsIncluded = includeIfItSatisfiesFeature(included, methodDeclaration,
methodDeclaration.getAnnotations());
if(methodIsIncluded)
for(T methodDeclaration : methodDeclarations) {
if(satisfiesFeatureCondition(methodDeclaration.getAnnotations())) {
included.add(methodDeclaration);
removeStatementsBasedOnTheRequiredFeature(methodDeclaration.getBlock());
}
}

return included;
}

Expand All @@ -172,8 +168,8 @@ protected void removeInterfaceDeclarationsBasedOnTheRequiredFeature() {
new LinkedList<InterfaceDeclaration>();

for (InterfaceDeclaration id : rebecaModel.getRebecaCode().getInterfaceDeclaration()) {
boolean included = includeIfItSatisfiesFeature(includedInterfaceDeclarations, id, id.getAnnotations());
if(included) {
if(satisfiesFeatureCondition(id.getAnnotations())) {
includedInterfaceDeclarations.add(id);
List<MsgsrvDeclaration> includedMsgsrvs = removeMethods(id.getMsgsrvs());
id.getMsgsrvs().clear();
id.getMsgsrvs().addAll(includedMsgsrvs);
Expand All @@ -188,8 +184,9 @@ protected void removeReactiveClassDeclarationsBasedOnTheRequiredFeature() {
new LinkedList<ReactiveClassDeclaration>();

for (ReactiveClassDeclaration rcd : rebecaModel.getRebecaCode().getReactiveClassDeclaration()) {
boolean included = includeIfItSatisfiesFeature(includedReactiveClassDeclarations, rcd, rcd.getAnnotations());
if(included) {
if(satisfiesFeatureCondition(rcd.getAnnotations())) {
includedReactiveClassDeclarations.add(rcd);

List<ConstructorDeclaration> includedConstructurs = removeMethods(rcd.getConstructors());
rcd.getConstructors().clear();
rcd.getConstructors().addAll(includedConstructurs);
Expand All @@ -204,14 +201,18 @@ protected void removeReactiveClassDeclarationsBasedOnTheRequiredFeature() {

LinkedList<FieldDeclaration> includedStatevars = new LinkedList<FieldDeclaration>();
for(FieldDeclaration fd : rcd.getStatevars()) {
includeIfItSatisfiesFeature(includedStatevars, fd, fd.getAnnotations());
if(satisfiesFeatureCondition(fd.getAnnotations())) {
includedStatevars.add(fd);
}
}
rcd.getStatevars().clear();
rcd.getStatevars().addAll(includedStatevars);

LinkedList<FieldDeclaration> includedKnownRebecs = new LinkedList<FieldDeclaration>();
for(FieldDeclaration fd : rcd.getKnownRebecs()) {
includeIfItSatisfiesFeature(includedKnownRebecs, fd, fd.getAnnotations());
if(satisfiesFeatureCondition(fd.getAnnotations())) {
includedKnownRebecs.add(fd);
}
}
rcd.getKnownRebecs().clear();
rcd.getKnownRebecs().addAll(includedKnownRebecs);
Expand All @@ -228,7 +229,9 @@ protected void removeRebecInstancesBasedOnTheRequiredFeature() {
List<MainRebecDefinition> mrds = rebecaModel.getRebecaCode().getMainDeclaration().getMainRebecDefinition();

for(MainRebecDefinition mrd : mrds) {
includeIfItSatisfiesFeature(included, mrd, mrd.getAnnotations());
if(satisfiesFeatureCondition(mrd.getAnnotations())) {
included.add(mrd);
}
}
mrds.clear();
mrds.addAll(included);
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit d141053

Please sign in to comment.