]>
Commit | Line | Data |
---|---|---|
cacbc350 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- S Y S T E M . V A L _ L L I -- | |
6 | -- -- | |
84fdd8a3 | 7 | -- B o d y -- |
cacbc350 | 8 | -- -- |
748086b7 | 9 | -- Copyright (C) 1992-2009, Free Software Foundation, Inc. -- |
cacbc350 RK |
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- -- | |
748086b7 | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
cacbc350 RK |
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 -- | |
748086b7 JJ |
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/>. -- | |
cacbc350 RK |
26 | -- -- |
27 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 28 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
cacbc350 RK |
29 | -- -- |
30 | ------------------------------------------------------------------------------ | |
31 | ||
32 | with System.Unsigned_Types; use System.Unsigned_Types; | |
33 | with System.Val_LLU; use System.Val_LLU; | |
34 | with System.Val_Util; use System.Val_Util; | |
35 | ||
36 | package body System.Val_LLI is | |
37 | ||
bfe7c10c BD |
38 | ---------------------------- |
39 | -- Scan_Long_Long_Integer -- | |
40 | ---------------------------- | |
cacbc350 RK |
41 | |
42 | function Scan_Long_Long_Integer | |
43 | (Str : String; | |
d90e94c7 | 44 | Ptr : not null access Integer; |
84fdd8a3 | 45 | Max : Integer) return Long_Long_Integer |
cacbc350 RK |
46 | is |
47 | Uval : Long_Long_Unsigned; | |
48 | -- Unsigned result | |
49 | ||
50 | Minus : Boolean := False; | |
51 | -- Set to True if minus sign is present, otherwise to False | |
52 | ||
53 | Start : Positive; | |
54 | -- Saves location of first non-blank (not used in this case) | |
55 | ||
56 | begin | |
57 | Scan_Sign (Str, Ptr, Max, Minus, Start); | |
bfe7c10c BD |
58 | |
59 | if Str (Ptr.all) not in '0' .. '9' then | |
60 | Ptr.all := Start; | |
61 | raise Constraint_Error; | |
62 | end if; | |
63 | ||
64 | Uval := Scan_Raw_Long_Long_Unsigned (Str, Ptr, Max); | |
cacbc350 RK |
65 | |
66 | -- Deal with overflow cases, and also with maximum negative number | |
67 | ||
68 | if Uval > Long_Long_Unsigned (Long_Long_Integer'Last) then | |
69 | if Minus | |
bfe7c10c BD |
70 | and then Uval = Long_Long_Unsigned (-(Long_Long_Integer'First)) |
71 | then | |
cacbc350 RK |
72 | return Long_Long_Integer'First; |
73 | else | |
74 | raise Constraint_Error; | |
75 | end if; | |
76 | ||
77 | -- Negative values | |
78 | ||
79 | elsif Minus then | |
80 | return -(Long_Long_Integer (Uval)); | |
81 | ||
82 | -- Positive values | |
83 | ||
84 | else | |
85 | return Long_Long_Integer (Uval); | |
86 | end if; | |
cacbc350 RK |
87 | end Scan_Long_Long_Integer; |
88 | ||
89 | ----------------------------- | |
90 | -- Value_Long_Long_Integer -- | |
91 | ----------------------------- | |
92 | ||
93 | function Value_Long_Long_Integer (Str : String) return Long_Long_Integer is | |
94 | V : Long_Long_Integer; | |
95 | P : aliased Integer := Str'First; | |
cacbc350 RK |
96 | begin |
97 | V := Scan_Long_Long_Integer (Str, P'Access, Str'Last); | |
98 | Scan_Trailing_Blanks (Str, P); | |
99 | return V; | |
cacbc350 RK |
100 | end Value_Long_Long_Integer; |
101 | ||
102 | end System.Val_LLI; |