1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00
Fixed Bug 40842 - Parser: NPE while parsing class declaration in full parse mode 
	Fixed Bug 40843 - Parser: failParse doesn't set parsePassed = false on EOF.
	Fixed Miscellaneous overrides issues involving parameters & functions. 


TESTS
	Added/moved tests as necessary for bugfix 40842 & 40843.
This commit is contained in:
John Camelon 2003-07-28 20:49:47 +00:00
parent 33fdeeac10
commit 95b11e1171
10 changed files with 74 additions and 30 deletions

View file

@ -1,3 +1,6 @@
2003-07-28 John Camelon
Added/moved tests as necessary for bugfix 40842 & 40843.
2003-07-28 Andrew Niefer 2003-07-28 Andrew Niefer
This patch creates a new failing test class : FullParseFailedTests. This This patch creates a new failing test class : FullParseFailedTests. This
is for writing failed tests on the parser doing COMPLETE_PARSE. is for writing failed tests on the parser doing COMPLETE_PARSE.

View file

@ -13,8 +13,8 @@
*/ */
package org.eclipse.cdt.core.parser.failedTests; package org.eclipse.cdt.core.parser.failedTests;
import java.io.StringWriter; import junit.framework.Test;
import java.io.Writer; import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.tests.BaseASTTest; import org.eclipse.cdt.core.parser.tests.BaseASTTest;
@ -32,14 +32,10 @@ public class FullParseFailedTests extends BaseASTTest {
public FullParseFailedTests(String name) { public FullParseFailedTests(String name) {
super(name); super(name);
} }
public void testBug40842() throws Exception{ public static Test suite() {
Writer code = new StringWriter(); TestSuite suite = new TestSuite(FullParseFailedTests.class.getName());
return suite;
//note that if the parse fails at EOF, parse.failParse never sets
//parsePassed = false because it will throw EOF on LA(1), so get
//around this by adding more code after the error.
code.write("class A {} a;\n int x;");
assertCodeFailsFullParse(code.toString());
} }
} }

View file

@ -11,6 +11,8 @@
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
@ -810,6 +812,22 @@ public class CompleteParseASTTest extends TestCase
assertEquals( fromAST[i], theTruth[i]); assertEquals( fromAST[i], theTruth[i]);
} }
} }
public void testBug40842() throws Exception{
Writer code = new StringWriter();
code.write("class A {} a;\n");
Iterator i = parse(code.toString()).getDeclarations();
IASTVariable instanceA = (IASTVariable)i.next();
assertFalse( i.hasNext() );
}
public void testOverride() throws Exception
{
Iterator i = parse( "void foo();\n void foo( int );\n").getDeclarations();
IASTFunction f1 = (IASTFunction)i.next();
IASTFunction f2 = (IASTFunction)i.next();
assertFalse( i.hasNext() );
}
} }

View file

@ -429,7 +429,7 @@ public class QuickParseASTTests extends BaseASTTest
} }
public void testBug36290() throws Exception { public void testBug36290() throws Exception {
parse("typedef void ( A:: * pFunction ) ( void ); "); parse("typedef void ( A:: * pMethod ) ( void ); ");
parse("typedef void (boo) ( void ); "); parse("typedef void (boo) ( void ); ");
parse("typedef void boo (void); "); parse("typedef void boo (void); ");
} }

View file

@ -98,7 +98,7 @@ public class AutomatedIntegrationSuite extends TestSuite
suite.addTestSuite(LokiFailures.class); suite.addTestSuite(LokiFailures.class);
suite.addTestSuite(STLFailedTests.class); suite.addTestSuite(STLFailedTests.class);
suite.addTestSuite(CModelElementsFailedTests.class); suite.addTestSuite(CModelElementsFailedTests.class);
suite.addTestSuite(FullParseFailedTests.class); suite.addTest(FullParseFailedTests.suite());
// Last test to trigger report generation // Last test to trigger report generation
suite.addTest(suite.new GenerateReport("generateReport")); suite.addTest(suite.new GenerateReport("generateReport"));

View file

@ -1,3 +1,8 @@
2003-07-28 John Camelon
Fixed Bug 40842 - Parser: NPE while parsing class declaration in full parse mode
Fixed Bug 40843 - Parser: failParse doesn't set parsePassed = false on EOF.
Fixed Miscellaneous overrides issues involving parameters & functions.
2003-07-28 John Camelon 2003-07-28 John Camelon
Fixed Bug 40730 : Parser is not searching the include path for #include"<name>" Fixed Bug 40730 : Parser is not searching the include path for #include"<name>"

View file

@ -19,9 +19,8 @@ import java.util.Iterator;
public interface IASTAbstractDeclaration extends IASTTypeSpecifierOwner public interface IASTAbstractDeclaration extends IASTTypeSpecifierOwner
{ {
public boolean isConst(); public boolean isConst();
public Iterator getPointerOperators(); public Iterator getPointerOperators();
public Iterator getArrayModifiers(); public Iterator getArrayModifiers();
} }

