How to use gotoST method in avocado

Best Python code snippet using avocado_python

parsetab.py

Source:parsetab.py Github

copy

Full Screen

1# parsetab.py2# This file is automatically generated. Do not edit.3# pylint: disable=W,C,R4_tabversion = '3.10'5_lr_method = 'LALR'6_lr_signature = 'COLON COMMA DISTINT DIV EQUALS EQUALSEQUALS FLOAT64 FLOATLITERAL FMT FUNC GOTO GREATER GREATEREQUAL ID IF IMPORT INT INTLITERAL LECOR LEKEY LEPAR LESS LESSEQUAL MINUS PACKAGE PLUS POINT PRINTF RETURN RICOR RIKEY RIPAR SEMICOLON STRINGLITERAL TIMES VARstart : PACKAGE ID SEMICOLON IMPORT LEPAR STRINGLITERAL RIPAR SEMICOLON declarations codeListdeclarations : declarations declaration\n | declarationdeclaration : VAR idList LECOR INTLITERAL RICOR FLOAT64 SEMICOLON\n | VAR idList type SEMICOLONtype : INT\n | FLOAT64idList : idList COMMA ID\n | IDcodeList : codeList code\n | codecode : FUNC ID LEPAR RIPAR statementstatement : LEKEY instructions RIKEYinstructions : instructions instruction\n | instructioninstruction : assign SEMICOLON\n | print SEMICOLON\n | if\n | gotoSt SEMICOLON\n | label\n | callFunc SEMICOLON\n | retSt SEMICOLONretSt : RETURNcallFunc : ID LEPAR RIPARlabel : ID COLONgotoSt : GOTO IDif : IF expression LEKEY GOTO ID SEMICOLON RIKEYassign : access EQUALS finalExpassign : ID EQUALS expression\n | ID EQUALS accessprint : FMT POINT PRINTF LEPAR STRINGLITERAL COMMA printValue RIPARprintValue : INT LEPAR finalExp RIPAR\n | finalExpexpression : finalExp PLUS finalExp\n | finalExp MINUS finalExp\n | finalExp TIMES finalExp\n | finalExp DIV finalExp\n | finalExp GREATER finalExp\n | finalExp LESS finalExp\n | finalExp GREATEREQUAL finalExp\n | finalExp LESSEQUAL finalExp\n | finalExp EQUALSEQUALS finalExp\n | finalExp DISTINT finalExp\n | finalExpfinalExp : ID\n | INTLITERAL\n | MINUS INTLITERAL\n | FLOATLITERALaccess : ID LECOR INT LEPAR finalExp RIPAR RICOR\n | ID LECOR finalExp RICOR'7 8_lr_action_items = {'PACKAGE':([0,],[2,]),'$end':([1,13,15,19,32,51,],[0,-1,-11,-10,-12,-13,]),'ID':([2,12,16,24,33,35,36,39,41,47,48,52,53,54,55,56,57,58,59,60,62,80,81,82,83,84,85,86,87,88,89,91,94,109,115,117,],[3,18,20,29,45,45,-15,-18,-20,65,70,-14,-16,-17,-19,-21,-22,65,72,-25,65,65,65,65,65,65,65,65,65,65,65,65,107,65,-27,65,]),'SEMICOLON':([3,8,22,23,25,34,37,38,40,42,43,49,65,66,68,69,70,71,72,73,74,75,90,92,95,96,97,98,99,100,101,102,103,104,107,111,116,],[4,9,-7,28,-6,50,53,54,55,56,57,-23,-45,-44,-46,-48,-26,-28,-45,-29,-30,-24,-47,-50,-34,-35,-36,-37,-38,-39,-40,-41,-42,-43,110,-49,-31,]),'IMPORT':([4,],[5,]),'LEPAR':([5,20,45,76,78,113,],[6,26,61,91,93,117,]),'STRINGLITERAL':([6,93,],[7,106,]),'RIPAR':([7,26,61,65,68,69,90,105,112,114,118,119,],[8,30,75,-45,-46,-48,-47,108,116,-33,119,-32,]),'VAR':([9,10,11,14,28,50,],[12,12,-3,-2,-5,-4,]),'FUNC':([10,11,13,14,15,19,28,32,50,51,],[16,-3,16,-2,-11,-10,-5,-12,-4,-13,]),'LECOR':([17,18,29,45,72,],[21,-9,-8,62,62,]),'COMMA':([17,18,29,106,],[24,-9,-8,109,]),'INT':([17,18,29,62,109,],[25,-9,-8,76,113,]),'FLOAT64':([17,18,29,31,],[22,-9,-8,34,]),'INTLITERAL':([21,47,58,59,62,67,80,81,82,83,84,85,86,87,88,89,91,109,117,],[27,68,68,68,68,90,68,68,68,68,68,68,68,68,68,68,68,68,68,]),'RICOR':([27,65,68,69,77,90,108,],[31,-45,-46,-48,92,-47,111,]),'LEKEY':([30,64,65,66,68,69,90,95,96,97,98,99,100,101,102,103,104,],[33,79,-45,-44,-46,-48,-47,-34,-35,-36,-37,-38,-39,-40,-41,-42,-43,]),'FMT':([33,35,36,39,41,52,53,54,55,56,57,60,115,],[46,46,-15,-18,-20,-14,-16,-17,-19,-21,-22,-25,-27,]),'IF':([33,35,36,39,41,52,53,54,55,56,57,60,115,],[47,47,-15,-18,-20,-14,-16,-17,-19,-21,-22,-25,-27,]),'GOTO':([33,35,36,39,41,52,53,54,55,56,57,60,79,115,],[48,48,-15,-18,-20,-14,-16,-17,-19,-21,-22,-25,94,-27,]),'RETURN':([33,35,36,39,41,52,53,54,55,56,57,60,115,],[49,49,-15,-18,-20,-14,-16,-17,-19,-21,-22,-25,-27,]),'RIKEY':([35,36,39,41,52,53,54,55,56,57,60,110,115,],[51,-15,-18,-20,-14,-16,-17,-19,-21,-22,-25,115,-27,]),'EQUALS':([44,45,92,111,],[58,59,-50,-49,]),'COLON':([45,],[60,]),'POINT':([46,],[63,]),'MINUS':([47,58,59,62,65,66,68,69,72,80,81,82,83,84,85,86,87,88,89,90,91,109,117,],[67,67,67,67,-45,81,-46,-48,-45,67,67,67,67,67,67,67,67,67,67,-47,67,67,67,]),'FLOATLITERAL':([47,58,59,62,80,81,82,83,84,85,86,87,88,89,91,109,117,],[69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,]),'PRINTF':([63,],[78,]),'PLUS':([65,66,68,69,72,90,],[-45,80,-46,-48,-45,-47,]),'TIMES':([65,66,68,69,72,90,],[-45,82,-46,-48,-45,-47,]),'DIV':([65,66,68,69,72,90,],[-45,83,-46,-48,-45,-47,]),'GREATER':([65,66,68,69,72,90,],[-45,84,-46,-48,-45,-47,]),'LESS':([65,66,68,69,72,90,],[-45,85,-46,-48,-45,-47,]),'GREATEREQUAL':([65,66,68,69,72,90,],[-45,86,-46,-48,-45,-47,]),'LESSEQUAL':([65,66,68,69,72,90,],[-45,87,-46,-48,-45,-47,]),'EQUALSEQUALS':([65,66,68,69,72,90,],[-45,88,-46,-48,-45,-47,]),'DISTINT':([65,66,68,69,72,90,],[-45,89,-46,-48,-45,-47,]),}9_lr_action = {}10for _k, _v in _lr_action_items.items():11 for _x,_y in zip(_v[0],_v[1]):12 if not _x in _lr_action: _lr_action[_x] = {}13 _lr_action[_x][_k] = _y14del _lr_action_items15_lr_goto_items = {'start':([0,],[1,]),'declarations':([9,],[10,]),'declaration':([9,10,],[11,14,]),'codeList':([10,],[13,]),'code':([10,13,],[15,19,]),'idList':([12,],[17,]),'type':([17,],[23,]),'statement':([30,],[32,]),'instructions':([33,],[35,]),'instruction':([33,35,],[36,52,]),'assign':([33,35,],[37,37,]),'print':([33,35,],[38,38,]),'if':([33,35,],[39,39,]),'gotoSt':([33,35,],[40,40,]),'label':([33,35,],[41,41,]),'callFunc':([33,35,],[42,42,]),'retSt':([33,35,],[43,43,]),'access':([33,35,59,],[44,44,74,]),'expression':([47,59,],[64,73,]),'finalExp':([47,58,59,62,80,81,82,83,84,85,86,87,88,89,91,109,117,],[66,71,66,77,95,96,97,98,99,100,101,102,103,104,105,114,118,]),'printValue':([109,],[112,]),}16_lr_goto = {}17for _k, _v in _lr_goto_items.items():18 for _x, _y in zip(_v[0], _v[1]):19 if not _x in _lr_goto: _lr_goto[_x] = {}20 _lr_goto[_x][_k] = _y21del _lr_goto_items22_lr_productions = [23 ("S' -> start","S'",1,None,None,None),24 ('start -> PACKAGE ID SEMICOLON IMPORT LEPAR STRINGLITERAL RIPAR SEMICOLON declarations codeList','start',10,'p_start','optimization.py',148),25 ('declarations -> declarations declaration','declarations',2,'p_declarations','optimization.py',152),26 ('declarations -> declaration','declarations',1,'p_declarations','optimization.py',153),27 ('declaration -> VAR idList LECOR INTLITERAL RICOR FLOAT64 SEMICOLON','declaration',7,'p_declaration','optimization.py',161),28 ('declaration -> VAR idList type SEMICOLON','declaration',4,'p_declaration','optimization.py',162),29 ('type -> INT','type',1,'p_type','optimization.py',169),30 ('type -> FLOAT64','type',1,'p_type','optimization.py',170),31 ('idList -> idList COMMA ID','idList',3,'p_idList','optimization.py',177),32 ('idList -> ID','idList',1,'p_idList','optimization.py',178),33 ('codeList -> codeList code','codeList',2,'p_codeList','optimization.py',185),34 ('codeList -> code','codeList',1,'p_codeList','optimization.py',186),35 ('code -> FUNC ID LEPAR RIPAR statement','code',5,'p_code','optimization.py',194),36 ('statement -> LEKEY instructions RIKEY','statement',3,'p_statement','optimization.py',198),37 ('instructions -> instructions instruction','instructions',2,'p_instructions','optimization.py',202),38 ('instructions -> instruction','instructions',1,'p_instructions','optimization.py',203),39 ('instruction -> assign SEMICOLON','instruction',2,'p_instruction','optimization.py',211),40 ('instruction -> print SEMICOLON','instruction',2,'p_instruction','optimization.py',212),41 ('instruction -> if','instruction',1,'p_instruction','optimization.py',213),42 ('instruction -> gotoSt SEMICOLON','instruction',2,'p_instruction','optimization.py',214),43 ('instruction -> label','instruction',1,'p_instruction','optimization.py',215),44 ('instruction -> callFunc SEMICOLON','instruction',2,'p_instruction','optimization.py',216),45 ('instruction -> retSt SEMICOLON','instruction',2,'p_instruction','optimization.py',217),46 ('retSt -> RETURN','retSt',1,'p_return','optimization.py',221),47 ('callFunc -> ID LEPAR RIPAR','callFunc',3,'p_callFunc','optimization.py',225),48 ('label -> ID COLON','label',2,'p_label','optimization.py',229),49 ('gotoSt -> GOTO ID','gotoSt',2,'p_goto','optimization.py',233),50 ('if -> IF expression LEKEY GOTO ID SEMICOLON RIKEY','if',7,'p_if','optimization.py',237),51 ('assign -> access EQUALS finalExp','assign',3,'p_assign','optimization.py',241),52 ('assign -> ID EQUALS expression','assign',3,'p_assign2','optimization.py',245),53 ('assign -> ID EQUALS access','assign',3,'p_assign2','optimization.py',246),54 ('print -> FMT POINT PRINTF LEPAR STRINGLITERAL COMMA printValue RIPAR','print',8,'p_print','optimization.py',251),55 ('printValue -> INT LEPAR finalExp RIPAR','printValue',4,'p_printValue','optimization.py',255),56 ('printValue -> finalExp','printValue',1,'p_printValue','optimization.py',256),57 ('expression -> finalExp PLUS finalExp','expression',3,'p_expression','optimization.py',264),58 ('expression -> finalExp MINUS finalExp','expression',3,'p_expression','optimization.py',265),59 ('expression -> finalExp TIMES finalExp','expression',3,'p_expression','optimization.py',266),60 ('expression -> finalExp DIV finalExp','expression',3,'p_expression','optimization.py',267),61 ('expression -> finalExp GREATER finalExp','expression',3,'p_expression','optimization.py',268),62 ('expression -> finalExp LESS finalExp','expression',3,'p_expression','optimization.py',269),63 ('expression -> finalExp GREATEREQUAL finalExp','expression',3,'p_expression','optimization.py',270),64 ('expression -> finalExp LESSEQUAL finalExp','expression',3,'p_expression','optimization.py',271),65 ('expression -> finalExp EQUALSEQUALS finalExp','expression',3,'p_expression','optimization.py',272),66 ('expression -> finalExp DISTINT finalExp','expression',3,'p_expression','optimization.py',273),67 ('expression -> finalExp','expression',1,'p_expression','optimization.py',274),68 ('finalExp -> ID','finalExp',1,'p_finalExp','optimization.py',281),69 ('finalExp -> INTLITERAL','finalExp',1,'p_finalExp','optimization.py',282),70 ('finalExp -> MINUS INTLITERAL','finalExp',2,'p_finalExp','optimization.py',283),71 ('finalExp -> FLOATLITERAL','finalExp',1,'p_finalExp','optimization.py',284),72 ('access -> ID LECOR INT LEPAR finalExp RIPAR RICOR','access',7,'p_access','optimization.py',291),73 ('access -> ID LECOR finalExp RICOR','access',4,'p_access','optimization.py',292),...

