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

Method setDef

chapter07/src/main/java/com/seaofnodes/simple/node/Node.java:180–195  ·  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

178 * @return new_def for flow coding
179 */
180 Node setDef(int idx, Node new_def ) {
181 Node old_def = in(idx);
182 if( old_def == new_def ) return this; // No change
183 // If new def is not null, add the corresponding def->use edge
184 // This needs to happen before removing the old node's def->use edge as
185 // the new_def might get killed if the old node kills it recursively.
186 if( new_def != null )
187 new_def.addUse(this);
188 if( old_def != null && // If the old def exists, remove a def->use edge
189 old_def.delUse(this) ) // If we removed the last use, the old def is now dead
190 old_def.kill(); // Kill old def
191 // Set the new_def over the old (killed) edge
192 _inputs.set(idx,new_def);
193 // Return self for easy flow-coding
194 return new_def;
195 }
196
197 // Remove the numbered input, compressing the inputs in-place. This
198 // shuffles the order deterministically - which is suitable for Region and

Callers 5

endLoopMethod · 0.95
updateMethod · 0.45
ctrlMethod · 0.45
dupMethod · 0.45
mergeScopesMethod · 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