View file

@ -88,9 +88,18 @@ public class Parser implements IParser
*/ */
protected void failParse() throws EndOfFile protected void failParse() throws EndOfFile
{ {
if (firstErrorOffset == DEFAULT_OFFSET) try
firstErrorOffset = LA(1).getOffset(); {
parsePassed = false; if (firstErrorOffset == DEFAULT_OFFSET)
firstErrorOffset = LA(1).getOffset();
} catch( EndOfFile eof )
{
throw eof;
}
finally
{
parsePassed = false;
}
} }
/** /**
* This is the standard cosntructor that we expect the Parser to be instantiated * This is the standard cosntructor that we expect the Parser to be instantiated

View file

@ -713,6 +713,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol); setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol);
List references = new ArrayList(); List references = new ArrayList();
setParameter( symbol, returnType, false, references );
setParameters( symbol, references, parameters.iterator() );
try try
{ {
ownerScope.addSymbol( symbol ); ownerScope.addSymbol( symbol );
@ -722,9 +726,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
throw new ASTSemanticException(); throw new ASTSemanticException();
} }
setParameter( symbol, returnType, false, references );
setParameters( symbol, references, parameters.iterator() );
ASTFunction function = new ASTFunction( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references ); ASTFunction function = new ASTFunction( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references );
try try
{ {
@ -901,6 +903,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
setMethodTypeInfoBits( symbol, isConst, isVolatile, isVirtual, isExplicit ); setMethodTypeInfoBits( symbol, isConst, isVolatile, isVirtual, isExplicit );
List references = new ArrayList(); List references = new ArrayList();
setParameter( symbol, returnType, false, references );
setParameters( symbol, references, parameters.iterator() );
try try
{ {
ownerScope.addSymbol( symbol ); ownerScope.addSymbol( symbol );
@ -910,8 +915,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
throw new ASTSemanticException(); throw new ASTSemanticException();
} }
setParameter( symbol, returnType, false, references );
setParameters( symbol, references, parameters.iterator() );
ASTMethod method = new ASTMethod( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, isConstructor, isDestructor, isPureVirtual, visibility ); ASTMethod method = new ASTMethod( symbol, parameters, returnType, exception, startOffset, nameOffset, ownerTemplate, references, isConstructor, isDestructor, isPureVirtual, visibility );
try try
@ -1006,19 +1010,26 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
newSymbol.getTypeInfo().setBit( isStatic, TypeInfo.isStatic ); newSymbol.getTypeInfo().setBit( isStatic, TypeInfo.isStatic );
newSymbol.getTypeInfo().setBit( abstractDeclaration.isConst(), TypeInfo.isConst ); newSymbol.getTypeInfo().setBit( abstractDeclaration.isConst(), TypeInfo.isConst );
} }
protected ISymbol cloneSimpleTypeSymbol( protected ISymbol cloneSimpleTypeSymbol(
String name, String name,
IASTAbstractDeclaration abstractDeclaration, IASTAbstractDeclaration abstractDeclaration,
List references) List references)
{ {
ISymbol newSymbol = null; ISymbol newSymbol = null;
ISymbol symbolToBeCloned = null;
if( abstractDeclaration.getTypeSpecifier() instanceof ASTSimpleTypeSpecifier ) if( abstractDeclaration.getTypeSpecifier() instanceof ASTSimpleTypeSpecifier )
{ {
ISymbol symbolToBeCloned = ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol(); symbolToBeCloned = ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol();
newSymbol = (ISymbol)symbolToBeCloned.clone();
newSymbol.setName( name );
references.addAll( ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getReferences() ); references.addAll( ((ASTSimpleTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getReferences() );
} }
else if( abstractDeclaration.getTypeSpecifier() instanceof ASTClassSpecifier )
{
symbolToBeCloned = ((ASTClassSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol();
}
newSymbol = (ISymbol) symbolToBeCloned.clone();
newSymbol.setName( name );
return newSymbol; return newSymbol;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -2485,10 +2485,13 @@ public class ParserSymbolTable {
return false; return false;
} }
int size = getParameterList().size(); int size = ( getParameterList() == null ) ? 0 : getParameterList().size();
if( function.getParameterList().size() != size ){ int fsize = ( function.getParameterList() == null ) ? 0 : function.getParameterList().size();
if( fsize != size ){
return false; return false;
} }
if( fsize == 0 )
return true;
Iterator iter = getParameterList().iterator(); Iterator iter = getParameterList().iterator();
Iterator fIter = function.getParameterList().iterator(); Iterator fIter = function.getParameterList().iterator();