pascal-lab / Tai-e-assignments

Tai-e assignments for static program analysis
https://tai-e.pascal-lab.net/
GNU Lesser General Public License v3.0
1.06k stars 242 forks source link

About the A1 #4

Open Shmily8421 opened 2 years ago

Shmily8421 commented 2 years ago

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

DianQK commented 2 years ago

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

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

Shmily8421 commented 2 years ago

Emmmm, Could u say that in more details?

DianQK commented 2 years ago

@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. :)

Shmily8421 commented 2 years ago

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.

MirageLyu commented 2 years ago

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.

BruceJiang066 commented 1 year ago

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 " != "

cyk2018 commented 1 year ago

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).