0N/A/*
1472N/A * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
0N/Apackage sun.jvm.hotspot.debugger.cdbg.basic;
0N/A
0N/Aimport java.util.*;
0N/Aimport sun.jvm.hotspot.debugger.*;
0N/Aimport sun.jvm.hotspot.debugger.cdbg.*;
0N/Aimport sun.jvm.hotspot.utilities.Assert;
0N/A
0N/Apublic class BasicCompoundType extends BasicType implements CompoundType {
0N/A private CompoundTypeKind kind;
0N/A private List baseClasses;
0N/A private List fields;
0N/A
0N/A public BasicCompoundType(String name, int size, CompoundTypeKind kind) {
0N/A this(name, size, kind, 0);
0N/A }
0N/A
0N/A private BasicCompoundType(String name, int size, CompoundTypeKind kind, int cvAttributes) {
0N/A super(name, size, cvAttributes);
0N/A if (Assert.ASSERTS_ENABLED) {
0N/A Assert.that(kind != null, "null kind");
0N/A }
0N/A this.kind = kind;
0N/A }
0N/A
0N/A public CompoundType asCompound() { return this; }
0N/A
0N/A public int getNumBaseClasses() {
0N/A return ((baseClasses == null) ? 0 : baseClasses.size());
0N/A }
0N/A public BaseClass getBaseClass(int i) {
0N/A return (BaseClass) baseClasses.get(i);
0N/A }
0N/A
0N/A public void addBaseClass(BaseClass b) {
0N/A if (baseClasses == null) {
0N/A baseClasses = new ArrayList();
0N/A }
0N/A baseClasses.add(b);
0N/A }
0N/A
0N/A public int getNumFields() {
0N/A return ((fields == null) ? 0 : fields.size());
0N/A }
0N/A public Field getField(int i) {
0N/A return (Field) fields.get(i);
0N/A }
0N/A
0N/A public void addField(Field f) {
0N/A if (fields == null) {
0N/A fields = new ArrayList();
0N/A }
0N/A fields.add(f);
0N/A }
0N/A
0N/A public boolean isClass() { return (kind == CompoundTypeKind.CLASS); }
0N/A public boolean isStruct() { return (kind == CompoundTypeKind.STRUCT); }
0N/A public boolean isUnion() { return (kind == CompoundTypeKind.UNION); }
0N/A
0N/A Type resolveTypes(BasicCDebugInfoDataBase db, ResolveListener listener) {
0N/A super.resolveTypes(db, listener);
0N/A if (baseClasses != null) {
0N/A for (Iterator iter = baseClasses.iterator(); iter.hasNext(); ) {
0N/A BasicBaseClass b = (BasicBaseClass) iter.next();
0N/A b.resolveTypes(this, db, listener);
0N/A }
0N/A }
0N/A if (fields != null) {
0N/A for (Iterator iter = fields.iterator(); iter.hasNext(); ) {
0N/A BasicField b = (BasicField) iter.next();
0N/A b.resolveTypes(this, db, listener);
0N/A }
0N/A }
0N/A return this;
0N/A }
0N/A
0N/A public void iterateObject(Address a, ObjectVisitor v, FieldIdentifier f) {
0N/A // What kind of iteration are we doing? If the end user requested
0N/A // iteration over a given object at a given address, the field
0N/A // identifier will be null, and we should descend and iterate over
0N/A // our fields and superclasses. Otherwise, we are already
0N/A // iterating through an object, and it is up to the end user
0N/A // whether to descend into the embedded object.
0N/A if (f == null) {
0N/A // FIXME: this is one of the key hard components of this
0N/A // implementation. Will need to properly handle multiple
0N/A // inheritance and possibly virtual base classes (i.e., not
0N/A // iterating twice for a virtual base class inherited indirectly
0N/A // more than once). For now, we do the simple thing, which
0N/A // assumes single inheritance.
0N/A for (int i = 0; i < getNumBaseClasses(); i++) {
0N/A BasicCompoundType b = (BasicCompoundType) getBaseClass(i).getType();
0N/A b.iterateObject(a, v, f);
0N/A }
0N/A // Now we are in our scope
0N/A v.enterType(this, a);
0N/A // Iterate through our fields
0N/A for (int i = 0; i < getNumFields(); i++) {
0N/A Field field = getField(i);
0N/A BasicType fieldType = (BasicType) field.getType();
0N/A fieldType.iterateObject(a.addOffsetTo(field.getOffset()), v, new BasicNamedFieldIdentifier(field));
0N/A }
0N/A v.exitType();
0N/A } else {
0N/A v.doCompound(f, a);
0N/A }
0N/A }
0N/A
0N/A protected Type createCVVariant(int cvAttributes) {
0N/A BasicCompoundType t = new BasicCompoundType(getName(), getSize(), kind, cvAttributes);
0N/A t.kind = kind;
0N/A t.baseClasses = baseClasses;
0N/A t.fields = fields;
0N/A return t;
0N/A }
0N/A
0N/A public void visit(TypeVisitor v) {
0N/A v.doCompoundType(this);
0N/A }
0N/A}