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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,dda6cdc6d53fb10d X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!nntp.giganews.com!local1.nntp.ash.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 30 Apr 2004 19:28:55 -0500 Date: Fri, 30 Apr 2004 20:28:54 -0400 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Type detection References: <409243DA.2000906@noos.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: NNTP-Posting-Host: 24.147.90.114 X-Trace: sv3-jsaBEomAo+B4Y69/S67Vp4NReuqEY43VhJu3Z9K+uVUhUqyqb64RAedqPSkzqCvo5uqOS5vMAgql+Z0!9ig697ZcM6n4/WvCSpZpP2mXQurmqsV3qKxKlapvWE1QIZSUJIA6eCPRPu96aQ== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: controlnews3.google.com comp.lang.ada:152 Date: 2004-04-30T20:28:54-04:00 List-Id: Bj�rn Persson wrote: > For the special case of distinguishing integer types from enumeration > types, I've been thinking of using something like this... I extended the idea a little further, but there is still some work to do. A character type is an enumeration type where at least one of the enumeration values is a character literal. So the test for enumeration types could be extended with a loop. Since a boolean type is either Boolean or a type derived from it, I guess checking that 'Size = 1 and that the literals are TRUE and FALSE should be close enough. ------------------------------------------------------------------------- with Ada.Text_IO; with Ada.Characters.Handling; procedure Datatype is generic type Unknown is (<>); function Find_Datatype return String; function Find_Datatype return String is begin if Ada.Characters.Handling.Is_Letter (Unknown'Image(Unknown'First)(1)) then return "Enumeration"; elsif Unknown'Pos( Unknown'Base'First) < 0 then return "Integer"; elsif Unknown'Pos(Unknown'Base'First) = 0 then begin if Unknown'Succ(Unknown'Last) = Unknown'First then return "Unsigned"; else return "Enumeration?"; end if; exception when others => return "Enumeration too"; -- It's an enumeration. end; else return "Unknown Type"; end if; end Find_Datatype; type Unsigned_16 is mod 2**16; type Weekday is (Monday, Tuesday, Wednesday, Thursday, Friday); function Find_Boolean is new Find_Datatype(Boolean); function Find_Integer is new Find_Datatype(Integer); function Find_Character is new Find_Datatype(Character); function Find_Unsigned is new Find_Datatype(Unsigned_16); function Find_Enumeration is new Find_Datatype(Weekday); begin Ada.Text_IO.Put_Line(" Find_Boolean returned " & Find_Boolean); Ada.Text_IO.Put_Line(" Find_Integer returned " & Find_Integer); Ada.Text_IO.Put_Line(" Find_Character returned " & Find_Character); Ada.Text_IO.Put_Line(" Find_Unsigned returned " & Find_Unsigned); Ada.Text_IO.Put_Line(" Find_Enumeration returned " & Find_Enumeration); end Datatype; -- Robert I. Eachus "The terrorist enemy holds no territory, defends no population, is unconstrained by rules of warfare, and respects no law of morality. Such an enemy cannot be deterred, contained, appeased or negotiated with. It can only be destroyed--and that, ladies and gentlemen, is the business at hand." -- Dick Cheney