Full Screen

Full Screen

deal_return.py

Source:deal_return.py Github

copy

Full Screen

1from __future__ import print_function2import sys3sys.path.extend(['.', '..'])4sys.path.append("../")5from pycparser import parse_file, c_parser, c_generator, c_ast6global_return_sta = {}7global_return_decl={}8def get_last_linenum(c, last_num, inc_linenum):9 if c.coord is not None:10 templine = int(str(c.coord).split(":")[1])11 if templine > last_num:12 last_num = templine13 if len(inc_linenum) == 0:14 inc_linenum.append(last_num)15 else:16 inc_linenum[0] = last_num17 for child in c:18 if child is None:19 continue20 else:21 if child.coord is not None:22 templine = int(str(child.coord).split(":")[1])23 if templine > last_num:24 last_num = templine25 if len(inc_linenum) == 0:26 inc_linenum.append(last_num)27 else:28 inc_linenum[0] = last_num29 # print("finally_last_num:" + str(last_num))30 get_last_linenum(child, last_num, inc_linenum)31 # return last_num32def find_return(st, ret_name, gotost, funnamne,pst):33 """34 在每一条语句(复合语句,简单语句,语句)中递归查找所有的return语句,修改成赋值语句并添加goto语句35 find all return statement and modify it and insert new statement36 :param st: 复合语句或者简单语句对应的ast37 :param ret_name: 返回值变量名38 :param gotost: goto语句对应的ast39 :return:40 """41 if type(st)==c_ast.Label:42 print("findlabel...")43 print(st)44 if type(st)==c_ast.Compound or type(st)==c_ast.If or type(st)==c_ast.For or type(st)==c_ast.While or type(st)==c_ast.DoWhile \45 or type(st)==c_ast.Switch or type(st)==c_ast.Case or type(st)==c_ast.Default or type(st)==c_ast.Label:46 for child in st:47 find_return(child,ret_name,gotost,funnamne,st)48 elif type(st) == c_ast.Return:49 assign = c_ast.Assignment(op='=', lvalue=c_ast.ID(name=ret_name), rvalue=st.expr)50 if type(st.expr) == c_ast.FuncCall:51 lineinfo = str(st.coord)52 index = lineinfo.index(":")53 rindex = lineinfo.rindex(":")54 linenum = int(lineinfo[index + 1:rindex])55 last_num = -156 inc_linenum = []57 get_last_linenum(st, last_num, inc_linenum)58 global_return_sta[funnamne][linenum] = [assign, inc_linenum[0]]59 if type(pst) == c_ast.Compound:60 pst.block_items.remove(st)61 pst.block_items.append(assign)62 pst.block_items.append(gotost)63 elif type(pst) == c_ast.If and st == pst.iftrue:64 tempst = c_ast.Compound(block_items=[assign, gotost])65 pst.iftrue = tempst66 elif type(pst) == c_ast.If and st == pst.iffalse:67 tempst = c_ast.Compound(block_items=[assign, gotost])68 pst.iffalse = tempst69 elif type(pst) ==c_ast.Label:70 tempst = c_ast.Compound(block_items=[assign, gotost])71 pst.stmt = tempst72 else:73 if type(pst) == c_ast.Case or type(pst) == c_ast.Default:74 pst.stmts.remove(st)75 pst.stmts.append(assign)76 pst.stmts.append(gotost)77 # if type(st) == c_ast.If:78 # for i in st:79 # if type(i) == c_ast.Return:80 # assign = c_ast.Assignment(op='=', lvalue=c_ast.ID(name=ret_name), rvalue=i.expr)81 # if type(i.expr) == c_ast.FuncCall:82 # lineinfo = str(i.coord)83 # index = lineinfo.index(":")84 # rindex = lineinfo.rindex(":")85 # linenum = int(lineinfo[index + 1:rindex])86 # last_num = -187 # inc_linenum = []88 # get_last_linenum(i, last_num, inc_linenum)89 # global_return_sta[funnamne][linenum] = [assign, inc_linenum[0]]90 # if type(st) == c_ast.Compound:91 # st.block_items.remove(i)92 # st.block_items.append(assign)93 # st.block_items.append(gotost)94 # elif type(st) == c_ast.If and i == st.iftrue:95 # tempst = c_ast.Compound(block_items=[assign, gotost])96 # st.iftrue = tempst97 # elif type(st) == c_ast.If and i == st.iffalse:98 # tempst = c_ast.Compound(block_items=[assign, gotost])99 # st.iffalse = tempst100 # else:101 # if type(st) == c_ast.Case or type(st) == c_ast.Default:102 # st.stmts.remove(i)103 # st.stmts.append(assign)104 # st.stmts.append(gotost)105 # continue106 # else:107 # find_return(i, ret_name, gotost, funnamne)108 # else:109 # for child in st:110 # if type(child) == c_ast.Return:111 # assign = c_ast.Assignment(op='=', lvalue=c_ast.ID(name=ret_name), rvalue=child.expr)112 # if type(child.expr) == c_ast.FuncCall:113 # lineinfo = str(child.coord)114 # index = lineinfo.index(":")115 # rindex = lineinfo.rindex(":")116 # linenum = int(lineinfo[index + 1:rindex])117 # last_num = -1118 # inc_linenum = []119 # get_last_linenum(child, last_num, inc_linenum)120 # global_return_sta[funnamne][linenum] = [assign, inc_linenum[0]]121 # if type(st) == c_ast.Compound:122 # st.block_items.remove(child)123 # st.block_items.append(assign)124 # st.block_items.append(gotost)125 # else:126 # if type(st) == c_ast.Case or type(st) == c_ast.Default:127 # st.stmts.remove(child)128 # st.stmts.append(assign)129 # st.stmts.append(gotost)130 # continue131 # else:132 # find_return(child, ret_name, gotost, funnamne)133def deal_return(rast, funnamne, return_val):134 """135 进行return归一化操作,将函数中的return语句替换为赋值语句,并添加label136 :param rast: 对应于函数的ast137 :param funnamne: 函数名138 :return_val:list,存放为每个函数定义的返回值变量139 :return: 无140 """141 if funnamne == "ssl_add_clienthello_tlsext":142 print("funast....")143 print(rast)144 # rast is a funast145 print("return_name....")146 ret_name = funnamne + "_return_"147 labelname = funnamne + "_label_"148 gotost = c_ast.Goto(name=labelname)149 returntype = rast.decl.type.type150 if type(returntype) == c_ast.TypeDecl:151 returnname = returntype.type.names[0]152 temptype = c_ast.TypeDecl(declname=ret_name, quals=[], type=c_ast.IdentifierType(names=[returnname]))153 elif type(returntype) == c_ast.PtrDecl:154 returnname = returntype.type.type.names[0]155 temptype = c_ast.PtrDecl(quals=[], type=c_ast.TypeDecl(declname=ret_name, quals=[],156 type=c_ast.IdentifierType(names=[returnname])))157 else:158 print(rast.decl)159 returnname = returntype.type.type.names[0]160 if returnname == 'void':161 pass162 else:163 global_return_sta[funnamne] = {}164 returnsta = c_ast.Decl(name=ret_name, quals=[], storage=[], funcspec=[], type=temptype, init=None,165 bitsize=None)166 # rast.body.block_items.insert(0, returnsta)167 global_return_decl[funnamne]=returnsta168 return_val.append(returnsta)169 # deal_last_return(rast,ret_name)170 if type(rast.body.block_items[-1])==c_ast.Label and type(rast.body.block_items[-1].stmt)==c_ast.Return:171 find_return(rast.body.block_items[-1],ret_name,gotost,funnamne,None)172 for s in rast.body.block_items:173 if type(s)==c_ast.Label:174 print("labal....")175 print(s)176 if type(s) == c_ast.Return:177 assign = c_ast.Assignment(op='=', lvalue=c_ast.ID(name=ret_name), rvalue=s.expr)178 if type(s.expr) == c_ast.FuncCall:179 lineinfo = str(s.coord)180 index = lineinfo.index(":")181 rindex = lineinfo.rindex(":")182 linenum = int(lineinfo[index + 1:rindex])183 last_num = -1184 inc_linenum = []185 get_last_linenum(s, last_num, inc_linenum)186 global_return_sta[funnamne][linenum] = [assign, inc_linenum[0]]187 index=rast.body.block_items.index(s)188 rast.body.block_items.remove(s)189 rast.body.block_items.insert(index,assign)190 index=index+1191 rast.body.block_items.insert(index,gotost)192 else:193 find_return(s, ret_name, gotost, funnamne,None)194 """添加label"""195 labelname = funnamne + "_label_"196 labelst = c_ast.Label(name=labelname, stmt=c_ast.FuncCall(name=c_ast.ID(name="printf"), args=c_ast.ExprList(197 exprs=[c_ast.Constant(type="string", value='"##\\n"')])))198 rast.body.block_items.append(labelst)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful