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
- added testBadParameterInfo to ParserSymbolTableTest

View file

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

View file

@ -345,6 +345,7 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
Iterator i = parse(code.toString()).getDeclarations();
IASTVariable instanceA = (IASTVariable)i.next();
assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 0 );
}
public void testNestedClassname() throws Exception
@ -744,4 +745,32 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
IASTFunction foo = (IASTFunction)i.next();
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
In completeParseASTFactory.getExpressionResultType()
- Added the handling of some more expression types.

View file

@ -32,5 +32,7 @@ public interface IASTFunction extends IASTCodeScope, IASTOffsetableNamedElement,
*/
public void setHasFunctionBody(boolean b);
public boolean hasFunctionBody();
public boolean previouslyDeclared();
}

View file

@ -326,7 +326,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner
*/
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.ITokenDuple;
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.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
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.IASTTemplateParameter;
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.IASTUsingDirective;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
@ -1545,7 +1546,7 @@ public class Parser implements IParser
}
ITokenDuple d = name();
IASTElaboratedTypeSpecifier elaboratedTypeSpec = null;
IASTTypeSpecifier elaboratedTypeSpec = null;
final boolean isForewardDecl = ( LT(1) == IToken.tSEMI );
try
@ -1567,7 +1568,7 @@ public class Parser implements IParser
sdw.setTypeSpecifier(elaboratedTypeSpec);
if( isForewardDecl )
elaboratedTypeSpec.acceptElement( requestor );
((IASTElaboratedTypeSpecifier)elaboratedTypeSpec).acceptElement( requestor );
}
/**
* 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
{
private final boolean isForwardDeclaration;
private List references;
private final boolean isForwardDeclaration;
private final ASTClassKind kind;
private final ASTQualifiedNamedElement qualifiedName;
private NamedOffsets offsets = new NamedOffsets();
@ -48,7 +49,7 @@ public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElabora
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), checkSymbol.getName() );
store = new ASTReferenceStore( references );
isForwardDeclaration = isDecl;
this.references = references;
}
/* (non-Javadoc)
* @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) {
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
{
private boolean hasFunctionBody = false;
private final boolean previouslyDeclared;
private boolean hasFunctionBody = false;
private final IASTTemplate ownerTemplate;
private final IASTAbstractDeclaration returnType;
private final IASTExceptionSpecification exception;
@ -51,7 +52,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
* @param ownerTemplate
* @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 );
this.parameters = parameters;
@ -63,6 +64,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
this.ownerTemplate = ownerTemplate;
this.references = new ASTReferenceStore( references );
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 ?
(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 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 )
{
super(
@ -56,7 +56,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
startOffset,
nameOffset,
ownerTemplate,
references);
references, previouslyDeclared );
this.visibility = visibility;
this.isConstructor = isConstructor;
this.isDestructor = isDestructor;

View file

@ -425,9 +425,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ISymbolASTExtension extension = symbol.getASTExtension();
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 );
else if( astSymbol instanceof IASTFunction ) // TODO : other foreward declare cases
else if( astSymbol instanceof IASTFunction || astSymbol instanceof IASTMethod )
{
extension = new ForewardDeclaredSymbolExtension( symbol, astSymbol );
}
@ -1351,7 +1355,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
setParameters( symbol, references, parameters.iterator() );
symbol.setIsForwardDeclaration(!isFunctionDefinition);
boolean previouslyDeclared = false;
if( isFunctionDefinition )
{
List functionParameters = new LinkedList();
@ -1371,6 +1375,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( functionDeclaration != null )
{
functionDeclaration.setTypeSymbol( symbol );
previouslyDeclared = true;
}
}
@ -1382,7 +1387,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{
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
{
attachSymbolExtension(symbol, function);
@ -1491,13 +1496,20 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
List newReferences = null;
if( absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier )
{
IASTSimpleTypeSpecifier.Type kind = ((IASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getType();
if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
if( ((IASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getType() == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
{
xrefSymbol = ((ASTSimpleTypeSpecifier)absDecl.getTypeSpecifier()).getSymbol();
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 = "";
if(absDecl instanceof IASTParameterDeclaration){
@ -1654,8 +1666,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
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
{
attachSymbolExtension( symbol, method );
@ -1984,10 +1998,31 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
throw new ASTSemanticException();
}
}
return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration();
}
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();
}
throw new ASTSemanticException();
}
protected ParserSymbolTable pst;

View file

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