为什么这个 VHDL 函数中的括号前有一个撇号?

Why is there an apostrophe before a parenthesis in this VHDL function?

我是编写测试平台的新手,因此有很多新语法需要我学习。我一直在努力理解 "string" 之后的撇号的含义。

它似乎不是 here 的属性。另外,我从未在 VHDL 中看到撇号后有括号。

    procedure Shrink_line(L : inout LINE; pos : in integer)
is 
    variable old_L : LINE := L;
begin
    if pos > 1 then
        L := new string'(old_L(pos to old_L'high));
        Deallocate(old_L);
    end if;
end;

这是一个限定表达式。

IEEE 标准 1076-2008,9.3.5 限定表达式:

A qualified expression is a basic operation (see 5.1) that is used to explicitly state the type, and possibly the subtype, of an operand that is an expression or an aggregate."

qualified_expression ::=
       type_mark ' ( expression )
     | type_mark ' aggregate

此限定表达式说明了在过程中分配给 L 的分配器(9.3.7 分配器)的类型和子类型。

限定表达式的操作数是表达式old_L(pos to old_L'high)

它不是聚合,它不使用命名关联来区分它与具有单一选择的括号表达式(9.3.3 聚合)。

因为您没有使用覆盖表达式的引用,所以您可能不知道这个分配器可以做什么。创建一个 MCVE:

use std.textio.all;

entity foo is
end entity;

architecture fum of foo is

    procedure Shrink_line(L : inout LINE; pos : in integer) 
    is 
        variable old_L : LINE := L;
    begin
        if pos > 1 then
            L := new string'(old_L(pos to old_L'high));
            Deallocate(old_L);
        end if;
    end;

begin
    process
        variable L: LINE;
    begin
        write (L, string'("...shrinking violet"));
        Shrink_line(L, 14);
        writeline(OUTPUT,L);
        wait;
    end process;
end architecture;

运行 模拟中的这段代码提供了一个输出:

ghdl -a foo.vhdl
ghdl -e foo
ghdl -r foo
violet

输出来自 OUTPUT 的写入行(即文件 STD_OUTPUT(POSIX 说法中的标准输出)。

9.3.7 分配器,第 2 段:

The type of the object created by an allocator is the base type of the type mark given in either the subtype indication or the qualified expression. For an allocator with a subtype indication, the initial value of the created object is the same as the default initial value for an explicitly declared variable of the designated subtype. For an allocator with a qualified expression, this expression defines the initial value of the created object.

使用旧分配器的子类型约束创建新分配器从位置 pos 开始复制旧分配器中的字符串。

另一件需要注意的事情是,字符串左边界默认为 1。 Shrink_line 指望这一点。