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 java.util.ArrayList; 27 import java.util.Collection; 28 import java.util.List; 29 30 import jdk.test.lib.jittester.IRNode; 31 import jdk.test.lib.jittester.ProductionFailedException; 32 import jdk.test.lib.jittester.Symbol; 33 import jdk.test.lib.jittester.SymbolTable; 34 import jdk.test.lib.jittester.Type; 35 import jdk.test.lib.jittester.TypeList; 36 import jdk.test.lib.jittester.VariableInfo; 37 import jdk.test.lib.jittester.functions.ArgumentDeclaration; 38 import jdk.test.lib.jittester.functions.FunctionDeclaration; 39 import jdk.test.lib.jittester.functions.FunctionDefinition; 40 import jdk.test.lib.jittester.functions.FunctionInfo; 41 import jdk.test.lib.jittester.types.TypeKlass; 42 import jdk.test.lib.jittester.types.TypeVoid; 43 import jdk.test.lib.jittester.utils.PseudoRandom; 44 45 class FunctionDeclarationFactory extends Factory { 46 private final Type resultType; 47 private final TypeKlass ownerClass; 48 private final String name; 49 private final int memberFunctionsArgLimit; 50 private final int flags; 51 52 FunctionDeclarationFactory(String name, TypeKlass ownerClass, Type resultType, 53 int memberFunctionsArgLimit, int flags) { 54 this.name = name; 55 this.ownerClass = ownerClass; 56 this.resultType = resultType; 57 this.memberFunctionsArgLimit = memberFunctionsArgLimit; 58 this.flags = flags; 59 } 60 61 @Override 62 public IRNode produce() throws ProductionFailedException { 63 Type resType = resultType; 64 if (resType == null) { 65 List<Type> types = new ArrayList<>(TypeList.getAll()); 66 types.add(new TypeVoid()); 67 resType = PseudoRandom.randomElement(types); 68 } 69 int argNumber = (int) (PseudoRandom.random() * memberFunctionsArgLimit); 70 ArrayList<VariableInfo> argumentsInfo = new ArrayList<>(argNumber + 1); 71 argumentsInfo.add(new VariableInfo("this", ownerClass, ownerClass, 72 VariableInfo.FINAL | VariableInfo.LOCAL | VariableInfo.INITIALIZED)); 73 ArrayList<ArgumentDeclaration> argumentsDeclaration = new ArrayList<>(argNumber); 74 SymbolTable.push(); 75 FunctionInfo functionInfo; 76 IRNodeBuilder builder = new IRNodeBuilder().setArgumentType(ownerClass); 77 try { 78 int i = 0; 79 for (; i < argNumber; i++) { 80 ArgumentDeclaration d = builder.setVariableNumber(i) 81 .getArgumentDeclarationFactory().produce(); 82 argumentsDeclaration.add(d); 83 argumentsInfo.add(d.variableInfo); 84 } 85 Collection<Symbol> thisKlassFuncs = SymbolTable 86 .getAllCombined(ownerClass, FunctionInfo.class); | 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 java.util.ArrayList; 27 import java.util.Collection; 28 import java.util.List; 29 30 import jdk.test.lib.jittester.ProductionFailedException; 31 import jdk.test.lib.jittester.Symbol; 32 import jdk.test.lib.jittester.SymbolTable; 33 import jdk.test.lib.jittester.Type; 34 import jdk.test.lib.jittester.TypeList; 35 import jdk.test.lib.jittester.VariableInfo; 36 import jdk.test.lib.jittester.functions.ArgumentDeclaration; 37 import jdk.test.lib.jittester.functions.FunctionDeclaration; 38 import jdk.test.lib.jittester.functions.FunctionDefinition; 39 import jdk.test.lib.jittester.functions.FunctionInfo; 40 import jdk.test.lib.jittester.types.TypeKlass; 41 import jdk.test.lib.jittester.utils.PseudoRandom; 42 43 class FunctionDeclarationFactory extends Factory<FunctionDeclaration> { 44 private final Type resultType; 45 private final TypeKlass ownerClass; 46 private final String name; 47 private final int memberFunctionsArgLimit; 48 private final int flags; 49 50 FunctionDeclarationFactory(String name, TypeKlass ownerClass, Type resultType, 51 int memberFunctionsArgLimit, int flags) { 52 this.name = name; 53 this.ownerClass = ownerClass; 54 this.resultType = resultType; 55 this.memberFunctionsArgLimit = memberFunctionsArgLimit; 56 this.flags = flags; 57 } 58 59 @Override 60 public FunctionDeclaration produce() throws ProductionFailedException { 61 Type resType = resultType; 62 if (resType == null) { 63 List<Type> types = new ArrayList<>(TypeList.getAll()); 64 types.add(TypeList.VOID); 65 resType = PseudoRandom.randomElement(types); 66 } 67 int argNumber = (int) (PseudoRandom.random() * memberFunctionsArgLimit); 68 ArrayList<VariableInfo> argumentsInfo = new ArrayList<>(argNumber + 1); 69 argumentsInfo.add(new VariableInfo("this", ownerClass, ownerClass, 70 VariableInfo.FINAL | VariableInfo.LOCAL | VariableInfo.INITIALIZED)); 71 ArrayList<ArgumentDeclaration> argumentsDeclaration = new ArrayList<>(argNumber); 72 SymbolTable.push(); 73 FunctionInfo functionInfo; 74 IRNodeBuilder builder = new IRNodeBuilder().setArgumentType(ownerClass); 75 try { 76 int i = 0; 77 for (; i < argNumber; i++) { 78 ArgumentDeclaration d = builder.setVariableNumber(i) 79 .getArgumentDeclarationFactory().produce(); 80 argumentsDeclaration.add(d); 81 argumentsInfo.add(d.variableInfo); 82 } 83 Collection<Symbol> thisKlassFuncs = SymbolTable 84 .getAllCombined(ownerClass, FunctionInfo.class); |