| /******************************************************************************* |
| * Copyright (c) 2009, 2010 Nokia and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Nokia - Initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.cdt.debug.edc.internal.symbols; |
| |
| import java.util.ArrayList; |
| import java.util.Map; |
| |
| import org.eclipse.cdt.debug.edc.symbols.IScope; |
| import org.eclipse.cdt.debug.edc.symbols.IType; |
| |
| public class ArrayType extends MayBeQualifiedType implements IArrayType { |
| |
| protected ArrayList<IArrayBoundType> bounds = new ArrayList<IArrayBoundType>(); |
| protected String nameWithSize; |
| protected int boundsOnLastName = 0; |
| |
| /** |
| * |
| * @param name not including any [] |
| * @param scope |
| * @param byteSize |
| * @param properties |
| */ |
| public ArrayType(String name, IScope scope, int byteSize, Map<Object, Object> properties) { |
| super(name, scope, byteSize, properties); |
| nameWithSize = name + "[]"; |
| } |
| |
| @Override |
| public String getName() { |
| if (!(boundsOnLastName == getBoundsCount())){ |
| if (name == null || name.length() == 0){ |
| IType subType = getType(); |
| if (subType != null){ |
| name = subType.getName(); |
| } else { |
| name = ""; |
| } |
| } |
| nameWithSize = name; |
| for (IArrayBoundType bound : bounds){ |
| nameWithSize += "[" + bound.getBoundCount() + "]"; |
| } |
| } |
| return nameWithSize; |
| } |
| |
| public int getBoundsCount() { |
| return bounds.size(); |
| } |
| |
| public void addBound(IArrayBoundType bound) { |
| // existing array dimensions now represent bound.getBoundCount() times |
| // as many array elements, |
| // and have a higher dimensional position |
| for (IArrayBoundType existingBound : this.bounds) { |
| existingBound.multiplyElementCount(bound.getBoundCount()); |
| existingBound.incDimensionIndex(); |
| } |
| bounds.add(bound); |
| byteSize = 0; // recalculate |
| } |
| |
| public IArrayBoundType[] getBounds() { |
| IArrayBoundType[] boundsArray = new IArrayBoundType[bounds.size()]; |
| for (int i = 0; i < bounds.size(); i++) { |
| boundsArray[i] = bounds.get(i); |
| } |
| return boundsArray; |
| } |
| |
| // get the Nth bound. E.g., for "a[X][Y]", getBound(0) returns info for |
| // "[X]" |
| public IArrayBoundType getBound(int index) { |
| if (index >= 0 && index < bounds.size()) |
| return bounds.get(index); |
| |
| return null; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.cdt.debug.edc.internal.symbols.Type#getByteSize() |
| */ |
| @Override |
| public int getByteSize() { |
| if (byteSize == 0) { |
| if (bounds.size() > 0) { |
| updateByteSizeFromSubType(); |
| for (IArrayBoundType bound : bounds) { |
| byteSize *= bound.getBoundCount(); |
| } |
| } |
| } |
| return byteSize; |
| } |
| } |