mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Writable DOM Support for:
C++ Qualified Names. ASM Declarations in C++. Namespace Definitions & Aliases.
This commit is contained in:
parent
06a31c42a6
commit
bf7b23eb9e
14 changed files with 623 additions and 137 deletions
|
@ -0,0 +1,31 @@
|
|||
/**********************************************************************
|
||||
* 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 ICPPASTNamespaceAlias extends IASTDeclaration {
|
||||
|
||||
public static final ASTNodeProperty ALIAS_NAME = new ASTNodeProperty( "Alias name"); //$NON-NLS-1$
|
||||
public static final ASTNodeProperty MAPPING_NAME = new ASTNodeProperty( "Mapping name"); //$NON-NLS-1$
|
||||
|
||||
public IASTName getAlias();
|
||||
public void setAlias( IASTName name );
|
||||
|
||||
public ICPPASTQualifiedName getQualifiedName();
|
||||
public void setQualifiedName( ICPPASTQualifiedName qualifiedName );
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/**********************************************************************
|
||||
* 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 java.util.List;
|
||||
|
||||
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 ICPPASTNamespaceDefinition extends IASTDeclaration {
|
||||
|
||||
public static final ASTNodeProperty OWNED_DECLARATION = new ASTNodeProperty( "Owned" ); //$NON-NLS-1$
|
||||
public static final ASTNodeProperty NAMESPACE_NAME = new ASTNodeProperty( "Name"); //$NON-NLS-1$
|
||||
|
||||
|
||||
public IASTName getName();
|
||||
public void setName( IASTName name );
|
||||
|
||||
/**
|
||||
* A translation unit contains an ordered sequence of declarations.
|
||||
*
|
||||
* @return List of IASTDeclaration
|
||||
*/
|
||||
public List getDeclarations();
|
||||
|
||||
public void addDeclaration( IASTDeclaration declaration );
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/**********************************************************************
|
||||
* 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 java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface ICPPASTQualifiedName extends IASTName {
|
||||
|
||||
public static final ASTNodeProperty SEGMENT_NAME = new ASTNodeProperty( "Segment"); //$NON-NLS-1$
|
||||
public void addName( IASTName name );
|
||||
public List getNames();
|
||||
}
|
|
@ -44,6 +44,7 @@ public interface ITokenDuple {
|
|||
|
||||
public abstract ITokenDuple getSubrange( int startIndex, int endIndex );
|
||||
public IToken getToken(int index);
|
||||
public ITokenDuple[] getSegments();
|
||||
|
||||
public int findLastTokenType( int type );
|
||||
|
||||
|
|
|
@ -339,4 +339,13 @@ public abstract class AbstractToken implements IToken, ITokenDuple {
|
|||
*/
|
||||
public void acceptElement(ISourceElementRequestor requestor) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ITokenDuple#getSegmentIterator()
|
||||
*/
|
||||
public ITokenDuple[] getSegments() {
|
||||
ITokenDuple [] r = new ITokenDuple[0];
|
||||
r[0] = this;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,10 +88,33 @@ public class BasicTokenDuple implements ITokenDuple {
|
|||
return TokenFactory.createTokenDuple( first, last, newArgs );
|
||||
}
|
||||
return TokenFactory.createTokenDuple( first, last );
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ITokenDuple[] getSegments()
|
||||
{
|
||||
|
||||
List r = new ArrayList();
|
||||
IToken token = null;
|
||||
IToken prev = null;
|
||||
IToken last = getLastToken();
|
||||
IToken startOfSegment = getFirstToken();
|
||||
for( ;; ){
|
||||
if( token == last )
|
||||
break;
|
||||
prev = token;
|
||||
token = ( token != null ) ? token.getNext() : getFirstToken();
|
||||
if( token.getType() == IToken.tLT )
|
||||
token = TokenFactory.consumeTemplateIdArguments( token, last );
|
||||
if( token.getType() == IToken.tCOLONCOLON ){
|
||||
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev );
|
||||
r.add( d );
|
||||
startOfSegment = token.getNext();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return (ITokenDuple[]) r.toArray( new ITokenDuple[ r.size() ]);
|
||||
|
||||
}
|
||||
|
||||
public ITokenDuple getLeadingSegments(){
|
||||
if( getFirstToken() == null )
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
|
||||
|
@ -58,6 +59,7 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
|||
import org.eclipse.cdt.internal.core.parser.ParserProblemFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTASMDeclaration;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTBreakStatement;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTCaseStatement;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTContinueStatement;
|
||||
|
@ -1568,4 +1570,39 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
protected abstract IASTNode forInitStatement() throws BacktrackException,
|
||||
EndOfFileException;
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @throws EndOfFileException
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTDeclaration asmDeclaration() throws EndOfFileException, BacktrackException {
|
||||
IToken first = consume(IToken.t_asm);
|
||||
consume(IToken.tLPAREN);
|
||||
String assembly = consume(IToken.tSTRING).getImage();
|
||||
consume(IToken.tRPAREN);
|
||||
consume(IToken.tSEMI);
|
||||
cleanupLastToken();
|
||||
return buildASMDirective( first.getOffset(), assembly );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offset
|
||||
* @param assembly
|
||||
* @return
|
||||
*/
|
||||
protected IASTASMDeclaration buildASMDirective(int offset, String assembly) {
|
||||
IASTASMDeclaration result = createASMDirective();
|
||||
((ASTNode)result).setOffset( offset );
|
||||
result.setAssembly( assembly );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected IASTASMDeclaration createASMDirective() {
|
||||
return new CASTASMDeclaration();
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ import org.eclipse.cdt.internal.core.parser2.ASTNode;
|
|||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
class CASTNode extends ASTNode implements IASTNode {
|
||||
public class CASTNode extends ASTNode implements IASTNode {
|
||||
|
||||
|
||||
private IASTNode parent;
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
||||
|
@ -335,13 +334,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
BacktrackException {
|
||||
switch (LT(1)) {
|
||||
case IToken.t_asm:
|
||||
IToken first = consume(IToken.t_asm);
|
||||
consume(IToken.tLPAREN);
|
||||
String assembly = consume(IToken.tSTRING).getImage();
|
||||
consume(IToken.tRPAREN);
|
||||
consume(IToken.tSEMI);
|
||||
cleanupLastToken();
|
||||
return buildASMDirective( first.getOffset(), assembly );
|
||||
return asmDeclaration();
|
||||
default:
|
||||
IASTDeclaration d = simpleDeclaration();
|
||||
cleanupLastToken();
|
||||
|
@ -350,25 +343,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offset
|
||||
* @param assembly
|
||||
* @return
|
||||
*/
|
||||
protected IASTASMDeclaration buildASMDirective(int offset, String assembly) {
|
||||
IASTASMDeclaration result = createASMDirective();
|
||||
((CASTNode)result).setOffset( offset );
|
||||
result.setAssembly( assembly );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected IASTASMDeclaration createASMDirective() {
|
||||
return new CASTASMDeclaration();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws BacktrackException
|
||||
* @throws EndOfFileException
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/**********************************************************************
|
||||
* 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 java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTName extends CPPASTNode implements ICPPASTQualifiedName {
|
||||
|
||||
/**
|
||||
* @param duple
|
||||
*/
|
||||
public CPPASTName() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
|
||||
*/
|
||||
public IBinding resolveBinding() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
if( names == null ) return null;
|
||||
removeNullNames();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for( int i = 0; i < names.length; ++i )
|
||||
{
|
||||
String n = names[i].toString();
|
||||
if( n == null )
|
||||
return null;
|
||||
buffer.append( n );
|
||||
if( i != names.length - 1 )
|
||||
buffer.append( "::"); //$NON-NLS-1$
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#addName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public void addName(IASTName name) {
|
||||
if( names == null )
|
||||
{
|
||||
names = new IASTName[ DEFAULT_NAMES_LIST_SIZE ];
|
||||
currentIndex = 0;
|
||||
}
|
||||
if( names.length == currentIndex )
|
||||
{
|
||||
IASTName [] old = names;
|
||||
names = new IASTName[ old.length * 2 ];
|
||||
for( int i = 0; i < old.length; ++i )
|
||||
names[i] = old[i];
|
||||
}
|
||||
names[ currentIndex++ ] = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param decls2
|
||||
*/
|
||||
private void removeNullNames() {
|
||||
int nullCount = 0;
|
||||
for( int i = 0; i < names.length; ++i )
|
||||
if( names[i] == null )
|
||||
++nullCount;
|
||||
if( nullCount == 0 ) return;
|
||||
IASTName [] old = names;
|
||||
int newSize = old.length - nullCount;
|
||||
names = new IASTName[ newSize ];
|
||||
for( int i = 0; i < newSize; ++i )
|
||||
names[i] = old[i];
|
||||
currentIndex = newSize;
|
||||
}
|
||||
|
||||
private int currentIndex = 0;
|
||||
private IASTName [] names = null;
|
||||
private static final int DEFAULT_NAMES_LIST_SIZE = 4;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#getNames()
|
||||
*/
|
||||
public List getNames() {
|
||||
if( names == null ) return Collections.EMPTY_LIST;
|
||||
removeNullNames();
|
||||
return Arrays.asList( names );
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**********************************************************************
|
||||
* 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.ICPPASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTNode;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTNamespaceAlias extends CASTNode implements
|
||||
ICPPASTNamespaceAlias {
|
||||
|
||||
private IASTName alias;
|
||||
private ICPPASTQualifiedName qualifiedName;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias#getAlias()
|
||||
*/
|
||||
public IASTName getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias#setAlias(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public void setAlias(IASTName name) {
|
||||
this.alias = name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias#getQualifiedName()
|
||||
*/
|
||||
public ICPPASTQualifiedName 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) {
|
||||
this.qualifiedName = qualifiedName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/**********************************************************************
|
||||
* 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 java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTNamespaceDefinition extends CPPASTNode implements
|
||||
ICPPASTNamespaceDefinition {
|
||||
|
||||
private IASTName name;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition#getName()
|
||||
*/
|
||||
public IASTName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
public void setName(IASTName name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition#getDeclarations()
|
||||
*/
|
||||
public List getDeclarations() {
|
||||
if( declarations == null ) return Collections.EMPTY_LIST;
|
||||
removeNullDeclarations();
|
||||
return Arrays.asList( declarations );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
|
||||
*/
|
||||
public void addDeclaration(IASTDeclaration declaration) {
|
||||
if( declarations == null )
|
||||
{
|
||||
declarations = new IASTDeclaration[ DEFAULT_DECLARATIONS_LIST_SIZE ];
|
||||
currentIndex = 0;
|
||||
}
|
||||
if( declarations.length == currentIndex )
|
||||
{
|
||||
IASTDeclaration [] old = declarations;
|
||||
declarations = new IASTDeclaration[ old.length * 2 ];
|
||||
for( int i = 0; i < old.length; ++i )
|
||||
declarations[i] = old[i];
|
||||
}
|
||||
declarations[ currentIndex++ ] = declaration;
|
||||
}
|
||||
|
||||
private void removeNullDeclarations() {
|
||||
int nullCount = 0;
|
||||
for( int i = 0; i < declarations.length; ++i )
|
||||
if( declarations[i] == null )
|
||||
++nullCount;
|
||||
if( nullCount == 0 ) return;
|
||||
IASTDeclaration [] old = declarations;
|
||||
int newSize = old.length - nullCount;
|
||||
declarations = new IASTDeclaration[ newSize ];
|
||||
for( int i = 0; i < newSize; ++i )
|
||||
declarations[i] = old[i];
|
||||
currentIndex = newSize;
|
||||
}
|
||||
|
||||
private int currentIndex = 0;
|
||||
private IASTDeclaration [] declarations = null;
|
||||
private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4;
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**********************************************************************
|
||||
* 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.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.parser2.ASTNode;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTNode extends ASTNode implements IASTNode {
|
||||
|
||||
private IASTNode parent;
|
||||
private ASTNodeProperty property;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit()
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit() {
|
||||
if( this instanceof IASTTranslationUnit ) return (IASTTranslationUnit) this;
|
||||
IASTNode node = getParent();
|
||||
while( ! (node instanceof IASTTranslationUnit ))
|
||||
{
|
||||
node = node.getParent();
|
||||
}
|
||||
return (IASTTranslationUnit) node;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getParent()
|
||||
*/
|
||||
public IASTNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void setParent(IASTNode node) {
|
||||
this.parent = node;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent()
|
||||
*/
|
||||
public ASTNodeProperty getPropertyInParent() {
|
||||
return property;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.ASTNodeProperty)
|
||||
*/
|
||||
public void setPropertyInParent(ASTNodeProperty property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
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;
|
||||
|
@ -26,6 +27,9 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
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.gnu.IGNUASTCompoundStatementExpression;
|
||||
import org.eclipse.cdt.core.parser.BacktrackException;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
|
@ -56,6 +60,7 @@ import org.eclipse.cdt.internal.core.parser2.c.CASTEnumerationSpecifier;
|
|||
import org.eclipse.cdt.internal.core.parser2.c.CASTEnumerator;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTExpressionList;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTName;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTUnaryExpression;
|
||||
|
||||
/**
|
||||
|
@ -69,7 +74,7 @@ import org.eclipse.cdt.internal.core.parser2.c.CASTUnaryExpression;
|
|||
public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||
|
||||
private ScopeStack templateIdScopes = new ScopeStack();
|
||||
protected Object translationUnit;
|
||||
protected IASTTranslationUnit translationUnit;
|
||||
private static class ScopeStack {
|
||||
private int[] stack;
|
||||
|
||||
|
@ -2605,31 +2610,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
throws EndOfFileException, BacktrackException {
|
||||
switch (LT(1)) {
|
||||
case IToken.t_asm:
|
||||
IToken first = consume(IToken.t_asm);
|
||||
consume(IToken.tLPAREN);
|
||||
char[] assembly = consume(IToken.tSTRING).getCharImage();
|
||||
consume(IToken.tRPAREN);
|
||||
IToken last = consume(IToken.tSEMI);
|
||||
|
||||
try {
|
||||
// astFactory.createASMDefinition(
|
||||
// scope,
|
||||
// assembly,
|
||||
// first.getOffset(),
|
||||
// first.getLineNumber(), last.getEndOffset(),
|
||||
// last.getLineNumber(), last.getFilename());
|
||||
} catch (Exception e) {
|
||||
logException("declaration:createASMDefinition", e); //$NON-NLS-1$
|
||||
throwBacktrack(first.getOffset(), last.getEndOffset(), first
|
||||
.getLineNumber(), first.getFilename());
|
||||
}
|
||||
// if we made it this far, then we have all we need
|
||||
// do the callback
|
||||
// resultDeclaration.acceptElement(requestor);
|
||||
break;
|
||||
return asmDeclaration();
|
||||
case IToken.t_namespace:
|
||||
namespaceDefinition();
|
||||
break;
|
||||
return namespaceDefinitionOrAlias();
|
||||
case IToken.t_using:
|
||||
usingClause();
|
||||
break;
|
||||
|
@ -2717,105 +2700,71 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
* request a backtrack
|
||||
*
|
||||
*/
|
||||
protected Object namespaceDefinition()
|
||||
protected IASTDeclaration namespaceDefinitionOrAlias()
|
||||
throws BacktrackException, EndOfFileException {
|
||||
IToken first = consume(IToken.t_namespace);
|
||||
|
||||
IToken identifier = null;
|
||||
IToken first = consume(IToken.t_namespace);
|
||||
IASTName name = null;
|
||||
// optional name
|
||||
if (LT(1) == IToken.tIDENTIFIER)
|
||||
identifier = identifier();
|
||||
name = createName( identifier() );
|
||||
else
|
||||
name = createName();
|
||||
|
||||
if (LT(1) == IToken.tLBRACE) {
|
||||
IToken lbrace = consume();
|
||||
Object namespaceDefinition = null;
|
||||
try {
|
||||
namespaceDefinition = null; /*
|
||||
* astFactory.createNamespaceDefinition(
|
||||
* scope, (identifier == null ?
|
||||
* EMPTY_STRING:
|
||||
* identifier.getCharImage()),
|
||||
* //$NON-NLS-1$ first.getOffset(),
|
||||
* first.getLineNumber(),
|
||||
* (identifier == null ?
|
||||
* first.getOffset() :
|
||||
* identifier.getOffset()),
|
||||
* (identifier == null ?
|
||||
* first.getEndOffset() :
|
||||
* identifier.getEndOffset() ),
|
||||
* (identifier == null ?
|
||||
* first.getLineNumber() :
|
||||
* identifier.getLineNumber() ),
|
||||
* first.getFilename());
|
||||
*/
|
||||
} catch (Exception e1) {
|
||||
|
||||
logException(
|
||||
"namespaceDefinition:createNamespaceDefinition", e1); //$NON-NLS-1$
|
||||
throwBacktrack(first.getOffset(), lbrace.getEndOffset(), first
|
||||
.getLineNumber(), first.getFilename());
|
||||
return null;
|
||||
}
|
||||
// namespaceDefinition.enterScope( requestor );
|
||||
try {
|
||||
cleanupLastToken();
|
||||
namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
||||
int checkToken = LA(1).hashCode();
|
||||
switch (LT(1)) {
|
||||
case IToken.tRBRACE:
|
||||
//consume(Token.tRBRACE);
|
||||
break namespaceDeclarationLoop;
|
||||
default:
|
||||
try {
|
||||
declaration();
|
||||
} catch (BacktrackException bt) {
|
||||
failParse(bt);
|
||||
if (checkToken == LA(1).hashCode())
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
consume();
|
||||
ICPPASTNamespaceDefinition namespaceDefinition = createNamespaceDefinition();
|
||||
((CPPASTNode)namespaceDefinition).setOffset( first.getOffset() );
|
||||
namespaceDefinition.setName( name );
|
||||
name.setParent( namespaceDefinition );
|
||||
name.setPropertyInParent( ICPPASTNamespaceDefinition.NAMESPACE_NAME );
|
||||
|
||||
cleanupLastToken();
|
||||
namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
||||
int checkToken = LA(1).hashCode();
|
||||
switch (LT(1)) {
|
||||
case IToken.tRBRACE:
|
||||
break namespaceDeclarationLoop;
|
||||
default:
|
||||
try {
|
||||
IASTDeclaration d = declaration();
|
||||
d.setParent( namespaceDefinition );
|
||||
d.setPropertyInParent( ICPPASTNamespaceDefinition.OWNED_DECLARATION );
|
||||
namespaceDefinition.addDeclaration( d );
|
||||
} catch (BacktrackException bt) {
|
||||
failParse(bt);
|
||||
if (checkToken == LA(1).hashCode())
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
if (checkToken == LA(1).hashCode())
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
// consume the }
|
||||
IToken last = consume(IToken.tRBRACE);
|
||||
|
||||
// namespaceDefinition.setEndingOffsetAndLineNumber(
|
||||
// last.getOffset() + last.getLength(), last.getLineNumber());
|
||||
} finally {
|
||||
// namespaceDefinition.exitScope( requestor );
|
||||
if (checkToken == LA(1).hashCode())
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
// consume the }
|
||||
consume(IToken.tRBRACE);
|
||||
|
||||
return namespaceDefinition;
|
||||
} else if (LT(1) == IToken.tASSIGN) {
|
||||
IToken assign = consume(IToken.tASSIGN);
|
||||
|
||||
if (identifier == null) {
|
||||
if (name.toString() == null) {
|
||||
throwBacktrack(first.getOffset(), assign.getEndOffset(), first
|
||||
.getLineNumber(), first.getFilename());
|
||||
return null;
|
||||
}
|
||||
|
||||
ITokenDuple duple = name();
|
||||
IToken semi = consume(IToken.tSEMI);
|
||||
ICPPASTQualifiedName qualifiedName = createQualifiedName( duple );
|
||||
consume(IToken.tSEMI);
|
||||
|
||||
Object alias = null;
|
||||
try {
|
||||
alias = null; /*
|
||||
* astFactory.createNamespaceAlias( scope,
|
||||
* identifier.getCharImage(), duple,
|
||||
* first.getOffset(), first.getLineNumber(),
|
||||
* identifier.getOffset(),
|
||||
* identifier.getEndOffset(),
|
||||
* identifier.getLineNumber(),
|
||||
* duple.getLastToken().getEndOffset(),
|
||||
* duple.getLastToken().getLineNumber() );
|
||||
*/
|
||||
} catch (Exception e1) {
|
||||
logException("namespaceDefinition:createNamespaceAlias", e1); //$NON-NLS-1$
|
||||
throwBacktrack(first.getOffset(), semi.getEndOffset(), first
|
||||
.getLineNumber(), first.getFilename());
|
||||
return null;
|
||||
}
|
||||
ICPPASTNamespaceAlias alias = createNamespaceAlias();
|
||||
((CPPASTNode)alias).setOffset( first.getOffset() );
|
||||
alias.setAlias( name );
|
||||
name.setParent( alias );
|
||||
name.setPropertyInParent( ICPPASTNamespaceAlias.ALIAS_NAME );
|
||||
alias.setQualifiedName( qualifiedName );
|
||||
qualifiedName.setParent( alias );
|
||||
qualifiedName.setPropertyInParent( ICPPASTNamespaceAlias.MAPPING_NAME );
|
||||
return alias;
|
||||
} else {
|
||||
int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0;
|
||||
|
@ -2825,6 +2774,66 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected ICPPASTNamespaceAlias createNamespaceAlias() {
|
||||
return new CPPASTNamespaceAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param duple
|
||||
* @return
|
||||
*/
|
||||
protected ICPPASTQualifiedName createQualifiedName(ITokenDuple duple) {
|
||||
CPPASTName result = new CPPASTName();
|
||||
result.setOffset( duple.getStartOffset());
|
||||
ITokenDuple [] segments = duple.getSegments();
|
||||
for( int i = 0; i < segments.length; ++i )
|
||||
{
|
||||
IASTName subName = null;
|
||||
// take each name and add it to the result
|
||||
if( segments[i] instanceof IToken )
|
||||
subName = createName( (IToken)segments[i]);
|
||||
else if( segments[i].getTemplateIdArgLists() == null )
|
||||
subName = createName( segments[i] );
|
||||
else // templateID
|
||||
subName = createTemplateID( segments[i] );
|
||||
subName.setParent( result );
|
||||
subName.setPropertyInParent( ICPPASTQualifiedName.SEGMENT_NAME );
|
||||
result.addName( subName );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param duple
|
||||
* @return
|
||||
*/
|
||||
private IASTName createTemplateID(ITokenDuple duple) {
|
||||
return new CASTName(); //TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* @param duple
|
||||
* @return
|
||||
*/
|
||||
protected IASTName createName(ITokenDuple duple) {
|
||||
CASTName name = new CASTName( duple.toCharArray() );
|
||||
name.setOffset( duple.getStartOffset());
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected ICPPASTNamespaceDefinition createNamespaceDefinition() {
|
||||
return new CPPASTNamespaceDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves as the catch-all for all complicated declarations, including
|
||||
* function-definitions.
|
||||
|
@ -4291,7 +4300,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
*/
|
||||
protected void translationUnit() {
|
||||
try {
|
||||
translationUnit = null; /* astFactory.createCompilationUnit(); */
|
||||
translationUnit = createTranslationUnit();
|
||||
} catch (Exception e2) {
|
||||
logException("translationUnit::createCompilationUnit()", e2); //$NON-NLS-1$
|
||||
return;
|
||||
|
@ -4302,7 +4311,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
while (true) {
|
||||
try {
|
||||
int checkOffset = LA(1).hashCode();
|
||||
declaration();
|
||||
IASTDeclaration declaration = declaration();
|
||||
translationUnit.addDeclaration( declaration );
|
||||
declaration.setParent( translationUnit );
|
||||
declaration.setPropertyInParent( IASTTranslationUnit.OWNED_DECLARATION );
|
||||
|
||||
if (LA(1).hashCode() == checkOffset)
|
||||
failParseWithErrorHandling();
|
||||
} catch (EndOfFileException e) {
|
||||
|
@ -4349,7 +4362,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
}
|
||||
}
|
||||
// compilationUnit.exitScope( requestor );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected IASTTranslationUnit createTranslationUnit() {
|
||||
return new CASTTranslationUnit();
|
||||
}
|
||||
|
||||
protected IToken consumeArrayModifiers(IDeclarator d) throws EndOfFileException, BacktrackException {
|
||||
|
@ -4380,7 +4399,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
* @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#getTranslationUnit()
|
||||
*/
|
||||
protected IASTTranslationUnit getTranslationUnit() {
|
||||
return (IASTTranslationUnit) translationUnit;
|
||||
return translationUnit;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -4461,4 +4480,5 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue