3

T'íc»7ã@sÒdZddlZddlmZddlmZmZmZmZm	Z	m
Z
mZmZddl
mZddlmZddlmZddlmZdd	lmZejeƒZeegefZejd
ƒZejdƒZejdƒZejd
ƒZ ejdƒZ!ejdƒZ"ejdƒZ#ejdƒZ$ejdƒZ%ejdƒZ&ejdƒZ'eddœdd„Z(Gdd„de)ƒZ*Gdd„dƒZ+Gdd„de+ƒZ,Gdd„de,ƒZ-Gd d!„d!e+ƒZ.Gd"d#„d#e,ƒZ/Gd$d%„d%e,ƒZ0Gd&d'„d'e,ƒZ1Gd(d)„d)e+ƒZ2Gd*d+„d+e)ƒZ3Gd,d-„d-e)ƒZ4Gd.d/„d/ƒZ5dS)0z2Utility functions common to the C and C++ domains.éN)Údeepcopy)ÚAnyÚCallableÚListÚMatchÚOptionalÚPatternÚTupleÚUnion)Únodes)ÚTextElement)Úaddnodes)ÚConfig)Úloggingz(?u)\s+z(@[a-zA-Z0-9_])[a-zA-Z0-9_]*\ba
(?x)
    (   # This 'extends' _anon_identifier_re with the ordinary identifiers,
        # make sure they are in sync.
        (~?\b[a-zA-Z_])  # ordinary identifiers
    |   (@[a-zA-Z0-9_])  # our extension for names of anonymous entities
    )
    [a-zA-Z0-9_]*\b
