qiezi的学习园地

AS/C/C++/D/Java/JS/Python/Ruby

  C++博客 :: 首页 :: 新随笔 ::  ::  :: 管理 ::

What's New for D 0.141

Dec 1, 2005

New/Changed Features

  • The predefined version identifier D_InlineAsm has been changed to D_InlineAsm_X86. The former made no sense, and although it is still defined, it is deprecated.
  • Added D code coverage analyzer.
  • Added .mangleof property for types, which gives the 'mangled' type name as a string.

Bugs Fixed



其中“D代码覆盖分析器”应该是很多人感兴趣的东西了,下面是一个例子(摘自http://digitalmars.com/d/code_coverage.html):

/* Eratosthenes Sieve prime number calculation. */
 
bit flags[
8191];
 
int main()
{   
int     i, prime, k, count, iter;

    printf(
"10 iterations\n");
    
for (iter = 1; iter <= 10; iter++)
    {    count 
= 0;
    flags[] 
= true;
    
for (i = 0; i < flags.length; i++)
    {   
if (flags[i])
        {    prime 
= i + i + 3;
        k 
= i + prime;
        
while (k < flags.length)
        {
            flags[k] 
= false;
            k 
+= prime;
        }
        count 
+= 1;
        }
    }
    }
    printf (
"\n%d primes\n", count);
    
return 0;
}

编译、运行:
dmd sieve -cov
sieve
结果如下:
       |/* Eratosthenes Sieve prime number calculation. */
       |
       |bit flags[8191];
       |
       |int main()
      5|{   int     i, prime, k, count, iter;
       |
      1|    printf("10 iterations\n");
     22|    for (iter = 1; iter <= 10; iter++)
     10|    {   count = 0;
     10|        flags[] = true;
163840|        for (i = 0; i < flags.length; i++)
  81910|        {   if (flags[i])
  18990|            {   prime = i + i + 3;
  18990|                k = i + prime;
168980|                while (k < flags.length)
       |                {
149990|                    flags[k] = false;
149990|                    k += prime;
       |                }
  18990|                count += 1;
       |            }
       |        }
       |    }
      1|    printf ("\n%d primes\n", count);
      1|    return 0;
       |}
sieve.d is 100% covered

另一个惊喜是mangleof属性,可以得到一个类型被编译器mangle后的名字。不知道mangle对应的中文翻译是什么?大概是“名字转换”吧。一点测试代码:
import std.stdio;

void test();

void test1(int n);

void test2(int n);


void main()
{
    
void function (intchar[]) f;
    
void function (int) f1;
    
void function () f2;
    writefln (f.mangleof);
    writefln (f1.mangleof);
    writefln (f2.mangleof);
    writefln (
int.mangleof);
    
float a;
    writefln (a.mangleof);
    writefln ((
&test).mangleof);
    writefln ((
&test1).mangleof);
    writefln ((
&test2).mangleof);
    writefln (
void.mangleof);
}
编译执行结果如下:
PFiAaZv
PFiZv
PFZv
i
f
PFZv
PFiZv
PFiZv
v
posted on 2005-12-06 10:41 qiezi 阅读(754) 评论(4)  编辑 收藏 引用 所属分类: 学习方向D