1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00
Partially fixed Bug 42979 : Cannot search for operator overloaders 
	

TESTS
	Added CompleteParseASTTest::testBug42979().
	Updated CompleteParseASTTest::testAndrewsExample().
This commit is contained in:
John Camelon 2003-09-15 19:04:48 +00:00
parent 5669e06d25
commit 780a8096ed
12 changed files with 121 additions and 22 deletions

View file

@ -1,3 +1,7 @@
2003-09-15 John Camelon
Added CompleteParseASTTest::testBug42979().
Updated CompleteParseASTTest::testAndrewsExample().
2003-09-13 Andrew Niefer 2003-09-13 Andrew Niefer
- added testBadParameterInfo to ParserSymbolTableTest - added testBadParameterInfo to ParserSymbolTableTest

View file

@ -92,7 +92,7 @@ public class BaseASTTest extends TestCase
public void assertCodeFailsParse(String code) { public void assertCodeFailsParse(String code) {
boolean testPassed = false; boolean testPassed = false;
try { try {
IASTCompilationUnit tu = parse(code); parse(code);
testPassed = true; testPassed = true;
fail( "We should not reach this point"); fail( "We should not reach this point");
} catch (Throwable e) { } catch (Throwable e) {
@ -106,7 +106,7 @@ public class BaseASTTest extends TestCase
public void assertCodeFailsFullParse(String code) { public void assertCodeFailsFullParse(String code) {
boolean testPassed = false; boolean testPassed = false;
try { try {
IASTCompilationUnit tu = fullParse(code); fullParse(code);
testPassed = true; testPassed = true;
fail( "We should not reach this point"); fail( "We should not reach this point");
} catch (Throwable e) { } catch (Throwable e) {

View file

@ -345,6 +345,7 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
Iterator i = parse(code.toString()).getDeclarations(); Iterator i = parse(code.toString()).getDeclarations();
IASTVariable instanceA = (IASTVariable)i.next(); IASTVariable instanceA = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 0 );
} }
public void testNestedClassname() throws Exception public void testNestedClassname() throws Exception
@ -744,4 +745,32 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
IASTFunction foo = (IASTFunction)i.next(); IASTFunction foo = (IASTFunction)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
} }
public void testBug42979() throws Exception
{
Writer code = new StringWriter();
code.write( "class OperatorOverload{\n" );
code.write( "public:\n" );
code.write( " bool operator==( const class OperatorOverload& that )\n" );
code.write( " { return true; }\n" );
code.write( " bool operator!=( const class OperatorOverload& that );\n" );
code.write( "}; \n" );
code.write( "bool OperatorOverload::operator!=( const class OperatorOverload& that )\n" );
code.write( "{ return false; }\n" );
Iterator i = parse( code.toString() ).getDeclarations();
IASTClassSpecifier classOp = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
Iterator subDeclarations = getDeclarations(classOp);
IASTMethod operatorEqualsDeclaration = (IASTMethod)subDeclarations.next();
IASTMethod operatorNotEqualsDeclaration = (IASTMethod)subDeclarations.next();
IASTMethod operatorNotEqualDefinition = (IASTMethod)i.next();
assertEquals( operatorNotEqualDefinition.getName(), operatorNotEqualsDeclaration.getName() );
assertFalse( i.hasNext());
assertEquals( callback.getReferences().size(), 4 );
for( int j =0; j < 4; ++j )
assertFalse( classOp.getNameOffset() == ((IASTReference)callback.getReferences().get(j)).getOffset() );
}
} }

View file

@ -1,3 +1,6 @@
2003-09-15 John Camelon
Partially fixed Bug 42979 : Cannot search for operator overloaders
2003-09-12 Hoda Amer 2003-09-12 Hoda Amer
In completeParseASTFactory.getExpressionResultType() In completeParseASTFactory.getExpressionResultType()
- Added the handling of some more expression types. - Added the handling of some more expression types.

View file

@ -33,4 +33,6 @@ public interface IASTFunction extends IASTCodeScope, IASTOffsetableNamedElement,
public void setHasFunctionBody(boolean b); public void setHasFunctionBody(boolean b);
public boolean hasFunctionBody(); public boolean hasFunctionBody();
public boolean previouslyDeclared();
} }

View file

