Skip to content

Commit

Permalink
Merge pull request #1804 from mgudemann/feature/parse_bootstrapmethod…
Browse files Browse the repository at this point in the history
…s_attribute

[TG-2365] Parse `BootstrapMethods` attribute
  • Loading branch information
Thomas Kiley authored Feb 28, 2018
2 parents ea7975f + 76d4014 commit 5cdfa94
Show file tree
Hide file tree
Showing 35 changed files with 1,841 additions and 0 deletions.
Binary file added regression/cbmc-java/lambda1/B.class
Binary file not shown.
9 changes: 9 additions & 0 deletions regression/cbmc-java/lambda1/B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class B {
public int y;

public static java.util.function.Function<Double, Double> dmul = x -> x * 3.1415;

public void set(int x) {
y = x;
}
}
Binary file added regression/cbmc-java/lambda1/C.class
Binary file not shown.
Binary file added regression/cbmc-java/lambda1/CustomLambda.class
Binary file not shown.
4 changes: 4 additions & 0 deletions regression/cbmc-java/lambda1/CustomLambda.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@FunctionalInterface
interface CustomLambda<T> {
boolean is_ok(T t);
}
Binary file added regression/cbmc-java/lambda1/Lambdatest$A.class
Binary file not shown.
Binary file added regression/cbmc-java/lambda1/Lambdatest.class
Binary file not shown.
84 changes: 84 additions & 0 deletions regression/cbmc-java/lambda1/Lambdatest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import java.util.function.*;

public class Lambdatest {

class A {
int x;
}

CustomLambda<Integer> custom = x -> true;
BiFunction<Float, Integer, Integer> add = (x0, y0) -> x0.intValue() + y0;
int z = 10;

A a;
B b = new B();

public Integer g(Float x, Integer y, BiFunction<Float, Integer, Integer> fun) {
return fun.apply(x, y);
}

public int f(Float x, Integer y, Integer z) {
Integer tmp = add.apply(x, y);
Function<Integer, Integer> mul = (a) -> a * tmp;
return mul.apply(z);
}

public int i(int x) {
int z = 5;
Function<Integer, Integer> foo = (a) -> a * z;
return foo.apply(x);
}

public int j(int x) {
Function<Integer, Integer> foo = (a) -> a * z;
return foo.apply(x);
}

public int k(int x) {
a.x = 10;

Function<Integer, Integer> foo = (y) -> y * a.x;
return foo.apply(x);
}

public int l(int x) {
b.y = 10;
Function<Integer, Integer> foo = (y) -> {
int r = y * b.y;
b.set(r);
return r;
};
b = new B();
b.y = 14;
return foo.apply(x);
}

public int m(int x) {
b.y = 10;
Function<Integer, Integer> foo = (y) -> {
int r = y * b.y;
b.y = r;
return r;
};
return foo.apply(x);
}

// test static field of different class
public double d(Double x) {
return B.dmul.apply(x);
}

public int capture2(Float a) {
return add.apply(a, 1);
}

public boolean custom(Integer i) {
return custom.is_ok(i);
}
}

class C implements CustomLambda<Integer> {
public boolean is_ok(Integer i) {
return true;
}
}
12 changes: 12 additions & 0 deletions regression/cbmc-java/lambda1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
Lambdatest.class
--verbosity 10 --show-goto-functions
lambda function reference lambda\$new\$0 in class \"Lambdatest\"
lambda function reference lambda\$new\$1 in class \"Lambdatest\"
lambda function reference lambda\$f\$2 in class \"Lambdatest\"
lambda function reference lambda\$i\$3 in class \"Lambdatest\"
lambda function reference lambda\$j\$4 in class \"Lambdatest\"
lambda function reference lambda\$k\$5 in class \"Lambdatest\"
lambda function reference lambda\$l\$6 in class \"Lambdatest\"
lambda function reference lambda\$m\$7 in class \"Lambdatest\"
lambda function reference lambda\$static\$0 in class \"B\"
3 changes: 3 additions & 0 deletions src/java_bytecode/java_bytecode_parse_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ void java_bytecode_parse_treet::classt::swap(
other.fields.swap(fields);
other.methods.swap(methods);
other.annotations.swap(annotations);
std::swap(
other.attribute_bootstrapmethods_read, attribute_bootstrapmethods_read);
std::swap(other.lambda_method_handle_map, lambda_method_handle_map);
}

void java_bytecode_parse_treet::output(std::ostream &out) const
Expand Down
25 changes: 25 additions & 0 deletions src/java_bytecode/java_bytecode_parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,33 @@ class java_bytecode_parse_treet
bool is_abstract=false;
bool is_enum=false;
bool is_public=false, is_protected=false, is_private=false;
bool attribute_bootstrapmethods_read = false;
size_t enum_elements=0;

enum class method_handle_typet
{
LAMBDA_METHOD_HANDLE,
UNKNOWN_HANDLE
};

typedef std::vector<u2> u2_valuest;
class lambda_method_handlet
{
public:
method_handle_typet handle_type;
irep_idt lambda_method_name;
irep_idt interface_type;
irep_idt method_type;
u2_valuest u2_values;
lambda_method_handlet() : handle_type(method_handle_typet::UNKNOWN_HANDLE)
{
}
};

typedef std::map<std::pair<irep_idt, size_t>, lambda_method_handlet>
lambda_method_handle_mapt;
lambda_method_handle_mapt lambda_method_handle_map;

typedef std::list<irep_idt> implementst;
implementst implements;
optionalt<std::string> signature;
Expand Down
Loading

0 comments on commit 5cdfa94

Please sign in to comment.