Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved property edges #1642

Merged
merged 8 commits into from
Aug 9, 2024
Merged

Improved property edges #1642

merged 8 commits into from
Aug 9, 2024

Conversation

oxisto
Copy link
Member

@oxisto oxisto commented Aug 1, 2024

TL;DR

This PR adds major improvements to property edges. We got rid of the Properties map and replaced them with individual Kotlin properties. Furthermore lists of edges are now dedicated container classes with magic.

Introduction of new specific edge classes

Next to the Dataflow edge class, which already exists, we added new edge classes. The PropertyEdge class itself is now abstract and thus no "generic" property edges (without any properties) can be created. There were a few uses of these kind of edges, this PR reverts them back to regular node lists (until we decide that this edge actually needs properties).

Usage

This edge class denotes the usage of a declaration in a reference.

Invoke

Invocation of a function declaration by a call expression.

AstEdge

Part of the AST.

TemplateArgument

AST edge for template invocation arguments.

EvaluationOrder

Part of the EOG.

ControlDependence

Part of the CDG.

Conversion of properties in Properties map to individual properties

This is basically the consequence of the above:

  • INDEX: index to Edge
  • NAME: name to Edge
  • DEPENDENCE: dependence to Edge
  • UNREACHABLE: unreachable to EvaluationOrder
  • BRANCH: branch to EvaluationOrder
  • BRANCH: branches to ControlDependence
  • INSTANTIATION: instantiation to TemplateArgument

Simplified creation of edges

Previously we had a lot of addXXX wrapper functions around property edges that took care of things like "mirroring" prev/next as well as inserting indices. This is all now done automagically by appropriate containers of property edges (and under the PropertyEdgeCollection interface under the hood.

This makes it easy to add new edges to the collection based on "target" nodes and it also supports setting appropriate properties using a builder pattern.

node1.nextEOGEdges.add(node2) {
  branch = false
  unreachable = true
}

For all "mirrored" properties, this will also add the edge to the corresponding mirror property (next vs. prev). In order to use this feature the mirror property needs to be specified.

class Node /* ... */ {
  var nextDFGEdges: Dataflows<Node> = Dataflows<Node>(this, Node::prevDFGEdges, outgoing = true)
  var prevDFGEdges: Dataflows<Node> = Dataflows<Node>(this, Node::nextDFGEdges, outgoing = false)
}
node1.nextDFGEdges.add(node2)
// node2 will also now have node1 in its prevDFGEdges

Open Issues

  • Use mirror collection in EOG nodes
  • Remove all remaining add/remove functions
  • Implement preRemove hook for removal functions
  • Final cleanups
  • Rename PropertyEdge to Edge to be more consistent with Node?
  • Decide on the type returned by unwrapping (List vs. MutableList vs UnwrappedEdgeList)

@oxisto oxisto marked this pull request as ready for review August 7, 2024 20:33
Copy link

sonarcloud bot commented Aug 9, 2024

@oxisto oxisto merged commit c12deb6 into main Aug 9, 2024
3 checks passed
@oxisto oxisto deleted the better-property-edges branch August 9, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent return type for getProperty(Properties.BRANCH)
3 participants