|
Java example source code file (NType.java)
The NType.java Java example source code/* * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.apple.internal.jobjc.generator.model.types; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import com.apple.internal.jobjc.generator.Utils; import com.apple.internal.jobjc.generator.model.coders.PrimitiveCoderDescriptor; import com.apple.internal.jobjc.generator.utils.Fp; import com.apple.internal.jobjc.generator.utils.NTypePrinter; import com.apple.internal.jobjc.generator.utils.QA; import com.apple.jobjc.JObjCRuntime.Width; /** * NType (Native Type) bridges the type and type64 attributes in BridgeSupport. * * For example: * * <pre> * type="c" // BridgeSupport attribute * (NPrimitive type: 'c') // Java object (in sexp form here, for readability) * * type="^v" * (NPointer subject: (NVoid)) * * type="{foo_t="a"c"b"b8"c"[32^v]}" * (NStruct * name: "foo_t" * fields: * (List<NField> * 0: (NField name:"a" type: (NPrimitive type: 'c')) * 1: (NField name:"b" type: (NBitfield size: 8)) * 2: (NField name:"c" type: * (NArray size: 32 * type: (NPointer subject: (NVoid)))))) * </pre> */ public abstract class NType implements Comparable<NType>{ public final Map<Width, Integer> sizeof; public NType(Map<Width, Integer> sizeof) { this.sizeof = sizeof; } public NType(){ this(new HashMap<Width, Integer>()); } public NType(int sz32, int sz64){ this(); this.sizeof.put(Width.W32, sz32); this.sizeof.put(Width.W64, sz32); } public int sizeof32(){ return sizeof.get(Width.W32); } public int sizeof64(){ return sizeof.get(Width.W64); } protected abstract boolean equals2(NType nt); private String _toString; @Override public String toString(){ return _toString != null ? _toString : (_toString = NTypePrinter.inst().print(this)); } @Override public boolean equals(Object o) { return o!=null && (o==this || (getClass().isInstance(o) && this.sizeof.equals(((NType) o).sizeof) && equals2((NType) o))); } public int compareTo(NType o){ return toString().compareTo(o.toString()); } // ** NType subclasses // ------------------- public static class NBitfield extends NType{ public final int length; public NBitfield(int length){ super(-1, -1); this.length = length; } @Override protected boolean equals2(NType nt) { return ((NBitfield) nt).length == length; } @Override public int hashCode() { return Integer.valueOf(length).hashCode(); } } public static class NPrimitive extends NType{ public static Collection<Character> CODES = Arrays.asList( 'B', 'c', 'C', 's', 'S', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd'); public final char type; protected NPrimitive(char c){ super(PrimitiveCoderDescriptor.createCoderDescriptorFor(c).getCoder().sizeof(Width.W32), PrimitiveCoderDescriptor.createCoderDescriptorFor(c).getCoder().sizeof(Width.W64)); type = c; } private static final Map<Character, NPrimitive> cache = new HashMap Other Java examples (source code examples)Here is a short list of links related to this Java NType.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.