pedal-edu / pedal

A collection of tools to analyze student's Python source code
https://pedal-edu.github.io/pedal/
MIT License
29 stars 7 forks source link

TIFA could map AST Nodes to Values #35

Open acbart opened 4 years ago

acbart commented 4 years ago

TIFA walks the AST and abstractly evaluates the program. At each step of the tree, it has a best guess (or guesses, technically) about what the current type of that expression is. We could easily produce a dictionary that maps instances of AST nodes from the tree to the type that was determined.

The biggest potential application of this is connecting that data back to CAIT. If you found an expression match in the source code, TIFA could tell you what type of value it is - not just when it is a Name, but when it's anything!

Student code:

my_list = ["Ice", "Fire", "Thunder"]
my_value = my_list[1]

Instructor code:

match= find_match("my_value = __expr__")
tifa_check_type(match['__expr__'])
# Would be a Tifa `StrType`

Not sure what the exact interface should look like; I kind of prefer the idea that Tifa would have a function rather than this being a method inside CAIT. However, I'm open to alternative ideas.

lukesg08 commented 1 year ago

So CAIT actually wraps AST nodes in CAIT nodes, but mirrors all of the base AST node functionality so that you SHOULD be able to treat them as AST nodes if I remember correctly. So you could pass the root node of a match to Tifa, if it can take in an AST, and then TIFA can just traverse over the CAIT version of the tree instead when it does it's usual activities.