1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Change in the BinaryElement constructor, takes

the address .
This commit is contained in:
Alain Magloire 2003-04-02 04:52:40 +00:00
parent c4787b1801
commit d0d01cd58e
5 changed files with 122 additions and 41 deletions

View file

@ -172,15 +172,13 @@ public class Binary extends Openable implements IBinary {
hash.put(path, module); hash.put(path, module);
info.addChild(module); info.addChild(module);
} }
function = new BinaryFunction(module, symbol.getName()); function = new BinaryFunction(module, symbol.getName(), symbol.getAddress());
function.setLines(symbol.getStartLine(), symbol.getEndLine()); function.setLines(symbol.getStartLine(), symbol.getEndLine());
function.setAddress(symbol.getAdress());
module.addChild(function); module.addChild(function);
} else { } else {
//function = new Function(parent, symbol.getName()); //function = new Function(parent, symbol.getName());
function = new BinaryFunction(this, symbol.getName()); function = new BinaryFunction(this, symbol.getName(), symbol.getAddress());
function.setLines(symbol.getStartLine(), symbol.getEndLine()); function.setLines(symbol.getStartLine(), symbol.getEndLine());
function.setAddress(symbol.getAdress());
info.addChild(function); info.addChild(function);
} }
// if (function != null) { // if (function != null) {
@ -204,14 +202,12 @@ public class Binary extends Openable implements IBinary {
hash.put(path, module); hash.put(path, module);
info.addChild(module); info.addChild(module);
} }
variable = new BinaryVariable(module, symbol.getName()); variable = new BinaryVariable(module, symbol.getName(), symbol.getAddress());
variable.setLines(symbol.getStartLine(), symbol.getEndLine()); variable.setLines(symbol.getStartLine(), symbol.getEndLine());
variable.setAddress(symbol.getAdress());
module.addChild(variable); module.addChild(variable);
} else { } else {
variable = new BinaryVariable(this, symbol.getName()); variable = new BinaryVariable(this, symbol.getName(), symbol.getAddress());
variable.setLines(symbol.getStartLine(), symbol.getEndLine()); variable.setLines(symbol.getStartLine(), symbol.getEndLine());
variable.setAddress(symbol.getAdress());
info.addChild(variable); info.addChild(variable);
} }

View file