z[1-9][0-9]*(\'[0-9]+)*z0[0-7]*(\'[0-7]+)*z"0[xX][0-9a-fA-F]+(\'[0-9a-fA-F]+)*z0[bB][01]+(\'[01]+)*a%(?x)
    # unsigned and/or (long) long, in any order, but at least one of them
    (
        ([uU]    ([lL]  |  (ll)  |  (LL))?)
        |
        (([lL]  |  (ll)  |  (LL))    [uU]?)
    )\b
    # the ending word boundary is important for distinguishing
    # between suffixes and UDLs in C++
a(?x)
    [+-]?(
    # decimal
      ([0-9]+(\'[0-9]+)*[eE][+-]?[0-9]+(\'[0-9]+)*)
    | (([0-9]+(\'[0-9]+)*)?\.[0-9]+(\'[0-9]+)*([eE][+-]?[0-9]+(\'[0-9]+)*)?)
    | ([0-9]+(\'[0-9]+)*\.([eE][+-]?[0-9]+(\'[0-9]+)*)?)
    # hex
    | (0[xX][0-9a-fA-F]+(\'[0-9a-fA-F]+)*[pP][+-]?[0-9a-fA-F]+(\'[0-9a-fA-F]+)*)
    | (0[xX]([0-9a-fA-F]+(\'[0-9a-fA-F]+)*)?\.
        [0-9a-fA-F]+(\'[0-9a-fA-F]+)*([pP][+-]?[0-9a-fA-F]+(\'[0-9a-fA-F]+)*)?)
    | (0[xX][0-9a-fA-F]+(\'[0-9a-fA-F]+)*\.([pP][+-]?[0-9a-fA-F]+(\'[0-9a-fA-F]+)*)?)
    )
z[fFlL]\bzÒ(?x)
    ((?:u8)|u|U|L)?
    '(
      (?:[^\\'])
    | (\\(
        (?:['"?\\abfnrtv])
      | (?:[0-7]{1,3})
      | (?:x[0-9a-fA-F]{2})
      | (?:u[0-9a-fA-F]{4})
      | (?:U[0-9a-fA-F]{8})
      ))
    )'
)ÚmodeÚreturncCs|dkrtd|ƒ‚dS)	NÚ
lastIsNameÚ
noneIsNameÚmarkTypeÚmarkNameÚparamÚudlz!Description mode '%s' is invalid.)rrrrrr)Ú	Exception)r©rú5/tmp/pip-build-gk9425m9/sphinx/sphinx/util/cfamily.pyÚverify_description_modeIsrc@seZdZdS)ÚNoOldIdErrorN)Ú__name__Ú
__module__Ú__qualname__rrrrrNsrc@sveZdZUeedœdd„ZdZegefedœdd„Z	e
edœd	d
„Zedœdd„Z
edœd
d„Zedœdd„ZdS)ÚASTBaseBase)ÚotherrcCs\t|ƒt|ƒk	rdSy.x(|jjƒD]\}}|t||ƒkr"dSq"WWntk
rVdSXdS)NFT)ÚtypeÚ__dict__ÚitemsÚgetattrÚAttributeError)Úselfr!ÚkeyÚvaluerrrÚ__eq__TszASTBaseBase.__eq__N)rcCst|ƒS)N)r)r'rrrÚcloneaszASTBaseBase.clone)Ú	transformrcCstt|ƒƒ‚dS)N)ÚNotImplementedErrorÚrepr)r'r,rrrÚ
_stringifydszASTBaseBase._stringifycCs|jdd„ƒS)NcSst|ƒS)N)Ústr)ÚastrrrÚ<lambda>hsz%ASTBaseBase.__str__.<locals>.<lambda>)r/)r'rrrÚ__str__gszASTBaseBase.__str__cCs|jdd„ƒS)NcSs|jƒS)N)Úget_display_string)r1rrrr2ksz0ASTBaseBase.get_display_string.<locals>.<lambda>)r/)r'rrrr4jszASTBaseBase.get_display_stringcCsd|jjS)Nz<%s>)Ú	__class__r)r'rrrÚ__repr__mszASTBaseBase.__repr__)rrrrÚboolr*Ú__hash__rÚintr+ÚStringifyTransformr0r/r3r4r6rrrrr Ss
r c@seZdZeddœdd„ZdS)ÚASTAttributeN)ÚsignodercCstt|ƒƒ‚dS)N)r-r.)r'r<rrrÚdescribe_signaturevszASTAttribute.describe_signature)rrrrr=rrrrr;usr;c@s<eZdZeddœdd„Zeedœdd„Zeddœd	d
„ZdS)ÚASTCPPAttributeN)ÚargrcCs
||_dS)N)r?)r'r?rrrÚ__init__{szASTCPPAttribute.__init__)r,rcCsd|jdS)Nz[[z]])r?)r'r,rrrr/~szASTCPPAttribute._stringify)r<rcCs>|jtjddƒƒ|jtj|j|jƒƒ|jtjddƒƒdS)Nz[[z]])Úappendr
Zdesc_sig_punctuationrÚTextr?)r'r<rrrr=sz"ASTCPPAttribute.describe_signature)	rrrr0r@r:r/rr=rrrrr>zsr>c@s2eZdZeedddœdd„Zeedœdd„ZdS)	ÚASTGnuAttributeÚASTBaseParenExprListN)ÚnameÚargsrcCs||_||_dS)N)rErF)r'rErFrrrr@ˆszASTGnuAttribute.__init__)r,rcCs(|jg}|jr|j||jƒƒdj|ƒS)NÚ)rErFrAÚjoin)r'r,Úresrrrr/ŒszASTGnuAttribute._stringify)rrrr0rr@r:r/rrrrrC‡srCc@s@eZdZeeddœdd„Zeedœdd„Ze	ddœd	d
„Z
dS)ÚASTGnuAttributeListN)ÚattrsrcCs
||_dS)N)rK)r'rKrrrr@”szASTGnuAttributeList.__init__)r,rcCsNdg}d}x.|jD]$}|s$|jdƒd}|j||ƒƒqW|jdƒdj|ƒS)Nz__attribute__((Tz, Fz))rG)rKrArH)r'r,rIÚfirstÚattrrrrr/—s

