var/opt/nydus/ops/pycparser/__pycache__/c_parser.cpython-38.pyc000064400000177225147205561540020576 0ustar00U af*"@sdddlmZddlmZddlmZddlmZmZm Z m Z ddl m Z m Z e GdddeZdS) )yacc)c_ast)CLexer) PLYParser ParseError parameterizedtemplate)fix_switch_casesfix_atomic_specifiersc@seZdZdedddddfddZd_dd Zd d Zd d ZddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zd`d"d#Zdad$d%Zd&d'Zd(d)Zd*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Z d?d@Z!dAdBZ"dCdDZ#dEdFZ$dGdHZ%dIdJZ&dKdLZ'dMdNZ(dOdPZ)dQdRZ*dSdTZ+dUdVZ,dWdXZ-dYdZZ.d[d\Z/d]d^Z0d_d`Z1dadbZ2dcddZ3dedfZ4dgdhZ5didjZ6dkdlZ7dmdnZ8dodpZ9dqdrZ:dsdtZ;dudvZd{d|Z?d}d~Z@ddZAddZBddZCddZDddZEddZFddZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWeXdddddZYeXdddddZZeXdddddZ[eXddddZ\eXdddddZ]eXdddddZ^eXdddddZ_eXdddddZ`ddZaddÄZbddńZcddDŽZdddɄZedd˄Zfdd̈́ZgddτZhddфZiddӄZjddՄZkddׄZlddلZmddۄZndd݄Zodd߄ZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}ddZ~ddZddZddZddZddZddZdd Zd d Zd d ZddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zd<d=Zd>d?Zd@dAZdBdCZdDdEZdFdGZdHdIZdJdKZdLdMZdNdOZdPdQZdRdSZdTdUZdVdWZdXdYZdZd[Zd\d]Zd^S(bCParserTzpycparser.lextabzpycparser.yacctabFc Cs||j|j|j|jd|_|jj|||d|jj|_ddddddd d d d d dddg}|D]} || qZtj|d||||d|_ t g|_ d|_ dS)a Create a new CParser. Some arguments for controlling the debug/optimization level of the parser are provided. The defaults are tuned for release/performance mode. The simple rules for using them are: *) When tweaking CParser/CLexer, set these to False *) When releasing a stable parser, set to True lex_optimize: Set to False when you're modifying the lexer. Otherwise, changes in the lexer won't be used, if some lextab.py file exists. When releasing with a stable lexer, set to True to save the re-generation of the lexer table on each run. lexer: Set this parameter to define the lexer to use if you're not using the default CLexer. lextab: Points to the lex table that's used for optimized mode. Only if you're modifying the lexer and want some tests to avoid re-generating the table, make this point to a local lex table file (that's been earlier generated with lex_optimize=True) yacc_optimize: Set to False when you're modifying the parser. Otherwise, changes in the parser won't be used, if some parsetab.py file exists. When releasing with a stable parser, set to True to save the re-generation of the parser table on each run. yacctab: Points to the yacc table that's used for optimized mode. Only if you're modifying the parser, make this point to a local yacc table file yacc_debug: Generate a parser.out file that explains how yacc built the parsing table from the grammar. taboutputdir: Set this parameter to control the location of generated lextab and yacctab files. )Z error_funcZon_lbrace_funcZon_rbrace_funcZtype_lookup_func)optimizelextab outputdirZabstract_declaratorZassignment_expressionZdeclaration_listZdeclaration_specifiers_no_typeZ designationZ expressionZidentifier_listZinit_declarator_listZid_init_declarator_listZinitializer_listZparameter_type_listZblock_item_listZtype_qualifier_listZstruct_declarator_listZtranslation_unit_or_empty)modulestartdebugr Z tabmodulerN) _lex_error_func_lex_on_lbrace_func_lex_on_rbrace_func_lex_type_lookup_funcclexbuildtokensZ_create_opt_rulercparserdict _scope_stack_last_yielded_token) selfZ lex_optimizelexerrZ yacc_optimizeZyacctabZ yacc_debugZ taboutputdirZrules_with_optZruler C/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/pycparser/c_parser.py__init__sN:   zCParser.__init__cCs6||j_|jtg|_d|_|jj||j|dS)a  Parses C code and returns an AST. text: A string containing the C source code filename: Name of the file being parsed (for meaningful error messages) debug: Debug flag to YACC N)inputrr)rfilenameZ reset_linenorrrrparse)rtextr$rr r r!r%s   z CParser.parsecCs|jtdSN)rappendrrr r r! _push_scopeszCParser._push_scopecCs t|jdkst|jdS)Nr)lenrAssertionErrorpopr)r r r! _pop_scopeszCParser._pop_scopecCs4|jd|ds"|d||d|jd|<dS)zC Add a new typedef name (ie a TYPEID) to the current scope Tz;Typedef %r previously declared as non-typedef in this scopeNrget _parse_errorrnamecoordr r r!_add_typedef_nameszCParser._add_typedef_namecCs4|jd|dr"|d||d|jd|<dS)ze Add a new object, function, or enum member name (ie an ID) to the current scope r/Fz;Non-typedef %r previously declared as typedef in this scopeNr0r3r r r!_add_identifierszCParser._add_identifiercCs.t|jD]}||}|dk r |Sq dS)z8 Is *name* a typedef-name in the current scope? NF)reversedrr1)rr4ZscopeZin_scoper r r!_is_type_in_scopes   zCParser._is_type_in_scopecCs|||||dSr')r2_coord)rmsglinecolumnr r r!rszCParser._lex_error_funccCs |dSr')r*r)r r r!rszCParser._lex_on_lbrace_funccCs |dSr')r.r)r r r!rszCParser._lex_on_rbrace_funccCs||}|S)z Looks up types that were previously defined with typedef. Passed to the lexer for recognizing identifiers that are types. )r9)rr4Zis_typer r r!rs zCParser._lex_type_lookup_funccCs|jjS)z We need access to yacc's lookahead token in certain cases. This is the last token yacc requested from the lexer, so we ask the lexer. )rZ last_tokenr)r r r!_get_yacc_lookahead_tokensz!CParser._get_yacc_lookahead_tokencCs\|}|}|jr|j}qt|tjr,||_|S|}t|jtjsF|j}q0|j|_||_|SdS)z Tacks a type modifier on a declarator, and returns the modified declarator. Note: the declarator and modifier may be modified N)type isinstancerTypeDecl)rdeclmodifierZ modifier_headZ modifier_tailZ decl_tailr r r!_type_modify_decls  zCParser._type_modify_declcCs|}t|tjs|j}q|j|_|jdd|_|D]:}t|tjs4t|dkr`| d|j q4||_|Sq4|st|jtj s| d|j tjdg|j d|_n tjdd|D|d j d|_|S) z- Fixes a declaration. Modifies decl. Nrz Invalid multiple types specifiedzMissing type in declarationintr5cSsg|]}|jD]}|qqSr )names).0idr4r r r! Ssz/CParser._fix_decl_name_type..) r@rrAr?declnamer4qualsIdentifierTyper+r2r5FuncDecl)rrBtypenamer?tnr r r!_fix_decl_name_type+s:      zCParser._fix_decl_name_typecCs>|ptgggggd}|r*|||n||d||S)a Declaration specifiers are represented by a dictionary with the entries: * qual: a list of type qualifiers * storage: a list of storage type qualifiers * type: a list of type specifiers * function: a list of function specifiers * alignment: a list of alignment specifiers This method is given a declaration specifier, and a new specifier of a given kind. If `append` is True, the new specifier is added to the end of the specifiers list, otherwise it's added at the beginning. Returns the declaration specifier, with the new specifier incorporated. )qualstorager?function alignmentrK)rr(insert)rZdeclspecZnewspeckindr(specr r r!_add_declaration_specifierWs z"CParser._add_declaration_specifierc Csbd|dk}g}|dddk r&n6|dddkrt|ddkstt|dd jd kst||dd jdsd }|dD]}t|d r|j}qq|d |tj|dd jddd|d|dd jd|dd<|dd =nrt |ddtj tj tj tj fs\|dd}t |tjs2|j}q|jdkr\|dd jd|_|dd =|D]} | ddk svt|rtjd|d|d| d| djd} nBtjd|d|d|d|d| d| d| d| djd } t | jtj tj tj tj fr | } n|| |d} |rH|r8|| j| jn|| j| jt| } || q`|S)z Builds a list of declarations all sharing the given specifiers. If typedef_namespace is true, each declared name is added to the "typedef namespace", which also includes objects, functions, and enum constants. typedefrTrKbitsizeNrBr?r/r?r5zInvalid declarationrVrLr?rMalignr5rS)r4rMrTr?r5rUinit r4rMr`rTZfuncspecr?rar\r5)r1r+rGr9hasattrr5r2rrAr@EnumStructUnionrNr?rLr,ZTypedefDeclrRr6r4r7r r() rrYdeclstypedef_namespaceZ is_typedefZ declarationsr5tZ decls_0_tailrB declarationZ fixed_declr r r!_build_declarationsps &           zCParser._build_declarationscCsLd|dkr|d|j|j|t|ddgddd}tj||||jd S) z' Builds a function definition. r[rTzInvalid typedefNrBraTrYrhrirK)rB param_declsbodyr5)r2r5rlrrZFuncDef)rrYrBrorprkr r r!_build_function_definitions  z"CParser._build_function_definitioncCs|dkrtjStjSdS)z` Given a token (either STRUCT or UNION), selects the appropriate AST class. structN)rrerf)rtokenr r r!_select_struct_union_classsz"CParser._select_struct_union_class) )leftZLOR)ruZLAND)ruOR)ruZXOR)ruAND)ruZEQZNE)ruGTZGELTZLE)ruZRSHIFTZLSHIFT)ruPLUSMINUS)ruZTIMESZDIVIDEZMODcCs2|ddkrtg|d<nt|d|d<dS)zh translation_unit_or_empty : translation_unit | empty rNrK)rZFileASTrpr r r!p_translation_unit_or_emptys z#CParser.p_translation_unit_or_emptycCs|d|d<dS)z4 translation_unit : external_declaration rrKNr r|r r r!p_translation_unit_1szCParser.p_translation_unit_1cCs"|d|d|d|d<dS)zE translation_unit : translation_unit external_declaration rr]rKN)extendr|r r r!p_translation_unit_2 szCParser.p_translation_unit_2cCs|dg|d<dS)z7 external_declaration : function_definition rrKNr r|r r r!p_external_declaration_1sz CParser.p_external_declaration_1cCs|d|d<dS)z/ external_declaration : declaration rrKNr r|r r r!p_external_declaration_2sz CParser.p_external_declaration_2cCs|dg|d<dS)zi external_declaration : pp_directive | pppragma_directive rrKNr r|r r r!p_external_declaration_3sz CParser.p_external_declaration_3cCs g|d<dS)z( external_declaration : SEMI rKNr r|r r r!p_external_declaration_4%sz CParser.p_external_declaration_4cCs|d|d<dS)z1 external_declaration : static_assert rrKNr r|r r r!p_external_declaration_5*sz CParser.p_external_declaration_5cCsVt|dkr.t|dd||dg|d<n$t|d|d||dg|d<dS)z static_assert : _STATIC_ASSERT LPAREN constant_expression COMMA unified_string_literal RPAREN | _STATIC_ASSERT LPAREN constant_expression RPAREN NrrK)r+rZ StaticAssert _token_coordr|r r r!p_static_assert_declaration/s "z#CParser.p_static_assert_declarationcCs|d||ddS)z pp_directive : PPHASH zDirectives not supported yetrN)r2rr|r r r!p_pp_directive8s zCParser.p_pp_directivecCspt|dkr*t|d||d|d<nBt|dkrTt|d||d|d<ntd||d|d<dS)z pppragma_directive : PPPRAGMA | PPPRAGMA PPPRAGMASTR | _PRAGMA LPAREN unified_string_literal RPAREN rrr]rKr rN)r+rZPragmarr|r r r!p_pppragma_directiveCs   zCParser.p_pppragma_directivecCs0t|dkr|dgn|d|dg|d<dS)z pppragma_directive_list : pppragma_directive | pppragma_directive_list pppragma_directive r]rrKNr+r|r r r!p_pppragma_directive_listOsz!CParser.p_pppragma_directive_listc CsNtgggtjdg||ddggd}|j||d|d|dd|d<d S) zU function_definition : id_declarator declaration_list_opt compound_statement rErrFrSrVrTr?rUr]rrYrBrorprKN)rrrNrrqrr}rYr r r!p_function_definition_1Ws zCParser.p_function_definition_1cCs.|d}|j||d|d|dd|d<dS)zl function_definition : declaration_specifiers id_declarator declaration_list_opt compound_statement rr]rrrKN)rqrr r r!p_function_definition_2iszCParser.p_function_definition_2cCs|d|d<dS)a_ statement : labeled_statement | expression_statement | compound_statement | selection_statement | iteration_statement | jump_statement | pppragma_directive | static_assert rrKNr r|r r r! p_statementxs zCParser.p_statementcCsFt|dkr6tj|d|dg||dd|d<n |d|d<dS)z} pragmacomp_or_statement : pppragma_directive_list statement | statement rrr]Z block_itemsr5rKN)r+rCompoundrr|r r r!p_pragmacomp_or_statements   z!CParser.p_pragmacomp_or_statementc Cs|d}|ddkr|d}tjtjtjf}t|dkrt|d|rtjd|d|d|d|d |ddd|djd g}q|j|t ddd gd d }n|j||dd d }||d<dS)z decl_body : declaration_specifiers init_declarator_list_opt | declaration_specifiers_no_type id_init_declarator_list_opt rr]Nr?rKrSrVrTrUrbrmTrn) rrerfrdr+r@rgr5rlr)rr}rYtyZs_u_or_erhr r r! p_decl_bodys6   zCParser.p_decl_bodycCs|d|d<dS)z& declaration : decl_body SEMI rrKNr r|r r r! p_declarationszCParser.p_declarationcCs,t|dkr|dn|d|d|d<dS)zj declaration_list : declaration | declaration_list declaration r]rrKNrr|r r r!p_declaration_list szCParser.p_declaration_listcCs||d|dd|d<dS)z] declaration_specifiers_no_type : type_qualifier declaration_specifiers_no_type_opt r]rrSrKNrZr|r r r!"p_declaration_specifiers_no_type_1sz*CParser.p_declaration_specifiers_no_type_1cCs||d|dd|d<dS)zf declaration_specifiers_no_type : storage_class_specifier declaration_specifiers_no_type_opt r]rrTrKNrr|r r r!"p_declaration_specifiers_no_type_2sz*CParser.p_declaration_specifiers_no_type_2cCs||d|dd|d<dS)za declaration_specifiers_no_type : function_specifier declaration_specifiers_no_type_opt r]rrUrKNrr|r r r!"p_declaration_specifiers_no_type_3sz*CParser.p_declaration_specifiers_no_type_3cCs||d|dd|d<dS)z_ declaration_specifiers_no_type : atomic_specifier declaration_specifiers_no_type_opt r]rr?rKNrr|r r r!"p_declaration_specifiers_no_type_4%sz*CParser.p_declaration_specifiers_no_type_4cCs||d|dd|d<dS)zb declaration_specifiers_no_type : alignment_specifier declaration_specifiers_no_type_opt r]rrVrKNrr|r r r!"p_declaration_specifiers_no_type_5*sz*CParser.p_declaration_specifiers_no_type_5cCs"|j|d|dddd|d<dS)zI declaration_specifiers : declaration_specifiers type_qualifier rr]rSTr(rKNrr|r r r!p_declaration_specifiers_1/sz"CParser.p_declaration_specifiers_1cCs"|j|d|dddd|d<dS)zR declaration_specifiers : declaration_specifiers storage_class_specifier rr]rTTrrKNrr|r r r!p_declaration_specifiers_24sz"CParser.p_declaration_specifiers_2cCs"|j|d|dddd|d<dS)zM declaration_specifiers : declaration_specifiers function_specifier rr]rUTrrKNrr|r r r!p_declaration_specifiers_39sz"CParser.p_declaration_specifiers_3cCs"|j|d|dddd|d<dS)zS declaration_specifiers : declaration_specifiers type_specifier_no_typeid rr]r?TrrKNrr|r r r!p_declaration_specifiers_4>sz"CParser.p_declaration_specifiers_4cCs|d|dd|d<dS)z2 declaration_specifiers : type_specifier Nrr?rKrr|r r r!p_declaration_specifiers_5Csz"CParser.p_declaration_specifiers_5cCs"|j|d|dddd|d<dS)zQ declaration_specifiers : declaration_specifiers_no_type type_specifier rr]r?TrrKNrr|r r r!p_declaration_specifiers_6Hsz"CParser.p_declaration_specifiers_6cCs"|j|d|dddd|d<dS)zN declaration_specifiers : declaration_specifiers alignment_specifier rr]rVTrrKNrr|r r r!p_declaration_specifiers_7Msz"CParser.p_declaration_specifiers_7cCs|d|d<dS)a storage_class_specifier : AUTO | REGISTER | STATIC | EXTERN | TYPEDEF | _THREAD_LOCAL rrKNr r|r r r!p_storage_class_specifierRsz!CParser.p_storage_class_specifiercCs|d|d<dS)zR function_specifier : INLINE | _NORETURN rrKNr r|r r r!p_function_specifier\szCParser.p_function_specifiercCs$tj|dg||dd|d<dS)a+ type_specifier_no_typeid : VOID | _BOOL | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | _COMPLEX | SIGNED | UNSIGNED | __INT128 rrFrKNrrNrr|r r r!p_type_specifier_no_typeidbsz"CParser.p_type_specifier_no_typeidcCs|d|d<dS)z type_specifier : typedef_name | enum_specifier | struct_or_union_specifier | type_specifier_no_typeid | atomic_specifier rrKNr r|r r r!p_type_specifierrszCParser.p_type_specifiercCs |d}|jd||d<dS)z= atomic_specifier : _ATOMIC LPAREN type_name RPAREN rZ_AtomicrKN)rMr()rr}typr r r!p_atomic_specifier|s zCParser.p_atomic_specifiercCs|d|d<dS)z type_qualifier : CONST | RESTRICT | VOLATILE | _ATOMIC rrKNr r|r r r!p_type_qualifierszCParser.p_type_qualifiercCs0t|dkr|d|dgn|dg|d<dS)z init_declarator_list : init_declarator | init_declarator_list COMMA init_declarator rrrrKNrr|r r r!p_init_declarator_listszCParser.p_init_declarator_listcCs,t|dt|dkr|dndd|d<dS)zb init_declarator : declarator | declarator EQUALS initializer rr]rNrmrKrr+r|r r r!p_init_declaratorszCParser.p_init_declaratorcCs0t|dkr|d|dgn|dg|d<dS)z id_init_declarator_list : id_init_declarator | id_init_declarator_list COMMA init_declarator rrrrKNrr|r r r!p_id_init_declarator_listsz!CParser.p_id_init_declarator_listcCs,t|dt|dkr|dndd|d<dS)zn id_init_declarator : id_declarator | id_declarator EQUALS initializer rr]rNrmrKrr|r r r!p_id_init_declaratorszCParser.p_id_init_declaratorcCs"|j|d|dddd|d<dS)zY specifier_qualifier_list : specifier_qualifier_list type_specifier_no_typeid rr]r?TrrKNrr|r r r!p_specifier_qualifier_list_1sz$CParser.p_specifier_qualifier_list_1cCs"|j|d|dddd|d<dS)zO specifier_qualifier_list : specifier_qualifier_list type_qualifier rr]rSTrrKNrr|r r r!p_specifier_qualifier_list_2sz$CParser.p_specifier_qualifier_list_2cCs|d|dd|d<dS)z4 specifier_qualifier_list : type_specifier Nrr?rKrr|r r r!p_specifier_qualifier_list_3sz$CParser.p_specifier_qualifier_list_3cCs$t|dgg|dggd|d<dS)zH specifier_qualifier_list : type_qualifier_list type_specifier rr]rrKNrr|r r r!p_specifier_qualifier_list_4sz$CParser.p_specifier_qualifier_list_4cCs tg|dggggd|d<dS)z9 specifier_qualifier_list : alignment_specifier rrrKNrr|r r r!p_specifier_qualifier_list_5sz$CParser.p_specifier_qualifier_list_5cCs||d|dd|d<dS)zR specifier_qualifier_list : specifier_qualifier_list alignment_specifier rr]rVrKNrr|r r r!p_specifier_qualifier_list_6sz$CParser.p_specifier_qualifier_list_6cCs0||d}||dd||dd|d<dS)z{ struct_or_union_specifier : struct_or_union ID | struct_or_union TYPEID rr]Nr4rhr5rK)rtrrr}klassr r r!p_struct_or_union_specifier_1s  z%CParser.p_struct_or_union_specifier_1cCsX||d}t|dkr6|dg||dd|d<n|d|d||dd|d<dS)z struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close | struct_or_union brace_open brace_close rrNr]rrKrrtr+rrr r r!p_struct_or_union_specifier_2s   z%CParser.p_struct_or_union_specifier_2cCs`||d}t|dkr:||dg||dd|d<n"||d|d||dd|d<dS)a struct_or_union_specifier : struct_or_union ID brace_open struct_declaration_list brace_close | struct_or_union ID brace_open brace_close | struct_or_union TYPEID brace_open struct_declaration_list brace_close | struct_or_union TYPEID brace_open brace_close rrr]rrKrNrrr r r!p_struct_or_union_specifier_3s   z%CParser.p_struct_or_union_specifier_3cCs|d|d<dS)zF struct_or_union : STRUCT | UNION rrKNr r|r r r!p_struct_or_unionszCParser.p_struct_or_unioncCs:t|dkr|dpg|d<n|d|dp.g|d<dS)z struct_declaration_list : struct_declaration | struct_declaration_list struct_declaration r]rrKNrr|r r r!p_struct_declaration_lists z!CParser.p_struct_declaration_listcCs|d}d|dkst|ddk r8|j||dd}nht|ddkr|dd}t|tjrf|}n t|}|j|t|d gd}n|j|tddd gd}||d<dS) zW struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI rr[rTr]NrYrhr?rKrBrm)r,rlr+r@rNoderNr)rr}rYrhnodeZ decl_typer r r!p_struct_declaration_1 s*       zCParser.p_struct_declaration_1cCs d|d<dS)z# struct_declaration : SEMI NrKr r|r r r!p_struct_declaration_20szCParser.p_struct_declaration_2cCs|dg|d<dS)z1 struct_declaration : pppragma_directive rrKNr r|r r r!p_struct_declaration_35szCParser.p_struct_declaration_3cCs0t|dkr|d|dgn|dg|d<dS)z struct_declarator_list : struct_declarator | struct_declarator_list COMMA struct_declarator rrrrKNrr|r r r!p_struct_declarator_list:sz CParser.p_struct_declarator_listcCs|ddd|d<dS)z( struct_declarator : declarator rNrBr\rKr r|r r r!p_struct_declarator_1CszCParser.p_struct_declarator_1cCsFt|dkr$|d|dd|d<ntdddd|dd|d<dS)z struct_declarator : declarator COLON constant_expression | COLON constant_expression rrrrKNr])r+rrAr|r r r!p_struct_declarator_2Hs zCParser.p_struct_declarator_2cCs"t|dd||d|d<dS)zM enum_specifier : ENUM ID | ENUM TYPEID r]NrrKrrdrr|r r r!p_enum_specifier_1QszCParser.p_enum_specifier_1cCs"td|d||d|d<dS)zG enum_specifier : ENUM brace_open enumerator_list brace_close NrrrKrr|r r r!p_enum_specifier_2WszCParser.p_enum_specifier_2cCs&t|d|d||d|d<dS)z enum_specifier : ENUM ID brace_open enumerator_list brace_close | ENUM TYPEID brace_open enumerator_list brace_close r]rrrKNrr|r r r!p_enum_specifier_3\szCParser.p_enum_specifier_3cCsht|dkr*t|dg|dj|d<n:t|dkrD|d|d<n |dj|d|d|d<dS)z enumerator_list : enumerator | enumerator_list COMMA | enumerator_list COMMA enumerator r]rrKrN)r+rZEnumeratorListr5Z enumeratorsr(r|r r r!p_enumerator_listbs   zCParser.p_enumerator_listcCs t|d||d|d<dS)z alignment_specifier : _ALIGNAS LPAREN type_name RPAREN | _ALIGNAS LPAREN constant_expression RPAREN rrrKN)rZAlignasrr|r r r!p_alignment_specifieroszCParser.p_alignment_specifiercCsbt|dkr(t|dd||d}nt|d|d||d}||j|j||d<dS)zR enumerator : ID | ID EQUALS constant_expression r]rNrrK)r+rZ Enumeratorrr7r4r5)rr}Z enumeratorr r r! p_enumeratorus   zCParser.p_enumeratorcCs|d|d<dS)zQ declarator : id_declarator | typeid_declarator rrKNr r|r r r! p_declaratorszCParser.p_declarator)rIID)ZtypeidTYPEID)Ztypeid_noparenrcCs|d|d<dS)z1 xxx_declarator : direct_xxx_declarator rrKNr r|r r r!p_xxx_declarator_1szCParser.p_xxx_declarator_1cCs||d|d|d<dS)z9 xxx_declarator : pointer direct_xxx_declarator r]rrKNrDr|r r r!p_xxx_declarator_2szCParser.p_xxx_declarator_2c Cs(tj|dddd||dd|d<dS)z' direct_xxx_declarator : yyy rNr_rK)rrArr|r r r!p_direct_xxx_declarator_1s z!CParser.p_direct_xxx_declarator_1cCs|d|d<dS)z@ direct_xxx_declarator : LPAREN xxx_declarator RPAREN r]rKNr r|r r r!p_direct_xxx_declarator_2sz!CParser.p_direct_xxx_declarator_2cCsft|dkr|dngpg}tjdt|dkr6|dn|d||djd}|j|d|d|d<dS) z} direct_xxx_declarator : direct_xxx_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET rrNrrr?Zdim dim_qualsr5rBrCrK)r+r ArrayDeclr5rD)rr}rMarrr r r!p_direct_xxx_declarator_3sz!CParser.p_direct_xxx_declarator_3cCs^dd|d|dfD}dd|D}tjd|d||djd }|j|d|d |d <dS) z direct_xxx_declarator : direct_xxx_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET | direct_xxx_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET cSs g|]}t|tr|n|gqSr r@list)rHitemr r r!rJsz5CParser.p_direct_xxx_declarator_4..rrcSs"g|]}|D]}|dk r |q qSr'r )rHZsublistrSr r r!rJs NrrrrrKrrr5rD)rr}Z listed_qualsrrr r r!p_direct_xxx_declarator_4sz!CParser.p_direct_xxx_declarator_4c CsZtjdt|d||d|ddk r0|dng|djd}|j|d|d|d<dS)zi direct_xxx_declarator : direct_xxx_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET NrrrrrrKrrrrr5rDrr}rr r r!p_direct_xxx_declarator_5sz!CParser.p_direct_xxx_declarator_5cCsztj|dd|djd}|jdkr`|jdk r`|jjD]$}t|tjrNq`| |j |jq:|j |d|d|d<dS)z direct_xxx_declarator : direct_xxx_declarator LPAREN parameter_type_list RPAREN | direct_xxx_declarator LPAREN identifier_list_opt RPAREN rNrargsr?r5LBRACErrK) rrOr5r>r?rparamsr@ EllipsisParamr7r4rD)rr}funcparamr r r!p_direct_xxx_declarator_6s   z!CParser.p_direct_xxx_declarator_6cCsj||d}tj|dpgd|d}t|dkr^|d}|jdk rJ|j}q8||_|d|d<n||d<dS)zm pointer : TIMES type_qualifier_list_opt | TIMES type_qualifier_list_opt pointer rr]N)rMr?r5rrK)rrZPtrDeclr+r?)rr}r5Z nested_typeZ tail_typer r r! p_pointers   zCParser.p_pointercCs0t|dkr|dgn|d|dg|d<dS)zs type_qualifier_list : type_qualifier | type_qualifier_list type_qualifier r]rrKNrr|r r r!p_type_qualifier_listszCParser.p_type_qualifier_listcCs:t|dkr*|djt||d|d|d<dS)zn parameter_type_list : parameter_list | parameter_list COMMA ELLIPSIS r]rrrKN)r+rr(rrrr|r r r!p_parameter_type_lists zCParser.p_parameter_type_listcCsNt|dkr*t|dg|dj|d<n |dj|d|d|d<dS)zz parameter_list : parameter_declaration | parameter_list COMMA parameter_declaration r]rrKrNr+rZ ParamListr5rr(r|r r r!p_parameter_list#s zCParser.p_parameter_listcCsT|d}|ds.tjdg||ddg|d<|j|t|ddgdd|d<d S) z parameter_declaration : declaration_specifiers id_declarator | declaration_specifiers typeid_noparen_declarator rr?rErFr]rrrKN)rrNrrlrrr r r!p_parameter_declaration_17s z!CParser.p_parameter_declaration_1c Cs|d}|ds.tjdg||ddg|d<t|ddkrt|ddjdkr||ddjdr|j|t|ddd gd d}nHtjd |d d|dpt dddd||dd }|d}| ||}||d<dS)zR parameter_declaration : declaration_specifiers abstract_declarator_opt rr?rErFr/rKr]Nrmrr rSr4rMr`r?r5) rrNrr+rGr9rlrTypenamerArR)rr}rYrBrPr r r!p_parameter_declaration_2Cs0 &  z!CParser.p_parameter_declaration_2cCsNt|dkr*t|dg|dj|d<n |dj|d|d|d<dS)ze identifier_list : identifier | identifier_list COMMA identifier r]rrKrNrr|r r r!p_identifier_listcs zCParser.p_identifier_listcCs|d|d<dS)z- initializer : assignment_expression rrKNr r|r r r!p_initializer_1mszCParser.p_initializer_1cCs6|ddkr&tg||d|d<n |d|d<dS)z initializer : brace_open initializer_list_opt brace_close | brace_open initializer_list COMMA brace_close r]NrrK)rInitListrr|r r r!p_initializer_2rs zCParser.p_initializer_2cCst|dkrN|ddkr |dnt|d|d}t|g|dj|d<nD|ddkrb|dnt|d|d}|dj||d|d<dS)z initializer_list : designation_opt initializer | initializer_list COMMA designation_opt initializer rrNr]rKr)r+rZNamedInitializerrr5exprsr()rr}rar r r!p_initializer_list{s  ((zCParser.p_initializer_listcCs|d|d<dS)z. designation : designator_list EQUALS rrKNr r|r r r! p_designationszCParser.p_designationcCs0t|dkr|dgn|d|dg|d<dS)z_ designator_list : designator | designator_list designator r]rrKNrr|r r r!p_designator_listszCParser.p_designator_listcCs|d|d<dS)zi designator : LBRACKET constant_expression RBRACKET | PERIOD identifier r]rKNr r|r r r! p_designatorszCParser.p_designatorc Cs\tjd|ddddd|dp0tdddd||dd}|||dd|d<dS) zH type_name : specifier_qualifier_list abstract_declarator_opt r rrSNr]rr?rK)rrrArrR)rr}rPr r r! p_type_names zCParser.p_type_namecCs*tdddd}|j||dd|d<dS)z+ abstract_declarator : pointer NrrrK)rrArD)rr}Z dummytyper r r!p_abstract_declarator_1s zCParser.p_abstract_declarator_1cCs||d|d|d<dS)zF abstract_declarator : pointer direct_abstract_declarator r]rrKNrr|r r r!p_abstract_declarator_2szCParser.p_abstract_declarator_2cCs|d|d<dS)z> abstract_declarator : direct_abstract_declarator rrKNr r|r r r!p_abstract_declarator_3szCParser.p_abstract_declarator_3cCs|d|d<dS)zA direct_abstract_declarator : LPAREN abstract_declarator RPAREN r]rKNr r|r r r!p_direct_abstract_declarator_1sz&CParser.p_direct_abstract_declarator_1cCs6tjd|dg|djd}|j|d|d|d<dS)zn direct_abstract_declarator : direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET NrrrrrKrrr r r!p_direct_abstract_declarator_2sz&CParser.p_direct_abstract_declarator_2cCsbt|dkr|dngpg}tjtddddt|dkrB|dn|d|||dd|d<dS)zk direct_abstract_declarator : LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET rr]NrrrrK)r+rrrAr)rr}rMr r r!p_direct_abstract_declarator_3s z&CParser.p_direct_abstract_declarator_3c CsFtjdt|d||dg|djd}|j|d|d|d<dS)zZ direct_abstract_declarator : direct_abstract_declarator LBRACKET TIMES RBRACKET NrrrrrKrrr r r!p_direct_abstract_declarator_4sz&CParser.p_direct_abstract_declarator_4c CsBtjtddddt|d||dg||dd|d<dS)z? direct_abstract_declarator : LBRACKET TIMES RBRACKET NrrrrK)rrrArrr|r r r!p_direct_abstract_declarator_5s  z&CParser.p_direct_abstract_declarator_5cCs4tj|dd|djd}|j|d|d|d<dS)zh direct_abstract_declarator : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN rNrrrrK)rrOr5rD)rr}rr r r!p_direct_abstract_declarator_6s z&CParser.p_direct_abstract_declarator_6cCs0tj|dtdddd||dd|d<dS)zM direct_abstract_declarator : LPAREN parameter_type_list_opt RPAREN r]NrrrK)rrOrArr|r r r!p_direct_abstract_declarator_7s  z&CParser.p_direct_abstract_declarator_7cCs(t|dtr|dn|dg|d<dS)zG block_item : declaration | statement rrKNrr|r r r! p_block_itemszCParser.p_block_itemcCs:t|dks|ddgkr"|dn|d|d|d<dS)z_ block_item_list : block_item | block_item_list block_item r]NrrKrr|r r r!p_block_item_listszCParser.p_block_item_listcCs"tj|d||dd|d<dS)zA compound_statement : brace_open block_item_list_opt brace_close r]rrrKN)rrrr|r r r!p_compound_statement_1s zCParser.p_compound_statement_1cCs&t|d|d||d|d<dS)z6 labeled_statement : ID COLON pragmacomp_or_statement rrrKN)rZLabelrr|r r r!p_labeled_statement_1szCParser.p_labeled_statement_1cCs(t|d|dg||d|d<dS)zL labeled_statement : CASE constant_expression COLON pragmacomp_or_statement r]rrrKN)rZCaserr|r r r!p_labeled_statement_2szCParser.p_labeled_statement_2cCs"t|dg||d|d<dS)z; labeled_statement : DEFAULT COLON pragmacomp_or_statement rrrKN)rZDefaultrr|r r r!p_labeled_statement_3szCParser.p_labeled_statement_3c Cs(t|d|dd||d|d<dS)zK selection_statement : IF LPAREN expression RPAREN pragmacomp_or_statement rrNrrKrIfrr|r r r!p_selection_statement_1!szCParser.p_selection_statement_1c Cs,t|d|d|d||d|d<dS)zZ selection_statement : IF LPAREN expression RPAREN statement ELSE pragmacomp_or_statement rrrrKNrr|r r r!p_selection_statement_2%szCParser.p_selection_statement_2c Cs*tt|d|d||d|d<dS)zO selection_statement : SWITCH LPAREN expression RPAREN pragmacomp_or_statement rrrrKN)r rZSwitchrr|r r r!p_selection_statement_3)szCParser.p_selection_statement_3cCs&t|d|d||d|d<dS)zN iteration_statement : WHILE LPAREN expression RPAREN pragmacomp_or_statement rrrrKN)rWhilerr|r r r!p_iteration_statement_1.szCParser.p_iteration_statement_1cCs&t|d|d||d|d<dS)zV iteration_statement : DO pragmacomp_or_statement WHILE LPAREN expression RPAREN SEMI rr]rrKN)rZDoWhilerr|r r r!p_iteration_statement_22szCParser.p_iteration_statement_2c Cs2t|d|d|d|d||d|d<dS)zx iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement rrr rrKN)rForrr|r r r!p_iteration_statement_36szCParser.p_iteration_statement_3c CsBtt|d||d|d|d|d||d|d<dS)zp iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement rrrrKN)rr%ZDeclListrr|r r r!p_iteration_statement_4:s  zCParser.p_iteration_statement_4cCs t|d||d|d<dS)z jump_statement : GOTO ID SEMI r]rrKN)rZGotorr|r r r!p_jump_statement_1?szCParser.p_jump_statement_1cCst||d|d<dS)z jump_statement : BREAK SEMI rrKN)rBreakrr|r r r!p_jump_statement_2CszCParser.p_jump_statement_2cCst||d|d<dS)z! jump_statement : CONTINUE SEMI rrKN)rContinuerr|r r r!p_jump_statement_3GszCParser.p_jump_statement_3cCs0tt|dkr|dnd||d|d<dS)z\ jump_statement : RETURN expression SEMI | RETURN SEMI rr]NrrK)rReturnr+rr|r r r!p_jump_statement_4KszCParser.p_jump_statement_4cCs4|ddkr$t||d|d<n |d|d<dS)z, expression_statement : expression_opt SEMI rNr]rK)rZEmptyStatementrr|r r r!p_expression_statementQs zCParser.p_expression_statementcCsjt|dkr|d|d<nLt|dtjsFt|dg|dj|d<|dj|d|d|d<dS)zn expression : assignment_expression | expression COMMA assignment_expression r]rrKrN)r+r@rExprListr5rr(r|r r r! p_expressionXs  zCParser.p_expressioncCs|d|d<dS)z: assignment_expression : LPAREN compound_statement RPAREN r]rKNr r|r r r!#p_parenthesized_compound_expressionesz+CParser.p_parenthesized_compound_expressioncCs$tj|dg||dd|d<dS)z typedef_name : TYPEID rrFrKNrr|r r r!p_typedef_nameiszCParser.p_typedef_namecCsDt|dkr|d|d<n&t|d|d|d|dj|d<dS)z assignment_expression : conditional_expression | unary_expression assignment_operator assignment_expression r]rrKrN)r+rZ Assignmentr5r|r r r!p_assignment_expressionms zCParser.p_assignment_expressioncCs|d|d<dS)a assignment_operator : EQUALS | XOREQUAL | TIMESEQUAL | DIVEQUAL | MODEQUAL | PLUSEQUAL | MINUSEQUAL | LSHIFTEQUAL | RSHIFTEQUAL | ANDEQUAL | OREQUAL rrKNr r|r r r!p_assignment_operator{s zCParser.p_assignment_operatorcCs|d|d<dS)z. constant_expression : conditional_expression rrKNr r|r r r!p_constant_expressionszCParser.p_constant_expressioncCsDt|dkr|d|d<n&t|d|d|d|dj|d<dS)z conditional_expression : binary_expression | binary_expression CONDOP expression COLON conditional_expression r]rrKrrN)r+rZ TernaryOpr5r|r r r!p_conditional_expressions z CParser.p_conditional_expressioncCsDt|dkr|d|d<n&t|d|d|d|dj|d<dS)ak binary_expression : cast_expression | binary_expression TIMES binary_expression | binary_expression DIVIDE binary_expression | binary_expression MOD binary_expression | binary_expression PLUS binary_expression | binary_expression MINUS binary_expression | binary_expression RSHIFT binary_expression | binary_expression LSHIFT binary_expression | binary_expression LT binary_expression | binary_expression LE binary_expression | binary_expression GE binary_expression | binary_expression GT binary_expression | binary_expression EQ binary_expression | binary_expression NE binary_expression | binary_expression AND binary_expression | binary_expression OR binary_expression | binary_expression XOR binary_expression | binary_expression LAND binary_expression | binary_expression LOR binary_expression r]rrKrN)r+rZBinaryOpr5r|r r r!p_binary_expressions zCParser.p_binary_expressioncCs|d|d<dS)z$ cast_expression : unary_expression rrKNr r|r r r!p_cast_expression_1szCParser.p_cast_expression_1cCs&t|d|d||d|d<dS)z; cast_expression : LPAREN type_name RPAREN cast_expression r]rrrKN)rZCastrr|r r r!p_cast_expression_2szCParser.p_cast_expression_2cCs|d|d<dS)z* unary_expression : postfix_expression rrKNr r|r r r!p_unary_expression_1szCParser.p_unary_expression_1cCs$t|d|d|dj|d<dS)z unary_expression : PLUSPLUS unary_expression | MINUSMINUS unary_expression | unary_operator cast_expression rr]rKNrUnaryOpr5r|r r r!p_unary_expression_2szCParser.p_unary_expression_2cCs:t|dt|dkr|dn|d||d|d<dS)z unary_expression : SIZEOF unary_expression | SIZEOF LPAREN type_name RPAREN | _ALIGNOF LPAREN type_name RPAREN rrr]rKN)rr?r+rr|r r r!p_unary_expression_3s  zCParser.p_unary_expression_3cCs|d|d<dS)z unary_operator : AND | TIMES | PLUS | MINUS | NOT | LNOT rrKNr r|r r r!p_unary_operatorszCParser.p_unary_operatorcCs|d|d<dS)z* postfix_expression : primary_expression rrKNr r|r r r!p_postfix_expression_1szCParser.p_postfix_expression_1cCs$t|d|d|dj|d<dS)zG postfix_expression : postfix_expression LBRACKET expression RBRACKET rrrKN)rArrayRefr5r|r r r!p_postfix_expression_2szCParser.p_postfix_expression_2cCs4t|dt|dkr|dnd|dj|d<dS)z postfix_expression : postfix_expression LPAREN argument_expression_list RPAREN | postfix_expression LPAREN RPAREN rrrNrK)rFuncCallr+r5r|r r r!p_postfix_expression_3szCParser.p_postfix_expression_3cCs>t|d||d}t|d|d||dj|d<dS)z postfix_expression : postfix_expression PERIOD ID | postfix_expression PERIOD TYPEID | postfix_expression ARROW ID | postfix_expression ARROW TYPEID rrr]rKN)rrr StructRefr5)rr}fieldr r r!p_postfix_expression_4szCParser.p_postfix_expression_4cCs(td|d|d|dj|d<dS)z{ postfix_expression : postfix_expression PLUSPLUS | postfix_expression MINUSMINUS r}r]rrKNr>r|r r r!p_postfix_expression_5szCParser.p_postfix_expression_5cCst|d|d|d<dS)z postfix_expression : LPAREN type_name RPAREN brace_open initializer_list brace_close | LPAREN type_name RPAREN brace_open initializer_list COMMA brace_close r]rrKN)rZCompoundLiteralr|r r r!p_postfix_expression_6szCParser.p_postfix_expression_6cCs|d|d<dS)z" primary_expression : identifier rrKNr r|r r r!p_primary_expression_1szCParser.p_primary_expression_1cCs|d|d<dS)z primary_expression : constant rrKNr r|r r r!p_primary_expression_2szCParser.p_primary_expression_2cCs|d|d<dS)zp primary_expression : unified_string_literal | unified_wstring_literal rrKNr r|r r r!p_primary_expression_3szCParser.p_primary_expression_3cCs|d|d<dS)z0 primary_expression : LPAREN expression RPAREN r]rKNr r|r r r!p_primary_expression_4 szCParser.p_primary_expression_4cCsB||d}tt|d|t|d|dg|||d<dS)za primary_expression : OFFSETOF LPAREN type_name COMMA offsetof_member_designator RPAREN rrrrKN)rrrFrr2)rr}r5r r r!p_primary_expression_5 s  zCParser.p_primary_expression_5cCst|dkr|d|d<nrt|dkrNt|d|d|d|dj|d<n>t|dkr|t|d|d|dj|d<ntdt|dS) z offsetof_member_designator : identifier | offsetof_member_designator PERIOD identifier | offsetof_member_designator LBRACKET expression RBRACKET r]rrKrrrz$Unexpected parsing state. len(p): %uN)r+rrHr5rDNotImplementedErrorr|r r r!p_offsetof_member_designators  ( "z$CParser.p_offsetof_member_designatorcCsNt|dkr*t|dg|dj|d<n |dj|d|d|d<dS)z argument_expression_list : assignment_expression | argument_expression_list COMMA assignment_expression r]rrKrN)r+rr2r5rr(r|r r r!p_argument_expression_list#s z"CParser.p_argument_expression_listcCs t|d||d|d<dS)z identifier : ID rrKN)rrrr|r r r! p_identifier-szCParser.p_identifiercCsd}d}|dddD]&}|dkr.|d7}q|dkr|d7}qd}|dkrVtdn|d krftd d |d |}t|d |d||d|d<dS)z constant : INT_CONST_DEC | INT_CONST_OCT | INT_CONST_HEX | INT_CONST_BIN | INT_CONST_CHAR rKrNlL)uUr z.Constant cannot have more than one u/U suffix.r]z.Constant cannot have more than two l/L suffix.z unsigned zlong rE) ValueErrorrConstantr)rr}ZuCountZlCountxrjprefixr r r! p_constant_11s$    zCParser.p_constant_1cCshd|dkrd}n0|dddkr,d}n|dddkrBd}nd}t||d||d|d <d S) zM constant : FLOAT_CONST | HEX_FLOAT_CONST r^rfloatr/)fFrWz long doubledoublerKN)lowerrr]r)rr}rjr r r! p_constant_2Hs zCParser.p_constant_2cCs"td|d||d|d<dS)z constant : CHAR_CONST | WCHAR_CONST | U8CHAR_CONST | U16CHAR_CONST | U32CHAR_CONST charrrKN)rr]rr|r r r! p_constant_3Ys  zCParser.p_constant_3cCsdt|dkr,td|d||d|d<n4|djdd|ddd|d_|d|d<dS)z~ unified_string_literal : STRING_LITERAL | unified_string_literal STRING_LITERAL r]stringrrKNr/)r+rr]rvaluer|r r r!p_unified_string_literalhs  (z CParser.p_unified_string_literalcCsht|dkr,td|d||d|d<n8|djdd|ddd|d_|d|d<dS)a unified_wstring_literal : WSTRING_LITERAL | U8STRING_LITERAL | U16STRING_LITERAL | U32STRING_LITERAL | unified_wstring_literal WSTRING_LITERAL | unified_wstring_literal U8STRING_LITERAL | unified_wstring_literal U16STRING_LITERAL | unified_wstring_literal U32STRING_LITERAL r]rirrKNr/)r+rr]rrjrstripr|r r r!p_unified_wstring_literalss  ,z!CParser.p_unified_wstring_literalcCs"|d|d<|d|ddS)z brace_open : LBRACE rrKNZ set_linenolinenor|r r r! p_brace_opens zCParser.p_brace_opencCs"|d|d<|d|ddS)z brace_close : RBRACE rrKNrnr|r r r! p_brace_closes zCParser.p_brace_closecCs d|d<dS)zempty : NrKr r|r r r!p_emptyszCParser.p_emptycCs@|r,|d|j|j|j|j|dn|d|jjdS)Nz before: %s)ror=zAt end of input)r2rjr:rorZfind_tok_columnr$r|r r r!p_errors zCParser.p_errorN)r F)F)F)__name__ __module__ __qualname__rr"r%r*r.r6r7r9rrrrr>rDrRrZrlrqrt precedencer~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r r r rrrrrrrrrrrrrrrr r"r#r&r)r*r,r.r0r1r3r4r5r6r7r8r9r:r;r<r=r@rArBrCrErGrJrKrLrMrNrOrPrQrSrTrUr`rfrhrkrmrprqrrrsr r r r!r st o     )2,  Y     7=       &                                                                      r N)Zplyrr rZc_lexerrZ plyparserrrrrZast_transformsr r r r r r r! s