OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [ada/] [s-valenu.adb] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 706 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT COMPILER COMPONENTS                         --
4
--                                                                          --
5
--                      S Y S T E M . V A L _ E N U M                       --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
10
--                                                                          --
11
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12
-- terms of the  GNU General Public License as published  by the Free Soft- --
13
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16
-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
17
--                                                                          --
18
-- As a special exception under Section 7 of GPL version 3, you are granted --
19
-- additional permissions described in the GCC Runtime Library Exception,   --
20
-- version 3.1, as published by the Free Software Foundation.               --
21
--                                                                          --
22
-- You should have received a copy of the GNU General Public License and    --
23
-- a copy of the GCC Runtime Library Exception along with this program;     --
24
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
27
-- GNAT was originally developed  by the GNAT team at  New York University. --
28
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
29
--                                                                          --
30
------------------------------------------------------------------------------
31
 
32
with Ada.Unchecked_Conversion;
33
with System.Val_Util; use System.Val_Util;
34
 
35
package body System.Val_Enum is
36
 
37
   -------------------------
38
   -- Value_Enumeration_8 --
39
   -------------------------
40
 
41
   function Value_Enumeration_8
42
     (Names   : String;
43
      Indexes : System.Address;
44
      Num     : Natural;
45
      Str     : String)
46
      return    Natural
47
   is
48
      F : Natural;
49
      L : Natural;
50
      S : String (Str'Range) := Str;
51
 
52
      type Natural_8 is range 0 .. 2 ** 7 - 1;
53
      type Index_Table is array (Natural) of Natural_8;
54
      type Index_Table_Ptr is access Index_Table;
55
 
56
      function To_Index_Table_Ptr is
57
        new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr);
58
 
59
      IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes);
60
 
61
   begin
62
      Normalize_String (S, F, L);
63
 
64
      for J in 0 .. Num loop
65
         if Names
66
           (Natural (IndexesT (J)) ..
67
            Natural (IndexesT (J + 1)) - 1) = S (F .. L)
68
         then
69
            return J;
70
         end if;
71
      end loop;
72
 
73
      raise Constraint_Error;
74
   end Value_Enumeration_8;
75
 
76
   --------------------------
77
   -- Value_Enumeration_16 --
78
   --------------------------
79
 
80
   function Value_Enumeration_16
81
     (Names   : String;
82
      Indexes : System.Address;
83
      Num     : Natural;
84
      Str     : String)
85
      return    Natural
86
   is
87
      F : Natural;
88
      L : Natural;
89
      S : String (Str'Range) := Str;
90
 
91
      type Natural_16 is range 0 .. 2 ** 15 - 1;
92
      type Index_Table is array (Natural) of Natural_16;
93
      type Index_Table_Ptr is access Index_Table;
94
 
95
      function To_Index_Table_Ptr is
96
        new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr);
97
 
98
      IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes);
99
 
100
   begin
101
      Normalize_String (S, F, L);
102
 
103
      for J in 0 .. Num loop
104
         if Names
105
           (Natural (IndexesT (J)) ..
106
            Natural (IndexesT (J + 1)) - 1) = S (F .. L)
107
         then
108
            return J;
109
         end if;
110
      end loop;
111
 
112
      raise Constraint_Error;
113
   end Value_Enumeration_16;
114
 
115
   --------------------------
116
   -- Value_Enumeration_32 --
117
   --------------------------
118
 
119
   function Value_Enumeration_32
120
     (Names   : String;
121
      Indexes : System.Address;
122
      Num     : Natural;
123
      Str     : String)
124
      return    Natural
125
   is
126
      F : Natural;
127
      L : Natural;
128
      S : String (Str'Range) := Str;
129
 
130
      type Natural_32 is range 0 .. 2 ** 31 - 1;
131
      type Index_Table is array (Natural) of Natural_32;
132
      type Index_Table_Ptr is access Index_Table;
133
 
134
      function To_Index_Table_Ptr is
135
        new Ada.Unchecked_Conversion (System.Address, Index_Table_Ptr);
136
 
137
      IndexesT : constant Index_Table_Ptr := To_Index_Table_Ptr (Indexes);
138
 
139
   begin
140
      Normalize_String (S, F, L);
141
 
142
      for J in 0 .. Num loop
143
         if Names
144
           (Natural (IndexesT (J)) ..
145
            Natural (IndexesT (J + 1)) - 1) = S (F .. L)
146
         then
147
            return J;
148
         end if;
149
      end loop;
150
 
151
      raise Constraint_Error;
152
   end Value_Enumeration_32;
153
 
154
end System.Val_Enum;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.