1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Patch for Devin Steffler.

FIXED 84466 - CPPASTCastExpression should implement ICPPASTCastExpression
FIXED 84467 - [C++ Lenghts] IASTTypeIdExpression's length is too short
FIXED 84576 - [C++ Lengths] ICPPASTLinkageSpecification has 0 length
FIXED 84696 - getReferences does not find the bindings of inherited classes
This commit is contained in:
John Camelon 2005-02-08 21:57:31 +00:00
parent 69d98316f4
commit 5cd81de8ff
5 changed files with 101 additions and 7 deletions

View file

@ -72,10 +72,13 @@ import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.dom.parser.c.CFunction;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
@ -2816,4 +2819,48 @@ public class AST2Tests extends AST2BaseTest {
assertTrue( star.isVariableSized() );
}
public void testBug84696() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append( "struct A {\n int a; \n};\n" ); //$NON-NLS-1$
buffer.append( "struct B: virtual A { };\n" ); //$NON-NLS-1$
buffer.append( "struct C: B { };\n" ); //$NON-NLS-1$
buffer.append( "struct D: B { };\n" ); //$NON-NLS-1$
buffer.append( "struct E: public C, public D { };\n" ); //$NON-NLS-1$
buffer.append( "struct F: public A { };\n" ); //$NON-NLS-1$
buffer.append( "void f() {\n" ); //$NON-NLS-1$
buffer.append( "E e;\n" ); //$NON-NLS-1$
buffer.append( "e.B::a = 0;\n" ); //$NON-NLS-1$
buffer.append( "F f;\n" ); //$NON-NLS-1$
buffer.append( "f.A::a = 1;\n}\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
CPPNameCollector col = new CPPNameCollector();
CPPVisitor.visitTranslationUnit(tu, col);
assertEquals(col.size(), 26);
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding();
assertNotNull(A);
assertNotNull(B);
assertInstances( col, A, 4 );
assertInstances( col, B, 4 );
}
public void testBug84466() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append( "struct B {};\n" ); //$NON-NLS-1$
buffer.append( "struct D : B {};\n" ); //$NON-NLS-1$
buffer.append( "void foo(D* dp)\n{\n" ); //$NON-NLS-1$
buffer.append( "B* bp = dynamic_cast<B*>(dp);\n}\n" ); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
ICPPASTCastExpression dynamic_cast = (ICPPASTCastExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)((IASTDeclarationStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[2]).getBody()).getStatements()[0]).getDeclaration()).getDeclarators()[0].getInitializer()).getExpression();
assertEquals(dynamic_cast.getOperator(), ICPPASTCastExpression.op_dynamic_cast);
}
}

View file

