Skip to content

Commit 28d6269

Browse files
author
Dominik Helm
committed
Fix type and visibility problems
1 parent efe58cc commit 28d6269

File tree

5 files changed

+116
-109
lines changed

5 files changed

+116
-109
lines changed

OPAL/tac/src/main/scala/org/opalj/tac/DUVar.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ object DefSites {
114114
* @param value The value information.
115115
*/
116116
class DVar[+Value <: ValueInformation /*org.opalj.ai.ValuesDomain#DomainValue*/ ] private (
117-
var origin: ValueOrigin,
117+
private[tac] var origin: ValueOrigin,
118118
val value: Value,
119119
private[tac] var useSites: IntTrieSet
120120
) extends DUVar[Value] {
@@ -230,7 +230,7 @@ object DVar {
230230

231231
class UVar[+Value <: ValueInformation /*org.opalj.ai.ValuesDomain#DomainValue*/ ] private (
232232
val value: Value,
233-
var defSites: IntTrieSet
233+
private[tac] var defSites: IntTrieSet
234234
) extends DUVar[Value] {
235235

236236
def name: String = {

OPAL/tac2bc/src/main/scala/org/opalj/tac2bc/ExprProcessor.scala

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ import org.opalj.tac.StaticFunctionCall
6969
import org.opalj.tac.StaticMethodCall
7070
import org.opalj.tac.StringConst
7171
import org.opalj.tac.UVar
72+
import org.opalj.tac.V
7273
import org.opalj.tac.Var
7374
import org.opalj.tac.VirtualFunctionCall
7475
import org.opalj.tac.VirtualMethodCall
7576
import org.opalj.value.IsSReferenceValue
77+
import org.opalj.value.ValueInformation
7678

7779
object ExprProcessor {
7880

@@ -84,17 +86,18 @@ object ExprProcessor {
8486
* @param code list where bytecode instructions should be added
8587
*/
8688
def processExpression(
87-
expr: Expr[_],
88-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
89+
expr: Expr[V],
90+
uVarToLVIndex: Map[IntTrieSet, Int],
8991
code: mutable.ListBuffer[CodeElement[Nothing]]
9092
): Unit = {
9193
expr match {
9294
case const: Const => loadConstant(const, code)
93-
case variable: Var[_] => loadVariable(variable, uVarToLVIndex, code)
94-
case getField: GetField[_] => processGetField(getField, uVarToLVIndex, code)
95+
case variable: Var[V] => loadVariable(variable, uVarToLVIndex, code)
96+
case getField: GetField[V] => processGetField(getField, uVarToLVIndex, code)
9597
case getStatic: GetStatic => processGetStatic(getStatic, code)
96-
case binaryExpr: BinaryExpr[_] => processBinaryExpr(binaryExpr, uVarToLVIndex, code)
97-
case call @ Call(declaringClass, isInterface, name, descriptor) =>
98+
case binaryExpr: BinaryExpr[V] => processBinaryExpr(binaryExpr, uVarToLVIndex, code)
99+
case callExpr: Call[V@unchecked] =>
100+
val call @ Call(declaringClass, isInterface, name, descriptor) = callExpr
98101
processCall(
99102
call,
100103
declaringClass,
@@ -105,33 +108,33 @@ object ExprProcessor {
105108
code
106109
)
107110
case newExpr: New => processNewExpr(newExpr.tpe, code)
108-
case primitiveTypecastExpr: PrimitiveTypecastExpr[_] =>
111+
case primitiveTypecastExpr: PrimitiveTypecastExpr[V] =>
109112
processPrimitiveTypeCastExpr(primitiveTypecastExpr, uVarToLVIndex, code)
110-
case arrayLength: ArrayLength[_] => processArrayLength(arrayLength, uVarToLVIndex, code)
111-
case arrayLoadExpr: ArrayLoad[_] => processArrayLoad(arrayLoadExpr, uVarToLVIndex, code)
112-
case newArrayExpr: NewArray[_] => processNewArray(newArrayExpr, uVarToLVIndex, code)
113-
case invokedynamicFunctionCall: InvokedynamicFunctionCall[_] =>
113+
case arrayLength: ArrayLength[V] => processArrayLength(arrayLength, uVarToLVIndex, code)
114+
case arrayLoadExpr: ArrayLoad[V] => processArrayLoad(arrayLoadExpr, uVarToLVIndex, code)
115+
case newArrayExpr: NewArray[V] => processNewArray(newArrayExpr, uVarToLVIndex, code)
116+
case invokedynamicFunctionCall: InvokedynamicFunctionCall[V] =>
114117
processInvokedynamicFunctionCall(invokedynamicFunctionCall, uVarToLVIndex, code)
115-
case compare: Compare[_] => processCompare(compare, uVarToLVIndex, code)
116-
case prefixExpr: PrefixExpr[_] => processPrefixExpr(prefixExpr, uVarToLVIndex, code)
117-
case instanceOf: InstanceOf[_] => processInstanceOf(instanceOf, uVarToLVIndex, code)
118+
case compare: Compare[V] => processCompare(compare, uVarToLVIndex, code)
119+
case prefixExpr: PrefixExpr[V] => processPrefixExpr(prefixExpr, uVarToLVIndex, code)
120+
case instanceOf: InstanceOf[V] => processInstanceOf(instanceOf, uVarToLVIndex, code)
118121
case _ =>
119122
throw new UnsupportedOperationException("Unsupported expression type" + expr)
120123
}
121124
}
122125

123126
private def processInstanceOf(
124-
instanceOf: InstanceOf[_],
125-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
127+
instanceOf: InstanceOf[V],
128+
uVarToLVIndex: Map[IntTrieSet, Int],
126129
code: mutable.ListBuffer[CodeElement[Nothing]]
127130
): Unit = {
128131
ExprProcessor.processExpression(instanceOf.value, uVarToLVIndex, code)
129132
code += INSTANCEOF(instanceOf.cmpTpe)
130133
}
131134

132135
private def processPrefixExpr(
133-
prefixExpr: PrefixExpr[_],
134-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
136+
prefixExpr: PrefixExpr[V],
137+
uVarToLVIndex: Map[IntTrieSet, Int],
135138
code: mutable.ListBuffer[CodeElement[Nothing]]
136139
): Unit = {
137140
// Process the operand (the expression being negated)
@@ -150,8 +153,8 @@ object ExprProcessor {
150153
}
151154

152155
private def processCompare(
153-
compare: Compare[_],
154-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
156+
compare: Compare[V],
157+
uVarToLVIndex: Map[IntTrieSet, Int],
155158
code: mutable.ListBuffer[CodeElement[Nothing]]
156159
): Unit = {
157160
// Process the left expression
@@ -181,8 +184,8 @@ object ExprProcessor {
181184
}
182185

183186
private def processInvokedynamicFunctionCall(
184-
invokedynamicFunctionCall: InvokedynamicFunctionCall[_],
185-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
187+
invokedynamicFunctionCall: InvokedynamicFunctionCall[V],
188+
uVarToLVIndex: Map[IntTrieSet, Int],
186189
code: mutable.ListBuffer[CodeElement[Nothing]]
187190
): Unit = {
188191
// Process each parameter
@@ -196,8 +199,8 @@ object ExprProcessor {
196199
}
197200

198201
private def processNewArray(
199-
newArrayExpr: NewArray[_],
200-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
202+
newArrayExpr: NewArray[V],
203+
uVarToLVIndex: Map[IntTrieSet, Int],
201204
code: mutable.ListBuffer[CodeElement[Nothing]]
202205
): Unit = {
203206
// Process each parameter
@@ -215,8 +218,8 @@ object ExprProcessor {
215218
}
216219

217220
private def processArrayLoad(
218-
arrayLoadExpr: ArrayLoad[_],
219-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
221+
arrayLoadExpr: ArrayLoad[V],
222+
uVarToLVIndex: Map[IntTrieSet, Int],
220223
code: mutable.ListBuffer[CodeElement[Nothing]]
221224
): Unit = {
222225
// Load the array reference onto the stack
@@ -241,15 +244,15 @@ object ExprProcessor {
241244
}
242245

243246
// Helper function to infer the element type from the array reference expression
244-
def inferElementType(expr: Expr[_]): Type = {
245-
expr.asInstanceOf[UVar[_]].value.asInstanceOf[IsSReferenceValue[_]].theUpperTypeBound.asInstanceOf[ArrayType] match {
247+
def inferElementType(expr: Expr[V]): Type = {
248+
expr.asVar.value.asInstanceOf[IsSReferenceValue[_]].theUpperTypeBound match {
246249
case ArrayType(componentType) => componentType
247250
case _ => throw new IllegalArgumentException(s"Expected an array type but found: ${expr.cTpe}")
248251
}
249252
}
250253
private def processArrayLength(
251-
arrayLength: ArrayLength[_],
252-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
254+
arrayLength: ArrayLength[V],
255+
uVarToLVIndex: Map[IntTrieSet, Int],
253256
code: mutable.ListBuffer[CodeElement[Nothing]]
254257
): Unit = {
255258
// Process the receiver object (e.g., aload_0 for `this`)
@@ -265,24 +268,26 @@ object ExprProcessor {
265268
}
266269

267270
def processCall(
268-
call: Call[_],
271+
call: Call[V],
269272
declaringClass: ReferenceType,
270273
isInterface: Boolean,
271274
methodName: String,
272275
methodDescriptor: MethodDescriptor,
273-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
276+
uVarToLVIndex: Map[IntTrieSet, Int],
274277
code: mutable.ListBuffer[CodeElement[Nothing]]
275278
): Unit = {
276279
// Process each parameter
277280
for (param <- call.allParams) ExprProcessor.processExpression(param, uVarToLVIndex, code)
278-
code += call match {
279-
case _: VirtualMethodCall[_] | _: VirtualFunctionCall[_] =>
280-
if (isInterface) INVOKEINTERFACE(declaringClass.asObjectType, methodName, methodDescriptor)
281-
else INVOKEVIRTUAL(declaringClass, methodName, methodDescriptor)
282-
case _: NonVirtualMethodCall[_] | _: NonVirtualFunctionCall[_] =>
283-
INVOKESPECIAL(declaringClass.asObjectType, isInterface, methodName, methodDescriptor)
284-
case _: StaticMethodCall[_] | _: StaticFunctionCall[_] =>
285-
INVOKESTATIC(declaringClass.asObjectType, isInterface, methodName, methodDescriptor)
281+
code += {
282+
call match {
283+
case _: VirtualMethodCall[V] | _: VirtualFunctionCall[V] =>
284+
if (isInterface) INVOKEINTERFACE(declaringClass.asObjectType, methodName, methodDescriptor)
285+
else INVOKEVIRTUAL(declaringClass, methodName, methodDescriptor)
286+
case _: NonVirtualMethodCall[V] | _: NonVirtualFunctionCall[V] =>
287+
INVOKESPECIAL(declaringClass.asObjectType, isInterface, methodName, methodDescriptor)
288+
case _: StaticMethodCall[V] | _: StaticFunctionCall[V] =>
289+
INVOKESTATIC(declaringClass.asObjectType, isInterface, methodName, methodDescriptor)
290+
}
286291
}
287292
}
288293

@@ -312,13 +317,13 @@ object ExprProcessor {
312317
}
313318

314319
// Method to get LVIndex for a variable
315-
private def getVariableLvIndex(variable: Var[_], uVarToLVIndex: mutable.Map[IntTrieSet, Int]): Int = {
320+
private def getVariableLvIndex(variable: Var[V], uVarToLVIndex: Map[IntTrieSet, Int]): Int = {
316321
variable match {
317-
case duVar: DUVar[_] =>
322+
case duVar: DUVar[ValueInformation] =>
318323
val uVarDefSites = uVarToLVIndex.find { case (defSites, _) =>
319324
duVar match {
320-
case dVar: DVar[_] => defSites.contains(dVar.origin)
321-
case uVar: UVar[_] => defSites.exists(uVar.defSites.contains)
325+
case dVar: DVar[ValueInformation] => defSites.contains(dVar.originatedAt)
326+
case uVar: UVar[ValueInformation] => defSites.exists(uVar.definedBy.contains)
322327
}
323328
}
324329
uVarDefSites match {
@@ -330,8 +335,8 @@ object ExprProcessor {
330335
}
331336

332337
private def loadVariable(
333-
variable: Var[_],
334-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
338+
variable: Var[V],
339+
uVarToLVIndex: Map[IntTrieSet, Int],
335340
code: mutable.ListBuffer[CodeElement[Nothing]]
336341
): Unit = {
337342
val index = getVariableLvIndex(variable, uVarToLVIndex)
@@ -351,8 +356,8 @@ object ExprProcessor {
351356
}
352357

353358
def storeVariable(
354-
variable: Var[_],
355-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
359+
variable: Var[V],
360+
uVarToLVIndex: Map[IntTrieSet, Int],
356361
code: mutable.ListBuffer[CodeElement[Nothing]]
357362
): Unit = {
358363
val index: Int = getVariableLvIndex(variable, uVarToLVIndex)
@@ -372,8 +377,8 @@ object ExprProcessor {
372377
}
373378

374379
private def processGetField(
375-
getField: GetField[_],
376-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
380+
getField: GetField[V],
381+
uVarToLVIndex: Map[IntTrieSet, Int],
377382
code: mutable.ListBuffer[CodeElement[Nothing]]
378383
): Unit = {
379384
// Load the object reference onto the stack
@@ -390,8 +395,8 @@ object ExprProcessor {
390395
}
391396

392397
private def processBinaryExpr(
393-
binaryExpr: BinaryExpr[_],
394-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
398+
binaryExpr: BinaryExpr[V],
399+
uVarToLVIndex: Map[IntTrieSet, Int],
395400
code: mutable.ListBuffer[CodeElement[Nothing]]
396401
): Unit = {
397402
// process the left expr and save the pc to give in the right expr processing
@@ -445,8 +450,8 @@ object ExprProcessor {
445450
}
446451
}
447452
private def processPrimitiveTypeCastExpr(
448-
primitiveTypecastExpr: PrimitiveTypecastExpr[_],
449-
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
453+
primitiveTypecastExpr: PrimitiveTypecastExpr[V],
454+
uVarToLVIndex: Map[IntTrieSet, Int],
450455
code: mutable.ListBuffer[CodeElement[Nothing]]
451456
): Unit = {
452457
// First, process the operand expression and add its instructions to the buffer

OPAL/tac2bc/src/main/scala/org/opalj/tac2bc/LvIndicesPreparation.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.opalj.tac.DUVar
99
import org.opalj.tac.Expr
1010
import org.opalj.tac.Stmt
1111
import org.opalj.tac.UVar
12+
import org.opalj.tac.V
1213
import org.opalj.value.ValueInformation
1314

1415
/**
@@ -36,10 +37,10 @@ object LvIndicesPreparation {
3637
def prepareLvIndices(
3738
method: Method,
3839
tacStmts: Array[(Stmt[DUVar[ValueInformation]], Int)]
39-
): mutable.Map[IntTrieSet, Int] = {
40+
): Map[IntTrieSet, Int] = {
4041

4142
// container for all DUVars in the method
42-
val duVars = mutable.ListBuffer[DUVar[_]]()
43+
val duVars = mutable.ListBuffer[DUVar[ValueInformation]]()
4344
tacStmts.foreach {
4445
case (stmt, _) =>
4546
if (stmt.isAssignment)
@@ -48,8 +49,8 @@ object LvIndicesPreparation {
4849
}
4950
val uVarToLVIndex = mutable.Map[IntTrieSet, Int]()
5051
val nextLVIndexAfterParameters = mapParametersAndPopulate(method, uVarToLVIndex)
51-
collectAllUVarsAndPopulateUVarToLVIndexMap(duVars, uVarToLVIndex, nextLVIndexAfterParameters)
52-
uVarToLVIndex
52+
collectAllUVarsAndPopulateUVarToLVIndexMap(duVars.toSeq, uVarToLVIndex, nextLVIndexAfterParameters)
53+
uVarToLVIndex.toMap
5354
}
5455

5556
/**
@@ -60,13 +61,13 @@ object LvIndicesPreparation {
6061
* @param initialLVIndex The initial index after having processed the parameters
6162
*/
6263
private def collectAllUVarsAndPopulateUVarToLVIndexMap(
63-
duVars: mutable.ListBuffer[DUVar[_]],
64+
duVars: Seq[DUVar[ValueInformation]],
6465
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
6566
initialLVIndex: Int
6667
): Unit = {
6768
var nextLVIndex = initialLVIndex
68-
duVars.toArray.foreach {
69-
case uVar: UVar[_] =>
69+
duVars.foreach {
70+
case uVar: UVar[ValueInformation] =>
7071
nextLVIndex = populateUVarToLVIndexMap(uVar, uVarToLVIndex, nextLVIndex)
7172
case _ => // we only need uVars
7273
}
@@ -100,20 +101,20 @@ object LvIndicesPreparation {
100101
* @param uVar A variable used in the method.
101102
*/
102103
private def populateUVarToLVIndexMap(
103-
uVar: UVar[_],
104+
uVar: UVar[ValueInformation],
104105
uVarToLVIndex: mutable.Map[IntTrieSet, Int],
105106
initialLVIndex: Int
106107
): Int = {
107108
var nextLVIndex = initialLVIndex
108-
val existingEntry = uVarToLVIndex.find { case (key, _) => key.intersect(uVar.defSites).nonEmpty }
109+
val existingEntry = uVarToLVIndex.find { case (key, _) => key.intersect(uVar.definedBy).nonEmpty }
109110
existingEntry match {
110111
case Some((existingDefSites, index)) =>
111-
val mergedDefSites = existingDefSites ++ uVar.defSites
112+
val mergedDefSites = existingDefSites ++ uVar.definedBy
112113
uVarToLVIndex -= existingDefSites
113114
uVarToLVIndex(mergedDefSites) = index
114115

115116
case None =>
116-
uVarToLVIndex.getOrElseUpdate(uVar.defSites, nextLVIndex)
117+
uVarToLVIndex.getOrElseUpdate(uVar.definedBy, nextLVIndex)
117118
nextLVIndex = incrementLVIndex(uVar, nextLVIndex)
118119
}
119120
nextLVIndex
@@ -126,7 +127,7 @@ object LvIndicesPreparation {
126127
* @param initialLVIndex current LV index
127128
* @return updated LV index based on the type of UVar
128129
*/
129-
private def incrementLVIndex(uVar: UVar[_], initialLVIndex: Int): Int = {
130+
private def incrementLVIndex(uVar: UVar[ValueInformation], initialLVIndex: Int): Int = {
130131
initialLVIndex + uVar.cTpe.operandSize
131132
}
132133

@@ -136,7 +137,7 @@ object LvIndicesPreparation {
136137
* @param expr The expression to be traversed
137138
* @param duVars ListBuffer to be extended with all DUVars found in the expression.
138139
*/
139-
private def collectDUVarFromExpr(expr: Expr[_], duVars: mutable.ListBuffer[DUVar[_]]): Unit = {
140+
private def collectDUVarFromExpr(expr: Expr[V], duVars: mutable.ListBuffer[DUVar[ValueInformation]]): Unit = {
140141
if (expr.isVar) duVars += expr.asVar
141142
else expr.forallSubExpressions(subExpr => { collectDUVarFromExpr(subExpr, duVars); true })
142143
}

0 commit comments

Comments
 (0)