未记录的内在例程 [英] Undocumented intrinsic routines

查看:140
本文介绍了未记录的内在例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi具有此列表: Delphi内在例程

但是该列表是不完整

Delphi has this list: Delphi Intrinsic Routines
But that list is incomplete.

存在哪些无证的内在函数,因为它们的目的是什么时候和什么?

Which undocumented intrinsic functions exist, since when and what is their purpose?

推荐答案

我知道以下未记录的内在函数。

I know of the following undocumented intrinsic functions.

Delphi 2007:此处哈佛的博客

Delphi 2007: here and Hallvard's blog:

默认

function Default(T: Typeidentifier): value of T;     

返回类型标识符的零表示形式 T

Returns the zero representation of type identifier T.

在XE7测试版中介绍了以下内在函数:博客 Stefan Glienke

The following intrinsics introduced in XE7 are explained in the XE7 beta blog and by Stefan Glienke

IsManagedType

function IsManagedType(T: TypeIdentifier): Boolean;   

如果 T interface string 动态数组,或包含此类记录的记录。包含托管类型的类将返回false。

True if T is a interface, string or dynamic array, or a record containing such. A class containing a managed type will return false.

HasWeakRef

function HasWeakRef(T: TypeIdentifier): Boolean;    

不确定它的作用,它看起来只能在NextGen编译器中有用。

Unsure what it does, it looks to only be useful in the NextGen compiler.

GetTypeKind

function GetTypeKind(T: TypeIdentifier): TTypeKind;   

PTypeInfo(System.TypeInfo(T))^ .Kind; ,但是由于它是一个编译器,内在函数在compiletime中解析,而条件代码的计算结果为false将被编译器剥离。

Does the same thing as PTypeInfo(System.TypeInfo(T))^.Kind;, however because it is a compiler intrinsic the function is resolved at compiletime and conditional code that evaluates to false will be stripped by the compiler.

IsConstValue

function IsConstValue(const Value): Boolean;          

如果Value是常量,则为True,否则为false。

这有助于编译器,以消除死代码,因为该函数在编译时被评估。

这只适用于内联函数,它允许较短的生成代码。

True if Value is a constant, false if not.
This helps the compiler to eliminate dead code because the function is evaluated at compile time.
This is only useful in inline functions, where it allows for shorter generated code.

TypeInfo

function TypeInfo(T: typeindentifier): PTypeInfo;

这个函数不是没有这样的文档,但是未记录的是它是XE7之后的内在函数。

这意味着如果TypeInfo(T)= TypeInfo(byte)then ... 不会生成代码段任何代码,如果T不是一个字节,测试将在compiletime解析。

但编译时解析仅在通用例程中工作,只有在执行 if(TypeInfo T)= TypeInfo(sometype) test。

如果TypeInfo(byte)= TypeInfo(smallint)then
,则测试即使总是评估为false,也不会被消除。

也不会使用 TypeInfo(T)

This function is not undocumented as such, but what is undocumented is that it is an intrinsic function since XE7.
That means that the snippet if TypeInfo(T) = TypeInfo(byte) then ... does not generate any code if T is not a byte and the test will be resolved at compiletime.
However the compile-time resolution only works inside generic routines and only when doing a if (TypeInfo(T) = TypeInfo(sometype) test.
The test if TypeInfo(byte) = TypeInfo(smallint) then does not get eliminated even though it always evaluates to false.
Nor does other use of TypeInfo(T).

ReturnAddress

以下内容与returnaddress上的引发异常一起使用 construct。

The following are used with the raise exception at returnaddress construct.

function ReturnAddress(Expression): pointer;          //Delphi ?
function AddressOfReturnAddress(Expression): pointer; //Delphi ?

据我所知,您无法直接从用户代码调用它们。

And as far as I know you can't call them directly from user code.

IsConstValue的示例


type
   TFlavor = (Tasty, Nasty);
   TIntegerHelper = record helper for integer
     function GetSomething(Flavor: TFlavor): TPoint; inline;
   private
     function GetTastyPoint: TPoint;
     function GetNastyPoint: TPoint;
   end;
 
 function TIntegerHelper.GetSomething(Flavor: TFlavor): TPoint;
 begin
   if IsConstValue(Flavor) then begin
     if Flavor = Tasty then Result:= Self.GetTastyPoint
     else Result:= Self.GetNastyPoint;
   end else begin
     Assert(1=0, 'This function can only be called with constant parameters');
   end;
 end; 

procedure Test;
var
  pt: TPoint;
begin
  pt:= 100000.GetSomething(Tasty); 


此调用将被转换为GetTastyPoint,并且 if / then 序列将被链接器消除。

This call will get translated to GetTastyPoint and the if/then sequence will be eliminated by the linker.

这篇关于未记录的内在例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