Permalink
Browse files

* tests/bytecode/codegraph/AnonClass.java: support by skipping ...

  • Loading branch information...
1 parent 883342f commit 49c3a24941cf70a8d8f969ec4255fcfba59616c0 @aryx aryx committed Dec 12, 2012
Showing with 35 additions and 2 deletions.
  1. +17 −2 lang_bytecode/analyze/graph_code_bytecode.ml
  2. +18 −0 tests/bytecode/codegraph/AnonClass.java
@@ -31,7 +31,9 @@ open JClassLow
* - package lookup, all names are resolved in the bytecode
* (still need a class lookup for fields/methods though ...)
* - handling nested classes, they are compiled in another class
- * with a $ suffix
+ * with a '$' used as a separator instead of '.'
+ * - handling anonymous classes, they are compiled in another class with
+ * a '$N' suffix.
* - handling generics?
* - type checking to resolve certain method calls, the bytecode is fully
* typed (a bit like TAL), one can get the type of each 'invoke' opcode
@@ -167,6 +169,10 @@ let add_use_edge env dst =
g +> G.add_edge (src, dst) G.Use;
()
+(*****************************************************************************)
+(* Lookup *)
+(*****************************************************************************)
+
let (lookup2:
Graph_code.graph -> Graph_code.node -> string -> Graph_code.node option) =
fun g start fld ->
@@ -201,6 +207,10 @@ let lookup g n s =
)
)
+(*****************************************************************************)
+(* Bytecode<->Java connection *)
+(*****************************************************************************)
+
let unmangle graph_java (full_str_bytecode_name, kind) =
let xs = Common.split "\\." full_str_bytecode_name in
let (package, bytecode_name_entity) =
@@ -210,7 +220,12 @@ let unmangle graph_java (full_str_bytecode_name, kind) =
)
in
let ys = Common.split "\\$" bytecode_name_entity in
-
+ let ys =
+ if ys +> List.exists (fun s -> s =~ "[0-9]+")
+ (* todo: look in graph_java for the corresponding anon_xxx *)
+ then [List.hd ys]
+ else ys
+ in
let full_name = package ++ ys in
Common.join "." full_name, kind
@@ -0,0 +1,18 @@
+package Foo;
+class AnonClass {
+ void foo1() {
+ Object o = new Object() {
+
+ };
+ Object o2 = new Object() {
+
+ };
+ }
+ class NestedClass {
+ void foo1() {
+ Object o = new Object() {
+
+ };
+ }
+ }
+}

0 comments on commit 49c3a24

Please sign in to comment.