mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
Adding using declaration/directive support.
Refactored use of ICPPASTQualifiedName.
This commit is contained in:
parent
0ad6f1bcb0
commit
f6aa88405c
7 changed files with 193 additions and 75 deletions
|
@ -25,7 +25,7 @@ public interface ICPPASTNamespaceAlias extends IASTDeclaration {
|
|||
public IASTName getAlias();
|
||||
public void setAlias( IASTName name );
|
||||
|
||||
public ICPPASTQualifiedName getQualifiedName();
|
||||
public void setQualifiedName( ICPPASTQualifiedName qualifiedName );
|
||||
public IASTName getQualifiedName();
|
||||
public void setQualifiedName( IASTName qualifiedName );
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/**********************************************************************
|
||||
* 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 v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface ICPPASTUsingDeclaration extends IASTDeclaration {
|
||||
|
||||
public static final ASTNodeProperty NAME = new ASTNodeProperty( "Name"); //$NON-NLS-1$
|
||||
|
||||
public void setIsTypename( boolean value );
|
||||
public boolean isTypename();
|
||||
|
||||
public IASTName getName();
|
||||
public void setName(IASTName name);
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/**********************************************************************
|
||||
* 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 v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface ICPPASTUsingDirective extends IASTDeclaration {
|
||||
|
||||
public static final ASTNodeProperty QUALIFIED_NAME = new ASTNodeProperty( "Name"); //$NON-NLS-1$
|
||||
|
||||
public IASTName getQualifiedName();
|
||||
public void setQualifiedName( IASTName qualifiedName );
|
||||
|
||||
}
|
|
@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.parser2.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTNode;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +21,7 @@ public class CPPASTNamespaceAlias extends CASTNode implements
|
|||
ICPPASTNamespaceAlias {
|
||||
|
||||
private IASTName alias;
|
||||
private ICPPASTQualifiedName qualifiedName;
|
||||
private IASTName qualifiedName;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias#getAlias()
|
||||
|
@ -41,14 +40,14 @@ public class CPPASTNamespaceAlias extends CASTNode implements
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias#getQualifiedName()
|
||||
*/
|
||||
public ICPPASTQualifiedName getQualifiedName() {
|
||||
public IASTName getQualifiedName() {
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias#setQualifiedName(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName)
|
||||
*/
|
||||
public void setQualifiedName(ICPPASTQualifiedName qualifiedName) {
|
||||
public void setQualifiedName(IASTName qualifiedName) {
|
||||
this.qualifiedName = qualifiedName;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/**********************************************************************
|
||||
* 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 v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser2.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTUsingDeclaration extends CPPASTNode implements
|
||||
ICPPASTUsingDeclaration {
|
||||
|
||||
private boolean typeName;
|
||||
private IASTName name;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration#setIsTypename(boolean)
|
||||
*/
|
||||
public void setIsTypename(boolean value) {
|
||||
this.typeName = value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration#isTypename()
|
||||
*/
|
||||
public boolean isTypename() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration#getName()
|
||||
*/
|
||||
public IASTName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration#setName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public void setName(IASTName name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/**********************************************************************
|
||||
* 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 v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser2.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTUsingDirective extends CPPASTNode implements
|
||||
ICPPASTUsingDirective {
|
||||
|
||||
private IASTName name;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective#getQualifiedName()
|
||||
*/
|
||||
public IASTName getQualifiedName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective#setQualifiedName(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName)
|
||||
*/
|
||||
public void setQualifiedName(IASTName qualifiedName) {
|
||||
this.name = qualifiedName;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,6 @@
|
|||
package org.eclipse.cdt.internal.core.parser2.cpp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
|
@ -30,6 +29,8 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||
import org.eclipse.cdt.core.parser.BacktrackException;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
|
@ -2073,7 +2074,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
* @throws BacktrackException
|
||||
* request for a backtrack
|
||||
*/
|
||||
protected Object usingClause() throws EndOfFileException,
|
||||
protected IASTDeclaration usingClause() throws EndOfFileException,
|
||||
BacktrackException {
|
||||
IToken firstToken = consume(IToken.t_using);
|
||||
|
||||
|
@ -2081,39 +2082,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
// using-directive
|
||||
consume(IToken.t_namespace);
|
||||
|
||||
// optional :: and nested classes handled in name
|
||||
ITokenDuple duple = null;
|
||||
int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0;
|
||||
IASTName name = null;
|
||||
if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON)
|
||||
duple = name();
|
||||
name = createName( name() );
|
||||
else
|
||||
throwBacktrack(firstToken.getOffset(), endOffset, firstToken
|
||||
.getLineNumber(), firstToken.getFilename());
|
||||
if (LT(1) == IToken.tSEMI) {
|
||||
IToken last = consume(IToken.tSEMI);
|
||||
Object astUD = null;
|
||||
|
||||
try {
|
||||
astUD = null; /*
|
||||
* astFactory.createUsingDirective(scope,
|
||||
* duple, firstToken.getOffset(),
|
||||
* firstToken.getLineNumber(),
|
||||
* last.getEndOffset(), last.getLineNumber()); }
|
||||
* catch( ASTSemanticException ase ) { backup(
|
||||
* last ); throwBacktrack( ase.getProblem() );
|
||||
*/
|
||||
} catch (Exception e1) {
|
||||
logException("usingClause:createUsingDirective", e1); //$NON-NLS-1$
|
||||
throwBacktrack(firstToken.getOffset(), last.getEndOffset(),
|
||||
firstToken.getLineNumber(), last.getFilename());
|
||||
}
|
||||
// astUD.acceptElement(requestor );
|
||||
return astUD;
|
||||
}
|
||||
endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0;
|
||||
throwBacktrack(firstToken.getOffset(), endOffset, firstToken
|
||||
.getLineNumber(), firstToken.getFilename());
|
||||
|
||||
consume(IToken.tSEMI);
|
||||
ICPPASTUsingDirective astUD = createUsingDirective();
|
||||
((CPPASTNode)astUD).setOffset( firstToken.getOffset() );
|
||||
astUD.setQualifiedName( name );
|
||||
name.setParent( astUD );
|
||||
name.setPropertyInParent( ICPPASTUsingDirective.QUALIFIED_NAME );
|
||||
return astUD;
|
||||
}
|
||||
|
||||
boolean typeName = false;
|
||||
|
||||
if (LT(1) == IToken.t_typename) {
|
||||
|
@ -2121,43 +2106,29 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
consume(IToken.t_typename);
|
||||
}
|
||||
|
||||
ITokenDuple name = null;
|
||||
if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) {
|
||||
// optional :: and nested classes handled in name
|
||||
name = name();
|
||||
} else {
|
||||
throwBacktrack(firstToken.getOffset(),
|
||||
(lastToken != null) ? lastToken.getEndOffset() : 0,
|
||||
firstToken.getLineNumber(), firstToken.getFilename());
|
||||
}
|
||||
if (LT(1) == IToken.tSEMI) {
|
||||
IToken last = consume(IToken.tSEMI);
|
||||
Object declaration = null;
|
||||
try {
|
||||
declaration = null; /*
|
||||
* astFactory.createUsingDeclaration( scope,
|
||||
* typeName, name, firstToken.getOffset(),
|
||||
* firstToken.getLineNumber(),
|
||||
* last.getEndOffset(),
|
||||
* last.getLineNumber());
|
||||
*/
|
||||
} catch (Exception e1) {
|
||||
logException("usingClause:createUsingDeclaration", e1); //$NON-NLS-1$
|
||||
// if (e1 instanceof ASTSemanticException
|
||||
// && ((ASTSemanticException) e1).getProblem() != null)
|
||||
// throwBacktrack(((ASTSemanticException) e1).getProblem());
|
||||
// else
|
||||
throwBacktrack(firstToken.getOffset(), last.getEndOffset(),
|
||||
firstToken.getLineNumber(), firstToken
|
||||
.getFilename());
|
||||
}
|
||||
// declaration.acceptElement( requestor );
|
||||
return declaration;
|
||||
}
|
||||
int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0;
|
||||
throwBacktrack(firstToken.getOffset(), endOffset, firstToken
|
||||
.getLineNumber(), firstToken.getFilename());
|
||||
return null;
|
||||
IASTName name = createName( name() );
|
||||
consume( IToken.tSEMI );
|
||||
ICPPASTUsingDeclaration result = createUsingDeclaration();
|
||||
((CPPASTNode)result).setOffset( firstToken.getOffset() );
|
||||
result.setIsTypename( typeName );
|
||||
result.setName( name );
|
||||
name.setPropertyInParent( ICPPASTUsingDeclaration.NAME );
|
||||
name.setParent( result );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private ICPPASTUsingDeclaration createUsingDeclaration() {
|
||||
return new CPPASTUsingDeclaration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected ICPPASTUsingDirective createUsingDirective() {
|
||||
return new CPPASTUsingDirective();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2614,8 +2585,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
case IToken.t_namespace:
|
||||
return namespaceDefinitionOrAlias();
|
||||
case IToken.t_using:
|
||||
usingClause();
|
||||
break;
|
||||
return usingClause();
|
||||
case IToken.t_export:
|
||||
case IToken.t_template:
|
||||
templateDeclaration();
|
||||
|
@ -2754,7 +2724,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
ITokenDuple duple = name();
|
||||
ICPPASTQualifiedName qualifiedName = createQualifiedName( duple );
|
||||
IASTName qualifiedName = createName( duple );
|
||||
consume(IToken.tSEMI);
|
||||
|
||||
ICPPASTNamespaceAlias alias = createNamespaceAlias();
|
||||
|
@ -2822,6 +2792,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
* @return
|
||||
*/
|
||||
protected IASTName createName(ITokenDuple duple) {
|
||||
if( duple.getSegmentCount() != 1 ) return createQualifiedName( duple );
|
||||
CASTName name = new CASTName( duple.toCharArray() );
|
||||
name.setOffset( duple.getStartOffset());
|
||||
return name;
|
||||
|
|
Loading…
Add table
Reference in a new issue