U af @s`ddlZejjdkreefZneZeZdZdZ ddZ dZ dZ d Z d d ZeZd Zd dZddZddZddZddZddlZddlZddlZddlZedZddddddddd d! Zd"d#ZGd$d%d%eZ Gd&d'd'eZ!e"d(kr\ddl#m$Z$e$$Z%ddlZe&ej'd)Z(e()Z*e!e%Z+e+,e*ej'd)e+-Z.e.sLq\e/e+j0e.q:dS)*N) ZCPP_ID CPP_INTEGERZ CPP_FLOATZ CPP_STRINGZCPP_CHARCPP_WSZ CPP_COMMENT1Z CPP_COMMENT2Z CPP_POUNDZ CPP_DPOUNDz+-*/%|&~^<>=!?()[]{}.,;:\'"cCs|jj|jd7_|S)z\s+ lexerlinenovaluecounttr B/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/pycparser/ply/cpp.pyt_CPP_WSsrz\#z\#\#z[A-Za-z_][\w_]*cCs|S)zA(((((0x)|(0X))[0-9a-fA-F]+)|(\d+))([uU][lL]|[lL][uU]|[uU]|[lL])?)r r r r rr+srz?((\d+)(\.\d+)(e(\+|-)?(\d+))? | (\d+)e(\+|-)?(\d+))([lL]|[fF])?cCs|jj|jd7_|S)z\"([^\\\n]|(\\(.|\n)))*?\"rrr r r r t_CPP_STRING5srcCs|jj|jd7_|S)z(L)?\'([^\\\n]|(\\(.|\n)))*?\'rrr r r r t_CPP_CHAR;srcCs8|jd}|jj|7_d|_|r.d|nd|_|S)z(/\*(.|\n)*?\*/)rr )r r rrtype)r Zncrr r rt_CPP_COMMENT1As  rcCsd|_d|_|S)z (//.*?(\n|$))rr)rr r r r rt_CPP_COMMENT2JsrcCs(|jd|_|jd|_|jd|SNr)r rrskipr r r rt_errorPs   rz\?\?[=/\'\(\)\!<>\-]#\^[]|{}~) =/'()!<>-cCstdd|S)NcSst|dSN) _trigraph_repgroup)gr r rzztrigraph..) _trigraph_patsub)inputr r rtrigraphysr6c@seZdZdddZdS)MacroNFcCs0||_||_||_||_|r&|d|_d|_dSr,)namer arglistvariadicvarargsource)selfr8r r9r:r r r__init__s zMacro.__init__)NF)__name__ __module__ __qualname__r>r r r rr7sr7c@seZdZd&ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ d'ddZ ddZd(ddZddZddZd d!Zdifd"d#Zd$d%ZdS)) PreprocessorNcCsl|dkrtj}||_i|_g|_g|_|t}|dt d||dt d|d|_ dS)Nz __DATE__ "%s"z%b %d %Yz __TIME__ "%s"z%H:%M:%S) lexrmacrospath temp_pathlexprobetime localtimedefinestrftimeparser)r=rtmr r rr>szPreprocessor.__init__cCs0g}|j||j}|s q,||q|SN)rr5tokenappend)r=texttokenstokr r rtokenizes   zPreprocessor.tokenizecCstd|||fdS)Nz%s:%d %s)print)r=filelinemsgr r rerrorszPreprocessor.errorc Cs|jd|j}|r$|jdkr.tdn|j|_|jd|j}|r^t|jdkrhtdn|j|_t|j|_ |jd|j}|r|jdkrtdn|j|_ |jd|j}|r|jdkrd|_ n|j|_ |jd |j}|r|jd krd|_ td n|j|_ |j |j f|_ d d d ddddddg }|D]:}|j||j}|rz|j|krNtd|qNdS)N identifierz"Couldn't determine identifier typeZ12345i90zCouldn't determine integer typez "filename"zCouldn't determine string typez rz%Couldn't determine token for newlinesr)r*r##rr&r',.z,Unable to lex '%s' required for preprocessor)rr5rOr rUrt_IDint t_INTEGERt_INTEGER_TYPEt_STRINGZt_SPACEZ t_NEWLINEt_WS)r=rScharscr r rrGsD                 zPreprocessor.lexprobecCs|j|dSrN)rErP)r=rEr r radd_path szPreprocessor.add_pathccs|j}dd|D}tt|D]T}|d}||dr(|t|kr(||dd||||<d||<|d7}q4q(d|}||d|_g}| }|sq| ||j |j krd|j kr|Vg}q|r|VdS)NcSsg|] }|qSr )rstrip.0xr r r sz,Preprocessor.group_lines..rrr-r)rclone splitlinesxrangelenendswithjoinr5rrOrPrrcr )r=r5rClinesij current_linerSr r r group_liness*     zPreprocessor.group_linescCstd}|t|kr*||j|jkr*|d7}q|d|=t|d}|dkrb||j|jkrb|d8}q@||dd=|Sr)rprrc)r=rRrtr r r tokenstrip8s    zPreprocessor.tokenstripc Csg}g}g}d}t|}d}||kr>||j|jkr>|d7}q||krd||jdkrd||dn ||j|djddggfS|d7}||kr`||}|jdkr|||d7}n|jdkr|d8}|dkr|r||||||d||fS||nD|jdkrL|dkrL|||||dg}n |||d7}q||j|djddggfS) Nrrr&zMissing '(' in macro argumentsr'r\r-zMissing ')' in macro arguments) rprrcr rPrYr<rrx) r= tokenlistargs positionsZ current_argZnestingZtokenlenrtr r r r collect_argsTsD            zPreprocessor.collect_argscCsg|_g|_g|_d}|t|jkr|j|j|jkrh|j|j|jkrh|j|j|j}|dkr|j|djdkrt |j||j|<|j |j|_|j|d=|j ||dfqn|dkr |j|djdkr |j d||df|j|d=qnZ|dt|jkrT|j|djdkrT|j d||f|d7}qn|j d||fn|j|jdkr|j r|dkr|j|djdkr|dt|jkr|j|dj|jkr|j|dj|j kr|j |d|d7}q|jjdd d d dS) Nrrrr[reer\cSs|dS)Nr )rjr r rr1r2z,Preprocessor.macro_prescan..T)keyreverse)patch str_patchvar_comma_patchrpr rr^r9indexcopyrbrPr:r;sort)r=macrortargnumr r r macro_prescansB(   *( zPreprocessor.macro_prescanc Cs dd|jD}i}|jD]X\}}||krRdddd||Ddd||<t||||<||||_qd}|jr|d s|jD]}d||<d }qi}|jD]^\} }}| d kr|||||d <q| d kr||kr|||||<|||||d <q|rdd|D}|S)NcSsg|]}t|qSr rri_xr r rrksz2Preprocessor.macro_expand_args..z"%s"rlcSsg|] }|jqSr r rhr r rrksrz\\Fr-Trerr}cSsg|] }|r|qSr r riZ_ir r rrks) r rrrreplacerr:rr expand_macros) r=rrzrepZ str_expansionrrtZ comma_patchexpandedptyper r rmacro_expand_argss.( zPreprocessor.macro_expand_argscCs|dkr i}d}|t|kr||}|j|jkr|j|jkr|j|krd||j<|j|j}|js|dd|jD|}|D] }|j|_q||||d<|t|7}n|d}|t|kr||j|jkr|d7}q||jdkr| ||d\} } } |j sTt| t|jkrT| |j |jd|jt|jf|| }n@|j rt| t|jdkrt|jdkr| |j |jd |jt|jdfn&| |j |jd |jt|jdf|| }n|j rLt| t|jdkr| gnD||| t|jd|| d| t|jd<| t|jd=||| } || |} | D]} |j| _qh| |||| <|t| 7}||j=qn"|jd kr|j|_||j|_|d7}q|S) NrTcSsg|]}t|qSr rrr r rrksz.Preprocessor.expand_macros..rr&zMacro %s requires %d argumentsr~z(Macro %s must have at least %d argumentsz'Macro %s must have at least %d argumentZ__LINE__)rprr^r rDr9rrrcr|r:rYr<rPrr`ra)r=rRrrtr mexr}rutokcountrzr{rrr r rrs\    "  (&  4      zPreprocessor.expand_macroscCsNd}|t|kr||j|jkr||jdkr|d}d}d}|t|kr||j|jkrl|d7}qDnn||j|jkr||j|jkrd}nd}|sqn<||jdkrd}n(||jd krqn||j||jd |d7}qD|j ||_| |||_||d|d=|d7}q| |}t |D]\}}|j|jkrpt |||<|j ||_| d||_n`|j|j kr.t |||<t||j||_||jd d kr.||jdd ||_qq.d dd|D}|dd}|dd}|dd}z t|}Wn0tk rH||j|djdd}YnX|S)NrdefinedrFZ0LZ1Lr&Tr'zMalformed defined()r-Z0123456789abcdefABCDEFrlcSsg|]}t|jqSr strr rhr r rrkSsz)Preprocessor.evalexpr..z&&z and z||z or r(z not zCouldn't evaluate expression)rprr^r rcrDrYr<rr`rar enumeraterrrrreval Exception)r=rRrtruZ needparenresultr exprr r revalexpr(s^"            zPreprocessor.evalexprccst|}||}|sd}|d|||_g}d}d}g}|D],} t| D]\} } | j|jkrPqjqP| jdkrb| D]$} | j|jkrzd| jkrz|| qz| | | dd} | r| dj} | | dd}nd} g}| d kr|r`| |D] } | Vqg}||qp| d krz|r`| |D] } | Vq2g}|j d }| |D] } | VqX||j d <||_qp| d kr|r`| |D] } | Vqg}| |qp| d kr|||f|r`|dj|j krd}d}nd}qp| dkr8|||f|r`|dj|j kr0d}d}nd}qp| dkrv|||f|r`||}|spd}d}nd}n| dkr|r|ddr|rd}n|s||}|rd}d}n||j| djdn| dkr*|r|ddr(|rd}n|s(d}d}n||j| djdn6| dkrp|rH|\}}n||j| djdnqB|rB|| qB| |D] } | Vq|g}dS)Nrlz __FILE__ "%s"TFrrrrrJincludeZ__FILE__undefZifdefZifndefifelifr-zMisplaced #elifelsezMisplaced #elseendifzMisplaced #endif)r6rwrJr<rrrcr rPrxrrDrrrrYrpopextend)r=r5r<r rschunkenableZ iftriggerZifstackrjrtrSZ dirtokensr8rzZoldfilerr r rparsegencs                         zPreprocessor.parsegenc cs|sdS|r|djdkr4|dj|jkr4||}|djdkrd}|t|krl||jdkrbqx|d7}qFtddSddd|d|D}|jdg|j}nB|dj|jkr|djdd }|jdg|j}n td dS|D]}t j||}zbt |d  }t j |}|r0|j d||||D] } | Vq<|rX|jd=WqWqtk rxYqXqtd |dS) Nrr)rr*zMalformed #include <...>rlcSsg|] }|jqSr rrhr r rrksz(Preprocessor.include..r-zMalformed #include statementrzCouldn't find '%s')r rrbrrprUrrrErFosopenreaddirnameinsertrIOError) r=rRrtfilenamerEpZinamedataZdnamerSr r rrsF      zPreprocessor.includecCst|tr||}|}zz|d}t|dkr:|d}nd}|s^t|jg}||j|j<n4|j|jkrt|j| |dd}||j|j<n|jdkr| |dd\}}}d} |D]} | rt dqd dd | D} | d kr d } |j | d_d | d_d } | dd=qnb| d dd kr| dj|j krd } | dd=| djd dd kr| djdd | d_qt| dks| dj|j krt dqq| |d|d} d} | t| krX| dt| krL| | j|jkr| | djdkr| | =qn0| | jdkrL| | dj|jkrL| | d=| d7} qt|j| dd |D| }||||j|j<nt dWntk rt dYnXdS)Nrrr~r&Fz0No more arguments may follow a variadic argumentrlcSsg|]}t|jqSr rrr r rrk1sz'Preprocessor.define..z...TZ __VA_ARGS__zInvalid macro argumentr[cSsg|]}|djqS)rrrhr r rrkOszBad macro definition) isinstance STRING_TYPESrTrpr7r rDrrcrxr|rUrrr^r LookupError)r=rRZlinetokr8mtyperrrzr{r:aZastrZmvaluertr r rrJsl           $ &&    zPreprocessor.definecCs0|dj}z |j|=Wntk r*YnXdS)Nr)r rDr)r=rRidr r rr]s   zPreprocessor.undefcCs||_||||_dSrN)ignorerrL)r=r5r<rr r rparseiszPreprocessor.parsecCsDz"t|j}|j|jkr|WSqWntk r>d|_YdSXdSrN)nextrLrr StopIteration)r=rSr r rrOrs  zPreprocessor.token)N)N)N)r?r@rAr>rTrYrGrfrwrxr|rrrrrrrJrrrOr r r rrBs&  < !5+2 B; 1F  rB__main__r)1sys version_infomajorrunicoderrangerorRliteralsrZ t_CPP_POUNDZ t_CPP_DPOUNDZt_CPP_IDrZ t_CPP_INTEGERZ t_CPP_FLOATrrrrrrerrHos.pathrcompiler3r.r6objectr7rBr?Zply.lexrCrrargvfrr5rrrOrSrUr<r r r r sj     c