From: "Pat Rogers" <progers@classwide.com>
Subject: Re: Looping over a tagged record?
Date: Thu, 21 Jun 2001 08:24:52 -0500
Date: 2001-06-21T08:24:52-05:00 [thread overview]
Message-ID: <LAmY6.890$Mz1.15447@nnrp1.sbc.net> (raw)
In-Reply-To: mailman.993114925.4754.comp.lang.ada@ada.eu.org
"M. A. Alves" <maa@liacc.up.pt> wrote in message
news:mailman.993114925.4754.comp.lang.ada@ada.eu.org...
> > > Often I also want to merge record and array i.e. have named _and_
> > > iteratable "components". Theoretically this comes down to "types as
> > > objects", which Ada doesn't have. Practically, a "standard" Ada idiom
for
> > > this is an heterogenous array indexed on an enumeration e.g. (not
tested):
> >
> > Could you please elaborate on exactly what you mean by "types as
objects"?
>
> Essentialy that you can manipulate types as you do objects. A language
> with less basic semantic devices. Types would be an elaboration of the
> programmer. A reflexive tower of 2 or 3 levels. Hardly a software
> engineering language. Roughly approximative model in Ada:
>
> type Object is ...
> procedure Add_Property(O: Object; Name: String);
> procedure Add_Property(O: Object; Name, Value: String);
> procedure Add_Property(O: Object; Name: String; Value: Object);
> ...
Reflection is indeed the right approach for doing this in general. A
working interface looks like this:
package OpenAda.MOP is
type Class is tagged limited private;
-- The idea is to represent the abstraction of a class, rather
-- than just a (tagged) type: a class is a tagged type with
-- an encapsulating package and primitive operations declared
-- within that package.
type Class_Reference is access all Class;
type Any_Class is access all Class'Class;
-- Introspection
-- Note these should be class-wide or otherwise non-primitive
-- since they are not intended to be overridden.
Introspection_Failure : exception;
function Class_For( Package_Name, Type_Name : Wide_String )
return Class_Reference;
-- Package_Name is that of a library package declaration.
-- Type_Name is that of a visibly tagged or extended type
-- exported by the package indicated by Package_Name.
-- Note the term 'primitive operation' is that of the Ada RM: the
-- primitive operations of a type are those subprograms that are
-- declared with the type in the same package and mention the type
-- in the parameter and result-type profile. See the RM Glossary.
function Visible_Primitives( This : access Class'Class )
return OpenAda.Syntax.Sequence.Reference;
-- Returns a list of pointers to either procedure or function
declarations
-- occurring in the visible part of the enclosing package declaration
function Hidden_Primitives( This : access Class'Class )
return OpenAda.Syntax.Sequence.Reference;
-- Returns a list of pointers to either procedure or function
declarations
-- occurring in the private part of the enclosing package declaration
function All_Primitives( This : access Class'Class )
return OpenAda.Syntax.Sequence.Reference;
-- Returns a list of pointers to either procedure or function
declarations
-- occurring anywhere in the enclosing package declaration
function Visible_Primitives( This : access Class'Class;
Named : Wide_String )
return OpenAda.Syntax.Sequence.Reference;
-- Returns a list of pointers to either procedure or function
declarations;
-- one for every primitive named 'Named' declared in the visible part of
-- the enclosing package declaration
function Hidden_Primitives( This : access Class'Class;
Named : Wide_String )
return OpenAda.Syntax.Sequence.Reference;
-- Returns a list of pointers to either procedure or function
declarations;
-- one for every primitive named 'Named' declared in the private part of
-- the enclosing package declaration
function Is_Primitive( This : access Class'Class;
Subprogram_Name : Wide_String )
return Boolean;
-- Returns True iff Subprogram_Name exists and is primitive, false
otherwise
function Is_Primitive( This : access Class'Class;
Subprogram : access
OpenAda.Syntax.Subprogram_Declaration.Node'Class )
return Boolean;
-- Returns True iff designated Subprogram is primitive, false otherwise
function Is_Primitive_Call( This : access Class'Class;
Call : access
OpenAda.Syntax.Procedure_Call.Node'Class )
return Boolean;
function Declared_Components( This : access Class'Class )
return OpenAda.Syntax.Sequence.Reference;
-- Returns a list of Component_Declaration.Reference or
-- Discriminant_Specification.Reference values, but not for
-- those components inhertied from ancestors (if any).
function Declared_Component( This : access Class'Class;
Named : Wide_String )
return OpenAda.Syntax.Any;
-- Returns null if no such component, otherwise returns either
-- a Component_Declaration.Reference or
Discriminant_Specification.Reference
function Is_Declared_Component( This : access Class'Class;
Component_Name : Wide_String )
return Boolean;
function Direct_Ancestor( This : access Class'Class )
return OpenAda.Syntax.Name.Any;
-- Returns null if not a derived type
function Is_Abstract( This : access Class'Class )
return Boolean;
function Is_Declared_Limited( This : access Class'Class )
return Boolean;
-- returns True iff the reserved word 'limited' appears in
-- the declaration of this type. Hence the type might be
-- limited if any ancestry is limited but we won't know.
function Primary_Type_Declaration( This : access Class'Class )
return OpenAda.Syntax.Type_Declaration.Any;
function Enclosing_Package( This : access Class'Class )
return OpenAda.Syntax.Package_Declaration.Any;
function Enclosing_Compilation_Unit( This : access Class'Class )
return OpenAda.Syntax.Compilation_Unit.Any;
function Corresponding_Body( This : access Class'Class )
return OpenAda.Syntax.Package_Body.Any;
function Corresponding_Body_Compilation_Unit( This : access Class'Class )
return OpenAda.Syntax.Compilation_Unit.Any;
function Corresponding_Body( This : access Class'Class;
Primitive :
OpenAda.Syntax.Subprogram_Declaration.Any )
return OpenAda.Syntax.Subprogram_Body.Any;
function Corresponding_Body( This : access Class'Class;
Primitive :
OpenAda.Syntax.Procedure_Declaration.Any )
return OpenAda.Syntax.Procedure_Body.Any;
function Corresponding_Body( This : access Class'Class;
Primitive :
OpenAda.Syntax.Function_Declaration.Any )
return OpenAda.Syntax.Function_Body.Any;
function Subject_Package_Name( This : access Class'Class )
return Wide_String;
function Subject_Type_Name( This : access Class'Class )
return Wide_String;
function Pragma_Metaclass_Parameters( This : access Class'Class )
return OpenAda.Pragma_Metaclass.Any_Content;
-- Only meaningful (non-null) when 'This' is set during translation.
-- Returns null if 'This' is loaded manually via function Class_For.
-- Intercession
Intercession_Failure : exception;
function Parsed_Input( This : access Class'Class )
return OpenAda.Syntax.Compilation.Any;
-- returns the parsed input from the input file, ie the sequence of
compilation items
and so forth....
next prev parent reply other threads:[~2001-06-21 13:24 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-19 20:39 Looping over a tagged record? M R Goodwin
2001-06-19 21:31 ` Pascal Obry
2001-06-19 21:32 ` Pascal Obry
2001-06-19 22:20 ` Samuel T. Harris
2001-06-19 23:45 ` mgoodwinSPAMMY
2001-06-20 1:33 ` Pat Rogers
2001-06-20 3:13 ` Pat Rogers
2001-06-20 2:58 ` DuckE
2001-06-20 13:15 ` Ted Dennison
2001-06-20 15:01 ` M. A. Alves
2001-06-21 2:36 ` DuckE
2001-06-21 10:14 ` M. A. Alves
2001-06-21 13:24 ` Pat Rogers [this message]
2001-06-21 17:08 ` Charles Hixson
2001-06-21 18:58 ` tmoran
2001-06-21 23:02 ` Charles Hixson
2001-06-22 19:04 ` B.Gaffney
2001-06-22 20:36 ` Pascal Obry
2001-06-22 2:18 ` DuckE
2001-06-22 17:33 ` Charles Hixson
2001-06-22 18:24 ` tmoran
2001-09-13 0:29 ` Gnat Windows load error tmoran
2001-09-13 18:15 ` Jerry van Dijk
2001-09-13 23:17 ` tmoran
2001-09-13 3:58 ` Ada web crawler tmoran
2001-11-17 21:50 ` ada.strings.bounded slice errors tmoran
2001-11-18 17:16 ` Florian Weimer
2001-11-18 19:31 ` tmoran
2001-11-19 7:12 ` Florian Weimer
2002-02-08 20:55 ` How to get a traceback in Gnat 3.14p tmoran
2002-02-08 21:24 ` Pascal Obry
2002-02-08 22:28 ` tmoran
2002-02-11 0:10 ` How to use gnatelim in Gnat 3.14p? tmoran
2002-02-15 17:23 ` does gnatelim work? tmoran
2002-02-15 18:18 ` Stephen Leake
2002-02-15 21:58 ` tmoran
2002-02-18 1:31 ` Stephen Leake
2002-04-15 3:05 ` Announce: .rc files with Gnat tmoran
2002-04-15 14:48 ` Ted Dennison
2002-05-25 7:06 ` slice'access? tmoran
2002-05-25 16:47 ` slice'access? Robert Dewar
2002-05-25 18:28 ` slice'access? tmoran
2002-05-25 20:20 ` slice'access? Jeffrey Carter
2002-05-25 23:39 ` slice'access? tmoran
2002-05-26 14:22 ` slice'access? Robert Dewar
2002-09-30 1:54 ` 'write of bounded string? tmoran
2002-09-30 16:06 ` Stephen Leake
2002-10-27 23:01 ` phone# etc bdean
2002-10-28 3:04 ` tmoran
2002-11-06 3:14 ` A little Ada app tmoran
2002-11-06 11:37 ` Larry Kilgallen
2002-11-06 15:08 ` Ted Dennison
2002-11-06 18:02 ` tmoran
2001-06-21 3:09 ` Looping over a tagged record? gresset1
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox