PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/test/language/unclassified/position/aux_position.e

http://github.com/tybor/Liberty
Specman e | 121 lines | 77 code | 8 blank | 36 comment | 5 complexity | 41510e1bfb757e7890eefc9e7b568818 MD5 | raw file
  1-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries.
  2-- See the Copyright notice at the end of this file.
  3--
  4expanded class AUX_POSITION
  5   --
  6   -- To test the True POSITION class of the compiler.
  7   --
  8
  9insert
 10   PLATFORM
 11   ANY
 12
 13feature {ANY}
 14   line: INTEGER
 15         -- The corresponding `line' number in the source file or 0
 16         -- when `is_unknown'.
 17      local
 18         bit: INTEGER_32
 19      do
 20         if mangling.bit_test(0) then
 21            bit := mangling |>> 1
 22            bit := bit.bit_and(0x00007fff)
 23         else
 24            bit := mangling |>> 8
 25            bit := bit.bit_and(0x00001fff)
 26         end
 27         Result := bit
 28      ensure
 29         not is_unknown implies Result >= 0
 30      end
 31
 32   column: INTEGER
 33         -- The `column' number in the source file or 0 when `is_unknown' or
 34         -- when there is not enough space in `mangling' for the `column'.
 35      local
 36         bit: INTEGER_32
 37      do
 38         if mangling.bit_test(0) then
 39            -- Result is 0 because `column' is not memorized.
 40         else
 41            bit := mangling |>> 1 -- To drop the flag.
 42            bit := bit.bit_and(0x0000007f)
 43            Result := bit
 44         end
 45      ensure
 46         Result >= 0
 47      end
 48
 49   is_unknown: BOOLEAN
 50         -- True when the `eiffel_parser' as called `set'.
 51      do
 52         Result := mangling = 0
 53      end
 54
 55   set (li, co: INTEGER; class_id: INTEGER_16)
 56      require
 57         li >= 1
 58         co >= 1
 59         class_id >= 0
 60      local
 61         l, c, i: INTEGER
 62      do
 63         check
 64            Integer_bits >= 32
 65         end
 66         if class_id <= 2047 and then li <= 8191 and then co <= 127 then
 67            mangling := class_id.to_integer_32 |<< 21 -- 11 bits for `id'
 68            mangling := mangling | (li |<< 8) -- 13 bits for `line'
 69            mangling := mangling | (co |<< 1) -- 7  bits for `column'
 70         else
 71            -- The `column' is not memorized.
 72            mangling := class_id.to_integer_32 |<< 17 -- 15 bits for `id'
 73            mangling := mangling | (li |<< 1) -- 16 bits for `line'
 74            mangling := mangling | 1 -- forget `column'.
 75         end
 76         l := line
 77         c := column
 78         i := id
 79      ensure
 80         line = li
 81         id = class_id
 82         column = 0 or else column = co
 83      end
 84
 85   mangling: INTEGER_32
 86         -- In order to save memory (there are a lot of objects like `Current'),
 87         -- the `id' of the class, the `line' and the `column' are saved in this
 88         -- BIT sequence. Two mangling are used, and the `column' may be
 89         -- dropped (not memorized, see `set'). This implementation assume
 90         -- that `Integer_bits' is greater or equal to 32.
 91
 92   id: INTEGER_16
 93      do
 94         if mangling.bit_test(0) then
 95            Result := (mangling |>>> 17).low_16
 96         else
 97            Result := (mangling |>>> 21).low_16
 98         end
 99      ensure
100         Result >= 0
101      end
102
103end -- class AUX_POSITION
104--
105-- ------------------------------------------------------------------------------------------------------------------------------
106-- Copyright notice below. Please read.
107--
108-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
109-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
110-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
111-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
112-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
113-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
114--
115-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
116-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
117--
118-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
119--
120-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
121-- ------------------------------------------------------------------------------------------------------------------------------