1 /* 2 * Copyright (c) 2014, 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.internal.clang; 25 26 import java.nio.ByteBuffer; 27 28 public class Type extends StructType { 29 Type(ByteBuffer buf) { 30 super(buf); 31 } 32 33 // Function Types 34 public native boolean isVariadic(); 35 public native Type resultType(); 36 public native int numberOfArgs(); 37 public native Type argType(int idx); 38 private native int getCallingConvention1(); 39 40 public CallingConvention getCallingConvention() { 41 int v = getCallingConvention1(); 42 return CallingConvention.valueOf(v); 43 } 44 45 // Pointer type 46 public native Type getPointeeType(); 47 48 // array/vector type 49 public native Type getElementType(); 50 public native long getNumberOfElements(); 51 52 // Struct/RecordType 53 public native long getOffsetOf(String fieldName); 54 55 // Typedef 56 public native Type canonicalType(); 57 58 public native String spelling(); 59 60 public native int kind1(); 61 62 public native long size(); 63 64 public TypeKind kind() { 65 int v = kind1(); 66 // FIXME: assert(v == getData().getInt(0)); 67 return TypeKind.valueOf(v); 68 } 69 70 public native Cursor getDeclarationCursor(); 71 72 public native boolean equalType(Type other); 73 74 @Override 75 public boolean equals(Object other) { 76 if (this == other) { 77 return true; 78 } 79 if (!(other instanceof Type)) { 80 return false; 81 } 82 return equalType((Type)other); 83 } 84 85 @Override 86 public int hashCode() { 87 return spelling().hashCode(); 88 } 89 }