1 /*
2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import jdk.incubator.code.CodeReflection;
25
26 /*
27 * @test
28 * @summary Smoke test for code reflection with conditional and/or expressions.
29 * @modules jdk.incubator.code
30 * @build ConditionalAndOrTest
31 * @build CodeReflectionTester
32 * @run main CodeReflectionTester ConditionalAndOrTest
33 */
34
35 public class ConditionalAndOrTest {
36
37 @CodeReflection
38 @IR("""
39 func @"test1" (%0 : java.type:"ConditionalAndOrTest", %1 : java.type:"int")java.type:"void" -> {
40 %2 : Var<java.type:"int"> = var %1 @"i";
41 %3 : java.type:"boolean" = java.cand
42 ()java.type:"boolean" -> {
43 %4 : java.type:"int" = var.load %2;
44 %5 : java.type:"int" = constant @1;
45 %6 : java.type:"boolean" = gt %4 %5;
46 yield %6;
47 }
48 ()java.type:"boolean" -> {
49 %7 : java.type:"int" = var.load %2;
50 %8 : java.type:"int" = constant @10;
51 %9 : java.type:"boolean" = lt %7 %8;
52 yield %9;
53 };
54 %10 : Var<java.type:"boolean"> = var %3 @"b";
55 return;
56 };
57 """)
58 void test1(int i) {
59 boolean b = i > 1 && i < 10;
60 }
61
62 @CodeReflection
63 @IR("""
64 func @"test2" (%0 : java.type:"ConditionalAndOrTest", %1 : java.type:"int")java.type:"void" -> {
65 %2 : Var<java.type:"int"> = var %1 @"i";
66 %3 : java.type:"boolean" = java.cor
67 ()java.type:"boolean" -> {
68 %4 : java.type:"int" = var.load %2;
69 %5 : java.type:"int" = constant @1;
70 %6 : java.type:"boolean" = gt %4 %5;
71 yield %6;
72 }
73 ()java.type:"boolean" -> {
74 %7 : java.type:"int" = var.load %2;
75 %8 : java.type:"int" = constant @10;
76 %9 : java.type:"boolean" = lt %7 %8;
77 yield %9;
78 };
79 %10 : Var<java.type:"boolean"> = var %3 @"b";
80 return;
81 };
82 """)
83 void test2(int i) {
84 boolean b = i > 1 || i < 10;
85 }
86
87 @CodeReflection
88 @IR("""
89 func @"test3" (%0 : java.type:"ConditionalAndOrTest", %1 : java.type:"int")java.type:"void" -> {
90 %2 : Var<java.type:"int"> = var %1 @"i";
91 %3 : java.type:"boolean" = java.cor
92 ()java.type:"boolean" -> {
93 %4 : java.type:"boolean" = java.cand
94 ()java.type:"boolean" -> {
95 %5 : java.type:"int" = var.load %2;
96 %6 : java.type:"int" = constant @1;
97 %7 : java.type:"boolean" = gt %5 %6;
98 yield %7;
99 }
100 ()java.type:"boolean" -> {
101 %8 : java.type:"int" = var.load %2;
102 %9 : java.type:"int" = constant @10;
103 %10 : java.type:"boolean" = lt %8 %9;
104 yield %10;
105 };
106 yield %4;
107 }
108 ()java.type:"boolean" -> {
109 %11 : java.type:"int" = var.load %2;
110 %12 : java.type:"int" = constant @100;
111 %13 : java.type:"boolean" = eq %11 %12;
112 yield %13;
113 };
114 %14 : Var<java.type:"boolean"> = var %3 @"b";
115 return;
116 };
117 """)
118 void test3(int i) {
119 boolean b = i > 1 && i < 10 || i == 100;
120 }
121 }