mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
More Tests for C++ bindings
This commit is contained in:
parent
ef21d7a687
commit
73f50ce64b
13 changed files with 502 additions and 38 deletions
|
@ -16,6 +16,7 @@ import junit.framework.TestSuite;
|
|||
|
||||
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
||||
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.GCCTests;
|
||||
import org.eclipse.cdt.core.parser.tests.parser2.CompleteParser2Tests;
|
||||
|
@ -57,6 +58,7 @@ public class ParserTestSuite extends TestCase {
|
|||
suite.addTest( GCCParserExtensionTestSuite.suite() );
|
||||
suite.addTestSuite( AST2Tests.class );
|
||||
suite.addTestSuite( GCCTests.class );
|
||||
suite.addTestSuite( AST2CPPTests.class );
|
||||
suite.addTestSuite( QuickParser2Tests.class );
|
||||
suite.addTestSuite( CompleteParser2Tests.class );
|
||||
return suite;
|
||||
|
|
|
@ -737,5 +737,29 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertTrue( ((IPointerType) ft.getReturnType()).getType() instanceof IFunctionType );
|
||||
assertEquals( ft.getParameterTypes().length, 1 );
|
||||
}
|
||||
|
||||
public void testFunctionDeclarations() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("typedef int Int; \n"); //$NON-NLS-1$
|
||||
buffer.append("void f( int i ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void f( const int ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void f( Int i ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void g( char * ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void g( char [] ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void h( int()() ); \n"); //$NON-NLS-1$
|
||||
buffer.append("void h( int (*) () ); \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
CPPNameCollector collector = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, collector );
|
||||
|
||||
IFunction f = (IFunction) collector.getName( 1 ).resolveBinding();
|
||||
IFunction g = (IFunction) collector.getName( 8 ).resolveBinding();
|
||||
IFunction h = (IFunction) collector.getName( 12 ).resolveBinding();
|
||||
|
||||
assertInstances( collector, f, 3 );
|
||||
assertInstances( collector, g, 2 );
|
||||
assertInstances( collector, h, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,30 @@ package org.eclipse.cdt.core.parser.tests.parser2;
|
|||
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
|
@ -29,6 +49,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguratio
|
|||
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
|
@ -45,6 +66,31 @@ public class CompleteParser2Tests extends TestCase {
|
|||
|
||||
private static final NullLogService NULL_LOG = new NullLogService();
|
||||
|
||||
static private class CPPNameCollector extends CPPVisitor.CPPBaseVisitorAction {
|
||||
{
|
||||
processNames = true;
|
||||
}
|
||||
public List nameList = new ArrayList();
|
||||
public boolean processName( IASTName name ){
|
||||
nameList.add( name );
|
||||
return true;
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
if( idx < 0 || idx >= nameList.size() )
|
||||
return null;
|
||||
return (IASTName) nameList.get( idx );
|
||||
}
|
||||
public int size() { return nameList.size(); }
|
||||
}
|
||||
|
||||
protected void assertInstances( CPPNameCollector nameCollector, IBinding binding, int num ) throws Exception {
|
||||
int count = 0;
|
||||
for( int i = 0; i < nameCollector.size(); i++ )
|
||||
if( nameCollector.getName( i ).resolveBinding() == binding )
|
||||
count++;
|
||||
|
||||
assertEquals( count, num );
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit parse(String code, boolean expectedToPass,
|
||||
ParserLanguage lang) throws Exception {
|
||||
|
@ -116,87 +162,283 @@ public class CompleteParser2Tests extends TestCase {
|
|||
|
||||
public void testSimpleNamespace() throws Exception
|
||||
{
|
||||
parse( "namespace A { }").getDeclarations(); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "namespace A { }"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 1 );
|
||||
assertTrue( col.getName(0).resolveBinding() instanceof ICPPNamespace );
|
||||
}
|
||||
|
||||
public void testMultipleNamespaceDefinitions() throws Exception
|
||||
{
|
||||
parse( "namespace A { } namespace A { }"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "namespace A { } namespace A { }"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 2 );
|
||||
ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||
assertInstances( col, A, 2 );
|
||||
}
|
||||
|
||||
public void testNestedNamespaceDefinitions() throws Exception
|
||||
{
|
||||
parse( "namespace A { namespace B { } }"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "namespace A { namespace B { } }"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 2 );
|
||||
ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||
ICPPNamespace B = (ICPPNamespace) col.getName(1).resolveBinding();
|
||||
|
||||
assertSame( A.getNamespaceScope(), B.getNamespaceScope().getParent() );
|
||||
}
|
||||
|
||||
public void testEmptyClassDeclaration() throws Exception
|
||||
{
|
||||
parse( "class A { };"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "class A { };"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 1 );
|
||||
assertTrue( col.getName(0).resolveBinding() instanceof ICPPClassType );
|
||||
}
|
||||
|
||||
public void testSimpleSubclass() throws Exception
|
||||
{
|
||||
parse( "class A { }; class B : public A { };"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "class A { }; class B : public A { };"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 3 );
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding();
|
||||
|
||||
assertInstances( col, A, 2 );
|
||||
|
||||
assertEquals( B.getBases().length, 1 );
|
||||
ICPPBase base = B.getBases()[0];
|
||||
assertSame( base.getBaseClass(), A );
|
||||
assertEquals( base.getVisibility(), ICPPBase.v_public );
|
||||
assertFalse( base.isVirtual() );
|
||||
}
|
||||
|
||||
public void testNestedSubclass() throws Exception
|
||||
{
|
||||
parse( "namespace N { class A { }; } class B : protected virtual N::A { };"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "namespace N { class A { }; } class B : protected virtual N::A { };"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 6 );
|
||||
ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||
ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding();
|
||||
ICPPClassType B = (ICPPClassType) col.getName(2).resolveBinding();
|
||||
|
||||
assertInstances( col, N, 2 );
|
||||
assertInstances( col, A, 3 );
|
||||
assertInstances( col, B, 1 );
|
||||
|
||||
assertSame( A.getScope(), N.getNamespaceScope() );
|
||||
|
||||
ICPPBase base = B.getBases()[0];
|
||||
assertSame( base.getBaseClass(), A );
|
||||
assertTrue( base.isVirtual() );
|
||||
assertEquals( base.getVisibility(), ICPPBase.v_protected );
|
||||
}
|
||||
|
||||
public void testSimpleVariable() throws Exception
|
||||
{
|
||||
parse( "int x;"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "int x;"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 1 );
|
||||
IVariable x = (IVariable) col.getName(0).resolveBinding();
|
||||
|
||||
assertTrue( x.getType() instanceof IBasicType );
|
||||
IBasicType t = (IBasicType) x.getType();
|
||||
assertEquals( t.getType(), IBasicType.t_int );
|
||||
}
|
||||
|
||||
public void testSimpleClassReferenceVariable() throws Exception
|
||||
{
|
||||
parse( "class A { }; A x;"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "class A { }; A x;"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 3 );
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
IVariable x = (IVariable) col.getName(2).resolveBinding();
|
||||
|
||||
assertInstances( col, A, 2 );
|
||||
assertSame( x.getType(), A );
|
||||
}
|
||||
|
||||
public void testNestedClassReferenceVariable() throws Exception
|
||||
{
|
||||
parse( "namespace N { class A { }; } N::A x;"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "namespace N { class A { }; } N::A x;"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 6 );
|
||||
ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||
ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding();
|
||||
IVariable x = (IVariable) col.getName(5).resolveBinding();
|
||||
|
||||
assertInstances( col, N, 2 );
|
||||
assertInstances( col, A, 3 );
|
||||
assertSame( x.getType(), A );
|
||||
assertSame( A.getScope(), N.getNamespaceScope() );
|
||||
}
|
||||
|
||||
public void testMultipleDeclaratorsVariable() throws Exception
|
||||
{
|
||||
parse( "class A { }; A x, y, z;"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "class A { }; A x, y, z;"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 5 );
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
IVariable x = (IVariable) col.getName(2).resolveBinding();
|
||||
IVariable y = (IVariable) col.getName(3).resolveBinding();
|
||||
IVariable z = (IVariable) col.getName(4).resolveBinding();
|
||||
|
||||
assertInstances( col, A, 2 );
|
||||
assertSame( A, x.getType() );
|
||||
assertSame( x.getType(), y.getType() );
|
||||
assertSame( y.getType(), z.getType() );
|
||||
}
|
||||
|
||||
public void testSimpleField() throws Exception
|
||||
{
|
||||
parse( "class A { double x; };"); //$NON-NLS-1$
|
||||
}
|
||||
IASTTranslationUnit tu = parse( "class A { double x; };"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 2 );
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
ICPPField x = (ICPPField) col.getName(1).resolveBinding();
|
||||
|
||||
assertSame( x.getScope(), A.getCompositeScope() );
|
||||
List fields = A.getFields();
|
||||
assertEquals( fields.size(), 1 );
|
||||
assertSame( fields.get(0), x );
|
||||
}
|
||||
|
||||
public void testUsingClauses() throws Exception
|
||||
{
|
||||
parse( "namespace A { namespace B { int x; class C { static int y = 5; }; } } \n using namespace A::B;\n using A::B::x;using A::B::C;using A::B::C::y;"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "namespace A { namespace B { int x; class C { static int y = 5; }; } } \n using namespace A::B;\n using A::B::x;using A::B::C;using A::B::C::y;"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 21 );
|
||||
ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||
ICPPNamespace B = (ICPPNamespace) col.getName(1).resolveBinding();
|
||||
IVariable x = (IVariable) col.getName(2).resolveBinding();
|
||||
ICPPClassType C = (ICPPClassType) col.getName(3).resolveBinding();
|
||||
ICPPField y = (ICPPField) col.getName(4).resolveBinding();
|
||||
|
||||
assertInstances( col, A, 5 );
|
||||
assertInstances( col, B, 6 );
|
||||
assertInstances( col, x, 3 );
|
||||
assertInstances( col, C, 4 );
|
||||
assertInstances( col, y, 3 );
|
||||
}
|
||||
|
||||
public void testEnumerations() throws Exception
|
||||
{
|
||||
parse( "namespace A { enum E { e1, e2, e3 }; E varE;}"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "namespace A { enum E { e1, e2, e3 }; E varE;}"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 7 );
|
||||
ICPPNamespace A = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||
IEnumeration E = (IEnumeration) col.getName(1).resolveBinding();
|
||||
IEnumerator e1 = (IEnumerator) col.getName(2).resolveBinding();
|
||||
IEnumerator e2 = (IEnumerator) col.getName(3).resolveBinding();
|
||||
IEnumerator e3 = (IEnumerator) col.getName(4).resolveBinding();
|
||||
IVariable varE = (IVariable) col.getName(6).resolveBinding();
|
||||
|
||||
assertInstances( col, E, 2 );
|
||||
assertSame( E.getScope(), A.getNamespaceScope() );
|
||||
assertSame( e1.getScope(), A.getNamespaceScope() );
|
||||
assertNotNull( e2 );
|
||||
assertNotNull( e3 );
|
||||
assertNotNull( varE );
|
||||
}
|
||||
|
||||
public void testSimpleFunction() throws Exception
|
||||
{
|
||||
parse( "void foo( void );"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "void foo( void );"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 2 );
|
||||
IFunction foo = (IFunction) col.getName(0).resolveBinding();
|
||||
IParameter p = (IParameter) col.getName(1).resolveBinding();
|
||||
|
||||
assertEquals( foo.getParameters().size(), 1 );
|
||||
assertSame( foo.getParameters().get(0), p );
|
||||
assertSame( p.getScope(), foo.getFunctionScope() );
|
||||
}
|
||||
|
||||
public void testSimpleFunctionWithTypes() throws Exception
|
||||
{
|
||||
parse( "class A { public: \n class B { }; }; const A::B & foo( A * myParam );"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "class A { public: \n class B { }; }; const A::B & foo( A * myParam );"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 8 );
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
ICPPClassType B = (ICPPClassType) col.getName(1).resolveBinding();
|
||||
IFunction foo = (IFunction) col.getName(5).resolveBinding();
|
||||
IParameter p = (IParameter) col.getName(7).resolveBinding();
|
||||
|
||||
assertInstances( col, A, 3 );
|
||||
assertInstances( col, B, 3 );
|
||||
|
||||
IFunctionType ftype = foo.getType();
|
||||
assertTrue( ftype.getReturnType() instanceof ICPPReferenceType );
|
||||
ICPPReferenceType rt = (ICPPReferenceType) ftype.getReturnType();
|
||||
assertTrue( rt.getType() instanceof IQualifierType );
|
||||
assertSame( ((IQualifierType)rt.getType()).getType(), B );
|
||||
|
||||
IType pt = ftype.getParameterTypes()[0];
|
||||
assertEquals( p.getType(), pt );
|
||||
assertTrue( pt instanceof IPointerType );
|
||||
assertSame( ((IPointerType) pt).getType(), A );
|
||||
}
|
||||
|
||||
public void testSimpleMethod() throws Exception
|
||||
{
|
||||
parse( "class A { void foo(); };"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "class A { void foo(); };"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 2 );
|
||||
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
ICPPMethod foo = (ICPPMethod) col.getName(1).resolveBinding();
|
||||
|
||||
assertSame( foo.getScope(), A.getCompositeScope() );
|
||||
}
|
||||
|
||||
public void testSimpleMethodWithTypes() throws Exception
|
||||
{
|
||||
parse( "class U { }; class A { U foo( U areDumb ); };"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "class U { }; class A { U foo( U areDumb ); };"); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
CPPVisitor.visitTranslationUnit( tu, col );
|
||||
|
||||
assertEquals( col.size(), 6 );
|
||||
ICPPClassType U = (ICPPClassType) col.getName(0).resolveBinding();
|
||||
ICPPClassType A = (ICPPClassType) col.getName(1).resolveBinding();
|
||||
ICPPMethod foo = (ICPPMethod) col.getName(3).resolveBinding();
|
||||
IParameter p = (IParameter) col.getName(5).resolveBinding();
|
||||
|
||||
assertInstances( col, U, 3 );
|
||||
assertSame( foo.getScope(), A.getCompositeScope() );
|
||||
IFunctionType ft = foo.getType();
|
||||
assertSame( ft.getReturnType(), U );
|
||||
assertSame( p.getType(), U );
|
||||
}
|
||||
|
||||
public void testUsingDeclarationWithFunctionsAndMethods() throws Exception
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
||||
/**
|
||||
* Represents the relationship between a class and one of its base classes.
|
||||
*
|
||||
|
@ -32,9 +34,9 @@ public interface ICPPBase {
|
|||
*/
|
||||
public int getVisibility();
|
||||
|
||||
public static final int v_private = 1;
|
||||
public static final int v_protected = 2;
|
||||
public static final int v_public = 3;
|
||||
public static final int v_private = ICPPASTBaseSpecifier.v_private;
|
||||
public static final int v_protected = ICPPASTBaseSpecifier.v_protected;
|
||||
public static final int v_public = ICPPASTBaseSpecifier.v_public;
|
||||
|
||||
/**
|
||||
* Whether this is a virtual base class.
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*******************************************************************************
|
||||
* 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 Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Dec 15, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPBaseClause implements ICPPBase {
|
||||
ICPPASTBaseSpecifier base = null;
|
||||
|
||||
public CPPBaseClause( ICPPASTBaseSpecifier base ){
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBase#getBaseClass()
|
||||
*/
|
||||
public ICPPClassType getBaseClass() {
|
||||
return (ICPPClassType) base.getName().resolveBinding();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBase#getVisibility()
|
||||
*/
|
||||
public int getVisibility() {
|
||||
return base.getVisibility();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBase#isVirtual()
|
||||
*/
|
||||
public boolean isVirtual() {
|
||||
return base.isVirtual();
|
||||
}
|
||||
|
||||
}
|
|
@ -34,6 +34,9 @@ public class CPPBasicType implements ICPPBasicType {
|
|||
}
|
||||
|
||||
public boolean equals( Object object ) {
|
||||
if( object instanceof CPPTypedef )
|
||||
return object.equals( this );
|
||||
|
||||
if( !(object instanceof CPPBasicType) )
|
||||
return false;
|
||||
|
||||
|
|
|
@ -13,16 +13,23 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -38,12 +45,41 @@ public class CPPClassType implements ICPPClassType {
|
|||
declarations = new ICPPASTElaboratedTypeSpecifier[] { (ICPPASTElaboratedTypeSpecifier) declSpec };
|
||||
}
|
||||
|
||||
private ICPPASTCompositeTypeSpecifier checkForDefinition( IASTElaboratedTypeSpecifier declSpec ){
|
||||
//TODO
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
|
||||
*/
|
||||
public List getFields() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
if( definition == null ){
|
||||
ICPPASTCompositeTypeSpecifier temp = checkForDefinition( declarations[0] );
|
||||
if( temp == null )
|
||||
return null; //TODO IProblem
|
||||
definition = temp;
|
||||
}
|
||||
|
||||
IASTDeclaration[] members = definition.getMembers();
|
||||
int size = members.length;
|
||||
List fields = new ArrayList( size );
|
||||
if( size > 0 ){
|
||||
|
||||
for( int i = 0; i < size; i++ ){
|
||||
IASTNode node = members[i];
|
||||
if( node instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator[] declarators = ((IASTSimpleDeclaration)node).getDeclarators();
|
||||
for( int j = 0; j < declarators.length; j++ ){
|
||||
IASTDeclarator declarator = declarators[i];
|
||||
IBinding binding = declarator.getName().resolveBinding();
|
||||
if( binding != null && binding instanceof IField )
|
||||
fields.add( binding );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -121,8 +157,18 @@ public class CPPClassType implements ICPPClassType {
|
|||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases()
|
||||
*/
|
||||
public ICPPBase [] getBases() {
|
||||
// TODO Auto-generated method stub
|
||||
return ICPPBase.EMPTY_BASE_ARRAY;
|
||||
if( definition == null )
|
||||
return null; //TODO
|
||||
ICPPASTBaseSpecifier [] bases = definition.getBaseSpecifiers();
|
||||
if( bases.length == 0 )
|
||||
return ICPPBase.EMPTY_BASE_ARRAY;
|
||||
|
||||
ICPPBase [] bindings = new ICPPBase[ bases.length ];
|
||||
for( int i = 0; i < bases.length; i++ ){
|
||||
bindings[i] = new CPPBaseClause( bases[i] );
|
||||
}
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
|
||||
/**
|
||||
|
@ -40,6 +41,18 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
if( o instanceof ITypedef )
|
||||
return o.equals( this );
|
||||
if( !( o instanceof CPPPointerType ) )
|
||||
return false;
|
||||
|
||||
CPPPointerType pt = (CPPPointerType) o;
|
||||
if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() )
|
||||
return type.equals( pt.getType() );
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IPointerType#getType()
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
|
||||
/**
|
||||
|
@ -32,6 +33,18 @@ public class CPPQualifierType implements IQualifierType, ITypeContainer {
|
|||
this.isVolatile = isVolatile;
|
||||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
if( o instanceof ITypedef )
|
||||
return o.equals( this );
|
||||
if( !( o instanceof CPPQualifierType ) )
|
||||
return false;
|
||||
|
||||
CPPQualifierType pt = (CPPQualifierType) o;
|
||||
if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() )
|
||||
return type.equals( pt.getType() );
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IQualifierType#isConst()
|
||||
*/
|
||||
|
|
|
@ -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 Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Dec 15, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPReferenceType implements ICPPReferenceType {
|
||||
IType type = null;
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @param operator
|
||||
*/
|
||||
public CPPReferenceType( IType type ) {
|
||||
this.type = type;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType#getType()
|
||||
*/
|
||||
public IType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
|
@ -284,10 +284,26 @@ public class CPPSemantics {
|
|||
return data;
|
||||
}
|
||||
|
||||
static private ICPPScope getLookupScope( IASTName name ){
|
||||
IASTNode parent = name.getParent();
|
||||
|
||||
if( parent instanceof IASTDeclSpecifier ){
|
||||
IASTNode node = parent.getParent();
|
||||
if( node instanceof IASTParameterDeclaration ){
|
||||
IASTNode n = CPPVisitor.getContainingBlockItem( parent );
|
||||
return (ICPPScope) CPPVisitor.getContainingScope( n );
|
||||
}
|
||||
} else if( parent instanceof ICPPASTBaseSpecifier ) {
|
||||
IASTNode n = CPPVisitor.getContainingBlockItem( parent );
|
||||
return (ICPPScope) CPPVisitor.getContainingScope( n );
|
||||
}
|
||||
return (ICPPScope) CPPVisitor.getContainingScope( name );
|
||||
}
|
||||
|
||||
static private void lookup( CPPSemantics.LookupData data, IASTName name ){
|
||||
IASTNode node = name;
|
||||
|
||||
ICPPScope scope = (ICPPScope) CPPVisitor.getContainingScope( node );
|
||||
ICPPScope scope = getLookupScope( name );
|
||||
while( scope != null ){
|
||||
IASTNode blockItem = CPPVisitor.getContainingBlockItem( node );
|
||||
if( scope.getPhysicalNode() != blockItem.getParent() )
|
||||
|
|
|
@ -35,6 +35,16 @@ public class CPPTypedef implements ITypedef, ITypeContainer {
|
|||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
if( o instanceof ITypedef )
|
||||
return getType().equals( ((ITypedef)o).getType());
|
||||
|
||||
if( !( o instanceof IType ) )
|
||||
return false;
|
||||
|
||||
return getType().equals( o );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ITypedef#getType()
|
||||
*/
|
||||
|
|
|
@ -65,6 +65,7 @@ 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.IASTWhileStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
|
@ -90,6 +91,7 @@ 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.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
|
@ -204,9 +206,10 @@ public class CPPVisitor {
|
|||
ICPPASTNamespaceDefinition namespaceDef = (ICPPASTNamespaceDefinition) declaration;
|
||||
ICPPScope scope = (ICPPScope) getContainingScope( namespaceDef );
|
||||
CPPNamespace binding = (CPPNamespace) scope.getBinding( namespaceDef.getName() );
|
||||
if( binding == null )
|
||||
if( binding == null ){
|
||||
binding = new CPPNamespace( namespaceDef );
|
||||
else
|
||||
scope.addBinding( binding );
|
||||
} else
|
||||
binding.addDefinition( namespaceDef );
|
||||
return binding;
|
||||
} else if( declaration instanceof ICPPASTUsingDirective ){
|
||||
|
@ -842,17 +845,12 @@ public class CPPVisitor {
|
|||
//so only create the base type from the declspec and not the qualifiers
|
||||
pt = getBaseType( pDeclSpec );
|
||||
|
||||
pt = getPointerTypes( pt, pDtor );
|
||||
pt = createType( pt, pDtor );
|
||||
|
||||
//any parameter of type array of T is adjusted to be pointer to T
|
||||
if( pDtor instanceof IASTArrayDeclarator ){
|
||||
IASTArrayModifier [] mods = ((IASTArrayDeclarator)pDtor).getArrayModifiers();
|
||||
for( int j = 0; j < mods.length - 1; j++ ){
|
||||
pt = new CPPArrayType( pt );
|
||||
}
|
||||
if( mods.length > 0 ){
|
||||
pt = new CPPPointerType( pt );
|
||||
}
|
||||
if( pt instanceof IArrayType ){
|
||||
IArrayType at = (IArrayType) pt;
|
||||
pt = new CPPPointerType( at.getType() );
|
||||
}
|
||||
|
||||
//any parameter to type function returning T is adjusted to be pointer to function
|
||||
|
@ -895,7 +893,10 @@ public class CPPVisitor {
|
|||
private static IType getPointerTypes( IType type, IASTDeclarator declarator ){
|
||||
IASTPointerOperator [] ptrOps = declarator.getPointerOperators();
|
||||
for( int i = ptrOps.length - 1; i >= 0; i-- ){
|
||||
type = new CPPPointerType( type, (IASTPointer) ptrOps[i] );
|
||||
if( ptrOps[i] instanceof IASTPointer )
|
||||
type = new CPPPointerType( type, (IASTPointer) ptrOps[i] );
|
||||
else if( ptrOps[i] instanceof ICPPASTReferenceOperator )
|
||||
type = new CPPReferenceType( type );
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue