MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / setDef

Method setDef

chapter02/src/main/java/com/seaofnodes/simple/node/Node.java:138–153  ·  view source on GitHub ↗

Change a def into a Node. Keeps the edges correct, by removing the corresponding use->def edge. This may make the original def go dead. This function is co-recursive with #kill. @param idx which def to set @param new_def the new definition @return new_def for f

(int idx, Node new_def )

Source from the content-addressed store, hash-verified

136 * @return new_def for flow coding
137 */
138 Node setDef(int idx, Node new_def ) {
139 Node old_def = in(idx);
140 if( old_def == new_def ) return this; // No change
141 // If new def is not null, add the corresponding def->use edge
142 // This needs to happen before removing the old node's def->use edge as
143 // the new_def might get killed if the old node kills it recursively.
144 if( new_def != null )
145 new_def.addUse(this);
146 if( old_def != null && // If the old def exists, remove a def->use edge
147 old_def.delUse(this) ) // If we removed the last use, the old def is now dead
148 old_def.kill(); // Kill old def
149 // Set the new_def over the old (killed) edge
150 _inputs.set(idx,new_def);
151 // Return self for easy flow-coding
152 return new_def;
153 }
154
155 // Breaks the edge invariants, used temporarily
156 protected <N extends Node> void addUse(N n) { _outputs.add(n); }

Callers 1

killMethod · 0.95

Calls 5

inMethod · 0.95
delUseMethod · 0.95
killMethod · 0.95
addUseMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected