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

Method setDef

chapter04/src/main/java/com/seaofnodes/simple/node/Node.java:137–152  ·  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. This method is the normal path for altering a Node, because it does the proper d

(int idx, Node new_def )

Source from the content-addressed store, hash-verified

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

Callers 2

updateMethod · 0.45
ctrlMethod · 0.45

Calls 5

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

Tested by

no test coverage detected