ó Ü_e[c@s*ddlmZdefd„ƒYZdS(i(tc_astt CGeneratorcBsýeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zed„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z!d„Z"d „Z#d!„Z$d"„Z%d#„Z&d$„Z'd%„Z(d&„Z)d'„Z*d(„Z+d)„Z,d*„Z-d+„Z.d,„Z/d-„Z0d.„Z1d/„Z2d0„Z3ed1„Z4d2„Z5gd3„Z6d4„Z7d5„Z8d6„Z9RS(7s¬ Uses the same visitor pattern as c_ast.NodeVisitor, but modified to return a value from each visit method, using string accumulation in generic_visit. cCs d|_dS(Ni(t indent_level(tself((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt__init__scCs d|jS(Nt (R(R((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt _make_indentscCs)d|jj}t|||jƒ|ƒS(Ntvisit_(t __class__t__name__tgetattrt generic_visit(Rtnodetmethod((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisitscs7|dkrdSdj‡fd†|jƒDƒƒSdS(Ntc3s$|]\}}ˆj|ƒVqdS(N(R(t.0tc_nametc(R(s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pys #s(tNonetjointchildren(RR ((Rs:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyR s cCs|jS(N(tvalue(Rtn((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_Constant%scCs|jS(N(tname(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_ID(scCs'd}|jr#|d|j7}n|S(Ns#pragmaR(tstring(RRtret((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_Pragma+s cCs.|j|jƒ}|d|j|jƒdS(Nt[t](t_parenthesize_unless_simpleRRt subscript(RRtarrref((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_ArrayRef1scCs-|j|jƒ}||j|j|jƒS(N(R RttypeRtfield(RRtsref((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_StructRef5scCs.|j|jƒ}|d|j|jƒdS(Nt(t)(R RRtargs(RRtfref((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_FuncCall9scCsx|j|jƒ}|jdkr)d|S|jdkr@d|S|jdkrcd|j|jƒSd|j|fSdS(Nsp++s%s++sp--s%s--tsizeofs sizeof(%s)s%s%s(R texprtopR(RRtoperand((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_UnaryOp=scsPˆj|j‡fd†ƒ}ˆj|j‡fd†ƒ}d||j|fS(Ncsˆj|ƒ S(N(t_is_simple_node(td(R(s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytLscsˆj|ƒ S(N(R2(R3(R(s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyR4Nss%s %s %s(t_parenthesize_iftlefttrightR/(RRtlval_strtrval_str((Rs:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_BinaryOpJs   cCs8|j|jd„ƒ}d|j|jƒ|j|fS(NcSst|tjƒS(N(t isinstanceRt Assignment(R((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyR4Tss%s %s %s(R5trvalueRtlvalueR/(RRR9((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_AssignmentQs cCsdj|jƒS(NR(Rtnames(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_IdentifierTypeWscCs_t|tjƒr'd|j|ƒdSt|tjƒrNd|j|ƒdS|j|ƒSdS(Nt{t}R(R)(R;RtInitListRtExprList(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt _visit_exprZs cCsn|r|jn |j|ƒ}|jrD|d|j|jƒ7}n|jrj|d|j|jƒ7}n|S(Ns : s = (Rt_generate_decltbitsizeRtinitRF(RRtno_typets((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_Declbs   cs`ˆj|jdƒ}t|jƒdkr\|ddj‡fd†|jdDƒƒ7}n|S(Niis, c3s$|]}ˆj|dtƒVqdS(RJN(RLtTrue(Rtdecl(R(s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pys os(RtdeclstlenR(RRRK((Rs:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_DeclListls cCsFd}|jr,|dj|jƒd7}n||j|jƒ7}|S(NRR(tstorageRt_generate_typeR$(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_Typedefss  cCs2d|j|jƒd}|d|j|jƒS(NR(R)R(RStto_typeR R.(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_CastyscCs=g}x'|jD]}|j|j|ƒƒqWdj|ƒS(Ns, (texprstappendRFR(RRtvisited_subexprsR.((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_ExprList}scCs=g}x'|jD]}|j|j|ƒƒqWdj|ƒS(Ns, (RWRXRFR(RRRYR.((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_InitListƒscCsÆd}|jr#|d|j7}n|jrÂ|d7}x|t|jjƒD]h\}}||j7}|jrˆ|d|j|jƒ7}n|t|jjƒdkrI|d7}qIqIW|d7}n|S(NtenumRs {s = is, RC(Rtvaluest enumeratet enumeratorsRRRP(RRRKtit enumerator((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_Enum‰s      cs„ˆj|jƒ}dˆ_ˆj|jƒ}|jrpdj‡fd†|jDƒƒ}|d|d|dS|d|dSdS(Nis; c3s|]}ˆj|ƒVqdS(N(R(Rtp(R(s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pys œss (RRNRtbodyt param_declsR(RRRNRdtknrdecls((Rs:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_FuncDef—s  "cCs‰d}x||jD]q}t|tjƒr>||j|ƒ7}qt|tjƒrj||j|ƒd7}q||j|ƒd7}qW|S(NRs s; (textR;RtFuncDefRtPragma(RRRKRh((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_FileAST¡scsxˆjƒd}ˆjd7_|jrQ|dj‡fd†|jDƒƒ7}nˆjd8_|ˆjƒd7}|S(Ns{ iRc3s|]}ˆj|ƒVqdS(N(t_generate_stmt(Rtstmt(R(s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pys °ss} (RRt block_itemsR(RRRK((Rs:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_Compound¬s )cCs,d|j|jƒd|j|jƒdS(NR(s){RC(RR$RI(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_CompoundLiteralµscCsdS(Nt;((RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_EmptyStatement¹scs dj‡fd†|jDƒƒS(Ns, c3s|]}ˆj|ƒVqdS(N(R(Rtparam(R(s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pys ½s(Rtparams(RR((Rs:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_ParamList¼scCs4d}|jr,|d|j|jƒ7}n|dS(NtreturnRRq(R.R(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_Return¿s cCsdS(Nsbreak;((RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_BreakÄscCsdS(Ns continue;((RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_ContinueÇscCsZd|j|jƒd}|d|j|jƒd7}|d|j|jƒd7}|S(NR(s) ? s) : R)(RFtcondtiftruetiffalse(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_TernaryOpÊscCsŽd}|jr(||j|jƒ7}n|d7}||j|jdtƒ7}|jrŠ||jƒd7}||j|jdtƒ7}n|S(Nsif (s) t add_indentselse (RzRRlR{RMR|R(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_IfÐs   cCs²d}|jr(||j|jƒ7}n|d7}|jrX|d|j|jƒ7}n|d7}|jrˆ|d|j|jƒ7}n|d7}||j|jdtƒ7}|S(Nsfor (RqRs) R~(RIRRztnextRlRmRM(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_ForÚs      cCsRd}|jr(||j|jƒ7}n|d7}||j|jdtƒ7}|S(Nswhile (s) R~(RzRRlRmRM(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_Whileås   cCsfd}||j|jdtƒ7}||jƒd7}|jrX||j|jƒ7}n|d7}|S(Nsdo R~swhile (s);(RlRmRMRRzR(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_DoWhileìs  cCs:d|j|jƒd}||j|jdtƒ7}|S(Nsswitch (s) R~(RRzRlRmRM(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_SwitchôscCsKd|j|jƒd}x*|jD]}||j|dtƒ7}q$W|S(Nscase s: R~(RR.tstmtsRlRM(RRRKRm((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_CaseùscCs7d}x*|jD]}||j|dtƒ7}qW|S(Ns default: R~(R…RlRM(RRRKRm((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_DefaultÿscCs|jd|j|jƒS(Ns: (RRlRm(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_LabelscCsd|jdS(Nsgoto Rq(R(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_GotoscCsdS(Ns...((RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_EllipsisParam scCs|j|dƒS(Ntstruct(t_generate_struct_union(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_StructscCs|j|jƒS(N(RSR$(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_TypenamescCs|j|dƒS(Ntunion(RŒ(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt visit_UnionscCsˆd}xa|jD]V}t|tjƒr<|d|j7}qt|tjƒr|d|jd7}qqW|d|j|jƒ7}|S(NRt.RRs = (RR;RtIDtConstantRRFR.(RRRKR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_NamedInitializerscCs |j|ƒS(N(RS(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pytvisit_FuncDecl!scCs¤|d|jpd}|jr |d7}||jƒ7}|jd7_|d7}x$|jD]}||j|ƒ7}q]W|jd8_||jƒd7}n|S(se Generates code for structs and unions. name should be either 'struct' or union. RRs is{ RC(RRORRRl(RRRRKRN((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyRŒ$s   cCsït|ƒ}|r$|jd7_n|jƒ}|rH|jd8_n|tjtjtjtjtjtj tj tj tj tj tjtjtjf kr·||j|ƒdS|tjfkrÖ|j|ƒS||j|ƒdSdS(sÄ Generation from a statement node. This method exists as a wrapper for individual visit_* methods to handle different treatment of some statements in this context. is; s N(R$RRRtDeclR<tCasttUnaryOptBinaryOpt TernaryOptFuncCalltArrayReft StructRefR“R’tTypedefRERtCompound(RRR~ttyptindent((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyRl4s   cCshd}|jr(dj|jƒd}n|jrN|dj|jƒd7}n||j|jƒ7}|S(s& Generation from a Decl node. RR(tfuncspecRRRRSR$(RRRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyRGPs  cCsrt|ƒ}|tjkrÈd}|jrG|dj|jƒd7}n||j|jƒ7}|jro|jnd}x5t|ƒD]'\}}t|tj ƒrø|dkr×t||dtj ƒr×d|d}n|d|j|j ƒd7}q‚t|tj ƒrb|dkrAt||dtj ƒrAd|d}n|d|j|j ƒd7}q‚t|tj ƒr‚|jrœd dj|jƒ|f}q©d |}q‚q‚W|rÄ|d|7}n|S|tjkrç|j|jƒS|tjkr|j|jƒS|tjkr)dj|jƒdS|tj tj tj fkra|j|j||gƒS|j|ƒSd S( sø Recursive generation from a type node. n is the type node. modifiers collects the PtrDecl, ArrayDecl and FuncDecl modifiers encountered on the way down to a TypeDecl, to allow proper generation from it. RRiiR(R)RRs* %s %st*N(R$RtTypeDecltqualsRRtdeclnameR^R;t ArrayDecltPtrDecltdimtFuncDeclR*R–RGtTypenameRStIdentifierTypeR@(RRt modifiersR RKtnstrR`tmodifier((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyRSYs@  &!&! cCs/|j|ƒ}||ƒr'd|dS|SdS(s‘ Visits 'n' and returns its string representation, parenthesized if the condition function applied to the node returns True. R(R)N(RF(RRt conditionRK((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyR5‡s  csˆj|‡fd†ƒS(s. Common use case for _parenthesize_if csˆj|ƒ S(N(R2(R3(R(s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyR4”s(R5(RR((Rs:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyR ‘scCs+t|tjtjtjtjtjfƒS(s~ Returns True for nodes that are "simple" - i.e. nodes that always have higher precedence than operators. (R;RR“R’RœRR›(RR((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyR2–s(:R t __module__t__doc__RRRR RRRR#R'R,R1R:R?RARFtFalseRLRQRTRVRZR[RbRgRkRoRpRrRuRwRxRyR}RRR‚RƒR„R†R‡RˆR‰RŠRRŽRR”R•RŒRlRGRSR5R R2(((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyR sn                                          . N(RRtobjectR(((s:/tmp/pip-install-KP2Jbq/pycparser/pycparser/c_generator.pyt s