mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Hoda Amer
Core : Added references to variables with pointers in solution of bug#42453:Expression result types not computed Tests: Added tests to CompleteParseASTTest to test the expression result type for function calls that reference variables with pointers (bug#42453).
This commit is contained in:
parent
e6e17610e5
commit
6c33540aab
4 changed files with 83 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
2003-09-05 Hoda Amer
|
||||
Added tests to CompleteParseASTTest to test the expression result type
|
||||
for function calls that reference variables with pointers (bug#42453).
|
||||
|
||||
2003-09-05 John Camelon
|
||||
Added CompleteParseASTTest::testSimpleIfStatement(), testSimpleWhileStatement().
|
||||
testSimpleSwitchStatement(), testSimpleDoStatement().
|
||||
|
|
|
@ -652,6 +652,59 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
|||
assertEquals( fr2.getReferencedElement(), f1 );
|
||||
|
||||
}
|
||||
public void testExpressionResultValueWithReferenceTypesAndPointers1() throws Exception
|
||||
{
|
||||
Iterator i = parse ("class A {}; \n A * pa; \n int f(A ia){} \n int x = f(*pa);").getDeclarations();
|
||||
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTVariable a = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
IASTClassReference clr1 = (IASTClassReference) references.next();
|
||||
IASTClassReference clr2 = (IASTClassReference) references.next();
|
||||
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
|
||||
IASTVariableReference ar1 = (IASTVariableReference) references.next();
|
||||
IASTFunctionReference fr2 = (IASTFunctionReference) references.next();
|
||||
assertEquals( clr1.getReferencedElement(), cl );
|
||||
assertEquals( ar1.getReferencedElement(), a );
|
||||
assertEquals( fr2.getReferencedElement(), f1 );
|
||||
|
||||
}
|
||||
public void testExpressionResultValueWithReferenceTypesAndPointers2() throws Exception
|
||||
{
|
||||
Iterator i = parse ("class A {}; \n A * pa; \n int f(A *ia){} \n int x = f(pa);").getDeclarations();
|
||||
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTVariable a = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
IASTClassReference clr1 = (IASTClassReference) references.next();
|
||||
IASTClassReference clr2 = (IASTClassReference) references.next();
|
||||
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
|
||||
IASTVariableReference ar1 = (IASTVariableReference) references.next();
|
||||
IASTFunctionReference fr2 = (IASTFunctionReference) references.next();
|
||||
assertEquals( clr1.getReferencedElement(), cl );
|
||||
assertEquals( ar1.getReferencedElement(), a );
|
||||
assertEquals( fr2.getReferencedElement(), f1 );
|
||||
}
|
||||
public void testExpressionResultValueWithReferenceTypesAndPointers3() throws Exception
|
||||
{
|
||||
Iterator i = parse ("class A {}; \n A * pa; \n int f(A ** ia){} \n int x = f(&pa);").getDeclarations();
|
||||
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTVariable a = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
IASTClassReference clr1 = (IASTClassReference) references.next();
|
||||
IASTClassReference clr2 = (IASTClassReference) references.next();
|
||||
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
|
||||
IASTVariableReference ar1 = (IASTVariableReference) references.next();
|
||||
IASTFunctionReference fr2 = (IASTFunctionReference) references.next();
|
||||
assertEquals( clr1.getReferencedElement(), cl );
|
||||
assertEquals( ar1.getReferencedElement(), a );
|
||||
assertEquals( fr2.getReferencedElement(), f1 );
|
||||
}
|
||||
|
||||
|
||||
public void testSimpleIfStatement() throws Exception
|
||||
{
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2003-09-05 Hoda Amer
|
||||
- Added references to variables with pointers in solution
|
||||
of bug#42453:Expression result types not computed
|
||||
|
||||
2003-09-05 John Camelon
|
||||
Continue to add support for parsing within function bodies.
|
||||
Add workaround for 1.2 for inline function declaration-before-use chicken-and-egg.
|
||||
|
|
|
@ -779,6 +779,28 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
result.add(info);
|
||||
return result;
|
||||
}
|
||||
if (expression.getExpressionKind() == IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION){
|
||||
TypeInfo info = null;
|
||||
List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType();
|
||||
if( lhsResult.iterator().hasNext())
|
||||
info = (TypeInfo)lhsResult.iterator().next();
|
||||
if ((info != null) && (info.getTypeSymbol() != null)){
|
||||
info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_reference));
|
||||
}
|
||||
result.add(info);
|
||||
return result;
|
||||
}
|
||||
if (expression.getExpressionKind() == IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION){
|
||||
TypeInfo info = null;
|
||||
List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType();
|
||||
if( lhsResult.iterator().hasNext())
|
||||
info = (TypeInfo)lhsResult.iterator().next();
|
||||
if ((info != null)&& (info.getTypeSymbol() != null)){
|
||||
info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer));
|
||||
}
|
||||
result.add(info);
|
||||
return result;
|
||||
}
|
||||
if ((expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS) ){
|
||||
ASTExpression right = (ASTExpression)expression.getLHSExpression();
|
||||
|
|
Loading…
Add table
Reference in a new issue