@@ -113,20 +113,62 @@ void Engine::resolveIds()
113
113
const auto &inputs = block->inputs ();
114
114
for (const auto &input : inputs) {
115
115
input->setValueBlock (getBlock (input->valueBlockId ()));
116
+
116
117
if (container)
117
118
input->setInputId (container->resolveInput (input->name ()));
118
- input->primaryValue ()->setValuePtr (getEntity (input->primaryValue ()->valueId ()));
119
- input->secondaryValue ()->setValuePtr (getEntity (input->primaryValue ()->valueId ()));
119
+
120
+ InputValue *value = input->primaryValue ();
121
+ std::string id = value->valueId (); // no reference!
122
+ value->setValuePtr (getEntity (id));
123
+ assert (input->secondaryValue ()->type () != InputValue::Type::Variable && input->secondaryValue ()->type () != InputValue::Type::List); // secondary values never have a variable or list
124
+ input->secondaryValue ()->setValuePtr (getEntity (input->secondaryValue ()->valueId ()));
125
+
126
+ // Add missing variables and lists
127
+ if (!value->valuePtr ()) {
128
+ if (value->type () == InputValue::Type::Variable) {
129
+ assert (!id.empty ());
130
+ std::cout << " warning: variable " << value->value ().toString () << " referenced by an input missing, creating in stage" << std::endl;
131
+ auto var = std::make_shared<Variable>(id, value->value ().toString ());
132
+ value->setValuePtr (var);
133
+ stage ()->addVariable (var);
134
+ } else if (value->type () == InputValue::Type::List) {
135
+ assert (!id.empty ());
136
+ std::cout << " warning: list " << value->value ().toString () << " referenced by an input missing, creating in stage" << std::endl;
137
+ std::shared_ptr<List> list = std::make_shared<List>(id, value->value ().toString ());
138
+ value->setValuePtr (list);
139
+ stage ()->addList (list);
140
+ }
141
+ }
120
142
}
121
143
122
144
const auto &fields = block->fields ();
123
145
for (auto field : fields) {
124
- field->setValuePtr (getEntity (field->valueId ()));
146
+ std::string id = field->valueId (); // no reference!
147
+ field->setValuePtr (getEntity (id));
148
+
125
149
if (container) {
126
150
field->setFieldId (container->resolveField (field->name ()));
151
+
127
152
if (!field->valuePtr ())
128
153
field->setSpecialValueId (container->resolveFieldValue (field->value ().toString ()));
129
154
}
155
+
156
+ // TODO: Move field information out of Engine
157
+ if (!field->valuePtr ()) {
158
+ if (field->name () == " VARIABLE" ) {
159
+ assert (!id.empty ());
160
+ std::cout << " warning: variable " << field->value ().toString () << " referenced by a field missing, creating in stage" << std::endl;
161
+ auto var = std::make_shared<Variable>(id, field->value ().toString ());
162
+ field->setValuePtr (var);
163
+ stage ()->addVariable (var);
164
+ } else if (field->name () == " LIST" ) {
165
+ assert (!id.empty ());
166
+ std::cout << " warning: list " << field->value ().toString () << " referenced by a field missing, creating in stage" << std::endl;
167
+ std::shared_ptr<List> list = std::make_shared<List>(id, field->value ().toString ());
168
+ field->setValuePtr (list);
169
+ stage ()->addList (list);
170
+ }
171
+ }
130
172
}
131
173
132
174
block->updateInputMap ();
0 commit comments