* "limited with" packages @ 2007-06-20 13:20 adam.betts155 2007-06-20 15:38 ` Adam Beneschan 0 siblings, 1 reply; 10+ messages in thread From: adam.betts155 @ 2007-06-20 13:20 UTC (permalink / raw) I have the following code: --------------------------------------------------------------------------------------------------------------------------- with my_package; use my_package; package other_package is type type_one (<>) is private; type type_one_pointer is access constant type_one'class; function create (t_2: type_two'class) return type_one'class; ........ end other_package; --------------------------------------------------------------------------------------------------------------------------- limited with other_package; package my_package is type type_two is private; function get_type_one (t_2: type_two'class) return other_package.type_one_pointer; ......... end my_package --------------------------------------------------------------------------------------------------------------------------- package body my_package is function get_type_one (t_2: type_two'class) return other_package.type_one_pointer is t_one_ptr : other_package.type_one_pointer; begin t_one_ptr := new other_package.type_one'class'( other_package.create(t_2) ); end get_type_one; end my_package; --------------------------------------------------------------------------------------------------------------------------- However, I'm getting the error:"create" not declared in "other_package" which I do not understand as it does not complain about the types (type_one and type_one_pointer). Maybe it is my misunderstanding of the "limited with" clause. Any help much appreciated. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-20 13:20 "limited with" packages adam.betts155 @ 2007-06-20 15:38 ` Adam Beneschan 2007-06-20 16:06 ` adam.betts155 2007-06-20 16:27 ` adam.betts155 0 siblings, 2 replies; 10+ messages in thread From: Adam Beneschan @ 2007-06-20 15:38 UTC (permalink / raw) On Jun 20, 6:20 am, adam.betts...@gmail.com wrote: > I have the following code: > > --------------------------------------------------------------------------------------------------------------------------- > with my_package; use my_package; > package other_package is > type type_one (<>) is private; > type type_one_pointer is access constant type_one'class; > > function create (t_2: type_two'class) return type_one'class; > ........ > end other_package; > --------------------------------------------------------------------------------------------------------------------------- > limited with other_package; > package my_package is > type type_two is private; > > function get_type_one (t_2: type_two'class) return > other_package.type_one_pointer; > ......... > end my_package > --------------------------------------------------------------------------------------------------------------------------- > package body my_package is > > function get_type_one (t_2: type_two'class) return > other_package.type_one_pointer is > t_one_ptr : other_package.type_one_pointer; > begin > t_one_ptr := new > other_package.type_one'class'( other_package.create(t_2) ); > end get_type_one; > > end my_package; > --------------------------------------------------------------------------------------------------------------------------- > > However, I'm getting the error:"create" not declared in > "other_package" > > which I do not understand as it does not complain about the types > (type_one and type_one_pointer). Maybe it is my misunderstanding of > the "limited with" clause. Any help much appreciated. See 10.1.1(12.1-12.3). "limited with" gives you a limited view of a package; the only things you get in the limited view are types (and types inside nested packages), plus those types are viewed as if they were incomplete types, in essence. You don't get functions like "create". Put a regular "with other_package" on my_package's body: with other_package; package body my_package is...... -- Adam ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-20 15:38 ` Adam Beneschan @ 2007-06-20 16:06 ` adam.betts155 2007-06-20 16:32 ` Adam Beneschan 2007-06-20 16:27 ` adam.betts155 1 sibling, 1 reply; 10+ messages in thread From: adam.betts155 @ 2007-06-20 16:06 UTC (permalink / raw) On Jun 20, 4:38 pm, Adam Beneschan <a...@irvine.com> wrote: > On Jun 20, 6:20 am, adam.betts...@gmail.com wrote: > > > > > I have the following code: > > > --------------------------------------------------------------------------------------------------------------------------- > > with my_package; use my_package; > > package other_package is > > type type_one (<>) is private; > > type type_one_pointer is access constant type_one'class; > > > function create (t_2: type_two'class) return type_one'class; > > ........ > > end other_package; > > --------------------------------------------------------------------------------------------------------------------------- > > limited with other_package; > > package my_package is > > type type_two is private; > > > function get_type_one (t_2: type_two'class) return > > other_package.type_one_pointer; > > ......... > > end my_package > > --------------------------------------------------------------------------------------------------------------------------- > > package body my_package is > > > function get_type_one (t_2: type_two'class) return > > other_package.type_one_pointer is > > t_one_ptr : other_package.type_one_pointer; > > begin > > t_one_ptr := new > > other_package.type_one'class'( other_package.create(t_2) ); > > end get_type_one; > > > end my_package; > > --------------------------------------------------------------------------------------------------------------------------- > > > However, I'm getting the error:"create" not declared in > > "other_package" > > > which I do not understand as it does not complain about the types > > (type_one and type_one_pointer). Maybe it is my misunderstanding of > > the "limited with" clause. Any help much appreciated. > > See 10.1.1(12.1-12.3). "limited with" gives you a limited view of a > package; the only things you get in the limited view are types (and > types inside nested packages), plus those types are viewed as if they > were incomplete types, in essence. You don't get functions like > "create". Put a regular "with other_package" on my_package's body: > > with other_package; > package body my_package is...... > > -- Adam Really thanks. I've spent a couple of hours banging my head about this, in the end I programmed around it. I can't believe the solution is so simple. Not to make excuses but I'm relatively new to Ada (few months), and I'm trying to use most of the advanced features as my project requires it. I think I lack a thorough understanding of how the Ada compiler works. So, does the "limited with" clause only apply at the spec level? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-20 16:06 ` adam.betts155 @ 2007-06-20 16:32 ` Adam Beneschan 0 siblings, 0 replies; 10+ messages in thread From: Adam Beneschan @ 2007-06-20 16:32 UTC (permalink / raw) On Jun 20, 9:06 am, adam.betts...@gmail.com wrote: > Really thanks. I've spent a couple of hours banging my head about > this, in the end I programmed around it. I can't believe the solution > is so simple. Not to make excuses but I'm relatively new to Ada (few > months), and I'm trying to use most of the advanced features as my > project requires it. I think I lack a thorough understanding of how > the Ada compiler works. So, does the "limited with" clause only apply > at the spec level? You wouldn't want to use it on a body. "limited with" is a new feature of Ada. The purpose is to handle a situation where you want to write a package P1 that uses types declared in P2, and similarly P2 that uses types declared in P1. (You might have record structures in P1 and P2 that point to each other.) The problem was that you couldn't compile P1 without compiling P2 first, and you couldn't compile P2 without compiling P1 first, and you couldn't get a chicken until you had the egg first, and ... you get the idea. "limited with" was a solution to this. In your example, you can compile My_Package's spec without compiling Other_Package first; at some point, Other_Package will undergo a very simple scan just to see what type names are available, and My_Package's spec can then use those type names, but in a very restricted way---about the only thing you can do is to declare an access type that points to it. (In particular, I believe that your function declaration that returns a type_one_pointer is illegal, because the compiler won't know enough about type_one_pointer at that point. You'll need to move type_one_pointer to My_Package.) After you compile My_Package's spec, you can compile Other_Package, and then you can compile the bodies. Since Other_Package has been compiled by that time, there's no longer any need for a "limited with Other_Package"; at that point you will want to do a normal "with". I hope this helps give you a general idea of what's going on. -- Adam ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-20 15:38 ` Adam Beneschan 2007-06-20 16:06 ` adam.betts155 @ 2007-06-20 16:27 ` adam.betts155 2007-06-20 18:13 ` Adam Beneschan 1 sibling, 1 reply; 10+ messages in thread From: adam.betts155 @ 2007-06-20 16:27 UTC (permalink / raw) Adam Beneschan wrote: > On Jun 20, 6:20 am, adam.betts...@gmail.com wrote: > > I have the following code: > > > > --------------------------------------------------------------------------------------------------------------------------- > > with my_package; use my_package; > > package other_package is > > type type_one (<>) is private; > > type type_one_pointer is access constant type_one'class; > > > > function create (t_2: type_two'class) return type_one'class; > > ........ > > end other_package; > > --------------------------------------------------------------------------------------------------------------------------- > > limited with other_package; > > package my_package is > > type type_two is private; > > > > function get_type_one (t_2: type_two'class) return > > other_package.type_one_pointer; > > ......... > > end my_package > > --------------------------------------------------------------------------------------------------------------------------- > > package body my_package is > > > > function get_type_one (t_2: type_two'class) return > > other_package.type_one_pointer is > > t_one_ptr : other_package.type_one_pointer; > > begin > > t_one_ptr := new > > other_package.type_one'class'( other_package.create(t_2) ); > > end get_type_one; > > > > end my_package; > > --------------------------------------------------------------------------------------------------------------------------- > > > > However, I'm getting the error:"create" not declared in > > "other_package" > > > > which I do not understand as it does not complain about the types > > (type_one and type_one_pointer). Maybe it is my misunderstanding of > > the "limited with" clause. Any help much appreciated. > > See 10.1.1(12.1-12.3). "limited with" gives you a limited view of a > package; the only things you get in the limited view are types (and > types inside nested packages), plus those types are viewed as if they > were incomplete types, in essence. You don't get functions like > "create". Put a regular "with other_package" on my_package's body: > > with other_package; > package body my_package is...... > > -- Adam However, it now seems I have another issue, with similar code... --------------------------------------------------------------------------------------------------------------------------- with my_package; use my_package; package other_package is type type_one (<>) is private; function create (t_2: type_two'class) return type_one'class; ........ end other_package; --------------------------------------------------------------------------------------------------------------------------- limited with other_package; package my_package is type type_two is private; procedure get_type_one (t_2: in out type_two'class; t_1: out other_package.type_one'class); ......... end my_package --------------------------------------------------------------------------------------------------------------------------- package body my_package is procedure get_type_one (t_2: in out type_two'class; t_1: out other_package.type_one'class); begin t_1 := create(t_2); end get_type_one; end my_package; --------------------------------------------------------------------------------------------------------------------------- This time the compiler is complaining that: 1) procedure get_type_one in the package body of my_package is "not fully conformant with declaration" in the spec and that, 2) the type of t_1 does not match ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-20 16:27 ` adam.betts155 @ 2007-06-20 18:13 ` Adam Beneschan 2007-06-20 18:27 ` Anh Vo 0 siblings, 1 reply; 10+ messages in thread From: Adam Beneschan @ 2007-06-20 18:13 UTC (permalink / raw) On Jun 20, 9:27 am, adam.betts...@gmail.com wrote: > Adam Beneschan wrote: > > On Jun 20, 6:20 am, adam.betts...@gmail.com wrote: > > > I have the following code: > > > > --------------------------------------------------------------------------------------------------------------------------- > > > with my_package; use my_package; > > > package other_package is > > > type type_one (<>) is private; > > > type type_one_pointer is access constant type_one'class; > > > > function create (t_2: type_two'class) return type_one'class; > > > ........ > > > end other_package; > > > --------------------------------------------------------------------------------------------------------------------------- > > > limited with other_package; > > > package my_package is > > > type type_two is private; > > > > function get_type_one (t_2: type_two'class) return > > > other_package.type_one_pointer; > > > ......... > > > end my_package > > > --------------------------------------------------------------------------------------------------------------------------- > > > package body my_package is > > > > function get_type_one (t_2: type_two'class) return > > > other_package.type_one_pointer is > > > t_one_ptr : other_package.type_one_pointer; > > > begin > > > t_one_ptr := new > > > other_package.type_one'class'( other_package.create(t_2) ); > > > end get_type_one; > > > > end my_package; > > > --------------------------------------------------------------------------------------------------------------------------- > > > > However, I'm getting the error:"create" not declared in > > > "other_package" > > > > which I do not understand as it does not complain about the types > > > (type_one and type_one_pointer). Maybe it is my misunderstanding of > > > the "limited with" clause. Any help much appreciated. > > > See 10.1.1(12.1-12.3). "limited with" gives you a limited view of a > > package; the only things you get in the limited view are types (and > > types inside nested packages), plus those types are viewed as if they > > were incomplete types, in essence. You don't get functions like > > "create". Put a regular "with other_package" on my_package's body: > > > with other_package; > > package body my_package is...... > > > -- Adam > > However, it now seems I have another issue, with similar code... > > --------------------------------------------------------------------------------------------------------------------------- > with my_package; use my_package; > package other_package is > type type_one (<>) is private; > > function create (t_2: type_two'class) return type_one'class; > ........ > end other_package; > > --------------------------------------------------------------------------------------------------------------------------- > limited with other_package; > package my_package is > type type_two is private; > > procedure get_type_one (t_2: in out type_two'class; t_1: out > other_package.type_one'class); > ......... > end my_package > --------------------------------------------------------------------------------------------------------------------------- > package body my_package is > procedure get_type_one (t_2: in out type_two'class; t_1: out > other_package.type_one'class); > begin > t_1 := create(t_2); > end get_type_one; > end my_package; > > --------------------------------------------------------------------------------------------------------------------------- > > This time the compiler is complaining that: > 1) procedure get_type_one in the package body of my_package is "not > fully conformant with declaration" in the spec and that, > 2) the type of t_1 does not match I think that's a compiler bug. -- Adam ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-20 18:13 ` Adam Beneschan @ 2007-06-20 18:27 ` Anh Vo 2007-06-20 18:44 ` Adam Beneschan 2007-06-21 8:13 ` adam.betts155 0 siblings, 2 replies; 10+ messages in thread From: Anh Vo @ 2007-06-20 18:27 UTC (permalink / raw) On Jun 20, 11:13 am, Adam Beneschan <a...@irvine.com> wrote: > On Jun 20, 9:27 am, adam.betts...@gmail.com wrote: > > This time the compiler is complaining that: > > 1) procedure get_type_one in the package body of my_package is "not > > fully conformant with declaration" in the spec and that, > > 2) the type of t_1 does not match > > I think that's a compiler bug. I am not sure about that. The first thing to correct correct the syntax error as marked below package body my_package is procedure get_type_one (t_2: in out type_two'class; t_1: out other_package.type_one'class); -- syntax error here! begin t_1 := create(t_2); end get_type_one; end my_package; ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-20 18:27 ` Anh Vo @ 2007-06-20 18:44 ` Adam Beneschan 2007-06-21 8:13 ` adam.betts155 1 sibling, 0 replies; 10+ messages in thread From: Adam Beneschan @ 2007-06-20 18:44 UTC (permalink / raw) On Jun 20, 11:27 am, Anh Vo <anhvofrc...@gmail.com> wrote: > On Jun 20, 11:13 am, Adam Beneschan <a...@irvine.com> wrote: > > > On Jun 20, 9:27 am, adam.betts...@gmail.com wrote: > > > This time the compiler is complaining that: > > > 1) procedure get_type_one in the package body of my_package is "not > > > fully conformant with declaration" in the spec and that, > > > 2) the type of t_1 does not match > > > I think that's a compiler bug. > > I am not sure about that. The first thing to correct correct the > syntax error as marked below There were a number of errors that I just assumed didn't occur in the actual code he was trying to compile. You can't even get as far as he did without making type_one "tagged private", since 'Class in my_package's spec wouldn't be accepted on it. So I'm assuming that the code just wasn't typed into c.l.a correctly. -- Adam ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-20 18:27 ` Anh Vo 2007-06-20 18:44 ` Adam Beneschan @ 2007-06-21 8:13 ` adam.betts155 2007-06-22 5:10 ` Simon Wright 1 sibling, 1 reply; 10+ messages in thread From: adam.betts155 @ 2007-06-21 8:13 UTC (permalink / raw) On 20 Jun, 19:27, Anh Vo <anhvofrc...@gmail.com> wrote: > On Jun 20, 11:13 am, Adam Beneschan <a...@irvine.com> wrote: > > > On Jun 20, 9:27 am, adam.betts...@gmail.com wrote: > > > This time the compiler is complaining that: > > > 1) procedure get_type_one in the package body of my_package is "not > > > fully conformant with declaration" in the spec and that, > > > 2) the type of t_1 does not match > > > I think that's a compiler bug. > > I am not sure about that. The first thing to correct correct the > syntax error as marked below > > package body my_package is > procedure get_type_one (t_2: in out type_two'class; t_1: out > other_package.type_one'class); -- syntax error here! > begin > t_1 := create(t_2); > end get_type_one; > end my_package; Yeah sorry that was just a typo...I was just trying to produce a minimal example from my rather complex code, so it got a bit sloppy. In general my code compiles except for the error that I pointed out above in my last post. I'm thinking it is a compiler bug ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: "limited with" packages 2007-06-21 8:13 ` adam.betts155 @ 2007-06-22 5:10 ` Simon Wright 0 siblings, 0 replies; 10+ messages in thread From: Simon Wright @ 2007-06-22 5:10 UTC (permalink / raw) adam.betts155@gmail.com writes: > Yeah sorry that was just a typo...I was just trying to produce a > minimal example from my rather complex code, so it got a bit sloppy. I always try to check out this sort of thing with a minimal compilable example -- it makes things clearer to me and it's much easier to report the bug to the vendor (if indeed it is one!) ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2007-06-22 5:10 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2007-06-20 13:20 "limited with" packages adam.betts155 2007-06-20 15:38 ` Adam Beneschan 2007-06-20 16:06 ` adam.betts155 2007-06-20 16:32 ` Adam Beneschan 2007-06-20 16:27 ` adam.betts155 2007-06-20 18:13 ` Adam Beneschan 2007-06-20 18:27 ` Anh Vo 2007-06-20 18:44 ` Adam Beneschan 2007-06-21 8:13 ` adam.betts155 2007-06-22 5:10 ` Simon Wright
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox