Get Reference Information for an Entity

In addition to getting general entity and metrics information, you can also get information about the references to or from an entity. Again, you obtain a list of all references for a particular entity, and then filter the list to include only those types of references that you are interested in.

The following example reports where an entity is defined showing the parent entity in which it is defined, as well as the file, line, and column location where the definition occurs.

First, get all the references for the entity, then filter the reference list to include only those where the entity is defined , of which there should only be one occurrence.

udbListReference(entity, &refs, NULL); 
udbListReferenceFilter(refs,  
   udbKindParse("definedin,declaredin"), NULL, 0, &defs, 
   NULL); 

Once you have the desired list of references, you can do whatever you want with them. As always, remember to free the Reference Lists when done.

if (defs != NULL && defs[0] != 0)  { 
   printf ("     %s (%s at line:%d col:%d)\n\n", 
           	
udbEntityNameShort(udbReferenceEntity(defs[0])), 
           	
udbEntityNameShort(udbReferenceFile(defs[0])), 
           	udbReferenceLine(defs[0]), 
           	udbReferenceColumn(defs[0]) ); 
   udbListReferenceFree(defs); 
 }
 udbListReferenceFree(refs); 

Scientific Toolworks, Inc.
http://www.scitools.com