Skip to content

Commit

Permalink
Graph pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkosertic committed May 6, 2024
1 parent d3eb5c8 commit 20b9bf7
Show file tree
Hide file tree
Showing 6 changed files with 654 additions and 362 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2024 Mirko Sertic
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.mirkosertic.bytecoder.core.patternmatcher;

import de.mirkosertic.bytecoder.core.ir.Node;

import java.util.HashMap;
import java.util.Map;

class EvaluationContext {

private final Node[] nodeIndex;
private final Map<Node, Node[]> outgoingFlows;

EvaluationContext(final Node rootNode, final int indexSize) {
this.nodeIndex = new Node[indexSize];
this.nodeIndex[0] = rootNode;
this.outgoingFlows = new HashMap<>();
}

Node getRoot() {
return nodeIndex[0];
}

Node[] outgoingDataFlowsFor(final Node node) {
return outgoingFlows.computeIfAbsent(node, Node::outgoingDataFlows);
}

boolean nodeKnownAt(final int index) {
return nodeIndex[index] != null;
}

void registerNodeAt(final int index, final Node node) {
nodeIndex[index] = node;
}

Node getNodeAt(final int index) {
return nodeIndex[index];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2024 Mirko Sertic
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.mirkosertic.bytecoder.core.patternmatcher;

import de.mirkosertic.bytecoder.core.ir.Node;

import java.util.Map;

public class Match {

private final Node root;
private final Map<Node, Node> mappings;

Match(final Node root, final Map<Node, Node> mappings) {
this.root = root;
this.mappings = mappings;
}

public Node root() {
return root;
}

public Node mappingFor(final Node node) {
return mappings.get(node);
}
}
Loading

0 comments on commit 20b9bf7

Please sign in to comment.