mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
CORE
Fixed bug39535 - Parser fails on namesapce aliases TESTS Moved bug39535 from failedTests to quickParse success tests.
This commit is contained in:
parent
2e52ac872d
commit
cb951980f4
11 changed files with 386 additions and 5 deletions
|
@ -1,3 +1,6 @@
|
|||
2003-08-28 John Camelon
|
||||
Moved bug39535 from failedTests to quickParse success tests.
|
||||
|
||||
2003-08-25 John Camelon
|
||||
Moved testBug39526() from ASTFailedTests.java to QuickParseASTTests.java.
|
||||
Moved testBug41520() from FullParseFailedTests.java to CompleteParseASTTest.java
|
||||
|
|
|
@ -81,10 +81,7 @@ public class ASTFailedTests extends BaseASTTest
|
|||
{
|
||||
assertCodeFailsParse("class AString { operator char const *() const; };");
|
||||
}
|
||||
public void testBug39535() throws Exception
|
||||
{
|
||||
assertCodeFailsParse("namespace bar = foo;");
|
||||
}
|
||||
|
||||
public void testBug39536A() throws Exception
|
||||
{
|
||||
IASTTemplateDeclaration template = (IASTTemplateDeclaration)parse("template<class E> class X { X<E>(); };").getDeclarations().next();
|
||||
|
|
|
@ -1773,6 +1773,11 @@ public class QuickParseASTTests extends BaseASTTest
|
|||
{
|
||||
parse("UnitList unit_list (String(\"keV\"));");
|
||||
}
|
||||
|
||||
public void testBug39535() throws Exception
|
||||
{
|
||||
parse("namespace bar = foo;");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
2003-08-28 John Camelon
|
||||
Fixed bug39535 - Parser fails on namesapce aliases
|
||||
|
||||
2003-08-26 Bogdan Gheorghe
|
||||
Added parser constant to all debugLog tracing statements.
|
||||
|
||||
|
|
|
@ -51,6 +51,15 @@ public interface IASTFactory
|
|||
String identifier,
|
||||
int startingOffset,
|
||||
int nameOffset) throws ASTSemanticException;
|
||||
|
||||
public IASTNamespaceAlias createNamespaceAlias(
|
||||
IASTScope scope,
|
||||
String identifier,
|
||||
ITokenDuple alias,
|
||||
int startingOffset,
|
||||
int nameOffset,
|
||||
int endOffset ) throws ASTSemanticException;
|
||||
|
||||
public IASTCompilationUnit createCompilationUnit();
|
||||
public IASTLinkageSpecification createLinkageSpecification(
|
||||
IASTScope scope,
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/**********************************************************************
|
||||
* 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.ast;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public interface IASTNamespaceAlias
|
||||
extends ISourceElementCallbackDelegate, IASTDeclaration, IASTOffsetableNamedElement
|
||||
{
|
||||
public String getAlias();
|
||||
public IASTNamespaceDefinition getNamespace() throws ASTNotImplementedException;
|
||||
}
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
|
@ -781,6 +782,29 @@ public class Parser implements IParser
|
|||
last.getOffset() + last.getLength());
|
||||
namespaceDefinition.exitScope( requestor );
|
||||
}
|
||||
else if( LT(1) == IToken.tASSIGN )
|
||||
{
|
||||
consume( IToken.tASSIGN );
|
||||
|
||||
if( identifier == null )
|
||||
throw backtrack;
|
||||
|
||||
ITokenDuple duple = name();
|
||||
|
||||
IASTNamespaceAlias alias = null;
|
||||
|
||||
try
|
||||
{
|
||||
alias = astFactory.createNamespaceAlias(
|
||||
scope, identifier.toString(), duple, first.getOffset(),
|
||||
identifier.getOffset(), duple.getLastToken().getEndOffset() );
|
||||
}
|
||||
catch (ASTSemanticException e)
|
||||
{
|
||||
failParse();
|
||||
throw backtrack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw backtrack;
|
||||
|
@ -926,7 +950,7 @@ public class Parser implements IParser
|
|||
}
|
||||
protected void handleFunctionBody(Declarator d) throws Backtrack, EndOfFile
|
||||
{
|
||||
if ( true ) // TODO - Enable parsing within function bodies i.e. mode == ParserMode.QUICK_PARSE)
|
||||
if ( mode == ParserMode.QUICK_PARSE ) // TODO - Enable parsing within function bodies i.e. mode == ParserMode.QUICK_PARSE)
|
||||
{
|
||||
// speed up the parser by skiping the body
|
||||
// simply look for matching brace and return
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
/**********************************************************************
|
||||
* 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.ast.complete;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class ASTNamespaceAlias extends ASTSymbol implements IASTNamespaceAlias
|
||||
{
|
||||
private NamedOffsets offsets = new NamedOffsets();
|
||||
private final String alias;
|
||||
private final IASTNamespaceDefinition namespace;
|
||||
private final ASTReferenceStore store;
|
||||
/**
|
||||
* @param scope
|
||||
* @param symbol
|
||||
* @param startingOffset
|
||||
* @param nameOffset
|
||||
* @param endOffset
|
||||
*/
|
||||
public ASTNamespaceAlias(ISymbol s, String alias, IASTNamespaceDefinition namespaceDefinition, int startingOffset, int nameOffset, int endOffset, List references)
|
||||
{
|
||||
super( s );
|
||||
this.alias = alias;
|
||||
this.namespace = namespaceDefinition;
|
||||
setStartingOffset(startingOffset);
|
||||
setEndingOffset(endOffset);
|
||||
setNameOffset(nameOffset);
|
||||
store = new ASTReferenceStore( references);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getAlias()
|
||||
*/
|
||||
public String getAlias()
|
||||
{
|
||||
return alias;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getNamespace()
|
||||
*/
|
||||
public IASTNamespaceDefinition getNamespace()
|
||||
throws ASTNotImplementedException
|
||||
{
|
||||
return namespace;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
|
||||
*/
|
||||
public void acceptElement(ISourceElementRequestor requestor)
|
||||
{
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
|
||||
*/
|
||||
public void enterScope(ISourceElementRequestor requestor)
|
||||
{
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
|
||||
*/
|
||||
public void exitScope(ISourceElementRequestor requestor)
|
||||
{
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName()
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return getSymbol().getName();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset()
|
||||
*/
|
||||
public int getNameOffset()
|
||||
{
|
||||
return offsets.getNameOffset();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int)
|
||||
*/
|
||||
public void setNameOffset(int o)
|
||||
{
|
||||
offsets.setNameOffset( o );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int)
|
||||
*/
|
||||
public void setStartingOffset(int o)
|
||||
{
|
||||
offsets.setStartingOffset(o);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int)
|
||||
*/
|
||||
public void setEndingOffset(int o)
|
||||
{
|
||||
offsets.setEndingOffset(o);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset()
|
||||
*/
|
||||
public int getStartingOffset()
|
||||
{
|
||||
return offsets.getStartingOffset();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset()
|
||||
*/
|
||||
public int getEndingOffset()
|
||||
{
|
||||
return offsets.getEndingOffset();
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTReference;
|
||||
|
@ -1392,4 +1393,44 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
}
|
||||
|
||||
protected ParserSymbolTable pst = new ParserSymbolTable();
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNamespaceAlias(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, org.eclipse.cdt.core.parser.ITokenDuple, int, int, int)
|
||||
*/
|
||||
public IASTNamespaceAlias createNamespaceAlias(IASTScope scope, String identifier, ITokenDuple alias, int startingOffset, int nameOffset, int endOffset) throws ASTSemanticException
|
||||
{
|
||||
IContainerSymbol startingSymbol = scopeToSymbol(scope);
|
||||
List references = new ArrayList();
|
||||
|
||||
ISymbol namespaceSymbol = lookupQualifiedName( startingSymbol, alias, references, true );
|
||||
|
||||
if( namespaceSymbol.getType() != TypeInfo.t_namespace )
|
||||
throw new ASTSemanticException();
|
||||
|
||||
ISymbol newSymbol = pst.newContainerSymbol( identifier, TypeInfo.t_namespace );
|
||||
newSymbol.setTypeSymbol( namespaceSymbol );
|
||||
|
||||
try
|
||||
{
|
||||
startingSymbol.addSymbol( newSymbol );
|
||||
}
|
||||
catch (ParserSymbolTableException e)
|
||||
{
|
||||
throw new ASTSemanticException();
|
||||
}
|
||||
|
||||
ASTNamespaceAlias astAlias = new ASTNamespaceAlias(
|
||||
newSymbol, alias.toString(), (IASTNamespaceDefinition)namespaceSymbol.getASTExtension().getPrimaryDeclaration(),
|
||||
startingOffset, nameOffset, endOffset, references );
|
||||
try
|
||||
{
|
||||
attachSymbolExtension( newSymbol, astAlias );
|
||||
}
|
||||
catch (ExtensionException e1)
|
||||
{
|
||||
throw new ASTSemanticException();
|
||||
}
|
||||
return astAlias;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
/**********************************************************************
|
||||
* 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.ast.quick;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class ASTNamespaceAlias extends ASTDeclaration implements IASTNamespaceAlias
|
||||
{
|
||||
|
||||
private final String alias;
|
||||
private final String identifier;
|
||||
private NamedOffsets offsets = new NamedOffsets();
|
||||
/**
|
||||
* @param scope
|
||||
* @param identifier
|
||||
* @param string
|
||||
* @param startingOffset
|
||||
* @param nameOffset
|
||||
* @param endOffset
|
||||
*/
|
||||
public ASTNamespaceAlias(IASTScope scope, String identifier, String string, int startingOffset, int nameOffset, int endOffset)
|
||||
{
|
||||
super( scope );
|
||||
setStartingOffset(startingOffset);
|
||||
setNameOffset(nameOffset);
|
||||
setEndingOffset(endOffset);
|
||||
this.identifier = identifier;
|
||||
this.alias = string;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
|
||||
*/
|
||||
public void acceptElement(ISourceElementRequestor requestor)
|
||||
{
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
|
||||
*/
|
||||
public void enterScope(ISourceElementRequestor requestor)
|
||||
{
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
|
||||
*/
|
||||
public void exitScope(ISourceElementRequestor requestor)
|
||||
{
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getAlias()
|
||||
*/
|
||||
public String getAlias()
|
||||
{
|
||||
return alias;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getNamespace()
|
||||
*/
|
||||
public IASTNamespaceDefinition getNamespace() throws ASTNotImplementedException
|
||||
{
|
||||
throw new ASTNotImplementedException();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName()
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return identifier;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset()
|
||||
*/
|
||||
public int getNameOffset()
|
||||
{
|
||||
return offsets.getNameOffset();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int)
|
||||
*/
|
||||
public void setNameOffset(int o)
|
||||
{
|
||||
offsets.setNameOffset(o);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int)
|
||||
*/
|
||||
public void setStartingOffset(int o)
|
||||
{
|
||||
offsets.setStartingOffset(o);
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int)
|
||||
*/
|
||||
public void setEndingOffset(int o)
|
||||
{
|
||||
offsets.setEndingOffset(o);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset()
|
||||
*/
|
||||
public int getStartingOffset()
|
||||
{
|
||||
return offsets.getStartingOffset();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset()
|
||||
*/
|
||||
public int getEndingOffset()
|
||||
{
|
||||
return offsets.getEndingOffset();
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
|
@ -267,4 +268,12 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
|
|||
{
|
||||
return new ASTElaboratedTypeSpecifier( scope, elaboratedClassKind, typeName.toString(), startingOffset, typeName.getFirstToken().getOffset(), endOffset );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNamespaceAlias(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, org.eclipse.cdt.core.parser.ITokenDuple, int, int, int)
|
||||
*/
|
||||
public IASTNamespaceAlias createNamespaceAlias(IASTScope scope, String identifier, ITokenDuple alias, int startingOffset, int nameOffset, int endOffset)
|
||||
{
|
||||
return new ASTNamespaceAlias( scope, identifier, alias.toString(), startingOffset, nameOffset, endOffset );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue