mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bugs 68623 & 69428 - fix up parsing of constructor initializers
This commit is contained in:
parent
93350b3442
commit
b8324eb1a0
3 changed files with 36 additions and 5 deletions
|
@ -2036,4 +2036,31 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
|||
writer.write( "}\n" );
|
||||
parse( writer.toString() );
|
||||
}
|
||||
|
||||
public void testBug68623() throws Exception{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write( "class A { \n" );
|
||||
writer.write( " A(); \n" );
|
||||
writer.write( " class sub{}; \n" );
|
||||
writer.write( " sub * x; \n" );
|
||||
writer.write( "}; \n" );
|
||||
writer.write( "A::A() : x( (sub *) 0 ) {} \n" );
|
||||
|
||||
parse( writer.toString() );
|
||||
|
||||
writer = new StringWriter();
|
||||
writer.write( "class A { \n" );
|
||||
writer.write( " A() : x (0) {} \n" );
|
||||
writer.write( " int x; \n" );
|
||||
writer.write( "}; \n" );
|
||||
|
||||
Iterator i = parse( writer.toString() ).getDeclarations();
|
||||
IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
|
||||
i = A.getDeclarations();
|
||||
IASTMethod constructor = (IASTMethod) i.next();
|
||||
IASTField x = (IASTField) i.next();
|
||||
|
||||
assertAllReferences( 1, createTaskList( new Task( x ) ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1333,6 +1333,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
{
|
||||
int startingOffset = consume(IToken.tCOLON).getOffset();
|
||||
IASTScope scope = d.getDeclarationWrapper().getScope();
|
||||
scope = astFactory.getDeclaratorScope(scope, d.getNameDuple());
|
||||
for (;;)
|
||||
{
|
||||
if (LT(1) == IToken.tLBRACE)
|
||||
|
@ -1344,16 +1345,14 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
consume(IToken.tLPAREN);
|
||||
IASTExpression expressionList = null;
|
||||
|
||||
expressionList = expression(d.getDeclarationWrapper().getScope(), CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.EXPRESSION);
|
||||
expressionList = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.EXPRESSION);
|
||||
|
||||
IToken rparen = consume(IToken.tRPAREN);
|
||||
|
||||
try
|
||||
{
|
||||
d.addConstructorMemberInitializer(
|
||||
astFactory.createConstructorMemberInitializer(
|
||||
d.getDeclarationWrapper().getScope(),
|
||||
duple, expressionList));
|
||||
astFactory.createConstructorMemberInitializer(scope, duple, expressionList) );
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
|
|
|
@ -1927,7 +1927,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
symbol = lookupQualifiedName( scopeSymbol, duple, references, true );
|
||||
} catch( ASTSemanticException ase )
|
||||
{
|
||||
requireReferenceResolution = true;
|
||||
//use the class specifier's unresolved reference mechanism to resolve these references.
|
||||
//TODO: resolve unresolved references in the expressionList using resolveLeftoverConstructorInitializerMembers
|
||||
if( scope instanceof ASTClassSpecifier ){
|
||||
ASTClassSpecifier classSpecifier = (ASTClassSpecifier) scope;
|
||||
classSpecifier.addUnresolvedReference( new UnresolvedReferenceDuple(scopeSymbol, duple ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue