o $a7@sdZddlZddlmZddlmZmZmZmZm Z m Z m Z m Z ddl mZddlmZddlmZddlmZeeZeegefZed Zed Zed Zed Zed ZedZ edZ!edZ"edZ#edZ$edZ%deddfddZ&Gddde'Z(GdddZ)Gddde)Z*Gddde*Z+Gd d!d!e)Z,Gd"d#d#e*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/Z3dS)0z sphinx.util.cfamily ~~~~~~~~~~~~~~~~~~~ Utility functions common to the C and C++ domains. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. Ndeepcopy)AnyCallableListMatchOptionalPatternTupleUnion)nodes) TextElement)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}) )) )' modereturncCs|dvr td|dS)N) lastIsName noneIsNamemarkTypemarkNameparamudlz!Description mode '%s' is invalid.) Exception)rr5/usr/lib/python3/dist-packages/sphinx/util/cfamily.pyverify_description_modePs rc@ eZdZdS) NoOldIdErrorN__name__ __module__ __qualname__rrrrrUsrc@s~eZdZUdedefddZdZegefe d<defddZ d e de fd d Z de fd d Zde fddZde fddZdS) ASTBaseBaseotherrcCsZt|t|ur dSz|jD]\}}|t||krWdSqWdSty,YdSw)NFT)type__dict__itemsgetattrAttributeError)selfr#keyvaluerrr__eq__[s zASTBaseBase.__eq__N__hash__cCt|SNrr)rrrclonehszASTBaseBase.clone transformcC tt|r/NotImplementedErrorreprr)r2rrr _stringifyk zASTBaseBase._stringifycC|ddS)NcSr.r/)strastrrroz%ASTBaseBase.__str__..r8r0rrr__str__nzASTBaseBase.__str__cCr:)NcSs|Sr/)get_display_stringr<rrrr>rr?z0ASTBaseBase.get_display_string..r@r0rrrrCqrBzASTBaseBase.get_display_stringcCs d|jjS)Nz<%s>) __class__rr0rrr__repr__tr9zASTBaseBase.__repr__)rr r!rboolr,r-rint__annotations__r1StringifyTransformr;r8rArCrErrrrr"Zs  r"c@seZdZdeddfddZdS) ASTAttributesignoderNcCr3r/r4r)rKrrrdescribe_signature}r9zASTAttribute.describe_signature)rr r!r rMrrrrrJ|srJc@sBeZdZdeddfddZdedefddZd eddfd d ZdS) ASTCPPAttributeargrNcC ||_dSr/rO)r)rOrrr__init__ zASTCPPAttribute.__init__r2cCsd|jdS)Nz[[z]]rQr7rrrr8rBzASTCPPAttribute._stringifyrKcCt|}|t||dSr/r;appendr Textr)rKtxtrrrrMz"ASTCPPAttribute.describe_signature) rr r!r;rRrIr8r rMrrrrrNsrNc@s8eZdZdededddfddZdedefd d ZdS) ASTGnuAttributenameargsASTBaseParenExprListrNcC||_||_dSr/)r\r])r)r\r]rrrrR zASTGnuAttribute.__init__r2cCs(|jg}|jr|||jd|S)N)r\r]rVjoin)r)r2resrrrr8s zASTGnuAttribute._stringify)rr r!r;rrRrIr8rrrrr[sr[c@sFeZdZdeeddfddZdedefddZd e ddfd d Z dS) ASTGnuAttributeListattrsrNcCrPr/)re)r)rerrrrRrSzASTGnuAttributeList.__init__r2cCsJdg}d}|jD]}|s|dd}|||q|dd|S)Nz__attribute__((Tz, Fz))ra)rerVrb)r)r2rcfirstattrrrrr8s    zASTGnuAttributeList._stringifyrKcCrTr/rUrXrrrrMrZz&ASTGnuAttributeList.describe_signature) rr r!rr[rRrIr;r8r rMrrrrrds rdc@sFeZdZdZdeddfddZdedefdd Zd eddfd d Z dS) ASTIdAttributez*For simple attributes defined by the user.idrNcCrPr/ri)r)rirrrrRrSzASTIdAttribute.__init__r2cCs|jSr/rjr7rrrr8szASTIdAttribute._stringifyrKcCs|t|j|jdSr/)rVr rWrirLrrrrMz!ASTIdAttribute.describe_signature rr r!__doc__r;rRrIr8r rMrrrrrhs rhc@sJeZdZdZdededdfddZdedefd d Zd eddfd d Z dS)ASTParenAttributez)For paren attributes defined by the user.rirOrNcCr_r/rirO)r)rirOrrrrRr`zASTParenAttribute.__init__r2cCs|jd|jdS)N()ror7rrrr8zASTParenAttribute._stringifyrKcCrTr/rUrXrrrrMrZz$ASTParenAttribute.describe_signaturerlrrrrrns rnc@r)r^Nrrrrrr^r^c@r)$UnsupportedMultiCharacterCharLiteralNrrrrrrtrsrtc@r)DefinitionErrorNrrrrrrursruc@seZdZdedeejeeefefddddfddZ d e e d ede fd d Z edefd dZdeddfddZdeddfddZdeddfddZdedefddZdedefddZdedefddZdefdd Zdedefd!d"Zdedefd#d$Zedefd%d&Zedefd'd(Zedefd)d*Zdefd+d,Zd-d.d/eddfd0d1Zed2d3Z ed4d5Z!d6e edefd7d8Z"de#e$fd9d:Z%de&fd;d<Z'dS)= BaseParser definitionlocationconfigrrNcCsD||_||_||_d|_t|j|_d|_d|_g|_ d|_ dS)Nr)rNT) striprwrxryposlenend last_match_previous_state otherErrorsallowFallbackExpressionParsing)r)rwrxryrrrrRs   zBaseParser.__init__errorsheadercCst|dkr$t|dkrt|dt|ddStt|ddS|dg}|D]D}t|ddkred}||d|dt|ddD]}t|dkrTqK|||||dqKq*|t|dq*td|S)Nr z z: ra)r|rur;rVsplitrb)r)rrresulteindentlinerrr_make_multi_errors&       zBaseParser._make_multi_errorcCtr/r5r0rrrlanguagezBaseParser.languagemsgcCs&d|jd}td||j|fdS)N-^z%s %s %s)r{printrw)r)r indicatorrrrstatusszBaseParser.statuscCshg}d|jd}td|j||j|j|f}||df|jD] }||dfq!g|_||d)Nrrz2Invalid %s declaration: %s [error at %d] %s %sz Main errorzPotential other errorra)r{rurrwrVrr)r)rrrexMainerrrrrfail s  zBaseParser.failcCstj||jddS)N)rx)loggerwarningrx)r)rrrrwarnrrzBaseParser.warnregexcCs>||j|j}|dur|j|jf|_||_||_dSdSNTF)matchrwr{r~rr})r)rrrrrrs zBaseParser.matchstringcCs8t|}|j|j|j||kr|j|7_dSdSr)r|rwr{)r)rstrlenrrr skip_string!s zBaseParser.skip_stringwordcCs|tdt|S)Nz\b%s\b)rrecompileescaper)rrrr skip_word(rkzBaseParser.skip_wordcCs |tSr/)r_whitespace_rer0rrrskip_ws+rSzBaseParser.skip_wscC||r |dSdSr)rrrrrrskip_word_and_ws. zBaseParser.skip_word_and_wscCrr)rr)r)rrrrskip_string_and_ws4rzBaseParser.skip_string_and_wscCs |j|jkSr/)r{r}r0rrreof:s zBaseParser.eofcCs$z|j|jWStyYdSw)NEOF)rwr{ IndexErrorr0rrr current_char>s  zBaseParser.current_charcCs|jdur |jSdSr/)r~groupr0rrr matched_textEs  zBaseParser.matched_textcCs|j|jd}|j|_|Sr/)rwr{r})r)rvrrr read_restLszBaseParser.read_restF)allowSemicolonrcCsT||r|js|j|jddkr|ddSdSdS|js(|ddSdS)N;z Expected end of definition or ;.zExpected end of definition.)rrrwr{r)r)rrrr assert_endQszBaseParser.assert_endcCrr/rr0rrr id_attributes\rzBaseParser.id_attributescCrr/rr0rrrparen_attributes`rzBaseParser.paren_attributesr}cCsdddd}|j}g}|jsSt|dkr|j|vrn9|j|vr*|||jnt|dkr<|j|dkr<|n |jdvrI|d|j|jd 7_|jr|jr]|d ||j||jS) Nrq]})rp[{rz)]}z&Unexpected '%s' in balanced-token-seq.rz8Could not find end of balanced-token-seq starting at %d.) r{rr|rkeysrVpoprrw)r)r}bracketsstartPossymbolsrrr_parse_balanced_token_seqds&    z$BaseParser._parse_balanced_token_seqcCs||j}|dr4|ds||_n|jdgd}|ds&|d|ds0|dt|S|dr|dsC|d|dsM|d g} |t rd|j }| }| t |||d rjqO|d rpn|d qP|d s|dt|S|jD] }||rt|Sq|jD])}||sq|ds|d|jd gd}|d s|dt||SdS)Nrr)r}z!Expected ']' in end of attribute.z-Expected ']' in end of attribute after [[...] __attribute__rpz#Expected '(' after '__attribute__'.z$Expected '(' after '__attribute__('.r,rqz2Expected identifier, ')', or ',' in __attribute__.z(Expected ')' after '__attribute__((...)'z0Expected '(' after user-defined paren-attribute.z1Expected ')' to end user-defined paren-attribute.)rr{rrrrrNrr identifier_rer_parse_paren_expression_listrVr[rdrrhrrn)r)rrOrer\exprsrirrr_parse_attributexsZ                         zBaseParser._parse_attributecCrr/rr0rrrrsz'BaseParser._parse_paren_expression_list)(rr r!r;r r Noder rGrRrrrurpropertyrrrrr rFrrrrrrrrrrrrrrrrJrr^rrrrrrvsF     8rv)4rmrcopyrtypingrrrrrr r r docutilsr docutils.nodesr sphinx.configr sphinx.utilr getLoggerrrr;rIrranon_identifier_rerinteger_literal_reoctal_literal_rehex_literal_rebinary_literal_reintegers_literal_suffix_refloat_literal_refloat_literal_suffix_rechar_literal_rerrrr"rJrNr[rdrhrnr^rtrurvrrrrsD (              "