-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
219 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../de/monticore/expressions/streamexpressions/_ast/ASTEventStreamConstructorExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.monticore.expressions.streamexpressions._ast; | ||
|
||
import de.monticore.ast.ASTNode; | ||
import de.monticore.expressions.expressionsbasis._ast.ASTExpression; | ||
import de.monticore.expressions.streamexpressions.StreamExpressionsMill; | ||
import de.monticore.expressions.streamexpressions._ast.util.ASTNodeSiblingComparator; | ||
import de.monticore.expressions.streamexpressions._util.IStreamExpressionsTypeDispatcher; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ASTEventStreamConstructorExpression extends ASTEventStreamConstructorExpressionTOP { | ||
|
||
@Override | ||
public boolean isEventTimed() { | ||
return true; | ||
} | ||
|
||
/** | ||
* each inner List represents a time slice, | ||
* each time slice may hold any number of ASTExpressions. | ||
*/ | ||
public List<List<ASTExpression>> getExpressionsPerTimeSlice() { | ||
List<List<ASTExpression>> result = | ||
new ArrayList<>(sizeTickInStreamConstructors() + 1); | ||
List<ASTNode> nodes = new ArrayList<>(); | ||
nodes.addAll(getExpressionList()); | ||
nodes.addAll(getTickInStreamConstructorList()); | ||
nodes.sort(new ASTNodeSiblingComparator()); | ||
IStreamExpressionsTypeDispatcher dispatcher = | ||
StreamExpressionsMill.typeDispatcher(); | ||
List<ASTExpression> currentTimeSlice = new ArrayList(); | ||
for (int i = 0; i < nodes.size(); i++) { | ||
ASTNode node = nodes.get(i); | ||
if (dispatcher.isExpressionsBasisASTExpression(node)) { | ||
currentTimeSlice.add(dispatcher.asExpressionsBasisASTExpression(node)); | ||
} | ||
// Tick | ||
else { | ||
result.add(currentTimeSlice); | ||
currentTimeSlice = new ArrayList(); | ||
} | ||
} | ||
result.add(currentTimeSlice); | ||
return result; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...de/monticore/expressions/streamexpressions/_ast/ASTSimpleStreamConstructorExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.monticore.expressions.streamexpressions._ast; | ||
|
||
public class ASTSimpleStreamConstructorExpression extends ASTSimpleStreamConstructorExpressionTOP { | ||
|
||
|
||
|
||
} |
28 changes: 17 additions & 11 deletions
28
.../java/de/monticore/expressions/streamexpressions/_ast/ASTStreamConstructorExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
package de.monticore.expressions.streamexpressions._ast; | ||
|
||
public class ASTStreamConstructorExpression extends ASTStreamConstructorExpressionTOP { | ||
import de.monticore.expressions.expressionsbasis._ast.ASTExpression; | ||
|
||
import java.util.List; | ||
|
||
public interface ASTStreamConstructorExpression extends ASTStreamConstructorExpressionTOP { | ||
|
||
/** | ||
* If default and not specified otherwise, Event should be chosen. | ||
*/ | ||
public boolean isDefaultTimed() { | ||
return getTiming() == ASTConstantsStreamExpressions.DEFAULT; | ||
default boolean isDefaultTimed() { | ||
return false; | ||
} | ||
|
||
public boolean isEventTimed() { | ||
return getTiming() == ASTConstantsStreamExpressions.EVENT; | ||
default boolean isEventTimed() { | ||
return false; | ||
} | ||
|
||
public boolean isSyncTimed() { | ||
return getTiming() == ASTConstantsStreamExpressions.SYNC; | ||
default boolean isSyncTimed() { | ||
return false; | ||
} | ||
|
||
public boolean isToptTimed() { | ||
return getTiming() == ASTConstantsStreamExpressions.TOPT; | ||
default boolean isToptTimed() { | ||
return false; | ||
} | ||
|
||
public boolean isUntimed() { | ||
return getTiming() == ASTConstantsStreamExpressions.UNTIMED; | ||
default boolean isUntimed() { | ||
return false; | ||
} | ||
|
||
List<ASTExpression> getExpressionList(); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...a/de/monticore/expressions/streamexpressions/_ast/ASTToptStreamConstructorExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.monticore.expressions.streamexpressions._ast; | ||
|
||
public class ASTToptStreamConstructorExpression extends ASTToptStreamConstructorExpressionTOP { | ||
|
||
@Override | ||
public boolean isToptTimed() { | ||
return true; | ||
} | ||
|
||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...n/java/de/monticore/expressions/streamexpressions/_ast/util/ASTNodeSiblingComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.monticore.expressions.streamexpressions._ast.util; | ||
|
||
import de.monticore.ast.ASTNode; | ||
import de.se_rwth.commons.SourcePosition; | ||
import de.se_rwth.commons.logging.Log; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* Sorting based on source Position, | ||
* intended to sort siblings/cousins/etc. and nothing else. | ||
* If useful, this could be moved elsewhere. | ||
*/ | ||
public class ASTNodeSiblingComparator implements Comparator<ASTNode> { | ||
|
||
@Override | ||
public int compare(ASTNode o1, ASTNode o2) { | ||
int start = compare(o1.get_SourcePositionStart(), o2.get_SourcePositionStart()); | ||
int end = compare(o1.get_SourcePositionEnd(), o2.get_SourcePositionEnd()); | ||
// check if we are indeed sorting siblings or similar | ||
if (!((start < 0 && end < 0) | ||
|| (start == 0 && end == 0) | ||
|| (start > 0 || end > 0) | ||
)) { | ||
Log.error("0xFD54C internal error: unexpected ASTNodes compared"); | ||
} | ||
return start; | ||
} | ||
|
||
protected int compare(SourcePosition o1, SourcePosition o2) { | ||
// check if we are indeed sorting siblings or similar | ||
if (o1.getFileName() != o2.getFileName()) { | ||
Log.error("0xFD54D internal error: unexpected ASTNodes compared"); | ||
} | ||
return o1.compareTo(o2); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
.../monticore/expressions/streamexpressions/_prettyprint/StreamExpressionsPrettyPrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* (c) https://github.com/MontiCore/monticore */ | ||
|
||
package de.monticore.expressions.streamexpressions._prettyprint; | ||
|
||
import de.monticore.expressions.expressionsbasis._ast.ASTExpression; | ||
import de.monticore.expressions.streamexpressions._ast.ASTEventStreamConstructorExpression; | ||
import de.monticore.prettyprint.CommentPrettyPrinter; | ||
import de.monticore.prettyprint.IndentPrinter; | ||
|
||
import java.util.List; | ||
|
||
public class StreamExpressionsPrettyPrinter extends StreamExpressionsPrettyPrinterTOP { | ||
|
||
public StreamExpressionsPrettyPrinter(IndentPrinter printer, boolean printComments) { | ||
super(printer, printComments); | ||
} | ||
|
||
public void handle(ASTEventStreamConstructorExpression node) { | ||
if (this.isPrintComments()) { | ||
CommentPrettyPrinter.printPreComments(node, getPrinter()); | ||
} | ||
if (node.isTiming()) { | ||
getPrinter().print("Event"); | ||
} | ||
getPrinter().print("<"); | ||
List<List<ASTExpression>> expressionsPerTimeSlice = | ||
node.getExpressionsPerTimeSlice(); | ||
for (int i = 0; i < expressionsPerTimeSlice.size(); i++) { | ||
if (i != 0) { | ||
getPrinter().print(";"); | ||
} | ||
for (int j = 0; j < expressionsPerTimeSlice.get(i).size(); j++) { | ||
if (j != 0) { | ||
getPrinter().print(","); | ||
} | ||
expressionsPerTimeSlice.get(i).get(j).accept(getTraverser()); | ||
} | ||
} | ||
getPrinter().print(">"); | ||
if (this.isPrintComments()) { | ||
CommentPrettyPrinter.printPostComments(node, getPrinter()); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters