a b@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#Zd_d$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@ddZAddZBddZCddZDddZEddZFddZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVeWdddddZXeWdddddZYeWdddddZZeWddddZ[eWdddddZ\eWdddddZ]eWdddddZ^eWdddddZ_ddZ`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\S(`CParserTzpycparser.lextabzpycparser.yacctabFc Cs~||j|j|j|jd|_|jj|||d|jj|_gd}|D]} || qBtj|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 outputdir)Zabstract_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_optruler!9/tmp/pip-target-98j97qn4/lib/python/pycparser/c_parser.py__init__s2:   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|jdksJ|jdS)Nr)lenrpopr*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]}||}|dur |Sq dS)z8 Is *name* a typedef-name in the current scope? NF)reversedrr1)rr4scopeZin_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. )r:)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" Sz/CParser._fix_decl_name_type..) rArrBr@declnamer4qualsIdentifierTyper,r2r5FuncDecl)rrCtypenamer@tnr!r!r"_fix_decl_name_type+s6      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 alignmentrM)rr)insert)rZdeclspecZnewspeckindr)specr!r!r"_add_declaration_specifierWs z"CParser._add_declaration_specifierc Csbd|dv}g}|dddur&n6|dddurt|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|jdur\|dd jd|_|dd =|D]} | ddusvJ|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. typedefrVrMbitsizeNrCr@r/r?r5zInvalid declarationrXrNr@rOalignr5rU)r4rOrVr@r5rWinit r4rOrbrVZfuncspecr@rcr^r5)r1r,rHr:hasattrr5r2rrBrAEnumStructUnionrPr@rNZTypedefDeclrTr6r4r7r r)) rr[declstypedef_namespaceZ is_typedefZ declarationsr5tZ decls_0_tailrC declarationZ fixed_declr!r!r"_build_declarationsps &            zCParser._build_declarationscCsLd|dvr|d|j|j|t|ddgddd}tj||||jd S) z' Builds a function definition. r]rVzInvalid typedefNrCrcTr[rjrkrM)rC param_declsbodyr5)r2r5rnrrZFuncDef)rr[rCrqrrrmr!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)rrgrh)rtokenr!r!r"_select_struct_union_classsz"CParser._select_struct_union_class) )leftZLOR)rwZLAND)rwOR)rwZXOR)rwAND)rwZEQZNE)rwGTZGELTZLE)rwZRSHIFTZLSHIFT)rwPLUSMINUS)rwZTIMESZDIVIDEZMODcCs2|ddurtg|d<nt|d|d<dS)zh translation_unit_or_empty : translation_unit | empty rNrM)rZFileASTrpr!r!r"p_translation_unit_or_emptys z#CParser.p_translation_unit_or_emptycCs|d|d<dS)z4 translation_unit : external_declaration rrMNr!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_rMN)extendr~r!r!r"p_translation_unit_2 szCParser.p_translation_unit_2cCs|dg|d<dS)z7 external_declaration : function_definition rrMNr!r~r!r!r"p_external_declaration_1sz CParser.p_external_declaration_1cCs|d|d<dS)z/ external_declaration : declaration rrMNr!r~r!r!r"p_external_declaration_2sz CParser.p_external_declaration_2cCs|dg|d<dS)zi external_declaration : pp_directive | pppragma_directive rrMNr!r~r!r!r"p_external_declaration_3sz CParser.p_external_declaration_3cCs g|d<dS)z( external_declaration : SEMI rMNr!r~r!r!r"p_external_declaration_4%sz CParser.p_external_declaration_4cCs|d|d<dS)z1 external_declaration : static_assert rrMNr!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 NrrM)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_directivecCsFt|dkr*t|d||d|d<ntd||d|d<dS)zg pppragma_directive : PPPRAGMA | PPPRAGMA PPPRAGMASTR rr_rMr rN)r,rPragmarr~r!r!r"p_pppragma_directive>s zCParser.p_pppragma_directivec CsNtgggtjdg||ddggd}|j||d|d|dd|d<d S) zU function_definition : id_declarator declaration_list_opt compound_statement rFrrGrUrXrVr@rWr_rr[rCrqrrrMN)rrrPrrsrrr[r!r!r"p_function_definition_1Is 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_rrrMN)rsrr!r!r"p_function_definition_2[szCParser.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 rrMNr!r~r!r!r" p_statementjs zCParser.p_statementcCsTt|dtjrDt|dkrDtj|d|dg||dd|d<n |d|d<dS)zx pragmacomp_or_statement : pppragma_directive statement | statement rrr_Z block_itemsr5rMN)rArrr,Compoundrr~r!r!r"p_pragmacomp_or_statements  z!CParser.p_pragmacomp_or_statementc Cs|d}|ddur|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@rMrUrXrVrWrdroTrp) rrgrhrfr,rArir5rnr)rrr[tyZs_u_or_erjr!r!r" p_decl_bodys6   zCParser.p_decl_bodycCs|d|d<dS)z& declaration : decl_body SEMI rrMNr!r~r!r!r" p_declarationszCParser.p_declarationcCs,t|dkr|dn|d|d|d<dS)zj declaration_list : declaration | declaration_list declaration r_rrMNr,r~r!r!r"p_declaration_listszCParser.p_declaration_listcCs||d|dd|d<dS)z] declaration_specifiers_no_type : type_qualifier declaration_specifiers_no_type_opt r_rrUrMNr\r~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_rrVrMNrr~r!r!r""p_declaration_specifiers_no_type_2 sz*CParser.p_declaration_specifiers_no_type_2cCs||d|dd|d<dS)za declaration_specifiers_no_type : function_specifier declaration_specifiers_no_type_opt r_rrWrMNrr~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@rMNrr~r!r!r""p_declaration_specifiers_no_type_4sz*CParser.p_declaration_specifiers_no_type_4cCs||d|dd|d<dS)zb declaration_specifiers_no_type : alignment_specifier declaration_specifiers_no_type_opt r_rrXrMNrr~r!r!r""p_declaration_specifiers_no_type_5sz*CParser.p_declaration_specifiers_no_type_5cCs"|j|d|dddd|d<dS)zI declaration_specifiers : declaration_specifiers type_qualifier rr_rUTr)rMNrr~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_rVTrrMNrr~r!r!r"p_declaration_specifiers_2&sz"CParser.p_declaration_specifiers_2cCs"|j|d|dddd|d<dS)zM declaration_specifiers : declaration_specifiers function_specifier rr_rWTrrMNrr~r!r!r"p_declaration_specifiers_3+sz"CParser.p_declaration_specifiers_3cCs"|j|d|dddd|d<dS)zS declaration_specifiers : declaration_specifiers type_specifier_no_typeid rr_r@TrrMNrr~r!r!r"p_declaration_specifiers_40sz"CParser.p_declaration_specifiers_4cCs|d|dd|d<dS)z2 declaration_specifiers : type_specifier Nrr@rMrr~r!r!r"p_declaration_specifiers_55sz"CParser.p_declaration_specifiers_5cCs"|j|d|dddd|d<dS)zQ declaration_specifiers : declaration_specifiers_no_type type_specifier rr_r@TrrMNrr~r!r!r"p_declaration_specifiers_6:sz"CParser.p_declaration_specifiers_6cCs"|j|d|dddd|d<dS)zN declaration_specifiers : declaration_specifiers alignment_specifier rr_rXTrrMNrr~r!r!r"p_declaration_specifiers_7?sz"CParser.p_declaration_specifiers_7cCs|d|d<dS)a storage_class_specifier : AUTO | REGISTER | STATIC | EXTERN | TYPEDEF | _THREAD_LOCAL rrMNr!r~r!r!r"p_storage_class_specifierDsz!CParser.p_storage_class_specifiercCs|d|d<dS)zR function_specifier : INLINE | _NORETURN rrMNr!r~r!r!r"p_function_specifierNszCParser.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 rrGrMNrrPrr~r!r!r"p_type_specifier_no_typeidTsz"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 rrMNr!r~r!r!r"p_type_specifierdszCParser.p_type_specifiercCs |d}|jd||d<dS)z= atomic_specifier : _ATOMIC LPAREN type_name RPAREN rZ_AtomicrMN)rOr))rrtypr!r!r"p_atomic_specifierns zCParser.p_atomic_specifiercCs|d|d<dS)z type_qualifier : CONST | RESTRICT | VOLATILE | _ATOMIC rrMNr!r~r!r!r"p_type_qualifieruszCParser.p_type_qualifiercCs0t|dkr|d|dgn|dg|d<dS)z init_declarator_list : init_declarator | init_declarator_list COMMA init_declarator rrrrMNrr~r!r!r"p_init_declarator_list}szCParser.p_init_declarator_listcCs,t|dt|dkr|dndd|d<dS)zb init_declarator : declarator | declarator EQUALS initializer rr_rNrorMrr,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 rrrrMNrr~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_rNrorMrr~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@TrrMNrr~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_rUTrrMNrr~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@rMrr~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_rrMNrr~r!r!r"p_specifier_qualifier_list_4sz$CParser.p_specifier_qualifier_list_4cCs tg|dggggd|d<dS)z9 specifier_qualifier_list : alignment_specifier rrrMNrr~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_rXrMNrr~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_Nr4rjr5rM)rvrrrklassr!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_rrMrrvr,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_rrMrNrrr!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 rrMNr!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_rrMNrr~r!r!r"p_struct_declaration_lists z!CParser.p_struct_declaration_listcCs|d}d|dvsJ|ddur8|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]rVr_Nr[rjr@rMrCro)rnr,rArNoderPr)rrr[rjnodeZ decl_typer!r!r"p_struct_declaration_1s*       zCParser.p_struct_declaration_1cCs d|d<dS)z# struct_declaration : SEMI NrMr!r~r!r!r"p_struct_declaration_2"szCParser.p_struct_declaration_2cCs|dg|d<dS)z1 struct_declaration : pppragma_directive rrMNr!r~r!r!r"p_struct_declaration_3'szCParser.p_struct_declaration_3cCs0t|dkr|d|dgn|dg|d<dS)z struct_declarator_list : struct_declarator | struct_declarator_list COMMA struct_declarator rrrrMNrr~r!r!r"p_struct_declarator_list,sz CParser.p_struct_declarator_listcCs|ddd|d<dS)z( struct_declarator : declarator rNrCr^rMr!r~r!r!r"p_struct_declarator_15szCParser.p_struct_declarator_1cCsFt|dkr$|d|dd|d<ntdddd|dd|d<dS)z struct_declarator : declarator COLON constant_expression | COLON constant_expression rrrrMNr_)r,rrBr~r!r!r"p_struct_declarator_2:s zCParser.p_struct_declarator_2cCs"t|dd||d|d<dS)zM enum_specifier : ENUM ID | ENUM TYPEID r_NrrMrrfrr~r!r!r"p_enum_specifier_1CszCParser.p_enum_specifier_1cCs"td|d||d|d<dS)zG enum_specifier : ENUM brace_open enumerator_list brace_close NrrrMrr~r!r!r"p_enum_specifier_2IszCParser.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_rrrMNrr~r!r!r"p_enum_specifier_3NszCParser.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_rrMrN)r,rZEnumeratorListr5Z enumeratorsr)r~r!r!r"p_enumerator_listTs   zCParser.p_enumerator_listcCs t|d||d|d<dS)z alignment_specifier : _ALIGNAS LPAREN type_name RPAREN | _ALIGNAS LPAREN constant_expression RPAREN rrrMN)rZAlignasrr~r!r!r"p_alignment_specifieraszCParser.p_alignment_specifiercCsbt|dkr(t|dd||d}nt|d|d||d}||j|j||d<dS)zR enumerator : ID | ID EQUALS constant_expression r_rNrrM)r,rZ Enumeratorrr7r4r5)rrZ enumeratorr!r!r" p_enumeratorgs    zCParser.p_enumeratorcCs|d|d<dS)zQ declarator : id_declarator | typeid_declarator rrMNr!r~r!r!r" p_declaratorwszCParser.p_declarator)rJID)ZtypeidTYPEID)Ztypeid_noparenrcCs|d|d<dS)z1 xxx_declarator : direct_xxx_declarator rrMNr!r~r!r!r"p_xxx_declarator_1}szCParser.p_xxx_declarator_1cCs||d|d|d<dS)z9 xxx_declarator : pointer direct_xxx_declarator r_rrMNrEr~r!r!r"p_xxx_declarator_2szCParser.p_xxx_declarator_2c Cs(tj|dddd||dd|d<dS)z' direct_xxx_declarator : yyy rNrarM)rrBrr~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_rMNr!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@dim dim_qualsr5rCrDrM)r,r ArrayDeclr5rE)rrrOarrr!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!rAlist)rIitemr!r!r"rKsz5CParser.p_direct_xxx_declarator_4..rrcSs"g|]}|D]}|dur |q qSr(r!)rIZsublistrUr!r!r"rKsNrrrrrMrrr5rE)rrZ listed_qualsrrr!r!r"p_direct_xxx_declarator_4sz!CParser.p_direct_xxx_declarator_4c CsZtjdt|d||d|ddur0|dng|djd}|j|d|d|d<dS)zi direct_xxx_declarator : direct_xxx_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET NrrrrrrMrrrrr5rErrrr!r!r"p_direct_xxx_declarator_5sz!CParser.p_direct_xxx_declarator_5cCsztj|dd|djd}|jdkr`|jdur`|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@r5LBRACErrM) rrQr5r?r@rparamsrA EllipsisParamr7r4rE)rrfuncparamr!r!r"p_direct_xxx_declarator_6s  z!CParser.p_direct_xxx_declarator_6cCsj||d}tj|dpgd|d}t|dkr^|d}|jdurJ|j}q8||_|d|d<n||d<dS)zm pointer : TIMES type_qualifier_list_opt | TIMES type_qualifier_list_opt pointer rr_N)rOr@r5rrM)rrZPtrDeclr,r@)rrr5Z 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_rrMNrr~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_rrrMN)r,rr)rrrr~r!r!r"p_parameter_type_list s 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_rrMrNr,rZ ParamListr5rr)r~r!r!r"p_parameter_lists 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@rFrGr_rrrMN)rrPrrnrrr!r!r"p_parameter_declaration_1)s 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@rFrGr/rMr_Nrorr rUr4rOrbr@r5) rrPrr,rHr:rnrTypenamerBrT)rrr[rCrRr!r!r"p_parameter_declaration_25s0 &  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_rrMrNrr~r!r!r"p_identifier_listUs zCParser.p_identifier_listcCs|d|d<dS)z- initializer : assignment_expression rrMNr!r~r!r!r"p_initializer_1_szCParser.p_initializer_1cCs6|ddur&tg||d|d<n |d|d<dS)z initializer : brace_open initializer_list_opt brace_close | brace_open initializer_list COMMA brace_close r_NrrM)rInitListrr~r!r!r"p_initializer_2ds zCParser.p_initializer_2cCst|dkrN|ddur |dnt|d|d}t|g|dj|d<nD|ddurb|dnt|d|d}|dj||d|d<dS)z initializer_list : designation_opt initializer | initializer_list COMMA designation_opt initializer rrNr_rMr)r,rZNamedInitializerrr5exprsr))rrrcr!r!r"p_initializer_listms  ((zCParser.p_initializer_listcCs|d|d<dS)z. designation : designator_list EQUALS rrMNr!r~r!r!r" p_designationyszCParser.p_designationcCs0t|dkr|dgn|d|dg|d<dS)z_ designator_list : designator | designator_list designator r_rrMNrr~r!r!r"p_designator_listszCParser.p_designator_listcCs|d|d<dS)zi designator : LBRACKET constant_expression RBRACKET | PERIOD identifier r_rMNr!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 rrUNr_rr@rM)rrrBrrT)rrrRr!r!r" p_type_names zCParser.p_type_namecCs*tdddd}|j||dd|d<dS)z+ abstract_declarator : pointer NrrrM)rrBrE)rrZ dummytyper!r!r"p_abstract_declarator_1s zCParser.p_abstract_declarator_1cCs||d|d|d<dS)zF abstract_declarator : pointer direct_abstract_declarator r_rrMNrr~r!r!r"p_abstract_declarator_2szCParser.p_abstract_declarator_2cCs|d|d<dS)z> abstract_declarator : direct_abstract_declarator rrMNr!r~r!r!r"p_abstract_declarator_3szCParser.p_abstract_declarator_3cCs|d|d<dS)zA direct_abstract_declarator : LPAREN abstract_declarator RPAREN r_rMNr!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 NrrrrrMrrr!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_NrrrrM)r,rrrBr)rrrOr!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 NrrrrrMrrr!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 NrrrrM)rrrBrrr~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 rNrrrrM)rrQr5rE)rrrr!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_NrrrM)rrQrBrr~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 rrMNrr~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_NrrMrr~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_rrrMN)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 rrrMN)rLabelrr~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_rrrMN)rZCaserr~r!r!r"p_labeled_statement_2 szCParser.p_labeled_statement_2cCs"t|dg||d|d<dS)z; labeled_statement : DEFAULT COLON pragmacomp_or_statement rrrMN)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 rrNrrMrIfrr~r!r!r"p_selection_statement_1szCParser.p_selection_statement_1c Cs,t|d|d|d||d|d<dS)zZ selection_statement : IF LPAREN expression RPAREN statement ELSE pragmacomp_or_statement rrrrMNrr~r!r!r"p_selection_statement_2szCParser.p_selection_statement_2c Cs*tt|d|d||d|d<dS)zO selection_statement : SWITCH LPAREN expression RPAREN pragmacomp_or_statement rrrrMN)r rZSwitchrr~r!r!r"p_selection_statement_3szCParser.p_selection_statement_3cCs&t|d|d||d|d<dS)zN iteration_statement : WHILE LPAREN expression RPAREN pragmacomp_or_statement rrrrMN)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_rrMN)rZDoWhilerr~r!r!r"p_iteration_statement_2$szCParser.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" rrMN)rForrr~r!r!r"p_iteration_statement_3(szCParser.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 rrrrMN)rr)ZDeclListrr~r!r!r"p_iteration_statement_4,szCParser.p_iteration_statement_4cCs t|d||d|d<dS)z jump_statement : GOTO ID SEMI r_rrMN)rZGotorr~r!r!r"p_jump_statement_11szCParser.p_jump_statement_1cCst||d|d<dS)z jump_statement : BREAK SEMI rrMN)rBreakrr~r!r!r"p_jump_statement_25szCParser.p_jump_statement_2cCst||d|d<dS)z! jump_statement : CONTINUE SEMI rrMN)rContinuerr~r!r!r"p_jump_statement_39szCParser.p_jump_statement_3cCs0tt|dkr|dnd||d|d<dS)z\ jump_statement : RETURN expression SEMI | RETURN SEMI rr_NrrM)rReturnr,rr~r!r!r"p_jump_statement_4=szCParser.p_jump_statement_4cCs4|ddur$t||d|d<n |d|d<dS)z, expression_statement : expression_opt SEMI rNr_rM)rZEmptyStatementrr~r!r!r"p_expression_statementCs 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_rrMrN)r,rArExprListr5rr)r~r!r!r" p_expressionJs  zCParser.p_expressioncCs|d|d<dS)z: assignment_expression : LPAREN compound_statement RPAREN r_rMNr!r~r!r!r"#p_parenthesized_compound_expressionWsz+CParser.p_parenthesized_compound_expressioncCs$tj|dg||dd|d<dS)z typedef_name : TYPEID rrGrMNrr~r!r!r"p_typedef_name[szCParser.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_rrMrN)r,rZ Assignmentr5r~r!r!r"p_assignment_expression_s zCParser.p_assignment_expressioncCs|d|d<dS)a assignment_operator : EQUALS | XOREQUAL | TIMESEQUAL | DIVEQUAL | MODEQUAL | PLUSEQUAL | MINUSEQUAL | LSHIFTEQUAL | RSHIFTEQUAL | ANDEQUAL | OREQUAL rrMNr!r~r!r!r"p_assignment_operatorms zCParser.p_assignment_operatorcCs|d|d<dS)z. constant_expression : conditional_expression rrMNr!r~r!r!r"p_constant_expression|szCParser.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_rrMrrN)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_rrMrN)r,rZBinaryOpr5r~r!r!r"p_binary_expressions zCParser.p_binary_expressioncCs|d|d<dS)z$ cast_expression : unary_expression rrMNr!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_rrrMN)rZCastrr~r!r!r"p_cast_expression_2szCParser.p_cast_expression_2cCs|d|d<dS)z* unary_expression : postfix_expression rrMNr!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_rMNrUnaryOpr5r~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_rMN)rrCr,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 rrMNr!r~r!r!r"p_unary_operatorszCParser.p_unary_operatorcCs|d|d<dS)z* postfix_expression : primary_expression rrMNr!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 rrrMN)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 rrrNrM)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_rMN)rrr StructRefr5)rrfieldr!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 rr_rrMNrBr~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_rrMN)rZCompoundLiteralr~r!r!r"p_postfix_expression_6szCParser.p_postfix_expression_6cCs|d|d<dS)z" primary_expression : identifier rrMNr!r~r!r!r"p_primary_expression_1szCParser.p_primary_expression_1cCs|d|d<dS)z primary_expression : constant rrMNr!r~r!r!r"p_primary_expression_2szCParser.p_primary_expression_2cCs|d|d<dS)zp primary_expression : unified_string_literal | unified_wstring_literal rrMNr!r~r!r!r"p_primary_expression_3szCParser.p_primary_expression_3cCs|d|d<dS)z0 primary_expression : LPAREN expression RPAREN r_rMNr!r~r!r!r"p_primary_expression_4szCParser.p_primary_expression_4cCsB||d}tt|d|t|d|dg|||d<dS)za primary_expression : OFFSETOF LPAREN type_name COMMA offsetof_member_designator RPAREN rrrrMN)rrrJrr6)rrr5r!r!r"p_primary_expression_5s  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_rrMrrrz$Unexpected parsing state. len(p): %uN)r,rrLr5rHNotImplementedErrorr~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_rrMrN)r,rr6r5rr)r~r!r!r"p_argument_expression_lists z"CParser.p_argument_expression_listcCs t|d||d|d<dS)z identifier : ID rrMN)rrrr~r!r!r" p_identifierszCParser.p_identifiercCsd}d}|dddD]&}|dvr.|d7}q|dvr|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 rMrNlL)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 rF) ValueErrorrConstantr)rrZuCountZlCountxrlprefixr!r!r" p_constant_1#s    zCParser.p_constant_1cCshd|dvrd}n0|dddvr,d}n|dddvrBd}nd}t||d||d|d <d S) zM constant : FLOAT_CONST | HEX_FLOAT_CONST rbrfloatr/)fFr[z long doubledoublerMN)lowerrrar)rrrlr!r!r" p_constant_2:szCParser.p_constant_2cCs"td|d||d|d<dS)z constant : CHAR_CONST | WCHAR_CONST | U8CHAR_CONST | U16CHAR_CONST | U32CHAR_CONST charrrMN)rrarr~r!r!r" p_constant_3KszCParser.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_stringrrMNr/)r,rrarvaluer~r!r!r"p_unified_string_literalZs   (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_rmrrMNr/)r,rrarrnrstripr~r!r!r"p_unified_wstring_literales  ,z!CParser.p_unified_wstring_literalcCs"|d|d<|d|ddS)z brace_open : LBRACE rrMNZ set_linenolinenor~r!r!r" p_brace_openvs zCParser.p_brace_opencCs"|d|d<|d|ddS)z brace_close : RBRACE rrMNrrr~r!r!r" p_brace_close|s zCParser.p_brace_closecCs d|d<dS)zempty : NrMr!r~r!r!r"p_emptyszCParser.p_emptycCs@|r,|d|j|j|j|j|dn|d|jjdS)Nz before: %s)rsr>zAt end of input)r2rnr;rsrZfind_tok_columnr%r~r!r!r"p_errors zCParser.p_errorN)r F)F)F)__name__ __module__ __qualname__rr#r&r+r.r6r7r:rrrrr?rErTr\rnrsrv precedencerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r r r rrrrrrrrrrrrrrrrr!r#r$r&r'r*r-r.r0r2r4r5r7r8r9r:r;r<r=r>r?r@rArDrErFrGrIrKrNrOrPrQrRrSrTrUrWrXrYrdrjrlrorqrtrurvrwr!r!r!r"r sr o     )2,  Y    7=       &                                                                     r N)Zplyrr rZc_lexerrZ plyparserrrrrZast_transformsr r r r!r!r!r" s