有测试C程序的简洁的工具吗? [英] Is there a tool to test the conciseness of c program?

查看:134
本文介绍了有测试C程序的简洁的工具吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我要检查以下code是否可以更简洁与否:

For example I want to check whether the following code can be more concise or not:

for(i = 0; i < map->size; i++){
    if(0 < map->bucket[i].n){
        p = map->bucket[i].list;
        while(p){
            h = hash(p->key) % n;
            if(bucket[h].list){
                new_p = bucket[h].list;
                while(new_p->next)new_p = new_p->next;
                new_p->next = p;
                next = p->next;
                p->next = NULL;
                p = p->next;
            }
            else{
                bucket[h].list = p;
                bucket[h].n++;
                next = p->next;
                p->next = NULL;
                p = p->next;
            }   
        }
    }
}

是否有这类任务的任何工具?

Is there any tool for such kind of task?

这将是对我帮助很大。

推荐答案

您可以询问这里几件事情。你的问题的一个可能的跨pretation是您正在寻找的切片,一个工具,需要一个程序,并产生了一个选择从原来的程序中的指令的程序,那计算的部分或全部的原始的结果。换言之,一个限幅器将删除指令没有必要为您感兴趣的结果中的至少一个

You could be asking for several things here. One possible interpretation of your question is that you are looking for a slicer, a tool that takes a program and produces a program made of a selection of the instructions from the original program, and that computes some or all of the results of the original. In other words, a slicer removes that instructions that are not necessary for at least one of the results you are interested in.

有是为C程序的开源切片这里

There is an Open-Source slicer for C programs here.

有关使程序更简洁,从原来计划只保留指令,因为他们太强也许约束。您可能还需要允许不是保存或删除等一些转换。该切片机上面链接的框架是太提供了这种转变的一部分。例如:

For making programs more concise, perhaps the constraint of keeping only instructions from the original program as they are is too strong. You may also want to allow some transformations other than "keeping" or "removing". The framework that the slicer linked above is part of provides this kind of transformation too. For instance:

int main(int c, char **v)
{
  int x = 2;
  int y = x + c;
  return y; 
}

在上面的程序,指示preserve退出code不能删除任何指令的切片机:它们都有助于结果。但是,如果你先申请一个常量传播,转化其价值每不断前pression:

In the above program, a slicer instructed to preserve the exit code cannot remove any instruction: they all contribute to the result. But if you first apply a constant propagation, transforming every constant expression in its value:

int main(int c, char **v)
{
  int x = 2;
  int y = 2 + c;
  return y; 
}

然后,切片机可以在第二次删除无用的变量 X

int main(int c, char **v)
{
  int y = 2 + c;
  return y; 
}

这篇关于有测试C程序的简洁的工具吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