Vuo  2.3.2
VuoCompilerPort.cc
Go to the documentation of this file.
1 
10 #include "VuoCable.hh"
11 #include "VuoCompilerPort.hh"
12 #include "VuoCompilerCable.hh"
14 #include "VuoCompilerPortClass.hh"
15 #include "VuoCompilerType.hh"
16 #include "VuoException.hh"
17 #include "VuoPort.hh"
18 #include "VuoStringUtilities.hh"
19 #include "VuoType.hh"
20 
25  : VuoCompilerNodeArgument(basePort)
26 {
27  dataType = NULL;
28  indexInPortContexts = -1;
29  constantsCache = NULL;
30 }
31 
36 {
37  return (! getBase()->getConnectedCables().empty());
38 }
39 
44 {
45  vector<VuoCable *> connectedCables = getBase()->getConnectedCables();
46  for (vector<VuoCable *>::iterator cable = connectedCables.begin(); cable != connectedCables.end(); ++cable)
47  if ((*cable)->hasCompiler() && (*cable)->getCompiler()->carriesData())
48  return true;
49  return false;
50 }
51 
58 {
59  if (dataType)
60  return dataType;
61 
62  VuoType *dataTypeFromClass = static_cast<VuoCompilerPortClass *>(getBase()->getClass()->getCompiler())->getDataVuoType();
63  if (dataTypeFromClass)
64  return dataTypeFromClass;
65 
66  return NULL;
67 }
68 
73 {
74  this->dataType = dataType;
75 }
76 
80 void VuoCompilerPort::setNodeIdentifier(string nodeIdentifier)
81 {
82  this->nodeIdentifier = nodeIdentifier;
83 }
84 
91 {
92  if (nodeIdentifier.empty())
93  throw VuoException("VuoCompilerPort::setNodeIdentifier() must be called before VuoCompilerPort::getIdentifier().");
94 
95  return VuoStringUtilities::buildPortIdentifier(nodeIdentifier, getBase()->getClass()->getName());
96 }
97 
101 void VuoCompilerPort::setIndexInPortContexts(int indexInPortContexts)
102 {
103  this->indexInPortContexts = indexInPortContexts;
104 }
105 
110 {
111  return indexInPortContexts;
112 }
113 
118 {
119  this->constantsCache = constantsCache;
120 }
121 
125 Value * VuoCompilerPort::getDataVariable(Module *module, BasicBlock *block, Value *nodeContextValue)
126 {
127  Value *portContextValue = generateGetPortContext(module, block, nodeContextValue);
128  return VuoCompilerCodeGenUtilities::generateGetPortContextDataVariable(module, block, portContextValue, getDataVuoType()->getCompiler());
129 }
130 
134 Value * VuoCompilerPort::generateGetPortContext(Module *module, BasicBlock *block, Value *nodeContextValue)
135 {
136  if (indexInPortContexts < 0)
137  throw VuoException("VuoCompilerPort::setIndexInPortContexts() must be called before VuoCompilerPort::generateGetPortContext().");
138 
139  return VuoCompilerCodeGenUtilities::generateGetNodeContextPortContext(module, block, nodeContextValue, indexInPortContexts);
140 }