在Specman中,为什么我的宏观标签是代码主体返回垃圾的标签?

StackOverflow https://stackoverflow.com/questions/3774300

  •  04-10-2019
  •  | 
  •  

与这篇文章类似http://feedproxy.google.com/~r/cadence/community/blogs/fv/~3/ivdcila8_es/eventering-multiple-multiple-when-when-when-when-subtypes-simultanease.aspx

我想制作一个宏,以循环展开,以解决一些规格的问题和继承问题。

我首先是:

-- macros.e
<'
define <FOREACH_UNROLL'action> "FOREACH_UNROLL (<UNROLLEES>\[<unrollee'name>,...\]) (<STATEMENTS>{<statement>;...})" as computed {
   print <UNROLLEES>;
   print str_split(<UNROLLEES>,"/ *, */");
   for each in str_split(<UNROLLEES>,"/ *, */") {
      out(it.as_a(string));
      var statements := str_replace( <STATEMENTS>,"\"REPLACE_ME\"",it);
      result =appendf("%s %s;",result,statements);
   };
};
'>


-- main.e
<'
import macros.e
extend sys {
   run() is also {
      FOREACH_UNROLL [baz,foo,bar] {
         out("REPLACE_ME");
         out("part2","REPLACE_ME");
      };
   };
};
'>

当我运行这个时,我得到了:

specman -c 'load $HOME/main; test'
Welcome to Specman Elite(64) (08.20.007-s)  -  Linked on Tue Dec 15 17:07:26
2009

Protected by U.S. Patents 6,141,630 ;6,182,258; 6,219,809; 6,347,388;
6,487,704; 6,499,132; 6,502,232; 6,519,727; 6,530,054; 6,675,138; 6,684,359;
6,687,662; 6,907,599; 6,918,076; 6,920,583; Other Patents Pending.

0 notifications were modified by command 'set notify -severity=WARNING
DEPR_START_TCM_ARG_BY_REF'
Checking license ... OK
Loading macros.e   (imported by main.e) ...
read...parse...update...patch...h code...code...clean...
Loading /nfs/pdx/home/rbroger1/main.e ...
read...parse...  <UNROLLEES> = "[35]"
  str_split(<UNROLLEES>,"/ *, */") =
0.      "[35]"
[35]
update...patch...h code...code...clean...
Doing setup ...
Generating the test using seed 1...

Starting the test ...
Running the test ...
REPLACE_ME
part2REPLACE_ME
No actual running requested.
Checking the test ...
Checking is complete - 0 DUT errors, 0 DUT warnings.

如果您查看打印输出 <UNROLLEES>:

<UNROLLEES> = "[35]"

为什么 <UNROLLEES> 给我吗 [35] 而不是卷曲括号内的身体? 35是ASCII值 #, ,所以我不知所措,为什么我会得到35 ...

PS我意识到宏来自魔鬼,但我认为代码复制更糟。我必须这样做,因为规格不是真正的多态性。

有帮助吗?

解决方案

事实证明我需要使用该功能 str_expand_dots 在我的Specman版本(8.2)中。

这是修改后的宏:E:

define <FOREACH_UNROLL'action> "FOREACH_UNROLL (<UNROLLEES>\[<unrollee'name>,...\]) (<STATEMENTS>{<statement>;...})" as computed {
   -- print str_expand_dots(<UNROLLEES>);
   --print str_expand_dots(<STATEMENTS>);
   -- print str_split(str_expand_dots(<UNROLLEES>),"/ *, */");
   for each  in str_split(str_expand_dots(<UNROLLEES>),"/ *, */") {
      var unrollee := str_replace(it, "[","");
      unrollee = str_replace(unrollee, "]","");
      --out(unrollee);
      var statements := str_replace( str_expand_dots(<STATEMENTS>),"\"REPLACE_ME\"",unrollee);
      result =appendf("%s %s;",result,statements);
   };
};

修改后的main.e:

import macros;
extend sys {
   run() is also {
      FOREACH_UNROLL ["baz","foo","bar"] {
         out("REPLACE_ME");
         out("part2","REPLACE_ME");
         if "REPLACE_ME" == "baz" {
            out("found baz");
         };
      };
   };
};

和输出:

Welcome to Specman Elite(64) (08.20.007-s)  -  Linked on Tue Dec 15 17:07:26
2009

Protected by U.S. Patents 6,141,630 ;6,182,258; 6,219,809; 6,347,388;
6,487,704; 6,499,132; 6,502,232; 6,519,727; 6,530,054; 6,675,138; 6,684,359;
6,687,662; 6,907,599; 6,918,076; 6,920,583; Other Patents Pending.

0 notifications were modified by command 'set notify -severity=WARNING
DEPR_START_TCM_ARG_BY_REF'
Checking license ... OK
Loading /nfs/pdx/home/rbroger1/macros.e   (imported by main.e) ...
read...parse...update...patch...h code...code...clean...
Loading /nfs/pdx/home/rbroger1/main.e ...
read...parse...update...patch...h code...code...clean...
Doing setup ...
Generating the test using seed 1...

Starting the test ...
Running the test ...
baz
part2baz
found baz
foo
part2foo
bar
part2bar
No actual running requested.
Checking the test ...
Checking is complete - 0 DUT errors, 0 DUT warnings.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top