Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2004-11-09 19:50:04 +0000
committerAndrew Niefer2004-11-09 19:50:04 +0000
commit62deca89c42ce800886da20e3a1440f0b81ddcd6 (patch)
treed411f52e08122c07ce72524251aa9c58197a4919
parentf9c3dd1186109a947a9d341e5f339882ee62c466 (diff)
downloadorg.eclipse.cdt-62deca89c42ce800886da20e3a1440f0b81ddcd6.tar.gz
org.eclipse.cdt-62deca89c42ce800886da20e3a1440f0b81ddcd6.tar.xz
org.eclipse.cdt-62deca89c42ce800886da20e3a1440f0b81ddcd6.zip
Some new tests for AST2Tests.
eleborate type specs are not working yet
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java113
1 files changed, 113 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index eab7d360b07..61f08adc17f 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -46,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
+import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParserLogService;
@@ -431,4 +432,116 @@ public class AST2Tests extends TestCase {
IASTExpressionStatement s = (IASTExpressionStatement) cs.getStatements().get( 1 );
return s.getExpression();
}
+
+
+ public void testMultipleDeclarators() throws Exception {
+ IASTTranslationUnit tu = parse( "int r, s;" , ParserLanguage.C ); //$NON-NLS-1$
+ IASTSimpleDeclaration decl = (IASTSimpleDeclaration)tu.getDeclarations().get(0);
+ IASTSimpleDeclSpecifier type = (IASTSimpleDeclSpecifier)decl.getDeclSpecifier();
+ List declarators = decl.getDeclarators();
+ assertEquals( 2, declarators.size() );
+
+ IASTDeclarator dtor1 = (IASTDeclarator) declarators.get(0);
+ IASTDeclarator dtor2 = (IASTDeclarator) declarators.get(1);
+
+ IASTName name1 = dtor1.getName();
+ IASTName name2 = dtor2.getName();
+
+ assertEquals( name1.resolveBinding().getName(), "r" );
+ assertEquals( name2.resolveBinding().getName(), "s" );
+ }
+
+ public void testStructureTagScoping_1() throws Exception{
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "struct A; \n" );
+ buffer.append( "void f(){ \n" );
+ buffer.append( " struct A; \n" );
+ buffer.append( " struct A * a; \n" );
+ buffer.append( "} \n" );
+
+ IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+
+ //struct A;
+ IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations().get(0);
+ IASTCompositeTypeSpecifier compTypeSpec = (IASTCompositeTypeSpecifier) decl1.getDeclSpecifier();
+ assertEquals( 0, decl1.getDeclarators().size() );
+ IASTName nameA1 = compTypeSpec.getName();
+
+ //void f() {
+ IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations().get(1);
+ IASTDeclarator fndtor = fndef.getDeclarator();
+ IASTName namef = fndtor.getName();
+
+ IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody();
+ assertEquals( 2, compoundStatement.getStatements().size() );
+
+ // struct A;
+ IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get( 0 );
+ IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration();
+ compTypeSpec = (IASTCompositeTypeSpecifier) decl2.getDeclSpecifier();
+ assertEquals( 0, decl2.getDeclarators().size() );
+ IASTName nameA2 = compTypeSpec.getName();
+
+ // struct A * a;
+ declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get(1);
+ IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) declStatement.getDeclaration();
+ compTypeSpec = (IASTCompositeTypeSpecifier) decl3.getDeclSpecifier();
+ IASTName nameA3 = compTypeSpec.getName();
+ IASTDeclarator dtor = (IASTDeclarator) decl3.getDeclarators().get(0);
+ IASTName namea = dtor.getName();
+ assertEquals( 1, dtor.getPointerOperators().size() );
+ ICASTPointer ptrOp = (ICASTPointer) dtor.getPointerOperators().get(0);
+
+ //bindings
+ ICompositeType str1 = (ICompositeType) nameA1.resolveBinding();
+ ICompositeType str2 = (ICompositeType) nameA2.resolveBinding();
+ IVariable var = (IVariable) namea.resolveBinding();
+ ICompositeType str3 = (ICompositeType) var.getType();
+ ICompositeType str4 = (ICompositeType) nameA3.resolveBinding();
+ assertNotSame( str1, str2 );
+ assertSame( str2, str3 );
+ assertSame( str3, str4 );
+ }
+
+ public void testStructureTagScoping_2() throws Exception{
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "struct A; \n" );
+ buffer.append( "void f(){ \n" );
+ buffer.append( " struct A * a; \n" );
+ buffer.append( "} \n" );
+
+ IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+
+ //struct A;
+ IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations().get(0);
+ IASTCompositeTypeSpecifier compTypeSpec = (IASTCompositeTypeSpecifier) decl1.getDeclSpecifier();
+ assertEquals( 0, decl1.getDeclarators().size() );
+ IASTName nameA1 = compTypeSpec.getName();
+
+ //void f() {
+ IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations().get(1);
+ IASTDeclarator fndtor = fndef.getDeclarator();
+ IASTName namef = fndtor.getName();
+
+ IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody();
+ assertEquals( 1, compoundStatement.getStatements().size() );
+
+ // struct A * a;
+ IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get(0);
+ IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration();
+ compTypeSpec = (IASTCompositeTypeSpecifier) decl2.getDeclSpecifier();
+ IASTName nameA2 = compTypeSpec.getName();
+ IASTDeclarator dtor = (IASTDeclarator) decl2.getDeclarators().get(0);
+ IASTName namea = dtor.getName();
+ assertEquals( 1, dtor.getPointerOperators().size() );
+ ICASTPointer ptrOp = (ICASTPointer) dtor.getPointerOperators().get(0);
+
+ //bindings
+ ICompositeType str1 = (ICompositeType) nameA1.resolveBinding();
+ ICompositeType str2 = (ICompositeType) nameA2.resolveBinding();
+ IVariable var = (IVariable) namea.resolveBinding();
+ ICompositeType str3 = (ICompositeType) var.getType();
+ assertSame( str1, str2 );
+ assertSame( str2, str3 );
+ }
}

Back to the top