CFG: Separate scope for method blocks

This commit is contained in:
Tom Hvitved
2020-11-19 09:29:15 +01:00
parent 4dd4373b53
commit 4626168969
5 changed files with 62 additions and 9 deletions

View File

@@ -8,7 +8,18 @@ private import internal.Splitting
private import internal.Completion
/** An AST node with an associated control-flow graph. */
class CfgScope = Method; // TODO: add more cases (e.g. bodies of lambdas/do blocks)
class CfgScope extends AstNode {
private string name;
CfgScope() {
name = this.(Method).getName().toString()
or
this = any(MethodCall mc | name = "block for " + mc.getMethod()).getBlock()
}
/** Gets the name of this scope. */
string getName() { result = name }
}
/**
* A control flow node.

View File

@@ -256,11 +256,7 @@ private module Trees {
}
}
private class BlockParameterTree extends LeafTree, BlockParameter { }
private class BlockParametersTree extends StandardPostOrderTree, BlockParameters {
final override AstNode getChildNode(int i) { result = this.getChild(i) }
private class BlockParametersTree extends LeafTree, BlockParameters {
override predicate isHidden() { any() }
}
@@ -282,6 +278,12 @@ private module Trees {
override predicate isHidden() { any() }
}
private class DoBlockTree extends StandardPreOrderTree, DoBlock {
final override AstNode getChildNode(int i) { result = this.getChild(i) }
override predicate isHidden() { any() }
}
private class ElseTree extends StandardPreOrderTree, Else {
final override AstNode getChildNode(int i) { result = this.getChild(i) }
@@ -382,12 +384,11 @@ private module Trees {
}
private class MethodCallTree extends StandardPostOrderTree, MethodCall {
// this.getBlock() is not included as it uses a different scope
final override AstNode getChildNode(int i) {
result = this.getArguments() and i = 0
or
result = this.getMethod() and i = 1
or
result = this.getBlock() and i = 2
}
}

View File

@@ -60,7 +60,12 @@ class Split extends TSplit {
string toString() { none() }
}
private CfgScope getScope(AstNode n) { result.getAFieldOrChild*() = n }
private AstNode parent(AstNode n) {
result.getAFieldOrChild() = n and
not n instanceof CfgScope
}
private CfgScope getScope(AstNode n) { result = parent+(n) }
/**
* Holds if split kinds `sk1` and `sk2` may overlap. That is, they may apply