static mddl_doc_t __merge(mddl_doc_t tgtsrc, mddl_doc_t src) { mddl_mddl_t troot; mddl_mddl_t sroot; size_t nmrg = 1; if ((troot = tgtsrc->tree) == NULL) { return NULL; } else if ((sroot = src->tree) == NULL) { return tgtsrc; } /* make sure there's (at least) one snap in troot */ if (troot->nsnap == 0 && sroot->nsnap > 0) { /* don't bother merging in this case */ nmrg = 0; } else if (sroot->nsnap > 0) { /* if sroot also has a snap, the first ones get merged ... */ if (__merge_snap(troot->snap, sroot->snap) < 0) { nmrg = 0; } } /* ... others just appended */ APPENDN(mddl, snap, troot, sroot, nmrg); return tgtsrc; }
static int __merge_insidn(mddl_instrumentIdentifier_t tgt, mddl_instrumentIdentifier_t src) { /* for ins idns to be merged the scopes must match ... */ if (!__scopeType_allsim_p(tgt, src)) { return -1; } /* ... and if the scope is `market' ... */ if (tgt->nscopeType == 1 && __scopeType_eq_p(tgt->scopeType, "market")) { if (!__marketIdentifier_allsim_p(tgt, src)) { /* ... the marketIdentifiers must match */ return -1; } else if (!__code_allsim_p(tgt, src)) { /* ... and also the codes */ return -1; } /* ah good, let's merge the guy then */ APPENDN(instrumentIdentifier, name, tgt, src, 0); return 0; } /* otherwise just append all children */ MERGEN(instrumentIdentifier, code, tgt, src, 0); MERGEN(instrumentIdentifier, name, tgt, src, 0); APPENDN(instrumentIdentifier, country, tgt, src, 0); APPENDN(instrumentIdentifier, instrumentData, tgt, src, 0); APPENDN(instrumentIdentifier, instrumentStatusType, tgt, src, 0); APPENDN(instrumentIdentifier, marketIdentifier, tgt, src, 0); MERGEN(instrumentIdentifier, scopeType, tgt, src, 0); APPENDN(instrumentIdentifier, segmentIdentifier, tgt, src, 0); APPENDN(instrumentIdentifier, tranche, tgt, src, 0); return 0; }
static int __merge_insdom(mddl_instrumentDomain_t tgt, mddl_instrumentDomain_t src) { #define __add_insidn mddl_instrumentDomain_add_instrumentIdentifier #define __add_objective mddl_instrumentDomain_add_objective size_t nmrg = 1; /* make sure there's instrument identifiers */ if (tgt->ninstrumentIdentifier == 0 && src->ninstrumentIdentifier > 0) { /* no merge now */ nmrg = 0; } else if (src->ninstrumentIdentifier > 0) { /* first gets merged ... */ mddl_instrumentIdentifier_t tgtii = tgt->instrumentIdentifier; if (__merge_insidn(tgtii, src->instrumentIdentifier) < 0) { /* error merging them, so append */ nmrg = 0; } } /* ... append the rest */ APPENDN(instrumentDomain, instrumentIdentifier, tgt, src, nmrg); /* same for objectives, no merge for them */ nmrg = 1; if (tgt->nobjective == 0 && src->nobjective > 0) { /* no merge now */ nmrg = 0; } else if (src->nobjective > 0) { /* try a merge ... */ mddl_objective_t tobj = tgt->objective; if (__merge_objective(tobj, src->objective) < 0) { /* error merging them, so append */ nmrg = 0; } } APPENDN(instrumentDomain, objective, tgt, src, nmrg); return 0; }
void NodeGen::appendBranchCodeNodes( int32 whichSucc, bool isBackwards, MergeNode* target, BranchBCTargetStack* targetStack, SExprStack* exprStack, PRegBList* exprStackPRs, SplitSig* s ) { // use nop nodes to avoid indexed br node being pred twice of // same merge node if two cases goto same place APPENDN(whichSucc, new NopNode); // move stack values to targetStack targetStack->mergeInExprsFromStack(exprStack, target, isBackwards); // append to current for a fwd or back branch for a branch bc Node* n = isBackwards ? (Node*) new RestartNode(exprStackPRs, s, target) : target; append( n); }
static int __merge_snap(mddl_snap_t tgt, mddl_snap_t src) { size_t nmrg = 1; /* make sure there's at least one insdom on both sides */ if (tgt->ninstrumentDomain == 0 && src->ninstrumentDomain > 0) { /* no merge in this case */ nmrg = 0; } else if (src->ninstrumentDomain > 0) { /* first one gets merged ... */ mddl_instrumentDomain_t tdom = tgt->instrumentDomain; if (__merge_insdom(tdom, src->instrumentDomain) < 0) { /* error merging them, so append */ nmrg = 0; } } /* ... and others just get appended */ APPENDN(snap, instrumentDomain, tgt, src, nmrg); return 0; }