/
mtree_replaceIifByCtrlif.m
76 lines (44 loc) · 1.28 KB
/
mtree_replaceIifByCtrlif.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [mtreeobj, ctrlif_index] = mtree_replaceIifByCtrlif(mtreeobj, ctrlif_index)
% transform iif functions into ctrlif functions calls
%
% Example:
%
% iif(a-b > 0, a, b)
%
% is changed to
%
% ctlfif(a-b > 0, a, b, index, datahandle)
%
%
% INPUT:
% mtreeobj --> mtreeobj from rhs
%
% OUTPUT:
% obj --> mtreeobj, where all iif are replaced by ctrlif
% notation:
% cIndex -> column index; refers to a property type
% rIndex -> row index of some object; refers to the entire row.
% cIndex = mtree_cIndex();
rIndex = mtree_rIndex(mtreeobj);
config = makeConfig();
% check if there are any iif
if ~isfield(rIndex.BODY, 'IIf')
% nothing to do
return
end
mtreeobj = mtree_createSeparateFunctionCallInNewLine(mtreeobj, rIndex.BODY.IIf_call, config.abs.PrefixNewlineFcn);
rIndex = mtree_rIndex(mtreeobj);
for i = 1:length(rIndex.BODY.IIf)
cond_feasible = mtree_checkFeasibilityOfCondition(mtreeobj, rIndex.BODY.cond);
if ~cond_feasible
continue
end
[mtreeobj, ~] = preprocess_setUpCtrlif(mtreeobj,...
rIndex.BODY.IIf_Equals(i), ...
ctrlif_index, ...
rIndex.BODY.IIf_Arg(i,1), ...
rIndex.BODY.IIf_Arg(i,2), ...
rIndex.BODY.IIf_Arg(i,3));
ctrlif_index = ctrlif_index + 1;
end
end % finito