1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 01:05:38 +02:00
Added Expression x-reference support into Parser.

TESTS
	Added testSimpleExpression(), testParameterExpressions() && 
	testNestedNamespaceExpression() to CompleteParseASTTest.java.
This commit is contained in:
John Camelon 2003-08-13 21:51:53 +00:00
parent 4214aed737
commit fa8baf0518
22 changed files with 1297 additions and 670 deletions

View file

@ -1,3 +1,7 @@
2003-08-13 John Camelon
Added testSimpleExpression(), testParameterExpressions() &&
testNestedNamespaceExpression() to CompleteParseASTTest.java.
2003-08-13 Sean Evoy 2003-08-13 Sean Evoy
Renamed the 'AllBuildTest' class to 'ManagedBuildTest' and updated the Renamed the 'AllBuildTest' class to 'ManagedBuildTest' and updated the
integration suite class. integration suite class.

View file

@ -193,6 +193,7 @@ public class CompleteParseASTTest extends TestCase
public void exitFunctionBody(IASTFunction function) public void exitFunctionBody(IASTFunction function)
{ {
popScope(); popScope();
getCurrentScope().addDeclaration(function);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -291,6 +292,7 @@ public class CompleteParseASTTest extends TestCase
public void exitMethodBody(IASTMethod method) public void exitMethodBody(IASTMethod method)
{ {
popScope(); popScope();
getCurrentScope().addDeclaration(method);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -536,7 +538,7 @@ public class CompleteParseASTTest extends TestCase
ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(), ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(),
ParserMode.COMPLETE_PARSE, callback ), callback, ParserMode.COMPLETE_PARSE ParserMode.COMPLETE_PARSE, callback ), callback, ParserMode.COMPLETE_PARSE
); );
parser.parse(); if( ! parser.parse() ) throw new ParserException( "FAILURE");
return callback.getCompilationUnit(); return callback.getCompilationUnit();
} }
@ -902,4 +904,29 @@ public class CompleteParseASTTest extends TestCase
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
} }
public void testSimpleExpression() throws Exception
{
Iterator i = parse( "int x; int y = x;").getDeclarations();
IASTVariable varX = (IASTVariable)i.next();
IASTVariable varY = (IASTVariable)i.next();
assertEquals( callback.getReferences().size(), 1 );
}
public void testParameterExpressions() throws Exception
{
Iterator i = parse( "int x = 5; void foo( int sub = x ) { }").getDeclarations();
IASTVariable varX = (IASTVariable)i.next();
IASTFunction funFoo = (IASTFunction)i.next();
assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 1 );
}
public void testNestedNamespaceExpression() throws Exception
{
Iterator i = parse( "namespace A { int x = 666; } int y = A::x;").getDeclarations();
IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)i.next();
IASTVariable variableY = (IASTVariable)i.next();
assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 );
}
} }

View file

@ -27,7 +27,7 @@ public class ExprEvalTest extends TestCase {
final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor(); final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor();
IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), null, nullCallback ), nullCallback, ParserMode.QUICK_PARSE); IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), null, nullCallback ), nullCallback, ParserMode.QUICK_PARSE);
IASTExpression expression = parser.expression(); IASTExpression expression = parser.expression(null);
assertEquals(expectedValue, expression.evaluateExpression()); assertEquals(expectedValue, expression.evaluateExpression());
} }

View file

@ -1429,7 +1429,7 @@ public class QuickParseASTTests extends BaseASTTest
assertFalse( enumerators.hasNext() ); assertFalse( enumerators.hasNext() );
assertEquals( enumerator.getName(), "isPointer"); assertEquals( enumerator.getName(), "isPointer");
assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION ); assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION );
assertEquals( enumerator.getInitialValue().getLiteralString(), "PointerTraits<T>::result"); assertEquals( enumerator.getInitialValue().getTypeId(), "PointerTraits<T>::result");
} }
public void testBug36690() throws Exception { public void testBug36690() throws Exception {

View file

@ -1,3 +1,6 @@
2003-08-13 John Camelon
Added Expression x-reference support into Parser.
2003-08-12 John Camelon 2003-08-12 John Camelon
Added X-Ref/Elaborated type support w/element requestor callbacks. Added X-Ref/Elaborated type support w/element requestor callbacks.

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTScope;
@ -40,7 +41,7 @@ public interface IParser {
* @throws Backtrack thrown if the Scanner/Stream provided does not yield a valid * @throws Backtrack thrown if the Scanner/Stream provided does not yield a valid
* expression * expression
*/ */
public IASTExpression expression() throws Backtrack; public IASTExpression expression(IASTScope scope) throws Backtrack;
/** /**
* Is the parser configured for ANSI C or ANSI C++? * Is the parser configured for ANSI C or ANSI C++?

View file

@ -11,12 +11,13 @@
package org.eclipse.cdt.core.parser.ast; package org.eclipse.cdt.core.parser.ast;
import org.eclipse.cdt.core.parser.Enum; import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
/** /**
* @author jcamelon * @author jcamelon
* *
*/ */
public interface IASTExpression public interface IASTExpression extends ISourceElementCallbackDelegate
{ {
public class Kind extends Enum public class Kind extends Enum
{ {

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.core.parser.ast; package org.eclipse.cdt.core.parser.ast;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
@ -88,14 +89,14 @@ public interface IASTFactory
int startingOffset, int startingOffset,
int endingOffset, IASTExpression initialValue)throws ASTSemanticException; int endingOffset, IASTExpression initialValue)throws ASTSemanticException;
public IASTExpression createExpression( public IASTExpression createExpression(
IASTScope scope,
IASTExpression.Kind kind, IASTExpression.Kind kind,
IASTExpression lhs, IASTExpression lhs,
IASTExpression rhs, IASTExpression rhs,
IASTExpression thirdExpression, IASTExpression thirdExpression,
String id, IToken id,
String typeId, ITokenDuple typeId,
String literal, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException;
IASTNewExpressionDescriptor newDescriptor);
public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(); public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor();
public IASTInitializerClause createInitializerClause( public IASTInitializerClause createInitializerClause(
IASTInitializerClause.Kind kind, IASTInitializerClause.Kind kind,

View file

@ -13,11 +13,12 @@ package org.eclipse.cdt.core.parser.ast;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.parser.Enum; import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public interface IASTInitializerClause { public interface IASTInitializerClause extends ISourceElementCallbackDelegate{
public class Kind extends Enum public class Kind extends Enum
{ {

View file

@ -1786,7 +1786,7 @@ public class Scanner implements IScanner {
IParser parser = ParserFactory.createParser(trial, nullCallback, ParserMode.QUICK_PARSE ); IParser parser = ParserFactory.createParser(trial, nullCallback, ParserMode.QUICK_PARSE );
try { try {
IASTExpression exp = parser.expression(); IASTExpression exp = parser.expression(null);
if( exp.evaluateExpression() == 0 ) if( exp.evaluateExpression() == 0 )
return false; return false;
} catch( Backtrack b ) } catch( Backtrack b )

View file

@ -0,0 +1,121 @@
/**********************************************************************
* 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;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
/**
* @author jcamelon
*/
public class ASTInitializerClause implements IASTInitializerClause {
private final IASTInitializerClause.Kind kind;
private final IASTExpression assignmentExpression;
private final List initializerClauses;
/**
* @param kind
* @param assignmentExpression
* @param initializerClauses
*/
public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses) {
this.kind = kind;
this.assignmentExpression = assignmentExpression;
this.initializerClauses = initializerClauses;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getKind()
*/
public Kind getKind() {
return kind;
}
public static class EmptyIterator implements Iterator
{
/* (non-Javadoc)
* @see java.util.Iterator#hasNext()
*/
public boolean hasNext()
{
return false;
}
/* (non-Javadoc)
* @see java.util.Iterator#next()
*/
public Object next()
{
throw new NoSuchElementException();
}
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
public void remove()
{
throw new UnsupportedOperationException();
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList()
*/
public Iterator getInitializers() {
if( initializerClauses == null )
return new EmptyIterator();
return initializerClauses.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression()
*/
public IASTExpression getAssigmentExpression() {
return assignmentExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
Iterator i = getInitializers();
while( i.hasNext() )
{
IASTInitializerClause initializerClause = (IASTInitializerClause)i.next();
initializerClause.acceptElement(requestor);
}
if( assignmentExpression != null )
assignmentExpression.acceptElement( 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)
{
}
}

View file

@ -14,6 +14,7 @@ import java.util.List;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.core.parser.ast.IASTMacro; import org.eclipse.cdt.core.parser.ast.IASTMacro;
@ -59,5 +60,10 @@ public class BaseASTFactory {
return new ASTParameterDeclaration( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp, parameterName, initializerClause ); return new ASTParameterDeclaration( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp, parameterName, initializerClause );
} }
public IASTInitializerClause createInitializerClause(IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses)
{
return new ASTInitializerClause( kind, assignmentExpression, initializerClauses );
}
} }

View file

@ -0,0 +1,139 @@
/**********************************************************************
* 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.ExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTExpression implements IASTExpression
{
private final Kind kind;
private final IASTExpression lhs;
private final IASTExpression rhs;
private final IASTExpression thirdExpression;
private final String literal;
private final String typeId;
private final String id;
private final IASTNewExpressionDescriptor newDescriptor;
private final List references;
/**
*
*/
public ASTExpression( Kind kind, IASTExpression lhs, IASTExpression rhs,
IASTExpression thirdExpression, String literal, String typeId, String id, IASTNewExpressionDescriptor newDescriptor, List references )
{
this.kind = kind;
this.lhs = lhs;
this.rhs = rhs;
this.thirdExpression = thirdExpression;
this.literal = literal;
this.typeId = typeId;
this.id = id;
this.newDescriptor = newDescriptor;
this.references = references;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind()
*/
public Kind getExpressionKind()
{
return kind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression()
*/
public IASTExpression getLHSExpression()
{
return lhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getRHSExpression()
*/
public IASTExpression getRHSExpression()
{
return rhs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getThirdExpression()
*/
public IASTExpression getThirdExpression()
{
return thirdExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString()
*/
public String getLiteralString()
{
return literal;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/
public String getTypeId()
{
return typeId;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getId()
*/
public String getId()
{
return id;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor()
*/
public IASTNewExpressionDescriptor getNewExpressionDescriptor()
{
return newDescriptor;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression()
*/
public int evaluateExpression() throws ExpressionEvaluationException
{
throw new ExpressionEvaluationException();
}
public List getReferences()
{
return references;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
ASTReferenceStore store = new ASTReferenceStore( references );
store.processReferences(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)
{
}
}

View file

@ -55,5 +55,8 @@ public class ASTField extends ASTVariable implements IASTField
{ {
requestor.acceptField(this); requestor.acceptField(this);
referenceDelegate.processReferences(requestor); referenceDelegate.processReferences(requestor);
if( getInitializerClause() != null )
getInitializerClause().acceptElement(requestor);
} }
} }

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification;
import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplate; import org.eclipse.cdt.core.parser.ast.IASTTemplate;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
@ -191,7 +192,23 @@ public class ASTFunction extends ASTScope implements IASTFunction
{ {
requestor.acceptFunctionDeclaration(this); requestor.acceptFunctionDeclaration(this);
references.processReferences(requestor); references.processReferences(requestor);
processParameterInitializers(requestor);
} }
/**
* @param requestor
*/
protected void processParameterInitializers(ISourceElementRequestor requestor)
{
Iterator i = parameters.iterator();
while( i.hasNext() )
{
IASTParameterDeclaration parm = (IASTParameterDeclaration)i.next();
if( parm.getDefaultValue() != null )
parm.getDefaultValue().acceptElement(requestor);
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/ */
@ -199,6 +216,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
{ {
requestor.enterFunctionBody( this ); requestor.enterFunctionBody( this );
references.processReferences(requestor); references.processReferences(requestor);
processParameterInitializers(requestor);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)

View file

@ -123,6 +123,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
{ {
requestor.acceptMethodDeclaration(this); requestor.acceptMethodDeclaration(this);
references.processReferences(requestor); references.processReferences(requestor);
processParameterInitializers(requestor);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)

View file

@ -160,6 +160,8 @@ public class ASTVariable extends ASTSymbol implements IASTVariable
{ {
requestor.acceptVariable(this); requestor.acceptVariable(this);
referenceDelegate.processReferences(requestor); referenceDelegate.processReferences(requestor);
if( initializerClause != null )
initializerClause.acceptElement(requestor);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)

View file

@ -87,67 +87,79 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, List references ) throws ASTSemanticException protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, List references, boolean throwOnError ) throws ASTSemanticException
{ {
ISymbol result = null; ISymbol result = null;
IToken firstSymbol = null; IToken firstSymbol = null;
switch( name.length() ) try
{ {
case 0: if( name == null ) throw new ASTSemanticException();
throw new ASTSemanticException();
case 1: switch( name.length() )
firstSymbol = name.getFirstToken(); {
try case 0:
{ if( throwOnError )
result = startingScope.lookup( firstSymbol.getImage()); throw new ASTSemanticException();
if( result != null ) case 1:
references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() )); firstSymbol = name.getFirstToken();
else try
{
result = startingScope.lookup( firstSymbol.getImage());
if( result != null )
references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() ));
else
throw new ASTSemanticException();
}
catch (ParserSymbolTableException e)
{
throw new ASTSemanticException();
}
break;
case 2:
firstSymbol = name.getFirstToken();
if( firstSymbol.getType() != IToken.tCOLONCOLON )
throw new ASTSemanticException(); throw new ASTSemanticException();
}
catch (ParserSymbolTableException e)
{
throw new ASTSemanticException();
}
break;
case 2:
firstSymbol = name.getFirstToken();
if( firstSymbol.getType() != IToken.tCOLONCOLON )
throw new ASTSemanticException();
try
{
result = pst.getCompilationUnit().lookup( name.getLastToken().getImage() );
references.add( createReference( result, name.getLastToken().getImage(), name.getLastToken().getOffset() ));
}
catch( ParserSymbolTableException e)
{
throw new ASTSemanticException();
}
break;
default:
Iterator iter = name.iterator();
firstSymbol = name.getFirstToken();
result = startingScope;
if( firstSymbol.getType() == IToken.tCOLONCOLON )
result = pst.getCompilationUnit();
while( iter.hasNext() )
{
IToken t = (IToken)iter.next();
if( t.getType() == IToken.tCOLONCOLON ) continue;
try try
{ {
if( t == name.getLastToken() ) result = pst.getCompilationUnit().lookup( name.getLastToken().getImage() );
result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() ); references.add( createReference( result, name.getLastToken().getImage(), name.getLastToken().getOffset() ));
else
result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() );
references.add( createReference( result, t.getImage(), t.getOffset() ));
} }
catch( ParserSymbolTableException pste ) catch( ParserSymbolTableException e)
{ {
throw new ASTSemanticException(); throw new ASTSemanticException();
} }
} break;
default:
Iterator iter = name.iterator();
firstSymbol = name.getFirstToken();
result = startingScope;
if( firstSymbol.getType() == IToken.tCOLONCOLON )
result = pst.getCompilationUnit();
while( iter.hasNext() )
{
IToken t = (IToken)iter.next();
if( t.getType() == IToken.tCOLONCOLON ) continue;
try
{
if( t == name.getLastToken() )
result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() );
else
result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() );
references.add( createReference( result, t.getImage(), t.getOffset() ));
}
catch( ParserSymbolTableException pste )
{
throw new ASTSemanticException();
}
}
}
}
catch( ASTSemanticException se )
{
if( throwOnError )
throw se;
return null;
} }
return result; return result;
} }
@ -165,7 +177,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
List references = new ArrayList(); List references = new ArrayList();
ISymbol symbol = lookupQualifiedName( ISymbol symbol = lookupQualifiedName(
scopeToSymbol( scope), duple, references ); scopeToSymbol( scope), duple, references, true );
try { try {
((ASTScope)scope).getContainerSymbol().addUsingDirective( (IContainerSymbol)symbol ); ((ASTScope)scope).getContainerSymbol().addUsingDirective( (IContainerSymbol)symbol );
@ -212,7 +224,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
int endingOffset) throws ASTSemanticException int endingOffset) throws ASTSemanticException
{ {
List references = new ArrayList(); List references = new ArrayList();
ISymbol symbol = lookupQualifiedName( scopeToSymbol(scope), name, references ); ISymbol symbol = lookupQualifiedName( scopeToSymbol(scope), name, references, true );
try try
{ {
@ -376,7 +388,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ITokenDuple containerSymbolName = ITokenDuple containerSymbolName =
name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name
currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol,
containerSymbolName, references); containerSymbolName, references, true);
if( currentScopeSymbol == null ) if( currentScopeSymbol == null )
throw new ASTSemanticException(); throw new ASTSemanticException();
} }
@ -610,17 +622,58 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor)
*/ */
public IASTExpression createExpression( public IASTExpression createExpression(
IASTScope scope,
Kind kind, Kind kind,
IASTExpression lhs, IASTExpression lhs,
IASTExpression rhs, IASTExpression rhs,
IASTExpression thirdExpression, IASTExpression thirdExpression,
String id, IToken id,
String typeId, ITokenDuple typeId,
String literal, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException
IASTNewExpressionDescriptor newDescriptor)
{ {
// TODO FIX THIS List references = new ArrayList();
return null;
getExpressionReferences(lhs, references);
getExpressionReferences(rhs, references);
getExpressionReferences(thirdExpression,references);
//look up id & add to references
IContainerSymbol startingScope = scopeToSymbol( scope );
if( id != null )
{
try
{
ISymbol s = startingScope.lookup( id.getImage() );
if( s != null )
references.add( createReference( s, id.getImage(), id.getOffset() ));
else
throw new ASTSemanticException();
}
catch (ParserSymbolTableException e)
{
throw new ASTSemanticException();
}
}
//look up typeId & add to references
if( typeId != null )
lookupQualifiedName( startingScope, typeId, references, false );
//TODO add newDescriptor's references & add to references
return new ASTExpression( kind, lhs, rhs, thirdExpression,
id == null ? "" : id.getImage(),
typeId == null ? "" : typeId.toString(),
literal, newDescriptor, references);
}
protected void getExpressionReferences(IASTExpression expression, List references)
{
if( expression != null )
{
references.addAll( ((ASTExpression)expression).getReferences() );
}
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor() * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor()
@ -630,17 +683,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
// TODO FIX THIS // TODO FIX THIS
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createInitializerClause(org.eclipse.cdt.core.parser.ast.IASTInitializerClause.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, java.util.List)
*/
public IASTInitializerClause createInitializerClause(
org.eclipse.cdt.core.parser.ast.IASTInitializerClause.Kind kind,
IASTExpression assignmentExpression,
List initializerClauses)
{
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExceptionSpecification(java.util.List) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExceptionSpecification(java.util.List)
*/ */
@ -1263,7 +1306,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
ITokenDuple containerSymbolName = ITokenDuple containerSymbolName =
name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name
currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol,
containerSymbolName, references); containerSymbolName, references, true);
if( currentScopeSymbol == null ) if( currentScopeSymbol == null )
throw new ASTSemanticException(); throw new ASTSemanticException();
} }

View file

@ -6,6 +6,7 @@
*/ */
package org.eclipse.cdt.internal.core.parser.ast.quick; package org.eclipse.cdt.internal.core.parser.ast.quick;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException; import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTExpression;
@ -162,6 +163,27 @@ public class ASTExpression implements IASTExpression {
throw new ExpressionEvaluationException(); throw new ExpressionEvaluationException();
} }
/* (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)
{
}
} }

View file

@ -1,59 +0,0 @@
/**********************************************************************
* 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 java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
/**
* @author jcamelon
*/
public class ASTInitializerClause implements IASTInitializerClause {
private final IASTInitializerClause.Kind kind;
private final IASTExpression assignmentExpression;
private final List initializerClauses;
/**
* @param kind
* @param assignmentExpression
* @param initializerClauses
*/
public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses) {
this.kind = kind;
this.assignmentExpression = assignmentExpression;
this.initializerClauses = initializerClauses;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getKind()
*/
public Kind getKind() {
return kind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList()
*/
public Iterator getInitializers() {
return initializerClauses.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression()
*/
public IASTExpression getAssigmentExpression() {
return assignmentExpression;
}
}

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind; import org.eclipse.cdt.core.parser.ast.ASTClassKind;
@ -148,8 +149,8 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String)
*/ */
public IASTExpression createExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, String id, String typeId, String literal, IASTNewExpressionDescriptor newDescriptor) { public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IToken id, ITokenDuple typeId, String literal, IASTNewExpressionDescriptor newDescriptor) {
return new ASTExpression( kind, lhs, rhs, thirdExpression, id, typeId, literal, newDescriptor ); return new ASTExpression( kind, lhs, rhs, thirdExpression, id == null ? "" : id.getImage(), typeId == null ? "" : typeId.toString(), literal, newDescriptor );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -160,13 +161,6 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createIASTInitializerClause()
*/
public IASTInitializerClause createInitializerClause(IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses) {
return new ASTInitializerClause( kind, assignmentExpression, initializerClauses );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExceptionSpecification(java.util.List) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExceptionSpecification(java.util.List)
*/ */
public IASTExceptionSpecification createExceptionSpecification(List typeIds) public IASTExceptionSpecification createExceptionSpecification(List typeIds)