mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
- fix bug 60149 - External Linkage is not recognized by the parser in Structural mode
- create StructureParseTest and add it to ParserTestSuite
This commit is contained in:
parent
a0578a62c3
commit
2d3fadb88c
4 changed files with 115 additions and 3 deletions
|
@ -44,6 +44,7 @@ public class ParserTestSuite extends TestCase {
|
||||||
suite.addTestSuite( CompleteParseASTExpressionTest.class );
|
suite.addTestSuite( CompleteParseASTExpressionTest.class );
|
||||||
suite.addTestSuite( CompleteParseASTSymbolIteratorTest.class );
|
suite.addTestSuite( CompleteParseASTSymbolIteratorTest.class );
|
||||||
suite.addTestSuite( CompleteParseASTTemplateTest.class );
|
suite.addTestSuite( CompleteParseASTTemplateTest.class );
|
||||||
|
suite.addTestSuite( StructuralParseTest.class );
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2004 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 Apr 29, 2004
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.core.parser.tests;
|
||||||
|
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.IParser;
|
||||||
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author aniefer
|
||||||
|
*/
|
||||||
|
public class StructuralParseTest extends TestCase {
|
||||||
|
|
||||||
|
public StructuralParseTest()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected StructuralParseCallback callback;
|
||||||
|
|
||||||
|
protected IASTCompilationUnit parse( String code ) throws ParserException, ParserFactoryError
|
||||||
|
{
|
||||||
|
return parse( code, true, ParserLanguage.CPP );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IASTCompilationUnit parse( String code, boolean throwOnError ) throws ParserException, ParserFactoryError
|
||||||
|
{
|
||||||
|
return parse( code, throwOnError, ParserLanguage.CPP );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IASTCompilationUnit parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError
|
||||||
|
{
|
||||||
|
callback = new StructuralParseCallback();
|
||||||
|
IParser parser = ParserFactory.createParser(
|
||||||
|
ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(),
|
||||||
|
ParserMode.STRUCTURAL_PARSE, language, callback, new NullLogService(), null ),
|
||||||
|
callback, ParserMode.STRUCTURAL_PARSE, language, null
|
||||||
|
);
|
||||||
|
if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE");
|
||||||
|
return callback.getCompilationUnit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug60149() throws Exception
|
||||||
|
{
|
||||||
|
IASTCompilationUnit cu = parse( "extern \"C\" { int v; } " );
|
||||||
|
|
||||||
|
Iterator i = cu.getDeclarations();
|
||||||
|
|
||||||
|
IASTLinkageSpecification ls = (IASTLinkageSpecification) i.next();
|
||||||
|
assertFalse( i.hasNext() );
|
||||||
|
|
||||||
|
i = ls.getDeclarations();
|
||||||
|
IASTVariable v = (IASTVariable) i.next();
|
||||||
|
assertEquals( v.getName(), "v" );
|
||||||
|
assertFalse( i.hasNext() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBug60480() throws Exception
|
||||||
|
{
|
||||||
|
IASTCompilationUnit cu = parse( "template < int > void foo();" );
|
||||||
|
Iterator i = cu.getDeclarations();
|
||||||
|
|
||||||
|
IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next();
|
||||||
|
assertFalse( i.hasNext() );
|
||||||
|
|
||||||
|
IASTFunction foo = (IASTFunction) template.getOwnedDeclaration();
|
||||||
|
assertEquals( foo.getName(), "foo" );
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||||
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTLinkageSpecification;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTScope;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTScope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,8 +47,12 @@ public class StructuralParseCallback extends QuickParseCallback{
|
||||||
|
|
||||||
|
|
||||||
private void addElement (IASTDeclaration element){
|
private void addElement (IASTDeclaration element){
|
||||||
if(inclusionLevel == 0)
|
if(inclusionLevel == 0){
|
||||||
|
if( currentScope instanceof ASTScope )
|
||||||
((ASTScope)currentScope).addDeclaration(element);
|
((ASTScope)currentScope).addDeclaration(element);
|
||||||
|
else if( currentScope instanceof ASTLinkageSpecification )
|
||||||
|
((ASTLinkageSpecification)currentScope).addDeclaration( element );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enterScope(IASTNode node){
|
private void enterScope(IASTNode node){
|
||||||
|
@ -158,6 +163,7 @@ public class StructuralParseCallback extends QuickParseCallback{
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
|
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
|
||||||
*/
|
*/
|
||||||
public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) {
|
public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) {
|
||||||
|
addElement(linkageSpec);
|
||||||
enterScope(linkageSpec);
|
enterScope(linkageSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,13 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.ast.complete;
|
package org.eclipse.cdt.internal.core.parser.ast.complete;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.Offsets;
|
import org.eclipse.cdt.internal.core.parser.ast.Offsets;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
||||||
|
@ -24,6 +27,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
||||||
*/
|
*/
|
||||||
public class ASTLinkageSpecification extends ASTAnonymousDeclaration implements IASTLinkageSpecification
|
public class ASTLinkageSpecification extends ASTAnonymousDeclaration implements IASTLinkageSpecification
|
||||||
{
|
{
|
||||||
|
private List declarations = new ArrayList();
|
||||||
private final String linkageString;
|
private final String linkageString;
|
||||||
private Offsets offsets = new Offsets();
|
private Offsets offsets = new Offsets();
|
||||||
/**
|
/**
|
||||||
|
@ -47,7 +51,7 @@ public class ASTLinkageSpecification extends ASTAnonymousDeclaration implements
|
||||||
*/
|
*/
|
||||||
public Iterator getDeclarations() throws ASTNotImplementedException
|
public Iterator getDeclarations() throws ASTNotImplementedException
|
||||||
{
|
{
|
||||||
throw new ASTNotImplementedException();
|
return declarations.iterator();
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int)
|
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int)
|
||||||
|
@ -126,5 +130,10 @@ public class ASTLinkageSpecification extends ASTAnonymousDeclaration implements
|
||||||
public int getEndingLine() {
|
public int getEndingLine() {
|
||||||
return offsets.getEndingLine();
|
return offsets.getEndingLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addDeclaration(IASTDeclaration declaration)
|
||||||
|
{
|
||||||
|
declarations.add(declaration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue