mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +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 abstract ITokenDuple getSubrange( int startIndex, int endIndex );
|
||||||
public IToken getToken(int index);
|
public IToken getToken(int index);
|
||||||
|
public ITokenDuple[] getSegments();
|
||||||
|
|
||||||
public int findLastTokenType( int type );
|
public int findLastTokenType( int type );
|
||||||
|
|
||||||
|
|
|
@ -339,4 +339,13 @@ public abstract class AbstractToken implements IToken, ITokenDuple {
|
||||||
*/
|
*/
|
||||||
public void acceptElement(ISourceElementRequestor requestor) {
|
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, newArgs );
|
||||||
}
|
}
|
||||||
return TokenFactory.createTokenDuple( first, last );
|
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(){
|
public ITokenDuple getLeadingSegments(){
|
||||||
if( getFirstToken() == null )
|
if( getFirstToken() == null )
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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.IASTBinaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
|
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.ParserProblemFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
|
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.CASTBreakStatement;
|
||||||
import org.eclipse.cdt.internal.core.parser2.c.CASTCaseStatement;
|
import org.eclipse.cdt.internal.core.parser2.c.CASTCaseStatement;
|
||||||
import org.eclipse.cdt.internal.core.parser2.c.CASTContinueStatement;
|
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,
|
protected abstract IASTNode forInitStatement() throws BacktrackException,
|
||||||
EndOfFileException;
|
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
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
class CASTNode extends ASTNode implements IASTNode {
|
public class CASTNode extends ASTNode implements IASTNode {
|
||||||
|
|
||||||
|
|
||||||
private IASTNode parent;
|
private IASTNode parent;
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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.IASTArrayDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
||||||
|
@ -335,13 +334,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
BacktrackException {
|
BacktrackException {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.t_asm:
|
case IToken.t_asm:
|
||||||
IToken first = consume(IToken.t_asm);
|
return asmDeclaration();
|
||||||
consume(IToken.tLPAREN);
|
|
||||||
String assembly = consume(IToken.tSTRING).getImage();
|
|
||||||
consume(IToken.tRPAREN);
|
|
||||||
consume(IToken.tSEMI);
|
|
||||||
cleanupLastToken();
|
|
||||||
return buildASMDirective( first.getOffset(), assembly );
|
|
||||||
default:
|
default:
|
||||||
IASTDeclaration d = simpleDeclaration();
|
IASTDeclaration d = simpleDeclaration();
|
||||||
cleanupLastToken();
|
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 BacktrackException
|
||||||
* @throws EndOfFileException
|
* @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;
|
package org.eclipse.cdt.internal.core.parser2.cpp;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
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.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
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.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
import org.eclipse.cdt.core.parser.BacktrackException;
|
import org.eclipse.cdt.core.parser.BacktrackException;
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
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.CASTEnumerator;
|
||||||
import org.eclipse.cdt.internal.core.parser2.c.CASTExpressionList;
|
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.CASTName;
|
||||||
|
import org.eclipse.cdt.internal.core.parser2.c.CASTTranslationUnit;
|
||||||
import org.eclipse.cdt.internal.core.parser2.c.CASTUnaryExpression;
|
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 {
|
public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
private ScopeStack templateIdScopes = new ScopeStack();
|
private ScopeStack templateIdScopes = new ScopeStack();
|
||||||
protected Object translationUnit;
|
protected IASTTranslationUnit translationUnit;
|
||||||
private static class ScopeStack {
|
private static class ScopeStack {
|
||||||
private int[] stack;
|
private int[] stack;
|
||||||
|
|
||||||
|
@ -2605,31 +2610,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
throws EndOfFileException, BacktrackException {
|
throws EndOfFileException, BacktrackException {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.t_asm:
|
case IToken.t_asm:
|
||||||
IToken first = consume(IToken.t_asm);
|
return asmDeclaration();
|
||||||
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;
|
|
||||||
case IToken.t_namespace:
|
case IToken.t_namespace:
|
||||||
namespaceDefinition();
|
return namespaceDefinitionOrAlias();
|
||||||
break;
|
|
||||||
case IToken.t_using:
|
case IToken.t_using:
|
||||||
usingClause();
|
usingClause();
|
||||||
break;
|
break;
|
||||||
|
@ -2717,105 +2700,71 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
* request a backtrack
|
* request a backtrack
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected Object namespaceDefinition()
|
protected IASTDeclaration namespaceDefinitionOrAlias()
|
||||||
throws BacktrackException, EndOfFileException {
|
throws BacktrackException, EndOfFileException {
|
||||||
IToken first = consume(IToken.t_namespace);
|
|
||||||
|
|
||||||
IToken identifier = null;
|
IToken first = consume(IToken.t_namespace);
|
||||||
|
IASTName name = null;
|
||||||
// optional name
|
// optional name
|
||||||
if (LT(1) == IToken.tIDENTIFIER)
|
if (LT(1) == IToken.tIDENTIFIER)
|
||||||
identifier = identifier();
|
name = createName( identifier() );
|
||||||
|
else
|
||||||
|
name = createName();
|
||||||
|
|
||||||
if (LT(1) == IToken.tLBRACE) {
|
if (LT(1) == IToken.tLBRACE) {
|
||||||
IToken lbrace = consume();
|
consume();
|
||||||
Object namespaceDefinition = null;
|
ICPPASTNamespaceDefinition namespaceDefinition = createNamespaceDefinition();
|
||||||
try {
|
((CPPASTNode)namespaceDefinition).setOffset( first.getOffset() );
|
||||||
namespaceDefinition = null; /*
|
namespaceDefinition.setName( name );
|
||||||
* astFactory.createNamespaceDefinition(
|
name.setParent( namespaceDefinition );
|
||||||
* scope, (identifier == null ?
|
name.setPropertyInParent( ICPPASTNamespaceDefinition.NAMESPACE_NAME );
|
||||||
* EMPTY_STRING:
|
|
||||||
* identifier.getCharImage()),
|
cleanupLastToken();
|
||||||
* //$NON-NLS-1$ first.getOffset(),
|
namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
|
||||||
* first.getLineNumber(),
|
int checkToken = LA(1).hashCode();
|
||||||
* (identifier == null ?
|
switch (LT(1)) {
|
||||||
* first.getOffset() :
|
case IToken.tRBRACE:
|
||||||
* identifier.getOffset()),
|
break namespaceDeclarationLoop;
|
||||||
* (identifier == null ?
|
default:
|
||||||
* first.getEndOffset() :
|
try {
|
||||||
* identifier.getEndOffset() ),
|
IASTDeclaration d = declaration();
|
||||||
* (identifier == null ?
|
d.setParent( namespaceDefinition );
|
||||||
* first.getLineNumber() :
|
d.setPropertyInParent( ICPPASTNamespaceDefinition.OWNED_DECLARATION );
|
||||||
* identifier.getLineNumber() ),
|
namespaceDefinition.addDeclaration( d );
|
||||||
* first.getFilename());
|
} catch (BacktrackException bt) {
|
||||||
*/
|
failParse(bt);
|
||||||
} catch (Exception e1) {
|
if (checkToken == LA(1).hashCode())
|
||||||
|
failParseWithErrorHandling();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (checkToken == LA(1).hashCode())
|
|
||||||
failParseWithErrorHandling();
|
|
||||||
}
|
}
|
||||||
// consume the }
|
if (checkToken == LA(1).hashCode())
|
||||||
IToken last = consume(IToken.tRBRACE);
|
failParseWithErrorHandling();
|
||||||
|
|
||||||
// namespaceDefinition.setEndingOffsetAndLineNumber(
|
|
||||||
// last.getOffset() + last.getLength(), last.getLineNumber());
|
|
||||||
} finally {
|
|
||||||
// namespaceDefinition.exitScope( requestor );
|
|
||||||
}
|
}
|
||||||
|
// consume the }
|
||||||
|
consume(IToken.tRBRACE);
|
||||||
|
|
||||||
return namespaceDefinition;
|
return namespaceDefinition;
|
||||||
} else if (LT(1) == IToken.tASSIGN) {
|
} else if (LT(1) == IToken.tASSIGN) {
|
||||||
IToken assign = consume(IToken.tASSIGN);
|
IToken assign = consume(IToken.tASSIGN);
|
||||||
|
|
||||||
if (identifier == null) {
|
if (name.toString() == null) {
|
||||||
throwBacktrack(first.getOffset(), assign.getEndOffset(), first
|
throwBacktrack(first.getOffset(), assign.getEndOffset(), first
|
||||||
.getLineNumber(), first.getFilename());
|
.getLineNumber(), first.getFilename());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITokenDuple duple = name();
|
ITokenDuple duple = name();
|
||||||
IToken semi = consume(IToken.tSEMI);
|
ICPPASTQualifiedName qualifiedName = createQualifiedName( duple );
|
||||||
|
consume(IToken.tSEMI);
|
||||||
|
|
||||||
Object alias = null;
|
ICPPASTNamespaceAlias alias = createNamespaceAlias();
|
||||||
try {
|
((CPPASTNode)alias).setOffset( first.getOffset() );
|
||||||
alias = null; /*
|
alias.setAlias( name );
|
||||||
* astFactory.createNamespaceAlias( scope,
|
name.setParent( alias );
|
||||||
* identifier.getCharImage(), duple,
|
name.setPropertyInParent( ICPPASTNamespaceAlias.ALIAS_NAME );
|
||||||
* first.getOffset(), first.getLineNumber(),
|
alias.setQualifiedName( qualifiedName );
|
||||||
* identifier.getOffset(),
|
qualifiedName.setParent( alias );
|
||||||
* identifier.getEndOffset(),
|
qualifiedName.setPropertyInParent( ICPPASTNamespaceAlias.MAPPING_NAME );
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
return alias;
|
return alias;
|
||||||
} else {
|
} else {
|
||||||
int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0;
|
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
|
* Serves as the catch-all for all complicated declarations, including
|
||||||
* function-definitions.
|
* function-definitions.
|
||||||
|
@ -4291,7 +4300,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
*/
|
*/
|
||||||
protected void translationUnit() {
|
protected void translationUnit() {
|
||||||
try {
|
try {
|
||||||
translationUnit = null; /* astFactory.createCompilationUnit(); */
|
translationUnit = createTranslationUnit();
|
||||||
} catch (Exception e2) {
|
} catch (Exception e2) {
|
||||||
logException("translationUnit::createCompilationUnit()", e2); //$NON-NLS-1$
|
logException("translationUnit::createCompilationUnit()", e2); //$NON-NLS-1$
|
||||||
return;
|
return;
|
||||||
|
@ -4302,7 +4311,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
int checkOffset = LA(1).hashCode();
|
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)
|
if (LA(1).hashCode() == checkOffset)
|
||||||
failParseWithErrorHandling();
|
failParseWithErrorHandling();
|
||||||
} catch (EndOfFileException e) {
|
} 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 {
|
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()
|
* @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#getTranslationUnit()
|
||||||
*/
|
*/
|
||||||
protected IASTTranslationUnit getTranslationUnit() {
|
protected IASTTranslationUnit getTranslationUnit() {
|
||||||
return (IASTTranslationUnit) translationUnit;
|
return translationUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -4461,4 +4480,5 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue