mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 61800: Lookup failing on definition of static field
fix problems with forward declarations of static fields/variables.
This commit is contained in:
parent
c9c666335f
commit
3e388658d9
8 changed files with 46 additions and 26 deletions
|
@ -9,10 +9,6 @@
|
||||||
* IBM Rational Software - Initial API and implementation */
|
* IBM Rational Software - Initial API and implementation */
|
||||||
package org.eclipse.cdt.core.parser.failedTests;
|
package org.eclipse.cdt.core.parser.failedTests;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.SelectionParseBaseTest;
|
import org.eclipse.cdt.core.parser.tests.SelectionParseBaseTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,18 +17,6 @@ import org.eclipse.cdt.core.parser.tests.SelectionParseBaseTest;
|
||||||
*/
|
*/
|
||||||
public class SelectionParseFailedTest extends SelectionParseBaseTest {
|
public class SelectionParseFailedTest extends SelectionParseBaseTest {
|
||||||
|
|
||||||
public void testBug61800() throws Exception
|
|
||||||
{
|
|
||||||
Writer writer = new StringWriter();
|
|
||||||
writer.write( "class ABCDEF {\n"); //$NON-NLS-1$
|
|
||||||
writer.write( " static int stInt; };\n"); //$NON-NLS-1$
|
|
||||||
writer.write( "int ABCDEF::stInt = 5;\n"); //$NON-NLS-1$
|
|
||||||
String code = writer.toString();
|
|
||||||
int startIndex = code.indexOf( "::stInt") + 2; //$NON-NLS-1$
|
|
||||||
IASTNode node = parse( code, startIndex, startIndex+ 5, false );
|
|
||||||
// IASTNode node = parse( code, startIndex, startIndex+ 5 );
|
|
||||||
// assertTrue( node instanceof IASTField );
|
|
||||||
// assertEquals( ((IASTField)node).getName(), "stInt" ); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -532,7 +532,7 @@ public class CompleteParseASTTemplateTest extends CompleteParseBaseTest {
|
||||||
Writer writer = new StringWriter();
|
Writer writer = new StringWriter();
|
||||||
writer.write( "template< class T > class A{ \n" ); //$NON-NLS-1$
|
writer.write( "template< class T > class A{ \n" ); //$NON-NLS-1$
|
||||||
writer.write( " typedef T * PT; \n" ); //$NON-NLS-1$
|
writer.write( " typedef T * PT; \n" ); //$NON-NLS-1$
|
||||||
writer.write( " static T member; \n" ); //$NON-NLS-1$
|
writer.write( " static T * member; \n" ); //$NON-NLS-1$
|
||||||
writer.write( "}; \n" ); //$NON-NLS-1$
|
writer.write( "}; \n" ); //$NON-NLS-1$
|
||||||
writer.write( "template< class T> A<T>::PT A<T>::member = null; \n" ); //$NON-NLS-1$
|
writer.write( "template< class T> A<T>::PT A<T>::member = null; \n" ); //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.io.StringWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTField;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||||
|
@ -331,4 +332,19 @@ public class SelectionParseTest extends SelectionParseBaseTest {
|
||||||
int startIndex = code.indexOf( "static_function( file )"); //$NON-NLS-1$
|
int startIndex = code.indexOf( "static_function( file )"); //$NON-NLS-1$
|
||||||
parse( code, startIndex, startIndex + "static_function".length() ); //$NON-NLS-1$
|
parse( code, startIndex, startIndex + "static_function".length() ); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug61800() throws Exception
|
||||||
|
{
|
||||||
|
Writer writer = new StringWriter();
|
||||||
|
writer.write( "class B {};\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "class ABCDEF {\n"); //$NON-NLS-1$
|
||||||
|
writer.write( " static B stInt; };\n"); //$NON-NLS-1$
|
||||||
|
writer.write( "B ABCDEF::stInt = 5;\n"); //$NON-NLS-1$
|
||||||
|
String code = writer.toString();
|
||||||
|
int startIndex = code.indexOf( "::stInt") + 2; //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTNode node = parse( code, startIndex, startIndex+ 5 );
|
||||||
|
assertTrue( node instanceof IASTField );
|
||||||
|
assertEquals( ((IASTField)node).getName(), "stInt" ); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
|
||||||
import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests;
|
import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests;
|
||||||
import org.eclipse.cdt.core.parser.failedTests.FailedCompleteParseASTTest;
|
import org.eclipse.cdt.core.parser.failedTests.FailedCompleteParseASTTest;
|
||||||
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
|
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
|
||||||
import org.eclipse.cdt.core.parser.failedTests.SelectionParseFailedTest;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
||||||
import org.eclipse.cdt.core.search.tests.SearchTestSuite;
|
import org.eclipse.cdt.core.search.tests.SearchTestSuite;
|
||||||
|
|
||||||
|
@ -71,7 +70,6 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
||||||
suite.addTestSuite(ASTFailedTests.class);
|
suite.addTestSuite(ASTFailedTests.class);
|
||||||
suite.addTestSuite(STLFailedTests.class);
|
suite.addTestSuite(STLFailedTests.class);
|
||||||
suite.addTestSuite(FailedCompleteParseASTTest.class);
|
suite.addTestSuite(FailedCompleteParseASTTest.class);
|
||||||
suite.addTestSuite(SelectionParseFailedTest.class);
|
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2706,12 +2706,18 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
|
|
||||||
if( variableDeclaration != null && newSymbol.getType() == variableDeclaration.getType() )
|
if( variableDeclaration != null && newSymbol.getType() == variableDeclaration.getType() )
|
||||||
{
|
{
|
||||||
if( !newSymbol.isType( ITypeInfo.t_type ) ||
|
TypeInfoProvider provider = pst.getTypeInfoProvider();
|
||||||
(newSymbol.isType( ITypeInfo.t_type ) && newSymbol.getTypeSymbol() != variableDeclaration.getTypeSymbol() ) )
|
|
||||||
|
ITypeInfo newInfo = newSymbol.getTypeInfo().getFinalType( provider );
|
||||||
|
ITypeInfo varInfo = variableDeclaration.getTypeInfo().getFinalType( provider );
|
||||||
|
|
||||||
|
if( newInfo.equals( varInfo ) )
|
||||||
{
|
{
|
||||||
variableDeclaration.setForwardSymbol( newSymbol );
|
variableDeclaration.setForwardSymbol( newSymbol );
|
||||||
previouslyDeclared = true;
|
previouslyDeclared = true;
|
||||||
}
|
}
|
||||||
|
provider.returnTypeInfo( newInfo );
|
||||||
|
provider.returnTypeInfo( varInfo );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
|
@ -2934,8 +2940,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
|
|
||||||
if( fieldDeclaration != null && newSymbol.getType() == fieldDeclaration.getType() )
|
if( fieldDeclaration != null && newSymbol.getType() == fieldDeclaration.getType() )
|
||||||
{
|
{
|
||||||
if( !newSymbol.isType( ITypeInfo.t_type ) ||
|
TypeInfoProvider provider = pst.getTypeInfoProvider();
|
||||||
(newSymbol.isType( ITypeInfo.t_type ) && newSymbol.getTypeSymbol() != fieldDeclaration.getTypeSymbol() ) )
|
|
||||||
|
ITypeInfo newInfo = newSymbol.getTypeInfo().getFinalType( provider );
|
||||||
|
ITypeInfo fieldInfo = fieldDeclaration.getTypeInfo().getFinalType( provider );
|
||||||
|
|
||||||
|
if( newInfo.equals( fieldInfo ) )
|
||||||
{
|
{
|
||||||
previouslyDeclared = true;
|
previouslyDeclared = true;
|
||||||
fieldDeclaration.setForwardSymbol( newSymbol );
|
fieldDeclaration.setForwardSymbol( newSymbol );
|
||||||
|
@ -2943,6 +2953,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
// ASTReference reference = (ASTReference) fieldReferences.iterator().next();
|
// ASTReference reference = (ASTReference) fieldReferences.iterator().next();
|
||||||
visibility = ((IASTField)fieldDeclaration.getASTExtension().getPrimaryDeclaration()).getVisiblity();
|
visibility = ((IASTField)fieldDeclaration.getASTExtension().getPrimaryDeclaration()).getVisiblity();
|
||||||
}
|
}
|
||||||
|
provider.returnTypeInfo( newInfo );
|
||||||
|
provider.returnTypeInfo( fieldInfo );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,10 @@ public class BasicTypeInfo implements ITypeInfo {
|
||||||
|
|
||||||
ITypeInfo type = (ITypeInfo)t;
|
ITypeInfo type = (ITypeInfo)t;
|
||||||
|
|
||||||
boolean result = ( _typeBits == type.getTypeBits() );
|
int bits1 = _typeBits & ~isTypedef & ~isForward & ~isStatic & ~isExtern;
|
||||||
|
int bits2 = type.getTypeBits() & ~isTypedef & ~isForward & ~isStatic & ~isExtern;
|
||||||
|
boolean result = ( bits1 == bits2 );
|
||||||
|
|
||||||
result &= ( _type == type.getType() );
|
result &= ( _type == type.getType() );
|
||||||
|
|
||||||
// Object def1 = getDefault();
|
// Object def1 = getDefault();
|
||||||
|
|
|
@ -526,7 +526,11 @@ public class ParserSymbolTable {
|
||||||
if( obj == null ){
|
if( obj == null ){
|
||||||
obj = foundSymbol;
|
obj = foundSymbol;
|
||||||
} else {
|
} else {
|
||||||
if( data.isPrefixLookup() ){
|
if( obj.isForwardDeclaration() && obj.getForwardSymbol() == foundSymbol )
|
||||||
|
obj = foundSymbol;
|
||||||
|
else if( foundSymbol.isForwardDeclaration() && foundSymbol.getForwardSymbol() == obj ){
|
||||||
|
//we already have what we want.
|
||||||
|
} else if( data.isPrefixLookup() ){
|
||||||
data.addAmbiguity( foundSymbol.getName() );
|
data.addAmbiguity( foundSymbol.getName() );
|
||||||
} else {
|
} else {
|
||||||
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous );
|
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous );
|
||||||
|
|
|
@ -464,6 +464,9 @@ public class BasicTokenDuple implements ITokenDuple {
|
||||||
}
|
}
|
||||||
i = i.getNext();
|
i = i.getNext();
|
||||||
}
|
}
|
||||||
|
if( i.getType() == IToken.tIDENTIFIER ){
|
||||||
|
qn.add( i.getImage() );
|
||||||
|
}
|
||||||
String [] qualifiedName = new String[ qn.size() ];
|
String [] qualifiedName = new String[ qn.size() ];
|
||||||
return (String[]) qn.toArray( qualifiedName );
|
return (String[]) qn.toArray( qualifiedName );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue