Tai-e-assignments icon indicating copy to clipboard operation
Tai-e-assignments copied to clipboard

About the A1

Open Shmily8421 opened this issue 2 years ago • 7 comments

How could I get the value from statement? The Lvalueclass and the Rvalueclass is not a Varclass image

Shmily8421 avatar Jul 03 '22 02:07 Shmily8421

@Shmily8421 RValue is not always Var, you can check Exp.getUses().

'a + b'.getUses() -> [Var, Var].

DianQK avatar Jul 03 '22 11:07 DianQK

Emmmm, Could u say that in more details?

Shmily8421 avatar Jul 03 '22 12:07 Shmily8421

@Shmily8421

2.1 Tai-e Classes You Need to Know

The RValue may be a Var, a BinaryExp, or another type. a + b is a BinaryExp (also AbstractBinaryExp):

You can get this code from dependencies.jar:

abstract class AbstractBinaryExp implements BinaryExp {
    public List<RValue> getUses() {
        return List.of(this.operand1, this.operand2);
    }
}

Maybe we should assume that the AST is brought directly into the IR?

  • a = b is Var = Var
  • a = b + c is Var = BinaryExp, this can be extended as Var = Var Op Var

btw, I don't know the design details of IR. because the getUses is a method of the Exp and I use recursion to handle this.

Read the code and comments in the project with patience and good luck. :)

DianQK avatar Jul 03 '22 13:07 DianQK

Okay, I can understand the AST logic. But as you said, the definition of these interface class is quite complex, so that I don't know how to get the Var in this sentence through the Stmt class.

Shmily8421 avatar Jul 04 '22 08:07 Shmily8421

Check the class pascal.taie.ir.stmt.AbstractStmt. There are 7 overrides of its method getUses(), and some of these override implementations reused Exp.getUses(). In most cases the getUses() actually returns a List of Var...while i didn't statically check all the cases, i have no idea if possible that the return List of getUses() contains objects of other subclasses of Rvalue instead of Var...maybe print the type during execution is a way to find it.

So, maybe you need to check if (rvalue instanceof Var), then force cast the rvalue to Var if true.

MirageLyu avatar Jul 04 '22 12:07 MirageLyu

How could I get the value from statement? The Lvalueclass and the Rvalueclass is not a Varclass image

boolean flag=(temp!=in) ,this statement must use the " equals()" to replace the " != "

BruceJiang066 avatar Dec 25 '22 11:12 BruceJiang066

How could I get the value from statement? The Lvalueclass and the Rvalueclass is not a Varclass image

boolean flag=(temp!=in) ,this statement must use the " equals()" to replace the " != "

you can also use the method "union" whose result type is boolean (true when the FactSet is changed).

cyk2018 avatar May 28 '23 03:05 cyk2018