zASTGnuAttributeList._stringify)r<rcCst|ƒ}|jtj||ƒƒdS)N)r0rArrB)r'r<Útxtrrrr=¢sz&ASTGnuAttributeList.describe_signature)rrrrrCr@r:r0r/rr=rrrrrJ“srJc@s@eZdZdZeddœdd„Zeedœdd„Zedd	œd
d„Z	dS)ÚASTIdAttributez*For simple attributes defined by the user.N)ÚidrcCs
||_dS)N)rP)r'rPrrrr@ªszASTIdAttribute.__init__)r,rcCs|jS)N)rP)r'r,rrrr/­szASTIdAttribute._stringify)r<rcCs|jtj|j|jƒƒdS)N)rArrBrP)r'r<rrrr=°sz!ASTIdAttribute.describe_signature)
rrrÚ__doc__r0r@r:r/rr=rrrrrO§srOc@sBeZdZdZeeddœdd„Zeedœdd„Zedd	œd
d„Z	dS)ÚASTParenAttributez)For paren attributes defined by the user.N)rPr?rcCs||_||_dS)N)rPr?)r'rPr?rrrr@·szASTParenAttribute.__init__)r,rcCs|jd|jdS)Nú(ú))rPr?)r'r,rrrr/»szASTParenAttribute._stringify)r<rcCst|ƒ}|jtj||ƒƒdS)N)r0rArrB)r'r<rNrrrr=¾sz$ASTParenAttribute.describe_signature)
rrrrQr0r@r:r/rr=rrrrrR´srRc@seZdZdS)rDN)rrrrrrrrDÅsrDc@seZdZdS)Ú$UnsupportedMultiCharacterCharLiteralN)rrrrrrrrUËsrUc@seZdZdS)ÚDefinitionErrorN)rrrrrrrrVÏsrVc@seZdZeeejeeefefdddœdd„Z	e
eeedœdd„Z
eed	œd
d„ƒZeddœd
d„Zeddœdd„Zeddœdd„Zeedœdd„Zeedœdd„Zeedœdd„Zed	œdd„Zeedœdd„Zeedœd d!„Zeed	œd"d#„ƒZeed	œd$d%„ƒZeed	œd&d'„ƒZed	œd(d)„Zd*d+œedd,œd-d.„Zed/d0„ƒZ ed1d2„ƒZ!e
eed3œd4d5„Z"e#e$d	œd6d7„Z%e&d	œd8d9„Z'dS):Ú
BaseParserrN)Ú
definitionÚlocationÚconfigrcCsD|jƒ|_||_||_d|_t|jƒ|_d|_d|_g|_	d|_
dS)NrT)rN)ÚstriprXrYrZÚposÚlenÚendÚ
last_matchÚ_previous_stateÚotherErrorsZallowFallbackExpressionParsing)r'rXrYrZrrrr@Ôs
zBaseParser.__init__)ÚerrorsÚheaderrcCsôt|ƒdkrHt|ƒdkr4t|dt|ddƒƒStt|ddƒƒS|dg}x”|D]Œ}t|dƒdkrÐd}|j|dƒ|jdƒxZt|dƒjdƒD]0}t|ƒdkr¬qš|j|ƒ|j|ƒ|jdƒqšWqV|jt|dƒƒqVWtdj|ƒƒS)NérÚ
z  z:
rG)r]rVr0rAÚsplitrH)r'rbrcÚresultÚeÚindentÚlinerrrÚ_make_multi_erroräs$



zBaseParser._make_multi_error)rcCst‚dS)N)r-)r'rrrÚlanguageúszBaseParser.language)ÚmsgrcCs&d|jd}td||j|fƒdS)Nú-ú^z%s
%s
%s)r\ÚprintrX)r'rmÚ	indicatorrrrÚstatusþszBaseParser.statuscCspg}d|jd}td|j||j|j|fƒ}|j|dfƒx|jD]}|j|dfƒqDWg|_|j|dƒ‚dS)Nrnroz2Invalid %s declaration: %s [error at %d]
  %s
  %sz
