home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / adaptor / src / callgraf.c < prev    next >
Text File  |  1994-01-02  |  7KB  |  303 lines

  1. # include "CallGraF.h"
  2. # include "yyCGFns.w"
  3. # include <stdio.h>
  4. # if defined __STDC__ | defined __cplusplus
  5. #  include <stdlib.h>
  6. # else
  7.    extern void exit ();
  8. # endif
  9. # include "CallGrap.h"
  10.  
  11. # ifndef NULL
  12. # define NULL 0L
  13. # endif
  14. # ifndef false
  15. # define false 0
  16. # endif
  17. # ifndef true
  18. # define true 1
  19. # endif
  20.  
  21. # ifdef yyInline
  22. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
  23.   if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
  24.   free += nodesize [kind]; \
  25.   ptr->yyHead.yyMark = 0; \
  26.   ptr->Kind = kind;
  27. # else
  28. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
  29. # endif
  30.  
  31. # define yyWrite(s) (void) fputs (s, yyf)
  32. # define yyWriteNl (void) fputc ('\n', yyf)
  33.  
  34. # line 15 "CallGraphFns.puma"
  35.  
  36. #define NoCallNodes NoCallGraph
  37. #define NoCallNode  NoCallGraph
  38. #define NoCallEdges NoCallGraph
  39.  
  40. static tCallGraph FoundCallNode;
  41.  
  42. tCallGraph  TheCallGraph;   /* for Output */
  43.  
  44. void CallGraphError (s)
  45. char s[];
  46. {  fprintf (stderr, "Internal Error for Call Graph : %s\n", s);
  47. }
  48.  
  49.  
  50.  
  51. static FILE * yyf = stdout;
  52.  
  53. static void yyAbort
  54. # ifdef __cplusplus
  55.  (char * yyFunction)
  56. # else
  57.  (yyFunction) char * yyFunction;
  58. # endif
  59. {
  60.  (void) fprintf (stderr, "Error: module CallGraphFns, routine %s failed\n", yyFunction);
  61.  exit (1);
  62. }
  63.  
  64. tCallGraph InsertNode ARGS((tCallGraph NodeList, tObject Decl, int kind));
  65. tCallGraph CallGraphSearchNode ARGS((tObject Decl, int kind));
  66. static tCallGraph LocalSearchNode ARGS((tCallGraph CG, tObject Decl, int kind));
  67. static tCallGraph EdgeListInsert ARGS((tCallGraph edgelist, tCallGraph node));
  68. void CallGraphInsertEdge ARGS((tCallGraph source, tCallGraph target));
  69.  
  70. tCallGraph InsertNode
  71. # if defined __STDC__ | defined __cplusplus
  72. (register tCallGraph NodeList, tObject Decl, register int kind)
  73. # else
  74. (NodeList, Decl, kind)
  75.  register tCallGraph NodeList;
  76.  tObject Decl;
  77.  register int kind;
  78. # endif
  79. {
  80. # line 61 "CallGraphFns.puma"
  81.  {
  82.   register tCallGraph yyV1;
  83.   {
  84. # line 62 "CallGraphFns.puma"
  85.    if (! (NodeList == NoCallGraph)) goto yyL1;
  86.   {
  87. # line 63 "CallGraphFns.puma"
  88.    yyALLOC (tCallGraph,CallGraph_PoolFreePtr,CallGraph_PoolMaxPtr,CallGraph_Alloc,CallGraph_NodeSize,MakeCallGraph,yyV1,kCallNode)
  89.     yyV1->CallNode.val = Decl;
  90.     yyV1->CallNode.unitkind = kind;
  91.     yyV1->CallNode.calling = NoCallEdges;
  92.     yyV1->CallNode.called_by = NoCallEdges;
  93.    FoundCallNode = yyV1;
  94.   }
  95.   }
  96.   {
  97.   register tCallGraph yyV2;
  98.    yyALLOC (tCallGraph,CallGraph_PoolFreePtr,CallGraph_PoolMaxPtr,CallGraph_Alloc,CallGraph_NodeSize,MakeCallGraph,yyV2,kCallNodeList)
  99.     yyV2->CallNodeList.Elem = FoundCallNode;
  100.     yyV2->CallNodeList.Next = NoCallNodes;
  101.    return yyV2;
  102.   }
  103.  }
  104. yyL1:;
  105.  
  106. # line 67 "CallGraphFns.puma"
  107.   {
  108. # line 68 "CallGraphFns.puma"
  109.    if (! (Decl == NodeList->CallNodeList.Elem->CallNode.val)) goto yyL2;
  110.   {
  111. # line 69 "CallGraphFns.puma"
  112.    FoundCallNode = NodeList->CallNodeList.Elem;
  113.   }
  114.   }
  115.    return NodeList;
  116. yyL2:;
  117.  
  118. # line 73 "CallGraphFns.puma"
  119.   {
  120. # line 74 "CallGraphFns.puma"
  121.    NodeList->CallNodeList.Next = InsertNode (NodeList->CallNodeList.Next, Decl, kind);
  122.   }
  123.    return NodeList;
  124.  
  125. }
  126.  
  127. tCallGraph CallGraphSearchNode
  128. # if defined __STDC__ | defined __cplusplus
  129. (tObject Decl, register int kind)
  130. # else
  131. (Decl, kind)
  132.  tObject Decl;
  133.  register int kind;
  134. # endif
  135. {
  136. # line 80 "CallGraphFns.puma"
  137.    return LocalSearchNode (TheCallGraph, Decl, kind);
  138.  
  139. }
  140.  
  141. static tCallGraph LocalSearchNode
  142. # if defined __STDC__ | defined __cplusplus
  143. (register tCallGraph CG, tObject Decl, register int kind)
  144. # else
  145. (CG, Decl, kind)
  146.  register tCallGraph CG;
  147.  tObject Decl;
  148.  register int kind;
  149. # endif
  150. {
  151. # line 86 "CallGraphFns.puma"
  152.   {
  153. # line 87 "CallGraphFns.puma"
  154.    if (! (Decl == NoObject)) goto yyL1;
  155.   {
  156. # line 88 "CallGraphFns.puma"
  157.    CallGraphError ("No Object for Searching Node");
  158.   }
  159.   }
  160.    return NoCallNode;
  161. yyL1:;
  162.  
  163.   if (CG->Kind == kCallGraph) {
  164.   if (equalint (kind, 0)) {
  165. # line 92 "CallGraphFns.puma"
  166.   {
  167. # line 93 "CallGraphFns.puma"
  168.    CG->CallGraph.UserNodes = InsertNode (CG->CallGraph.UserNodes, Decl, kind);
  169.   }
  170.    return FoundCallNode;
  171.  
  172.   }
  173.   if (equalint (kind, 1)) {
  174. # line 97 "CallGraphFns.puma"
  175.   {
  176. # line 98 "CallGraphFns.puma"
  177.    CG->CallGraph.IntrinsicNodes = InsertNode (CG->CallGraph.IntrinsicNodes, Decl, kind);
  178.   }
  179.    return FoundCallNode;
  180.  
  181.   }
  182.   if (equalint (kind, 2)) {
  183. # line 102 "CallGraphFns.puma"
  184.   {
  185. # line 103 "CallGraphFns.puma"
  186.    CG->CallGraph.ExternalNodes = InsertNode (CG->CallGraph.ExternalNodes, Decl, kind);
  187.   }
  188.    return FoundCallNode;
  189.  
  190.   }
  191.   }
  192.  yyAbort ("LocalSearchNode");
  193. }
  194.  
  195. static tCallGraph EdgeListInsert
  196. # if defined __STDC__ | defined __cplusplus
  197. (register tCallGraph edgelist, register tCallGraph node)
  198. # else
  199. (edgelist, node)
  200.  register tCallGraph edgelist;
  201.  register tCallGraph node;
  202. # endif
  203. {
  204. # line 109 "CallGraphFns.puma"
  205.  {
  206.   {
  207. # line 110 "CallGraphFns.puma"
  208.    if (! (edgelist == NoCallEdges)) goto yyL1;
  209.   }
  210.   {
  211.   register tCallGraph yyV1;
  212.    yyALLOC (tCallGraph,CallGraph_PoolFreePtr,CallGraph_PoolMaxPtr,CallGraph_Alloc,CallGraph_NodeSize,MakeCallGraph,yyV1,kCallEdgeList)
  213.     yyV1->CallEdgeList.Node = node;
  214.     yyV1->CallEdgeList.count = 1;
  215.     yyV1->CallEdgeList.Next = NoCallEdges;
  216.    return yyV1;
  217.   }
  218.  }
  219. yyL1:;
  220.  
  221. # line 114 "CallGraphFns.puma"
  222.   {
  223. # line 115 "CallGraphFns.puma"
  224.    if (! (node == edgelist->CallEdgeList.Node)) goto yyL2;
  225.   {
  226. # line 116 "CallGraphFns.puma"
  227.    edgelist->CallEdgeList.count = edgelist->CallEdgeList.count + 1;
  228.   }
  229.   }
  230.    return edgelist;
  231. yyL2:;
  232.  
  233. # line 120 "CallGraphFns.puma"
  234.   {
  235. # line 121 "CallGraphFns.puma"
  236.    edgelist->CallEdgeList.Next = EdgeListInsert (edgelist->CallEdgeList.Next, node);
  237.   }
  238.    return edgelist;
  239.  
  240. }
  241.  
  242. void CallGraphInsertEdge
  243. # if defined __STDC__ | defined __cplusplus
  244. (register tCallGraph source, register tCallGraph target)
  245. # else
  246. (source, target)
  247.  register tCallGraph source;
  248.  register tCallGraph target;
  249. # endif
  250. {
  251.   if (source == NoCallGraph) return;
  252.   if (target == NoCallGraph) return;
  253. # line 127 "CallGraphFns.puma"
  254.   {
  255. # line 128 "CallGraphFns.puma"
  256.    if (! (source == NoCallNode)) goto yyL1;
  257.   {
  258. # line 129 "CallGraphFns.puma"
  259.    CallGraphError ("Insert edge with source == NIL");
  260.   }
  261.   }
  262.    return;
  263. yyL1:;
  264.  
  265. # line 132 "CallGraphFns.puma"
  266.   {
  267. # line 133 "CallGraphFns.puma"
  268.    if (! (target == NoCallNode)) goto yyL2;
  269.   {
  270. # line 134 "CallGraphFns.puma"
  271.    CallGraphError ("Insert edge with target == NIL");
  272.   }
  273.   }
  274.    return;
  275. yyL2:;
  276.  
  277. # line 137 "CallGraphFns.puma"
  278.   {
  279. # line 139 "CallGraphFns.puma"
  280.    source->CallNode.calling = EdgeListInsert (source->CallNode.calling, target);
  281. # line 140 "CallGraphFns.puma"
  282.    target->CallNode.called_by = EdgeListInsert (target->CallNode.called_by, source);
  283.   }
  284.    return;
  285.  
  286. ;
  287. }
  288.  
  289. void BeginCallGraphFns ()
  290. {
  291. # line 52 "CallGraphFns.puma"
  292.  
  293.  
  294. TheCallGraph  = mCallGraph (NoCallNodes, NoCallNodes, NoCallNodes);
  295.                 /* all three lists are empty */
  296.  
  297.  
  298. }
  299.  
  300. void CloseCallGraphFns ()
  301. {
  302. }
  303.