From ae96e590fffbe567e0f8a2c9d36a5f0a028d06b3 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Fri, 5 Sep 2003 13:45:16 +0000 Subject: [PATCH] Patch for Andrew Niefer Fixed NPE in CompleParseASTFactory.createClassSpecifier caused by a null name. --- core/org.eclipse.cdt.core.tests/ChangeLog | 3 + .../parser/tests/CompleteParseASTTest.java | 11 ++++ core/org.eclipse.cdt.core/parser/ChangeLog | 3 + .../ast/complete/CompleteParseASTFactory.java | 57 +++++++++++-------- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 82742374472..08ec538e5a1 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -2,6 +2,9 @@ Updated ASTFailedTests::testBug39702() to fail more accurately. Added testSimpleFunctionBody(), testSimpleForLoop() to CompleteParseASTTest.java. +2003-09-04 Andrew Niefer + Added testBug42541 to CompleParseASTTests.java + 2003-09-04 Hoda Amer Call to ASTExpression getTypeId() changed to getTypeIdString(). diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index 15e344c1c8a..bd1f1b39984 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -596,5 +596,16 @@ public class CompleteParseASTTest extends CompleteParseBaseTest assertFalse( i.hasNext() ); assertEquals( callback.getReferences().size(), 5 ); } + + public void testBug42541() throws Exception + { + Iterator i = parse( "union{ int v; char a; } id;" ).getDeclarations(); + IASTVariable id = (IASTVariable)i.next(); + + IASTClassSpecifier union = (IASTClassSpecifier) id.getAbstractDeclaration().getTypeSpecifier(); + Iterator sub = getDeclarations( union ); + IASTField intV = (IASTField)sub.next(); + IASTField charA = (IASTField)sub.next(); + } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 6d38c786dba..6357a3d7d14 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -3,6 +3,9 @@ Updated IASTFactory/ISourceElementRequestor to include IASTCodeScope constructs, clients should keep this in mind and update their implementations. +2003-09-04 Andrew Niefer + Fix bug42541 - Anonymous structures cause NPE in full parse + 2003-09-03 Andrew Niefer fix bug in PST that prevents > 2 constructors diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index 97ef4d9e2b0..a37a97feec3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -432,35 +432,42 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto IContainerSymbol currentScopeSymbol = scopeToSymbol(scope); TypeInfo.eType pstType = classKindToTypeInfo(kind); List references = new ArrayList(); - IToken lastToken = name.getLastToken(); - if( name.length() != 1 ) // qualified name - { - ITokenDuple containerSymbolName = - name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name - currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, - containerSymbolName, references, true); - if( currentScopeSymbol == null ) - throw new ASTSemanticException(); + + String newSymbolName = ""; + + if( name != null ){ + IToken lastToken = name.getLastToken(); + if( name.length() != 1 ) // qualified name + { + ITokenDuple containerSymbolName = + name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name + currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, + containerSymbolName, references, true); + if( currentScopeSymbol == null ) + throw new ASTSemanticException(); + } + newSymbolName = lastToken.getImage(); } ISymbol classSymbol = null; - try - { - classSymbol = currentScopeSymbol.lookupMemberForDefinition(lastToken.getImage()); - } - catch (ParserSymbolTableException e) - { - throw new ASTSemanticException(); - } - - if( classSymbol != null && ! classSymbol.isForwardDeclaration() ) - throw new ASTSemanticException(); - - if( classSymbol != null && classSymbol.getType() != pstType ) - throw new ASTSemanticException(); + if( !newSymbolName.equals("") ){ + try + { + classSymbol = currentScopeSymbol.lookupMemberForDefinition(newSymbolName); + } + catch (ParserSymbolTableException e) + { + throw new ASTSemanticException(); + } + + if( classSymbol != null && ! classSymbol.isForwardDeclaration() ) + throw new ASTSemanticException(); + + if( classSymbol != null && classSymbol.getType() != pstType ) + throw new ASTSemanticException(); + } - - IDerivableContainerSymbol newSymbol = pst.newDerivableContainerSymbol( lastToken.getImage(), pstType ); + IDerivableContainerSymbol newSymbol = pst.newDerivableContainerSymbol( newSymbolName, pstType ); if( classSymbol != null ) classSymbol.setTypeSymbol( newSymbol );