mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Added parameters types to allow for content assist to show something useful in the completion proposals. Also refactored around names so that not every node needs a name and node types so that things that aren't bindings can be resolved by the Linkages. All this to properly support ITypes which aren't necessarily bindings.
This commit is contained in:
parent
d2b0d64e51
commit
d0da5589a7
30 changed files with 874 additions and 250 deletions
|
@ -44,6 +44,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Comparator;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -67,12 +68,13 @@ public class PDOM extends PlatformObject
|
|||
private final IPath dbPath;
|
||||
private Database db;
|
||||
|
||||
public static final int VERSION = 4;
|
||||
public static final int VERSION = 5;
|
||||
// 0 - the beginning of it all
|
||||
// 1 - first change to kick off upgrades
|
||||
// 2 - added file inclusions
|
||||
// 3 - added macros and change string implementation
|
||||
// 4 - added parameters in C++
|
||||
// 4 - added parameters in C++
|
||||
// 5 - added types and restructured nodes a bit
|
||||
|
||||
public static final int LINKAGES = Database.DATA_AREA;
|
||||
public static final int FILE_INDEX = Database.DATA_AREA + 4;
|
||||
|
@ -207,7 +209,7 @@ public class PDOM extends PlatformObject
|
|||
return file;
|
||||
}
|
||||
|
||||
public void addSymbols(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||
public void addSymbolsXXX(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||
final PDOMLinkage linkage = getLinkage(language);
|
||||
if (linkage == null)
|
||||
return;
|
||||
|
@ -403,8 +405,10 @@ public class PDOM extends PlatformObject
|
|||
public PDOMBinding getBinding(int record) throws CoreException {
|
||||
if (record == 0)
|
||||
return null;
|
||||
else
|
||||
return PDOMLinkage.getLinkage(this, record).getBinding(record);
|
||||
else {
|
||||
PDOMNode node = PDOMLinkage.getLinkage(this, record).getNode(record);
|
||||
return node instanceof PDOMBinding ? (PDOMBinding)node : null;
|
||||
}
|
||||
}
|
||||
|
||||
// Read-write lock rules. Readers don't conflict with other readers,
|
||||
|
|
|
@ -23,21 +23,16 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public abstract class PDOMBinding extends PDOMNode implements IBinding {
|
||||
public abstract class PDOMBinding extends PDOMNamedNode implements IBinding {
|
||||
|
||||
private static final int BINDING_TYPE_OFFSET = PDOMNode.RECORD_SIZE + 4; // size 4
|
||||
private static final int FIRST_DECL_OFFSET = PDOMNode.RECORD_SIZE + 8; // size 4
|
||||
private static final int FIRST_DEF_OFFSET = PDOMNode.RECORD_SIZE + 12; // size 4
|
||||
private static final int FIRST_REF_OFFSET = PDOMNode.RECORD_SIZE + 16; // size 4
|
||||
private static final int FIRST_DECL_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; // size 4
|
||||
private static final int FIRST_DEF_OFFSET = PDOMNamedNode.RECORD_SIZE + 4; // size 4
|
||||
private static final int FIRST_REF_OFFSET = PDOMNamedNode.RECORD_SIZE + 8; // size 4
|
||||
|
||||
protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 20;
|
||||
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 12;
|
||||
|
||||
protected PDOMBinding(PDOM pdom, PDOMNode parent, IASTName name, int type) throws CoreException {
|
||||
protected PDOMBinding(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name.toCharArray());
|
||||
Database db = pdom.getDB();
|
||||
|
||||
// Binding type
|
||||
db.putInt(record + BINDING_TYPE_OFFSET, type);
|
||||
}
|
||||
|
||||
public PDOMBinding(PDOM pdom, int record) {
|
||||
|
@ -51,10 +46,6 @@ public abstract class PDOMBinding extends PDOMNode implements IBinding {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static int getBindingType(PDOM pdom, int record) throws CoreException {
|
||||
return pdom.getDB().getInt(record + BINDING_TYPE_OFFSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the binding as the record orphaned, i.e., has no declarations
|
||||
* or references.
|
||||
|
@ -75,10 +66,6 @@ public abstract class PDOMBinding extends PDOMNode implements IBinding {
|
|||
return record;
|
||||
}
|
||||
|
||||
public int getBindingType() throws CoreException {
|
||||
return pdom.getDB().getInt(record + BINDING_TYPE_OFFSET);
|
||||
}
|
||||
|
||||
public boolean hasDeclarations() throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
return db.getInt(record + FIRST_DECL_OFFSET) != 0
|
||||
|
|
|
@ -18,6 +18,9 @@ import java.util.regex.Pattern;
|
|||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
|
@ -32,7 +35,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* This class represents a collection of symbols that can be linked together at
|
||||
* link time. These are generally global symbols specific to a given language.
|
||||
*/
|
||||
public abstract class PDOMLinkage extends PDOMNode {
|
||||
public abstract class PDOMLinkage extends PDOMNamedNode {
|
||||
|
||||
protected static final class MatchBinding implements IBTreeVisitor {
|
||||
private final PDOM pdom;
|
||||
|
@ -63,11 +66,19 @@ public abstract class PDOMLinkage extends PDOMNode {
|
|||
}
|
||||
}
|
||||
|
||||
private static final int ID_OFFSET = PDOMNode.RECORD_SIZE + 0;
|
||||
private static final int NEXT_OFFSET = PDOMNode.RECORD_SIZE + 4;
|
||||
private static final int INDEX_OFFSET = PDOMNode.RECORD_SIZE + 8;
|
||||
// record offsets
|
||||
private static final int ID_OFFSET = PDOMNamedNode.RECORD_SIZE + 0;
|
||||
private static final int NEXT_OFFSET = PDOMNamedNode.RECORD_SIZE + 4;
|
||||
private static final int INDEX_OFFSET = PDOMNamedNode.RECORD_SIZE + 8;
|
||||
|
||||
protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 12;
|
||||
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 12;
|
||||
|
||||
// node types
|
||||
protected static final int LINKAGE = 0; // special one for myself
|
||||
static final int POINTER_TYPE = 1;
|
||||
static final int QUALIFIER_TYPE = 2;
|
||||
|
||||
protected static final int LAST_NODE_TYPE = QUALIFIER_TYPE;
|
||||
|
||||
public PDOMLinkage(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
|
@ -132,15 +143,32 @@ public abstract class PDOMLinkage extends PDOMNode {
|
|||
return this;
|
||||
}
|
||||
|
||||
protected void addChild(PDOMNode child) throws CoreException {
|
||||
protected void addChild(PDOMNamedNode child) throws CoreException {
|
||||
getIndex().insert(child.getRecord(), child.getIndexComparator());
|
||||
}
|
||||
|
||||
public abstract PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException;
|
||||
|
||||
public abstract PDOMBinding adaptBinding(IBinding binding) throws CoreException;
|
||||
public PDOMNode getNode(int record) throws CoreException {
|
||||
switch (PDOMNode.getNodeType(pdom, record)) {
|
||||
case POINTER_TYPE:
|
||||
return new PDOMPointerType(pdom, record);
|
||||
case QUALIFIER_TYPE:
|
||||
return new PDOMQualifierType(pdom, record);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract PDOMBinding getBinding(int record) throws CoreException;
|
||||
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
|
||||
if (type instanceof IPointerType)
|
||||
return new PDOMPointerType(pdom, parent, (IPointerType)type);
|
||||
else if (type instanceof IQualifierType)
|
||||
return new PDOMQualifierType(pdom, parent, (IQualifierType)type);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract PDOMBinding addName(IASTName name, PDOMFile file) throws CoreException;
|
||||
|
||||
public abstract PDOMBinding adaptBinding(IBinding binding) throws CoreException;
|
||||
|
||||
public abstract PDOMBinding resolveBinding(IASTName name) throws CoreException;
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ public abstract class PDOMMember extends PDOMBinding {
|
|||
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 12;
|
||||
|
||||
public PDOMMember(PDOM pdom, PDOMMemberOwner parent, IASTName name, int type) throws CoreException {
|
||||
super(pdom, parent, name, type);
|
||||
public PDOMMember(PDOM pdom, PDOMMemberOwner parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
parent.addMember(this);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public abstract class PDOMMember extends PDOMBinding {
|
|||
}
|
||||
|
||||
public PDOMMember getNextMember() throws CoreException {
|
||||
return (PDOMMember)getLinkage().getBinding(
|
||||
return (PDOMMember)getLinkage().getNode(
|
||||
pdom.getDB().getInt(record + NEXT_MEMBER));
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public abstract class PDOMMember extends PDOMBinding {
|
|||
}
|
||||
|
||||
public PDOMMember getPrevMember() throws CoreException {
|
||||
return (PDOMMember)getLinkage().getBinding(
|
||||
return (PDOMMember)getLinkage().getNode(
|
||||
pdom.getDB().getInt(record + PREV_MEMBER));
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public abstract class PDOMMember extends PDOMBinding {
|
|||
}
|
||||
|
||||
public PDOMMemberOwner getMemberOwner() throws CoreException {
|
||||
return (PDOMCPPClassType)getLinkage().getBinding(
|
||||
return (PDOMCPPClassType)getLinkage().getNode(
|
||||
pdom.getDB().getInt(record + OWNER));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,16 +22,15 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMMemberOwner extends PDOMBinding {
|
||||
public abstract class PDOMMemberOwner extends PDOMBinding {
|
||||
|
||||
private static final int FIRST_MEMBER = PDOMBinding.RECORD_SIZE + 0;
|
||||
private static final int LAST_MEMBER = PDOMBinding.RECORD_SIZE + 4;
|
||||
|
||||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8;
|
||||
|
||||
public PDOMMemberOwner(PDOM pdom, PDOMNode parent, IASTName name,
|
||||
int type) throws CoreException {
|
||||
super(pdom, parent, name, type);
|
||||
public PDOMMemberOwner(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMMemberOwner(PDOM pdom, int record) {
|
||||
|
@ -63,12 +62,12 @@ public class PDOMMemberOwner extends PDOMBinding {
|
|||
}
|
||||
|
||||
public PDOMMember getFirstMember() throws CoreException {
|
||||
return (PDOMMember)getLinkage().getBinding(
|
||||
return (PDOMMember)getLinkage().getNode(
|
||||
pdom.getDB().getInt(record + FIRST_MEMBER));
|
||||
}
|
||||
|
||||
public PDOMMember getLastMember() throws CoreException {
|
||||
return (PDOMMember)getLinkage().getBinding(
|
||||
return (PDOMMember)getLinkage().getNode(
|
||||
pdom.getDB().getInt(record + LAST_MEMBER));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IString;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public abstract class PDOMNamedNode extends PDOMNode {
|
||||
|
||||
private static final int NAME = PDOMNode.RECORD_SIZE + 0;
|
||||
|
||||
protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
|
||||
|
||||
public PDOMNamedNode(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
}
|
||||
|
||||
public PDOMNamedNode(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
|
||||
super(pdom, parent);
|
||||
|
||||
Database db = pdom.getDB();
|
||||
db.putInt(record + NAME,
|
||||
name != null ? db.newString(name).getRecord() : 0);
|
||||
|
||||
if (parent != null)
|
||||
parent.addChild(this);
|
||||
}
|
||||
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public IString getDBName() throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
int namerec = db.getInt(record + NAME);
|
||||
return db.getString(namerec);
|
||||
}
|
||||
|
||||
public char[] getNameCharArray() throws CoreException {
|
||||
return getDBName().getChars();
|
||||
}
|
||||
|
||||
public boolean hasName(char[] name) throws CoreException {
|
||||
return getDBName().equals(name);
|
||||
}
|
||||
|
||||
public IBTreeComparator getIndexComparator() {
|
||||
return new IBTreeComparator() {
|
||||
public int compare(int record1, int record2) throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
int string1 = db.getInt(record1 + NAME);
|
||||
int string2 = db.getInt(record2 + NAME);
|
||||
return db.getString(string1).compare(db.getString(string2));
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
public abstract static class NodeFinder implements IBTreeVisitor {
|
||||
protected final PDOM pdom;
|
||||
protected final char[] name;
|
||||
protected NodeFinder(PDOM pdom, char [] name) {
|
||||
this.pdom = pdom;
|
||||
this.name = name;
|
||||
}
|
||||
public int compare(int record) throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
int namerec = db.getInt(record + NAME);
|
||||
return db.getString(namerec).compare(name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -15,9 +15,6 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
|
|||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IString;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -29,8 +26,8 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
public abstract class PDOMNode implements IPDOMNode{
|
||||
|
||||
private static final int PARENT = 0;
|
||||
private static final int NAME = 4;
|
||||
private static final int TYPE = 0;
|
||||
private static final int PARENT = 4;
|
||||
|
||||
protected static final int RECORD_SIZE = 8;
|
||||
|
||||
|
@ -42,24 +39,21 @@ public abstract class PDOMNode implements IPDOMNode{
|
|||
this.record = record;
|
||||
}
|
||||
|
||||
protected PDOMNode(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
|
||||
protected PDOMNode(PDOM pdom, PDOMNode parent) throws CoreException {
|
||||
this.pdom = pdom;
|
||||
Database db = pdom.getDB();
|
||||
|
||||
record = db.malloc(getRecordSize());
|
||||
|
||||
// name - must be before parent
|
||||
db.putInt(record + NAME, db.newString(name).getRecord());
|
||||
|
||||
// parent
|
||||
if (parent != null) {
|
||||
pdom.getDB().putInt(record + PARENT, parent.getRecord());
|
||||
parent.addChild(this);
|
||||
}
|
||||
// type
|
||||
db.putInt(record + TYPE, getNodeType());
|
||||
|
||||
// parent
|
||||
db.putInt(record + PARENT, parent != null ? parent.getRecord() : 0);
|
||||
}
|
||||
|
||||
protected abstract int getRecordSize();
|
||||
public abstract int getNodeType();
|
||||
|
||||
public PDOM getPDOM() {
|
||||
return pdom;
|
||||
|
@ -84,6 +78,10 @@ public abstract class PDOMNode implements IPDOMNode{
|
|||
// No children here.
|
||||
}
|
||||
|
||||
public static int getNodeType(PDOM pdom, int record) throws CoreException {
|
||||
return pdom.getDB().getInt(record + TYPE);
|
||||
}
|
||||
|
||||
public PDOMLinkage getLinkage() throws CoreException {
|
||||
return getLinkage(pdom, record);
|
||||
}
|
||||
|
@ -99,47 +97,9 @@ public abstract class PDOMNode implements IPDOMNode{
|
|||
|
||||
return pdom.getLinkage(linkagerec);
|
||||
}
|
||||
|
||||
public IString getDBName() throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
int namerec = db.getInt(record + NAME);
|
||||
return db.getString(namerec);
|
||||
}
|
||||
|
||||
public char[] getNameCharArray() throws CoreException {
|
||||
return getDBName().getChars();
|
||||
}
|
||||
|
||||
protected void addChild(PDOMNode child) throws CoreException {
|
||||
// by defaut do nothing
|
||||
|
||||
protected void addChild(PDOMNamedNode child) throws CoreException {
|
||||
// nothing here
|
||||
}
|
||||
|
||||
public boolean hasName(char[] name) throws CoreException {
|
||||
return getDBName().equals(name);
|
||||
}
|
||||
|
||||
public IBTreeComparator getIndexComparator() {
|
||||
return new IBTreeComparator() {
|
||||
public int compare(int record1, int record2) throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
int string1 = db.getInt(record1 + NAME);
|
||||
int string2 = db.getInt(record2 + NAME);
|
||||
return db.getString(string1).compare(db.getString(string2));
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
public abstract static class NodeFinder implements IBTreeVisitor {
|
||||
protected final PDOM pdom;
|
||||
protected final char[] name;
|
||||
protected NodeFinder(PDOM pdom, char [] name) {
|
||||
this.pdom = pdom;
|
||||
this.name = name;
|
||||
}
|
||||
public int compare(int record) throws CoreException {
|
||||
Database db = pdom.getDB();
|
||||
int namerec = db.getInt(record + NAME);
|
||||
return db.getString(namerec).compare(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
public class PDOMPointerType extends PDOMNode implements IPointerType,
|
||||
ITypeContainer {
|
||||
|
||||
private static final int FLAGS = PDOMNode.RECORD_SIZE + 1;
|
||||
private static final int TYPE = PDOMNode.RECORD_SIZE + 4;
|
||||
|
||||
private static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 5;
|
||||
|
||||
private static final int CONST = 0x1;
|
||||
private static final int VOLATILE = 0x2;
|
||||
|
||||
public PDOMPointerType(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
}
|
||||
|
||||
public PDOMPointerType(PDOM pdom, PDOMNode parent, IPointerType type) throws CoreException {
|
||||
super(pdom, parent);
|
||||
|
||||
Database db = pdom.getDB();
|
||||
|
||||
// type
|
||||
IType targetType = ((ITypeContainer)type).getType();
|
||||
if (type != null) {
|
||||
PDOMNode targetTypeNode = getLinkage().addType(this, targetType);
|
||||
if (targetTypeNode != null) {
|
||||
db.putInt(record + TYPE, targetTypeNode.getRecord());
|
||||
}
|
||||
}
|
||||
|
||||
// flags
|
||||
byte flags = 0;
|
||||
if (type.isConst())
|
||||
flags |= CONST;
|
||||
if (type.isVolatile())
|
||||
flags |= VOLATILE;
|
||||
db.putByte(record + FLAGS, flags);
|
||||
}
|
||||
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMLinkage.POINTER_TYPE;
|
||||
}
|
||||
|
||||
private byte getFlags() throws CoreException {
|
||||
return pdom.getDB().getByte(record + FLAGS);
|
||||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
try {
|
||||
PDOMNode node = getLinkage().getNode(pdom.getDB().getInt(record + TYPE));
|
||||
return node instanceof IType ? (IType)node : null;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConst() throws DOMException {
|
||||
try {
|
||||
return (getFlags() & CONST) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVolatile() throws DOMException {
|
||||
try {
|
||||
return (getFlags() & VOLATILE) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
return equals(type);
|
||||
}
|
||||
|
||||
public void setType(IType type) {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMQualifierType extends PDOMNode implements IQualifierType,
|
||||
ITypeContainer {
|
||||
|
||||
private static final int FLAGS = PDOMNode.RECORD_SIZE + 1;
|
||||
private static final int TYPE = PDOMNode.RECORD_SIZE + 4;
|
||||
|
||||
private static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 5;
|
||||
|
||||
private static final int CONST = 0x1;
|
||||
private static final int VOLATILE = 0x2;
|
||||
|
||||
public PDOMQualifierType(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
}
|
||||
|
||||
public PDOMQualifierType(PDOM pdom, PDOMNode parent, IQualifierType type) throws CoreException {
|
||||
super(pdom, parent);
|
||||
|
||||
Database db = pdom.getDB();
|
||||
|
||||
// type
|
||||
IType targetType = ((ITypeContainer)type).getType();
|
||||
if (type != null) {
|
||||
PDOMNode targetTypeNode = getLinkage().addType(this, targetType);
|
||||
if (targetTypeNode != null) {
|
||||
db.putInt(record + TYPE, targetTypeNode.getRecord());
|
||||
}
|
||||
}
|
||||
|
||||
// flags
|
||||
byte flags = 0;
|
||||
if (type.isConst())
|
||||
flags |= CONST;
|
||||
if (type.isVolatile())
|
||||
flags |= VOLATILE;
|
||||
db.putByte(record + FLAGS, flags);
|
||||
}
|
||||
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMLinkage.QUALIFIER_TYPE;
|
||||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
try {
|
||||
PDOMNode node = getLinkage().getNode(pdom.getDB().getInt(record + TYPE));
|
||||
return node instanceof IType ? (IType)node : null;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private byte getFlags() throws CoreException {
|
||||
return pdom.getDB().getByte(record + FLAGS);
|
||||
}
|
||||
|
||||
public boolean isConst() throws DOMException {
|
||||
try {
|
||||
return (getFlags() & CONST) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVolatile() throws DOMException {
|
||||
try {
|
||||
return (getFlags() & VOLATILE) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
return equals(type);
|
||||
}
|
||||
|
||||
public void setType(IType type) {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
public class PDOMCField extends PDOMMember implements IField {
|
||||
|
||||
public PDOMCField(PDOM pdom, PDOMMemberOwner parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCLinkage.CFIELD);
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMCField(PDOM pdom, int record) {
|
||||
|
@ -39,6 +39,10 @@ public class PDOMCField extends PDOMMember implements IField {
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCLinkage.CFIELD;
|
||||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
return null;
|
||||
// TODO - do we need the real type?
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
public class PDOMCFunction extends PDOMBinding implements IFunction {
|
||||
|
||||
public PDOMCFunction(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCLinkage.CFUNCTION);
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMCFunction(PDOM pdom, int record) {
|
||||
|
@ -41,6 +41,10 @@ public class PDOMCFunction extends PDOMBinding implements IFunction {
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCLinkage.CFUNCTION;
|
||||
}
|
||||
|
||||
public IParameter[] getParameters() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
|
|||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||
|
@ -37,6 +38,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -52,11 +54,15 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
public PDOMCLinkage(PDOM pdom) throws CoreException {
|
||||
super(pdom, GCCLanguage.ID, "C".toCharArray());
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return LINKAGE;
|
||||
}
|
||||
|
||||
public static final int CVARIABLE = 1;
|
||||
public static final int CFUNCTION = 2;
|
||||
public static final int CSTRUCTURE = 3;
|
||||
public static final int CFIELD = 4;
|
||||
public static final int CVARIABLE = PDOMLinkage.LAST_NODE_TYPE + 1;
|
||||
public static final int CFUNCTION = PDOMLinkage.LAST_NODE_TYPE + 2;
|
||||
public static final int CSTRUCTURE = PDOMLinkage.LAST_NODE_TYPE + 3;
|
||||
public static final int CFIELD = PDOMLinkage.LAST_NODE_TYPE + 4;
|
||||
|
||||
public ILanguage getLanguage() {
|
||||
return new GCCLanguage();
|
||||
|
@ -127,7 +133,7 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
return pdomBinding;
|
||||
}
|
||||
|
||||
private static final class FindBinding extends PDOMNode.NodeFinder {
|
||||
private static final class FindBinding extends PDOMNamedNode.NodeFinder {
|
||||
PDOMBinding pdomBinding;
|
||||
final int desiredType;
|
||||
public FindBinding(PDOM pdom, char[] name, int desiredType) {
|
||||
|
@ -141,7 +147,7 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
if (!tBinding.hasName(name))
|
||||
// no more bindings with our desired name
|
||||
return false;
|
||||
if (tBinding.getBindingType() != desiredType)
|
||||
if (tBinding.getNodeType() != desiredType)
|
||||
// wrong type, try again
|
||||
return true;
|
||||
|
||||
|
@ -182,14 +188,11 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage#getBinding(int)
|
||||
*/
|
||||
public PDOMBinding getBinding(int record) throws CoreException {
|
||||
public PDOMNode getNode(int record) throws CoreException {
|
||||
if (record == 0)
|
||||
return null;
|
||||
|
||||
switch (PDOMBinding.getBindingType(pdom, record)) {
|
||||
switch (PDOMNode.getNodeType(pdom, record)) {
|
||||
case CVARIABLE:
|
||||
return new PDOMCVariable(pdom, record);
|
||||
case CFUNCTION:
|
||||
|
@ -200,7 +203,7 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
return new PDOMCField(pdom, record);
|
||||
}
|
||||
|
||||
return null;
|
||||
return super.getNode(record);
|
||||
}
|
||||
|
||||
public PDOMBinding resolveBinding(IASTName name) throws CoreException {
|
||||
|
@ -229,4 +232,10 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
MatchBinding visitor = new MatchBinding(pdom, pattern, bindings);
|
||||
getIndex().accept(visitor);
|
||||
}
|
||||
|
||||
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,13 +32,17 @@ import org.eclipse.core.runtime.CoreException;
|
|||
public class PDOMCStructure extends PDOMMemberOwner implements ICompositeType {
|
||||
|
||||
public PDOMCStructure(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCLinkage.CSTRUCTURE);
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMCStructure(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCLinkage.CSTRUCTURE;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
public class PDOMCVariable extends PDOMBinding implements IVariable {
|
||||
|
||||
public PDOMCVariable(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCLinkage.CVARIABLE);
|
||||
super(pdom, parent, name);
|
||||
IVariable binding = (IVariable)name.getBinding();
|
||||
if (binding != null) {
|
||||
IType type = binding.getType();
|
||||
|
@ -43,6 +43,10 @@ public class PDOMCVariable extends PDOMBinding implements IVariable {
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCLinkage.CVARIABLE;
|
||||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
return null;
|
||||
// TODO - do we need the real type?
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems 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:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType {
|
||||
|
||||
public static final int TYPE_ID = PDOMNode.RECORD_SIZE + 0; // short
|
||||
public static final int FLAGS = PDOMNode.RECORD_SIZE + 2; // short
|
||||
|
||||
public static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
|
||||
|
||||
public static final int IS_LONG = 0x1;
|
||||
public static final int IS_SHORT = 0x2;
|
||||
public static final int IS_UNSIGNED = 0x4;
|
||||
public static final int IS_SIGNED = 0x8;
|
||||
|
||||
public PDOMCPPBasicType(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
}
|
||||
|
||||
public PDOMCPPBasicType(PDOM pdom, PDOMNode parent, ICPPBasicType type) throws CoreException {
|
||||
super(pdom, parent);
|
||||
|
||||
Database db = pdom.getDB();
|
||||
|
||||
db.putChar(record + TYPE_ID, (char)type.getType());
|
||||
|
||||
char flags = 0;
|
||||
if (type.isLong())
|
||||
flags |= IS_LONG;
|
||||
if (type.isShort())
|
||||
flags |= IS_SHORT;
|
||||
if (type.isSigned())
|
||||
flags |= IS_SIGNED;
|
||||
if (type.isUnsigned())
|
||||
flags |= IS_UNSIGNED;
|
||||
|
||||
db.putChar(record + FLAGS, flags);
|
||||
}
|
||||
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPBASICTYPE;
|
||||
}
|
||||
|
||||
public int getType() throws DOMException {
|
||||
try {
|
||||
return pdom.getDB().getChar(record + TYPE_ID);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public IASTExpression getValue() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
private char getFlags() throws CoreException {
|
||||
return pdom.getDB().getChar(record + FLAGS);
|
||||
}
|
||||
|
||||
public boolean isLong() throws DOMException {
|
||||
try {
|
||||
return (getFlags() & IS_LONG) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isShort() throws DOMException {
|
||||
try {
|
||||
return (getFlags() & IS_SHORT) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSigned() throws DOMException {
|
||||
try {
|
||||
return (getFlags() & IS_SIGNED) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUnsigned() throws DOMException {
|
||||
try {
|
||||
return (getFlags() & IS_UNSIGNED) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
// TODO something fancier
|
||||
return equals(type);
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -42,7 +42,7 @@ public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType,
|
|||
protected static final int RECORD_SIZE = PDOMMemberOwner.RECORD_SIZE + 0;
|
||||
|
||||
public PDOMCPPClassType(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCPPLinkage.CPPCLASSTYPE);
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMCPPClassType(PDOM pdom, int bindingRecord) {
|
||||
|
@ -52,6 +52,10 @@ public class PDOMCPPClassType extends PDOMMemberOwner implements ICPPClassType,
|
|||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPCLASSTYPE;
|
||||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
if (type instanceof PDOMBinding)
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PDOMCPPField extends PDOMMember implements ICPPField {
|
|||
|
||||
public PDOMCPPField(PDOM pdom, PDOMCPPClassType parent, IASTName name)
|
||||
throws CoreException {
|
||||
super(pdom, parent, name, PDOMCPPLinkage.CPPFIELD);
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMCPPField(PDOM pdom, int bindingRecord) {
|
||||
|
@ -42,6 +42,10 @@ public class PDOMCPPField extends PDOMMember implements ICPPField {
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPFIELD;
|
||||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
try {
|
||||
return (ICPPClassType)getMemberOwner();
|
||||
|
|
|
@ -44,7 +44,7 @@ public class PDOMCPPFunction extends PDOMBinding implements ICPPFunction, ICPPFu
|
|||
public static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8;
|
||||
|
||||
public PDOMCPPFunction(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCPPLinkage.CPPFUNCTION);
|
||||
super(pdom, parent, name);
|
||||
IASTNode parentNode = name.getParent();
|
||||
if (parentNode instanceof ICPPASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator funcDecl = (ICPPASTFunctionDeclarator)parentNode;
|
||||
|
@ -67,6 +67,10 @@ public class PDOMCPPFunction extends PDOMBinding implements ICPPFunction, ICPPFu
|
|||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPFUNCTION;
|
||||
}
|
||||
|
||||
public PDOMCPPParameter getFirstParameter() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + FIRST_PARAM);
|
||||
|
@ -146,8 +150,19 @@ public class PDOMCPPFunction extends PDOMBinding implements ICPPFunction, ICPPFu
|
|||
}
|
||||
|
||||
public IType[] getParameterTypes() throws DOMException {
|
||||
return new IType[0];
|
||||
// TODO throw new PDOMNotImplementedError();
|
||||
try {
|
||||
int n = pdom.getDB().getInt(record + NUM_PARAMS);
|
||||
IType[] types = new IType[n];
|
||||
PDOMCPPParameter param = getFirstParameter();
|
||||
while (param != null) {
|
||||
types[--n] = param.getType();
|
||||
param = param.getNextParameter();
|
||||
}
|
||||
return types;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return new IType[0];
|
||||
}
|
||||
}
|
||||
|
||||
public IType getReturnType() throws DOMException {
|
||||
|
|
|
@ -22,8 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
|
@ -49,6 +51,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -71,14 +74,20 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return LINKAGE;
|
||||
}
|
||||
|
||||
// Binding types
|
||||
public static final int CPPVARIABLE = 1;
|
||||
public static final int CPPFUNCTION = 2;
|
||||
public static final int CPPCLASSTYPE = 3;
|
||||
public static final int CPPFIELD = 4;
|
||||
public static final int CPPMETHOD = 5;
|
||||
public static final int CPPNAMESPACE = 6;
|
||||
public static final int CPPNAMESPACEALIAS = 7;
|
||||
public static final int CPPVARIABLE = PDOMLinkage.LAST_NODE_TYPE + 1;
|
||||
public static final int CPPFUNCTION = PDOMLinkage.LAST_NODE_TYPE + 2;
|
||||
public static final int CPPCLASSTYPE = PDOMLinkage.LAST_NODE_TYPE + 3;
|
||||
public static final int CPPFIELD = PDOMLinkage.LAST_NODE_TYPE + 4;
|
||||
public static final int CPPMETHOD = PDOMLinkage.LAST_NODE_TYPE + 5;
|
||||
public static final int CPPNAMESPACE = PDOMLinkage.LAST_NODE_TYPE + 6;
|
||||
public static final int CPPNAMESPACEALIAS = PDOMLinkage.LAST_NODE_TYPE + 7;
|
||||
public static final int CPPBASICTYPE = PDOMLinkage.LAST_NODE_TYPE + 8;
|
||||
public static final int CPPPARAMETER = PDOMLinkage.LAST_NODE_TYPE + 9;
|
||||
|
||||
public ILanguage getLanguage() {
|
||||
return new GPPLanguage();
|
||||
|
@ -147,8 +156,8 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
|
||||
return pdomBinding;
|
||||
}
|
||||
|
||||
private static final class FindBinding extends PDOMNode.NodeFinder {
|
||||
|
||||
private static final class FindBinding extends PDOMNamedNode.NodeFinder {
|
||||
PDOMBinding pdomBinding;
|
||||
final int desiredType;
|
||||
public FindBinding(PDOM pdom, char[] name, int desiredType) {
|
||||
|
@ -162,7 +171,7 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
if (!tBinding.hasName(name))
|
||||
// no more bindings with our desired name
|
||||
return false;
|
||||
if (tBinding.getBindingType() != desiredType)
|
||||
if (tBinding.getNodeType() != desiredType)
|
||||
// wrong type, try again
|
||||
return true;
|
||||
|
||||
|
@ -216,30 +225,6 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
return null;
|
||||
}
|
||||
|
||||
public PDOMBinding getBinding(int record) throws CoreException {
|
||||
if (record == 0)
|
||||
return null;
|
||||
|
||||
switch (PDOMBinding.getBindingType(pdom, record)) {
|
||||
case CPPVARIABLE:
|
||||
return new PDOMCPPVariable(pdom, record);
|
||||
case CPPFUNCTION:
|
||||
return new PDOMCPPFunction(pdom, record);
|
||||
case CPPCLASSTYPE:
|
||||
return new PDOMCPPClassType(pdom, record);
|
||||
case CPPFIELD:
|
||||
return new PDOMCPPField(pdom, record);
|
||||
case CPPMETHOD:
|
||||
return new PDOMCPPMethod(pdom, record);
|
||||
case CPPNAMESPACE:
|
||||
return new PDOMCPPNamespace(pdom, record);
|
||||
case CPPNAMESPACEALIAS:
|
||||
return new PDOMCPPNamespaceAlias(pdom, record);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public PDOMBinding resolveBinding(IASTName name) throws CoreException {
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName lastName = ((ICPPASTQualifiedName)name).getLastName();
|
||||
|
@ -281,4 +266,37 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
getIndex().accept(visitor);
|
||||
}
|
||||
|
||||
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
|
||||
if (type instanceof ICPPBasicType)
|
||||
return new PDOMCPPBasicType(pdom, parent, (ICPPBasicType)type);
|
||||
else
|
||||
return super.addType(parent, type);
|
||||
}
|
||||
|
||||
public PDOMNode getNode(int record) throws CoreException {
|
||||
if (record == 0)
|
||||
return null;
|
||||
|
||||
switch (PDOMNode.getNodeType(pdom, record)) {
|
||||
case CPPVARIABLE:
|
||||
return new PDOMCPPVariable(pdom, record);
|
||||
case CPPFUNCTION:
|
||||
return new PDOMCPPFunction(pdom, record);
|
||||
case CPPCLASSTYPE:
|
||||
return new PDOMCPPClassType(pdom, record);
|
||||
case CPPFIELD:
|
||||
return new PDOMCPPField(pdom, record);
|
||||
case CPPMETHOD:
|
||||
return new PDOMCPPMethod(pdom, record);
|
||||
case CPPNAMESPACE:
|
||||
return new PDOMCPPNamespace(pdom, record);
|
||||
case CPPNAMESPACEALIAS:
|
||||
return new PDOMCPPNamespaceAlias(pdom, record);
|
||||
case CPPBASICTYPE:
|
||||
return new PDOMCPPBasicType(pdom, record);
|
||||
}
|
||||
|
||||
return super.getNode(record);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class PDOMCPPMethod extends PDOMMember implements ICPPMethod, ICPPFunctio
|
|||
public static final int RECORD_SIZE = PDOMMember.RECORD_SIZE + 8;
|
||||
|
||||
public PDOMCPPMethod(PDOM pdom, PDOMMemberOwner parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCPPLinkage.CPPMETHOD);
|
||||
super(pdom, parent, name);
|
||||
IASTNode parentNode = name.getParent();
|
||||
if (parentNode instanceof ICPPASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator funcDecl = (ICPPASTFunctionDeclarator)parentNode;
|
||||
|
@ -69,6 +69,10 @@ public class PDOMCPPMethod extends PDOMMember implements ICPPMethod, ICPPFunctio
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPMETHOD;
|
||||
}
|
||||
|
||||
public PDOMCPPParameter getFirstParameter() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + FIRST_PARAM);
|
||||
return rec != 0 ? new PDOMCPPParameter(pdom, rec) : null;
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -44,7 +45,7 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
|
||||
|
||||
public PDOMCPPNamespace(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCPPLinkage.CPPNAMESPACE);
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMCPPNamespace(PDOM pdom, int record) {
|
||||
|
@ -55,6 +56,10 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPNAMESPACE;
|
||||
}
|
||||
|
||||
public BTree getIndex() throws CoreException {
|
||||
return new BTree(pdom.getDB(), record + INDEX_OFFSET);
|
||||
}
|
||||
|
@ -76,7 +81,7 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
});
|
||||
}
|
||||
|
||||
public void addChild(PDOMNode child) throws CoreException {
|
||||
public void addChild(PDOMNamedNode child) throws CoreException {
|
||||
getIndex().insert(child.getRecord(), child.getIndexComparator());
|
||||
}
|
||||
|
||||
|
@ -125,7 +130,7 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
private static final class FindBinding extends PDOMNode.NodeFinder {
|
||||
private static final class FindBinding extends PDOMNamedNode.NodeFinder {
|
||||
PDOMBinding pdomBinding;
|
||||
final int desiredType;
|
||||
public FindBinding(PDOM pdom, char[] name, int desiredType) {
|
||||
|
@ -139,7 +144,7 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
if (!tBinding.hasName(name))
|
||||
// no more bindings with our desired name
|
||||
return false;
|
||||
if (tBinding.getBindingType() != desiredType)
|
||||
if (tBinding.getNodeType() != desiredType)
|
||||
// wrong type, try again
|
||||
return true;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PDOMCPPNamespaceAlias extends PDOMBinding implements
|
|||
|
||||
public PDOMCPPNamespaceAlias(PDOM pdom, PDOMNode parent,
|
||||
IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCPPLinkage.CPPNAMESPACEALIAS);
|
||||
super(pdom, parent, name);
|
||||
}
|
||||
|
||||
public PDOMCPPNamespaceAlias(PDOM pdom, int record) {
|
||||
|
@ -42,6 +42,10 @@ public class PDOMCPPNamespaceAlias extends PDOMBinding implements
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPNAMESPACEALIAS;
|
||||
}
|
||||
|
||||
public ICPPNamespaceScope getNamespaceScope() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -28,11 +30,13 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
public class PDOMCPPParameter extends PDOMNode implements ICPPParameter {
|
||||
public class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter {
|
||||
|
||||
public static final int NEXT_PARAM = PDOMNode.RECORD_SIZE + 0;
|
||||
public static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
|
||||
private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0;
|
||||
private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4;
|
||||
|
||||
public static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 8;
|
||||
|
||||
public PDOMCPPParameter(PDOM pdom, int record) {
|
||||
super(pdom, record);
|
||||
}
|
||||
|
@ -40,13 +44,26 @@ public class PDOMCPPParameter extends PDOMNode implements ICPPParameter {
|
|||
public PDOMCPPParameter(PDOM pdom, PDOMNode parent, IASTName name, ICPPParameter param)
|
||||
throws CoreException {
|
||||
super(pdom, parent, name.toCharArray());
|
||||
// IType type = param.getType();
|
||||
|
||||
Database db = pdom.getDB();
|
||||
|
||||
db.putInt(record + NEXT_PARAM, 0);
|
||||
|
||||
IType type = param.getType();
|
||||
if (type != null) {
|
||||
PDOMNode typeNode = getLinkage().addType(this, type);
|
||||
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPPARAMETER;
|
||||
}
|
||||
|
||||
public void setNextParameter(PDOMCPPParameter nextParam) throws CoreException {
|
||||
int rec = nextParam != null ? nextParam.getRecord() : 0;
|
||||
pdom.getDB().putInt(record + NEXT_PARAM, rec);
|
||||
|
@ -79,8 +96,13 @@ public class PDOMCPPParameter extends PDOMNode implements ICPPParameter {
|
|||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
return null;
|
||||
// TODO throw new PDOMNotImplementedError();
|
||||
try {
|
||||
PDOMNode node = getLinkage().getNode(pdom.getDB().getInt(record + TYPE));
|
||||
return node instanceof IType ? (IType)node : null;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAuto() throws DOMException {
|
||||
|
|
|
@ -37,7 +37,7 @@ public class PDOMCPPVariable extends PDOMBinding implements ICPPVariable {
|
|||
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
|
||||
|
||||
public PDOMCPPVariable(PDOM pdom, PDOMNode parent, IASTName name) throws CoreException {
|
||||
super(pdom, parent, name, PDOMCPPLinkage.CPPVARIABLE);
|
||||
super(pdom, parent, name);
|
||||
|
||||
// Find the type record
|
||||
IASTNode nameParent = name.getParent();
|
||||
|
@ -60,6 +60,10 @@ public class PDOMCPPVariable extends PDOMBinding implements ICPPVariable {
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPPVARIABLE;
|
||||
}
|
||||
|
||||
public boolean isMutable() throws DOMException {
|
||||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
@ -67,7 +71,7 @@ public class PDOMCPPVariable extends PDOMBinding implements ICPPVariable {
|
|||
public IType getType() throws DOMException {
|
||||
try {
|
||||
int typeRec = pdom.getDB().getInt(record + TYPE_OFFSET);
|
||||
return typeRec != 0 ? (IType)getLinkage().getBinding(typeRec) : null;
|
||||
return (IType)getLinkage().getNode(typeRec);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return null;
|
||||
|
|
|
@ -37,7 +37,7 @@ public class CtagsBindingFinder implements IPDOMVisitor {
|
|||
public boolean visit(IPDOMNode node) throws CoreException {
|
||||
PDOMBinding binding = (PDOMBinding)node;
|
||||
if (name.equals(binding.getDBName())) {
|
||||
int type = binding.getBindingType();
|
||||
int type = binding.getNodeType();
|
||||
for (int i = 0; i < types.length; ++i) {
|
||||
if (type == types[i]) {
|
||||
bindings.add(binding);
|
||||
|
|
|
@ -19,8 +19,10 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOMCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -125,7 +127,16 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
|||
}
|
||||
|
||||
protected void changeTU(ITranslationUnit tu) throws CoreException, InterruptedException {
|
||||
IASTTranslationUnit ast = parse(tu);
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return;
|
||||
|
||||
PDOMCodeReaderFactory codeReaderFactory = new PDOMCodeReaderFactory(pdom);
|
||||
|
||||
// get the AST in a "Fast" way
|
||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu,
|
||||
codeReaderFactory,
|
||||
ILanguage.AST_USE_INDEX | ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||
if (ast == null)
|
||||
return;
|
||||
|
||||
|
@ -138,10 +149,12 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
|||
file.clear();
|
||||
|
||||
// Add the new symbols
|
||||
pdom.addSymbols(tu.getLanguage(), ast);
|
||||
addSymbols(tu.getLanguage(), ast, codeReaderFactory.getSkippedHeaders());
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
|
||||
pdom.fireChange();
|
||||
}
|
||||
|
||||
protected void removeTU(ITranslationUnit tu) throws CoreException, InterruptedException {
|
||||
|
|
|
@ -46,19 +46,6 @@ public abstract class PDOMFastIndexerJob extends Job {
|
|||
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse(ITranslationUnit tu) throws CoreException {
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return null;
|
||||
|
||||
PDOMCodeReaderFactory codeReaderFactory = new PDOMCodeReaderFactory(pdom);
|
||||
|
||||
// get the AST in a "Fast" way
|
||||
return language.getASTTranslationUnit(tu,
|
||||
codeReaderFactory,
|
||||
ILanguage.AST_USE_INDEX | ILanguage.AST_SKIP_IF_NO_BUILD_INFO);
|
||||
}
|
||||
|
||||
protected PDOMFile getCachedFile(String filename) throws CoreException {
|
||||
PDOMFile file = (PDOMFile)fileMap.get(filename);
|
||||
if (file == null) {
|
||||
|
@ -82,73 +69,74 @@ public abstract class PDOMFastIndexerJob extends Job {
|
|||
if (ast == null)
|
||||
return;
|
||||
|
||||
Set skippedHeaders = codeReaderFactory.getSkippedHeaders();
|
||||
|
||||
pdom.acquireWriteLock();
|
||||
try {
|
||||
final PDOMLinkage linkage = pdom.getLinkage(language);
|
||||
if (linkage == null)
|
||||
return;
|
||||
|
||||
// Add in the includes
|
||||
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
|
||||
for (int i = 0; i < includes.length; ++i) {
|
||||
IASTPreprocessorIncludeStatement include = includes[i];
|
||||
|
||||
IASTFileLocation sourceLoc = include.getFileLocation();
|
||||
String sourcePath
|
||||
= sourceLoc != null
|
||||
? sourceLoc.getFileName()
|
||||
: ast.getFilePath(); // command-line includes
|
||||
|
||||
PDOMFile sourceFile = getCachedFile(sourcePath);
|
||||
String destPath = include.getPath();
|
||||
PDOMFile destFile = getCachedFile(destPath);
|
||||
sourceFile.addIncludeTo(destFile);
|
||||
}
|
||||
|
||||
// Add in the macros
|
||||
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
|
||||
for (int i = 0; i < macros.length; ++i) {
|
||||
IASTPreprocessorMacroDefinition macro = macros[i];
|
||||
|
||||
IASTFileLocation sourceLoc = macro.getFileLocation();
|
||||
if (sourceLoc == null)
|
||||
continue; // skip built-ins and command line macros
|
||||
|
||||
String filename = sourceLoc.getFileName();
|
||||
if (skippedHeaders.contains(filename))
|
||||
continue;
|
||||
|
||||
PDOMFile sourceFile = getCachedFile(filename);
|
||||
sourceFile.addMacro(macro);
|
||||
}
|
||||
|
||||
// Add in the names
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
|
||||
public int visit(IASTName name) {
|
||||
try {
|
||||
IASTFileLocation nameLoc = name.getFileLocation();
|
||||
if (nameLoc != null)
|
||||
linkage.addName(name, getCachedFile(nameLoc.getFileName()));
|
||||
return PROCESS_CONTINUE;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
};
|
||||
});;
|
||||
|
||||
// Tell the world
|
||||
pdom.fireChange();
|
||||
addSymbols(language, ast, codeReaderFactory.getSkippedHeaders());
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
|
||||
// Tell the world
|
||||
pdom.fireChange();
|
||||
}
|
||||
|
||||
protected void addSymbols(ILanguage language, IASTTranslationUnit ast, Set skippedHeaders) throws InterruptedException, CoreException {
|
||||
final PDOMLinkage linkage = pdom.getLinkage(language);
|
||||
if (linkage == null)
|
||||
return;
|
||||
|
||||
// Add in the includes
|
||||
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
|
||||
for (int i = 0; i < includes.length; ++i) {
|
||||
IASTPreprocessorIncludeStatement include = includes[i];
|
||||
|
||||
IASTFileLocation sourceLoc = include.getFileLocation();
|
||||
String sourcePath
|
||||
= sourceLoc != null
|
||||
? sourceLoc.getFileName()
|
||||
: ast.getFilePath(); // command-line includes
|
||||
|
||||
PDOMFile sourceFile = getCachedFile(sourcePath);
|
||||
String destPath = include.getPath();
|
||||
PDOMFile destFile = getCachedFile(destPath);
|
||||
sourceFile.addIncludeTo(destFile);
|
||||
}
|
||||
|
||||
// Add in the macros
|
||||
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
|
||||
for (int i = 0; i < macros.length; ++i) {
|
||||
IASTPreprocessorMacroDefinition macro = macros[i];
|
||||
|
||||
IASTFileLocation sourceLoc = macro.getFileLocation();
|
||||
if (sourceLoc == null)
|
||||
continue; // skip built-ins and command line macros
|
||||
|
||||
String filename = sourceLoc.getFileName();
|
||||
if (skippedHeaders.contains(filename))
|
||||
continue;
|
||||
|
||||
PDOMFile sourceFile = getCachedFile(filename);
|
||||
sourceFile.addMacro(macro);
|
||||
}
|
||||
|
||||
// Add in the names
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
public int visit(IASTName name) {
|
||||
try {
|
||||
IASTFileLocation nameLoc = name.getFileLocation();
|
||||
if (nameLoc != null)
|
||||
linkage.addName(name, getCachedFile(nameLoc.getFileName()));
|
||||
return PROCESS_CONTINUE;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
};
|
||||
});;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
|
|||
}
|
||||
|
||||
// Add the new symbols
|
||||
pdom.addSymbols(tu.getLanguage(), ast);
|
||||
addSymbols(tu.getLanguage(), ast);
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
|
|
|
@ -12,10 +12,17 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
|
@ -49,10 +56,73 @@ public abstract class PDOMFullIndexerJob extends Job {
|
|||
|
||||
pdom.acquireWriteLock();
|
||||
try {
|
||||
pdom.addSymbols(tu.getLanguage(), ast);
|
||||
addSymbols(tu.getLanguage(), ast);
|
||||
} finally {
|
||||
pdom.releaseWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
public void addSymbols(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||
final PDOMLinkage linkage = pdom.getLinkage(language);
|
||||
if (linkage == null)
|
||||
return;
|
||||
|
||||
// Add in the includes
|
||||
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
|
||||
for (int i = 0; i < includes.length; ++i) {
|
||||
IASTPreprocessorIncludeStatement include = includes[i];
|
||||
|
||||
IASTFileLocation sourceLoc = include.getFileLocation();
|
||||
String sourcePath
|
||||
= sourceLoc != null
|
||||
? sourceLoc.getFileName()
|
||||
: ast.getFilePath(); // command-line includes
|
||||
|
||||
PDOMFile sourceFile = pdom.addFile(sourcePath);
|
||||
String destPath = include.getPath();
|
||||
PDOMFile destFile = pdom.addFile(destPath);
|
||||
sourceFile.addIncludeTo(destFile);
|
||||
}
|
||||
|
||||
// Add in the macros
|
||||
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
|
||||
for (int i = 0; i < macros.length; ++i) {
|
||||
IASTPreprocessorMacroDefinition macro = macros[i];
|
||||
|
||||
IASTFileLocation sourceLoc = macro.getFileLocation();
|
||||
if (sourceLoc == null)
|
||||
continue; // skip built-ins and command line macros
|
||||
|
||||
PDOMFile sourceFile = pdom.getFile(sourceLoc.getFileName());
|
||||
if (sourceFile != null) // not sure why this would be null
|
||||
sourceFile.addMacro(macro);
|
||||
}
|
||||
|
||||
// Add in the names
|
||||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
|
||||
public int visit(IASTName name) {
|
||||
try {
|
||||
IASTFileLocation fileloc = name.getFileLocation();
|
||||
if (fileloc != null) {
|
||||
PDOMFile file = pdom.addFile(fileloc.getFileName());
|
||||
linkage.addName(name, file);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
};
|
||||
});;
|
||||
|
||||
// Tell the world
|
||||
pdom.fireChange();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
@ -270,7 +271,7 @@ public class IndexView extends ViewPart implements PDOM.IListener {
|
|||
return "null :(";
|
||||
} else if (element instanceof PDOMNode) {
|
||||
try {
|
||||
return ((PDOMNode)element).getDBName().getString();
|
||||
return ((PDOMNamedNode)element).getDBName().getString();
|
||||
} catch (CoreException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue