⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slice.c

📁 一个很不错的程序切片工具,希望大家来讨论以下,对测试人员很有帮助
💻 C
📖 第 1 页 / 共 3 页
字号:
			if(is_bit_on (files[f].stmts[succ].active_local,					files[f].stmts[n].defs->id)){				return 1;			}			break;		case LIF_GDEF:			if (is_bit_on (files[f].stmts[succ].active_global,					files[f].stmts[n].defs->id)){				return 1;			}			break;		case LIF_CDEF:			{ int id,pid;			if(v_opt)				printf ("\ndef to chain %d\n",					files[f].stmts[n].defs->id);			chain_resolve_set (files[f].stmts[n].defs->id,proc);			while (chain_resolve_get(&id,&pid)){				if(v_opt)printf ("chain resolves to: %s\n",					pid?procs[pid].locals[id].name:					globals[id].name);				if (!pid || (pid == proc)){					if (is_bit_on(pid?files[f].stmts[succ].active_local:						files[f].stmts[succ].active_global,id)){										match = 1;						chain_resolve_path (f,n,proc);					}				}				else {				if (is_other_active (files[f].stmts[succ].active_other,					pid,id)){							match += add_to_id_set (								&files[f].stmts[n].active_other,pid,id);								chain_resolve_path (f,n,proc);				}				}			}						if (match){				id = chains[files[f].stmts[n].defs->id].id;				pid = chains[files[f].stmts[n].defs->id].pid;				if (pid == 0)					bit_on (files[f].stmts[n].active_global,id);				else if (pid == proc)					bit_on (files[f].stmts[n].active_local,id);				}				else {					if (is_other_active (files[f].stmts[succ].active_other,						pid,id)){						match += add_to_id_set (							&files[f].stmts[n].active_other,pid,id);						return match;				}			}			}			break;		default:;		}	}	else {		int		id,pid;		if(v_opt)print_base_state();		var_resolve_set (files[f].stmts[n].defs,proc);		while (var_resolve_get(&id,&pid)){			/*			printf ("resolves to: %s\n",pid?				procs[proc].locals[id].name: globals[id].name);			*/			if ((pid == 0) || (pid == proc)){				if (is_bit_on (pid?files[f].stmts[succ].active_local:						files[f].stmts[succ].active_global,id)){					var_resolve_path (f,n,proc);					match = 1;				}			}			else {				if (is_other_active (files[f].stmts[succ].active_other,					pid,id)){					match += add_to_id_set (						&files[f].stmts[n].active_other,pid,id);					return match;				}			}		}		if (match)			if (files[f].stmts[n].defs->code == LIF_GDEF)				bit_on (files[f].stmts[n].active_global,					files[f].stmts[n].defs->id);			else if (files[f].stmts[n].defs->code == LIF_DEF)				bit_on (files[f].stmts[n].active_local,					files[f].stmts[n].defs->id);	}	return match;}add_to_active (f,n,pid,id,proc_id)	int	f,n,pid,id,proc_id;{	bit_set	active;	is_id_valid (pid,id);	if(v_opt)printf ("add %s to active %d (L %d) of %s\n",		var_name(pid,id),n,files[f].stmts[n].froml,		procs[proc_id].proc_name);	if (proc_id == pid) active =		files[f].stmts[n].active_local;	else if (pid){		add_to_id_set (&files[f].stmts[n].active_other,pid,id);		return;	}	else active = files[f].stmts[n].active_global;	bit_on(active,id);}de_ref_chain (f,pid,refs,n)	var_ptr	refs;	int		pid,f,n;{	int		id,proc_id;	stmt_ptr stmt;	int		chain_id;	stmt = &files[f].stmts[n];	chain_resolve_set (refs->id,pid);	chain_id = refs->id;	add_to_active (f,n,pid,chains[chain_id].id,		chains[chain_id].pid);	while (chain_resolve_get (&id,&proc_id)){		if(v_opt)printf ("chain resolve to %d %d %s \n",id,proc_id,			var_name(proc_id,id));		if(v_opt)fflush(stdout);		chain_resolve_path (f,n,pid);		add_to_active (f,n,proc_id,id,pid);	}}de_ref_ref (f,pid,refs,n)	var_ptr	refs;	int		pid,f,n;{	int		id,proc_id;	stmt_ptr stmt;	stmt = &files[f].stmts[n];	if(v_opt)printf ("de ref %s %s in %s at %d\n",		refs->code == LIF_REF?"local":(refs->code == LIF_GREF?		"global":"???"),		refs->code == LIF_REF?procs[pid].locals[refs->id].name:		(refs->code == LIF_GREF?		globals[refs->id].name:"???"),		procs[pid].proc_name,stmt->froml);	if(v_opt)fflush(stdout);	var_resolve_set (refs,pid);	while (var_resolve_get (&id,&proc_id)){		if(v_opt)printf ("resolve to %d %d %s \n",id,proc_id,			var_name(proc_id,id));		fflush(stdout);		var_resolve_path (f,n,pid);		add_to_active (f,n,proc_id,id,pid);	}}int add_stmt_to_slice(pid,f,stmt,slice,succ)	int		pid,f,stmt;	stmt_ptr succ;	bit_set slice;{	int		already_in_slice = 0;	int		change = 0;	bit_set active;	id_set_ptr others;	int		at;	var_ptr	refs;	set_ptr	control;	if(v_opt)printf ("add stmt %d to slice  ",stmt);	if (is_bit_on (slice,stmt)) already_in_slice = 1;	else bit_on (slice,stmt);	if (already_in_slice) if(v_opt)printf ("already in ");	if(v_opt)printf ("\n");	if (!already_in_slice){		refs = files[f].stmts[stmt].refs;		while (refs){			switch (refs->code){			case LIF_REF:				bit_on (files[f].stmts[stmt].active_local,refs->id);				if (refs->level != 0)					de_ref_ref (f,pid,refs,stmt);				break;			case LIF_GREF:				bit_on(files[f].stmts[stmt].active_global,refs->id);				if (refs->level != 0)					de_ref_ref (f,pid,refs,stmt);				break;			case LIF_CREF:				de_ref_chain (f,pid,refs,stmt);				break;			default:;			}			refs = refs->next;		}		control = files[f].stmts[stmt].requires;		while (control){			if (!is_bit_on(slice,control->id)){				add_stmt_to_slice(pid,f,control->id,slice,(stmt_ptr)NULL);				if(v_opt)printf ("add %d required by %d\n",					control->id,stmt);			}			control = control -> next;		}	}	if (succ){		at = -1;		while ((at = get_next_member(succ->active_local,at)) >= 0){			if(!is_var_defed(&files[f].stmts[stmt],at,1)){				if (!is_bit_on(files[f].stmts[stmt].active_local,at)){					bit_on (files[f].stmts[stmt].active_local,at);					change += 1;				}			}		}		at = -1;		while ((at = get_next_member(succ->active_global,at)) >= 0){			if(!is_var_defed(&files[f].stmts[stmt],at,0)){				if (!is_bit_on(files[f].stmts[stmt].active_global,at)){					bit_on (files[f].stmts[stmt].active_global,at);					change += 1;				}			}		}		others = succ->active_other;		while(others){			change += add_to_id_set (&files[f].stmts[stmt].active_other,				others->pid,others->id);			others = others -> next;		}	}	return change + 1 - already_in_slice;}int pass_criteria (f,stmt,succ)	int		f,stmt,succ;{	int		change,c;	id_set_ptr active;	change = 0;	if (!bit_set_equal (files[f].stmts[stmt].active_global,						files[f].stmts[succ].active_global)){		change = cunion_bit_set (files[f].stmts[stmt].active_global,			files[f].stmts[succ].active_global);	}	if (!bit_set_equal (files[f].stmts[stmt].active_local,						files[f].stmts[succ].active_local)){		c = cunion_bit_set (files[f].stmts[stmt].active_local,			files[f].stmts[succ].active_local);		change += c;	}	active = files[f].stmts[succ].active_other;	while (active){		change += add_to_id_set (&files[f].stmts[stmt].active_other,			active->pid,active->id);		active = active -> next;	}	return change;}# define LINE 60print_active_stmt (f,proc,stmt,mark)	int		f,stmt,mark;{	stmt_ptr s;	int		k,var,n;	char	buff[100];	id_set_ptr active;		s = &files[f].stmts[stmt];		var = -1;		n = printf ("%3d%c:",stmt,mark?'*':' ');		/*		n = printf ("%3d%c:",stmt,is_bit_on(slice,stmt)?'*':' ');		*/		while ((var = get_next_member(s->active_global,var)) >= 0){			sprintf (buff," %s",globals[var].name);			k = strlen(buff);			if (k + n > LINE) {				printf ("\n");				n = printf ("    %s",buff);			}			else n += printf ("%s",buff);		}		var = -1;		n += printf (" & ");		while ((var = get_next_member(s->active_local,var)) >= 0){			sprintf (buff," %s",procs[proc].locals[var].name);			k = strlen(buff);			if (k + n > LINE) {				printf ("\n");				n = printf ("    %s",buff);			}			else n += printf ("%s",buff);		}		n += printf (" &+ ");		active = s->active_other;		while (active){			sprintf (buff," %s",var_name(active->pid,active->id));			/*			sprintf (buff," %s",procs[active->pid].locals[				active->id].name);				*/			k = strlen(buff);			if (k + n > LINE) {				printf ("\n");				n = printf ("    %s",buff);			}			else n += printf ("%s",buff);			active = active -> next;		}		printf ("\n");}void active_hook (fid,line)	int		fid,line;{	int		stmt,proc;	stmt = line_to_stmt(fid,line);	proc = stmt_to_proc (fid,stmt);	if (proc){		printf ("\nProcedure %s may define: ",procs[proc].proc_name);		print_proc_defs (0,proc);		printf ("\nline %d in %s ",line,procs[proc].proc_name);		print_active_stmt (fid,proc,stmt,0);	}	else {		printf ("can't find proc for file %d line %d\n",fid,line);	}}print_active (proc,slice)	int		proc;	bit_set slice;{	int		stmt;	char	buff[100];	int		k,var,n,f;	stmt_ptr s;	id_set_ptr active;	printf ("active sets for proc %s\n",procs[proc].proc_name);	f = procs[proc].file_id;	for (stmt = procs[proc].entry; stmt <= procs[proc].exit; stmt++){		print_active_stmt (f,proc,stmt,is_bit_on(slice,stmt));	}}print_all_active (slices,active)	bit_set		slices[],active;{	int			file,proc;	proc = -1;	while ((proc = get_next_member(active,proc)) >= 0){		file = procs[proc].file_id;		print_active (proc,slices[file]);	}}add_ptr_to_active (f,pid,ptr_id,stmt)	int	f,pid,stmt,ptr_id;{	int		ptr,var_id,proc_id;	set_ptr	a;	bit_set	active;	a = ptr_points_to(ptr_id);	while (a){		var_id = addrs[a->id].id;		proc_id = addrs[a->id].pid;		if (proc_id){			if (proc_id == pid)				active = files[f].stmts[stmt].active_local;			/* else add to other active */			else active = NULL;		}		else active = files[f].stmts[stmt].active_global;		if (active) bit_on (active,var_id);		ptr = proc_id?procs[proc_id].locals[var_id].ptr_id:			globals[var_id].ptr_id;		if(ptr)add_ptr_to_active (f,pid,ptr,stmt);		a = a -> next;	}}add_an_actual (from_pid,call,act)	call_ptr	call;	int			from_pid;	actual_ptr	act;{	int		pid,stmt,f;	var_ptr		refs;	stmt = call->stmt;	f = procs[from_pid].file_id;	pid = from_pid;	refs = act->actuals;	while(refs){		switch (refs->code){		case LIF_AREF:			if (addrs[refs->id].pid)				bit_on (files[f].stmts[stmt].active_local,					addrs[refs->id].id);			else				bit_on (files[f].stmts[stmt].active_global,					addrs[refs->id].id);			break;		case LIF_REF:			bit_on (files[f].stmts[stmt].active_local,refs->id);			if(v_opt)printf ("add actual %d %s\n",refs->id,				procs[from_pid].locals[refs->id].name);			if (procs[from_pid].locals[refs->id].is_pointer)				add_ptr_to_active (f,pid,					procs[from_pid].locals[refs->id].ptr_id,stmt);			break;		case LIF_GREF:			bit_on(files[f].stmts[stmt].active_global,refs->id);			if (refs->level != 0)				de_ref_ref (f,pid,refs,stmt);			break;		case LIF_CREF:			de_ref_chain (f,pid,refs,stmt);			break;		default:;		}		refs = refs->next;	}}add_actuals (from_pid,call)	call_ptr	call;	int			from_pid;{	int		pid,stmt,f;	actual_ptr	act;	var_ptr		refs;	stmt = call->stmt;	f = procs[from_pid].file_id;	pid = from_pid;	act = call->actuals;	while (act){		refs = act->actuals;		while(refs){			switch (refs->code){			case LIF_AREF:				if (addrs[refs->id].pid)					bit_on (files[f].stmts[stmt].active_local,						addrs[refs->id].id);				else					bit_on (files[f].stmts[stmt].active_global,						addrs[refs->id].id);				break;			case LIF_REF:				bit_on (files[f].stmts[stmt].active_local,refs->id);				if (refs->level != 0)					de_ref_ref (f,pid,refs,stmt);				break;			case LIF_GREF:				bit_on(files[f].stmts[stmt].active_global,refs->id);				if (refs->level != 0)					de_ref_ref (f,pid,refs,stmt);				break;			case LIF_CREF:				de_ref_chain (f,pid,refs,stmt);				break;			default:;			}			refs = refs->next;		}		act = act -> next;	}}actual_ptr	find_actual (call,n)	int		n;	call_ptr	call;{	actual_ptr	act;	act = call->actuals;	while (act){		if (act->actual_number == n) return act;		act = act -> next;	}	return NULL;}export_called_active (call,called_proc,calling_proc,calling_stmt)	int		calling_proc,called_proc;	int		calling_stmt;	call_ptr	call;{	int		f,fs,start;	int		at;	actual_ptr act;	id_set_ptr	others;	int		change;	start = procs[called_proc].entry;	f = procs[calling_proc].file_id;	fs = procs[called_proc].file_id;	union_bit_set (files[f].stmts[calling_stmt].active_global,		files[fs].stmts[start].active_global);	at = -1;	while ((at=get_next_member(files[fs].stmts[start].active_local,at))			>= 0){		if(v_opt)printf ("in call to %s need id %d (%s)\n",			procs[called_proc].proc_name,at,			procs[called_proc].locals[at].name);		act = find_actual (call,at);		if (act) add_an_actual (calling_proc,call,act);	}	others = files[fs].stmts[start].active_other;	while (others){		if (others->pid == calling_proc){				bit_on (files[f].stmts[calling_stmt].active_local,						others->id);		}		else {			change = add_to_id_set (				&files[f].stmts[calling_stmt].active_other,				others->pid,others->id);		}		others = others->next;	}}slice_across_call (final,slice_sets,call,proc,active)	int		proc;	bit_set	final[],slice_sets[];	bit_set	active;	call_ptr	call;{	int		pid;	int		f,fs;	set_ptr	r;	int		i,at;	id_set_ptr others;	int		change;	if(v_opt)printf ("slice across\n");	pid = call->pid;	if (is_bit_on (dont_descend,pid)) return;	f = procs[pid].file_id;	fs = procs[proc].file_id;	clear_active_proc(pid);	for (i = procs[pid].entry; i <= procs[pid].exit; i++)		bit_off (slice_sets[f],i);	/* if (!is_bit_on (active,pid)) */{		add_stmt_to_slice (pid,f,procs[pid].entry,slice_sets[f],(stmt_ptr)NULL);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -