[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Applied [HEAD] Initializer fixes
|
CORE
Fixed bug39526 - Parser doesn't handle initializers correctly.
Fixed bug41520 - FullParse : Constructor Initializer is mistaken
as function prototype
TESTS
Moved testBug39526() from ASTFailedTests.java to
QuickParseASTTests.java.
Moved testBug41520() from FullParseFailedTests.java to
CompleteParseASTTest.java
JohnC
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.67
diff -u -r1.67 ChangeLog
--- ChangeLog 25 Aug 2003 14:13:26 -0000 1.67
+++ ChangeLog 25 Aug 2003 15:08:52 -0000
@@ -1,4 +1,8 @@
2003-08-25 John Camelon
+ Moved testBug39526() from ASTFailedTests.java to QuickParseASTTests.java.
+ Moved testBug41520() from FullParseFailedTests.java to CompleteParseASTTest.java
+
+2003-08-25 John Camelon
Updated TranslationUnitTests to not include K&R testing.
2003-08-25 John Camelon
Index: failures/org/eclipse/cdt/core/model/failedTests/FailedTranslationUnitTests.java
===================================================================
RCS file: failures/org/eclipse/cdt/core/model/failedTests/FailedTranslationUnitTests.java
diff -N failures/org/eclipse/cdt/core/model/failedTests/FailedTranslationUnitTests.java
--- failures/org/eclipse/cdt/core/model/failedTests/FailedTranslationUnitTests.java 12 Aug 2003 18:19:50 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,57 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM Rational Software - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.model.failedTests;
-
-import org.eclipse.cdt.core.model.CModelException;
-import org.eclipse.cdt.core.model.IFunction;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.core.model.tests.TranslationUnitBaseTest;
-import org.eclipse.cdt.testplugin.CProjectHelper;
-
-/**
- * @author jcamelon
- *
- */
-public class FailedTranslationUnitTests extends TranslationUnitBaseTest
-{
- /**
- *
- */
- public FailedTranslationUnitTests()
- {
- super();
- // TODO Auto-generated constructor stub
- }
- /**
- * @param name
- */
- public FailedTranslationUnitTests(String name)
- {
- super(name);
- // TODO Auto-generated constructor stub
- }
-
- /***
- * Simple sanity test for old K&R-style C function declaration
- */
- public void testKRFunctionDeclarations() throws CModelException
- {
- ITranslationUnit myTranslationUnit = CProjectHelper.findTranslationUnit(testProject,"exetest.c");
-
- assertTrue(myTranslationUnit.getElement("KRFunction") instanceof IFunction);
- IFunction myKRFunction = (IFunction)myTranslationUnit.getElement("KRFunction");
- // reverse both these assertions to pass the test
- assertNotSame(myKRFunction.getSignature(), "KRFunction(const char*, int(*)(float), parm3)");
- assertNotSame(myKRFunction.getReturnType(), "bool");
- }
-
-
-}
Index: failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java,v
retrieving revision 1.9
diff -u -r1.9 ASTFailedTests.java
--- failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java 12 Aug 2003 18:19:55 -0000 1.9
+++ failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java 25 Aug 2003 15:08:52 -0000
@@ -39,14 +39,7 @@
}
public void testBug39504A() throws Exception
{
- try
- {
- IASTVariable variable = (IASTVariable)parse("int y = sizeof(x[0]);").getDeclarations().next();
- }
- catch( ClassCastException cce )
- {
- assertFalse( "We should not get a cast error here", false );
- }
+ assertCodeFailsParse("int y = sizeof(x[0]);");
}
public void testBug39504B() throws Exception
{
@@ -65,10 +58,7 @@
{
assertCodeFailsParse("C &(C::*DD)(const C &x) = &C::operator=;");
}
- public void testBug39526() throws Exception
- {
- assertCodeFailsParse("UnitList unit_list (String(\"keV\"));");
- }
+
public void testBug39528() throws Exception
{
Writer code = new StringWriter();
@@ -254,8 +244,7 @@
}
public void testBug39698A() throws Exception
{
- Iterator declarations = parse("int c = a <? b;").getDeclarations();
- assertFalse( "Should be 1 declaration, not 0", declarations.hasNext() );
+ assertCodeFailsParse("int c = a <? b;");
}
public void testBug39698B() throws Exception
{
Index: failures/org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java
===================================================================
RCS file: failures/org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java
diff -N failures/org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java
--- failures/org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java 13 Aug 2003 23:54:09 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM Corp. - Rational Software - initial implementation
- ******************************************************************************/
-/*
- * Created on Jul 28, 2003
- */
-package org.eclipse.cdt.core.parser.failedTests;
-
-import java.util.Iterator;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.cdt.core.parser.ast.IASTVariable;
-import org.eclipse.cdt.core.parser.tests.CompleteParseASTTest;
-
-/**
- * @author aniefer
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class FullParseFailedTests extends CompleteParseASTTest {
-
- /**
- * @param a
- */
- public FullParseFailedTests(String name) {
- super(name);
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(FullParseFailedTests.class.getName());
- return suite;
- }
-
- public void testBug41520() throws Exception
- {
- Iterator i = parse( "int x = 666; int y ( x );").getDeclarations();
- IASTVariable variableX = (IASTVariable)i.next();
- try
- {
- IASTVariable variableY = (IASTVariable)i.next();
- failedAsExpected();
- }catch( ClassCastException cce )
- {
- //this is bad
- }
- }
-
- /**
- *
- */
- private void failedAsExpected()
- {
- }
-
-
-}
\ No newline at end of file
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java,v
retrieving revision 1.15
diff -u -r1.15 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 20 Aug 2003 18:05:19 -0000 1.15
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 25 Aug 2003 15:08:52 -0000
@@ -10,22 +10,10 @@
***********************************************************************/
package org.eclipse.cdt.core.parser.tests;
-import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Hashtable;
import java.util.Iterator;
-import java.util.List;
-import java.util.Stack;
-import junit.framework.TestCase;
-
-import org.eclipse.cdt.core.parser.IParser;
-import org.eclipse.cdt.core.parser.IProblem;
-import org.eclipse.cdt.core.parser.ISourceElementRequestor;
-import org.eclipse.cdt.core.parser.ParserFactory;
-import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
@@ -33,516 +21,32 @@
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
-import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTFieldReference;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
-import org.eclipse.cdt.core.parser.ast.IASTFunctionReference;
-import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
-import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.ast.IASTMethod;
-import org.eclipse.cdt.core.parser.ast.IASTMethodReference;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
-import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
import org.eclipse.cdt.core.parser.ast.IASTReference;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
-import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
-import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
-import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
-import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
-import org.eclipse.cdt.internal.core.parser.ParserException;
-import org.eclipse.cdt.internal.core.parser.ScannerInfo;
/**
* @author jcamelon
*
*/
-public class CompleteParseASTTest extends TestCase
+public class CompleteParseASTTest extends CompleteParseBaseTest
{
- public class Scope implements IASTScope
- {
- private List decls = new ArrayList();
- private final IASTScope scope;
- public Scope( IASTScope scope )
- {
- this.scope = scope;
- }
-
- public void addDeclaration( IASTDeclaration d )
- {
- decls.add(d);
- }
-
- public Iterator getDeclarations()
- {
- return decls.iterator();
- }
-
- /**
- * @return
- */
- public IASTScope getScope()
- {
-
- return scope;
- }
- }
-
- public class FullParseCallback implements ISourceElementRequestor
- {
- private List references = new ArrayList();
- private List forewardDecls = new ArrayList();
- private Stack inclusions = new Stack();
- private Scope compilationUnit;
-
- public IASTScope getCompilationUnit()
- {
- return compilationUnit;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable)
- */
- public void acceptVariable(IASTVariable variable)
- {
- getCurrentScope().addDeclaration( variable );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction)
- */
- public void acceptFunctionDeclaration(IASTFunction function)
- {
- getCurrentScope().addDeclaration(function);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective)
- */
- public void acceptUsingDirective(IASTUsingDirective usageDirective)
- {
- getCurrentScope().addDeclaration(usageDirective);
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration)
- */
- public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration)
- {
- getCurrentScope().addDeclaration(usageDeclaration);
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition)
- */
- public void acceptASMDefinition(IASTASMDefinition asmDefinition)
- {
- getCurrentScope().addDeclaration(asmDefinition);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefDeclaration(org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration)
- */
- public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef)
- {
- getCurrentScope().addDeclaration(typedef);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier)
- */
- public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration)
- {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration)
- */
- public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration)
- {
- getCurrentScope().addDeclaration( abstractDeclaration );
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
- */
- public void enterFunctionBody(IASTFunction function)
- {
- pushScope( function );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
- */
- public void exitFunctionBody(IASTFunction function)
- {
- popScope();
- getCurrentScope().addDeclaration(function);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
- */
- public void enterCompilationUnit(IASTCompilationUnit compilationUnit)
- {
- pushScope( compilationUnit );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
- */
- public void enterInclusion(IASTInclusion inclusion)
- {
- pushInclusion( inclusion );
- }
-
- /**
- * @param inclusion
- */
- private void pushInclusion(IASTInclusion inclusion)
- {
- inclusions.push( inclusion );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
- */
- public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition)
- {
- pushScope( namespaceDefinition );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#entesrClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
- */
- public void enterClassSpecifier(IASTClassSpecifier classSpecification)
- {
- pushScope( classSpecification );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
- */
- public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec)
- {
- pushScope( linkageSpec );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
- */
- public void enterTemplateDeclaration(IASTTemplateDeclaration declaration)
- {
- // TODO Auto-generated method stub
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization)
- */
- public void enterTemplateSpecialization(IASTTemplateSpecialization specialization)
- {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation)
- */
- public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation)
- {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod)
- */
- public void acceptMethodDeclaration(IASTMethod method)
- {
- getCurrentScope().addDeclaration( method );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
- */
- public void enterMethodBody(IASTMethod method)
- {
- pushScope(method);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
- */
- public void exitMethodBody(IASTMethod method)
- {
- popScope();
- getCurrentScope().addDeclaration(method);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField)
- */
- public void acceptField(IASTField field)
- {
- getCurrentScope().addDeclaration(field);
-
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
- */
- public void exitTemplateDeclaration(IASTTemplateDeclaration declaration)
- {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization)
- */
- public void exitTemplateSpecialization(IASTTemplateSpecialization specialization)
- {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation)
- */
- public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation)
- {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
- */
- public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec)
- {
- popScope();
- getCurrentScope().addDeclaration(linkageSpec);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
- */
- public void exitClassSpecifier(IASTClassSpecifier classSpecification)
- {
- popScope();
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
- */
- public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition)
- {
- popScope();
- getCurrentScope().addDeclaration(namespaceDefinition);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
- */
- public void exitInclusion(IASTInclusion inclusion)
- {
- popInclusion();
- }
-
- /**
- *
- */
- private void popInclusion()
- {
- inclusions.pop();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
- */
- public void exitCompilationUnit(IASTCompilationUnit compilationUnit)
- {
- this.compilationUnit = popScope();
- }
-
-
-
- private Stack scopes = new Stack();
- protected Scope getCurrentScope()
- {
- return (Scope)scopes.peek();
- }
-
- protected Scope popScope()
- {
- Scope s = (Scope)scopes.pop();
- h.put( s.getScope(), s );
- return s;
- }
-
- protected void pushScope( IASTScope scope )
- {
- scopes.push( new Scope( scope ));
- }
-
- Hashtable h = new Hashtable();
-
- public Scope lookup( IASTScope s)
- {
- return (Scope)h.get(s);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
- */
- public void acceptProblem(IProblem problem)
- {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro)
- */
- public void acceptMacro(IASTMacro macro)
- {
- // TODO Auto-generated method stub
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassReference)
- */
- public void acceptClassReference(IASTClassReference reference)
- {
- references.add( reference );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefReference(org.eclipse.cdt.core.parser.ast.IASTTypedefReference)
- */
- public void acceptTypedefReference(IASTTypedefReference reference)
- {
- references.add( reference );
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptNamespaceReference(org.eclipse.cdt.core.parser.ast.IASTNamespaceReference)
- */
- public void acceptNamespaceReference(IASTNamespaceReference reference)
- {
- references.add( reference );
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference)
- */
- public void acceptEnumerationReference(IASTEnumerationReference reference)
- {
- references.add( reference );
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariableReference(org.eclipse.cdt.core.parser.ast.IASTVariableReference)
- */
- public void acceptVariableReference(IASTVariableReference reference)
- {
- references.add( reference );
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionReference(org.eclipse.cdt.core.parser.ast.IASTFunctionReference)
- */
- public void acceptFunctionReference(IASTFunctionReference reference)
- {
- references.add( reference );
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFieldReference(org.eclipse.cdt.core.parser.ast.IASTFieldReference)
- */
- public void acceptFieldReference(IASTFieldReference reference)
- {
- references.add( reference );
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodReference(org.eclipse.cdt.core.parser.ast.IASTMethodReference)
- */
- public void acceptMethodReference(IASTMethodReference reference)
- {
- references.add( reference );
-
- }
-
- public List getReferences()
- {
- return references;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
- */
- public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType)
- {
- forewardDecls.add( elaboratedType );
- }
- /**
- * @return
- */
- public List getForewardDecls()
- {
- return forewardDecls;
- }
-
- }
-
- protected Iterator getDeclarations( IASTScope scope )
- {
- Scope s = callback.lookup( scope );
- if( s != null )
- return s.getDeclarations();
- return null;
- }
-
-
- protected FullParseCallback callback;
-
- protected IASTScope parse( String code )throws ParserException
- {
- callback = new FullParseCallback();
- IParser parser = ParserFactory.createParser(
- ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(),
- ParserMode.COMPLETE_PARSE, callback ), callback, ParserMode.COMPLETE_PARSE
- );
- if( ! parser.parse() ) throw new ParserException( "FAILURE");
- return callback.getCompilationUnit();
- }
-
- /**
+ /**
* @param a
*/
public CompleteParseASTTest(String a)
@@ -998,6 +502,14 @@
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableC );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableD );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableA );
+ }
+
+ public void testBug41520() throws Exception
+ {
+ Iterator i = parse( "const int x = 666, y( x );").getDeclarations();
+ IASTVariable variableX = (IASTVariable)i.next();
+ IASTVariable variableY = (IASTVariable)i.next();
+ assertFalse( i.hasNext() );
}
}
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java
diff -N parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java 25 Aug 2003 15:08:52 -0000
@@ -0,0 +1,546 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.core.parser.tests;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Stack;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.core.parser.ISourceElementRequestor;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
+import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
+import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTClassReference;
+import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
+import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference;
+import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTField;
+import org.eclipse.cdt.core.parser.ast.IASTFieldReference;
+import org.eclipse.cdt.core.parser.ast.IASTFunction;
+import org.eclipse.cdt.core.parser.ast.IASTFunctionReference;
+import org.eclipse.cdt.core.parser.ast.IASTInclusion;
+import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
+import org.eclipse.cdt.core.parser.ast.IASTMacro;
+import org.eclipse.cdt.core.parser.ast.IASTMethod;
+import org.eclipse.cdt.core.parser.ast.IASTMethodReference;
+import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
+import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
+import org.eclipse.cdt.core.parser.ast.IASTScope;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
+import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
+import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
+import org.eclipse.cdt.core.parser.ast.IASTVariable;
+import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+import org.eclipse.cdt.internal.core.parser.ScannerInfo;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class CompleteParseBaseTest extends TestCase
+{
+ /**
+ *
+ */
+ public CompleteParseBaseTest()
+ {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+ /**
+ * @param name
+ */
+ public CompleteParseBaseTest(String name)
+ {
+ super(name);
+ // TODO Auto-generated constructor stub
+ }
+ public static class Scope implements IASTScope
+ {
+ private List decls = new ArrayList();
+ private final IASTScope scope;
+ public Scope( IASTScope scope )
+ {
+ this.scope = scope;
+ }
+
+ public void addDeclaration( IASTDeclaration d )
+ {
+ decls.add(d);
+ }
+
+ public Iterator getDeclarations()
+ {
+ return decls.iterator();
+ }
+
+ /**
+ * @return
+ */
+ public IASTScope getScope()
+ {
+
+ return scope;
+ }
+ }
+ public static class FullParseCallback implements ISourceElementRequestor
+ {
+ private List references = new ArrayList();
+ private List forewardDecls = new ArrayList();
+ private Stack inclusions = new Stack();
+ private Scope compilationUnit;
+
+ public IASTScope getCompilationUnit()
+ {
+ return compilationUnit;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable)
+ */
+ public void acceptVariable(IASTVariable variable)
+ {
+ getCurrentScope().addDeclaration( variable );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction)
+ */
+ public void acceptFunctionDeclaration(IASTFunction function)
+ {
+ getCurrentScope().addDeclaration(function);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective)
+ */
+ public void acceptUsingDirective(IASTUsingDirective usageDirective)
+ {
+ getCurrentScope().addDeclaration(usageDirective);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration)
+ */
+ public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration)
+ {
+ getCurrentScope().addDeclaration(usageDeclaration);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition)
+ */
+ public void acceptASMDefinition(IASTASMDefinition asmDefinition)
+ {
+ getCurrentScope().addDeclaration(asmDefinition);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefDeclaration(org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration)
+ */
+ public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef)
+ {
+ getCurrentScope().addDeclaration(typedef);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier)
+ */
+ public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration)
+ */
+ public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration)
+ {
+ getCurrentScope().addDeclaration( abstractDeclaration );
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
+ */
+ public void enterFunctionBody(IASTFunction function)
+ {
+ pushScope( function );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
+ */
+ public void exitFunctionBody(IASTFunction function)
+ {
+ popScope();
+ getCurrentScope().addDeclaration(function);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
+ */
+ public void enterCompilationUnit(IASTCompilationUnit compilationUnit)
+ {
+ pushScope( compilationUnit );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
+ */
+ public void enterInclusion(IASTInclusion inclusion)
+ {
+ pushInclusion( inclusion );
+ }
+
+ /**
+ * @param inclusion
+ */
+ private void pushInclusion(IASTInclusion inclusion)
+ {
+ inclusions.push( inclusion );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
+ */
+ public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition)
+ {
+ pushScope( namespaceDefinition );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#entesrClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
+ */
+ public void enterClassSpecifier(IASTClassSpecifier classSpecification)
+ {
+ pushScope( classSpecification );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
+ */
+ public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec)
+ {
+ pushScope( linkageSpec );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
+ */
+ public void enterTemplateDeclaration(IASTTemplateDeclaration declaration)
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization)
+ */
+ public void enterTemplateSpecialization(IASTTemplateSpecialization specialization)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation)
+ */
+ public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod)
+ */
+ public void acceptMethodDeclaration(IASTMethod method)
+ {
+ getCurrentScope().addDeclaration( method );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
+ */
+ public void enterMethodBody(IASTMethod method)
+ {
+ pushScope(method);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
+ */
+ public void exitMethodBody(IASTMethod method)
+ {
+ popScope();
+ getCurrentScope().addDeclaration(method);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField)
+ */
+ public void acceptField(IASTField field)
+ {
+ getCurrentScope().addDeclaration(field);
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
+ */
+ public void exitTemplateDeclaration(IASTTemplateDeclaration declaration)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization)
+ */
+ public void exitTemplateSpecialization(IASTTemplateSpecialization specialization)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation)
+ */
+ public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
+ */
+ public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec)
+ {
+ popScope();
+ getCurrentScope().addDeclaration(linkageSpec);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
+ */
+ public void exitClassSpecifier(IASTClassSpecifier classSpecification)
+ {
+ popScope();
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
+ */
+ public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition)
+ {
+ popScope();
+ getCurrentScope().addDeclaration(namespaceDefinition);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
+ */
+ public void exitInclusion(IASTInclusion inclusion)
+ {
+ popInclusion();
+ }
+
+ /**
+ *
+ */
+ private void popInclusion()
+ {
+ inclusions.pop();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
+ */
+ public void exitCompilationUnit(IASTCompilationUnit compilationUnit)
+ {
+ this.compilationUnit = popScope();
+ }
+
+
+
+ private Stack scopes = new Stack();
+ protected Scope getCurrentScope()
+ {
+ return (Scope)scopes.peek();
+ }
+
+ protected Scope popScope()
+ {
+ Scope s = (Scope)scopes.pop();
+ h.put( s.getScope(), s );
+ return s;
+ }
+
+ protected void pushScope( IASTScope scope )
+ {
+ scopes.push( new Scope( scope ));
+ }
+
+ Hashtable h = new Hashtable();
+
+ public Scope lookup( IASTScope s)
+ {
+ return (Scope)h.get(s);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
+ */
+ public void acceptProblem(IProblem problem)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro)
+ */
+ public void acceptMacro(IASTMacro macro)
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassReference)
+ */
+ public void acceptClassReference(IASTClassReference reference)
+ {
+ references.add( reference );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefReference(org.eclipse.cdt.core.parser.ast.IASTTypedefReference)
+ */
+ public void acceptTypedefReference(IASTTypedefReference reference)
+ {
+ references.add( reference );
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptNamespaceReference(org.eclipse.cdt.core.parser.ast.IASTNamespaceReference)
+ */
+ public void acceptNamespaceReference(IASTNamespaceReference reference)
+ {
+ references.add( reference );
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference)
+ */
+ public void acceptEnumerationReference(IASTEnumerationReference reference)
+ {
+ references.add( reference );
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariableReference(org.eclipse.cdt.core.parser.ast.IASTVariableReference)
+ */
+ public void acceptVariableReference(IASTVariableReference reference)
+ {
+ references.add( reference );
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionReference(org.eclipse.cdt.core.parser.ast.IASTFunctionReference)
+ */
+ public void acceptFunctionReference(IASTFunctionReference reference)
+ {
+ references.add( reference );
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFieldReference(org.eclipse.cdt.core.parser.ast.IASTFieldReference)
+ */
+ public void acceptFieldReference(IASTFieldReference reference)
+ {
+ references.add( reference );
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodReference(org.eclipse.cdt.core.parser.ast.IASTMethodReference)
+ */
+ public void acceptMethodReference(IASTMethodReference reference)
+ {
+ references.add( reference );
+
+ }
+
+ public List getReferences()
+ {
+ return references;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
+ */
+ public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType)
+ {
+ forewardDecls.add( elaboratedType );
+ }
+ /**
+ * @return
+ */
+ public List getForewardDecls()
+ {
+ return forewardDecls;
+ }
+
+ }
+ protected Iterator getDeclarations(IASTScope scope)
+ {
+ Scope s = callback.lookup( scope );
+ if( s != null )
+ return s.getDeclarations();
+ return null;
+ }
+ protected FullParseCallback callback;
+ protected IASTScope parse(String code) throws ParserException
+ {
+ callback = new FullParseCallback();
+ IParser parser = ParserFactory.createParser(
+ ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(),
+ ParserMode.COMPLETE_PARSE, callback ), callback, ParserMode.COMPLETE_PARSE
+ );
+ if( ! parser.parse() ) throw new ParserException( "FAILURE");
+ return callback.getCompilationUnit();
+ }
+}
Index: parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java,v
retrieving revision 1.13
diff -u -r1.13 QuickParseASTTests.java
--- parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java 25 Aug 2003 12:19:43 -0000 1.13
+++ parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java 25 Aug 2003 15:08:53 -0000
@@ -1768,5 +1768,11 @@
{
parse( "X sPassed(-1)");
}
+
+ public void testBug39526() throws Exception
+ {
+ parse("UnitList unit_list (String(\"keV\"));");
+ }
+
}
Index: suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java,v
retrieving revision 1.14
diff -u -r1.14 AutomatedIntegrationSuite.java
--- suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java 14 Aug 2003 19:49:48 -0000 1.14
+++ suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java 25 Aug 2003 15:08:54 -0000
@@ -27,7 +27,6 @@
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests;
-import org.eclipse.cdt.core.parser.failedTests.FullParseFailedTests;
import org.eclipse.cdt.core.parser.failedTests.LokiFailures;
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
@@ -103,7 +102,6 @@
suite.addTestSuite(LokiFailures.class);
suite.addTestSuite(STLFailedTests.class);
suite.addTestSuite(CModelElementsFailedTests.class);
- suite.addTest(FullParseFailedTests.suite());
// Last test to trigger report generation
suite.addTest(suite.new GenerateReport("generateReport"));
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.103
diff -u -r1.103 ChangeLog
--- parser/ChangeLog 25 Aug 2003 12:19:38 -0000 1.103
+++ parser/ChangeLog 25 Aug 2003 15:07:26 -0000
@@ -1,4 +1,8 @@
2003-08-25 John Camelon
+ Fixed bug39526 - Parser doesn't handle initializers correctly.
+ Fixed bug41520 - FullParse : Constructor Initializer is mistaken as function prototype
+
+2003-08-25 John Camelon
Fixed Bug 39530 - More problems with initializers.
Fixed Bug 37424 - Crash when opening big files
Refactored pointerOperators & cvQualifiers to not throw backtracks in optional case.
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.95
diff -u -r1.95 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java 25 Aug 2003 12:23:13 -0000 1.95
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java 25 Aug 2003 15:07:31 -0000
@@ -667,27 +667,47 @@
return;
}
default :
- IToken mark = mark();
- try
- {
- simpleDeclaration(
- true,
- false,
- scope,
- ownerTemplate);
- // try it first with the original strategy
- }
- catch (Backtrack bt)
- {
- // did not work
- backup(mark);
- simpleDeclaration(
- false,
- false,
- scope,
- ownerTemplate);
- // try it again with the second strategy
- }
+ simpleDeclarationStrategyUnion(scope, ownerTemplate);
+ }
+ }
+ protected void simpleDeclarationStrategyUnion(
+ IASTScope scope,
+ IASTTemplate ownerTemplate)
+ throws EndOfFile, Backtrack
+ {
+ IToken mark = mark();
+ try
+ {
+ simpleDeclaration(
+ SimpleDeclarationStrategy.TRY_CONSTRUCTOR,
+ false,
+ scope,
+ ownerTemplate);
+ // try it first with the original strategy
+ }
+ catch (Backtrack bt)
+ {
+ // did not work
+ backup(mark);
+
+ try
+ {
+ simpleDeclaration(
+ SimpleDeclarationStrategy.TRY_FUNCTION,
+ false,
+ scope,
+ ownerTemplate);
+ }
+ catch( Backtrack bt2 )
+ {
+ backup( mark );
+
+ simpleDeclaration(
+ SimpleDeclarationStrategy.TRY_VARIABLE,
+ false,
+ scope,
+ ownerTemplate);
+ }
}
}
/**
@@ -784,7 +804,7 @@
* @throws Backtrack request a backtrack
*/
protected void simpleDeclaration(
- boolean tryConstructor,
+ SimpleDeclarationStrategy strategy,
boolean forKR,
IASTScope scope,
IASTTemplate ownerTemplate)
@@ -793,7 +813,7 @@
DeclarationWrapper sdw =
new DeclarationWrapper(scope, LA(1).getOffset(), ownerTemplate);
- declSpecifierSeq(false, tryConstructor, sdw, forKR );
+ declSpecifierSeq(false, strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR, sdw, forKR );
try
{
if (sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED )
@@ -814,27 +834,17 @@
Declarator declarator = null;
if (LT(1) != IToken.tSEMI)
- try
- {
- declarator = initDeclarator(sdw, forKR);
+ {
+ declarator = initDeclarator(sdw, forKR, strategy);
- while (LT(1) == IToken.tCOMMA)
- {
- consume();
- try
- {
- initDeclarator(sdw, forKR);
- }
- catch (Backtrack b)
- {
- throw b;
- }
- }
- }
- catch (Backtrack b)
+ while (LT(1) == IToken.tCOMMA)
{
- // allowed to be empty
+ consume();
+ initDeclarator(sdw, forKR, strategy);
}
+ }
+
+
boolean done = false;
boolean hasFunctionBody = false;
switch (LT(1))
@@ -1027,19 +1037,12 @@
sdw.isUnsigned(), sdw.isTypeNamed()));
}
catch( ASTSemanticException se ) {
- failParse();
throw backtrack;
}
if (LT(1) != IToken.tSEMI)
- try
- {
- initDeclarator(sdw, false);
- }
- catch (Backtrack b)
- {
- // allowed to be empty
- }
+ initDeclarator(sdw, false, SimpleDeclarationStrategy.TRY_FUNCTION );
+
if (current == LA(1))
throw backtrack;
collection.addParameter(sdw);
@@ -1713,10 +1716,10 @@
* @throws Backtrack request a backtrack
*/
protected Declarator initDeclarator(
- DeclarationWrapper sdw, boolean forKR )
+ DeclarationWrapper sdw, boolean forKR, SimpleDeclarationStrategy strategy )
throws Backtrack
{
- Declarator d = declarator(sdw, sdw.getScope(), forKR );
+ Declarator d = declarator(sdw, sdw.getScope(), forKR, strategy );
// handle = initializerClause
if (LT(1) == IToken.tASSIGN)
{
@@ -1811,7 +1814,7 @@
* @throws Backtrack request a backtrack
*/
protected Declarator declarator(
- IDeclaratorOwner owner, IASTScope scope, boolean forKR )
+ IDeclaratorOwner owner, IASTScope scope, boolean forKR, SimpleDeclarationStrategy strategy )
throws Backtrack
{
Declarator d = null;
@@ -1825,7 +1828,7 @@
if (LT(1) == IToken.tLPAREN)
{
consume();
- declarator(d, scope, forKR);
+ declarator(d, scope, forKR, strategy );
consume(IToken.tRPAREN);
}
else if (LT(1) == IToken.t_operator)
@@ -1875,7 +1878,7 @@
throw backtrack;
// temporary fix for initializer/function declaration ambiguity
- if (!LA(2).looksLikeExpression() )
+ if (!LA(2).looksLikeExpression() && strategy != SimpleDeclarationStrategy.TRY_VARIABLE )
{
// parameterDeclarationClause
d.setIsFunction(true);
@@ -2018,7 +2021,7 @@
do
{
simpleDeclaration(
- false,
+ null,
true,
sdw.getScope(),
sdw.getOwnerTemplate());
Index: parser/org/eclipse/cdt/internal/core/parser/SimpleDeclarationStrategy.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/SimpleDeclarationStrategy.java
diff -N parser/org/eclipse/cdt/internal/core/parser/SimpleDeclarationStrategy.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/SimpleDeclarationStrategy.java 25 Aug 2003 15:07:31 -0000
@@ -0,0 +1,32 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+import org.eclipse.cdt.core.parser.Enum;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class SimpleDeclarationStrategy extends Enum
+{
+ public static final SimpleDeclarationStrategy TRY_CONSTRUCTOR = new SimpleDeclarationStrategy( 1 );
+ public static final SimpleDeclarationStrategy TRY_FUNCTION = new SimpleDeclarationStrategy( 2 );
+ public static final SimpleDeclarationStrategy TRY_VARIABLE = new SimpleDeclarationStrategy( 3 );
+
+ /**
+ * @param enumValue
+ */
+ public SimpleDeclarationStrategy(int enumValue)
+ {
+ super(enumValue);
+ }
+}