Main errorzPotential other errorrG)r\rVrlrXrArark)r'rmrbrqZexMainÚerrrrrÚfailszBaseParser.failcCstj||jddS)N)rY)ÚloggerÚwarningrY)r'rmrrrÚwarnszBaseParser.warn)ÚregexrcCs>|j|j|jƒ}|dk	r:|j|jf|_|jƒ|_||_dSdS)NTF)ÚmatchrXr\r_r`r^)r'rxryrrrrys
zBaseParser.match)ÚstringrcCs8t|ƒ}|j|j|j|…|kr4|j|7_dSdS)NTF)r]rXr\)r'rzZstrlenrrrÚskip_strings
zBaseParser.skip_string)ÚwordrcCs|jtjdtj|ƒƒƒS)Nz\b%s\b)ryÚreÚcompileÚescape)r'r|rrrÚ	skip_word"szBaseParser.skip_wordcCs
|jtƒS)N)ryÚ_whitespace_re)r'rrrÚskip_ws%szBaseParser.skip_wscCs|j|ƒr|jƒdSdS)NTF)r€r‚)r'r|rrrÚskip_word_and_ws(s
zBaseParser.skip_word_and_wscCs|j|ƒr|jƒdSdS)NTF)r{r‚)r'rzrrrÚskip_string_and_ws.s
zBaseParser.skip_string_and_wscCs|j|jkS)N)r\r^)r'rrrÚeof4szBaseParser.eofcCs&y|j|jStk
r dSXdS)NÚEOF)rXr\Ú
IndexError)r'rrrÚcurrent_char8szBaseParser.current_charcCs|jdk	r|jjƒSdSdS)N)r_Úgroup)r'rrrÚmatched_text?s

zBaseParser.matched_textcCs|j|jd…}|j|_|S)N)rXr\r^)r'ÚrvrrrÚ	read_restFszBaseParser.read_restF)ÚallowSemicolon)rrcCsH|jƒ|r4|jrD|j|jd…dkrD|jdƒn|jsD|jdƒdS)Nú;z Expected end of definition or ;.zExpected end of definition.)r‚r…rXr\rt)r'rrrrÚ
assert_endKszBaseParser.assert_endcCst‚dS)N)r-)r'rrrÚ
id_attributesVszBaseParser.id_attributescCst‚dS)N)r-)r'rrrÚparen_attributesZszBaseParser.paren_attributes)r^rcCsÊddddœ}|j}g}xŽ|js¤t|ƒdkr6|j|kr6P|j|jƒkrV|j||jƒn>t|ƒdkrz|j|d
krz|jƒn|jdkr”|jd|jƒ|jd7_qW|jrº|jd	|ƒ|j||j…S)NrTú]Ú})rSú[Ú{rrdz)]}z&Unexpected '%s' in balanced-token-seq.z8Could not find end of balanced-token-seq starting at %d.éÿÿÿÿ)	r\r…r]rˆÚkeysrAÚpoprtrX)r'r^ZbracketsÚstartPosÚsymbolsrrrÚ_parse_balanced_token_seq^s"

z$BaseParser._parse_balanced_token_seqcCsž|jƒ|j}|jdƒrh|jdƒs*||_n>|jdgd}|jdƒsL|jdƒ|jdƒs`|jdƒt|ƒS|jdƒr|jdƒsˆ|jdƒ|jdƒsœ|jd	ƒg}xR|jt	ƒrÊ|j
}|jƒ}|jt
||ƒƒ|jd
ƒrØq¢q¢|jdƒræPq¢|jdƒq¢W|jdƒs
|jd
ƒt|ƒSx$|jD]}|j|ƒrt|ƒSqWx`|jD]V}|j|ƒsTq@|jdƒsj|jdƒ|jdgd}|jdƒsŽ|jdƒt||ƒSWdS)Nr”r’)r^z!Expected ']' in end of attribute.z-Expected ']' in end of attribute after [[...]Z
__attribute__rSz#Expected '(' after '__attribute__'.z$Expected '(' after '__attribute__('.ú,rTz2Expected identifier, ')', or ',' in __attribute__.z(Expected ')' after '__attribute__((...)'z0Expected '(' after user-defined paren-attribute.z1Expected ')' to end user-defined paren-attribute.)r‚r\r„r{r›rtr>rƒryÚ
identifier_rerŠÚ_parse_paren_expression_listrArCrJrrOr‘rR)r'r™r?rKrEÚexprsrPrrrÚ_parse_attributersV















zBaseParser._parse_attributecCst‚dS)N)r-)r'rrrržªsz'BaseParser._parse_paren_expression_list)(rrrr0r
rÚNoder	r9r@rrrVrkÚpropertyrlrrrtrwrr7ryr{r€r‚rƒr„r…rˆrŠrŒrrr‘r›rr;r rDržrrrrrWÓs8	8rW)6rQr}ÚcopyrÚtypingrrrrrrr	r
ZdocutilsrZdocutils.nodesrZsphinxr
Z
sphinx.configrZsphinx.utilrÚ	getLoggerrrur0r:r~rZanon_identifier_rerZinteger_literal_reZoctal_literal_reZhex_literal_reZbinary_literal_reZintegers_literal_suffix_reZfloat_literal_reZfloat_literal_suffix_reZchar_literal_rerrrr r;r>rCrJrOrRrDrUrVrWrrrrÚ<module>sL(






	
"