mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
New class hierarchy for the binary and Archive:
IBinary IBinaryModule IBinaryFunction IBinaryVariable IBinaryElement
This commit is contained in:
parent
5c6b6cf09d
commit
aaad8cbc6b
13 changed files with 533 additions and 344 deletions
|
@ -62,14 +62,7 @@ public class Archive extends Openable implements IArchive {
|
|||
IBinaryObject[] objects = ar.getObjects();
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
final IBinaryObject obj = objects[i];
|
||||
Binary binary = new Binary(this, res.getLocation().append(obj.getName())) {
|
||||
protected IBinaryObject getBinaryObject(IResource res) {
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
// Force the loading of the children inf the Info by callin getElementInfo.
|
||||
binary.getElementInfo();
|
||||
Binary binary = new Binary(this, res.getLocation().append(obj.getName()), obj);
|
||||
info.addChild(binary);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -5,20 +5,18 @@ package org.eclipse.cdt.internal.core.model;
|
|||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
|
||||
import org.eclipse.cdt.core.IBinaryParser.ISymbol;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBinary;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
@ -26,67 +24,101 @@ import org.eclipse.core.runtime.Path;
|
|||
|
||||
public class Binary extends Openable implements IBinary {
|
||||
|
||||
public Binary(ICElement parent, IFile file) {
|
||||
this(parent, file.getLocation());
|
||||
IBinaryFile binaryFile;
|
||||
|
||||
public Binary(ICElement parent, IFile file, IBinaryFile bin) {
|
||||
super(parent, file, ICElement.C_BINARY);
|
||||
binaryFile = bin;
|
||||
}
|
||||
|
||||
public Binary(ICElement parent, IPath path) {
|
||||
public Binary(ICElement parent, IPath path, IBinaryFile bin) {
|
||||
super (parent, path, ICElement.C_BINARY);
|
||||
binaryFile = bin;
|
||||
}
|
||||
|
||||
public Binary(ICElement parent, IFile file, String name) {
|
||||
super(parent, file, name, ICElement.C_BINARY);
|
||||
}
|
||||
|
||||
public boolean hasDebug () {
|
||||
return ((BinaryInfo)getElementInfo()).hasDebug();
|
||||
public boolean isSharedLib() {
|
||||
if (binaryFile != null) {
|
||||
return binaryFile.getType() == IBinaryObject.SHARED;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExecutable() {
|
||||
return ((BinaryInfo)getElementInfo()).isExecutable();
|
||||
if (binaryFile != null) {
|
||||
return binaryFile.getType() == IBinaryObject.EXECUTABLE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isObject() {
|
||||
return ((BinaryInfo)getElementInfo()).isObject();
|
||||
}
|
||||
|
||||
public boolean isSharedLib() {
|
||||
return ((BinaryInfo)getElementInfo()).isSharedLib();
|
||||
if (binaryFile != null) {
|
||||
return binaryFile.getType() == IBinaryObject.OBJECT;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCore() {
|
||||
return ((BinaryInfo)getElementInfo()).isCore();
|
||||
if (binaryFile != null) {
|
||||
return binaryFile.getType() == IBinaryObject.CORE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String [] getNeededSharedLibs() {
|
||||
return ((BinaryInfo)getElementInfo()).getNeededSharedLibs();
|
||||
public boolean hasDebug() {
|
||||
if (isObject() || isExecutable() || isSharedLib()) {
|
||||
return ((IBinaryObject)binaryFile).hasDebug();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getCPU() {
|
||||
return ((BinaryInfo)getElementInfo()).getCPU();
|
||||
if (isObject() || isExecutable() || isSharedLib() || isCore()) {
|
||||
return ((IBinaryObject)binaryFile).getCPU();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String[] getNeededSharedLibs() {
|
||||
if (isExecutable()) {
|
||||
return ((IBinaryExecutable)binaryFile).getNeededSharedLibs();
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public long getText() {
|
||||
return ((BinaryInfo)getElementInfo()).getText();
|
||||
if (isObject() || isExecutable() || isSharedLib()) {
|
||||
return ((IBinaryObject)binaryFile).getText();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long getData() {
|
||||
return ((BinaryInfo)getElementInfo()).getData();
|
||||
if (isObject() || isExecutable() || isSharedLib()) {
|
||||
return ((IBinaryObject)binaryFile).getData();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long getBSS() {
|
||||
return ((BinaryInfo)getElementInfo()).getBSS();
|
||||
if (isObject() || isExecutable() || isSharedLib()) {
|
||||
return ((IBinaryObject)binaryFile).getBSS();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getSoname() {
|
||||
return ((BinaryInfo)getElementInfo()).getSoname();
|
||||
if (isSharedLib()) {
|
||||
return ((IBinaryShared)binaryFile).getSoName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.model.IBinary#isLittleEndian()
|
||||
*/
|
||||
public boolean isLittleEndian() {
|
||||
return ((BinaryInfo)getElementInfo()).isLittleEndian();
|
||||
if (isObject() || isExecutable() || isSharedLib() || isCore()) {
|
||||
return ((IBinaryObject)binaryFile).isLittleEndian();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CElementInfo createElementInfo() {
|
||||
|
@ -104,10 +136,9 @@ public class Binary extends Openable implements IBinary {
|
|||
|
||||
|
||||
boolean computeChildren(OpenableInfo info, IResource res) {
|
||||
IBinaryObject bin = getBinaryObject(res);
|
||||
if (bin != null) {
|
||||
if (isObject() || isExecutable() || isSharedLib()) {
|
||||
Map hash = new HashMap();
|
||||
ISymbol[] symbols = bin.getSymbols();
|
||||
ISymbol[] symbols = ((IBinaryObject)binaryFile).getSymbols();
|
||||
for (int i = 0; i < symbols.length; i++) {
|
||||
switch (symbols[i].getType()) {
|
||||
case ISymbol.FUNCTION :
|
||||
|
@ -119,74 +150,37 @@ public class Binary extends Openable implements IBinary {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (info instanceof BinaryInfo) {
|
||||
((BinaryInfo)info).loadInfo(bin);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected IBinaryObject getBinaryObject(IResource res) {
|
||||
IBinaryObject binary = null;
|
||||
IBinaryParser parser = null;
|
||||
IProject project = null;
|
||||
if (res != null) {
|
||||
project = res.getProject();
|
||||
}
|
||||
if (project != null) {
|
||||
parser = CModelManager.getDefault().getBinaryParser(project);
|
||||
}
|
||||
if (parser != null) {
|
||||
try {
|
||||
IPath path = res.getLocation();
|
||||
IBinaryFile bfile = parser.getBinary(path);
|
||||
if (bfile instanceof IBinaryObject) {
|
||||
binary = (IBinaryObject) bfile;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return binary;
|
||||
}
|
||||
|
||||
private void addFunction(OpenableInfo info, ISymbol symbol, Map hash) {
|
||||
ICElement parent = this;
|
||||
String filename = filename = symbol.getFilename();
|
||||
Function function = null;
|
||||
BinaryFunction function = null;
|
||||
|
||||
// Addr2line returns the funny "??" when it can find the file.
|
||||
if (filename != null && !filename.equals("??")) {
|
||||
TranslationUnit tu = null;
|
||||
BinaryModule module = null;
|
||||
IPath path = new Path(filename);
|
||||
if (hash.containsKey(path)) {
|
||||
tu = (TranslationUnit) hash.get(path);
|
||||
module = (BinaryModule)hash.get(path);
|
||||
} else {
|
||||
// A special ITranslationUnit we do not want the file to be parse.
|
||||
tu = new TranslationUnit(parent, path) {
|
||||
ArrayList array = new ArrayList(5);
|
||||
public void addChild(ICElement e) {
|
||||
array.add(e);
|
||||
array.trimToSize();
|
||||
}
|
||||
|
||||
public ICElement [] getChildren() {
|
||||
return (ICElement[])array.toArray(new ICElement[0]);
|
||||
}
|
||||
|
||||
protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm,
|
||||
Map newElements, IResource underlyingResource) throws CModelException {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
hash.put(path, tu);
|
||||
info.addChild(tu);
|
||||
// A special container we do not want the file to be parse.
|
||||
module = new BinaryModule(this, path);
|
||||
hash.put(path, module);
|
||||
info.addChild(module);
|
||||
}
|
||||
function = new Function(tu, symbol.getName());
|
||||
tu.addChild(function);
|
||||
function = new BinaryFunction(module, symbol.getName());
|
||||
function.setLines(symbol.getStartLine(), symbol.getEndLine());
|
||||
function.setAddress(symbol.getAdress());
|
||||
module.addChild(function);
|
||||
} else {
|
||||
function = new Function(parent, symbol.getName());
|
||||
//function = new Function(parent, symbol.getName());
|
||||
function = new BinaryFunction(this, symbol.getName());
|
||||
function.setLines(symbol.getStartLine(), symbol.getEndLine());
|
||||
function.setAddress(symbol.getAdress());
|
||||
info.addChild(function);
|
||||
}
|
||||
// if (function != null) {
|
||||
|
@ -198,40 +192,29 @@ public class Binary extends Openable implements IBinary {
|
|||
|
||||
private void addVariable(OpenableInfo info, ISymbol symbol, Map hash) {
|
||||
String filename = filename = symbol.getFilename();
|
||||
ICElement parent = this;
|
||||
Variable variable = null;
|
||||
BinaryVariable variable = null;
|
||||
// Addr2line returns the funny "??" when it can not find the file.
|
||||
if (filename != null && !filename.equals("??")) {
|
||||
TranslationUnit tu = null;
|
||||
BinaryModule module = null;
|
||||
IPath path = new Path(filename);
|
||||
if (hash.containsKey(path)) {
|
||||
tu = (TranslationUnit) hash.get(path);
|
||||
module = (BinaryModule)hash.get(path);
|
||||
} else {
|
||||
tu = new TranslationUnit(parent, path) {
|
||||
ArrayList array = new ArrayList(5);
|
||||
public void addChild(ICElement e) {
|
||||
array.add(e);
|
||||
array.trimToSize();
|
||||
}
|
||||
|
||||
public ICElement [] getChildren() {
|
||||
return (ICElement[])array.toArray(new ICElement[0]);
|
||||
}
|
||||
|
||||
protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm,
|
||||
Map newElements, IResource underlyingResource) throws CModelException {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
hash.put(path, tu);
|
||||
info.addChild(tu);
|
||||
module = new BinaryModule(this, path);
|
||||
hash.put(path, module);
|
||||
info.addChild(module);
|
||||
}
|
||||
variable = new Variable(tu, symbol.getName());
|
||||
tu.addChild(variable);
|
||||
variable = new BinaryVariable(module, symbol.getName());
|
||||
variable.setLines(symbol.getStartLine(), symbol.getEndLine());
|
||||
variable.setAddress(symbol.getAdress());
|
||||
module.addChild(variable);
|
||||
} else {
|
||||
variable = new Variable(parent, symbol.getName());
|
||||
variable = new BinaryVariable(this, symbol.getName());
|
||||
variable.setLines(symbol.getStartLine(), symbol.getEndLine());
|
||||
variable.setAddress(symbol.getAdress());
|
||||
info.addChild(variable);
|
||||
}
|
||||
|
||||
//if (variable != null) {
|
||||
// if (!external) {
|
||||
// variable.getVariableInfo().setAccessControl(IConstants.AccStatic);
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Created on Mar 30, 2003
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
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.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.IResource;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class BinaryElement extends CElement implements IBinaryElement, ISourceManipulation, ISourceReference {
|
||||
|
||||
long addr;
|
||||
|
||||
public BinaryElement(ICElement parent, String name, int type) {
|
||||
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)
|
||||
throws CModelException {
|
||||
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
|
||||
}
|
||||
|
||||
/* (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 {
|
||||
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)
|
||||
throws CModelException {
|
||||
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
|
||||
}
|
||||
|
||||
/* (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 {
|
||||
throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceReference#getSource()
|
||||
*/
|
||||
public String getSource() throws CModelException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceReference#getSourceRange()
|
||||
*/
|
||||
public ISourceRange getSourceRange() throws CModelException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceReference#getTranslationUnit()
|
||||
*/
|
||||
public ITranslationUnit getTranslationUnit() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.model.CElement#createElementInfo()
|
||||
*/
|
||||
protected CElementInfo createElementInfo() {
|
||||
return new CElementInfo(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICElement#getResource()
|
||||
*/
|
||||
public IResource getResource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBinaryElement#getAddress()
|
||||
*/
|
||||
public long getAddress() throws CModelException {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBinaryElement#getBinary()
|
||||
*/
|
||||
public IBinary getBinary() {
|
||||
ICElement current = this;
|
||||
do {
|
||||
if (current instanceof IBinary) {
|
||||
return (IBinary) current;
|
||||
}
|
||||
} while ((current = current.getParent()) != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IFunction;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class BinaryFunction extends BinaryElement implements IFunction {
|
||||
|
||||
public BinaryFunction(ICElement parent, String name) {
|
||||
super(parent, name, ICElement.C_FUNCTION);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IFunctionDeclaration#getExceptions()
|
||||
*/
|
||||
public String[] getExceptions() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IFunctionDeclaration#getNumberOfParameters()
|
||||
*/
|
||||
public int getNumberOfParameters() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IFunctionDeclaration#getParameterInitializer(int)
|
||||
*/
|
||||
public String getParameterInitializer(int pos) {
|
||||
// TODO Auto-generated method stub
|
||||
return new String();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IFunctionDeclaration#getParameterTypes()
|
||||
*/
|
||||
public String[] getParameterTypes() {
|
||||
// TODO Auto-generated method stub
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IFunctionDeclaration#getReturnType()
|
||||
*/
|
||||
public String getReturnType() {
|
||||
// TODO Auto-generated method stub
|
||||
return new String();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IFunctionDeclaration#getSignature()
|
||||
*/
|
||||
public String getSignature() {
|
||||
return getElementName();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IDeclaration#isStatic()
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IDeclaration#isConst()
|
||||
*/
|
||||
public boolean isConst() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IDeclaration#isVolatile()
|
||||
*/
|
||||
public boolean isVolatile() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IDeclaration#getAccessControl()
|
||||
*/
|
||||
public int getAccessControl() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,121 +5,11 @@ package org.eclipse.cdt.internal.core.model;
|
|||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryShared;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
class BinaryInfo extends OpenableInfo {
|
||||
|
||||
int type;
|
||||
boolean debug;
|
||||
String cpu = "";
|
||||
String shared[] = new String[0];
|
||||
long text;
|
||||
long data;
|
||||
long bss;
|
||||
String soname = "";
|
||||
boolean littleE;
|
||||
|
||||
public BinaryInfo(CElement element) {
|
||||
super(element);
|
||||
}
|
||||
|
||||
public String getCPU() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
public boolean isSharedLib() {
|
||||
return type == IBinaryObject.SHARED;
|
||||
}
|
||||
|
||||
public boolean isExecutable() {
|
||||
return type == IBinaryObject.EXECUTABLE;
|
||||
}
|
||||
|
||||
public boolean isObject() {
|
||||
return type == IBinaryObject.OBJECT;
|
||||
}
|
||||
|
||||
public boolean isCore() {
|
||||
return type == IBinaryObject.CORE;
|
||||
}
|
||||
|
||||
public boolean hasDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public String[] getNeededSharedLibs() {
|
||||
return shared;
|
||||
}
|
||||
|
||||
public long getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public long getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public long getBSS() {
|
||||
return bss;
|
||||
}
|
||||
|
||||
public String getSoname() {
|
||||
return soname;
|
||||
}
|
||||
|
||||
public boolean isLittleEndian() {
|
||||
return littleE;
|
||||
}
|
||||
|
||||
protected void loadInfo() {
|
||||
loadInfo(getBinaryObject());
|
||||
}
|
||||
|
||||
protected void loadInfo(IBinaryObject bin) {
|
||||
if (bin != null) {
|
||||
type = bin.getType();
|
||||
cpu = bin.getCPU();
|
||||
debug = bin.hasDebug();
|
||||
if (isExecutable()) {
|
||||
IBinaryExecutable exec = (IBinaryExecutable) bin;
|
||||
shared = exec.getNeededSharedLibs();
|
||||
}
|
||||
text = bin.getText();
|
||||
data = bin.getData();
|
||||
bss = bin.getBSS();
|
||||
if (isSharedLib()) {
|
||||
IBinaryShared shared = (IBinaryShared) bin;
|
||||
soname = shared.getSoName();
|
||||
}
|
||||
littleE = bin.isLittleEndian();
|
||||
}
|
||||
}
|
||||
|
||||
private IBinaryObject getBinaryObject() {
|
||||
IBinaryObject binary = null;
|
||||
IProject project = getElement().getCProject().getProject();
|
||||
IBinaryParser parser = CModelManager.getDefault().getBinaryParser(project);
|
||||
if (parser != null) {
|
||||
try {
|
||||
IPath path = getElement().getUnderlyingResource().getLocation();
|
||||
IBinaryFile bfile = parser.getBinary(path);
|
||||
if (bfile instanceof IBinaryObject) {
|
||||
binary = (IBinaryObject) bfile;
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return binary;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
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.IBinaryModule;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class BinaryModule extends Parent implements IBinaryModule {
|
||||
|
||||
IPath path;
|
||||
|
||||
public BinaryModule(Binary parent, IPath p) {
|
||||
super(parent, p.lastSegment(), ICElement.C_VCONTAINER);
|
||||
path = p;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBinaryModule#getBinaryElements()
|
||||
*/
|
||||
public IBinaryElement[] getBinaryElements() {
|
||||
ICElement[] e = getChildren();
|
||||
IBinaryElement[] b = new IBinaryElement[e.length];
|
||||
System.arraycopy(e, 0, b, 0, e.length);
|
||||
return b;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBinaryElement#getAddress()
|
||||
*/
|
||||
public long getAddress() throws CModelException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IBinaryElement#getBinary()
|
||||
*/
|
||||
public IBinary getBinary() {
|
||||
return (IBinary)getParent();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICElement#getResource()
|
||||
*/
|
||||
public IResource getResource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICElement#isReadOnly()
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.model.CElement#createElementInfo()
|
||||
*/
|
||||
protected CElementInfo createElementInfo() {
|
||||
return new CElementInfo(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICElement#getPath()
|
||||
*/
|
||||
public IPath getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
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);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IVariable#getInitializer()
|
||||
*/
|
||||
public String getInitializer() {
|
||||
// TODO Auto-generated method stub
|
||||
return "";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IVariableDeclaration#getTypeName()
|
||||
*/
|
||||
public String getTypeName() {
|
||||
// TODO Auto-generated method stub
|
||||
return "";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IVariableDeclaration#setTypeName(java.lang.String)
|
||||
*/
|
||||
public void setTypeName(String type) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IDeclaration#isStatic()
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IDeclaration#isConst()
|
||||
*/
|
||||
public boolean isConst() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IDeclaration#isVolatile()
|
||||
*/
|
||||
public boolean isVolatile() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IDeclaration#getAccessControl()
|
||||
*/
|
||||
public int getAccessControl() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -138,7 +138,7 @@ public class CContainer extends Openable implements ICContainer {
|
|||
} catch (CoreException e) {
|
||||
//System.out.println (e);
|
||||
//CPlugin.log (e);
|
||||
e.printStackTrace();
|
||||
//e.printStackTrace();
|
||||
}
|
||||
ICElement[] children = new ICElement[vChildren.size()];
|
||||
vChildren.toArray(children);
|
||||
|
|
|
@ -69,7 +69,7 @@ public class CContainerInfo extends OpenableInfo {
|
|||
} catch (CoreException e) {
|
||||
//System.out.println (e);
|
||||
//CPlugin.log (e);
|
||||
e.printStackTrace();
|
||||
//e.printStackTrace();
|
||||
}
|
||||
setNonCResources(notChildren.toArray());
|
||||
return nonCResources;
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.eclipse.cdt.core.model.IParent;
|
|||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
public abstract class CElement extends PlatformObject implements ICElement {
|
||||
|
@ -75,7 +76,7 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
|||
} catch (CModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return new Path(getElementName());
|
||||
}
|
||||
|
||||
public boolean exists() {
|
||||
|
@ -155,8 +156,16 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
|||
fEndLine = endLine;
|
||||
}
|
||||
|
||||
|
||||
public abstract IResource getUnderlyingResource() throws CModelException;
|
||||
public IResource getUnderlyingResource() throws CModelException {
|
||||
IResource res = getResource();
|
||||
if (res == null) {
|
||||
ICElement p = getParent();
|
||||
if (p != null) {
|
||||
res = p.getUnderlyingResource();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public abstract IResource getResource() ;
|
||||
|
||||
|
@ -292,8 +301,10 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
|||
* <p>Subclasses that are not IOpenable's must override this method.
|
||||
*/
|
||||
public IOpenable getOpenableParent() {
|
||||
|
||||
return (IOpenable)fParent;
|
||||
if (fParent instanceof IOpenable) {
|
||||
return (IOpenable)fParent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.model.ICElementDelta;
|
|||
import org.eclipse.cdt.core.model.ICModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -210,26 +211,11 @@ public class CModelManager implements IResourceChangeListener {
|
|||
if (bin.getType() == IBinaryFile.ARCHIVE) {
|
||||
cfile = new Archive(parent, file);
|
||||
} else {
|
||||
cfile = new Binary(parent, file);
|
||||
cfile = new Binary(parent, file, bin);
|
||||
}
|
||||
} else if (isTranslationUnit(file)) {
|
||||
cfile = new TranslationUnit(parent, file);
|
||||
}
|
||||
//else {
|
||||
// cfile = new CFile(parent, file);
|
||||
//}
|
||||
} else {
|
||||
// Probably it was deleted, find it
|
||||
if (parent instanceof CElement) {
|
||||
ICElement[] children = ((CElement)parent).getElementInfo().getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
IResource res = children[i].getResource();
|
||||
if (res != null && res.equals(file)) {
|
||||
cfile = children[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Added also to the Containers
|
||||
if (cfile != null && (cfile instanceof IBinary || cfile instanceof IArchive)) {
|
||||
|
@ -305,26 +291,6 @@ public class CModelManager implements IResourceChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void releaseCElement(IResource resource) {
|
||||
ICElement celement = getCElement(resource);
|
||||
if (celement == null) {
|
||||
if (resource.exists()) {
|
||||
celement = create(resource);
|
||||
} else {
|
||||
// Make sure they are not in the Containers.
|
||||
CProject cproj = (CProject)create(resource.getProject());
|
||||
if (cproj != null) {
|
||||
Parent container = (Parent)cproj.getArchiveContainer();
|
||||
removeChildrenContainer(container, resource);
|
||||
container = (Parent)cproj.getBinaryContainer();
|
||||
removeChildrenContainer(container, resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
releaseCElement(celement);
|
||||
}
|
||||
|
||||
public void releaseCElement(ICElement celement) {
|
||||
|
||||
// Guard.
|
||||
|
@ -349,30 +315,25 @@ public class CModelManager implements IResourceChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
if (celement instanceof IParent) {
|
||||
CElementInfo info = ((CElement)celement).getElementInfo();
|
||||
if (info != null) {
|
||||
ICElement[] children = info.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
releaseCElement(children[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the child from the parent list.
|
||||
Parent parent = (Parent)celement.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeChild(celement);
|
||||
}
|
||||
|
||||
if (celement instanceof CElement) {
|
||||
CElementInfo info = ((CElement)celement).getElementInfo();
|
||||
ICElement[] children = info.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
releaseCElement(children[i]);
|
||||
}
|
||||
}
|
||||
removeInfo(celement);
|
||||
}
|
||||
|
||||
public ICElement getCElement(IResource res) {
|
||||
return create(res);
|
||||
}
|
||||
|
||||
public ICElement getCElement(IPath path) {
|
||||
return create(path);
|
||||
}
|
||||
|
||||
public IBinaryParser getBinaryParser(IProject project) {
|
||||
try {
|
||||
return CCorePlugin.getDefault().getBinaryParser(project);
|
||||
|
@ -396,12 +357,15 @@ public class CModelManager implements IResourceChangeListener {
|
|||
*/
|
||||
public void resetBinaryParser(IProject project) {
|
||||
if (project != null) {
|
||||
releaseCElement(project);
|
||||
// Fired and ICElementDelta.PARSER_CHANGED
|
||||
CElementDelta delta = new CElementDelta(getCModel());
|
||||
delta.binaryParserChanged(create(project));
|
||||
registerCModelDelta(delta);
|
||||
fire();
|
||||
ICElement celement = create(project);
|
||||
if (celement != null) {
|
||||
releaseCElement(celement);
|
||||
// Fired and ICElementDelta.PARSER_CHANGED
|
||||
CElementDelta delta = new CElementDelta(getCModel());
|
||||
delta.binaryParserChanged(celement);
|
||||
registerCModelDelta(delta);
|
||||
fire();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,9 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public abstract class Openable extends Parent implements IOpenable, IBufferChangedListener {
|
||||
|
||||
|
||||
protected IResource resource;
|
||||
|
||||
public Openable (ICElement parent, IPath path, int type) {
|
||||
// Check if the file is under the workspace.
|
||||
this (parent, ResourcesPlugin.getWorkspace().getRoot().getFileForLocation (path),
|
||||
|
@ -34,26 +36,14 @@ public abstract class Openable extends Parent implements IOpenable, IBufferChang
|
|||
this (parent, resource, resource.getName(), type);
|
||||
}
|
||||
|
||||
public Openable (ICElement parent, IResource resource, String name, int type) {
|
||||
super (parent, resource, name, type);
|
||||
}
|
||||
|
||||
public IResource getUnderlyingResource() throws CModelException {
|
||||
IResource res = getResource();
|
||||
if (res == null) {
|
||||
ICElement p = getParent();
|
||||
if (p != null) {
|
||||
res = p.getUnderlyingResource();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
public Openable (ICElement parent, IResource res, String name, int type) {
|
||||
super (parent, name, type);
|
||||
resource = res;
|
||||
}
|
||||
|
||||
public IResource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
protected abstract CElementInfo createElementInfo ();
|
||||
|
||||
/**
|
||||
* The buffer associated with this element has changed. Registers
|
||||
|
|
|
@ -7,30 +7,13 @@ package org.eclipse.cdt.internal.core.model;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
public abstract class Parent extends CElement implements IParent {
|
||||
|
||||
protected IResource resource;
|
||||
|
||||
public Parent (ICElement parent, IPath path, int type) {
|
||||
// Check if the file is under the workspace.
|
||||
this (parent, ResourcesPlugin.getWorkspace().getRoot().getFileForLocation (path),
|
||||
path.lastSegment(), type);
|
||||
}
|
||||
|
||||
public Parent (ICElement parent, String name, int type) {
|
||||
this (parent, null, name, type);
|
||||
}
|
||||
|
||||
public Parent (ICElement parent, IResource resource, String name, int type) {
|
||||
super (parent, name, type);
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
// members
|
||||
|
@ -86,24 +69,6 @@ public abstract class Parent extends CElement implements IParent {
|
|||
return getElementInfo().hasChildren();
|
||||
}
|
||||
|
||||
public void setUnderlyingResource(IResource res) {
|
||||
resource = res;
|
||||
}
|
||||
|
||||
public IResource getUnderlyingResource() throws CModelException {
|
||||
if (resource == null) {
|
||||
ICElement p = getParent();
|
||||
if (p != null) {
|
||||
return p.getUnderlyingResource();
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
public IResource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
protected void setChanged () {
|
||||
getElementInfo().setChanged();
|
||||
}
|
||||
|
@ -112,5 +77,4 @@ public abstract class Parent extends CElement implements IParent {
|
|||
return getElementInfo().hasChanged();
|
||||
}
|
||||
|
||||
protected abstract CElementInfo createElementInfo ();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue