ILAttribute *ILAttributeCreate(ILImage *image, ILToken token) { ILAttribute *attr; /* Allocate memory for the attribute */ attr = ILMemStackAlloc(&(image->memStack), ILAttribute); if(!attr) { return 0; } /* Initialize the attribute fields */ attr->programItem.image = image; /* Assign the token code to the attribute */ if(!_ILImageSetToken(image, &(attr->programItem), token, IL_META_TOKEN_CUSTOM_ATTRIBUTE)) { return 0; } /* Return the attribute to the caller */ return attr; }
int _ILProgramItemLink(ILProgramItem *item1, ILProgramItem *item2) { ILProgramItemLink *link; ILProgramItemLink *link2; /* Bail out if item1 and item2 are identical */ if(item1 == item2) { return 1; } /* Create the link from item1 to item2 */ if(!(item1->linked)) { /* Create a new link entry for the item */ link = ILMemStackAlloc(&(item1->image->memStack), ILProgramItemLink); if(!link) { return 0; } link->customAttrs = (ILAttribute *)(item1->attrsOrLink); link->linkedItem = item2; link->next = 0; item1->attrsOrLink = (void *)link; item1->linked = 1; } else { /* Remove the current link, if present */ link = ((ILProgramItemLink *)(item1->attrsOrLink)); if(link->linkedItem != 0) { link2 = ((ILProgramItemLink *)(link->linkedItem->attrsOrLink)); link2 = link2->next; while(link2 != 0) { if(link2->linkedItem == item1) { link2->linkedItem = 0; break; } link2 = link2->next; } } /* Replace the current link entry for the item */ link->linkedItem = item2; } /* Create the reverse link from item2 to item1 */ if(!(item2->linked)) { /* Create a new link entry for the second item */ link = ILMemStackAlloc(&(item2->image->memStack), ILProgramItemLink); if(!link) { ((ILProgramItemLink *)(item1->attrsOrLink))->linkedItem = 0; return 0; } link->customAttrs = (ILAttribute *)(item2->attrsOrLink); link->linkedItem = 0; link->next = 0; item2->attrsOrLink = (void *)link; item2->linked = 1; } else { link = (ILProgramItemLink *)(item2->attrsOrLink); } link2 = link->next; while(link2 != 0) { if(link2->linkedItem == 0) { link2->linkedItem = item1; return 1; } link = link2; link2 = link2->next; } link2 = ILMemStackAlloc(&(item2->image->memStack), ILProgramItemLink); if(!link2) { ((ILProgramItemLink *)(item1->attrsOrLink))->linkedItem = 0; return 0; } link2->customAttrs = 0; link2->linkedItem = item1; link2->next = 0; link->next = link2; return 1; }