返回介绍

23.3 typename函数

发布于 2020-09-09 22:55:57 字数 2218 浏览 952 评论 0 收藏 0

typename_function ::=        // 没有包含在附录A中
    $typename(expression)
  | $typename(data_type)

语法 23-2 — typename函数语法(没有包含在附录A中)

$typename系统函数返回一个代表其自变量的解析类型的字符串。

The return string is constructed in the following steps:

  1. A typedef that creates an equivalent type is resolved back to built-in or user defined types.
  2. The default signing is removed, even if present explicitly in the source
  3. System generated names are created for anonymous structs, unions and enums.
  4. A ‘$’ is used as the placeholder for the name of an anonymous unpacked array.
  5. Actual encoded values are appended with numeration named constants.
  6. User defined type names are prefixed with their defining package or scope namespace.
  7. Array ranges are represented as unsized decimal numbers.
  8. Whitespace in the source is removed and a single space is added to separate identifiers and keywords from each other.
This process is similar to the way that type equality is computed, except that array ranges and built-in equivalent types are not normalized in the generated string. Thus $typename can be used in string comparisons for stricter type-checking of arrays than $typeof.

When called with an expression as its argument, $typename returns a string that represents the self-determined type result of the expression. The expression's return type is determined during elaboration but never evaluated. When used as an elaboration time constant, the expression shall not contain any hierarchical identifiers or references to elements of dynamic objects.

// source code // $typename would return
typedef bit node; // "bit"
node signed [2:0] X; // "bit signed[2:0]"
int signed Y; // "int"

package A;
    enum {A,B,C=99} X; // "enum{A=32’d0,B=32’d1,C=’32bX}A::e$1"
    typedef bit [9:1’b1] word // "A::bit[9:1]"
endpackage : A

import A:.*;

module top;
    typedef struct {node A,B;} AB_t;
    AB_t AB[10]; // "struct{bit A;bit B;}top.AB_t$[0:9]"
    ...
endmodule

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文