Vuo 2.4.4
Loading...
Searching...
No Matches
VuoCompilerPublishedNodeClass.cc
Go to the documentation of this file.
1
10#include <sstream>
11
12#include "VuoCompiler.hh"
18#include "VuoCompilerType.hh"
19#include "VuoGenericType.hh"
21#include "VuoNode.hh"
22#include "VuoNodeClass.hh"
23#include "VuoPublishedPort.hh"
24#include "VuoStringUtilities.hh"
25#include "VuoType.hh"
26
31 VuoCompilerSpecializedNodeClass(nodeClassName, module)
32{
33}
34
42
50
55VuoNodeClass * VuoCompilerPublishedNodeClass::newNodeClass(const string &nodeClassName, VuoCompiler *compiler, dispatch_queue_t llvmQueue, VuoCompilerPublishedNodeClass *singleton)
56{
57 vector<string> portNames;
58 vector<string> typeNames;
59 bool parsedOk = singleton->parseNodeClassName(nodeClassName, portNames, typeNames);
60 if (! parsedOk)
61 return NULL;
62
63 vector<VuoType *> types;
64 for (string typeName : typeNames)
65 {
66 VuoCompilerType *type = (typeName == "event" ? nullptr : compiler->getType(typeName));
67 types.push_back(type ? type->getBase() : nullptr);
68 }
69
70 return newNodeClass(portNames, types, llvmQueue, singleton);
71}
72
79VuoNodeClass * VuoCompilerPublishedNodeClass::newNodeClass(const vector<VuoPublishedPort *> &publishedPorts, dispatch_queue_t llvmQueue, VuoCompilerPublishedNodeClass *singleton)
80{
81 vector<string> portNames = singleton->formUniquePortNames(publishedPorts);
82
83 vector<VuoType *> types;
84 for (VuoPublishedPort *publishedPort : publishedPorts)
85 {
86 VuoType *type = static_cast<VuoCompilerPort *>(publishedPort->getCompiler())->getDataVuoType();
87 types.push_back(type);
88 }
89
90 return newNodeClass(portNames, types, llvmQueue, singleton);
91}
92
96VuoNodeClass * VuoCompilerPublishedNodeClass::newNodeClass(const vector<string> &portNames, const vector<VuoType *> &types, dispatch_queue_t llvmQueue, VuoCompilerPublishedNodeClass *singleton)
97{
98 string nodeClassName = singleton->buildNodeClassName(portNames, types);
99
100 bool isFullySpecialized = true;
101 for (VuoType *type : types)
102 {
103 if (dynamic_cast<VuoGenericType *>(type))
104 {
105 isFullySpecialized = false;
106 break;
107 }
108 }
109
110 __block VuoNodeClass *nodeClass;
112 {
113 dispatch_sync(llvmQueue, ^{
114 nodeClass = singleton->newNodeClassWithImplementation(nodeClassName, portNames, types);
115 });
116
117 vector<string> typeDependencies;
118 for (VuoType *type : types)
119 {
120 if (type && type->hasCompiler())
121 {
122 string typeDependency = type->getCompiler()->getDependencyPath();
123 if (! typeDependency.empty())
124 typeDependencies.push_back(typeDependency);
125 }
126 }
127
128 std::sort(typeDependencies.begin(), typeDependencies.end());
129 auto endOfUnique = std::unique(typeDependencies.begin(), typeDependencies.end());
130 typeDependencies.erase(endOfUnique, typeDependencies.end());
131
132 VuoCompilerPublishedNodeClass *publishedNodeClass = static_cast<VuoCompilerPublishedNodeClass *>(nodeClass->getCompiler());
134 }
135 else
136 {
137 nodeClass = singleton->newNodeClassWithoutImplementation(nodeClassName, portNames, types);
138 }
139
140 return nodeClass;
141}
142
154
159bool VuoCompilerPublishedNodeClass::parseNodeClassName(string nodeClassName, vector<string> &portNames, vector<string> &typeNames)
160{
161 string countAndNamesAndTypesStr = VuoStringUtilities::substrAfter(nodeClassName, getNodeClassNamePrefix() + ".");
162 if (countAndNamesAndTypesStr.empty())
163 return false;
164
165 vector<string> countAndNamesAndTypes = VuoStringUtilities::split(countAndNamesAndTypesStr, '.');
166 if (countAndNamesAndTypes.empty())
167 return false;
168
169 string countStr = countAndNamesAndTypes[0];
170 int count = atoi(countStr.c_str());
171 if (count != (countAndNamesAndTypes.size() - 1) / 2)
172 return false;
173
174 for (int i = 0; i < count; ++i)
175 {
176 string portName = countAndNamesAndTypes.at(1 + i);
177 portNames.push_back(portName);
178
179 string typeName = countAndNamesAndTypes.at(1 + count + i);
180 typeNames.push_back(typeName);
181 }
182
183 return true;
184}
185
189string VuoCompilerPublishedNodeClass::buildNodeClassName(const vector<string> &portNames, const vector<VuoType *> &types)
190{
191 vector<string> typeNames;
192 for (VuoType *type : types)
193 typeNames.push_back(type ? type->getModuleKey() : "event");
194
195 return buildNodeClassName(portNames, typeNames);
196}
197
201string VuoCompilerPublishedNodeClass::buildNodeClassName(const vector<string> &portNames, const vector<string> &typeNames)
202{
203 vector<string> nodeClassNameParts;
204 nodeClassNameParts.push_back(getNodeClassNamePrefix());
205
206 ostringstream oss;
207 oss << portNames.size();
208 nodeClassNameParts.push_back(oss.str());
209
210 for (string portName : portNames)
211 nodeClassNameParts.push_back(portName);
212
213 for (string typeName : typeNames)
214 nodeClassNameParts.push_back(typeName);
215
216 return VuoStringUtilities::join(nodeClassNameParts, '.');
217}
218
222string VuoCompilerPublishedNodeClass::buildNodeClassNameFromPorts(const vector<VuoPublishedPort *> &publishedPorts)
223{
224 vector<string> portNames = formUniquePortNames(publishedPorts);
225
226 vector<VuoType *> types;
227 for (VuoPublishedPort *publishedPort : publishedPorts)
228 {
229 VuoType *type = static_cast<VuoCompilerPort *>(publishedPort->getCompiler())->getDataVuoType();
230 types.push_back(type);
231 }
232
233 return buildNodeClassName(portNames, types);
234}
235
242vector<string> VuoCompilerPublishedNodeClass::formUniquePortNames(const vector<VuoPublishedPort *> &publishedPorts)
243{
244 set<string> takenPortNames = getReservedPortNames();
245
246 vector<string> portNames;
247 for (VuoPublishedPort *publishedPort : publishedPorts)
248 {
249 string uniquePortName = VuoStringUtilities::formUniqueIdentifier(takenPortNames, publishedPort->getClass()->getName());
250 portNames.push_back(uniquePortName);
251 }
252
253 return portNames;
254}
255
259json_object * VuoCompilerPublishedNodeClass::buildSpecializedModuleDetails(const vector<VuoType *> &types)
260{
261 map<string, string> specializedForGenericTypeName;
262 for (unsigned int i = 0; i < types.size(); ++i)
263 if (types[i])
265
267}
268
274{
275 ostringstream hash;
276 hash << VuoStringUtilities::hash(getBase()->getModuleKey());
277
278 return getNodeClassNamePrefix() + "." + hash.str() + ".vuonode";
279}
280
286{
290
291 ostringstream hash;
292 hash << VuoStringUtilities::hash(moduleKey);
293
294 return prefix + "." + hash.str() + ".vuonode";
295}
296
302{
303 return true;
304}
305
310{
311 vector<string> portNames;
312 vector<string> typeNames;
313 bool ok = parseNodeClassName(backingNodeClassName, portNames, typeNames);
314 if (! ok)
315 return NULL;
316
317 vector<VuoPublishedPort *> publishedPorts;
318 for (int i = 0; i < portNames.size(); ++i)
319 {
320 string portName = portNames[i];
321 string typeName = typeNames[i];
322 VuoType *type = (typeName == "event" ? NULL : compiler->getType(typeName)->getBase());
323 VuoCompilerPublishedPort *publishedPort = VuoCompilerPublishedPort::newPort(portName, type);
324 publishedPorts.push_back( static_cast<VuoPublishedPort *>(publishedPort->getBase()) );
325 }
326
327 return (dynamic_cast<VuoCompilerPublishedInputNodeClass *>(this) ?
328 compiler->createPublishedInputNode(publishedPorts)->getCompiler() :
329 compiler->createPublishedOutputNode(publishedPorts)->getCompiler());
330}
331
340
348
356
364
368string VuoCompilerPublishedNodeClass::createUnspecializedNodeClassName(set<VuoPortClass *> portClassesToUnspecialize)
369{
371 return "";
372}
373
378string VuoCompilerPublishedNodeClass::createSpecializedNodeClassNameWithReplacement(string genericTypeName, string specializedTypeName)
379{
381 return "";
382}