【发布时间】:2021-01-15 16:10:31
【问题描述】:
我正在完全用 Ada 和 DSA 开发一个 DBMS(数据库管理软件)。 但是我遇到了一些问题;行被实现为文档(MongoDB 风格),它们是受保护的接口,然后在与受保护类型相同的包中实现。 我必须先把它变成一个接口,这样才能有一个远程访问类型(受保护的类型不能有远程访问类型,因为它们没有被标记)。 对于所有被覆盖的函数(但不是过程),我收到相同的消息:
safira-documents.ads:845:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:845:27: first formal of "Is_Version_Controlled" declared at line 737 must be of mode "in" or access-to-constant
safira-documents.ads:856:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:856:27: first formal of "Get_Contents" declared at line 753 must be of mode "in" or access-to-constant
safira-documents.ads:861:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:861:27: first formal of "Get_Version" declared at line 760 must be of mode "in" or access-to-constant
safira-documents.ads:880:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:880:27: first formal of "Has_Key" declared at line 785 must be of mode "in" or access-to-constant
safira-documents.ads:888:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:888:27: first formal of "Get_Value" declared at line 795 must be of mode "in" or access-to-constant
safira-documents.ads:900:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:900:27: first formal of "Get_Id" declared at line 810 must be of mode "in" or access-to-constant
safira-documents.ads:902:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:902:27: first formal of "Get_Location" declared at line 812 must be of mode "in" or access-to-constant
safira-documents.ads:904:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:904:27: first formal of "Database" declared at line 816 must be of mode "in" or access-to-constant
safira-documents.ads:906:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:906:27: first formal of "Collection" declared at line 820 must be of mode "in" or access-to-constant
safira-documents.ads:908:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:908:27: first formal of "Get_Creation_Time_As_Dictionary" declared at line 824 must be of mode "in" or access-to-constant
safira-documents.ads:911:27: illegal overriding of subprogram inherited from interface
safira-documents.ads:911:27: first formal of "Get_Last_Update_Time_As_Dictionary" declared at line 828 must be of mode "in" or access-to-constant
gprbuild: *** compilation phase failed
相关代码是这样的:
package Safira.Documents with Remote_Types, Spark_Mode => On, Elaborate_Body is
type Update_Value_Operation is
access procedure
(K : in Key;
V : in out Value);
type Base_Document is protected interface;
-- Documents live in Storage_Nodes only. Clients access them through remote
-- access types.
-- This allows them to be declared as protected types with trustworthy atomic
-- operations that won't corrupt their content.
type Base_Document_Xs is access all Base_Document'Class;
-- << Many subprograms for the interface here >>
protected type Document is new Base_Document with
overriding function Is_Version_Controlled return Boolean;
overriding procedure Set_Mirror
(N : in Nodename_String.Bounded_String);
overriding procedure Remove_From_Mirror
(N : in Nodename_String.Bounded_String);
overriding procedure Set_Contents
(D : in Dictionary'Class);
overriding function Get_Contents return Dictionary'Class;
overriding procedure Revert_To
(Version : in Document_Version);
overriding function Get_Version
(Version : in Document_Version)
return Dictionary'Class;
overriding procedure Delete_Version
(Version : in Document_Version);
overriding procedure Define_New_Origin
(From : in Document_Version);
overriding procedure Delete_Entire_History;
overriding procedure Clone_From
(Origin : access Document);
overriding procedure Clone_From
(Origin : access Document;
Version : in Document_Version);
overriding function Has_Key
(K : in Key)
return Boolean;
overriding procedure Set_Value
(K : in Key;
V : in Value'Class);
overriding function Get_Value
(K : in Key)
return Value'Class;
overriding procedure Update_Value
(K : in Key;
V : in Value'Class);
overriding procedure Update_Value
(K : in Key;
Op : in Update_Value_Operation);
overriding function Get_Id return Document_Id;
overriding function Get_Location return Nodename_String.Bounded_String;
overriding function Database return Blueprint_String.Bounded_String;
overriding function Collection return Blueprint_String.Bounded_String;
overriding function Get_Creation_Time_As_Dictionary
return Dictionary'Class;
overriding function Get_Last_Update_Time_As_Dictionary
return Dictionary'Class;
private
Contents : Dictionary;
end Document;
end Safira.Documents;
将那些access 参数转换为接口规范中的in 参数(显然)解决了这个问题。但我不知道这是否会破坏远程功能。我可以在互联网上找到的所有 Remote_Types 示例都使用了远程类型方法的访问参数。
显然,接口的函数需要访问常量参数(即实际参数),我没有要求它,所以我确定这是一些 Ada 默认的安全/安全功能。
现在...我可以在不破坏远程功能的情况下将access 参数更改为in 吗?如果没有,有没有办法避免这种默认行为(换句话说,让他们访问可变参数)?
我为 Remote_Types 找到的所有示例都使用了access 参数,所以我担心将它们转换为in 参数的解决方案可能会使它们成为普通(非远程)方法,这会使这个包在分布式中作为 Remote_Types 无用应用。我可以尝试使其成为 Pure,但不知道是否可以轻松完成。
P.S.:它应该在未来开源(当它准备好时),所以如果我真的需要,我现在可以发布整个文件或整个项目。 我不喜欢在项目准备好之前发布我的项目,但如果有必要让某人找到解决方案……我会这样做。
【问题讨论】:
标签: ada