-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariable.m
91 lines (76 loc) · 3.01 KB
/
Variable.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
classdef Variable < Node
% Variable are variables that will be used during execution
% Lookupname:
% Variable.<VariableName>
properties
fieldName
valuesType
% 1: discrete, 2: continuous
% For bounded variables
lowerBound
% Lower bound of the variable
upperBound
% Upper bound of the variable
% For enumerated variables
allowedValues = {}
% A cell that enumerates all the values allowed
end
methods
function node = Variable(fieldName, valuesType, returnType, ...
arg1, arg2, requiredTags)
% The constructor for environment variables
% Arguments:
% fieldName: The name of the field. The identifier that
% is used to locate the environment variable from the
% context structure.
% valuesType: The type of the environment variable. Can be
% either 'enumerated' or 'bounded'.
% returnType: The return type. Could be any type that the
% environment variable returns.
% arg1: A shared variable. When valuesType is set to
% 'enumerated', the field should contain the list of
% allowed values. When the field valuesType is set to
% 'bounded', the lower bound of the variable's range
% should be provided.
% arg2: Only need to be specified when the field valuesType
% is set to 'bounded'. In such case, provide the upper
% bound of the variable's range.
if nargin < 3
returnType = 'unknown';
end
node = node@Node(returnType, 1);
node.appendLookupName('Variable');
node.appendLookupName(fieldName);
node.fieldName = fieldName;
if nargin <= 1 || strcmp(valuesType, 'none')
node.valuesType = 0;
if nargin >= 3
node.returnType = returnType;
end
elseif strcmp(valuesType, 'enumerated')
node.valuesType = 1;
node.allowedValues = arg1;
elseif strcmp(valuesType, 'bounded')
node.valuesType = 2;
node.lowerBound = arg1;
node.upperBound = arg2;
else
error("Unkown argument for valuesType.");
end
if nargin >= 6
node.addRequiredTags(requiredTags);
end
end
function init(~)
end
function output = exec(node, env)
output = getfield(env, node.fieldName);
end
function grow(~, ~)
% Environment variables does not grow
end
function summary(node, ~)
fprintf("" + node.fieldName);
end
end
end