1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-05 15:25:49 +02:00

Code formatting.

This commit is contained in:
Sergey Prigogin 2008-12-27 06:36:26 +00:00
parent 01d2201caa
commit 72e0dffa3d
3 changed files with 90 additions and 82 deletions

View file

@ -119,7 +119,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
} }
private class FindDefinitionAction extends CPPASTVisitor { private class FindDefinitionAction extends CPPASTVisitor {
private char [] nameArray = CPPClassType.this.getNameCharArray(); private char[] nameArray = CPPClassType.this.getNameCharArray();
public IASTName result = null; public IASTName result = null;
{ {
@ -130,10 +130,10 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
} }
@Override @Override
public int visit( IASTName name ){ public int visit(IASTName name) {
if( name instanceof ICPPASTTemplateId ) if (name instanceof ICPPASTTemplateId)
return PROCESS_SKIP; return PROCESS_SKIP;
if( name instanceof ICPPASTQualifiedName ) if (name instanceof ICPPASTQualifiedName)
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
char[] c = name.getLookupKey(); char[] c = name.getLookupKey();
@ -155,38 +155,40 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
} }
@Override @Override
public int visit( IASTDeclaration declaration ){ public int visit(IASTDeclaration declaration) {
if(declaration instanceof IASTSimpleDeclaration || declaration instanceof ICPPASTTemplateDeclaration) if (declaration instanceof IASTSimpleDeclaration || declaration instanceof ICPPASTTemplateDeclaration)
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@Override @Override
public int visit( IASTDeclSpecifier declSpec ){ public int visit(IASTDeclSpecifier declSpec) {
return (declSpec instanceof ICPPASTCompositeTypeSpecifier ) ? PROCESS_CONTINUE : PROCESS_SKIP; return (declSpec instanceof ICPPASTCompositeTypeSpecifier) ? PROCESS_CONTINUE : PROCESS_SKIP;
} }
@Override @Override
public int visit( IASTDeclarator declarator ) { return PROCESS_SKIP; } public int visit(IASTDeclarator declarator) {
return PROCESS_SKIP;
}
} }
private IASTName definition; private IASTName definition;
private IASTName [] declarations; private IASTName[] declarations;
private boolean checked = false; private boolean checked = false;
private ICPPClassType typeInIndex; private ICPPClassType typeInIndex;
public CPPClassType( IASTName name, IBinding indexBinding ){ public CPPClassType(IASTName name, IBinding indexBinding) {
if( name instanceof ICPPASTQualifiedName ){ if (name instanceof ICPPASTQualifiedName) {
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ]; name = ns[ns.length - 1];
} }
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
while( parent instanceof IASTName ) while(parent instanceof IASTName)
parent = parent.getParent(); parent = parent.getParent();
if( parent instanceof IASTCompositeTypeSpecifier ) if (parent instanceof IASTCompositeTypeSpecifier)
definition = name; definition = name;
else else
declarations = new IASTName[] { name }; declarations = new IASTName[] { name };
name.setBinding( this ); name.setBinding(this);
if (indexBinding instanceof ICPPClassType && indexBinding instanceof IIndexBinding) { if (indexBinding instanceof ICPPClassType && indexBinding instanceof IIndexBinding) {
typeInIndex= (ICPPClassType) indexBinding; typeInIndex= (ICPPClassType) indexBinding;
} }
@ -200,21 +202,21 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
return definition; return definition;
} }
public void checkForDefinition(){ public void checkForDefinition() {
if( !checked ) { if (!checked) {
FindDefinitionAction action = new FindDefinitionAction(); FindDefinitionAction action = new FindDefinitionAction();
IASTNode node = CPPVisitor.getContainingBlockItem( getPhysicalNode() ).getParent(); IASTNode node = CPPVisitor.getContainingBlockItem(getPhysicalNode()).getParent();
if( node instanceof ICPPASTCompositeTypeSpecifier ) if (node instanceof ICPPASTCompositeTypeSpecifier)
node = CPPVisitor.getContainingBlockItem( node.getParent() ); node = CPPVisitor.getContainingBlockItem(node.getParent());
while( node instanceof ICPPASTTemplateDeclaration ) while(node instanceof ICPPASTTemplateDeclaration)
node = node.getParent(); node = node.getParent();
node.accept( action ); node.accept(action);
definition = action.result; definition = action.result;
if( definition == null ){ if (definition == null) {
final IASTTranslationUnit translationUnit = node.getTranslationUnit(); final IASTTranslationUnit translationUnit = node.getTranslationUnit();
translationUnit.accept( action ); translationUnit.accept(action);
definition = action.result; definition = action.result;
if (definition == null && typeInIndex == null) { if (definition == null && typeInIndex == null) {
IIndex index= translationUnit.getIndex(); IIndex index= translationUnit.getIndex();
@ -228,23 +230,23 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
return; return;
} }
public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){ public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() {
if( definition != null ){ if (definition != null) {
IASTNode node = definition; IASTNode node = definition;
while( node instanceof IASTName ) while(node instanceof IASTName)
node = node.getParent(); node = node.getParent();
if( node instanceof ICPPASTCompositeTypeSpecifier ) if (node instanceof ICPPASTCompositeTypeSpecifier)
return (ICPPASTCompositeTypeSpecifier)node; return (ICPPASTCompositeTypeSpecifier)node;
} }
return null; return null;
} }
private ICPPASTElaboratedTypeSpecifier getElaboratedTypeSpecifier() { private ICPPASTElaboratedTypeSpecifier getElaboratedTypeSpecifier() {
if( declarations != null ){ if (declarations != null) {
IASTNode node = declarations[0]; IASTNode node = declarations[0];
while( node instanceof IASTName ) while(node instanceof IASTName)
node = node.getParent(); node = node.getParent();
if( node instanceof ICPPASTElaboratedTypeSpecifier ) if (node instanceof ICPPASTElaboratedTypeSpecifier)
return (ICPPASTElaboratedTypeSpecifier)node; return (ICPPASTElaboratedTypeSpecifier)node;
} }
return null; return null;
@ -255,20 +257,20 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
} }
public char[] getNameCharArray() { public char[] getNameCharArray() {
return ( definition != null ) ? definition.getSimpleID() : declarations[0].getSimpleID(); return (definition != null) ? definition.getSimpleID() : declarations[0].getSimpleID();
} }
public IScope getScope() { public IScope getScope() {
IASTName name = definition != null ? definition : declarations[0]; IASTName name = definition != null ? definition : declarations[0];
IScope scope = CPPVisitor.getContainingScope( name ); IScope scope = CPPVisitor.getContainingScope(name);
if( definition == null && name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME ){ if (definition == null && name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) {
IASTNode node = declarations[0].getParent().getParent(); IASTNode node = declarations[0].getParent().getParent();
if( node instanceof IASTFunctionDefinition || node instanceof IASTParameterDeclaration || if (node instanceof IASTFunctionDefinition || node instanceof IASTParameterDeclaration ||
( node instanceof IASTSimpleDeclaration && (node instanceof IASTSimpleDeclaration &&
( ((IASTSimpleDeclaration) node).getDeclarators().length > 0 || getElaboratedTypeSpecifier().isFriend() ) ) ) (((IASTSimpleDeclaration) node).getDeclarators().length > 0 || getElaboratedTypeSpecifier().isFriend())))
{ {
while( scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope ){ while(scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) {
try { try {
scope = scope.getParent(); scope = scope.getParent();
} catch (DOMException e1) { } catch (DOMException e1) {
@ -298,42 +300,42 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
} }
public IASTNode getPhysicalNode() { public IASTNode getPhysicalNode() {
return (definition != null ) ? (IASTNode) definition : declarations[0]; return (definition != null) ? (IASTNode) definition : declarations[0];
} }
public int getKey() { public int getKey() {
if( definition != null ) if (definition != null)
return getCompositeTypeSpecifier().getKey(); return getCompositeTypeSpecifier().getKey();
return getElaboratedTypeSpecifier().getKind(); return getElaboratedTypeSpecifier().getKind();
} }
public void addDefinition( IASTNode node ){ public void addDefinition(IASTNode node) {
if( node instanceof ICPPASTCompositeTypeSpecifier ) if (node instanceof ICPPASTCompositeTypeSpecifier)
definition = ((ICPPASTCompositeTypeSpecifier)node).getName(); definition = ((ICPPASTCompositeTypeSpecifier)node).getName();
} }
public void addDeclaration( IASTNode node ) { public void addDeclaration(IASTNode node) {
if( !(node instanceof ICPPASTElaboratedTypeSpecifier) ) if (!(node instanceof ICPPASTElaboratedTypeSpecifier))
return; return;
IASTName name = ((ICPPASTElaboratedTypeSpecifier) node).getName(); IASTName name = ((ICPPASTElaboratedTypeSpecifier) node).getName();
if( declarations == null ){ if (declarations == null) {
declarations = new IASTName[] { name }; declarations = new IASTName[] { name };
return; return;
} }
//keep the lowest offset declaration in [0] //keep the lowest offset declaration in [0]
if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ if (declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode) declarations[0]).getOffset()) {
declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, name ); declarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, declarations, name);
} else { } else {
declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); declarations = (IASTName[]) ArrayUtil.append(IASTName.class, declarations, name);
} }
} }
public void removeDeclaration(IASTNode node) { public void removeDeclaration(IASTNode node) {
if( definition == node ){ if (definition == node) {
definition = null; definition = null;
return; return;
} }
@ -341,17 +343,17 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
} }
public String[] getQualifiedName() { public String[] getQualifiedName() {
return CPPVisitor.getQualifiedName( this ); return CPPVisitor.getQualifiedName(this);
} }
public char[][] getQualifiedNameCharArray() { public char[][] getQualifiedNameCharArray() {
return CPPVisitor.getQualifiedNameCharArray( this ); return CPPVisitor.getQualifiedNameCharArray(this);
} }
public boolean isGloballyQualified() throws DOMException { public boolean isGloballyQualified() throws DOMException {
IScope scope = getScope(); IScope scope = getScope();
while( scope != null ){ while(scope != null) {
if( scope instanceof ICPPBlockScope ) if (scope instanceof ICPPBlockScope)
return false; return false;
scope = scope.getParent(); scope = scope.getParent();
} }
@ -362,9 +364,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
return Linkage.CPP_LINKAGE; return Linkage.CPP_LINKAGE;
} }
/* */ public boolean isSameType(IType type) {
public boolean isSameType( IType type ) {
if (type == this) if (type == this)
return true; return true;
if (type instanceof ITypedef || type instanceof IIndexType) if (type instanceof ITypedef || type instanceof IIndexType)
@ -372,7 +372,7 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
return false; return false;
} }
public ICPPBase [] getBases() { public ICPPBase[] getBases() {
return ClassTypeHelper.getBases(this); return ClassTypeHelper.getBases(this);
} }

View file

@ -27,7 +27,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
/** /**
* Look up bindings in BTree objects and IPDOMNode objects. This additionally * Look up bindings in BTree objects and IPDOMNode objects. This additionally
* takes into account function/method parameters as well as template * takes into account function/method parameters as well as template
* specialization arguments for overloading, . * specialization arguments for overloading.
*/ */
public class CPPFindBinding extends FindBinding { public class CPPFindBinding extends FindBinding {
@ -38,12 +38,12 @@ public class CPPFindBinding extends FindBinding {
@Override @Override
public int compare(int record1, int record2) throws CoreException { public int compare(int record1, int record2) throws CoreException {
int cmp = super.compare(record1, record2); int cmp = super.compare(record1, record2);
if(cmp==0) { if (cmp == 0) {
PDOMBinding binding1 = pdom.getBinding(record1); PDOMBinding binding1 = pdom.getBinding(record1);
PDOMBinding binding2 = pdom.getBinding(record2); PDOMBinding binding2 = pdom.getBinding(record2);
if(binding1 instanceof IPDOMOverloader && binding2 instanceof IPDOMOverloader) { if (binding1 instanceof IPDOMOverloader && binding2 instanceof IPDOMOverloader) {
int ty1 = ((IPDOMOverloader)binding1).getSignatureHash(); int ty1 = ((IPDOMOverloader) binding1).getSignatureHash();
int ty2 = ((IPDOMOverloader)binding2).getSignatureHash(); int ty2 = ((IPDOMOverloader) binding2).getSignatureHash();
cmp = ty1 < ty2 ? -1 : (ty1 > ty2 ? 1 : 0); cmp = ty1 < ty2 ? -1 : (ty1 > ty2 ? 1 : 0);
} }
} }
@ -88,7 +88,7 @@ public class CPPFindBinding extends FindBinding {
protected boolean matches(PDOMBinding binding) throws CoreException { protected boolean matches(PDOMBinding binding) throws CoreException {
if (super.matches(binding)) { if (super.matches(binding)) {
if (binding instanceof IPDOMOverloader) { if (binding instanceof IPDOMOverloader) {
int ty1 = ((IPDOMOverloader)binding).getSignatureHash(); int ty1 = ((IPDOMOverloader) binding).getSignatureHash();
return fSigHash == ty1; return fSigHash == ty1;
} }
} }
@ -96,45 +96,51 @@ public class CPPFindBinding extends FindBinding {
} }
} }
public static PDOMBinding findBinding(BTree btree, final PDOM pdom, final char[]name, final int c2, final int ty2, int localToFileRec) throws CoreException { public static PDOMBinding findBinding(BTree btree, final PDOM pdom, final char[] name,
final int c2, final int ty2, int localToFileRec) throws CoreException {
CPPFindBindingVisitor visitor= new CPPFindBindingVisitor(pdom, name, c2, ty2, localToFileRec); CPPFindBindingVisitor visitor= new CPPFindBindingVisitor(pdom, name, c2, ty2, localToFileRec);
btree.accept(visitor); btree.accept(visitor);
return visitor.getResult(); return visitor.getResult();
} }
public static PDOMBinding findBinding(PDOMNode node, PDOM pdom, char[] name, int constant,
public static PDOMBinding findBinding(PDOMNode node, PDOM pdom, char[]name, int constant, int sigHash, int localToFileRec) int sigHash, int localToFileRec) throws CoreException {
throws CoreException { CPPFindBindingVisitor visitor= new CPPFindBindingVisitor(pdom, name, constant, sigHash,
CPPFindBindingVisitor visitor= new CPPFindBindingVisitor(pdom, name, constant, sigHash, localToFileRec); localToFileRec);
try { try {
node.accept(visitor); node.accept(visitor);
} catch(OperationCanceledException ce) { } catch (OperationCanceledException e) {
} }
return visitor.getResult(); return visitor.getResult();
} }
public static PDOMBinding findBinding(BTree btree, PDOMLinkage linkage, IBinding binding,
public static PDOMBinding findBinding(BTree btree, PDOMLinkage linkage, IBinding binding, int localToFileRec) throws CoreException { int localToFileRec) throws CoreException {
Integer hash= 0; Integer hash= 0;
try { try {
hash = IndexCPPSignatureUtil.getSignatureHash(binding); hash = IndexCPPSignatureUtil.getSignatureHash(binding);
} catch (DOMException e) { } catch (DOMException e) {
} }
if(hash != null) { if (hash != null) {
return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), hash.intValue(), localToFileRec); return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(),
linkage.getBindingType(binding), hash.intValue(), localToFileRec);
} }
return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(), new int [] {linkage.getBindingType(binding)}, localToFileRec); return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(),
new int[] {linkage.getBindingType(binding)}, localToFileRec);
} }
public static PDOMBinding findBinding(PDOMNode node, PDOMLinkage linkage, IBinding binding, int localToFileRec) throws CoreException { public static PDOMBinding findBinding(PDOMNode node, PDOMLinkage linkage, IBinding binding,
int localToFileRec) throws CoreException {
Integer hash = null; Integer hash = null;
try { try {
hash = IndexCPPSignatureUtil.getSignatureHash(binding); hash = IndexCPPSignatureUtil.getSignatureHash(binding);
} catch (DOMException e) { } catch (DOMException e) {
} }
if(hash != null) { if (hash != null) {
return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), hash.intValue(), localToFileRec); return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(),
linkage.getBindingType(binding), hash.intValue(), localToFileRec);
} }
return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), new int[] {linkage.getBindingType(binding)}, localToFileRec); return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(),
new int[] {linkage.getBindingType(binding)}, localToFileRec);
} }
} }

View file

@ -121,7 +121,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements IPDOMCPPClassType, IPDO
@Override @Override
public void addChild(PDOMNode member) throws CoreException { public void addChild(PDOMNode member) throws CoreException {
pdom.removeCachedResult(record+PDOMCPPLinkage.CACHE_MEMBERS); pdom.removeCachedResult(record + PDOMCPPLinkage.CACHE_MEMBERS);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
list.addMember(member); list.addMember(member);
} }
@ -346,7 +346,9 @@ class PDOMCPPClassType extends PDOMCPPBinding implements IPDOMCPPClassType, IPDO
try { try {
final List<IBinding> list = new ArrayList<IBinding>(); final List<IBinding> list = new ArrayList<IBinding>();
for (PDOMCPPFriend friend = getFirstFriend(); for (PDOMCPPFriend friend = getFirstFriend();
friend != null; friend = friend.getNextFriend()) list.add(0,friend.getFriendSpecifier()); friend != null; friend = friend.getNextFriend()) {
list.add(0, friend.getFriendSpecifier());
}
return list.toArray(new IBinding[list.size()]); return list.toArray(new IBinding[list.size()]);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);