From d2e2b4f4b171abbdb164530b7340a6b4bd968d19 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Mon, 2 May 2005 20:15:51 +0000 Subject: [PATCH] Fixed Bug 93123 - No way to determine if an IASTName is a definition --- .../eclipse/cdt/core/dom/ast/IASTName.java | 9 +- .../cdt/core/dom/ast/IASTNameOwner.java | 7 +- .../parser/c/CASTCompositeTypeSpecifier.java | 2 +- .../core/dom/parser/c/CASTDeclarator.java | 31 +++- .../parser/c/CASTEnumerationSpecifier.java | 2 +- .../core/dom/parser/c/CASTEnumerator.java | 2 +- .../internal/core/dom/parser/c/CASTName.java | 148 ++++++++++------- .../cpp/CPPASTCompositeTypeSpecifier.java | 2 +- .../core/dom/parser/cpp/CPPASTDeclarator.java | 50 +++++- .../cpp/CPPASTEnumerationSpecifier.java | 2 +- .../core/dom/parser/cpp/CPPASTEnumerator.java | 2 +- .../core/dom/parser/cpp/CPPASTName.java | 154 +++++++++++------- .../parser/cpp/CPPASTNamespaceDefinition.java | 2 +- .../dom/parser/cpp/CPPASTPointerToMember.java | 2 +- .../dom/parser/cpp/CPPASTQualifiedName.java | 11 ++ .../core/dom/parser/cpp/CPPASTTemplateId.java | 12 ++ .../core/parser/scanner2/LocationMap.java | 8 +- 17 files changed, 314 insertions(+), 132 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTName.java index 5d89151ac20..18c8c2bd779 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTName.java @@ -69,7 +69,14 @@ public interface IASTName extends IASTNode { /** * Is this name being used in the AST as a reference rather than a declaration? - * @return + * @return boolean */ + public boolean isReference(); + + /** + * Is this name being used in the AST as a reference rather than a declaration? + * @return boolean + */ + public boolean isDefinition(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNameOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNameOwner.java index b6f9de1c996..f4ba660ed33 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNameOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNameOwner.java @@ -16,10 +16,15 @@ public interface IASTNameOwner { * Role of name in this construct is a reference. */ public static final int r_reference = 1; + + /** + * Role of name in this construct is a definition. + */ + public static final int r_definition = 2; /** * Role is unclear. */ - public static final int r_unclear = 2; + public static final int r_unclear = 3; /** * Get the role for the name. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java index e268151de4e..9207131427c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java @@ -113,7 +113,7 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements */ public int getRoleForName(IASTName n) { if( n == this.name ) - return r_declaration; + return r_definition; return r_unclear; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java index 822769c8367..c787d5c05a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java @@ -10,12 +10,15 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -125,7 +128,19 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator { { IASTNode getParent = getParent(); if( getParent instanceof IASTDeclaration ) - return r_declaration; + { + if( getParent instanceof IASTFunctionDefinition ) + return r_definition; + if( getParent instanceof IASTSimpleDeclaration ) + { + IASTSimpleDeclaration sd = (IASTSimpleDeclaration) getParent; + if( sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_extern ) + return r_declaration; + if( getInitializer() == null ) + return r_declaration; + } + return r_definition; + } if( getParent instanceof IASTTypeId ) return r_reference; if( getParent instanceof IASTDeclarator ) @@ -134,7 +149,19 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator { while ( t instanceof IASTDeclarator ) t = t.getParent(); if( t instanceof IASTDeclaration ) - return r_declaration; + { + if( getParent instanceof IASTFunctionDefinition ) + return r_definition; + if( getParent instanceof IASTSimpleDeclaration ) + { + IASTSimpleDeclaration sd = (IASTSimpleDeclaration) getParent; + if( sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_extern ) + return r_declaration; + if( getInitializer() != null ) + return r_definition; + } + return r_definition; + } if( t instanceof IASTTypeId ) return r_reference; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java index a66f9004877..0dba239a165 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java @@ -81,7 +81,7 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements */ public int getRoleForName(IASTName n ) { if( this.name == n ) - return r_declaration; + return r_definition; return r_unclear; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java index 65c57864240..c06771f12b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java @@ -69,7 +69,7 @@ public class CASTEnumerator extends CASTNode implements IASTEnumerator, IASTAmbi * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName) */ public int getRoleForName(IASTName n) { - if( n == name )return r_declaration; + if( n == name )return r_definition; return r_unclear; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java index 3cde1e00e91..ea61df4cb19 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTName.java @@ -21,13 +21,15 @@ import org.eclipse.cdt.core.dom.ast.IBinding; public class CASTName extends CASTNode implements IASTName { private final char[] name; - private static final char[] EMPTY_CHAR_ARRAY = { }; + + private static final char[] EMPTY_CHAR_ARRAY = {}; + private IBinding binding = null; /** - * @param name + * @param name */ - public CASTName(char [] name ) { + public CASTName(char[] name) { this.name = name; } @@ -38,74 +40,110 @@ public class CASTName extends CASTNode implements IASTName { name = EMPTY_CHAR_ARRAY; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() */ public IBinding resolveBinding() { - if( binding == null ) - CVisitor.createBinding( this ); - + if (binding == null) + CVisitor.createBinding(this); + return binding; } - public IBinding getBinding(){ - return binding; - } - - public IBinding[] resolvePrefix() { - return CVisitor.prefixLookup(this); - } - - public void setBinding( IBinding binding ){ - this.binding = binding; + + public IBinding getBinding() { + return binding; } - /* (non-Javadoc) + public IBinding[] resolvePrefix() { + return CVisitor.prefixLookup(this); + } + + public void setBinding(IBinding binding) { + this.binding = binding; + } + + /* + * (non-Javadoc) + * * @see java.lang.Object#toString() */ public String toString() { - if( name == EMPTY_CHAR_ARRAY ) return null; - return new String( name ); + if (name == EMPTY_CHAR_ARRAY) + return null; + return new String(name); } - + public char[] toCharArray() { - return name; + return name; } - - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitNames ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } - } + + public boolean accept(ASTVisitor action) { + if (action.shouldVisitNames) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } return true; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTName#isDeclaration() - */ - public boolean isDeclaration() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - if( role == IASTNameOwner.r_reference ) return false; - return true; - } - return false; - } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTName#isDeclaration() + */ + public boolean isDeclaration() { + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_reference: + case IASTNameOwner.r_unclear: + return false; + default: + return true; + } + } + return false; + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTName#isReference() - */ - public boolean isReference() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - if( role == IASTNameOwner.r_reference ) return true; - return false; - } - return false; - } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTName#isReference() + */ + public boolean isReference() { + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_reference: + return true; + default: + return false; + } + } + return false; + } + + public boolean isDefinition() { + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_definition: + return true; + default: + return false; + } + } + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index 616d3da56b8..85ba6365f69 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -136,7 +136,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier */ public int getRoleForName(IASTName name) { if( name == this.n ) - return r_declaration; + return r_definition; return r_unclear; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java index 135540aa572..e4a17140632 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java @@ -11,10 +11,15 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -121,10 +126,45 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator { * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName) */ public int getRoleForName(IASTName n) { - if( name == n ) - { - - } - return r_unclear; + IASTNode getParent = getParent(); + if( getParent instanceof IASTDeclaration ) + { + if( getParent instanceof IASTFunctionDefinition ) + return r_definition; + if( getParent instanceof IASTSimpleDeclaration ) + { + IASTSimpleDeclaration sd = (IASTSimpleDeclaration) getParent; + if( sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_extern ) + return r_declaration; + if( getInitializer() == null ) + return r_declaration; + } + return r_definition; + } + if( getParent instanceof IASTTypeId ) + return r_reference; + if( getParent instanceof IASTDeclarator ) + { + IASTNode t = getParent; + while ( t instanceof IASTDeclarator ) + t = t.getParent(); + if( t instanceof IASTDeclaration ) + { + if( getParent instanceof IASTFunctionDefinition ) + return r_definition; + if( getParent instanceof IASTSimpleDeclaration ) + { + IASTSimpleDeclaration sd = (IASTSimpleDeclaration) getParent; + if( sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_extern ) + return r_declaration; + if( getInitializer() != null ) + return r_definition; + } + return r_definition; + } + if( t instanceof IASTTypeId ) + return r_reference; + } + return r_unclear; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java index 9c3b36e6888..3f3bffe6276 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java @@ -103,7 +103,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier */ public int getRoleForName(IASTName n) { if (name == n) - return r_declaration; + return r_definition; return r_unclear; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java index 4d8404be39b..6f64e054595 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java @@ -70,7 +70,7 @@ public class CPPASTEnumerator extends CPPASTNode implements IASTEnumerator, IAST */ public int getRoleForName(IASTName n) { if( name == n ) - return r_declaration; + return r_definition; return r_reference; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java index 9a0546dd601..d4ee328c804 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java @@ -22,13 +22,15 @@ import org.eclipse.cdt.core.dom.ast.IBinding; public class CPPASTName extends CPPASTNode implements IASTName { private char[] name; - private static final char[] EMPTY_CHAR_ARRAY = { }; + + private static final char[] EMPTY_CHAR_ARRAY = {}; + private IBinding binding = null; /** - * @param name + * @param name */ - public CPPASTName(char [] name ) { + public CPPASTName(char[] name) { this.name = name; } @@ -39,78 +41,114 @@ public class CPPASTName extends CPPASTNode implements IASTName { name = EMPTY_CHAR_ARRAY; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() */ public IBinding resolveBinding() { - if( binding == null ) - binding = CPPVisitor.createBinding( this ); - + if (binding == null) + binding = CPPVisitor.createBinding(this); + return binding; } - - public IBinding[] resolvePrefix() { - return CPPSemantics.prefixLookup(this); - } - - public void setBinding( IBinding binding ){ - this.binding = binding; - } - public IBinding getBinding(){ - return binding; + + public IBinding[] resolvePrefix() { + return CPPSemantics.prefixLookup(this); } - /* (non-Javadoc) + public void setBinding(IBinding binding) { + this.binding = binding; + } + + public IBinding getBinding() { + return binding; + } + + /* + * (non-Javadoc) + * * @see java.lang.Object#toString() */ public String toString() { - if( name == EMPTY_CHAR_ARRAY ) return null; - return new String( name ); + if (name == EMPTY_CHAR_ARRAY) + return null; + return new String(name); } - + public char[] toCharArray() { - return name; + return name; } - - public void setName( char [] name ) - { + + public void setName(char[] name) { this.name = name; } - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitNames ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; - } - } + public boolean accept(ASTVisitor action) { + if (action.shouldVisitNames) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + default: + break; + } + } return true; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTName#isDeclaration() - */ - public boolean isDeclaration() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - if( role == IASTNameOwner.r_reference ) return false; - return true; - } - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTName#isReference() - */ - public boolean isReference() { - IASTNode parent = getParent(); - if (parent instanceof IASTNameOwner) { - int role = ((IASTNameOwner) parent).getRoleForName(this); - if( role == IASTNameOwner.r_reference ) return true; - return false; - } - return false; - } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTName#isDeclaration() + */ + public boolean isDeclaration() { + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_reference: + case IASTNameOwner.r_unclear: + return false; + default: + return true; + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTName#isReference() + */ + public boolean isReference() { + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_reference: + return true; + default: + return false; + } + } + return false; + } + + public boolean isDefinition() { + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + switch (role) { + case IASTNameOwner.r_definition: + return true; + default: + return false; + } + } + return false; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java index dd0345fd51c..3fd07f11f86 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java @@ -91,7 +91,7 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName) */ public int getRoleForName(IASTName n) { - if( name == n ) return r_declaration; + if( name == n ) return r_definition; return r_unclear; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java index 2f9b48b2ba9..98ef852f0a2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointerToMember.java @@ -46,7 +46,7 @@ public class CPPASTPointerToMember extends CPPASTPointer implements */ public int getRoleForName(IASTName name ) { if( name == this.n ) - return r_declaration; + return r_reference; return r_unclear; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index 6bb89cb0043..0261808c8b7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -254,5 +254,16 @@ public class CPPASTQualifiedName extends CPPASTNode implements return false; } + + public boolean isDefinition() { + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + if( role == IASTNameOwner.r_definition ) return true; + return false; + } + return false; + } + } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java index d65c68de843..4e09acd735b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -154,4 +155,15 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I } } } + + public boolean isDefinition() { + IASTNode parent = getParent(); + if (parent instanceof IASTNameOwner) { + int role = ((IASTNameOwner) parent).getRoleForName(this); + if( role == IASTNameOwner.r_definition ) return true; + return false; + } + return false; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index 6347b166003..9f2dfa9bb0e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -575,7 +575,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { */ public int getRoleForName(IASTName n) { if (name == n) - return r_declaration; + return r_definition; return r_unclear; } @@ -740,6 +740,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { return true; return false; } + + public boolean isDefinition() { + return isDeclaration(); + } /* * (non-Javadoc) @@ -784,7 +788,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { */ public int getRoleForName(IASTName n) { if (name == n) - return r_declaration; + return r_definition; return r_unclear; }