U _([@s ddlZGdddeZGdddeZGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZ GdddeZ GdddeZ GdddeZ GdddeZ GdddeZGdddeZGdddeZGd d!d!eZGd"d#d#eZGd$d%d%eZGd&d'd'eZGd(d)d)eZGd*d+d+eZGd,d-d-eZGd.d/d/eZGd0d1d1eZGd2d3d3eZGd4d5d5eZGd6d7d7eZGd8d9d9eZGd:d;d;eZGdd?d?eZ Gd@dAdAeZ!GdBdCdCeZ"GdDdEdEeZ#GdFdGdGeZ$GdHdIdIeZ%GdJdKdKeZ&GdLdMdMeZ'GdNdOdOeZ(GdPdQdQeZ)GdRdSdSeZ*GdTdUdUeZ+GdVdWdWeZ,GdXdYdYeZ-GdZd[d[eZ.Gd\d]d]eZ/Gd^d_d_eZ0Gd`dadaeZ1dS)bNc@s0eZdZdZddZejdddddfddZdS) NodecCsdS)z3 A sequence of all children that are Nodes Nrselfrr /c_ast.pychildrensz Node.childrenrFNc sd|}|r4|dk r4||jjd|dn||jjdjr|r~fddjD}dd d |D} n(fd djD} dd d | D} || |r|d j|dD]"\} } | j||d|||| dqdS)a Pretty print the Node and all its attributes and children (recursively) to a buffer. buf: Open IO buffer into which the Node is printed. offset: Initial offset (amount of leading spaces) attrnames: True if you want to see the attribute names in name=value pairs. False to only see the values. nodenames: True if you want to see the actual node names within their parents. showcoord: Do you want the coordinates of each Node to be displayed.  Nz : z: csg|]}|t|fqSrgetattr.0nrrr =szNode.show..z, css|]}d|VqdS)z%s=%sNr)r Znvrrr >szNode.show..csg|]}t|qSrr r rrrr@scss|]}d|VqdS)z%sNr)r vrrrrAsz (at %s) )offset attrnames nodenames showcoord _my_node_name)write __class____name__ attr_namesjoincoordrshow) rZbufrrrrrZleadZnvlistZattrstrZvlistZ child_namechildrrrrs.    z Node.show)r __module__ __qualname__ __slots__rsysstdoutrrrrrrsrc@s eZdZdZddZddZdS) NodeVisitora- A base NodeVisitor class for visiting c_ast nodes. Subclass it and define your own visit_XXX methods, where XXX is the class name you want to visit with these methods. For example: class ConstantVisitor(NodeVisitor): def __init__(self): self.values = [] def visit_Constant(self, node): self.values.append(node.value) Creates a list of values of all the constant nodes encountered below the given node. To use it: cv = ConstantVisitor() cv.visit(node) Notes: * generic_visit() will be called for AST nodes for which no visit_XXX method was defined. * The children of nodes for which a visit_XXX was defined will not be visited - if you need this, call generic_visit() on the node. You can use: NodeVisitor.generic_visit(self, node) * Modeled after Python's own AST visiting facilities (the ast module of Python 3.0) cCs"d|jj}t|||j}||S)z Visit a node. Zvisit_)rrr generic_visit)rnodemethodZvisitorrrrvisitss zNodeVisitor.visitcCs |D]\}}||qdS)zy Called if no explicit visitor function exists for a node. Implements preorder visiting of the node. N)rr))rr'Zc_namecrrrr&zszNodeVisitor.generic_visitN)rr r!__doc__r)r&rrrrr%Rs r%c@s&eZdZdZdddZddZdZdS) ArrayDecl)typedim dim_qualsr __weakref__NcCs||_||_||_||_dSN)r-r.r/r)rr-r.r/rrrr__init__szArrayDecl.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)Nr-r.)r-appendr.tuplernodelistrrrrs   zArrayDecl.children)r/)Nrr r!r"r2rrrrrrr,s r,c@s&eZdZdZdddZddZdZdS) ArrayRef)name subscriptrr0NcCs||_||_||_dSr1)r9r:r)rr9r:rrrrr2szArrayRef.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)Nr9r:)r9r3r:r4r5rrrrs   zArrayRef.childrenr)Nr7rrrrr8s r8c@s&eZdZdZdddZddZdZdS) Assignment)oplvaluervaluerr0NcCs||_||_||_||_dSr1)r<r=r>r)rr<r=r>rrrrr2szAssignment.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)Nr=r>)r=r3r>r4r5rrrrs   zAssignment.childrenr<)Nr7rrrrr;s r;c@s&eZdZdZdddZddZdZdS) BinaryOp)r<leftrightrr0NcCs||_||_||_||_dSr1)r<rArBr)rr<rArBrrrrr2szBinaryOp.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)NrArB)rAr3rBr4r5rrrrs   zBinaryOp.childrenr?)Nr7rrrrr@s r@c@s&eZdZdZdddZddZdZdS) Breakrr0NcCs ||_dSr1rrrrrrr2szBreak.__init__cCsdSNrrrrrrrszBreak.childrenr)Nr7rrrrrCs rCc@s&eZdZdZdddZddZdZdS) Case)exprstmtsrr0NcCs||_||_||_dSr1)rIrJr)rrIrJrrrrr2sz Case.__init__cCsPg}|jdk r|d|jft|jp(gD]\}}|d||fq,t|S)NrI stmts[%d])rIr3 enumeraterJr4rr6irrrrrs  z Case.childrenr)Nr7rrrrrHs rHc@s&eZdZdZdddZddZdZdS) Cast)to_typerIrr0NcCs||_||_||_dSr1)rPrIr)rrPrIrrrrr2sz Cast.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)NrPrI)rPr3rIr4r5rrrrs   z Cast.childrenr)Nr7rrrrrOs rOc@s&eZdZdZdddZddZdZdS) Compound) block_itemsrr0NcCs||_||_dSr1)rRr)rrRrrrrr2szCompound.__init__cCs6g}t|jpgD]\}}|d||fqt|S)Nzblock_items[%d])rLrRr3r4rMrrrrszCompound.childrenr)Nr7rrrrrQs rQc@s&eZdZdZdddZddZdZdS) CompoundLiteral)r-initrr0NcCs||_||_||_dSr1)r-rTr)rr-rTrrrrr2szCompoundLiteral.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)Nr-rT)r-r3rTr4r5rrrrs   zCompoundLiteral.childrenr)Nr7rrrrrSs rSc@s&eZdZdZdddZddZdZdS) Constant)r-valuerr0NcCs||_||_||_dSr1)r-rVr)rr-rVrrrrr2 szConstant.__init__cCs g}t|Sr1r4r5rrrrszConstant.children)r-rV)Nr7rrrrrUs rUc@s&eZdZdZdddZddZdZdS) ContinuerDNcCs ||_dSr1rErFrrrr2szContinue.__init__cCsdSrGrrrrrrszContinue.childrenr)Nr7rrrrrXs rXc@s&eZdZdZdddZddZdZdS) Decl) r9qualsstoragefuncspecr-rTbitsizerr0Nc Cs4||_||_||_||_||_||_||_||_dSr1)r9rZr[r\r-rTr]r) rr9rZr[r\r-rTr]rrrrr2 sz Decl.__init__cCsZg}|jdk r|d|jf|jdk r8|d|jf|jdk rR|d|jft|S)Nr-rTr])r-r3rTr]r4r5rrrr*s   z Decl.children)r9rZr[r\)Nr7rrrrrYs rYc@s&eZdZdZdddZddZdZdS) DeclList)declsrr0NcCs||_||_dSr1)r_r)rr_rrrrr25szDeclList.__init__cCs6g}t|jpgD]\}}|d||fqt|SNz decls[%d]rLr_r3r4rMrrrr9szDeclList.childrenr)Nr7rrrrr^3s r^c@s&eZdZdZdddZddZdZdS) Default)rJrr0NcCs||_||_dSr1)rJr)rrJrrrrr2CszDefault.__init__cCs6g}t|jpgD]\}}|d||fqt|S)NrK)rLrJr3r4rMrrrrGszDefault.childrenr)Nr7rrrrrbAs rbc@s&eZdZdZdddZddZdZdS) DoWhilecondstmtrr0NcCs||_||_||_dSr1rerfrrrerfrrrrr2QszDoWhile.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|SNrerfrer3rfr4r5rrrrVs   zDoWhile.childrenr)Nr7rrrrrcOs rcc@s&eZdZdZdddZddZdZdS) EllipsisParamrDNcCs ||_dSr1rErFrrrr2`szEllipsisParam.__init__cCsdSrGrrrrrrcszEllipsisParam.childrenr)Nr7rrrrrk^s rkc@s&eZdZdZdddZddZdZdS) EmptyStatementrDNcCs ||_dSr1rErFrrrr2jszEmptyStatement.__init__cCsdSrGrrrrrrmszEmptyStatement.childrenr)Nr7rrrrrlhs rlc@s&eZdZdZdddZddZdZdS) Enum)r9valuesrr0NcCs||_||_||_dSr1)r9rnr)rr9rnrrrrr2tsz Enum.__init__cCs&g}|jdk r|d|jft|S)Nrn)rnr3r4r5rrrrys z Enum.childrenr9)Nr7rrrrrmrs rmc@s&eZdZdZdddZddZdZdS) Enumerator)r9rVrr0NcCs||_||_||_dSr1)r9rVr)rr9rVrrrrr2szEnumerator.__init__cCs&g}|jdk r|d|jft|S)NrV)rVr3r4r5rrrrs zEnumerator.childrenro)Nr7rrrrrps rpc@s&eZdZdZdddZddZdZdS) EnumeratorList) enumeratorsrr0NcCs||_||_dSr1)rrr)rrrrrrrr2szEnumeratorList.__init__cCs6g}t|jpgD]\}}|d||fqt|S)Nzenumerators[%d])rLrrr3r4rMrrrrszEnumeratorList.childrenr)Nr7rrrrrqs rqc@s&eZdZdZdddZddZdZdS) ExprListexprsrr0NcCs||_||_dSr1rurrrurrrrr2szExprList.__init__cCs6g}t|jpgD]\}}|d||fqt|SNz exprs[%d]rLrur3r4rMrrrrszExprList.childrenr)Nr7rrrrrss rsc@s&eZdZdZdddZddZdZdS) FileAST)extrr0NcCs||_||_dSr1)r{r)rr{rrrrr2szFileAST.__init__cCs6g}t|jpgD]\}}|d||fqt|S)Nzext[%d])rLr{r3r4rMrrrrszFileAST.childrenr)Nr7rrrrrzs rzc@s&eZdZdZdddZddZdZdS) For)rTrenextrfrr0NcCs"||_||_||_||_||_dSr1)rTrer}rfr)rrTrer}rfrrrrr2s z For.__init__cCstg}|jdk r|d|jf|jdk r8|d|jf|jdk rR|d|jf|jdk rl|d|jft|S)NrTrer}rf)rTr3rer}rfr4r5rrrrs    z For.childrenr)Nr7rrrrr|s r|c@s&eZdZdZdddZddZdZdS) FuncCall)r9argsrr0NcCs||_||_||_dSr1)r9rr)rr9rrrrrr2szFuncCall.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)Nr9r)r9r3rr4r5rrrrs   zFuncCall.childrenr)Nr7rrrrr~s r~c@s&eZdZdZdddZddZdZdS) FuncDecl)rr-rr0NcCs||_||_||_dSr1)rr-r)rrr-rrrrr2szFuncDecl.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)Nrr-)rr3r-r4r5rrrrs   zFuncDecl.childrenr)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) FuncDef)decl param_declsbodyrr0NcCs||_||_||_||_dSr1)rrrr)rrrrrrrrr2szFuncDef.__init__cCsjg}|jdk r|d|jf|jdk r8|d|jft|jpBgD]\}}|d||fqFt|S)Nrrzparam_decls[%d])rr3rrLrr4rMrrrrs  zFuncDef.childrenr)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) Gotor9rr0NcCs||_||_dSr1r9rrr9rrrrr2sz Goto.__init__cCs g}t|Sr1rWr5rrrrsz Goto.childrenro)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) IDrNcCs||_||_dSr1rrrrrr2 sz ID.__init__cCs g}t|Sr1rWr5rrrr sz ID.childrenro)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) IdentifierType)namesrr0NcCs||_||_dSr1)rr)rrrrrrr2szIdentifierType.__init__cCs g}t|Sr1rWr5rrrrszIdentifierType.children)r)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) Ifreiftrueiffalserr0NcCs||_||_||_||_dSr1rerrrrrerrrrrrr2!sz If.__init__cCsZg}|jdk r|d|jf|jdk r8|d|jf|jdk rR|d|jft|SNrerrrer3rrr4r5rrrr's   z If.childrenr)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) InitListrtNcCs||_||_dSr1rvrwrrrr22szInitList.__init__cCs6g}t|jpgD]\}}|d||fqt|SrxryrMrrrr6szInitList.childrenr)Nr7rrrrr0s rc@s&eZdZdZdddZddZdZdS) Label)r9rfrr0NcCs||_||_||_dSr1)r9rfr)rr9rfrrrrr2@szLabel.__init__cCs&g}|jdk r|d|jft|S)Nrf)rfr3r4r5rrrrEs zLabel.childrenro)Nr7rrrrr>s rc@s&eZdZdZdddZddZdZdS) NamedInitializer)r9rIrr0NcCs||_||_||_dSr1)r9rIr)rr9rIrrrrr2NszNamedInitializer.__init__cCsPg}|jdk r|d|jft|jp(gD]\}}|d||fq,t|S)NrIzname[%d])rIr3rLr9r4rMrrrrSs  zNamedInitializer.childrenr)Nr7rrrrrLs rc@s&eZdZdZdddZddZdZdS) ParamList)paramsrr0NcCs||_||_dSr1)rr)rrrrrrr2^szParamList.__init__cCs6g}t|jpgD]\}}|d||fqt|S)Nz params[%d])rLrr3r4rMrrrrbszParamList.childrenr)Nr7rrrrr\s rc@s&eZdZdZdddZddZdZdS) PtrDecl)rZr-rr0NcCs||_||_||_dSr1)rZr-r)rrZr-rrrrr2lszPtrDecl.__init__cCs&g}|jdk r|d|jft|SNr-r-r3r4r5rrrrqs zPtrDecl.children)rZ)Nr7rrrrrjs rc@s&eZdZdZdddZddZdZdS) Return)rIrr0NcCs||_||_dSr1)rIr)rrIrrrrr2zszReturn.__init__cCs&g}|jdk r|d|jft|SNrIrIr3r4r5rrrr~s zReturn.childrenr)Nr7rrrrrxs rc@s&eZdZdZdddZddZdZdS) Structr9r_rr0NcCs||_||_||_dSr1r9r_rrr9r_rrrrr2szStruct.__init__cCs6g}t|jpgD]\}}|d||fqt|Sr`rarMrrrrszStruct.childrenro)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) StructRef)r9r-fieldrr0NcCs||_||_||_||_dSr1)r9r-rr)rr9r-rrrrrr2szStructRef.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|S)Nr9r)r9r3rr4r5rrrrs   zStructRef.children)r-)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) SwitchrdNcCs||_||_||_dSr1rgrhrrrr2szSwitch.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|Srirjr5rrrrs   zSwitch.childrenr)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) TernaryOprNcCs||_||_||_||_dSr1rrrrrr2szTernaryOp.__init__cCsZg}|jdk r|d|jf|jdk r8|d|jf|jdk rR|d|jft|Srrr5rrrrs   zTernaryOp.childrenr)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) TypeDecl)declnamerZr-rr0NcCs||_||_||_||_dSr1)rrZr-r)rrrZr-rrrrr2szTypeDecl.__init__cCs&g}|jdk r|d|jft|Srrr5rrrrs zTypeDecl.children)rrZ)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) Typedef)r9rZr[r-rr0NcCs"||_||_||_||_||_dSr1)r9rZr[r-r)rr9rZr[r-rrrrr2s zTypedef.__init__cCs&g}|jdk r|d|jft|Srrr5rrrrs zTypedef.children)r9rZr[)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) Typename)r9rZr-rr0NcCs||_||_||_||_dSr1)r9rZr-r)rr9rZr-rrrrr2szTypename.__init__cCs&g}|jdk r|d|jft|Srrr5rrrrs zTypename.children)r9rZ)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) UnaryOp)r<rIrr0NcCs||_||_||_dSr1)r<rIr)rr<rIrrrrr2szUnaryOp.__init__cCs&g}|jdk r|d|jft|Srrr5rrrrs zUnaryOp.childrenr?)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) UnionrNcCs||_||_||_dSr1rrrrrr2szUnion.__init__cCs6g}t|jpgD]\}}|d||fqt|Sr`rarMrrrrszUnion.childrenro)Nr7rrrrrs rc@s&eZdZdZdddZddZdZdS) WhilerdNcCs||_||_||_dSr1rgrhrrrr2szWhile.__init__cCs@g}|jdk r|d|jf|jdk r8|d|jft|Srirjr5rrrrs   zWhile.childrenr)Nr7rrrrrs r)2r#objectrr%r,r8r;r@rCrHrOrQrSrUrXrYr^rbrcrkrlrmrprqrsrzr|r~rrrrrrrrrrrrrrrrrrrrrrrrrrs`<0