mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Patch for Devin Steffler.
Fixed 78231 - [Parser] open declaration on elaborated type shouldn't jump to object hiding it
This commit is contained in:
parent
d5a0e947ff
commit
5946594715
10 changed files with 204 additions and 10 deletions
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNamespaceDefinition;
|
||||
|
@ -705,5 +706,37 @@ public class SelectionParseTest extends SelectionParseBaseTest {
|
|||
assertEquals( n.getStartingLine(), 2 );
|
||||
}
|
||||
|
||||
public void testBug78231A() throws Exception {
|
||||
Writer writer = new StringWriter();
|
||||
writer.write("struct Base {\n"); //$NON-NLS-1$
|
||||
writer.write("int Data; // 1\n"); //$NON-NLS-1$
|
||||
writer.write("struct Data; // 2\n};\n"); //$NON-NLS-1$
|
||||
|
||||
String code = writer.toString();
|
||||
int index = code.indexOf("struct Data;") + 7; //$NON-NLS-1$
|
||||
IASTNode node = parse( code, index, index + 4 );
|
||||
assertTrue(node instanceof IASTOffsetableNamedElement);
|
||||
IASTOffsetableNamedElement n = (IASTOffsetableNamedElement)node;
|
||||
assertEquals(n.getName(), "Data"); //$NON-NLS-1$
|
||||
assertEquals(n.getNameOffset(), 36);
|
||||
assertEquals(n.getStartingLine(), 3);
|
||||
}
|
||||
|
||||
public void testBug78231B() throws Exception {
|
||||
Writer writer = new StringWriter();
|
||||
writer.write("int Data;\n"); //$NON-NLS-1$
|
||||
writer.write("struct Base {\n"); //$NON-NLS-1$
|
||||
writer.write("int Data; // 1\n"); //$NON-NLS-1$
|
||||
writer.write("struct Data; // 2\n};\n"); //$NON-NLS-1$
|
||||
|
||||
String code = writer.toString();
|
||||
int index = code.indexOf("struct Data;") + 7; //$NON-NLS-1$
|
||||
IASTNode node = parse( code, index, index + 4 );
|
||||
assertTrue(node instanceof IASTOffsetableNamedElement);
|
||||
IASTOffsetableNamedElement n = (IASTOffsetableNamedElement)node;
|
||||
assertEquals(n.getName(), "Data"); //$NON-NLS-1$
|
||||
assertEquals(n.getNameOffset(), 46);
|
||||
assertEquals(n.getStartingLine(), 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ package org.eclipse.cdt.core.parser.ast;
|
|||
*
|
||||
*/
|
||||
public interface IASTAbstractTypeSpecifierDeclaration
|
||||
extends IASTDeclaration, IASTTypeSpecifierOwner, IASTTemplatedDeclaration, IASTOffsetableElement
|
||||
extends IASTDeclaration, IASTTypeSpecifierOwner, IASTTemplatedDeclaration, IASTOffsetableNamedElement
|
||||
{
|
||||
public boolean isFriendDeclaration();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
|
|||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTemplate;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
||||
|
@ -152,4 +153,66 @@ public class ASTAbstractTypeSpecifierDeclaration
|
|||
public char[] getFilename() {
|
||||
return fn;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
if (typeSpec instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpec).getName();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
if (typeSpec instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpec).getNameCharArray();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset()
|
||||
*/
|
||||
public int getNameOffset() {
|
||||
if (typeSpec instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpec).getNameOffset();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int)
|
||||
*/
|
||||
public void setNameOffset(int o) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset()
|
||||
*/
|
||||
public int getNameEndOffset() {
|
||||
if (typeSpec instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpec).getNameEndOffset();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffsetAndLineNumber(int, int)
|
||||
*/
|
||||
public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber()
|
||||
*/
|
||||
public int getNameLineNumber() {
|
||||
if (typeSpec instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpec).getNameLineNumber();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -749,7 +749,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
if( !CharArrayUtils.equals(newSymbolName, EMPTY_STRING) && !isTemplateId ){
|
||||
try
|
||||
{
|
||||
classSymbol = currentScopeSymbol.lookupMemberForDefinition(newSymbolName);
|
||||
classSymbol = currentScopeSymbol.lookupMemberForDefinition(newSymbolName, pstType);
|
||||
}
|
||||
catch (ParserSymbolTableException e)
|
||||
{
|
||||
|
@ -791,7 +791,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
}
|
||||
catch (ParserSymbolTableException e2)
|
||||
{
|
||||
handleProblem( e2.createProblemID(), newSymbolName );
|
||||
if (e2.reason == ParserSymbolTableException.r_InvalidOverload)
|
||||
handleProblem( e2.createProblemID(), newSymbolName, nameOffset, nameEndOffset, nameLine, false ); // to fix 65569 for this patch
|
||||
else
|
||||
handleProblem( e2.createProblemID(), newSymbolName, nameOffset, nameEndOffset, nameLine, true );
|
||||
}
|
||||
|
||||
if( name != null && name.getTemplateIdArgLists() != null )
|
||||
|
@ -3287,8 +3290,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
checkSymbol = ((IDerivableContainerSymbol) currentScopeSymbol)
|
||||
.lookupForFriendship(newSymbolName);
|
||||
} else {
|
||||
checkSymbol = currentScopeSymbol.elaboratedLookup(pstType,
|
||||
newSymbolName);
|
||||
if (!isForewardDecl)
|
||||
checkSymbol = currentScopeSymbol.elaboratedLookup(pstType, newSymbolName); // for using - goes outside scope with filter
|
||||
else
|
||||
checkSymbol = currentScopeSymbol.lookupMemberForDefinition(newSymbolName, pstType); // for declaring - stays inside scope with filter
|
||||
}
|
||||
} catch (ParserSymbolTableException e) {
|
||||
handleProblem(e.createProblemID(), nameToken.getCharImage(),
|
||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick;
|
|||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTemplate;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
|
||||
|
@ -150,5 +151,67 @@ public class ASTAbstractTypeSpecifierDeclaration
|
|||
{
|
||||
return endingOffset;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
if (typeSpecifier instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpecifier).getName();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
if (typeSpecifier instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpecifier).getNameCharArray();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset()
|
||||
*/
|
||||
public int getNameOffset() {
|
||||
if (typeSpecifier instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpecifier).getNameOffset();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int)
|
||||
*/
|
||||
public void setNameOffset(int o) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset()
|
||||
*/
|
||||
public int getNameEndOffset() {
|
||||
if (typeSpecifier instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpecifier).getNameEndOffset();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffsetAndLineNumber(int, int)
|
||||
*/
|
||||
public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber()
|
||||
*/
|
||||
public int getNameLineNumber() {
|
||||
if (typeSpecifier instanceof IASTOffsetableNamedElement)
|
||||
return ((IASTOffsetableNamedElement)typeSpecifier).getNameLineNumber();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -518,8 +518,17 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
|||
* ie, We need a seperate lookup function for looking up the member names
|
||||
* for a definition.
|
||||
*/
|
||||
public ISymbol lookupMemberForDefinition( char[] name ) throws ParserSymbolTableException{
|
||||
LookupData data = new LookupData( name );
|
||||
public ISymbol lookupMemberForDefinition( char[] name, final ITypeInfo.eType type ) throws ParserSymbolTableException{
|
||||
LookupData data = new LookupData( name ){
|
||||
public TypeFilter getFilter() {
|
||||
if( t == ITypeInfo.t_any ) return ANY_FILTER;
|
||||
if( filter == null ) filter = new TypeFilter( t );
|
||||
return filter;
|
||||
}
|
||||
private TypeFilter filter = null;
|
||||
private final ITypeInfo.eType t = type;
|
||||
};
|
||||
|
||||
data.qualified = true;
|
||||
|
||||
IContainerSymbol container = this;
|
||||
|
@ -538,6 +547,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
|||
return null;
|
||||
}
|
||||
|
||||
public ISymbol lookupMemberForDefinition( char[] name ) throws ParserSymbolTableException {
|
||||
return lookupMemberForDefinition(name, ITypeInfo.t_any);
|
||||
}
|
||||
|
||||
public IParameterizedSymbol lookupMethodForDefinition( char[] name, final List parameters ) throws ParserSymbolTableException{
|
||||
LookupData data = new LookupData( name ){
|
||||
public List getParameters() { return params; }
|
||||
|
|
|
@ -100,6 +100,7 @@ public interface IContainerSymbol extends ISymbol {
|
|||
*/
|
||||
public ISymbol elaboratedLookup( ITypeInfo.eType type, char[] name ) throws ParserSymbolTableException;
|
||||
public ISymbol lookup( char[] name ) throws ParserSymbolTableException;
|
||||
public ISymbol lookupMemberForDefinition( char[] name, ITypeInfo.eType type ) throws ParserSymbolTableException;
|
||||
public ISymbol lookupMemberForDefinition( char[] name ) throws ParserSymbolTableException;
|
||||
public IParameterizedSymbol lookupMethodForDefinition( char[] name, List parameters ) throws ParserSymbolTableException;
|
||||
public ISymbol lookupNestedNameSpecifier( char[] name ) throws ParserSymbolTableException;
|
||||
|
|
|
@ -854,7 +854,12 @@ public class ParserSymbolTable {
|
|||
( newType == ITypeInfo.t_type || (newType.compareTo( ITypeInfo.t_function ) >= 0 /*&& newType <= TypeInfo.typeMask*/) ) ){
|
||||
|
||||
return true;
|
||||
}
|
||||
// 3.3.7-2 (in any order) same as above but with origType and newType reversed
|
||||
} else if( (newType.compareTo(ITypeInfo.t_class) >= 0 && newType.compareTo(ITypeInfo.t_enumeration) <= 0) && //class name or enumeration ...
|
||||
( origType == ITypeInfo.t_type || (origType.compareTo( ITypeInfo.t_function ) >= 0 /*&& newType <= TypeInfo.typeMask*/) ) ){
|
||||
|
||||
return true;
|
||||
}
|
||||
//if the origtype is not a class-name or enumeration name, then the only other
|
||||
//allowable thing is if they are both functions.
|
||||
if( origSymbol instanceof IParameterizedSymbol && newSymbol instanceof IParameterizedSymbol )
|
||||
|
|
|
@ -359,10 +359,10 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory#lookupMemberForDefinition(java.lang.String)
|
||||
*/
|
||||
public ISymbol lookupMemberForDefinition(char[] name) throws ParserSymbolTableException {
|
||||
public ISymbol lookupMemberForDefinition(char[] name, ITypeInfo.eType type ) throws ParserSymbolTableException {
|
||||
ISymbol look = null;
|
||||
IContainerSymbol last = getLastSymbol();
|
||||
if( last != null ){
|
||||
if( last != null && last.isType(type)){
|
||||
look = last.lookupMemberForDefinition( name );
|
||||
} else {
|
||||
look = getContainingSymbol().lookupMemberForDefinition( name );
|
||||
|
@ -372,6 +372,10 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
|||
}
|
||||
return look;
|
||||
}
|
||||
|
||||
public ISymbol lookupMemberForDefinition(char[] name) throws ParserSymbolTableException {
|
||||
return lookupMemberForDefinition(name, ITypeInfo.t_any);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#elaboratedLookup(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, java.lang.String)
|
||||
|
|
|
@ -226,6 +226,13 @@ public class UndefinedTemplateSymbol extends BasicSymbol implements ITemplateSym
|
|||
return found;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMemberForDefinition(char[])
|
||||
*/
|
||||
public ISymbol lookupMemberForDefinition(char[] name, ITypeInfo.eType type) throws ParserSymbolTableException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMemberForDefinition(char[])
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue