mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Change in the BinaryElement constructor, takes
the address .
This commit is contained in:
parent
c4787b1801
commit
d0d01cd58e
5 changed files with 122 additions and 41 deletions
|
@ -172,15 +172,13 @@ public class Binary extends Openable implements IBinary {
|
|||
hash.put(path, 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.setAddress(symbol.getAdress());
|
||||
module.addChild(function);
|
||||
} else {
|
||||
//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.setAddress(symbol.getAdress());
|
||||
info.addChild(function);
|
||||
}
|
||||
// if (function != null) {
|
||||
|
@ -204,14 +202,12 @@ public class Binary extends Openable implements IBinary {
|
|||
hash.put(path, 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.setAddress(symbol.getAdress());
|
||||
module.addChild(variable);
|
||||
} else {
|
||||
variable = new BinaryVariable(this, symbol.getName());
|
||||
variable = new BinaryVariable(this, symbol.getName(), symbol.getAddress());
|
||||
variable.setLines(symbol.getStartLine(), symbol.getEndLine());
|
||||
variable.setAddress(symbol.getAdress());
|
||||
info.addChild(variable);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,23 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBinary;
|
||||
import org.eclipse.cdt.core.model.IBinaryElement;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
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.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
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;
|
||||
|
||||
public BinaryElement(ICElement parent, String name, int type) {
|
||||
public BinaryElement(ICElement parent, String name, int type, long a) {
|
||||
super(parent, name, type);
|
||||
}
|
||||
|
||||
public void setAddress(long a) {
|
||||
addr = a;
|
||||
}
|
||||
|
||||
/* (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)
|
||||
*/
|
||||
public void copy(
|
||||
ICElement container,
|
||||
ICElement sibling,
|
||||
String rename,
|
||||
boolean replace,
|
||||
IProgressMonitor monitor)
|
||||
public void copy(ICElement container, ICElement sibling, String rename, boolean replace, IProgressMonitor monitor)
|
||||
throws CModelException {
|
||||
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
|
||||
}
|
||||
|
@ -46,20 +44,14 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceManipulation#delete(boolean, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void delete(boolean force, IProgressMonitor monitor)
|
||||
throws CModelException {
|
||||
public void delete(boolean force, IProgressMonitor monitor) throws CModelException {
|
||||
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
|
||||
}
|
||||
|
||||
/* (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)
|
||||
*/
|
||||
public void move(
|
||||
ICElement container,
|
||||
ICElement sibling,
|
||||
String rename,
|
||||
boolean replace,
|
||||
IProgressMonitor monitor)
|
||||
public void move(ICElement container, ICElement sibling, String rename, boolean replace, IProgressMonitor monitor)
|
||||
throws CModelException {
|
||||
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
|
||||
}
|
||||
|
@ -67,8 +59,7 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
|
|||
/* (non-Javadoc)
|
||||
* @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)
|
||||
throws CModelException {
|
||||
public void rename(String name, boolean replace, IProgressMonitor monitor) throws CModelException {
|
||||
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()
|
||||
*/
|
||||
public String getSource() throws CModelException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
ITranslationUnit tu = getTranslationUnit();
|
||||
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)
|
||||
* @see org.eclipse.cdt.core.model.ISourceReference#getSourceRange()
|
||||
*/
|
||||
public ISourceRange getSourceRange() throws CModelException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return new SourceRange(getStartPos(),
|
||||
getLength(),
|
||||
getIdStartPos(),
|
||||
getIdLength(),
|
||||
getStartLine(),
|
||||
getEndLine());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceReference#getTranslationUnit()
|
||||
*/
|
||||
public ITranslationUnit getTranslationUnit() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
ITranslationUnit tu = 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)
|
||||
|
@ -114,8 +146,7 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
|
|||
* @see org.eclipse.cdt.core.model.IBinaryElement#getAddress()
|
||||
*/
|
||||
public long getAddress() throws CModelException {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return addr;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -126,7 +157,7 @@ public class BinaryElement extends CElement implements IBinaryElement, ISourceMa
|
|||
do {
|
||||
if (current instanceof IBinary) {
|
||||
return (IBinary) current;
|
||||
}
|
||||
}
|
||||
} while ((current = current.getParent()) != null);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.eclipse.cdt.core.model.IFunction;
|
|||
*/
|
||||
public class BinaryFunction extends BinaryElement implements IFunction {
|
||||
|
||||
public BinaryFunction(ICElement parent, String name) {
|
||||
super(parent, name, ICElement.C_FUNCTION);
|
||||
public BinaryFunction(ICElement parent, String name, long a) {
|
||||
super(parent, name, ICElement.C_FUNCTION, a);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.eclipse.cdt.core.model.IVariable;
|
|||
*/
|
||||
public class BinaryVariable extends BinaryElement implements IVariable {
|
||||
|
||||
public BinaryVariable(ICElement parent, String name) {
|
||||
super(parent, name, ICElement.C_VARIABLE);
|
||||
public BinaryVariable(ICElement parent, String name, long a) {
|
||||
super(parent, name, ICElement.C_VARIABLE, a);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue