1
2
3
4
5
6
7
8
9
10
11 simplify_expression: proc(input_tree,constant,input_tree_modified);
12
13 dcl (input_tree,tree,s) ptr;
14
15 dcl (i,constant,const(2:3)) fixed bin;
16 dcl fix_bin fixed bin based;
17
18 dcl (input_tree_modified,modified(2:3)) bit(1) aligned;
19
20 dcl null builtin;
21
22 tree = input_tree;
23
24 constant = 0;
25
26 input_tree_modified = "0"b;
27
28 if tree->node.type = reference_node
29 then do;
30 s = tree->reference.symbol;
31
32 if s->node.type = symbol_node
33 then if s->symbol.constant
34 then if s->symbol.fixed
35 then if s->symbol.binary
36 then if s->symbol.c_word_size = words_per_fix_bin_1
37 then if s->symbol.scale = 0
38 then do;
39 constant = s->symbol.initial->fix_bin;
40 input_tree_modified = "1"b;
41 end;
42
43 return;
44 end;
45
46 if tree->node.type ^= operator_node
47 then return;
48
49 if tree->operator.op_code^=add
50 & tree->operator.op_code^=sub
51 & tree->operator.op_code^=mult
52 then return;
53
54 do i = 2 to tree->operator.number;
55 call simplify_expression((tree->operand(i)),const(i),modified(i));
56 end;
57
58 if modified(2)
59 & modified(3)
60 then do;
61 if tree->operator.op_code=add
62 then constant = const(2)+const(3);
63 else
64
65 if tree->operator.op_code=sub
66 then constant = const(2)-const(3);
67 else constant = const(2)*const(3);
68
69 input_tree_modified = "1"b;
70
71 return;
72 end;
73
74 do i=2 to 3;
75 if modified(i)
76 then if tree->operand(i)->node.type = operator_node
77 then tree->operand(i) = declare_constant$integer((const(i)));
78 end;
79
80 return;
81
82 %include language_utility;
83 %include nodes;
84 %include op_codes;
85 %include operator;
86 %include reference;
87 %include symbol;
88 %include system;
89
90 end simplify_expression;