@ -4,17 +4,23 @@
*/ */
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import java.io.IOException;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.IBinaryElement; import org.eclipse.cdt.core.model.IBinaryElement;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceManipulation; import org.eclipse.cdt.core.model.ISourceManipulation;
import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
/** /**
*/ */
@ -22,23 +28,15 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
long addr; long addr;
public BinaryElement(ICElement parent, String name, int type) { public BinaryElement(ICElement parent, String name, int type, long a) {
super(parent, name, type); super(parent, name, type);
}
public void setAddress(long a) {
addr = a; addr = a;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ISourceManipulation#copy(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.cdt.core.model.ISourceManipulation#copy(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
*/ */
public void copy( public void copy(ICElement container, ICElement sibling, String rename, boolean replace, IProgressMonitor monitor)
ICElement container,
ICElement sibling,
String rename,
boolean replace,
IProgressMonitor monitor)
throws CModelException { throws CModelException {
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
} }
@ -46,20 +44,14 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ISourceManipulation#delete(boolean, org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.cdt.core.model.ISourceManipulation#delete(boolean, org.eclipse.core.runtime.IProgressMonitor)
*/ */
public void delete(boolean force, IProgressMonitor monitor) public void delete(boolean force, IProgressMonitor monitor) throws CModelException {
throws CModelException {
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ISourceManipulation#move(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.cdt.core.model.ISourceManipulation#move(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
*/ */
public void move( public void move(ICElement container, ICElement sibling, String rename, boolean replace, IProgressMonitor monitor)
ICElement container,
ICElement sibling,
String rename,
boolean replace,
IProgressMonitor monitor)
throws CModelException { throws CModelException {
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
} }
@ -67,8 +59,7 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ISourceManipulation#rename(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.cdt.core.model.ISourceManipulation#rename(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
*/ */
public void rename(String name, boolean replace, IProgressMonitor monitor) public void rename(String name, boolean replace, IProgressMonitor monitor) throws CModelException {
throws CModelException {
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
} }
@ -76,24 +67,65 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
* @see org.eclipse.cdt.core.model.ISourceReference#getSource() * @see org.eclipse.cdt.core.model.ISourceReference#getSource()
*/ */
public String getSource() throws CModelException { public String getSource() throws CModelException {
// TODO Auto-generated method stub ITranslationUnit tu = getTranslationUnit();
return null; if (tu != null) {
try {
IResource res = tu.getResource();
if (res != null && res instanceof IFile) {
StringBuffer buffer = Util.getContent((IFile)res);
return buffer.substring(getStartPos(),
getStartPos() + getLength());
}
} catch (IOException e) {
throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION);
}
}
return "";
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ISourceReference#getSourceRange() * @see org.eclipse.cdt.core.model.ISourceReference#getSourceRange()
*/ */
public ISourceRange getSourceRange() throws CModelException { public ISourceRange getSourceRange() throws CModelException {
// TODO Auto-generated method stub return new SourceRange(getStartPos(),
return null; getLength(),
getIdStartPos(),
getIdLength(),
getStartLine(),
getEndLine());
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ISourceReference#getTranslationUnit() * @see org.eclipse.cdt.core.model.ISourceReference#getTranslationUnit()
*/ */
public ITranslationUnit getTranslationUnit() { public ITranslationUnit getTranslationUnit() {
// TODO Auto-generated method stub ITranslationUnit tu = null;
return null; CModelManager mgr = CModelManager.getDefault();
ICElement parent = getParent();
if (parent != null) {
IPath path = parent.getPath();
if (path != null && path.isAbsolute()) {
IResource res = mgr.getCModel().getWorkspace().getRoot().getFileForLocation(path);
if (res != null && res.exists() && res.getType() == IResource.FILE) {
ICElement e = CModelManager.getDefault().create(res);
if (e instanceof ITranslationUnit) {
tu = (ITranslationUnit)e;
}
}
} else {
// ??? assert()
path = new Path("");
}
// Fall back to the project sourcemapper.
if (tu == null) {
ICProject cproject = getCProject();
SourceMapper mapper = mgr.getSourceMapper(cproject);
if (mapper != null) {
tu = mapper.findTranslationUnit(path.lastSegment());
}
}
}
return tu;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -114,8 +146,7 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
* @see org.eclipse.cdt.core.model.IBinaryElement#getAddress() * @see org.eclipse.cdt.core.model.IBinaryElement#getAddress()
*/ */
public long getAddress() throws CModelException { public long getAddress() throws CModelException {
// TODO Auto-generated method stub return addr;
return 0;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -12,8 +12,8 @@ import org.eclipse.cdt.core.model.IFunction;
*/ */
public class BinaryFunction extends BinaryElement implements IFunction { public class BinaryFunction extends BinaryElement implements IFunction {
public BinaryFunction(ICElement parent, String name) { public BinaryFunction(ICElement parent, String name, long a) {
super(parent, name, ICElement.C_FUNCTION); super(parent, name, ICElement.C_FUNCTION, a);
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -12,8 +12,8 @@ import org.eclipse.cdt.core.model.IVariable;
*/ */
public class BinaryVariable extends BinaryElement implements IVariable { public class BinaryVariable extends BinaryElement implements IVariable {
public BinaryVariable(ICElement parent, String name) { public BinaryVariable(ICElement parent, String name, long a) {
super(parent, name, ICElement.C_VARIABLE); super(parent, name, ICElement.C_VARIABLE, a);
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -0,0 +1,54 @@
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
/**
*/
public class SourceMapper {
ICProject cproject;
public SourceMapper(ICProject p) {
cproject = p;
}
public ITranslationUnit findTranslationUnit(String filename) {
return findTranslationUnit(cproject, filename);
}
public ITranslationUnit findTranslationUnit(ICContainer container, String filename) {
ArrayList list = container.getChildrenOfType(ICElement.C_UNIT);
for (int i = 0; i < list.size(); i++) {
Object o = list.get(i);
if (o instanceof ITranslationUnit) {
ITranslationUnit tu = (ITranslationUnit)o;
// TODO: What about non case sensitive filesystems.
if (filename.equals(tu.getElementName())) {
return tu;
}
}
}
// TODO: This to simple, we are not protected against
// loop in the file system symbolic links etc ..
list = container.getChildrenOfType(ICElement.C_CCONTAINER);
for (int i = 0; i < list.size(); i++) {
Object o = list.get(i);
if (o instanceof ICContainer) {
ITranslationUnit tu = findTranslationUnit((ICContainer)o, filename);
if (tu != null) {
return tu;
}
}
}
return null;
}
}