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 java.lang.runtime.CodeReflection;
 25 
 26 /*
 27  * @test
 28  * @summary Smoke test for code reflection with conditional and/or expressions.
 29  * @build ConditionalAndOrTest
 30  * @build CodeReflectionTester
 31  * @run main CodeReflectionTester ConditionalAndOrTest
 32  */
 33 
 34 public class ConditionalAndOrTest {
 35 
 36     @CodeReflection
 37     @IR("""
 38             func @"test1" (%0 : ConditionalAndOrTest, %1 : int)void -> {
 39                 %2 : Var<int> = var %1 @"i";
 40                 %3 : boolean = java.cand
 41                     ()boolean -> {
 42                         %4 : int = var.load %2;
 43                         %5 : int = constant @"1";
 44                         %6 : boolean = gt %4 %5;
 45                         yield %6;
 46                     }
 47                     ()boolean -> {
 48                         %7 : int = var.load %2;
 49                         %8 : int = constant @"10";
 50                         %9 : boolean = lt %7 %8;
 51                         yield %9;
 52                     };
 53                 %10 : Var<boolean> = var %3 @"b";
 54                 return;
 55             };
 56             """)
 57     void test1(int i) {
 58         boolean b = i > 1 && i < 10;
 59     }
 60 
 61     @CodeReflection
 62     @IR("""
 63             func @"test2" (%0 : ConditionalAndOrTest, %1 : int)void -> {
 64                 %2 : Var<int> = var %1 @"i";
 65                 %3 : boolean = java.cor
 66                     ()boolean -> {
 67                         %4 : int = var.load %2;
 68                         %5 : int = constant @"1";
 69                         %6 : boolean = gt %4 %5;
 70                         yield %6;
 71                     }
 72                     ()boolean -> {
 73                         %7 : int = var.load %2;
 74                         %8 : int = constant @"10";
 75                         %9 : boolean = lt %7 %8;
 76                         yield %9;
 77                     };
 78                 %10 : Var<boolean> = var %3 @"b";
 79                 return;
 80             };
 81             """)
 82     void test2(int i) {
 83         boolean b = i > 1 || i < 10;
 84     }
 85 
 86     @CodeReflection
 87     @IR("""
 88             func @"test3" (%0 : ConditionalAndOrTest, %1 : int)void -> {
 89                 %2 : Var<int> = var %1 @"i";
 90                 %3 : boolean = java.cor
 91                     ()boolean -> {
 92                         %4 : boolean = java.cand
 93                             ()boolean -> {
 94                                 %5 : int = var.load %2;
 95                                 %6 : int = constant @"1";
 96                                 %7 : boolean = gt %5 %6;
 97                                 yield %7;
 98                             }
 99                             ()boolean -> {
100                                 %8 : int = var.load %2;
101                                 %9 : int = constant @"10";
102                                 %10 : boolean = lt %8 %9;
103                                 yield %10;
104                             };
105                         yield %4;
106                     }
107                     ()boolean -> {
108                         %11 : int = var.load %2;
109                         %12 : int = constant @"100";
110                         %13 : boolean = eq %11 %12;
111                         yield %13;
112                     };
113                 %14 : Var<boolean> = var %3 @"b";
114                 return;
115             };
116             """)
117     void test3(int i) {
118         boolean b = i > 1 && i < 10 || i == 100;
119     }
120 }