1 /*
   2  * Copyright (c) 2015, 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 package jdk.test.lib.jittester.factories;
  25 
  26 import jdk.test.lib.jittester.Declaration;
  27 import jdk.test.lib.jittester.IRNode;
  28 import jdk.test.lib.jittester.ProductionFailedException;
  29 import jdk.test.lib.jittester.ProductionParams;
  30 import jdk.test.lib.jittester.Rule;
  31 import jdk.test.lib.jittester.TypeList;
  32 import jdk.test.lib.jittester.types.TypeKlass;
  33 
  34 class DeclarationFactory extends Factory<Declaration> {
  35     private final int operatorLimit;
  36     private final long complexityLimit;
  37     private final boolean isLocal;
  38     private final boolean exceptionSafe;
  39     private final TypeKlass ownerClass;
  40 
  41     DeclarationFactory(TypeKlass ownerClass, long complexityLimit,
  42             int operatorLimit, boolean isLocal, boolean safe) {
  43         this.ownerClass = ownerClass;
  44         this.isLocal = isLocal;
  45         this.exceptionSafe = safe;
  46         this.complexityLimit = complexityLimit;
  47         this.operatorLimit = operatorLimit;
  48     }
  49 
  50     @Override
  51     public Declaration produce() throws ProductionFailedException {
  52         Rule<IRNode> rule = new Rule<>("declaration");
  53         IRNodeBuilder builder = new IRNodeBuilder().setOwnerKlass(ownerClass)
  54                 .setResultType(TypeList.VOID)
  55                 .setIsLocal(isLocal)
  56                 .setComplexityLimit(complexityLimit)
  57                 .setOperatorLimit(operatorLimit)
  58                 .setIsLocal(isLocal)
  59                 .setExceptionSafe(exceptionSafe);
  60         rule.add("decl", builder
  61                 .setIsStatic(false)
  62                 .getVariableDeclarationFactory());
  63         rule.add("decl_and_init", builder
  64                 .setIsConstant(false)
  65                 .setIsStatic(false)
  66                 .getVariableInitializationFactory());
  67         if (!ProductionParams.disableFinalVariables.value()) {
  68             rule.add("const_decl_and_init", builder
  69                     .setIsConstant(true)
  70                     .setIsStatic(false)
  71                     .getVariableInitializationFactory());
  72         }
  73         if (!isLocal && !ProductionParams.disableStatic.value()) {
  74             rule.add("static_decl", builder
  75                     .setIsConstant(false)
  76                     .setIsStatic(true)
  77                     .getVariableDeclarationFactory());
  78             rule.add("static_decl_and_init", builder
  79                     .setIsConstant(false)
  80                     .setIsStatic(true)
  81                     .getVariableInitializationFactory());
  82             if (!ProductionParams.disableFinalVariables.value()) {
  83                 rule.add("static_const_decl_and_init", builder
  84                         .setIsConstant(true)
  85                         .setIsStatic(true)
  86                         .getVariableInitializationFactory());
  87             }
  88         }
  89         return new Declaration(rule.produce());
  90     }
  91 }