@ -326,7 +326,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner
*/ */
public void hasFunctionBody(boolean b) public void hasFunctionBody(boolean b)
{ {
hasFunctionBody = true; hasFunctionBody = b;
} }
/** /**

View file

@ -23,8 +23,8 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ITranslationResult; import org.eclipse.cdt.core.parser.ITranslationResult;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException; import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
@ -53,6 +53,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
@ -1545,7 +1546,7 @@ public class Parser implements IParser
} }
ITokenDuple d = name(); ITokenDuple d = name();
IASTElaboratedTypeSpecifier elaboratedTypeSpec = null; IASTTypeSpecifier elaboratedTypeSpec = null;
final boolean isForewardDecl = ( LT(1) == IToken.tSEMI ); final boolean isForewardDecl = ( LT(1) == IToken.tSEMI );
try try
@ -1567,7 +1568,7 @@ public class Parser implements IParser
sdw.setTypeSpecifier(elaboratedTypeSpec); sdw.setTypeSpecifier(elaboratedTypeSpec);
if( isForewardDecl ) if( isForewardDecl )
elaboratedTypeSpec.acceptElement( requestor ); ((IASTElaboratedTypeSpecifier)elaboratedTypeSpec).acceptElement( requestor );
} }
/** /**
* Consumes template parameters. * Consumes template parameters.

View file

@ -26,7 +26,8 @@ import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
*/ */
public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElaboratedTypeSpecifier public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElaboratedTypeSpecifier
{ {
private final boolean isForwardDeclaration; private List references;
private final boolean isForwardDeclaration;
private final ASTClassKind kind; private final ASTClassKind kind;
private final ASTQualifiedNamedElement qualifiedName; private final ASTQualifiedNamedElement qualifiedName;
private NamedOffsets offsets = new NamedOffsets(); private NamedOffsets offsets = new NamedOffsets();
@ -48,7 +49,7 @@ public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElabora
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), checkSymbol.getName() ); qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), checkSymbol.getName() );
store = new ASTReferenceStore( references ); store = new ASTReferenceStore( references );
isForwardDeclaration = isDecl; isForwardDeclaration = isDecl;
this.references = references;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier#getName() * @see org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier#getName()
@ -139,4 +140,9 @@ public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElabora
public void setNameOffset(int o) { public void setNameOffset(int o) {
offsets.setNameOffset(o); offsets.setNameOffset(o);
} }
public List getReferences()
{
return references;
}
} }

View file

@ -32,7 +32,8 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
*/ */
public class ASTFunction extends ASTScope implements IASTFunction public class ASTFunction extends ASTScope implements IASTFunction
{ {
private boolean hasFunctionBody = false; private final boolean previouslyDeclared;
private boolean hasFunctionBody = false;
private final IASTTemplate ownerTemplate; private final IASTTemplate ownerTemplate;
private final IASTAbstractDeclaration returnType; private final IASTAbstractDeclaration returnType;
private final IASTExceptionSpecification exception; private final IASTExceptionSpecification exception;
@ -51,7 +52,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
* @param ownerTemplate * @param ownerTemplate
* @param references * @param references
*/ */
public ASTFunction(IParameterizedSymbol symbol, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references) public ASTFunction(IParameterizedSymbol symbol, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references, boolean previouslyDeclared )
{ {
super( symbol ); super( symbol );
this.parameters = parameters; this.parameters = parameters;
@ -63,6 +64,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
this.ownerTemplate = ownerTemplate; this.ownerTemplate = ownerTemplate;
this.references = new ASTReferenceStore( references ); this.references = new ASTReferenceStore( references );
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() ); qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() );
this.previouslyDeclared =previouslyDeclared;
} }
@ -250,4 +252,13 @@ public class ASTFunction extends ASTScope implements IASTFunction
return ( getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration() ) instanceof IASTCodeScope ? return ( getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration() ) instanceof IASTCodeScope ?
(IASTCodeScope) getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration() : null; (IASTCodeScope) getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration() : null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#previouslyDeclared()
*/
public boolean previouslyDeclared()
{
return previouslyDeclared;
}
} }

View file

