6Wc@sddlZddlmZddlTddlTddlTddlmZddlmZddlmZm Z ddl Z ddl Z ddl Z defdYZ ed Zd efd YZdS( iN(tExporter(t*(tSingleCodeUnit(t EnumExporter(tmakeidt enumeratet ClassExportercBseZdZd'dZdZdZdZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdjZeeeeeeZidd6Zidejd6dejd6dejd6dejd6dejd6dejd 6Z d!Z!d"Z"d#Z#d$Z$d%Z%d&Z&RS((s9Generates boost.python code to export a class declarationcCstj|||i|_g|jd|jt^q>}t g|D]}|df^qr}t g|D]}|df^q}x|jj D] }t }x|D]}|j |j}|j|krx|D]}t|krtj|} |jj| _t| tr| jt} | |kr|jj|d|| Rs(%s) iR s s; s); tmodules delete %s; R sdeclaration-outsideR ( tINDENTt namespacestpythontpysteRRRtjointSectionR>(RR?tindenttboost_nstpyste_nstcodeRt needs_scopet scope_namettemplate_paramstconstructor_paramst in_indenttlinet nested_unitRtdeclarations_outsidetincludes((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR>sN          cCs|j|j|dS(s+Add the item into the corresponding sectionN(RR&(Rtsectiontitem((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pytAddscCsO|jj}|jd||jjp4|jj}|jdd|dS(s6Export the name of the class and its class_ statement.RRs"%s"N(RRRnRR R(Rt class_nameR((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR2scCs|jj}g}x]|D]U}xB|D]:}|jtjkr&|j|kr&|j|jq&q&W|rPqqW|rtjddj |}|j d|ndS(s7Expose the bases of the class into the template sections bases< %s > s, RN( RR%RBRCRDRR&RZR[R]Rn(RR@R%texportedR(R)Rb((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR3s   !cstj|j}fd}g|jD]}t|tr+|^q+}||_|jjrx.|D]#}|j ri|j |PqiqiWn|s|j ddnd}xA|D]9}|dkst |jt |jkr|}qqW|dk s t|j d|||j |x.|D]&}d||}|j d|q6W|jj s||jjr|j dtjdndS( snExports all the public contructors of the class, plus indicates if the class is noncopyable. csg|jD]}|j^q }||j }||j}dj|}dj|}d}||7}|r|r|d7}n|d|7}n|d7}|S(s1return the init<>() code for the given contructors, sinit< soptional< %s >s >()(t parametersRtminArgsR](tconstpt param_listtmin_params_listtmax_params_listt min_paramst max_paramstinit(tpy_ns(s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyt init_codes"      Rtno_inits.def(%s)R Rt noncopyableN(RZR[RYRQRt ConstructorRRtabstracttIsCopytremoveRnR#R,RqtAssertionErrortHasCopyConstructortboost(RR_R|R*RRstsmallerRb((R{s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR4s0  +       *   cCsg|jD]}t|tr |^q }x|D]}|j|jjrQq2n|j|jjpj|j}|j}|jj rd}nd}d|||f}|j d|q2WdS(sCExport the variables of the class, both static and simple variabless .def_readonlys.def_readwrites %s("%s", &%s)R N( RQRtVariableRRR1R RRtconstRn(RR*tvarstvarRtfullnametdef_Rb((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR5!s+    cCs0t|j}d|j|jf}||S(s=Returns the name of the overloads struct for the given methods_overloads_%i_%i(RRRrtmaxArgs(RtmethodRt overloads((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyt OverloadName1scCsb|jj}g}|r^xC|D]8\}}|j|}||j|_|j|qWn|S(N(Rt __added__RR R&(Rt added_methodstresultRR R$((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pytGetAddedMethods8s csifd}fd}d}gjD]}||r:|^q:}|jji}xv|D]n}j|j}|jrqxn|jp|j} tj||j |_ |j pd} | rdt j | j f} nd} |j |jkrI|j rI||j|} dt j| f} n||} d| | f}|| 7}|| 7}|d7}jd|t|tr|jrd || Returns true if the given method is exportable by this routine(Rt ClassOperatort DestructorRRtvirtual(Rtignore((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyt IsExportable_sRWs, %s%s()s .def("%s", %st)R iR s.staticmethod("%s")N(RQtextendRRRR1R t exporterutilst HandlePolicytpolicyRZR[tCodeRrRRRR\RnRRHRRb(RRRRR*tmethodst staticmethodsRt method_infoRRtoverloadt overload_nameRVRbR((RRs7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR7CsF (           cCsMxF|jD];}t|tkr |jr |j|jj |_q q WdS(sMake all methods that the user indicated to no_override no more virtual, delegating their export to the ExportMethods routineN(RRRHRRRt no_override(RRE((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR0scCst}x6|jD]+}t|tkr|jrt}PqqW|jj}|rt|j|j |j|}|r|j d||j n|j d|j x$|j D]}|j d|qW|j d|j |jn(|r|j d||jj ndS(NRR R (RORRRHRRMRtholdert_VirtualWrapperGeneratorR+RnRtGenerateDefinitionstGenerateVirtualWrapperRY(RR?thas_virtual_methodsRERt generatort definition((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR6s  !sO+ - * / % ^ & ! ~ | < > == != <= >= << >> && || += -= *= /= %= ^= &= |= <<= >>=t__call__s()t __float__s(const)?\s*double$s(const)?\s*float$t__int__s(const)?\s*int$t__long__s(const)?\s*long$t__str__s(const)?\s*char\s*\*?$s((const)?.*::basic_string<.*>\s*(\*|\&)?$csfd}fd}d}|}gjD]}t|tkr:|^q:}||}g|D]#}jd|jjso|^qo}x`|D]X} jd| jj} | rd| j} | jrj d| jqn | j } jd| jj } | p2| p2| jj k} || }|dk }| r| s~| rk| j} q~j | j} nd}jd| jj}|rd|j}nj d d | | |fq|rj d |q| jjkr| }t|tr)t|jd kpJt|toJt|jd k}|rvj d d | jtjfqt| jdkr|| jd }|| jd }n tjd}|| jd }j d d|| j|fqqWgjD]}t|tkr|^q}fd}x|D]}jd|jj}|jrnq?n||}|j s| r|j p||}|j } d}|jrd|jj}nj d d || |fq?|r?j d |q?q?WdS(sDExport all member operators and free operators related to this classcsmg}x`jD]U}t|trx=|jD]/}|jjjkr/|j|Pq/q/WqqW|S(s9Get all the free (global) operators related to this class(RRtOperatorRqRRRR&(t operatorsR$tparam(R(s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pytGetFreeOperatorss cs9|jjjkr#tjdStjd|jSdS(sGReturns the operand of this parameter (either "self", or "other")Rs other< %s >()N(RRRRZR[(R(R(s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyt GetOperands cSs|jj}d}|jr.|jdj}nd}|j|dko[|j|dk}|rtjd}tjd}d||fSdS(NRWit basic_ostreamis self_ns::Rs.def(%sstr(%s))(RRRqtfindRZR[R#(toperatort result_namet param1_nametostreamtis_strt namespacetself_((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pytHandleSpecialOperators  *  RRsdeclaration-outsideRWs, %s()R s.def("%s", %s%s)iis.def( %s%sself )iRs.def( %s %s %s )csf|jj}|jj}xDjjD]\}}|j|r+|Sq+Wt|}d|SdS(Ntto_(RRRtSPECIAL_CONVERTERStitemstmatchR(t convertertresult_fullnameRtregext method_name(R(s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pytConverterMethodName9s  N(RQRRRRR1RRRbRnRLR tBOOST_RENAME_OPERATORSR#RRtBOOST_SUPPORTED_OPERATORSRRR,RqRZR[tConverterOperatorR(RRRRtfreesR*tmemberst all_operatorsRRRRVR texport_as_methodt special_codethas_special_representationRt policy_objtoptis_unaryt left_operandt right_operandt convertersRRRRt policy_code((Rs7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR8sx   . 0       $$   .      cCsg|jD]}t|tr |^q }x|D]}|j|j}|jj|_|j|_|j|}|j|j t dd}|j |||j j|q2WdS(N(RQRRJRRR Rt __class__RRRR#RARR&(RR@R*tnested_classest nested_classt nested_infotexporterR?((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR9Ys+ cCsg|jD]}t|tr |^q }x|D]}|j|j}|jj|_|j|_t|}|j|j t dd}|j |||j j|q2WdS(N(RQRRKRRR RRRRRR#RARR&(RR@R*t nested_enumstenumt enum_infoRR?((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR:fs+  cCsO|jj}|rK|jj}||}|jddtj|fndS(NR s!%sregister_ptr_to_python< %s >();(Rt smart_ptrRRRnRZR[(RRRo((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR;ss   cCsg|jD]}t|tr |^q }xd|D]\}tt}|j|jj|kr2tj |j j}|r|j d|qq2q2WdS(Nsdeclaration-outside( RQRRHtreturn_value_policytreturn_opaque_pointerRRRRtEspecializeTypeIDRRn(RR*RRtreturn_opaque_policyR((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR<{s+  cCs:|jjr6x'|jjD]}|jd|qWndS(NR (Rt__code__Rn(RRb((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR=s N('t__name__t __module__t__doc__R#R RRRR+R.RAR/R>RnR2R3R4R5RRR7R0R6tsplitRRNtziptrangeR,RtretcompileRR8R9R:R;R<R=(((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyRsJ       % 8    9   U   !   c Cs|dkrt|j}ngt|D]}d|^q+}g|j| D]}|j^qO}gt||D]\}}d||f^qw}dj|}|||fS(Nsp%is%s %ss, (R#R,RqRRRR]( Rtcounttit param_namesR*t param_typestttntparams((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyt _ParamsInfos #&2RcBseeZdZdZdZdZdZdZdZdZ dZ d Z d Z RS( s?Generates code to export the virtual methods of the given classcCsgtj||_||_||_t|jd|_d|_ i|_ ||_ |j dS(Nt_Wrapper( R!R"RtbasesRRRt wrapper_nameR#tvirtual_methodst _method_countR?tGenerateVirtualMethods(RRRRR?((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR s     tpy_selfcCsbd|j}|j}|j}||kr2|gSgt||dD]}|d|^qFSdS(sReturns a list of default implementations for this method, one for each number of default arguments. Always returns at least one name, and return from the one with most arguments to the one with the least. tdefault_is_%iN(RRrRR(RRt base_nameRrRR((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pytDefaultImplementationNamess     cstj}tj}j|jjp+|j}|jj}d|dkrXdnt|\}}} d} |j rd} nd||j|| |j f} dj |} | rd| } nj } | ddt 7} | d 7} fd }|j r|jtjkr|j}|j}j|}xt|t||d D]m\}}t||\}}} | d 7} | d |||| f7} | |||7} | d 7} qlWn| S(sReturns a string with the declarations of the virtual wrapper and its default implementations. This string must be put inside the Wrapper body. sreturn tvoidRWs consts%s %s(%s)%s%s { s, isb%(return_str)s%(python)scall_method< %(result)s >(%(self_str)s, "%(rename)s"%(param_names_str)s); s} csd}j|jj}|sG|d|jdj|fS|jrijjd|jndjdg|}|d|j|fSdS(s3Return the body of a default implementation wrapperis %s%s(%s); s, sdeclaration-outsidetthisN(RRRRR]RbR?R>(RRtindent2RR(R_t return_strR(s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyt DefaultImpls  is s%s %s(%s)%s { (RZR\R[RRR RRRRt ExceptionsR]tSELFtlocalsRRBRCtprivateRrRR RR(RRR_R\R[R RRRRt constantnessR$tparam_names_strtself_strRRrRt impl_namest impl_nametargNum((R_RRs7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyt Declarations>      &      ) cCsmtj}|j|jjp"|j}|j|}|jj}||j}|j j}|j }d} |j rd} n|j } |j } |jrg} n|rg|D]} d|| f^q} ng} xt|t| | dD]w\}}g|j| D]} | j^q }dj|}d|||| f}d|||f}| j|qW|j}|jrtjd|}n|j|j}tj||j|_|jpd}|rd tj|jf}ng}| rO|jd ||| d |fxI| d D] }|jd |||fq(Wn|jd |||f|S( sgReturns a list of lines, which should be put inside the class_ statement to export this method.RWs consts&%s::%sis, s%s (%s::*)(%s)%ss (%s)&%s::%sspure_virtual(%s)s, %s%s()s.def("%s", %s, %s%s)is.def("%s", %s%s)(RZR\RRR R RRRRt is_uniqueRRrRRRRRqR]R&RLR[RRRR(RRR\R t default_namesRoRRtis_method_uniqueRRrRtdefault_pointersR*RRRuRt signaturetdefault_pointerRVRRt definitions((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pytMethodDefinitionsL         &)&  !!cCstj|jS(N(RZR\R(R((s7/usr/lib/python2.7/dist-packages/Pyste/ClassExporter.pyR/sc CsEd}d}i}g|_x@|jD]5}||r+d|||<|jj|q+q+Wx`|jD]U}g|D]!}||r{tj|^q{}x|D]}|jj|qWqnWg|jD]}||r|^q} xO| D]G}||} ||r| |kr|jj|d|| s       |