Example #1
0
    void replaceFunc (AstCFunc* oldfuncp, AstCFunc* newfuncp) {
	if (oldfuncp==newfuncp) return;
	if (newfuncp) {
	    UINFO(4, "   Replace "<<oldfuncp<<" -WITH-> "<<newfuncp<<endl);
	} else UINFO(4, "   Remove "<<oldfuncp<<endl);
	pair <CallMmap::iterator,CallMmap::iterator> eqrange = m_callMmap.equal_range(oldfuncp);
	for (CallMmap::iterator nextit = eqrange.first; nextit != eqrange.second;) {
	    CallMmap::iterator eqit = nextit++;
	    AstCCall* callp = eqit->second;
	    if (!callp->user3()) {  // !already done
		UINFO(4, "     Called "<<callp<<endl);
		if (callp->funcp() != oldfuncp) callp->v3fatalSrc("Call list broken, points to call w/different func");
		if (newfuncp) {
		    AstCCall* newp = new AstCCall(callp, newfuncp);
		    // Special new AstCCall form above transfers children of callp to newfuncp
		    callp->replaceWith(newp);
		    addCall(newp); // Fix the table
		} else { // Just deleting empty function
		    callp->unlinkFrBack();
		}
		callp->user3(true);	// Dead now
		pushDeletep(callp); VL_DANGLING(callp);
		m_callMmap.erase(eqit);	// Fix the table
	    }
	}
    }