-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Passing section-paragraph map to intermediate AST build functions for…
… use in RETCALL construction
- Loading branch information
1 parent
e1d073d
commit 70cfe8b
Showing
11 changed files
with
132 additions
and
58 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
18 changes: 18 additions & 0 deletions
18
smojol-core/src/main/java/org/smojol/common/transpiler/RetCallTranspilerNode.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,18 @@ | ||
package org.smojol.common.transpiler; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.smojol.common.ast.SemanticCategory; | ||
|
||
public class RetCallTranspilerNode extends TranspilerNode { | ||
private final String fallthroughTarget; | ||
|
||
public RetCallTranspilerNode(String fallthroughTarget, TranspilerCodeBlockNode body) { | ||
super(ImmutableList.of(), ImmutableList.of(SemanticCategory.BLOCK_BOUNDARY)); | ||
this.fallthroughTarget = fallthroughTarget; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return String.format("callret (\"%s\")", fallthroughTarget); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...oolkit/src/main/java/org/smojol/toolkit/analysis/task/transpiler/SectionParagraphMap.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,30 @@ | ||
package org.smojol.toolkit.analysis.task.transpiler; | ||
|
||
import lombok.Getter; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.smojol.common.ast.FlowNode; | ||
import org.smojol.common.ast.FlowNodeType; | ||
import org.smojol.common.navigation.FlowNodeNavigator; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
public class SectionParagraphMap { | ||
private final Map<FlowNode, List<FlowNode>> sectionParagraphsPairs; | ||
private final Map<FlowNode, FlowNode> paragraphToSectionMap; | ||
|
||
public SectionParagraphMap(FlowNode flowRoot) { | ||
List<FlowNode> sectionFlowNodes = new FlowNodeNavigator(flowRoot).findAllByCondition(fn -> fn.type() == FlowNodeType.SECTION); | ||
sectionParagraphsPairs = sectionFlowNodes.stream() | ||
.map(sfn -> (Pair<FlowNode, List<FlowNode>>) ImmutablePair.of(sfn, new FlowNodeNavigator(sfn).findAllByCondition(n -> n.type() == FlowNodeType.PARAGRAPH))) | ||
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight)); | ||
paragraphToSectionMap = sectionFlowNodes.stream().flatMap(sfn -> | ||
new FlowNodeNavigator(sfn).findAllByCondition(n -> n.type() == FlowNodeType.PARAGRAPH).stream() | ||
.map(para -> ImmutablePair.of(para, sfn)) | ||
).collect(Collectors.toMap(Pair::getLeft, Pair::getRight)); | ||
|
||
} | ||
} |
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
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
Oops, something went wrong.