[docs]classPyASTNode:"""Represents a high-level Python wrapper for a single `ASTNode`. Provides convenient accessors for commonly used node information."""def__init__(self,parent:PyTranslationUnit,node:ASTNode)->None:self._parent=parentself._node=nodeself._lib=parent.libdef__repr__(self)->str:returnf"PyASTNode(tag={self.tag})"
[docs]defis_public(self)->bool:"""True if the node is marked as pub."""returnself._lib.isNodePublic(self._parent.ptr,self._node)
[docs]defis_extern(self)->bool:"""True if the node is marked as extern."""returnself._lib.isNodeExtern(self._parent.ptr,self._node)
[docs]defis_export(self)->bool:"""True if the node is marked as export."""returnself._lib.isNodeExport(self._parent.ptr,self._node)
[docs]defis_container(self)->bool:"""True if the node is a container (Enum, Struct, Union, or Opaque)."""returnself._lib.isNodeContainer(self._node)
[docs]defis_const(self)->bool:"""Whether the node is marked as const."""returnself._lib.isNodeConst(self._parent.ptr,self._node)
[docs]defis_struct(self)->bool:"""Whether the node points to a struct."""returnself._lib.isNodeStruct(self._parent.ptr,self._node)
[docs]defis_union(self)->bool:"""Whether the node points to a union."""returnself._lib.isNodeUnion(self._parent.ptr,self._node)
[docs]defis_opaque(self)->bool:"""Whether the node points to an opaque."""returnself._lib.isNodeOpaque(self._parent.ptr,self._node)
[docs]defis_enum(self)->bool:"""Whether the node points to an enum."""returnself._lib.isNodeEnum(self._parent.ptr,self._node)
[docs]defis_error_union(self)->bool:"""Whether the node is a part of an error union."""returnself._lib.isNodeErrorUnion(self._parent.ptr,self._node)
@propertydeftag(self)->NodeTag:"""The node's tag."""returnself._node.tag@propertydefspelling(self)->str:"""The node's spelling as a decoded UTF-8 string."""returnself._lib.getNodeSpelling(self._parent.ptr,self._node).to_list(PyString)[0]@propertydefsource(self)->str:"""Raw source of the node."""returnself._lib.getNodeSource(self._parent.ptr,self._node.index).to_list(PyString)[0]@propertydeftype(self)->Optional[PyASTNode]:"""The type node assigned to Node. For functions, it's the return type. For variable declarations, it specifies the type hint."""node_type=self._lib.getNodeType(self._parent.ptr,self._node)ifnode_type.index!=self._node.index:returnPyASTNode(self.parent,node_type)@propertydefbody(self)->Optional[str]:"""Node's raw body."""body_slice=self._lib.getNodeBody(self._parent.ptr,self._node)ifnotbody_slice.is_empty:returnbody_slice.to_list(PyString)[0]@propertydefparams(self)->List[NodeParam]:"""A list of node's parameters. For functions, these are arguments"""result=[]params_count=self._lib.getNodeParamsCount(self._parent.ptr,self._node)ifparams_count==0:returnresultbuffer=(NodeParam*params_count)()filled=self._lib.getNodeParams(self._parent.ptr,self._node,buffer,params_count)foriinrange(filled):result.append(buffer[i])returnresult@propertydefalign(self)->Optional[str]:"""The align value for the node."""align_slice=self._lib.getNodeAlign(self._parent.ptr,self._node)ifnotalign_slice.is_empty:returnalign_slice.to_list(PyString)[0]@propertydefreleased(self)->bool:"""Indicates whether the ASTNode has been released."""returnself._parent.released@propertydefparent(self)->PyTranslationUnit:"""The parent of this ASTNode."""returnself._parent