Skip to content

Commit 360bf12

Browse files
committed
Cumulative updates
1 parent df34460 commit 360bf12

20 files changed

+1076
-827
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "tip"
22

3-
scalaVersion := "2.12.6"
3+
scalaVersion := "2.12.8"
44

55
trapExit := false
66

src/tip/analysis/AndersenAnalysis.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import tip.solvers._
55
import tip.util.Log
66
import tip.ast.AstNodeData.{AstNodeWithDeclaration, DeclarationData}
77

8+
import scala.language.implicitConversions
9+
810
class AndersenAnalysis(program: AProgram)(implicit declData: DeclarationData) extends DepthFirstAstVisitor[Null] with PointsToAnalysis {
911

1012
val log = Log.logger[this.type]()
@@ -32,6 +34,11 @@ class AndersenAnalysis(program: AProgram)(implicit declData: DeclarationData) ex
3234
*/
3335
def visit(node: AstNode, arg: Null): Unit = {
3436

37+
/**
38+
* Implicitly convert from `AIdentifier` to `ADeclaration` by extracting the declaration node for the given identifier node.
39+
*/
40+
implicit def pdef(id: AIdentifier): ADeclaration = id.declaration
41+
3542
node match {
3643
case AAssignStmt(id: AIdentifier, alloc: AAlloc, _) => ??? //<--- Complete here
3744
case AAssignStmt(id1: AIdentifier, AUnaryOp(RefOp, id2: AIdentifier, _), _) => ??? //<--- Complete here

src/tip/analysis/CallContext.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ trait CallContext
1111
/**
1212
* Functions for creating call contexts.
1313
* @tparam C the type for call contexts
14-
* @tparam L the type for the abstract state lattice
1514
*/
16-
trait CallContextFunctions[C <: CallContext, L <: Lattice] {
15+
trait CallContextFunctions[C <: CallContext] {
1716

18-
val statelattice: L
17+
/**
18+
* The type for the abstract state lattice.
19+
*/
20+
type statelatticetype = Lattice
21+
22+
val statelattice: statelatticetype
1923

2024
/**
2125
* Initial context, for the main function.
@@ -47,7 +51,7 @@ case class CallStringContext(cs: List[CfgCallNode]) extends CallContext {
4751
/**
4852
* Call context construction for call strings.
4953
*/
50-
trait CallStringFunctions[L <: Lattice] extends CallContextFunctions[CallStringContext, L] {
54+
trait CallStringFunctions extends CallContextFunctions[CallStringContext] {
5155

5256
/**
5357
* Default maximum length for call strings: 1.
@@ -78,7 +82,7 @@ case class FunctionalContext(x: Any) extends CallContext { // TODO: find some wa
7882
/**
7983
* Call context construction for functional approach.
8084
*/
81-
trait FunctionalFunctions[L <: Lattice] extends CallContextFunctions[FunctionalContext, L] {
85+
trait FunctionalFunctions extends CallContextFunctions[FunctionalContext] {
8286

8387
/**
8488
* Creates a context as the empty abstract state.
Lines changed: 59 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,62 @@
11
package tip.analysis
22

3-
import tip.ast._
4-
import tip.cfg.{CfgNode, CfgStmtNode, IntraproceduralProgramCfg}
5-
import tip.lattices.{FlatLattice, MapLattice}
6-
import tip.solvers.{SimpleMapLatticeFixpointSolver, SimpleWorklistFixpointSolver}
7-
import tip.ast.AstNodeData.{AstNodeWithDeclaration, DeclarationData}
8-
9-
abstract class ConstantPropagationAnalysis(cfg: IntraproceduralProgramCfg)(implicit declData: DeclarationData) extends FlowSensitiveAnalysis[CfgNode](cfg) {
10-
11-
import tip.cfg.CfgOps._
12-
13-
val declaredVars: Set[ADeclaration] = cfg.nodes.flatMap(_.declaredVars)
14-
15-
val lattice = new MapLattice(cfg.nodes, new MapLattice(declaredVars, new FlatLattice[Int]()))
16-
17-
def transfer(n: CfgNode, s: lattice.sublattice.Element): lattice.sublattice.Element =
18-
n match {
19-
case r: CfgStmtNode =>
20-
r.data match {
21-
case varr: AVarStmt =>
22-
varr.declIds.foldLeft(s) { (acc, id) =>
23-
acc + (id -> lattice.sublattice.sublattice.Top)
24-
}
25-
case ass: AAssignStmt =>
26-
ass.left match {
27-
case id: AIdentifier =>
28-
val vdef: ADeclaration = id.declaration
29-
s + (vdef -> absEval(ass.right, s))
30-
case _ => ???
31-
}
32-
case _ => s
33-
}
34-
case _ => s
35-
}
36-
37-
private def absEval(exp: AExpr, env: Map[ADeclaration, lattice.sublattice.sublattice.Element]): lattice.sublattice.sublattice.Element =
38-
exp match {
39-
case id: AIdentifier => env(id.declaration)
40-
case num: ANumber => lattice.sublattice.sublattice.FlatEl(num.value)
41-
case bin: ABinaryOp =>
42-
val left = absEval(bin.left, env)
43-
val right = absEval(bin.right, env)
44-
(left, right) match {
45-
case (lattice.sublattice.sublattice.FlatEl(x), lattice.sublattice.sublattice.FlatEl(y)) =>
46-
bin.operator match {
47-
case Eqq => lattice.sublattice.sublattice.FlatEl(if (x == y) 1 else 0)
48-
case Divide => if (y != 0) lattice.sublattice.sublattice.FlatEl(x / y) else lattice.sublattice.sublattice.Top
49-
case GreatThan => lattice.sublattice.sublattice.FlatEl(if (x > y) 1 else 0)
50-
case Minus => lattice.sublattice.sublattice.FlatEl(x - y)
51-
case Plus => lattice.sublattice.sublattice.FlatEl(x + y)
52-
case Times => lattice.sublattice.sublattice.FlatEl(x * y)
53-
case _ => ???
54-
}
55-
case (lattice.sublattice.sublattice.Bot, _) => lattice.sublattice.sublattice.Bot
56-
case (_, lattice.sublattice.sublattice.Bot) => lattice.sublattice.sublattice.Bot
57-
case (_, lattice.sublattice.sublattice.Top) => lattice.sublattice.sublattice.Top
58-
case (lattice.sublattice.sublattice.Top, _) => lattice.sublattice.sublattice.Top
59-
}
60-
case input: AInput => lattice.sublattice.sublattice.Top
61-
case _ => ???
62-
63-
}
3+
import tip.ast.AstNodeData.DeclarationData
4+
import tip.cfg.{InterproceduralProgramCfg, IntraproceduralProgramCfg}
5+
import tip.lattices.ConstantPropagationLattice
6+
7+
object ConstantPropagationAnalysis {
8+
9+
object Intraprocedural {
10+
11+
/**
12+
* Intraprocedural analysis that uses the simple fixpoint solver.
13+
*/
14+
class SimpleSolver(cfg: IntraproceduralProgramCfg)(implicit declData: DeclarationData)
15+
extends IntraprocValueAnalysisSimpleSolver(cfg, ConstantPropagationLattice)
16+
17+
/**
18+
* Intraprocedural analysis that uses the worklist solver.
19+
*/
20+
class WorklistSolver(cfg: IntraproceduralProgramCfg)(implicit declData: DeclarationData)
21+
extends IntraprocValueAnalysisWorklistSolver(cfg, ConstantPropagationLattice)
22+
23+
/**
24+
* Intraprocedural analysis that uses the worklist solver with reachability.
25+
*/
26+
class WorklistSolverWithReachability(cfg: IntraproceduralProgramCfg)(implicit declData: DeclarationData)
27+
extends IntraprocValueAnalysisWorklistSolverWithReachability(cfg, ConstantPropagationLattice)
28+
29+
/**
30+
* Intraprocedural analysis that uses the worklist solver with reachability and propagation-style.
31+
*/
32+
class WorklistSolverWithReachabilityAndPropagation(cfg: IntraproceduralProgramCfg)(implicit declData: DeclarationData)
33+
extends IntraprocValueAnalysisWorklistSolverWithReachabilityAndPropagation(cfg, ConstantPropagationLattice)
34+
}
35+
36+
object Interprocedural {
37+
38+
/**
39+
* Interprocedural analysis that uses the worklist solver with reachability.
40+
*/
41+
class WorklistSolverWithReachability(cfg: InterproceduralProgramCfg)(implicit declData: DeclarationData)
42+
extends InterprocValueAnalysisWorklistSolverWithReachability(cfg, ConstantPropagationLattice)
43+
44+
/**
45+
* Interprocedural analysis that uses the worklist solver with reachability and propagation-style.
46+
*/
47+
class WorklistSolverWithReachabilityAndPropagation(cfg: InterproceduralProgramCfg)(implicit declData: DeclarationData)
48+
extends InterprocValueAnalysisWorklistSolverWithReachabilityAndPropagation(cfg, ConstantPropagationLattice)
49+
50+
/**
51+
* Interprocedural analysis that uses the worklist solver with reachability and propagation-style.
52+
* with call-string context sensivity.
53+
*/
54+
class CallString(cfg: InterproceduralProgramCfg)(implicit declData: DeclarationData) extends CallStringValueAnalysis(cfg, ConstantPropagationLattice)
55+
56+
/**
57+
* Interprocedural analysis that uses the worklist solver with reachability and propagation-style.
58+
* with functional-approach context sensivity.
59+
*/
60+
class Functional(cfg: InterproceduralProgramCfg)(implicit declData: DeclarationData) extends FunctionalValueAnalysis(cfg, ConstantPropagationLattice)
61+
}
6462
}
65-
66-
/**
67-
* Constant propagation analysis that uses the simple fipoint solver.
68-
*/
69-
class ConstantPropagationAnalysisSimpleSolver(cfg: IntraproceduralProgramCfg)(implicit declData: DeclarationData)
70-
extends ConstantPropagationAnalysis(cfg)
71-
with SimpleMapLatticeFixpointSolver[CfgNode]
72-
with ForwardDependencies
73-
74-
/**
75-
* Constant propagation analysis that uses the worklist solver.
76-
*/
77-
class ConstantPropagationAnalysisWorklistSolver(cfg: IntraproceduralProgramCfg)(implicit declData: DeclarationData)
78-
extends ConstantPropagationAnalysis(cfg)
79-
with SimpleWorklistFixpointSolver[CfgNode]
80-
with ForwardDependencies

src/tip/analysis/FlowSensitiveAnalysis.scala

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,63 +49,68 @@ object FlowSensitiveAnalysis {
4949
case AnalysisOption.Disabled => None
5050
case AnalysisOption.`simple` =>
5151
Some(kind match {
52-
case Analysis.sign => new IntraprocSignAnalysisSimpleSolver(typedCfg.left.get)
52+
case Analysis.sign => new SimpleSignAnalysis(typedCfg.left.get); // same functionality as SignAnalysis.Intraprocedural.SimpleSolver(typedCfg.left.get)
5353
case Analysis.livevars => new LiveVarsAnalysisSimpleSolver(typedCfg.left.get)
5454
case Analysis.available => new AvailableExpAnalysisSimpleSolver(typedCfg.left.get)
5555
//case Analysis.vbusy => new VeryBusyExpAnalysisSimpleSolver(typedCfg.left.get) <--- Complete here
5656
//case Analysis.reaching => new ReachingDefAnalysisSimpleSolver(typedCfg.left.get) <--- Complete here
57-
case Analysis.constprop => new ConstantPropagationAnalysisSimpleSolver(typedCfg.left.get)
57+
case Analysis.constprop => new ConstantPropagationAnalysis.Intraprocedural.SimpleSolver(typedCfg.left.get)
5858
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
5959
})
6060
case AnalysisOption.`wl` =>
6161
Some(kind match {
62-
case Analysis.sign => new IntraprocSignAnalysisWorklistSolver(typedCfg.left.get)
62+
case Analysis.sign => new SignAnalysis.Intraprocedural.WorklistSolver(typedCfg.left.get)
6363
case Analysis.livevars => new LiveVarsAnalysisWorklistSolver(typedCfg.left.get)
6464
case Analysis.available => new AvailableExpAnalysisWorklistSolver(typedCfg.left.get)
6565
//case Analysis.vbusy => new VeryBusyExpAnalysisWorklistSolver(typedCfg.left.get) <--- Complete here
6666
//case Analysis.reaching => new ReachingDefAnalysisWorklistSolver(typedCfg.left.get) <--- Complete here
67-
case Analysis.constprop => new ConstantPropagationAnalysisWorklistSolver(typedCfg.left.get)
67+
case Analysis.constprop => new ConstantPropagationAnalysis.Intraprocedural.WorklistSolver(typedCfg.left.get)
6868
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
6969
})
7070
case AnalysisOption.`wlr` =>
7171
Some(kind match {
72-
case Analysis.sign => new IntraprocSignAnalysisWorklistSolverWithReachability(typedCfg.left.get)
73-
case Analysis.interval => new IntervalAnalysisWorklistSolverWithReachability(typedCfg.left.get)
72+
case Analysis.sign => new SignAnalysis.Intraprocedural.WorklistSolverWithReachability(typedCfg.left.get)
73+
case Analysis.constprop => new ConstantPropagationAnalysis.Intraprocedural.WorklistSolverWithReachability(typedCfg.left.get)
7474
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
7575
})
7676
case AnalysisOption.`wlrw` =>
7777
Some(kind match {
78-
case Analysis.interval => new IntervalAnalysisWorklistSolverWithWidening(typedCfg.left.get)
78+
case Analysis.interval => new IntervalAnalysis.Intraprocedural.WorklistSolverWithWidening(typedCfg.left.get)
7979
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
8080
})
8181
case AnalysisOption.`wlrwn` =>
8282
Some(kind match {
83-
case Analysis.interval => new IntervalAnalysisWorklistSolverWithWideningAndNarrowing(typedCfg.left.get)
83+
case Analysis.interval => new IntervalAnalysis.Intraprocedural.WorklistSolverWithWideningAndNarrowing(typedCfg.left.get)
8484
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
8585
})
8686
case AnalysisOption.`wlrp` =>
8787
Some(kind match {
88-
case Analysis.sign => new IntraprocSignAnalysisWorklistSolverWithReachabilityAndPropagation(typedCfg.left.get)
88+
case Analysis.sign => new SignAnalysis.Intraprocedural.WorklistSolverWithReachabilityAndPropagation(typedCfg.left.get)
89+
case Analysis.constprop => new ConstantPropagationAnalysis.Intraprocedural.WorklistSolverWithReachabilityAndPropagation(typedCfg.left.get)
8990
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
9091
})
9192
case AnalysisOption.`iwlr` =>
9293
Some(kind match {
93-
case Analysis.sign => new InterprocSignAnalysisWorklistSolverWithReachability(typedCfg.right.get)
94+
case Analysis.sign => new SignAnalysis.Interprocedural.WorklistSolverWithReachability(typedCfg.right.get)
95+
case Analysis.constprop => new ConstantPropagationAnalysis.Interprocedural.WorklistSolverWithReachability(typedCfg.right.get)
9496
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
9597
})
9698
case AnalysisOption.`iwlrp` =>
9799
Some(kind match {
98-
case Analysis.sign => new InterprocSignAnalysisWorklistSolverWithReachabilityAndPropagation(typedCfg.right.get)
100+
case Analysis.sign => new SignAnalysis.Interprocedural.WorklistSolverWithReachabilityAndPropagation(typedCfg.right.get)
101+
case Analysis.constprop => new ConstantPropagationAnalysis.Interprocedural.WorklistSolverWithReachabilityAndPropagation(typedCfg.right.get)
99102
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
100103
})
101104
case AnalysisOption.`csiwlrp` =>
102105
Some(kind match {
103-
case Analysis.sign => new CallStringSignAnalysis(typedCfg.right.get)
106+
case Analysis.sign => new SignAnalysis.Interprocedural.CallString(typedCfg.right.get)
107+
case Analysis.constprop => new ConstantPropagationAnalysis.Interprocedural.CallString(typedCfg.right.get)
104108
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
105109
})
106110
case AnalysisOption.`cfiwlrp` =>
107111
Some(kind match {
108-
case Analysis.sign => new FunctionalSignAnalysis(typedCfg.right.get)
112+
case Analysis.sign => new SignAnalysis.Interprocedural.Functional(typedCfg.right.get)
113+
case Analysis.constprop => new ConstantPropagationAnalysis.Interprocedural.Functional(typedCfg.right.get)
109114
case _ => throw new RuntimeException(s"Unsupported solver option `$options` for the analysis $kind")
110115
})
111116
case AnalysisOption.`ide` =>

0 commit comments

Comments
 (0)