Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Camelon2003-08-25 11:19:06 -0400
committerJohn Camelon2003-08-25 11:19:06 -0400
commit4f65c461c30a0599003d82ee1e0e9fd29d281edf (patch)
tree6ff3f3038c779e62d171f7e9d5228f9699ba341d
parentd6a7d069a1cb8c99f424803eeddf832c9cb12d8e (diff)
downloadorg.eclipse.cdt-4f65c461c30a0599003d82ee1e0e9fd29d281edf.tar.gz
org.eclipse.cdt-4f65c461c30a0599003d82ee1e0e9fd29d281edf.tar.xz
org.eclipse.cdt-4f65c461c30a0599003d82ee1e0e9fd29d281edf.zip
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
-rw-r--r--core/org.eclipse.cdt.core.tests/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/FailedTranslationUnitTests.java57
-rw-r--r--core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java17
-rw-r--r--core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java66
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java508
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java546
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java6
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java115
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SimpleDeclarationStrategy.java32
11 files changed, 664 insertions, 693 deletions
diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog
index 3dba66cec7b..7231d41a831 100644
--- a/core/org.eclipse.cdt.core.tests/ChangeLog
+++ b/core/org.eclipse.cdt.core.tests/ChangeLog
@@ -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
diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/FailedTranslationUnitTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/FailedTranslationUnitTests.java
deleted file mode 100644
index 658e0861e68..00000000000
--- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/model/failedTests/FailedTranslationUnitTests.java
+++ /dev/null
@@ -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");
- }
-
-
-}
diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java
index 6d394cc65b3..14f5d43b602 100644
--- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java
+++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java
@@ -39,14 +39,7 @@ public class ASTFailedTests extends BaseASTTest
}
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 @@ public class ASTFailedTests extends BaseASTTest
{
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 class ASTFailedTests extends BaseASTTest
}
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
{
diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java
deleted file mode 100644
index c56bddfe1a5..00000000000
--- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java
+++ /dev/null
@@ -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
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 3262a5cc067..f7e05d59452 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
@@ -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.IASTAbstractTypeSpecifierDeclaration;
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)
@@ -1000,4 +504,12 @@ public class CompleteParseASTTest extends TestCase
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() );
+ }
+
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java
new file mode 100644
index 00000000000..c84f2910352
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java
@@ -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();
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
index 39afa82a699..17c402c306c 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
@@ -1768,5 +1768,11 @@ public class QuickParseASTTests extends BaseASTTest
{
parse( "X sPassed(-1)");
}
+
+ public void testBug39526() throws Exception
+ {
+ parse("UnitList unit_list (String(\"keV\"));");
+ }
+
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
index d59fb10e29b..0a4d990ccdd 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
@@ -27,7 +27,6 @@ import org.eclipse.cdt.core.model.tests.BinaryTests;
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 @@ public class AutomatedIntegrationSuite extends TestSuite
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"));
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog
index 72fd45b0d55..216467a8205 100644
--- a/core/org.eclipse.cdt.core/parser/ChangeLog
+++ b/core/org.eclipse.cdt.core/parser/ChangeLog
@@ -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.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
index 3a448f13283..e28cf1a9a10 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
@@ -667,27 +667,47 @@ public class Parser implements IParser
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 @@ public class Parser implements IParser
* @throws Backtrack request a backtrack
*/
protected void simpleDeclaration(
- boolean tryConstructor,
+ SimpleDeclarationStrategy strategy,
boolean forKR,
IASTScope scope,
IASTTemplate ownerTemplate)
@@ -793,7 +813,7 @@ public class Parser implements IParser
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 @@ public class Parser implements IParser
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 @@ public class Parser implements IParser
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 @@ public class Parser implements IParser
* @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 @@ public class Parser implements IParser
* @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 @@ public class Parser implements IParser
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 @@ public class Parser implements IParser
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 @@ public class Parser implements IParser
do
{
simpleDeclaration(
- false,
+ null,
true,
sdw.getScope(),
sdw.getOwnerTemplate());
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SimpleDeclarationStrategy.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SimpleDeclarationStrategy.java
new file mode 100644
index 00000000000..2a0fef675bf
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SimpleDeclarationStrategy.java
@@ -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);
+ }
+}

Back to the top