backend_open62541_nodes.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ###
  4. ### Author: Chris Iatrou (ichrispa@core-vector.net)
  5. ### Version: rev 13
  6. ###
  7. ### This program was created for educational purposes and has been
  8. ### contributed to the open62541 project by the author. All licensing
  9. ### terms for this source is inherited by the terms and conditions
  10. ### specified for by the open62541 project (see the projects readme
  11. ### file for more information on the LGPL terms and restrictions).
  12. ###
  13. ### This program is not meant to be used in a production environment. The
  14. ### author is not liable for any complications arising due to the use of
  15. ### this program.
  16. ###
  17. from nodes import *
  18. from backend_open62541_datatypes import *
  19. import re
  20. import logging
  21. logger = logging.getLogger(__name__)
  22. #################
  23. # Generate Code #
  24. #################
  25. def generateNodeIdPrintable(node):
  26. if isinstance(node.id, NodeId):
  27. CodePrintable = node.__class__.__name__ + "_" + str(node.id)
  28. else:
  29. CodePrintable = node.__class__.__name__ + "_unknown_nid"
  30. return re.sub('[^0-9a-z_]+', '_', CodePrintable.lower())
  31. def generateNodeValueInstanceName(node, parent, arrayIndex):
  32. return generateNodeIdPrintable(parent) + "_" + str(node.alias) + "_" + str(arrayIndex)
  33. def generateReferenceCode(reference):
  34. if reference.isForward:
  35. return "retVal |= UA_Server_addReference(server, %s, %s, %s, true);" % \
  36. (generateNodeIdCode(reference.source),
  37. generateNodeIdCode(reference.referenceType),
  38. generateExpandedNodeIdCode(reference.target))
  39. else:
  40. return "retVal |= UA_Server_addReference(server, %s, %s, %s, false);" % \
  41. (generateNodeIdCode(reference.source),
  42. generateNodeIdCode(reference.referenceType),
  43. generateExpandedNodeIdCode(reference.target))
  44. def generateReferenceTypeNodeCode(node):
  45. code = []
  46. code.append("UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;")
  47. if node.isAbstract:
  48. code.append("attr.isAbstract = true;")
  49. if node.symmetric:
  50. code.append("attr.symmetric = true;")
  51. if node.inverseName != "":
  52. code.append("attr.inverseName = UA_LOCALIZEDTEXT(\"\", \"%s\");" % \
  53. node.inverseName)
  54. return code
  55. def generateObjectNodeCode(node):
  56. code = []
  57. code.append("UA_ObjectAttributes attr = UA_ObjectAttributes_default;")
  58. if node.eventNotifier:
  59. code.append("attr.eventNotifier = true;")
  60. return code
  61. def generateCommonVariableCode(node, nodeset):
  62. code = []
  63. codeCleanup = []
  64. codeGlobal = []
  65. if node.valueRank is not None:
  66. code.append("attr.valueRank = %d;" % node.valueRank)
  67. if node.valueRank > 0:
  68. code.append("attr.arrayDimensionsSize = %d;" % node.valueRank)
  69. code.append("UA_UInt32 arrayDimensions[{}];".format(node.valueRank))
  70. if len(node.arrayDimensions) == node.valueRank:
  71. for idx, v in enumerate(node.arrayDimensions):
  72. code.append("arrayDimensions[{}] = {};".format(idx, int(str(v))))
  73. else:
  74. for dim in range(0, node.valueRank):
  75. code.append("arrayDimensions[{}] = 0;".format(dim))
  76. code.append("attr.arrayDimensions = &arrayDimensions[0];")
  77. if node.dataType is not None:
  78. dataTypeNode = nodeset.getBaseDataType(nodeset.getDataTypeNode(node.dataType))
  79. if dataTypeNode is None:
  80. raise RuntimeError("Cannot get BaseDataType for dataType : " + str(node.dataType) + " of node " + node.browseName.name + " " + str(node.id))
  81. code.append("attr.dataType = %s;" % generateNodeIdCode(node.dataType))
  82. if dataTypeNode.isEncodable():
  83. if node.value is not None:
  84. [code1, codeCleanup1, codeGlobal1] = generateValueCode(node.value, nodeset.nodes[node.id], nodeset)
  85. code += code1
  86. codeCleanup += codeCleanup1
  87. codeGlobal += codeGlobal1
  88. if node.valueRank is not None and node.valueRank > 0 and len(node.arrayDimensions) == node.valueRank and len(node.value.value) > 0:
  89. numElements = 1
  90. hasZero = False
  91. for v in node.arrayDimensions:
  92. dim = int(unicode(v))
  93. if dim > 0:
  94. numElements = numElements * dim
  95. else:
  96. hasZero = True
  97. if hasZero == False and len(node.value.value) == numElements:
  98. code.append("attr.value.arrayDimensionsSize = attr.arrayDimensionsSize;")
  99. code.append("attr.value.arrayDimensions = attr.arrayDimensions;")
  100. logger.warning("printing arrayDimensions")
  101. else:
  102. logger.error("Dimension with size 0 or value count mismatch detected, ArrayDimensions won't be copied to the Value attribute.")
  103. elif not isinstance(node, VariableTypeNode): # Don't generate a dummy value for VariableType nodes
  104. code += generateValueCodeDummy(dataTypeNode, nodeset.nodes[node.id], nodeset)
  105. elif node.value is not None:
  106. raise RuntimeError("Cannot encode dataTypeNode: " + dataTypeNode.browseName.name + " for value of node " + node.browseName.name + " " + str(node.id))
  107. return [code, codeCleanup, codeGlobal]
  108. def generateVariableNodeCode(node, nodeset):
  109. code = []
  110. codeCleanup = []
  111. codeGlobal = []
  112. code.append("UA_VariableAttributes attr = UA_VariableAttributes_default;")
  113. if node.historizing:
  114. code.append("attr.historizing = true;")
  115. code.append("attr.minimumSamplingInterval = %f;" % node.minimumSamplingInterval)
  116. code.append("attr.userAccessLevel = %d;" % node.userAccessLevel)
  117. code.append("attr.accessLevel = %d;" % node.accessLevel)
  118. # in order to be compatible with mostly OPC UA client
  119. # force valueRank = -1 for scalar VariableNode
  120. if node.valueRank == -2 and node.value is not None and len(node.value.value) == 1:
  121. node.valueRank = -1
  122. [code1, codeCleanup1, codeGlobal1] = generateCommonVariableCode(node, nodeset)
  123. code += code1
  124. codeCleanup += codeCleanup1
  125. codeGlobal += codeGlobal1
  126. return [code, codeCleanup, codeGlobal]
  127. def generateVariableTypeNodeCode(node, nodeset):
  128. code = []
  129. codeCleanup = []
  130. codeGlobal = []
  131. code.append("UA_VariableTypeAttributes attr = UA_VariableTypeAttributes_default;")
  132. if node.isAbstract:
  133. code.append("attr.isAbstract = true;")
  134. [code1, codeCleanup1, codeGlobal1] = generateCommonVariableCode(node, nodeset)
  135. code += code1
  136. codeCleanup += codeCleanup1
  137. codeGlobal += codeGlobal1
  138. return [code, codeCleanup, codeGlobal]
  139. def lowerFirstChar(inputString):
  140. return inputString[0].lower() + inputString[1:]
  141. def generateExtensionObjectSubtypeCode(node, parent, nodeset, global_var_code, instanceName=None, isArrayElement=False):
  142. code = [""]
  143. codeCleanup = [""]
  144. logger.debug("Building extensionObject for " + str(parent.id))
  145. logger.debug("Value " + str(node.value))
  146. logger.debug("Encoding " + str(node.encodingRule))
  147. typeBrowseNode = makeCIdentifier(nodeset.getDataTypeNode(parent.dataType).browseName.name)
  148. #TODO: review this
  149. if typeBrowseNode == "NumericRange":
  150. # in the stack we define a separate structure for the numeric range, but
  151. # the value itself is just a string
  152. typeBrowseNode = "String"
  153. typeString = "UA_" + typeBrowseNode
  154. if instanceName is None:
  155. instanceName = generateNodeValueInstanceName(node, parent, 0)
  156. code.append("UA_STACKARRAY(" + typeString + ", " + instanceName + ", 1);")
  157. typeArr = nodeset.getDataTypeNode(parent.dataType).typesArray
  158. typeString = nodeset.getDataTypeNode(parent.dataType).browseName.name.upper()
  159. typeArrayString = typeArr + "[" + typeArr + "_" + typeString + "]"
  160. code.append("UA_init({ref}{instanceName}, &{typeArrayString});".format(ref="&" if isArrayElement else "",
  161. instanceName=instanceName,
  162. typeArrayString=typeArrayString))
  163. # Assign data to the struct contents
  164. # Track the encoding rule definition to detect arrays and/or ExtensionObjects
  165. encFieldIdx = 0
  166. for subv in node.value:
  167. encField = node.encodingRule[encFieldIdx]
  168. encFieldIdx = encFieldIdx + 1
  169. memberName = lowerFirstChar(encField[0])
  170. if isinstance(subv, list):
  171. if len(subv) == 0:
  172. continue
  173. logger.info("ExtensionObject contains array")
  174. memberName = lowerFirstChar(encField[0])
  175. encTypeString = "UA_" + subv[0].__class__.__name__
  176. code.append("UA_STACKARRAY(" + encTypeString + ", " + instanceName + "_" + memberName+", {0});".format(len(subv)))
  177. encTypeArr = nodeset.getDataTypeNode(subv[0].__class__.__name__).typesArray
  178. encTypeArrayString = encTypeArr + "[" + encTypeArr + "_" + subv[0].__class__.__name__.upper() + "]"
  179. code.append("UA_init({ref}{instanceName}, &{typeArrayString});".format(ref="&" if isArrayElement else "",
  180. instanceName=instanceName + "_" + memberName,
  181. typeArrayString=encTypeArrayString))
  182. subArrayIdx = 0
  183. for val in subv:
  184. code.append(generateNodeValueCode(instanceName + "_" + memberName + "[" + str(subArrayIdx) + "]" +" = ", val, instanceName,instanceName + "_gehtNed_member", global_var_code, asIndirect=False))
  185. subArrayIdx = subArrayIdx + 1
  186. code.append(instanceName + "->" + memberName + " = " + instanceName+"_"+ memberName+";")
  187. continue
  188. else:
  189. logger.debug(
  190. "Encoding of field " + memberName + " is " + str(subv.encodingRule) + "defined by " + str(encField))
  191. # Check if this is an array
  192. accessor = "." if isArrayElement else "->"
  193. if subv.valueRank is None or subv.valueRank == 0:
  194. valueName = instanceName + accessor + memberName
  195. code.append(generateNodeValueCode(valueName + " = " ,
  196. subv, instanceName,valueName, global_var_code, asIndirect=False))
  197. else:
  198. memberName = lowerFirstChar(encField[0])
  199. code.append(generateNodeValueCode(instanceName + accessor + memberName + "Size = ", subv, instanceName,valueName, global_var_code, asIndirect=False))
  200. if not isArrayElement:
  201. code.append("UA_Variant_setScalar(&attr.value, " + instanceName + ", &" + typeArrayString + ");")
  202. return [code, codeCleanup]
  203. def getTypeBrowseName(dataTypeNode):
  204. typeBrowseName = makeCIdentifier(dataTypeNode.browseName.name)
  205. #TODO: review this
  206. if typeBrowseName == "NumericRange":
  207. # in the stack we define a separate structure for the numeric range, but
  208. # the value itself is just a string
  209. typeBrowseName = "String"
  210. return typeBrowseName
  211. def generateValueCodeDummy(dataTypeNode, parentNode, nodeset):
  212. code = []
  213. valueName = generateNodeIdPrintable(parentNode) + "_variant_DataContents"
  214. typeBrowseName = getTypeBrowseName(dataTypeNode)
  215. typeArr = dataTypeNode.typesArray + "[" + dataTypeNode.typesArray + "_" + typeBrowseName.upper() + "]"
  216. typeStr = "UA_" + typeBrowseName
  217. if parentNode.valueRank is not None and parentNode.valueRank > 0:
  218. for i in range(0, parentNode.valueRank):
  219. code.append("UA_Variant_setArray(&attr.value, NULL, (UA_Int32) " + "0, &" + typeArr + ");")
  220. elif not dataTypeNode.isAbstract:
  221. code.append("UA_STACKARRAY(" + typeStr + ", " + valueName + ", 1);")
  222. code.append("UA_init(" + valueName + ", &" + typeArr + ");")
  223. code.append("UA_Variant_setScalar(&attr.value, " + valueName + ", &" + typeArr + ");")
  224. return code
  225. def getTypesArrayForValue(nodeset, value):
  226. typeNode = nodeset.getNodeByBrowseName(value.__class__.__name__)
  227. if typeNode is None or value.isInternal:
  228. typesArray = "UA_TYPES"
  229. else:
  230. typesArray = typeNode.typesArray
  231. typeName = makeCIdentifier(value.__class__.__name__.upper())
  232. return "&" + typesArray + "[" + typesArray + "_" + typeName + "]"
  233. def isArrayVariableNode(node, parentNode):
  234. return parentNode.valueRank is not None and (parentNode.valueRank != -1 and (parentNode.valueRank >= 0
  235. or (len(node.value) > 1
  236. and (parentNode.valueRank != -2 or parentNode.valueRank != -3))))
  237. def generateValueCode(node, parentNode, nodeset, bootstrapping=True):
  238. code = []
  239. codeCleanup = []
  240. codeGlobal = []
  241. valueName = generateNodeIdPrintable(parentNode) + "_variant_DataContents"
  242. # node.value either contains a list of multiple identical BUILTINTYPES, or it
  243. # contains a single builtintype (which may be a container); choose if we need
  244. # to create an array or a single variable.
  245. # Note that some genious defined that there are arrays of size 1, which are
  246. # distinctly different then a single value, so we need to check that as well
  247. # Semantics:
  248. # -3: Scalar or 1-dim
  249. # -2: Scalar or x-dim | x>0
  250. # -1: Scalar
  251. # 0: x-dim | x>0
  252. # n: n-dim | n>0
  253. if (len(node.value) == 0):
  254. return ["", "", ""]
  255. if not isinstance(node.value[0], Value):
  256. return ["", "", ""]
  257. dataTypeNode = nodeset.getDataTypeNode(parentNode.dataType)
  258. if isArrayVariableNode(node, parentNode):
  259. # User the following strategy for all directly mappable values a la 'UA_Type MyInt = (UA_Type) 23;'
  260. if isinstance(node.value[0], Guid):
  261. logger.warn("Don't know how to print array of GUID in node " + str(parentNode.id))
  262. elif isinstance(node.value[0], DiagnosticInfo):
  263. logger.warn("Don't know how to print array of DiagnosticInfo in node " + str(parentNode.id))
  264. elif isinstance(node.value[0], StatusCode):
  265. logger.warn("Don't know how to print array of StatusCode in node " + str(parentNode.id))
  266. else:
  267. if isinstance(node.value[0], ExtensionObject):
  268. code.append("UA_" + getTypeBrowseName(dataTypeNode) + " " + valueName + "[" + str(len(node.value)) + "];")
  269. for idx, v in enumerate(node.value):
  270. logger.debug("Building extObj array index " + str(idx))
  271. instanceName = valueName + "[" + str(idx) + "]"
  272. [code1, codeCleanup1] = generateExtensionObjectSubtypeCode(v, parent=parentNode, nodeset=nodeset,
  273. global_var_code=codeGlobal, instanceName=instanceName,
  274. isArrayElement=True)
  275. code = code + code1
  276. codeCleanup = codeCleanup + codeCleanup1
  277. else:
  278. code.append("UA_" + node.value[0].__class__.__name__ + " " + valueName + "[" + str(len(node.value)) + "];")
  279. for idx, v in enumerate(node.value):
  280. instanceName = generateNodeValueInstanceName(v, parentNode, idx)
  281. code.append(generateNodeValueCode(
  282. valueName + "[" + str(idx) + "] = " , v, instanceName, valueName, codeGlobal))
  283. code.append("UA_Variant_setArray(&attr.value, &" + valueName +
  284. ", (UA_Int32) " + str(len(node.value)) + ", " + "&" +
  285. dataTypeNode.typesArray + "["+dataTypeNode.typesArray + "_" + getTypeBrowseName(dataTypeNode).upper() +"]);")
  286. #scalar value
  287. else:
  288. # User the following strategy for all directly mappable values a la 'UA_Type MyInt = (UA_Type) 23;'
  289. if isinstance(node.value[0], Guid):
  290. logger.warn("Don't know how to print scalar GUID in node " + str(parentNode.id))
  291. elif isinstance(node.value[0], DiagnosticInfo):
  292. logger.warn("Don't know how to print scalar DiagnosticInfo in node " + str(parentNode.id))
  293. elif isinstance(node.value[0], StatusCode):
  294. logger.warn("Don't know how to print scalar StatusCode in node " + str(parentNode.id))
  295. else:
  296. # The following strategy applies to all other types, in particular strings and numerics.
  297. if isinstance(node.value[0], ExtensionObject):
  298. [code1, codeCleanup1] = generateExtensionObjectSubtypeCode(node.value[0], parent=parentNode, nodeset=nodeset, global_var_code=codeGlobal, isArrayElement=False)
  299. code = code + code1
  300. codeCleanup = codeCleanup + codeCleanup1
  301. instanceName = generateNodeValueInstanceName(node.value[0], parentNode, 0)
  302. if not(isinstance(node.value[0], ExtensionObject)):
  303. code.append("UA_" + node.value[0].__class__.__name__ + " *" + valueName + " = UA_" + node.value[
  304. 0].__class__.__name__ + "_new();")
  305. code.append("if (!" + valueName + ") return UA_STATUSCODE_BADOUTOFMEMORY;")
  306. code.append(generateNodeValueCode("*" + valueName + " = " , node.value[0], instanceName, valueName, codeGlobal, asIndirect=True))
  307. code.append(
  308. "UA_Variant_setScalar(&attr.value, " + valueName + ", " +
  309. getTypesArrayForValue(nodeset, node.value[0]) + ");")
  310. if node.value[0].__class__.__name__ == "ByteString":
  311. # The data is on the stack, not heap, so we can not delete the ByteString
  312. codeCleanup.append("{}->data = NULL;".format(valueName))
  313. codeCleanup.append("{}->length = 0;".format(valueName))
  314. codeCleanup.append("UA_{0}_delete({1});".format(
  315. node.value[0].__class__.__name__, valueName))
  316. return [code, codeCleanup, codeGlobal]
  317. def generateMethodNodeCode(node):
  318. code = []
  319. code.append("UA_MethodAttributes attr = UA_MethodAttributes_default;")
  320. if node.executable:
  321. code.append("attr.executable = true;")
  322. if node.userExecutable:
  323. code.append("attr.userExecutable = true;")
  324. return code
  325. def generateObjectTypeNodeCode(node):
  326. code = []
  327. code.append("UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;")
  328. if node.isAbstract:
  329. code.append("attr.isAbstract = true;")
  330. return code
  331. def generateDataTypeNodeCode(node):
  332. code = []
  333. code.append("UA_DataTypeAttributes attr = UA_DataTypeAttributes_default;")
  334. if node.isAbstract:
  335. code.append("attr.isAbstract = true;")
  336. return code
  337. def generateViewNodeCode(node):
  338. code = []
  339. code.append("UA_ViewAttributes attr = UA_ViewAttributes_default;")
  340. if node.containsNoLoops:
  341. code.append("attr.containsNoLoops = true;")
  342. code.append("attr.eventNotifier = (UA_Byte)%s;" % str(node.eventNotifier))
  343. return code
  344. def getNodeTypeDefinition(node):
  345. for ref in node.references:
  346. # 40 = HasTypeDefinition
  347. if ref.referenceType.i == 40:
  348. return ref.target
  349. return None
  350. def generateSubtypeOfDefinitionCode(node):
  351. for ref in node.inverseReferences:
  352. # 45 = HasSubtype
  353. if ref.referenceType.i == 45:
  354. return generateNodeIdCode(ref.target)
  355. return "UA_NODEID_NULL"
  356. def generateNodeCode_begin(node, nodeset, generate_ns0, parentref, code_global):
  357. code = []
  358. codeCleanup = []
  359. code.append("UA_StatusCode retVal = UA_STATUSCODE_GOOD;")
  360. # Attributes
  361. if isinstance(node, ReferenceTypeNode):
  362. code.extend(generateReferenceTypeNodeCode(node))
  363. elif isinstance(node, ObjectNode):
  364. code.extend(generateObjectNodeCode(node))
  365. elif isinstance(node, VariableNode) and not isinstance(node, VariableTypeNode):
  366. [code1, codeCleanup1, codeGlobal1] = generateVariableNodeCode(node, nodeset)
  367. code.extend(code1)
  368. codeCleanup.extend(codeCleanup1)
  369. code_global.extend(codeGlobal1)
  370. elif isinstance(node, VariableTypeNode):
  371. [code1, codeCleanup1, codeGlobal1] = generateVariableTypeNodeCode(node, nodeset)
  372. code.extend(code1)
  373. codeCleanup.extend(codeCleanup1)
  374. code_global.extend(codeGlobal1)
  375. elif isinstance(node, MethodNode):
  376. code.extend(generateMethodNodeCode(node))
  377. elif isinstance(node, ObjectTypeNode):
  378. code.extend(generateObjectTypeNodeCode(node))
  379. elif isinstance(node, DataTypeNode):
  380. code.extend(generateDataTypeNodeCode(node))
  381. elif isinstance(node, ViewNode):
  382. code.extend(generateViewNodeCode(node))
  383. if node.displayName is not None:
  384. code.append("attr.displayName = " + generateLocalizedTextCode(node.displayName, alloc=False) + ";")
  385. if node.description is not None:
  386. code.append("#ifdef UA_ENABLE_NODESET_COMPILER_DESCRIPTIONS")
  387. code.append("attr.description = " + generateLocalizedTextCode(node.description, alloc=False) + ";")
  388. code.append("#endif")
  389. if node.writeMask is not None:
  390. code.append("attr.writeMask = %d;" % node.writeMask)
  391. if node.userWriteMask is not None:
  392. code.append("attr.userWriteMask = %d;" % node.userWriteMask)
  393. # AddNodes call
  394. code.append("retVal |= UA_Server_addNode_begin(server, UA_NODECLASS_{},".
  395. format(makeCIdentifier(node.__class__.__name__.upper().replace("NODE" ,""))))
  396. code.append(generateNodeIdCode(node.id) + ",")
  397. code.append(generateNodeIdCode(parentref.target) + ",")
  398. code.append(generateNodeIdCode(parentref.referenceType) + ",")
  399. code.append(generateQualifiedNameCode(node.browseName) + ",")
  400. if isinstance(node, VariableNode) or isinstance(node, ObjectNode):
  401. typeDefRef = node.popTypeDef()
  402. code.append(generateNodeIdCode(typeDefRef.target) + ",")
  403. else:
  404. code.append(" UA_NODEID_NULL,")
  405. code.append("(const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_{}ATTRIBUTES],NULL, NULL);".
  406. format(makeCIdentifier(node.__class__.__name__.upper().replace("NODE" ,""))))
  407. code.extend(codeCleanup)
  408. return "\n".join(code)
  409. def generateNodeCode_finish(node):
  410. code = []
  411. if isinstance(node, MethodNode):
  412. code.append("UA_Server_addMethodNode_finish(server, ")
  413. else:
  414. code.append("UA_Server_addNode_finish(server, ")
  415. code.append(generateNodeIdCode(node.id))
  416. if isinstance(node, MethodNode):
  417. code.append(", NULL, 0, NULL, 0, NULL);")
  418. else:
  419. code.append(");")
  420. return "\n".join(code)