Ada中类型/程序包别名的单独声明 [英] Separate declarations of types/packages aliases in Ada
问题描述
我想声明一些用户定义的编译器常量",以使我的规范文件尽可能保持常量".这在C ++中很常见,例如:
I would like to declare some "user-defined compiler-constants" to keep my specification files as "constant" as possible. This is something common in C++, e.g. :
// misc/config.hh
namespace misc
{
typedef std::shared_ptr<A> A_ptr;
namespace arch = ibmpc;
}
// misc/code.hh
#include "misc/config.hh"
namespace misc
{
void function p(A_ptr a);
}
哪个人会在Ada里?
-- misc.ads
package Misc is
use Types; ----> forbidden !
procedure P(A : A_Access);
end Misc;
-- misc-types.ads
package Misc.Types is
type A_Access is A'Access;
end Misc.Types;
这当然是行不通的,因为use
是上下文关键字...因此,我的问题是:在Ada中如何做具有相同结果的事情?
Of course this does not work since use
is a context keyword...hence my question : how is it possible to do something with the same results in Ada ?
推荐答案
我认为这是从C ++原始版本到Ada的合理映射:
I think this is a reasonable mapping from your C++ original to Ada:
首先,我认为文件misc.ads
中与您的namespace misc
相对应,
To start with, corresponding more-or-less, I think, to your namespace misc
, in file misc.ads
,
package Misc is
end Misc;
然后,与文件misc-config.ads
中的config.hh
相对应,
Then, corresponding to config.hh
, in file misc-config.ads
,
package Misc.Config is
type A is (For_Example, An_Enumeration);
type A_Access is access A;
end Misc.Config;
(当然,它也可以引用Misc
中的类型).然后,对应于code.hh
,在文件misc-code.ads
中,
(which could, of course, also reference types in Misc
). Then, corresponding to code.hh
, in file misc-code.ads
,
with Misc.Config;
package Misc.Code is
use Config;
procedure P (A : A_Access);
end Misc.Code;
就规范而言,个人而言我不会use Config;
-这会使确定定义内容的位置变得困难.请注意,您可以在显示的位置说出use Config;
或use Misc.Config;
,因为您是Misc
的孩子;在context子句中(也可以),您必须use Misc.Config;
.
Personally I wouldn’t use Config;
, at any rate in specs - it can make it difficult to work out where something is defined. Note, you can say use Config;
or use Misc.Config;
where shown, because you’re in a child of Misc
; in the context clause, which is also OK, you would have to use Misc.Config;
.
这篇关于Ada中类型/程序包别名的单独声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!