1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries
--
-- SmartEiffel is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License, as published by the
-- Free Software Foundation; either version 2, or (at your option) any later
-- version.
-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-- more details. You should have received a copy of the GNU General Public
-- License along with SmartEiffel; see the file COPYING. If not, write to
-- the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-- MA 02111-1307, USA.
--
-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.
-- - University of Nancy 1 - FRANCE
-- Copyright(C) 2003: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne
-- - University of Nancy 2 - FRANCE
--
-- Dominique COLNET, Suzanne COLLIN, Olivier ZENDRA,
-- Philippe RIBET, Cyril ADRIAN
--
-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
--
class CP_INFO
--
-- Print a human readable version of a JVM *.class generated
-- by SmartEiffel.
--
inherit CP_INFO_TAGS
creation clear
feature {CP_INFO_VISITOR}
accept(visitor: CP_INFO_VISITOR) is
do
visitor.visit_cp_info(Current)
end
feature {PRINT_JVM_CLASS}
tag: CHARACTER; -- Must be one defined in CP_INFO_TAGS.
info: STRING; -- Contains the corresponding information.
feature {CONSTANT_POOL}
clear is
do
tag := Constant_empty
if info = Void then
!!info.make(4)
else
info.clear
end
end
is_tagged(tag_value: CHARACTER): BOOLEAN is
do
Result := tag = tag_value
end
feature
set_class(i: STRING) is
require
i.count = 2
do
tag := Constant_class
info.copy(i)
end
set_fieldref(i: STRING) is
require
i.count = 4
do
tag := Constant_fieldref
info.copy(i)
end
set_methodref(i: STRING) is
require
i.count = 4
do
tag := Constant_methodref
info.copy(i)
end
set_interface_methodref(i: STRING) is
require
i.count = 4
do
tag := Constant_interfacemethodref
info.copy(i)
end
set_string(str: STRING) is
require
str.count >= 2
local
i: INTEGER
c: CHARACTER
do
tag := Constant_string
info.clear
info.extend(str.item(1))
info.extend(str.item(2))
from
i := 3
until
i > str.count
loop
c := str.item(i)
if c = '%U' then
info.extend('%/192/')
info.extend('%/128/')
else
info.extend(c)
end
i := i + 1
end
end
set_integer(i: STRING) is
require
i.count = 4
do
tag := Constant_integer
info.copy(i)
end
set_float(i: STRING) is
require
i.count = 4
do
tag := Constant_float
info.copy(i)
end
set_long(i: STRING) is
require
i.count = 8
do
tag := Constant_long
info.copy(i)
end
set_double(i: STRING) is
require
i.count = 8
do
tag := Constant_double
info.copy(i)
end
set_name_and_type(i: STRING) is
require
i.count = 4
do
tag := Constant_name_and_type
info.copy(i)
end
set_utf8(i: STRING) is
require
i.count >= 2
do
tag := Constant_utf8
info.copy(i)
ensure
info.count = u2_to_integer(1) + 2
end
feature -- Testing :
is_class: BOOLEAN is
do
Result := tag = Constant_class
end
is_fieldref: BOOLEAN is
do
Result := tag = Constant_fieldref
end
is_methodref: BOOLEAN is
do
Result := tag = Constant_methodref
end
is_interface_methodref: BOOLEAN is
do
Result := tag = Constant_interfacemethodref
end
is_string: BOOLEAN is
do
Result := tag = Constant_string
end
is_integer: BOOLEAN is
do
Result := tag = Constant_integer
end
is_float: BOOLEAN is
do
Result := tag = Constant_float
end
is_long: BOOLEAN is
do
Result := tag = Constant_long
end
is_double: BOOLEAN is
do
Result := tag = Constant_double
end
is_name_and_type: BOOLEAN is
do
Result := tag = Constant_name_and_type
end
is_utf8: BOOLEAN is
do
Result := tag = Constant_utf8
end
feature
view_in(str: STRING) is
-- Append in `str' a human readable version.
-- Note: assume `constant_pool' is checked.
local
idx, length, i: INTEGER
do
inspect
tag
when Constant_class then
idx := u2_to_integer(1)
constant_pool.view_in(str,idx)
when Constant_fieldref then
idx := u2_to_integer(1)
constant_pool.view_in(str,idx)
str.extend('.')
idx := u2_to_integer(3)
constant_pool.view_in(str,idx)
when Constant_methodref then
idx := u2_to_integer(1)
constant_pool.view_in(str,idx)
str.extend('.')
idx := u2_to_integer(3)
constant_pool.view_in(str,idx)
when Constant_interfacemethodref then
when Constant_string then
idx := u2_to_integer(1)
constant_pool.view_in(str,idx)
when Constant_integer then
when Constant_float then
when Constant_long then
when Constant_double then
when Constant_name_and_type then
idx := u2_to_integer(1)
constant_pool.view_in(str,idx)
str.extend(':')
idx := u2_to_integer(3)
constant_pool.view_in(str,idx)
when Constant_utf8 then
from
length := u2_to_integer(1)
i := 3
until
length = 0
loop
str.extend(info.item(i))
i := i + 1
length := length - 1
end
end
end
feature {CONSTANT_POOL}
b_put is
do
jvm.b_put_u1(tag)
jvm.b_put_byte_string(info)
end
feature {CONSTANT_POOL} -- Update and search :
-- *** ACOMPLETER AU FUR ET A MESURE ***
is_class_idx(utf8: INTEGER): BOOLEAN is
do
if Constant_class = tag then
Result := u2_to_integer(1) = utf8
end
end
is_fieldref_idx(c, nt: INTEGER): BOOLEAN is
do
if Constant_fieldref = tag then
if u2_to_integer(1) = c then
Result := u2_to_integer(3) = nt
end
end
end
is_methodref_idx(c, nt: INTEGER): BOOLEAN is
do
if Constant_methodref = tag then
if u2_to_integer(1) = c then
Result := u2_to_integer(3) = nt
end
end
end
is_name_and_type_idx(n, d: INTEGER): BOOLEAN is
do
if Constant_name_and_type = tag then
if u2_to_integer(1) = n then
Result := u2_to_integer(3) = d
end
end
end
is_string_idx(utf8: INTEGER): BOOLEAN is
do
if Constant_string = tag then
Result := u2_to_integer(1) = utf8
end
end
is_utf8_idx(contents: STRING): BOOLEAN is
local
i1, i2: INTEGER
do
if Constant_utf8 = tag then
if u2_to_integer(1) = contents.count then
from
i1 := contents.count + 1
i2 := info.count + 1
check
i1 + 2 = i2
end
Result := true
until
not Result or else i1 = 1
loop
i1 := i1 - 1
i2 := i2 - 1
Result := contents.item(i1) = info.item(i2)
end
end
end
end
feature {NONE}
u2_to_integer(i: INTEGER): INTEGER is
do
Result := info.item(i).code * 256
Result := Result + info.item(i + 1).code
end
end -- CP_INFO
|