@ -10,6 +10,7 @@
**********************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
@ -18,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
@ -37,9 +39,12 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.parser.ParserException;
@ -328,5 +333,26 @@ public class DOMLocationTests extends AST2BaseTest {
assertSoleLocation( third_if, third_if_start, total_if_end - third_if_start );
}
}
public void testBug84467() throws Exception
{
String code = "class D { };\n D d1;\n const D d2;\n void foo() {\n typeid(d1) == typeid(d2);\n }"; //$NON-NLS-1$
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
IASTBinaryExpression bexp = (IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[3]).getBody()).getStatements()[0]).getExpression();
IASTTypeIdExpression exp = (IASTTypeIdExpression)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[3]).getBody()).getStatements()[0]).getExpression()).getOperand1();
assertSoleLocation( bexp, code.indexOf( "typeid(d1) == typeid(d2)"), "typeid(d1) == typeid(d2)".length() ); //$NON-NLS-1$ //$NON-NLS-2$
assertSoleLocation( exp, code.indexOf( "typeid(d1)"), "typeid(d1)".length() ); //$NON-NLS-1$ //$NON-NLS-2$
exp = (IASTTypeIdExpression)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[3]).getBody()).getStatements()[0]).getExpression()).getOperand2();
assertSoleLocation( exp, code.indexOf( "typeid(d2)"), "typeid(d2)".length() ); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testBug84576() throws Exception
{
String code = "namespace A {\n extern \"C\" int g();\n }"; //$NON-NLS-1$
IASTTranslationUnit tu = parse( code, ParserLanguage.CPP );
ICPPASTLinkageSpecification spec = (ICPPASTLinkageSpecification)((ICPPASTNamespaceDefinition)tu.getDeclarations()[0]).getDeclarations()[0];
assertSoleLocation( spec, code.indexOf( "extern \"C\""), "extern \"C\"".length() ); //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -10,14 +10,14 @@
**********************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
/**
* @author jcamelon
*/
public class CPPASTCastExpression extends CPPASTUnaryExpression implements
IASTCastExpression {
ICPPASTCastExpression {
private IASTTypeId typeId;
/* (non-Javadoc)

View file

@ -808,7 +808,8 @@ public class CPPVisitor {
prop == ICPPASTPointerToMember.NAME ||
prop == ICPPASTTypenameExpression.TYPENAME ||
prop == ICPPASTUsingDeclaration.NAME ||
prop == ICPPASTQualifiedName.SEGMENT_NAME)
prop == ICPPASTQualifiedName.SEGMENT_NAME ||
prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME)
break;
else if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ){
IASTNode p = name.getParent().getParent();
@ -827,7 +828,8 @@ public class CPPVisitor {
prop == ICPPASTUsingDeclaration.NAME ||
prop == IASTFunctionCallExpression.FUNCTION_NAME ||
prop == ICPPASTUsingDeclaration.NAME ||
prop == ICPPASTQualifiedName.SEGMENT_NAME)
prop == ICPPASTQualifiedName.SEGMENT_NAME ||
prop == IASTNamedTypeSpecifier.NAME)
{
break;
}
@ -842,7 +844,8 @@ public class CPPVisitor {
return PROCESS_CONTINUE;
}
if( CharArrayUtils.equals(name.toCharArray(), binding.getNameCharArray()) &&
if( binding != null &&
CharArrayUtils.equals(name.toCharArray(), binding.getNameCharArray()) &&
name.resolveBinding() == binding ){
if( refs.length == idx ){
IASTName [] temp = new IASTName[ refs.length * 2 ];

View file

@ -147,6 +147,10 @@ import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
*/
public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private static final String CONST_CAST = "const_cast"; //$NON-NLS-1$
private static final String REINTERPRET_CAST = "reinterpret_cast"; //$NON-NLS-1$
private static final String STATIC_CAST = "static_cast"; //$NON-NLS-1$
private static final String DYNAMIC_CAST = "dynamic_cast"; //$NON-NLS-1$
private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE = 4;
private ScopeStack templateIdScopes = new ScopeStack();
protected CPPASTTranslationUnit translationUnit;
@ -1422,7 +1426,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
isTypeId = false;
lhs = expression();
}
lastOffset = consume(IToken.tRPAREN).getOffset();
lastOffset = consume(IToken.tRPAREN).getEndOffset();
if (templateIdScopes.size() > 0) {
templateIdScopes.pop();
}
@ -1784,7 +1788,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
protected IASTExpression specialCastExpression(int kind)
throws EndOfFileException, BacktrackException {
int startingOffset = LA(1).getOffset();
consume();
IToken op = consume();
consume(IToken.tLT);
IASTTypeId typeID = typeId(false, false);
consume(IToken.tGT);
@ -1797,6 +1801,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
typeID.setParent(result);
typeID.setPropertyInParent(IASTCastExpression.TYPE_ID);
result.setOperand(lhs);
if (op.toString().equals(DYNAMIC_CAST)) {
result.setOperator(ICPPASTCastExpression.op_dynamic_cast);
} else if (op.toString().equals(STATIC_CAST)) {
result.setOperator(ICPPASTCastExpression.op_static_cast);
} else if (op.toString().equals(REINTERPRET_CAST)) {
result.setOperator(ICPPASTCastExpression.op_reinterpret_cast);
} else if (op.toString().equals(CONST_CAST)) {
result.setOperator(ICPPASTCastExpression.op_const_cast);
} else {
result.setOperator(IASTCastExpression.op_cast);
}
lhs.setParent(result);
lhs.setPropertyInParent(IASTCastExpression.OPERAND);
return result;
@ -1929,6 +1946,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
ICPPASTLinkageSpecification linkage = createLinkageSpecification();
((ASTNode) linkage).setOffset(firstToken.getOffset());
linkage.setLiteral(spec.getImage());
((ASTNode) linkage).setLength(spec.getEndOffset() - firstToken.getOffset());
if (LT(1) == IToken.tLBRACE) {
consume(IToken.tLBRACE);