From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,da9f9995bafb51df X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.204.156.18 with SMTP id u18mr99429bkw.3.1333793910937; Sat, 07 Apr 2012 03:18:30 -0700 (PDT) Path: h15ni95986bkw.0!nntp.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!news2.euro.net!newsfeed.freenet.ag!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 07 Apr 2012 12:18:32 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Assigning a "subclass" instance to a "superclass" variable References: In-Reply-To: Message-ID: <4f801475$0$6570$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 07 Apr 2012 12:18:29 CEST NNTP-Posting-Host: 46f9db0b.newsspool3.arcor-online.net X-Trace: DXC=id[lcJ]QNG@=8m7nZkdN^@McF=Q^Z^V3H4Fo<]lROoRA8kFejVH On 06.04.12 22:49, deuteros wrote: > I'm still trying to understand how Ada does object orientation. Just for completeness, type Animal is... . / \ ยด ~ ` | type Dog is new Animal... Each type declaration is typically followed by a number of declarations of subprograms that take, or return, at least one argument of the preceding type. These subprograms become the primitive operations of the preceding type (its methods), overriding operations where the parent type has the "same" operation. Placing the type declarations in packages at all, in nested packages, in task bodies, in child packages, declaring them local to a procedure, etc ... is the programmer's choice: doing any of these will establish corresponding visibility of the types. So the key question might be where you want the types visible. > So in Ada I'm trying to achieve something similar with my Statement > package: > > package Statements is > > type Statement is abstract tagged > record > tokens : Vector; > executedtokens : Vector; > end record; > > type Statement_Access is access all Statement'Class; Do you need this pointer type right here or in any child packages of Statements, and in such a way that it is globally visible, and in scope everywhere Statement is? If so, do the pointers need to be pointing to non-constant Statement objects on the stack as well? If not, you could start by omitting the "all", or replace "all" by "constant". Insofar as tagged objects are by-reference types already, explicit pointers are rarely needed for "O-O effects". This is somewhat like Java, which, for O-O objects, passes references. (But needs "new" allocators when creating O-O objects, unlike Ada.) Pointers can become necessary in case one record type needs to have a component of any type from a hierarchy like Animal'Class. That's because the specific type isn't known yet: could be Dog, Pig, Hound_Dog, Spider, ..., but the compiler needs to establish the 'Size of the record type, hence indirection because a pointer has a known size. It's like declaring a field of type Animal in a Java class and assigning it a Dog object reference, or Pig object reference, etc. > So when I create a child of Statement, how to I set up the .ads file? As said, you do not even need to put a child type in its own package. If you choose to pick from the setups Simon has shown, and if such a package should be translated with GCC, the default method requires file names to be "expressions.ads" and "statements-expressions.ads", respectively.