[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Applied [HEAD] Namespace alias support
|
CORE
Fixed bug39535 - Parser fails on namesapce aliases
TESTS
Moved bug39535 from failedTests to quickParse success tests.
JohnC
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.68
diff -u -r1.68 ChangeLog
--- ChangeLog 25 Aug 2003 15:19:06 -0000 1.68
+++ ChangeLog 28 Aug 2003 15:01:02 -0000
@@ -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
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.10
diff -u -r1.10 ASTFailedTests.java
--- failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java 25 Aug 2003 15:19:06 -0000 1.10
+++ failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java 28 Aug 2003 15:01:03 -0000
@@ -81,10 +81,7 @@
{
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();
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.14
diff -u -r1.14 QuickParseASTTests.java
--- parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java 25 Aug 2003 15:19:06 -0000 1.14
+++ parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java 28 Aug 2003 15:01:13 -0000
@@ -1773,6 +1773,11 @@
{
parse("UnitList unit_list (String(\"keV\"));");
}
+
+ public void testBug39535() throws Exception
+ {
+ parse("namespace bar = foo;");
+ }
}
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.105
diff -u -r1.105 ChangeLog
--- parser/ChangeLog 26 Aug 2003 19:15:58 -0000 1.105
+++ parser/ChangeLog 28 Aug 2003 15:00:03 -0000
@@ -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.
Index: parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java,v
retrieving revision 1.25
diff -u -r1.25 IASTFactory.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java 25 Aug 2003 15:41:30 -0000 1.25
+++ parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java 28 Aug 2003 15:00:04 -0000
@@ -51,6 +51,15 @@
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,
Index: parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceAlias.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceAlias.java
diff -N parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceAlias.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceAlias.java 28 Aug 2003 15:00:04 -0000
@@ -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;
+}
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.98
diff -u -r1.98 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java 26 Aug 2003 19:15:58 -0000 1.98
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java 28 Aug 2003 15:00:11 -0000
@@ -41,6 +41,7 @@
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 @@
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 @@
}
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
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceAlias.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceAlias.java
diff -N parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceAlias.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceAlias.java 28 Aug 2003 15:00:12 -0000
@@ -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();
+ }
+}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java,v
retrieving revision 1.21
diff -u -r1.21 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 25 Aug 2003 18:19:55 -0000 1.21
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 28 Aug 2003 15:00:15 -0000
@@ -37,6 +37,7 @@
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 @@
}
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;
+ }
}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceAlias.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceAlias.java
diff -N parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceAlias.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceAlias.java 28 Aug 2003 15:00:16 -0000
@@ -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();
+ }
+}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java,v
retrieving revision 1.27
diff -u -r1.27 QuickParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java 25 Aug 2003 15:41:30 -0000 1.27
+++ parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java 28 Aug 2003 15:00:17 -0000
@@ -35,6 +35,7 @@
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;
@@ -266,5 +267,13 @@
public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier(IASTScope scope, ASTClassKind elaboratedClassKind, ITokenDuple typeName, int startingOffset, int endOffset, boolean isForewardDecl)
{
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 );
}
}