blob: bf9b657b5a2fa45e214ffe23767511dea37c523f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009, 2010, 2011 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
* Broadcom - Refactored ForwardTypeReference to separate top-level class
*******************************************************************************/
package org.eclipse.cdt.debug.edc.internal.symbols.dwarf;
import java.util.Collections;
import java.util.Map;
import org.eclipse.cdt.debug.edc.internal.symbols.IForwardTypeReference;
import org.eclipse.cdt.debug.edc.symbols.IScope;
import org.eclipse.cdt.debug.edc.symbols.IType;
/**
* This represents a forward type reference, which is a type
* that resolves itself when referenced.
*/
public class ForwardTypeReference implements IType, IForwardTypeReference {
static public final IType NULL_TYPE_ENTRY = new IType() {
public int getByteSize() {
return 0;
}
public String getName() {
return DwarfMessages.DwarfDebugInfoProvider_UnhandledType;
}
public Map<Object, Object> getProperties() {
return Collections.emptyMap();
}
public IScope getScope() {
return null;
}
public IType getType() {
return null;
}
public void setType(IType type) {
throw new IllegalStateException();
}
public void dispose() {
}
};
private DwarfDebugInfoProvider provider;
private IType type = null;
protected final long offset;
public ForwardTypeReference(DwarfDebugInfoProvider provider, long offset) {
this.provider = provider;
this.offset = offset;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.edc.internal.symbols.dwarf.IForwardTypeReference#getReferencedType()
*/
public IType getReferencedType() {
if (type == null) {
synchronized (this){// Instances are globally visible and so can be accessed from multiple threads
if (type == null) {
// to prevent recursion
IType newType = NULL_TYPE_ENTRY;
newType = provider.resolveTypeReference(this);
if (newType == null) {
// FIXME
newType = NULL_TYPE_ENTRY;
}
type = newType;
}
}
}
return type;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.edc.internal.symbols.IType#getByteSize()
*/
public int getByteSize() {
return getReferencedType().getByteSize();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.edc.internal.symbols.IType#getName()
*/
public String getName() {
return getReferencedType().getName();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.edc.internal.symbols.IType#getProperties()
*/
public Map<Object, Object> getProperties() {
return getReferencedType().getProperties();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.edc.internal.symbols.IType#getScope()
*/
public IScope getScope() {
return getReferencedType().getScope();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.edc.internal.symbols.IType#getType()
*/
public IType getType() {
return getReferencedType().getType();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.edc.internal.symbols.IType#setType(org.eclipse.cdt.debug.edc.internal.symbols.IType)
*/
public void setType(IType type_) {
getReferencedType().setType(type_);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.edc.internal.symbols.IType#dispose()
*/
public void dispose() {
type = null;
provider = null;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (offset ^ (offset >>> 32));
result = prime * result + ((provider == null) ? 0 : provider.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ForwardTypeReference other = (ForwardTypeReference) obj;
if (offset != other.offset)
return false;
if (provider == null) {
if (other.provider != null)
return false;
} else if (!provider.equals(other.provider))
return false;
return true;
}
}