在Javac的源代码中,从类型到符号到其类型的遍历的目的是什么?

发布于 2025-02-03 12:41:57 字数 1210 浏览 1 评论 0原文

javac的源代码中,我看到了此形式的成语:

Type t = ...;

// Now let's say I want to, say, get its supertype. The idiom seems to be:
Object o = t.tsym.type.supertype_field;

// ...rather than:
Object o = t.supertype_field;

我知道某些type s and 符号 s s是循环依赖性。也就是说,例如,每个非编码> clasStype 具有classSymbol,每个非eRror classSymbol具有clasStype < /code>,即使从逻辑上类型的符号之前(在构造期间,所有内容都被扭曲以彼此指向)。

我还朦胧地理解,在编译过程中可能存在各种错误,因此给定的类型实际上可能是errortype,我想可能具有与之关联的不同信息。

通过说t.tsym.type.something而不仅仅是t.something,可以实现什么样的规范化?

如果(减少心理负载)我假装错误永远不存在(因此,clasStype s具有classSymbol s,反之亦然),什么时候有实质性的差异访问T.Somethingt.tsym.type.something

有一个具体示例共享/class/com/com/sun/tools/javac/code/types.java#l2531“ rel =“ nofollow noreferrer”> supertype(type) method 。

In the source code for javac, I have seen idioms of this form:

Type t = ...;

// Now let's say I want to, say, get its supertype. The idiom seems to be:
Object o = t.tsym.type.supertype_field;

// ...rather than:
Object o = t.supertype_field;

I understand that certain Types and Symbols are circular dependencies. That is, every non-error ClassType, for example, has a ClassSymbol, and every non-error ClassSymbol has a ClassType, even though logically types precede symbols (during construction everything is twiddled to point to each other).

I also understand hazily that there may be various errors during compilation such that a given Type may actually be an ErrorType and I suppose may have different information associated with it.

What kind of canonicalizing is being accomplished by saying t.tsym.type.something rather than just t.something?

If (to reduce mental load) I pretend that errors never exist (so all, say, ClassTypes have ClassSymbols and vice versa), when is there a substantive difference between accessing t.something and t.tsym.type.something?

There is a concrete example in the supertype(Type) method.

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

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

发布评论

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