@ -45,7 +45,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
* @param ownerTemplate * @param ownerTemplate
* @param references * @param references
*/ */
public ASTMethod(IParameterizedSymbol symbol, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references, public ASTMethod(IParameterizedSymbol symbol, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int nameOffset, IASTTemplate ownerTemplate, List references, boolean previouslyDeclared,
boolean isConstructor, boolean isDestructor, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain ) boolean isConstructor, boolean isDestructor, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain )
{ {
super( super(
@ -56,7 +56,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
startOffset, startOffset,
nameOffset, nameOffset,
ownerTemplate, ownerTemplate,
references); references, previouslyDeclared );
this.visibility = visibility; this.visibility = visibility;
this.isConstructor = isConstructor; this.isConstructor = isConstructor;
this.isDestructor = isDestructor; this.isDestructor = isDestructor;

View file

@ -425,9 +425,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ISymbolASTExtension extension = symbol.getASTExtension(); ISymbolASTExtension extension = symbol.getASTExtension();
if( extension == null ) if( extension == null )
{ {
if( astSymbol instanceof IASTNamespaceDefinition ) if( astSymbol instanceof IASTNamespaceDefinition ||
astSymbol instanceof IASTEnumerationSpecifier ||
astSymbol instanceof IASTClassSpecifier ||
astSymbol instanceof IASTElaboratedTypeSpecifier )
extension = new NamespaceSymbolExtension( symbol, astSymbol ); extension = new NamespaceSymbolExtension( symbol, astSymbol );
else if( astSymbol instanceof IASTFunction ) // TODO : other foreward declare cases else if( astSymbol instanceof IASTFunction || astSymbol instanceof IASTMethod )
{ {
extension = new ForewardDeclaredSymbolExtension( symbol, astSymbol ); extension = new ForewardDeclaredSymbolExtension( symbol, astSymbol );
} }
@ -1351,7 +1355,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
setParameters( symbol, references, parameters.iterator() ); setParameters( symbol, references, parameters.iterator() );
symbol.setIsForwardDeclaration(!isFunctionDefinition); symbol.setIsForwardDeclaration(!isFunctionDefinition);
boolean previouslyDeclared = false;
if( isFunctionDefinition ) if( isFunctionDefinition )
{ {
List functionParameters = new LinkedList(); List functionParameters = new LinkedList();
@ -1371,6 +1375,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( functionDeclaration != null ) if( functionDeclaration != null )
{ {
functionDeclaration.setTypeSymbol( symbol ); functionDeclaration.setTypeSymbol( symbol );
previouslyDeclared = true;
} }
} }
@ -1382,7 +1387,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
throw new ASTSemanticException(); throw new ASTSemanticException();
} }
ASTFunction function = new ASTFunction( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references ); ASTFunction function = new ASTFunction( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, previouslyDeclared );
try try
{ {
attachSymbolExtension(symbol, function); attachSymbolExtension(symbol, function);
@ -1491,13 +1496,20 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
List newReferences = null; List newReferences = null;
if( absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ) if( absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier )
{ {
IASTSimpleTypeSpecifier.Type kind = ((IASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getType(); if( ((IASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getType() == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
{ {
xrefSymbol = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getSymbol(); xrefSymbol = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getSymbol();
newReferences = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getReferences(); newReferences = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getReferences();
} }
} }
else if( absDecl.getTypeSpecifier() instanceof ASTElaboratedTypeSpecifier )
{
ASTElaboratedTypeSpecifier elab = (ASTElaboratedTypeSpecifier)absDecl.getTypeSpecifier();
xrefSymbol = elab.getSymbol();
newReferences = new ArrayList();
newReferences.addAll( elab.getReferences() );
newReferences.add( createReference( xrefSymbol, elab.getName(), elab.getNameOffset()) );
}
String paramName = ""; String paramName = "";
if(absDecl instanceof IASTParameterDeclaration){ if(absDecl instanceof IASTParameterDeclaration){
@ -1654,8 +1666,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
throw new ASTSemanticException(); throw new ASTSemanticException();
} }
boolean previouslyDeclared = false;
//TODO : Hoda - if symbol was previously declared in PST, then set this to true
ASTMethod method = new ASTMethod( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, isConstructor, isDestructor, isPureVirtual, visibility, constructorChain ); ASTMethod method = new ASTMethod( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, previouslyDeclared, isConstructor, isDestructor, isPureVirtual, visibility, constructorChain );
try try
{ {
attachSymbolExtension( symbol, method ); attachSymbolExtension( symbol, method );
@ -1984,10 +1998,31 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
throw new ASTSemanticException(); throw new ASTSemanticException();
} }
} }
return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration();
} }
else
{
if( checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTClassSpecifier ||
checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTEnumerationSpecifier
)
{
ASTElaboratedTypeSpecifier elab = new ASTElaboratedTypeSpecifier( checkSymbol, kind, startingOffset, name.getFirstToken().getOffset(), endOffset, references, isForewardDecl );
try
{
attachSymbolExtension( checkSymbol, elab );
}
catch (ExtensionException e2)
{
throw new ASTSemanticException();
}
return elab;
}
if( checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTElaboratedTypeSpecifier )
return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration();
}
return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration(); throw new ASTSemanticException();
} }
protected ParserSymbolTable pst; protected ParserSymbolTable pst;

View file

@ -218,4 +218,12 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction
{ {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFunction#previouslyDeclared()
*/
public boolean previouslyDeclared()
{
// TODO Auto-generated method stub
return false;
}
} }