3 ]([@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@s0eZdZfZddZejdddddfddZdS)NodecCsdS)z3 A sequence of all children that are Nodes N)selfrr/usr/lib/python3.6/c_ast.pychildrensz Node.childrenrFNc sd|}|r4|dk r4|j|jjd|dn|j|jjdjr|r~fddjD}djd d |D} n(fd djD} djd d | D} |j| |r|jd j|jdx.jD]"\} } | j||d|||| dqWdS)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|fqSr)getattr).0n)rrr =szNode.show..z, css|]}d|VqdS)z%s=%sNr)r Znvrrr >szNode.show..csg|]}t|qSr)r)r r )rrrr @scss|]}d|VqdS)z%sNr)r vrrrr Asz (at %s) )offset attrnames nodenames showcoord _my_node_name)write __class____name__ attr_namesjoincoordrshow) rZbufrrrrrZleadZnvlistZattrstrZvlistZ child_namechildr)rrrs,    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$x|jD]\}}|j|q WdS)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)rrr__doc__r&r#rrrrr"Rs r"c@s&eZdZd Zd ddZd d Zd ZdS) ArrayDecltypedim dim_qualsr __weakref__NcCs||_||_||_||_dS)N)r*r+r,r)rr*r+r,rrrr__init__szArrayDecl.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)Nr*r+)r*appendr+tuple)rnodelistrrrrs   zArrayDecl.children)r*r+r,rr-)N)r,)rrrrr.rrrrrrr)s r)c@s&eZdZd Zd ddZdd ZfZdS) ArrayRefname subscriptrr-NcCs||_||_||_dS)N)r3r4r)rr3r4rrrrr.szArrayRef.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)Nr3r4)r3r/r4r0)rr1rrrrs   zArrayRef.children)r3r4rr-)N)rrrrr.rrrrrrr2s r2c@s&eZdZd Zd ddZd d Zd ZdS) Assignmentoplvaluervaluerr-NcCs||_||_||_||_dS)N)r6r7r8r)rr6r7r8rrrrr.szAssignment.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)Nr7r8)r7r/r8r0)rr1rrrrs   zAssignment.children)r6r7r8rr-)N)r6)rrrrr.rrrrrrr5s r5c@s&eZdZd Zd ddZd d Zd ZdS)BinaryOpr6leftrightrr-NcCs||_||_||_||_dS)N)r6r:r;r)rr6r:r;rrrrr.szBinaryOp.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)Nr:r;)r:r/r;r0)rr1rrrrs   zBinaryOp.children)r6r:r;rr-)N)r6)rrrrr.rrrrrrr9s r9c@s&eZdZdZd ddZddZfZdS) Breakrr-NcCs ||_dS)N)r)rrrrrr.szBreak.__init__cCsfS)Nr)rrrrrszBreak.children)rr-)N)rrrrr.rrrrrrr<s r<c@s&eZdZd Zd ddZdd ZfZdS) Caseexprstmtsrr-NcCs||_||_||_dS)N)r>r?r)rr>r?rrrrr.sz Case.__init__cCsTg}|jdk r|jd|jfx,t|jp*gD]\}}|jd||fq.Wt|S)Nr>z stmts[%d])r>r/ enumerater?r0)rr1irrrrrs  z Case.children)r>r?rr-)N)rrrrr.rrrrrrr=s r=c@s&eZdZd Zd ddZdd ZfZdS) Castto_typer>rr-NcCs||_||_||_dS)N)rCr>r)rrCr>rrrrr.sz Cast.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)NrCr>)rCr/r>r0)rr1rrrrs   z Cast.children)rCr>rr-)N)rrrrr.rrrrrrrBs rBc@s&eZdZd Zd ddZddZfZdS) Compound block_itemsrr-NcCs||_||_dS)N)rEr)rrErrrrr.szCompound.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nzblock_items[%d])r@rEr/r0)rr1rArrrrrszCompound.children)rErr-)N)rrrrr.rrrrrrrDs rDc@s&eZdZd Zd ddZdd ZfZdS) CompoundLiteralr*initrr-NcCs||_||_||_dS)N)r*rGr)rr*rGrrrrr.szCompoundLiteral.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)Nr*rG)r*r/rGr0)rr1rrrrs   zCompoundLiteral.children)r*rGrr-)N)rrrrr.rrrrrrrFs rFc@s&eZdZd Zd ddZdd Zd ZdS) Constantr*valuerr-NcCs||_||_||_dS)N)r*rIr)rr*rIrrrrr. szConstant.__init__cCs g}t|S)N)r0)rr1rrrrszConstant.children)r*rIrr-)N)r*rI)rrrrr.rrrrrrrHs rHc@s&eZdZdZd ddZddZfZdS) Continuerr-NcCs ||_dS)N)r)rrrrrr.szContinue.__init__cCsfS)Nr)rrrrrszContinue.children)rr-)N)rrrrr.rrrrrrrJs rJc @s&eZdZdZdd d Zd dZdZd S)Declr3qualsstoragefuncspecr*rGbitsizerr-Nc Cs4||_||_||_||_||_||_||_||_dS)N)r3rLrMrNr*rGrOr) rr3rLrMrNr*rGrOrrrrr. sz Decl.__init__cCsZg}|jdk r|jd|jf|jdk r8|jd|jf|jdk rR|jd|jft|S)Nr*rGrO)r*r/rGrOr0)rr1rrrr*s   z Decl.children) r3rLrMrNr*rGrOrr-)N)r3rLrMrN)rrrrr.rrrrrrrKs rKc@s&eZdZd Zd ddZddZfZdS) DeclListdeclsrr-NcCs||_||_dS)N)rQr)rrQrrrrr.5szDeclList.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nz decls[%d])r@rQr/r0)rr1rArrrrr9szDeclList.children)rQrr-)N)rrrrr.rrrrrrrP3s rPc@s&eZdZd Zd ddZddZfZdS) Defaultr?rr-NcCs||_||_dS)N)r?r)rr?rrrrr.CszDefault.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nz stmts[%d])r@r?r/r0)rr1rArrrrrGszDefault.children)r?rr-)N)rrrrr.rrrrrrrRAs rRc@s&eZdZd Zd ddZdd ZfZdS) DoWhilecondstmtrr-NcCs||_||_||_dS)N)rTrUr)rrTrUrrrrr.QszDoWhile.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)NrTrU)rTr/rUr0)rr1rrrrVs   zDoWhile.children)rTrUrr-)N)rrrrr.rrrrrrrSOs rSc@s&eZdZdZd ddZddZfZdS) EllipsisParamrr-NcCs ||_dS)N)r)rrrrrr.`szEllipsisParam.__init__cCsfS)Nr)rrrrrcszEllipsisParam.children)rr-)N)rrrrr.rrrrrrrV^s rVc@s&eZdZdZd ddZddZfZdS) EmptyStatementrr-NcCs ||_dS)N)r)rrrrrr.jszEmptyStatement.__init__cCsfS)Nr)rrrrrmszEmptyStatement.children)rr-)N)rrrrr.rrrrrrrWhs rWc@s&eZdZd Zd ddZdd Zd ZdS) Enumr3valuesrr-NcCs||_||_||_dS)N)r3rYr)rr3rYrrrrr.tsz Enum.__init__cCs&g}|jdk r|jd|jft|S)NrY)rYr/r0)rr1rrrrys z Enum.children)r3rYrr-)N)r3)rrrrr.rrrrrrrXrs rXc@s&eZdZd Zd ddZdd Zd ZdS) Enumeratorr3rIrr-NcCs||_||_||_dS)N)r3rIr)rr3rIrrrrr.szEnumerator.__init__cCs&g}|jdk r|jd|jft|S)NrI)rIr/r0)rr1rrrrs zEnumerator.children)r3rIrr-)N)r3)rrrrr.rrrrrrrZs rZc@s&eZdZd Zd ddZddZfZdS) EnumeratorList enumeratorsrr-NcCs||_||_dS)N)r\r)rr\rrrrr.szEnumeratorList.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nzenumerators[%d])r@r\r/r0)rr1rArrrrrszEnumeratorList.children)r\rr-)N)rrrrr.rrrrrrr[s r[c@s&eZdZd Zd ddZddZfZdS) ExprListexprsrr-NcCs||_||_dS)N)r^r)rr^rrrrr.szExprList.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nz exprs[%d])r@r^r/r0)rr1rArrrrrszExprList.children)r^rr-)N)rrrrr.rrrrrrr]s r]c@s&eZdZd Zd ddZddZfZdS) FileASTextrr-NcCs||_||_dS)N)r`r)rr`rrrrr.szFileAST.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nzext[%d])r@r`r/r0)rr1rArrrrrszFileAST.children)r`rr-)N)rrrrr.rrrrrrr_s r_c@s&eZdZd Zd dd Zd d ZfZdS)ForrGrTnextrUrr-NcCs"||_||_||_||_||_dS)N)rGrTrbrUr)rrGrTrbrUrrrrr.s z For.__init__cCstg}|jdk r|jd|jf|jdk r8|jd|jf|jdk rR|jd|jf|jdk rl|jd|jft|S)NrGrTrbrU)rGr/rTrbrUr0)rr1rrrrs    z For.children)rGrTrbrUrr-)N)rrrrr.rrrrrrras rac@s&eZdZd Zd ddZdd ZfZdS) FuncCallr3argsrr-NcCs||_||_||_dS)N)r3rdr)rr3rdrrrrr.szFuncCall.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)Nr3rd)r3r/rdr0)rr1rrrrs   zFuncCall.children)r3rdrr-)N)rrrrr.rrrrrrrcs rcc@s&eZdZd Zd ddZdd ZfZdS) FuncDeclrdr*rr-NcCs||_||_||_dS)N)rdr*r)rrdr*rrrrr.szFuncDecl.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)Nrdr*)rdr/r*r0)rr1rrrrs   zFuncDecl.children)rdr*rr-)N)rrrrr.rrrrrrres rec@s&eZdZd Zd ddZd d ZfZdS) FuncDefdecl param_declsbodyrr-NcCs||_||_||_||_dS)N)rgrhrir)rrgrhrirrrrr.szFuncDef.__init__cCsng}|jdk r|jd|jf|jdk r8|jd|jfx,t|jpDgD]\}}|jd||fqHWt|S)Nrgrizparam_decls[%d])rgr/rir@rhr0)rr1rArrrrrs  zFuncDef.children)rgrhrirr-)N)rrrrr.rrrrrrrfs rfc@s&eZdZd Zd ddZddZd ZdS) Gotor3rr-NcCs||_||_dS)N)r3r)rr3rrrrr.sz Goto.__init__cCs g}t|S)N)r0)rr1rrrrsz Goto.children)r3rr-)N)r3)rrrrr.rrrrrrrjs rjc@s&eZdZd Zd ddZddZd ZdS) IDr3rr-NcCs||_||_dS)N)r3r)rr3rrrrr. sz ID.__init__cCs g}t|S)N)r0)rr1rrrr sz ID.children)r3rr-)N)r3)rrrrr.rrrrrrrks rkc@s&eZdZd Zd ddZddZd ZdS) IdentifierTypenamesrr-NcCs||_||_dS)N)rmr)rrmrrrrr.szIdentifierType.__init__cCs g}t|S)N)r0)rr1rrrrszIdentifierType.children)rmrr-)N)rm)rrrrr.rrrrrrrls rlc@s&eZdZd Zd ddZd d ZfZdS) IfrTiftrueiffalserr-NcCs||_||_||_||_dS)N)rTrorpr)rrTrorprrrrr.!sz If.__init__cCsZg}|jdk r|jd|jf|jdk r8|jd|jf|jdk rR|jd|jft|S)NrTrorp)rTr/rorpr0)rr1rrrr's   z If.children)rTrorprr-)N)rrrrr.rrrrrrrns rnc@s&eZdZd Zd ddZddZfZdS) InitListr^rr-NcCs||_||_dS)N)r^r)rr^rrrrr.2szInitList.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nz exprs[%d])r@r^r/r0)rr1rArrrrr6szInitList.children)r^rr-)N)rrrrr.rrrrrrrq0s rqc@s&eZdZd Zd ddZdd Zd ZdS) Labelr3rUrr-NcCs||_||_||_dS)N)r3rUr)rr3rUrrrrr.@szLabel.__init__cCs&g}|jdk r|jd|jft|S)NrU)rUr/r0)rr1rrrrEs zLabel.children)r3rUrr-)N)r3)rrrrr.rrrrrrrr>s rrc@s&eZdZd Zd ddZdd ZfZdS) NamedInitializerr3r>rr-NcCs||_||_||_dS)N)r3r>r)rr3r>rrrrr.NszNamedInitializer.__init__cCsTg}|jdk r|jd|jfx,t|jp*gD]\}}|jd||fq.Wt|S)Nr>zname[%d])r>r/r@r3r0)rr1rArrrrrSs  zNamedInitializer.children)r3r>rr-)N)rrrrr.rrrrrrrsLs rsc@s&eZdZd Zd ddZddZfZdS) ParamListparamsrr-NcCs||_||_dS)N)rur)rrurrrrr.^szParamList.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nz params[%d])r@rur/r0)rr1rArrrrrbszParamList.children)rurr-)N)rrrrr.rrrrrrrt\s rtc@s&eZdZd Zd ddZdd Zd ZdS) PtrDeclrLr*rr-NcCs||_||_||_dS)N)rLr*r)rrLr*rrrrr.lszPtrDecl.__init__cCs&g}|jdk r|jd|jft|S)Nr*)r*r/r0)rr1rrrrqs zPtrDecl.children)rLr*rr-)N)rL)rrrrr.rrrrrrrvjs rvc@s&eZdZd Zd ddZddZfZdS) Returnr>rr-NcCs||_||_dS)N)r>r)rr>rrrrr.zszReturn.__init__cCs&g}|jdk r|jd|jft|S)Nr>)r>r/r0)rr1rrrr~s zReturn.children)r>rr-)N)rrrrr.rrrrrrrwxs rwc@s&eZdZd Zd ddZdd Zd ZdS) Structr3rQrr-NcCs||_||_||_dS)N)r3rQr)rr3rQrrrrr.szStruct.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nz decls[%d])r@rQr/r0)rr1rArrrrrszStruct.children)r3rQrr-)N)r3)rrrrr.rrrrrrrxs rxc@s&eZdZd Zd ddZd d Zd ZdS) StructRefr3r*fieldrr-NcCs||_||_||_||_dS)N)r3r*rzr)rr3r*rzrrrrr.szStructRef.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)Nr3rz)r3r/rzr0)rr1rrrrs   zStructRef.children)r3r*rzrr-)N)r*)rrrrr.rrrrrrrys ryc@s&eZdZd Zd ddZdd ZfZdS) SwitchrTrUrr-NcCs||_||_||_dS)N)rTrUr)rrTrUrrrrr.szSwitch.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)NrTrU)rTr/rUr0)rr1rrrrs   zSwitch.children)rTrUrr-)N)rrrrr.rrrrrrr{s r{c@s&eZdZd Zd ddZd d ZfZdS) TernaryOprTrorprr-NcCs||_||_||_||_dS)N)rTrorpr)rrTrorprrrrr.szTernaryOp.__init__cCsZg}|jdk r|jd|jf|jdk r8|jd|jf|jdk rR|jd|jft|S)NrTrorp)rTr/rorpr0)rr1rrrrs   zTernaryOp.children)rTrorprr-)N)rrrrr.rrrrrrr|s r|c@s&eZdZd Zd ddZd d Zd ZdS)TypeDecldeclnamerLr*rr-NcCs||_||_||_||_dS)N)r~rLr*r)rr~rLr*rrrrr.szTypeDecl.__init__cCs&g}|jdk r|jd|jft|S)Nr*)r*r/r0)rr1rrrrs zTypeDecl.children)r~rLr*rr-)N)r~rL)rrrrr.rrrrrrr}s r}c@s&eZdZd Zd dd Zd d ZdZdS)Typedefr3rLrMr*rr-NcCs"||_||_||_||_||_dS)N)r3rLrMr*r)rr3rLrMr*rrrrr.s zTypedef.__init__cCs&g}|jdk r|jd|jft|S)Nr*)r*r/r0)rr1rrrrs zTypedef.children)r3rLrMr*rr-)N)r3rLrM)rrrrr.rrrrrrrs rc@s&eZdZd Zd ddZd d Zd ZdS)Typenamer3rLr*rr-NcCs||_||_||_||_dS)N)r3rLr*r)rr3rLr*rrrrr.szTypename.__init__cCs&g}|jdk r|jd|jft|S)Nr*)r*r/r0)rr1rrrrs zTypename.children)r3rLr*rr-)N)r3rL)rrrrr.rrrrrrrs rc@s&eZdZd Zd ddZdd Zd ZdS) UnaryOpr6r>rr-NcCs||_||_||_dS)N)r6r>r)rr6r>rrrrr.szUnaryOp.__init__cCs&g}|jdk r|jd|jft|S)Nr>)r>r/r0)rr1rrrrs zUnaryOp.children)r6r>rr-)N)r6)rrrrr.rrrrrrrs rc@s&eZdZd Zd ddZdd Zd ZdS) Unionr3rQrr-NcCs||_||_||_dS)N)r3rQr)rr3rQrrrrr.szUnion.__init__cCs:g}x,t|jpgD]\}}|jd||fqWt|S)Nz decls[%d])r@rQr/r0)rr1rArrrrrszUnion.children)r3rQrr-)N)r3)rrrrr.rrrrrrrs rc@s&eZdZd Zd ddZdd ZfZdS) WhilerTrUrr-NcCs||_||_||_dS)N)rTrUr)rrTrUrrrrr.szWhile.__init__cCs@g}|jdk r|jd|jf|jdk r8|jd|jft|S)NrTrU)rTr/rUr0)rr1rrrrs   zWhile.children)rTrUrr-)N)rrrrr.rrrrrrrs r)2r objectrr"r)r2r5r9r<r=rBrDrFrHrJrKrPrRrSrVrWrXrZr[r]r_rarcrerfrjrkrlrnrqrrrsrtrvrwrxryr{r|r}rrrrrrrrrs`<0