1 /* ***********************************************************
 2    *                                                         *
 3    * Copyright, (C) Honeywell Information Systems Inc., 1982 *
 4    *                                                         *
 5    *********************************************************** */
 6 %;
 7 /* ******************************************************
 8    *                                                    *
 9    *                                                    *
10    * Copyright (c) 1972 by Massachusetts Institute of   *
11    * Technology and Honeywell Information Systems, Inc. *
12    *                                                    *
13    *                                                    *
14    ****************************************************** */
15 
16 share_expression:   proc(a) returns(ptr);
17 
18 dcl       (a,p,inptr,outptr) ptr,
19 
20           n fixed bin(15),
21 
22           nodetype bit(9) aligned;
23 
24 dcl       null builtin;
25 
26 %include language_utility;
27 %include nodes;
28 %include operator;
29 %include reference;
30 %include symbol;
31 ^L
32           inptr = a;
33           outptr = null;
34 
35           if inptr=null then goto ret;
36           nodetype = inptr->node.type;
37 
38           if nodetype=operator_node
39           then do;
40                     p = inptr->operand(1);
41                     if p=null then goto copy;
42 
43                     if ^p->reference.shared
44                     then      p->reference.ref_count = p->reference.ref_count+1;
45                     else do;
46                               p = create_reference((inptr->operand(1)));
47                               p->reference = inptr->operand(1)->reference;
48                               p->reference.shared = "0"b;
49                               p->reference.ref_count = 2;
50                               inptr->operand(1) = p;
51                     end;
52 
53                     outptr = inptr;
54                     goto ret;
55           end;
56 
57           if nodetype=reference_node
58           then do;
59                     if ^inptr->reference.shared
60                     then      inptr->reference.ref_count = inptr->reference.ref_count + 1;
61 
62                     outptr = inptr;
63                     go to ret;
64           end;
65 
66 copy:
67           outptr = copy_expression((inptr));
68 
69 ret:
70           return(outptr);
71 
72           end share_expression;