1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 02:06:01 +02:00

Bug 302412: Syntax for c++0x initializer lists

This commit is contained in:
Markus Schorn 2010-02-17 16:23:57 +00:00
parent 608c4287b4
commit 1fc47b91e1
93 changed files with 3757 additions and 2846 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others. * Copyright (c) 2009, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -27,17 +27,23 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
public class ASTComparer extends Assert { public class ASTComparer extends Assert {
private static Set<String> methodsToIgnore = new HashSet<String>(Arrays.asList( private static Set<String> methodsToIgnore = new HashSet<String>(Arrays.asList(
// prevent infinite recursion // Prevent infinite recursion
"getParent", "getParent",
"getTranslationUnit", "getTranslationUnit",
"getLastName", "getLastName",
// original is usually frozen but copy must not be
"isFrozen", // Exponential complexity
// these methods are problematic "getOperand2", // duplicates getInitOperand2()
"getChildren", "getChildren",
"getProblem",
// Can be different in copy
"isFrozen",
"getContainingFilename", "getContainingFilename",
// ignore preprocessor nodes
// These methods are problematic
"getProblem",
// Ignore preprocessor nodes
"getMacroDefinitions", "getMacroDefinitions",
"getBuiltinMacroDefinitions", "getBuiltinMacroDefinitions",
"getIncludeDirectives", "getIncludeDirectives",
@ -45,7 +51,8 @@ public class ASTComparer extends Assert {
"getMacroExpansions", "getMacroExpansions",
"getPreprocessorProblems", "getPreprocessorProblems",
"getComments", "getComments",
// avoid name resolution
// Avoid name resolution
"isDeclaration", "isDeclaration",
"isDefinition", "isDefinition",
"isReference", "isReference",
@ -86,6 +93,9 @@ public class ASTComparer extends Assert {
if(methodsToIgnore.contains(getter.getName())) if(methodsToIgnore.contains(getter.getName()))
continue; continue;
if (getter.getAnnotation(Deprecated.class) != null)
continue;
try { try {
Class returnType = getter.getReturnType(); Class returnType = getter.getReturnType();

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -38,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
@ -356,6 +357,11 @@ public class AST2BaseTest extends BaseTestCase {
assertEquals(num, count); assertEquals(num, count);
} }
protected void isExpressionStringEqual(IASTInitializerClause exp, String str) {
String expressionString = ASTSignatureUtil.getExpressionString((IASTExpression) exp);
assertEquals(str, expressionString);
}
protected void isExpressionStringEqual(IASTExpression exp, String str) { protected void isExpressionStringEqual(IASTExpression exp, String str) {
String expressionString = ASTSignatureUtil.getExpressionString(exp); String expressionString = ASTSignatureUtil.getExpressionString(exp);
assertEquals(str, expressionString); assertEquals(str, expressionString);

View file

@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -43,7 +44,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -1623,9 +1623,8 @@ public class AST2CPPTests extends AST2BaseTest {
String code = "int x = ::ABC::DEF::ghi;"; //$NON-NLS-1$ String code = "int x = ::ABC::DEF::ghi;"; //$NON-NLS-1$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP); IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
IASTSimpleDeclaration x = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTSimpleDeclaration x = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTInitializerExpression e = (IASTInitializerExpression) x IASTEqualsInitializer e = (IASTEqualsInitializer) x.getDeclarators()[0].getInitializer();
.getDeclarators()[0].getInitializer(); IASTIdExpression id = (IASTIdExpression) e.getInitializerClause();
IASTIdExpression id = (IASTIdExpression) e.getExpression();
ICPPASTQualifiedName name = (ICPPASTQualifiedName) id.getName(); ICPPASTQualifiedName name = (ICPPASTQualifiedName) id.getName();
assertTrue(name.isFullyQualified()); assertTrue(name.isFullyQualified());
assertEquals(name.getNames().length, 3); assertEquals(name.getNames().length, 3);
@ -4435,10 +4434,10 @@ public class AST2CPPTests extends AST2BaseTest {
// } // }
public void testBug84466() throws Exception { public void testBug84466() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
ICPPASTCastExpression dynamic_cast = (ICPPASTCastExpression) ((IASTInitializerExpression) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu ICPPASTCastExpression dynamic_cast = (ICPPASTCastExpression) ((IASTEqualsInitializer) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu
.getDeclarations()[2]).getBody()).getStatements()[0]) .getDeclarations()[2]).getBody()).getStatements()[0])
.getDeclaration()).getDeclarators()[0].getInitializer()) .getDeclaration()).getDeclarators()[0].getInitializer())
.getExpression(); .getInitializerClause();
assertEquals(dynamic_cast.getOperator(), assertEquals(dynamic_cast.getOperator(),
ICPPASTCastExpression.op_dynamic_cast); ICPPASTCastExpression.op_dynamic_cast);
@ -5580,8 +5579,8 @@ public class AST2CPPTests extends AST2BaseTest {
public void testLongLiteral_225534() throws Exception { public void testLongLiteral_225534() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
IASTDeclarator decltor= ((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclarators()[0]; IASTDeclarator decltor= ((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclarators()[0];
IASTInitializerExpression init= (IASTInitializerExpression) decltor.getInitializer(); IASTEqualsInitializer init= (IASTEqualsInitializer) decltor.getInitializer();
ICPPASTLiteralExpression exp= (ICPPASTLiteralExpression) init.getExpression(); ICPPASTLiteralExpression exp= (ICPPASTLiteralExpression) init.getInitializerClause();
ICPPBasicType type= (ICPPBasicType) exp.getExpressionType(); ICPPBasicType type= (ICPPBasicType) exp.getExpressionType();
assertTrue(type.isLong()); assertTrue(type.isLong());
} }
@ -8045,5 +8044,38 @@ public class AST2CPPTests extends AST2BaseTest {
f= bh.assertNonProblem("t8", 2); f= bh.assertNonProblem("t8", 2);
assertEquals("const double", ASTTypeUtil.getType(f.getType().getReturnType())); assertEquals("const double", ASTTypeUtil.getType(f.getType().getReturnType()));
} }
// typedef int TInt;
// void test() {
// int a1= {}, a2{}; // Initializer for declarator
// int b1= {1}, b2{1};
//
// TInt c[12];
// c[{1,2}]; // Array subscript
//
// a1= int{}; // Functional casts
// a2= TInt{};
// b1= int{1};
// b2= TInt{};
//
// new({1}) int {}; // New expression initializer
// new({1}) int {1};
//
// a1= b1= {1}; // Assinment expression
// if (int a={2}) {} // Condition
// return {0,1,2}; // Return statement
// }
//
// struct S {
// int f;
// S(int);
// };
//
// S::S(int a) : f{a} {} // Member initializer
public void testInitSyntax_302412() throws Exception {
String code= getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -15,9 +15,9 @@ import java.io.Writer;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -186,17 +186,17 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest {
int length = "argc".length(); //$NON-NLS-1$ int length = "argc".length(); //$NON-NLS-1$
IASTNode node = parse( code, ParserLanguage.C, offset1, length ).getParent().getParent(); IASTNode node = parse( code, ParserLanguage.C, offset1, length ).getParent().getParent();
assertNotNull(node); assertNotNull(node);
assertTrue( node instanceof IASTInitializerExpression ); assertTrue( node instanceof IASTEqualsInitializer );
assertEquals( ((IASTIdExpression)((IASTInitializerExpression)node).getExpression()).getName().toString(), "argc" ); //$NON-NLS-1$ assertEquals( ((IASTIdExpression)((IASTEqualsInitializer)node).getInitializerClause()).getName().toString(), "argc" ); //$NON-NLS-1$
IASTName name = ((IASTIdExpression)((IASTInitializerExpression)node).getExpression()).getName(); IASTName name = ((IASTIdExpression)((IASTEqualsInitializer)node).getInitializerClause()).getName();
assertNotNull(name.resolveBinding()); assertNotNull(name.resolveBinding());
assertTrue(name.resolveBinding() instanceof IParameter); assertTrue(name.resolveBinding() instanceof IParameter);
assertEquals(((IParameter)name.resolveBinding()).getName(), "argc"); //$NON-NLS-1$ assertEquals(((IParameter)name.resolveBinding()).getName(), "argc"); //$NON-NLS-1$
node = parse( code, ParserLanguage.CPP, offset1, length ).getParent().getParent(); node = parse( code, ParserLanguage.CPP, offset1, length ).getParent().getParent();
assertNotNull(node); assertNotNull(node);
assertTrue( node instanceof IASTInitializerExpression ); assertTrue( node instanceof IASTEqualsInitializer );
assertEquals( ((IASTIdExpression)((IASTInitializerExpression)node).getExpression()).getName().toString(), "argc" ); //$NON-NLS-1$ assertEquals( ((IASTIdExpression)((IASTEqualsInitializer)node).getInitializerClause()).getName().toString(), "argc" ); //$NON-NLS-1$
name = ((IASTIdExpression)((IASTInitializerExpression)node).getExpression()).getName(); name = ((IASTIdExpression)((IASTEqualsInitializer)node).getInitializerClause()).getName();
assertNotNull(name.resolveBinding()); assertNotNull(name.resolveBinding());
assertTrue(name.resolveBinding() instanceof IParameter); assertTrue(name.resolveBinding() instanceof IParameter);
assertEquals(((IParameter)name.resolveBinding()).getName(), "argc"); //$NON-NLS-1$ assertEquals(((IParameter)name.resolveBinding()).getName(), "argc"); //$NON-NLS-1$

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -47,7 +48,6 @@ import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTImageLocation; import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -240,10 +240,9 @@ public class AST2Tests extends AST2BaseTest {
assertEquals("z", name_z.toString()); //$NON-NLS-1$ assertEquals("z", name_z.toString()); //$NON-NLS-1$
// = x + y // = x + y
IASTInitializerExpression initializer = (IASTInitializerExpression) declor_z IASTEqualsInitializer initializer = (IASTEqualsInitializer) declor_z
.getInitializer(); .getInitializer();
IASTBinaryExpression init_z = (IASTBinaryExpression) initializer IASTBinaryExpression init_z = (IASTBinaryExpression) initializer.getInitializerClause();
.getExpression();
assertEquals(IASTBinaryExpression.op_plus, init_z.getOperator()); assertEquals(IASTBinaryExpression.op_plus, init_z.getOperator());
IASTIdExpression ref_x = (IASTIdExpression) init_z.getOperand1(); IASTIdExpression ref_x = (IASTIdExpression) init_z.getOperand1();
IASTName name_ref_x = ref_x.getName(); IASTName name_ref_x = ref_x.getName();
@ -2038,8 +2037,8 @@ public class AST2Tests extends AST2BaseTest {
.getName(); .getName();
IASTName name_xy = xy.getDeclarators()[0].getName(); IASTName name_xy = xy.getDeclarators()[0].getName();
IASTDeclarator declarator_xy = xy.getDeclarators()[0]; IASTDeclarator declarator_xy = xy.getDeclarators()[0];
IASTInitializer[] initializers1 = ((IASTInitializerList) declarator_xy IASTInitializer[] initializers1 = ((IASTInitializerList) ((IASTEqualsInitializer) declarator_xy.getInitializer())
.getInitializer()).getInitializers(); .getInitializerClause()).getInitializers();
IASTName name_y2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers1[0]) IASTName name_y2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers1[0])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
@ -2056,14 +2055,14 @@ public class AST2Tests extends AST2BaseTest {
.getDeclSpecifier()).getName(); .getDeclSpecifier()).getName();
IASTName name_point = point.getDeclarators()[0].getName(); IASTName name_point = point.getDeclarators()[0].getName();
IASTDeclarator declarator_point = point.getDeclarators()[0]; IASTDeclarator declarator_point = point.getDeclarators()[0];
IASTInitializer[] initializers2 = ((IASTInitializerList) declarator_point IASTInitializer[] initializers2 = ((IASTInitializerList) ((IASTEqualsInitializer) declarator_point
.getInitializer()).getInitializers(); .getInitializer()).getInitializerClause()).getInitializers();
IASTName name_width2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers2[0]) IASTName name_width2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers2[0])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
IASTName name_pos2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers2[1]) IASTName name_pos2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers2[1])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
IASTName name_xy2 = ((IASTIdExpression) ((IASTUnaryExpression) ((IASTInitializerExpression) ((ICASTDesignatedInitializer) initializers2[1]) IASTName name_xy2 = ((IASTIdExpression) ((IASTUnaryExpression) ((IASTEqualsInitializer) ((ICASTDesignatedInitializer) initializers2[1])
.getOperandInitializer()).getExpression()).getOperand()) .getOperandInitializer()).getInitializerClause()).getOperand())
.getName(); .getName();
for (int j = 0; j < 2; ++j) { for (int j = 0; j < 2; ++j) {
@ -2136,13 +2135,12 @@ public class AST2Tests extends AST2BaseTest {
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
.getName(); .getName();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def final IASTDeclarator dtor = ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def
.getBody()).getStatements()[0]).getDeclaration()) .getBody()).getStatements()[0]).getDeclaration()).getDeclarators()[0];
.getDeclarators()[0].getInitializer()).getInitializers()[0]) final IASTInitializerList initializerList = (IASTInitializerList) ((IASTEqualsInitializer)dtor.getInitializer()).getInitializerClause();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializerList.getInitializers()[0])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializerList.getInitializers()[1])
.getBody()).getStatements()[0]).getDeclaration())
.getDeclarators()[0].getInitializer()).getInitializers()[1])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
assertEquals(a1.resolveBinding(), a2.resolveBinding()); assertEquals(a1.resolveBinding(), a2.resolveBinding());
@ -2177,11 +2175,11 @@ public class AST2Tests extends AST2BaseTest {
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
.getName(); .getName();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) S_decl final IASTInitializer[] initializers = ((IASTInitializerList) ((IASTEqualsInitializer) S_decl
.getDeclarators()[0].getInitializer()).getInitializers()[0]) .getDeclarators()[0].getInitializer()).getInitializerClause()).getInitializers();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers[0])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) S_decl IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers[1])
.getDeclarators()[0].getInitializer()).getInitializers()[1])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
assertEquals(a1.resolveBinding(), a2.resolveBinding()); assertEquals(a1.resolveBinding(), a2.resolveBinding());
@ -2219,11 +2217,11 @@ public class AST2Tests extends AST2BaseTest {
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0] .getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
.getName(); .getName();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) x_decl IASTInitializer initializer = x_decl.getDeclarators()[0].getInitializer();
.getDeclarators()[0].getInitializer()).getInitializers()[0]) initializer= (IASTInitializer) ((IASTEqualsInitializer) initializer).getInitializerClause();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) initializer).getInitializers()[0])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) x_decl IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) initializer).getInitializers()[1])
.getDeclarators()[0].getInitializer()).getInitializers()[1])
.getDesignators()[0]).getName(); .getDesignators()[0]).getName();
assertEquals(a1.resolveBinding(), a2.resolveBinding()); assertEquals(a1.resolveBinding(), a2.resolveBinding());
@ -5483,7 +5481,7 @@ public class AST2Tests extends AST2BaseTest {
final IASTFunctionDefinition fdef= getDeclaration(tu, 1); final IASTFunctionDefinition fdef= getDeclaration(tu, 1);
IASTFunctionDeclarator fdtor= fdef.getDeclarator(); IASTFunctionDeclarator fdtor= fdef.getDeclarator();
IASTParameterDeclaration pdecl= (IASTParameterDeclaration) fdtor.getChildren()[1]; IASTParameterDeclaration pdecl= (IASTParameterDeclaration) fdtor.getChildren()[1];
IASTExpression expr= ((IASTInitializerExpression) pdecl.getDeclarator().getInitializer()).getExpression(); IASTExpression expr= (IASTExpression) ((IASTEqualsInitializer) pdecl.getDeclarator().getInitializer()).getInitializerClause();
assertEquals("expr: " + exprStr, io[1].trim(), polnishNotation(expr)); assertEquals("expr: " + exprStr, io[1].trim(), polnishNotation(expr));
assertEquals(exprStr, expr.getRawSignature()); assertEquals(exprStr, expr.getRawSignature());
checkOffsets(exprStr, expr); checkOffsets(exprStr, expr);
@ -6425,7 +6423,7 @@ public class AST2Tests extends AST2BaseTest {
*/ */
private IBasicType getTypeForDeclaration(IASTDeclaration[] declarations, int index) { private IBasicType getTypeForDeclaration(IASTDeclaration[] declarations, int index) {
IASTInitializer init = ((IASTSimpleDeclaration)declarations[index]).getDeclarators()[0].getInitializer(); IASTInitializer init = ((IASTSimpleDeclaration)declarations[index]).getDeclarators()[0].getInitializer();
return (IBasicType)((IASTInitializerExpression)init).getExpression().getExpressionType(); return (IBasicType)((IASTExpression)((IASTEqualsInitializer)init).getInitializerClause()).getExpressionType();
} }
@ -7316,4 +7314,14 @@ public class AST2Tests extends AST2BaseTest {
assertEquals(i>2, ((IASTPreprocessorPragmaStatement) stmt).isPragmaOperator()); assertEquals(i>2, ((IASTPreprocessorPragmaStatement) stmt).isPragmaOperator());
} }
} }
// int min(int,int);
// void test() {
// int a= (min)(1, 2);
// }
public void testFunctionNameExpression() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.C, true);
parseAndCheckBindings(code, ParserLanguage.CPP, true);
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,8 +11,8 @@
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -28,77 +28,77 @@ public class AST2UtilOldTests extends AST2BaseTest {
{ {
IASTTranslationUnit tu = parse("int x = f();".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f();".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f()" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f()" ); //$NON-NLS-1$
} }
// Kind PRIMARY_INTEGER_LITERAL : int // Kind PRIMARY_INTEGER_LITERAL : int
public void testPrimaryIntegerLiteral() throws Exception public void testPrimaryIntegerLiteral() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(1, 2+3);".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(1, 2+3);".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(1, 2 + 3)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(1, 2 + 3)" ); //$NON-NLS-1$
} }
// Kind PRIMARY_CHAR_LITERAL : char // Kind PRIMARY_CHAR_LITERAL : char
public void testPrimaryCharLiteral() throws Exception public void testPrimaryCharLiteral() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f('c');".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f('c');".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f('c')" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f('c')" ); //$NON-NLS-1$
} }
// Kind PRIMARY_FLOAT_LITERAL : float // Kind PRIMARY_FLOAT_LITERAL : float
public void testPrimaryFloatLiteral() throws Exception public void testPrimaryFloatLiteral() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(1.13);".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(1.13);".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(1.13)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(1.13)" ); //$NON-NLS-1$
} }
// Kind PRIMARY_STRING_LITERAL : char* // Kind PRIMARY_STRING_LITERAL : char*
public void testPrimaryStringLiteral() throws Exception public void testPrimaryStringLiteral() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(\"str\");".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(\"str\");".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(\"str\")" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(\"str\")" ); //$NON-NLS-1$
} }
// Kind PRIMARY_BOOLEAN_LITERAL : bool // Kind PRIMARY_BOOLEAN_LITERAL : bool
public void testPrimaryBooleanLiteral() throws Exception public void testPrimaryBooleanLiteral() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(true);".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(true);".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(true)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(true)" ); //$NON-NLS-1$
} }
// Kind PRIMARY_THIS : type of inner most enclosing structure scope // Kind PRIMARY_THIS : type of inner most enclosing structure scope
public void testPrimaryThis() throws Exception public void testPrimaryThis() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(this);".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(this);".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(this)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(this)" ); //$NON-NLS-1$
} }
// Kind PRIMARY_BRACKETED_EXPRESSION : LHS // Kind PRIMARY_BRACKETED_EXPRESSION : LHS
public void testPrimaryBracketedExpression() throws Exception public void testPrimaryBracketedExpression() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(1, (2+3));".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(1, (2+3));".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(1, (2 + 3))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(1, (2 + 3))" ); //$NON-NLS-1$
} }
// Kind ID_EXPRESSION : type of the ID // Kind ID_EXPRESSION : type of the ID
public void testIdExpression() throws Exception public void testIdExpression() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(a);".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(a);".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(a)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(a)" ); //$NON-NLS-1$
} }
// Kind POSTFIX_SUBSCRIPT // Kind POSTFIX_SUBSCRIPT
public void testPostfixSubscript() throws Exception public void testPostfixSubscript() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(pa[1]);".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(pa[1]);".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(pa[1])" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(pa[1])" ); //$NON-NLS-1$
} }
public void testPostfixSubscriptA() throws Exception public void testPostfixSubscriptA() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(pa[1][2]);".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(pa[1][2]);".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(pa[1][2])" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(pa[1][2])" ); //$NON-NLS-1$
} }
// Kind POSTFIX_FUNCTIONCALL : return type of called function // Kind POSTFIX_FUNCTIONCALL : return type of called function
@ -106,344 +106,344 @@ public class AST2UtilOldTests extends AST2BaseTest {
{ {
IASTTranslationUnit tu = parse("int x = bar( foo( 3.0 ), foo( 5.0 ) ) ;".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = bar( foo( 3.0 ), foo( 5.0 ) ) ;".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "bar(foo(3.0), foo(5.0))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "bar(foo(3.0), foo(5.0))" ); //$NON-NLS-1$
} }
// Kind POSTFIX_SIMPLETYPE_* : simple type // Kind POSTFIX_SIMPLETYPE_* : simple type
public void testPostfixSimpletypesBug42823() throws Exception public void testPostfixSimpletypesBug42823() throws Exception
{ {
IASTTranslationUnit tu = parse("int someInt = foo( int(3), short(4), double(3.0), float(4.0), char( 'a'), wchar_t( 'a' ), signed( 2 ), unsigned( 3 ), bool( false ), long( 3L ) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int someInt = foo( int(3), short(4), double(3.0), float(4.0), char( 'a'), wchar_t( 'a' ), signed( 2 ), unsigned( 3 ), bool( false ), long( 3L ) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3L))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3L))" ); //$NON-NLS-1$
} }
// Kind POSTFIX_DOT_IDEXPRESSION : type of member in the scope of the container // Kind POSTFIX_DOT_IDEXPRESSION : type of member in the scope of the container
public void testPostfixDotExpression() throws Exception{ public void testPostfixDotExpression() throws Exception{
IASTTranslationUnit tu = parse("class A {int m;}; \n A a; \n int foo(char); int foo( int ); \n int x = foo( a.m );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("class A {int m;}; \n A a; \n int foo(char); int foo( int ); \n int x = foo( a.m );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a.m)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a.m)" ); //$NON-NLS-1$
} }
// Kind POSTFIX_ARROW_IDEXPRESSION : type of member in the scope of the container // Kind POSTFIX_ARROW_IDEXPRESSION : type of member in the scope of the container
public void testPostfixArrowExpression() throws Exception{ public void testPostfixArrowExpression() throws Exception{
IASTTranslationUnit tu = parse("class A {int m;}; \n A * a; \n int foo(char); int foo( int ); \n int x = foo( a->m );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("class A {int m;}; \n A * a; \n int foo(char); int foo( int ); \n int x = foo( a->m );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a->m)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a->m)" ); //$NON-NLS-1$
} }
// Kind POSTFIX_INCREMENT : LHS // Kind POSTFIX_INCREMENT : LHS
public void testPostfixIncrement() throws Exception public void testPostfixIncrement() throws Exception
{ {
IASTTranslationUnit tu = parse("int y = foo( x++ );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int y = foo( x++ );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(x++)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(x++)" ); //$NON-NLS-1$
} }
// Kind POSTFIX_DECREMENT : LHS // Kind POSTFIX_DECREMENT : LHS
public void testPostfixDecrement() throws Exception public void testPostfixDecrement() throws Exception
{ {
IASTTranslationUnit tu = parse("int y = foo( x-- );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int y = foo( x-- );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(x--)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(x--)" ); //$NON-NLS-1$
} }
// Kind POSTFIX_DYNAMIC_CAST // Kind POSTFIX_DYNAMIC_CAST
public void testPostfixDynamicCast() throws Exception{ public void testPostfixDynamicCast() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( dynamic_cast<B*>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( dynamic_cast<B*>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(dynamic_cast<B *>(a))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(dynamic_cast<B *>(a))" ); //$NON-NLS-1$
} }
// Kind POSTFIX_REINTERPRET_CAST // Kind POSTFIX_REINTERPRET_CAST
public void testPostfixReinterpretCast() throws Exception{ public void testPostfixReinterpretCast() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( reinterpret_cast<double *>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( reinterpret_cast<double *>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(reinterpret_cast<double *>(a))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(reinterpret_cast<double *>(a))" ); //$NON-NLS-1$
} }
// Kind POSTFIX_STATIC_CAST // Kind POSTFIX_STATIC_CAST
public void testPostfixStaticCast() throws Exception{ public void testPostfixStaticCast() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( static_cast<char>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( static_cast<char>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(static_cast<char>(a))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(static_cast<char>(a))" ); //$NON-NLS-1$
} }
// Kind POSTFIX_CONST_CAST // Kind POSTFIX_CONST_CAST
public void testPostfixConstCast() throws Exception{ public void testPostfixConstCast() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( const_cast<int *>(&a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( const_cast<int *>(&a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(const_cast<int *>(&a))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(const_cast<int *>(&a))" ); //$NON-NLS-1$
} }
// Kind POSTFIX_TYPEID_EXPRESSION : LHS // Kind POSTFIX_TYPEID_EXPRESSION : LHS
public void testPostfixTypeIdExpression() throws Exception{ public void testPostfixTypeIdExpression() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( typeid(5) );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( typeid(5) );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(typeid(5))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(typeid(5))" ); //$NON-NLS-1$
} }
// Kind POSTFIX_TYPEID_EXPRESSION : type of the ID // Kind POSTFIX_TYPEID_EXPRESSION : type of the ID
public void testPostfixTypeIdExpression2() throws Exception{ public void testPostfixTypeIdExpression2() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( typeid(a) );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( typeid(a) );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(typeid(a))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(typeid(a))" ); //$NON-NLS-1$
} }
// Kind POSTFIX_TYPEID_TYPEID : type of the ID // Kind POSTFIX_TYPEID_TYPEID : type of the ID
public void testPostfixTypeIdTypeId2() throws Exception{ public void testPostfixTypeIdTypeId2() throws Exception{
IASTTranslationUnit tu = parse("class A { }; int foo( int ); int x = foo( typeid(const A) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("class A { }; int foo( int ); int x = foo( typeid(const A) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getExpression(), "foo(typeid (const A))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(typeid (const A))" ); //$NON-NLS-1$
} }
// Kind UNARY_INCREMENT : LHS // Kind UNARY_INCREMENT : LHS
public void testUnaryIncrement() throws Exception public void testUnaryIncrement() throws Exception
{ {
IASTTranslationUnit tu = parse("int y = foo( ++x );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int y = foo( ++x );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(++x)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(++x)" ); //$NON-NLS-1$
} }
// Kind UNARY_DECREMENT : LHS // Kind UNARY_DECREMENT : LHS
public void testUnaryDecrement() throws Exception public void testUnaryDecrement() throws Exception
{ {
IASTTranslationUnit tu = parse("int y = foo( --x );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int y = foo( --x );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(--x)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(--x)" ); //$NON-NLS-1$
} }
// Kind UNARY_STAR_CASTEXPRESSION : LHS + t_pointer // Kind UNARY_STAR_CASTEXPRESSION : LHS + t_pointer
public void testUnaryStarCastExpression() throws Exception public void testUnaryStarCastExpression() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(*pa);".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(*pa);".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(*pa)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(*pa)" ); //$NON-NLS-1$
} }
// Kind UNARY_AMPSND_CASTEXPRESSION : LHS + t_reference // Kind UNARY_AMPSND_CASTEXPRESSION : LHS + t_reference
public void testUnaryAmpersandCastExpression() throws Exception public void testUnaryAmpersandCastExpression() throws Exception
{ {
IASTTranslationUnit tu = parse("int x = f(&pa);".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = f(&pa);".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "f(&pa)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "f(&pa)" ); //$NON-NLS-1$
} }
// Kind UNARY_PLUS_CASTEXPRESSION : LHS // Kind UNARY_PLUS_CASTEXPRESSION : LHS
public void testUnaryPlusCastExpression() throws Exception { public void testUnaryPlusCastExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( +5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( +5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(+5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(+5)" ); //$NON-NLS-1$
} }
// Kind UNARY_MINUS_CASTEXPRESSION : LHS // Kind UNARY_MINUS_CASTEXPRESSION : LHS
public void testUnaryMinusCastExpression() throws Exception { public void testUnaryMinusCastExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( -5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( -5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(-5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(-5)" ); //$NON-NLS-1$
} }
// Kind UNARY_NOT_CASTEXPRESSION : LHS // Kind UNARY_NOT_CASTEXPRESSION : LHS
public void testUnaryNotCastExpression() throws Exception { public void testUnaryNotCastExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( !b );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( !b );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(!b)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(!b)" ); //$NON-NLS-1$
} }
// Kind UNARY_TILDE_CASTEXPRESSION : LHS // Kind UNARY_TILDE_CASTEXPRESSION : LHS
public void testTildeNotCastExpression() throws Exception { public void testTildeNotCastExpression() throws Exception {
IASTTranslationUnit tu = parse("int y = foo( ~x );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int y = foo( ~x );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(~x)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(~x)" ); //$NON-NLS-1$
} }
// Kind UNARY_SIZEOF_UNARYEXPRESSION : unsigned int // Kind UNARY_SIZEOF_UNARYEXPRESSION : unsigned int
public void testUnarySizeofUnaryExpression() throws Exception { public void testUnarySizeofUnaryExpression() throws Exception {
IASTTranslationUnit tu = parse("int y = foo( sizeof(5) );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int y = foo( sizeof(5) );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(sizeof (5))" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(sizeof (5))" ); //$NON-NLS-1$
} }
// Kind UNARY_SIZEOF_TYPEID : unsigned int // Kind UNARY_SIZEOF_TYPEID : unsigned int
public void testUnarySizeofTypeId() throws Exception { public void testUnarySizeofTypeId() throws Exception {
IASTTranslationUnit tu = parse("int x, y = foo( sizeof(x) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x, y = foo( sizeof(x) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
final IASTExpression expression = ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[1].getInitializer()).getExpression(); final IASTInitializerClause expression = ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[1].getInitializer()).getInitializerClause();
isExpressionStringEqual( expression, "foo(sizeof (x))" ); //$NON-NLS-1$ isExpressionStringEqual( expression, "foo(sizeof (x))" ); //$NON-NLS-1$
} }
// Kind NEW_TYPEID // Kind NEW_TYPEID
public void testNewTypeId() throws Exception { public void testNewTypeId() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( new A() );".toString(), ParserLanguage.CPP); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( new A() );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(new A())" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(new A())" ); //$NON-NLS-1$
} }
// Kind CASTEXPRESSION // Kind CASTEXPRESSION
public void testCastExpression() throws Exception{ public void testCastExpression() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( (A*)b );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( (A*)b );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo((A *)b)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo((A *)b)" ); //$NON-NLS-1$
} }
// Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions // Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions
public void testMultiplicativeMultiply() throws Exception { public void testMultiplicativeMultiply() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a * b );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a * b );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a * b)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a * b)" ); //$NON-NLS-1$
} }
// Kind MULTIPLICATIVE_DIVIDE : usual arithmetic conversions // Kind MULTIPLICATIVE_DIVIDE : usual arithmetic conversions
public void testMultiplicativeDivide() throws Exception { public void testMultiplicativeDivide() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b / a );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b / a );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b / a)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b / a)" ); //$NON-NLS-1$
} }
// Kind MULTIPLICATIVE_MODULUS : usual arithmetic conversions // Kind MULTIPLICATIVE_MODULUS : usual arithmetic conversions
public void testMultiplicativeModulus() throws Exception { public void testMultiplicativeModulus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b % a );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b % a );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b % a)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b % a)" ); //$NON-NLS-1$
} }
// Kind ADDITIVE_PLUS : usual arithmetic conversions // Kind ADDITIVE_PLUS : usual arithmetic conversions
public void testAdditivePlus() throws Exception { public void testAdditivePlus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b + a );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b + a );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b + a)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b + a)" ); //$NON-NLS-1$
} }
// Kind ADDITIVE_MINUS : usual arithmetic conversions // Kind ADDITIVE_MINUS : usual arithmetic conversions
public void testAdditiveMinus() throws Exception { public void testAdditiveMinus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b - a );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b - a );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b - a)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b - a)" ); //$NON-NLS-1$
} }
// Kind SHIFT_LEFT : LHS // Kind SHIFT_LEFT : LHS
public void testShiftLeft() throws Exception { public void testShiftLeft() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a << 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a << 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a << 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a << 5)" ); //$NON-NLS-1$
} }
// Kind SHIFT_RIGHT : LHS // Kind SHIFT_RIGHT : LHS
public void testShiftRight() throws Exception { public void testShiftRight() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a >> 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a >> 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a >> 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a >> 5)" ); //$NON-NLS-1$
} }
// Kind RELATIONAL_LESSTHAN : bool // Kind RELATIONAL_LESSTHAN : bool
public void testRelationalLessThan() throws Exception { public void testRelationalLessThan() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b < 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b < 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b < 3)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b < 3)" ); //$NON-NLS-1$
} }
// Kind RELATIONAL_GREATERTHAN : bool // Kind RELATIONAL_GREATERTHAN : bool
public void testRelationalGreaterThan() throws Exception { public void testRelationalGreaterThan() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b > 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b > 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b > 3)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b > 3)" ); //$NON-NLS-1$
} }
// Kind RELATIONAL_LESSTHANEQUALTO : bool // Kind RELATIONAL_LESSTHANEQUALTO : bool
public void testRelationalLessThanOrEqual() throws Exception { public void testRelationalLessThanOrEqual() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b <= 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b <= 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b <= 3)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b <= 3)" ); //$NON-NLS-1$
} }
// Kind RELATIONAL_GREATERTHANEQUALTO : bool // Kind RELATIONAL_GREATERTHANEQUALTO : bool
public void testRelationalGreaterThanOrEqual() throws Exception { public void testRelationalGreaterThanOrEqual() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b >= 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b >= 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b >= 3)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b >= 3)" ); //$NON-NLS-1$
} }
// Kind EQUALITY_EQUALS : bool // Kind EQUALITY_EQUALS : bool
public void testEqualityEquals() throws Exception { public void testEqualityEquals() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b == 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b == 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b == 3)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b == 3)" ); //$NON-NLS-1$
} }
// Kind EQUALITY_NOTEQUALS : bool // Kind EQUALITY_NOTEQUALS : bool
public void testEqualityNotEquals() throws Exception { public void testEqualityNotEquals() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b != 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( b != 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(b != 3)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(b != 3)" ); //$NON-NLS-1$
} }
// Kind ANDEXPRESSION : usual arithmetic conversions // Kind ANDEXPRESSION : usual arithmetic conversions
public void testAndExpression() throws Exception { public void testAndExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a & b );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a & b );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a & b)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a & b)" ); //$NON-NLS-1$
} }
// Kind EXCLUSIVEOREXPRESSION : usual arithmetic conversions // Kind EXCLUSIVEOREXPRESSION : usual arithmetic conversions
public void testExclusiveOrExpression() throws Exception { public void testExclusiveOrExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a ^ b );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a ^ b );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a ^ b)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a ^ b)" ); //$NON-NLS-1$
} }
// Kind INCLUSIVEOREXPRESSION : : usual arithmetic conversions // Kind INCLUSIVEOREXPRESSION : : usual arithmetic conversions
public void testInclusiveOrExpression() throws Exception { public void testInclusiveOrExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a | b );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a | b );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a | b)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a | b)" ); //$NON-NLS-1$
} }
// Kind LOGICALANDEXPRESSION : bool // Kind LOGICALANDEXPRESSION : bool
public void testLogicalAndExpression() throws Exception { public void testLogicalAndExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a && b );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a && b );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a && b)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a && b)" ); //$NON-NLS-1$
} }
// Kind LOGICALOREXPRESSION : bool // Kind LOGICALOREXPRESSION : bool
public void testLogicalOrExpression() throws Exception { public void testLogicalOrExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a || b );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a || b );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a || b)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a || b)" ); //$NON-NLS-1$
} }
// Kind CONDITIONALEXPRESSION : conditional Expression Conversions // Kind CONDITIONALEXPRESSION : conditional Expression Conversions
public void testConditionalExpression() throws Exception { public void testConditionalExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a > 5 ? b : c );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a > 5 ? b : c );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a > 5 ? b : c)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a > 5 ? b : c)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_NORMAL : LHS // Kind ASSIGNMENTEXPRESSION_NORMAL : LHS
public void testAssignmentExpressionNormal() throws Exception { public void testAssignmentExpressionNormal() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a = 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a = 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a = 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a = 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_PLUS : LHS // Kind ASSIGNMENTEXPRESSION_PLUS : LHS
public void testAssignmentExpressionPlus() throws Exception { public void testAssignmentExpressionPlus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a += 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a += 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a += 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a += 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_MINUS : LHS // Kind ASSIGNMENTEXPRESSION_MINUS : LHS
public void testAssignmentExpressionMinus() throws Exception { public void testAssignmentExpressionMinus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a -= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a -= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a -= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a -= 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_MULT : LHS // Kind ASSIGNMENTEXPRESSION_MULT : LHS
public void testAssignmentExpressionMulti() throws Exception { public void testAssignmentExpressionMulti() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a *= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a *= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a *= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a *= 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_DIV : LHS // Kind ASSIGNMENTEXPRESSION_DIV : LHS
public void testAssignmentExpressionDiv() throws Exception { public void testAssignmentExpressionDiv() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a /= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a /= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a /= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a /= 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_MOD : LHS // Kind ASSIGNMENTEXPRESSION_MOD : LHS
public void testAssignmentExpressionMod() throws Exception { public void testAssignmentExpressionMod() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a %= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a %= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a %= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a %= 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_LSHIFT : LHS // Kind ASSIGNMENTEXPRESSION_LSHIFT : LHS
public void testAssignmentExpressionLShift() throws Exception { public void testAssignmentExpressionLShift() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a >>= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a >>= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a >>= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a >>= 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_RSHIFT : LHS // Kind ASSIGNMENTEXPRESSION_RSHIFT : LHS
public void testAssignmentExpressionRShift() throws Exception { public void testAssignmentExpressionRShift() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a <<= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a <<= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a <<= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a <<= 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_AND : LHS // Kind ASSIGNMENTEXPRESSION_AND : LHS
public void testAssignmentExpressionAnd() throws Exception { public void testAssignmentExpressionAnd() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a &= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a &= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a &= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a &= 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_OR : LHS // Kind ASSIGNMENTEXPRESSION_OR : LHS
public void testAssignmentExpressionOr() throws Exception { public void testAssignmentExpressionOr() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a |= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a |= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a |= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a |= 5)" ); //$NON-NLS-1$
} }
// Kind ASSIGNMENTEXPRESSION_XOR : LHS // Kind ASSIGNMENTEXPRESSION_XOR : LHS
public void testAssignmentExpressionXOr() throws Exception { public void testAssignmentExpressionXOr() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a ^= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$ IASTTranslationUnit tu = parse("int x = foo( a ^= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual( ((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression(), "foo(a ^= 5)" ); //$NON-NLS-1$ isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(a ^= 5)" ); //$NON-NLS-1$
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,8 +14,8 @@ import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -51,16 +51,16 @@ public class AST2UtilTests extends AST2BaseTest {
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C); IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C);
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[2].getInitializer()).getExpression(), "0"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[2].getInitializer()).getInitializerClause(), "0"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[1]).getDeclarators()[0].getInitializer()).getExpression(), "l ? m : n"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[1]).getDeclarators()[0].getInitializer()).getInitializerClause(), "l ? m : n"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getExpression(), "l ^ m"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getInitializerClause(), "l ^ m"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[3]).getDeclarators()[0].getInitializer()).getExpression(), "i <<= j"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[3]).getDeclarators()[0].getInitializer()).getInitializerClause(), "i <<= j"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getExpression(), "sizeof (int)"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getInitializerClause(), "sizeof (int)"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[5]).getDeclarators()[0].getInitializer()).getExpression(), "~f"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[5]).getDeclarators()[0].getInitializer()).getInitializerClause(), "~f"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getExpression(), "++e"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getInitializerClause(), "++e"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[7]).getDeclarators()[0].getInitializer()).getExpression(), "d++"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[7]).getDeclarators()[0].getInitializer()).getInitializerClause(), "d++"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[8]).getDeclarators()[0].getInitializer()).getExpression(), "sizeof b"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[8]).getDeclarators()[0].getInitializer()).getInitializerClause(), "sizeof b"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[9]).getDeclarators()[0].getInitializer()).getExpression(), "b + c"); //$NON-NLS-1$ isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[9]).getDeclarators()[0].getInitializer()).getInitializerClause(), "b + c"); //$NON-NLS-1$
} }
public void testSimpleParameter() throws Exception { public void testSimpleParameter() throws Exception {
@ -141,14 +141,14 @@ public class AST2UtilTests extends AST2BaseTest {
IASTDeclaration[] d = tu.getDeclarations(); IASTDeclaration[] d = tu.getDeclarations();
// verify signatures // verify signatures
isSignatureEqual( ((IASTTypeIdExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId(), "int"); //$NON-NLS-1$ isSignatureEqual( ((IASTTypeIdExpression)((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause()).getTypeId(), "int"); //$NON-NLS-1$
isSignatureEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "Squaw"); //$NON-NLS-1$ isSignatureEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "Squaw"); //$NON-NLS-1$
isSignatureEqual( ((IASTCastExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId() , "jc"); //$NON-NLS-1$ isSignatureEqual( ((IASTCastExpression)((IASTEqualsInitializer)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getInitializerClause()).getTypeId() , "jc"); //$NON-NLS-1$
// verify types // verify types
isTypeEqual( ((IASTTypeIdExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId(), "int"); //$NON-NLS-1$ isTypeEqual( ((IASTTypeIdExpression)((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause()).getTypeId(), "int"); //$NON-NLS-1$
isTypeEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "Squaw"); //$NON-NLS-1$ isTypeEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "Squaw"); //$NON-NLS-1$
isTypeEqual( ((IASTCastExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId() , "short int"); //$NON-NLS-1$ isTypeEqual( ((IASTCastExpression)((IASTEqualsInitializer)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getInitializerClause()).getTypeId() , "short int"); //$NON-NLS-1$
} }
public void testKnRC() throws Exception { public void testKnRC() throws Exception {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,10 +14,10 @@ package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation; import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
@ -51,8 +51,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
StringBuffer buffer = new StringBuffer( "#define ABC D\n" ); //$NON-NLS-1$ StringBuffer buffer = new StringBuffer( "#define ABC D\n" ); //$NON-NLS-1$
buffer.append( "int ABC;"); //$NON-NLS-1$ buffer.append( "int ABC;"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition ABC = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0]; IASTPreprocessorObjectStyleMacroDefinition ABC = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTDeclarator d = var.getDeclarators()[0]; IASTDeclarator d = var.getDeclarators()[0];
@ -77,8 +77,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
StringBuffer buffer = new StringBuffer( "#define ABC * D\n" ); //$NON-NLS-1$ StringBuffer buffer = new StringBuffer( "#define ABC * D\n" ); //$NON-NLS-1$
buffer.append( "int ABC;"); //$NON-NLS-1$ buffer.append( "int ABC;"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition ABC = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0]; IASTPreprocessorObjectStyleMacroDefinition ABC = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTDeclarator d = var.getDeclarators()[0]; IASTDeclarator d = var.getDeclarators()[0];
@ -124,8 +124,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
StringBuffer buffer = new StringBuffer( "#define XYZ const\n"); //$NON-NLS-1$ StringBuffer buffer = new StringBuffer( "#define XYZ const\n"); //$NON-NLS-1$
buffer.append( "XYZ int var;"); //$NON-NLS-1$ buffer.append( "XYZ int var;"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition defXYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0]; IASTPreprocessorObjectStyleMacroDefinition defXYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTSimpleDeclSpecifier declSpec = (IASTSimpleDeclSpecifier) var.getDeclSpecifier(); IASTSimpleDeclSpecifier declSpec = (IASTSimpleDeclSpecifier) var.getDeclSpecifier();
@ -154,8 +154,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
buffer.append( "int C_PO var;"); //$NON-NLS-1$ buffer.append( "int C_PO var;"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions(); final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions();
IASTPreprocessorMacroDefinition XYZ = macroDefinitions[0]; IASTPreprocessorMacroDefinition XYZ = macroDefinitions[0];
IASTPreprocessorMacroDefinition PO = macroDefinitions[1]; IASTPreprocessorMacroDefinition PO = macroDefinitions[1];
@ -188,8 +188,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
buffer.append( "XYZ IT C_PO C_PO V;"); //$NON-NLS-1$ buffer.append( "XYZ IT C_PO C_PO V;"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition XYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0]; IASTPreprocessorObjectStyleMacroDefinition XYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
// IASTPreprocessorObjectStyleMacroDefinition PO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[1]; // IASTPreprocessorObjectStyleMacroDefinition PO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[1];
IASTPreprocessorObjectStyleMacroDefinition C_PO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[2]; IASTPreprocessorObjectStyleMacroDefinition C_PO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[2];
@ -238,8 +238,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
buffer.append( "_PTR _EXFUN(memchr,(const _PTR, int, size_t));\n"); //$NON-NLS-1$ buffer.append( "_PTR _EXFUN(memchr,(const _PTR, int, size_t));\n"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i], true, true); IASTTranslationUnit tu = parse(code, language, true, true);
final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions(); final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions();
IASTPreprocessorObjectStyleMacroDefinition _PTR = (IASTPreprocessorObjectStyleMacroDefinition) macroDefinitions[0]; IASTPreprocessorObjectStyleMacroDefinition _PTR = (IASTPreprocessorObjectStyleMacroDefinition) macroDefinitions[0];
IASTPreprocessorFunctionStyleMacroDefinition _EXFUN = (IASTPreprocessorFunctionStyleMacroDefinition) macroDefinitions[2]; IASTPreprocessorFunctionStyleMacroDefinition _EXFUN = (IASTPreprocessorFunctionStyleMacroDefinition) macroDefinitions[2];
@ -280,8 +280,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
buffer.append( "#define ABC ghi\n"); //$NON-NLS-1$ buffer.append( "#define ABC ghi\n"); //$NON-NLS-1$
buffer.append( "int ABC;\n"); //$NON-NLS-1$ buffer.append( "int ABC;\n"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorMacroDefinition [] macros = tu.getMacroDefinitions(); IASTPreprocessorMacroDefinition [] macros = tu.getMacroDefinitions();
assertEquals( macros.length, 2 ); assertEquals( macros.length, 2 );
IASTPreprocessorObjectStyleMacroDefinition ABC1 = (IASTPreprocessorObjectStyleMacroDefinition) macros[0]; IASTPreprocessorObjectStyleMacroDefinition ABC1 = (IASTPreprocessorObjectStyleMacroDefinition) macros[0];
@ -314,8 +314,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
StringBuffer buffer = new StringBuffer( "#define MACRO mm\n"); //$NON-NLS-1$ StringBuffer buffer = new StringBuffer( "#define MACRO mm\n"); //$NON-NLS-1$
buffer.append( "int MACRO;\n"); //$NON-NLS-1$ buffer.append( "int MACRO;\n"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition MACRO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0]; IASTPreprocessorObjectStyleMacroDefinition MACRO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
IASTName macro_name = MACRO.getName(); IASTName macro_name = MACRO.getName();
IMacroBinding binding = (IMacroBinding) macro_name.resolveBinding(); IMacroBinding binding = (IMacroBinding) macro_name.resolveBinding();
@ -336,8 +336,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
buffer.append( "#define MYAPI API\n"); //$NON-NLS-1$ buffer.append( "#define MYAPI API\n"); //$NON-NLS-1$
buffer.append( "MYAPI void func() {}" ); //$NON-NLS-1$ buffer.append( "MYAPI void func() {}" ); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0]; IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
assertNotNull( f.getFileLocation() ); assertNotNull( f.getFileLocation() );
} }
@ -350,11 +350,11 @@ public class DOMLocationMacroTests extends AST2BaseTest {
buffer.append( "int var= FUNCTION(1);"); //$NON-NLS-1$ buffer.append( "int var= FUNCTION(1);"); //$NON-NLS-1$
String code = buffer.toString(); String code = buffer.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTInitializerExpression initializer= (IASTInitializerExpression)var.getDeclarators()[0].getInitializer(); IASTEqualsInitializer initializer= (IASTEqualsInitializer)var.getDeclarators()[0].getInitializer();
IASTExpression expr= initializer.getExpression(); IASTInitializerClause expr= initializer.getInitializerClause();
assertNotNull(expr.getFileLocation()); assertNotNull(expr.getFileLocation());
IASTNodeLocation [] locations = expr.getNodeLocations(); IASTNodeLocation [] locations = expr.getNodeLocations();
assertEquals(1, locations.length); assertEquals(1, locations.length);
@ -369,8 +369,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
private void assertMacroLocation(IASTDeclaration decl, int index, int length) { private void assertMacroLocation(IASTDeclaration decl, int index, int length) {
IASTSimpleDeclaration var = (IASTSimpleDeclaration) decl; IASTSimpleDeclaration var = (IASTSimpleDeclaration) decl;
IASTInitializerExpression initializer= (IASTInitializerExpression)var.getDeclarators()[0].getInitializer(); IASTEqualsInitializer initializer= (IASTEqualsInitializer)var.getDeclarators()[0].getInitializer();
IASTExpression expr= initializer.getExpression(); IASTInitializerClause expr= initializer.getInitializerClause();
assertNotNull(expr.getFileLocation()); assertNotNull(expr.getFileLocation());
IASTNodeLocation [] locations = expr.getNodeLocations(); IASTNodeLocation [] locations = expr.getNodeLocations();
assertEquals(1, locations.length); assertEquals(1, locations.length);
@ -384,8 +384,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
private void assertExpressionLocation(IASTDeclaration decl, int index, int length) { private void assertExpressionLocation(IASTDeclaration decl, int index, int length) {
IASTSimpleDeclaration var = (IASTSimpleDeclaration) decl; IASTSimpleDeclaration var = (IASTSimpleDeclaration) decl;
IASTInitializerExpression initializer= (IASTInitializerExpression)var.getDeclarators()[0].getInitializer(); IASTEqualsInitializer initializer= (IASTEqualsInitializer)var.getDeclarators()[0].getInitializer();
IASTExpression expr= initializer.getExpression(); IASTInitializerClause expr= initializer.getInitializerClause();
IASTFileLocation fileLocation = expr.getFileLocation(); IASTFileLocation fileLocation = expr.getFileLocation();
assertNotNull(fileLocation); assertNotNull(fileLocation);
assertEquals(index, fileLocation.getNodeOffset()); assertEquals(index, fileLocation.getNodeOffset());
@ -402,8 +402,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$ sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString(); String code = sb.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations(); IASTDeclaration[] decls = tu.getDeclarations();
assertMacroLocation(decls[1], code.indexOf("Nullstr;"), "Nullstr".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertMacroLocation(decls[1], code.indexOf("Nullstr;"), "Nullstr".length()); //$NON-NLS-1$ //$NON-NLS-2$
assertExpressionLocation(decls[2], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertExpressionLocation(decls[2], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$
@ -421,8 +421,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$ sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString(); String code = sb.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations(); IASTDeclaration[] decls = tu.getDeclarations();
assertMacroLocation(decls[0], code.indexOf("ADD(ONEYONENOE,TWO, THREE)"), "ADD(ONEYONENOE,TWO, THREE)".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertMacroLocation(decls[0], code.indexOf("ADD(ONEYONENOE,TWO, THREE)"), "ADD(ONEYONENOE,TWO, THREE)".length()); //$NON-NLS-1$ //$NON-NLS-2$
assertExpressionLocation(decls[1], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertExpressionLocation(decls[1], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$
@ -438,8 +438,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$ sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString(); String code = sb.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations(); IASTDeclaration[] decls = tu.getDeclarations();
assertMacroLocation(decls[0], code.indexOf("add2 z);"), "add2 z)".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertMacroLocation(decls[0], code.indexOf("add2 z);"), "add2 z)".length()); //$NON-NLS-1$ //$NON-NLS-2$
assertExpressionLocation(decls[1], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertExpressionLocation(decls[1], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$
@ -455,8 +455,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$ sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString(); String code = sb.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations(); IASTDeclaration[] decls = tu.getDeclarations();
assertMacroLocation(decls[0], code.indexOf("YO;"), "YO".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertMacroLocation(decls[0], code.indexOf("YO;"), "YO".length()); //$NON-NLS-1$ //$NON-NLS-2$
assertExpressionLocation(decls[1], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertExpressionLocation(decls[1], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$
@ -472,8 +472,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$ sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString(); String code = sb.toString();
for(int i = 0; i < languages.length; i++) { for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, languages[i]); IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations(); IASTDeclaration[] decls = tu.getDeclarations();
assertMacroLocation(decls[0], code.indexOf("MAKEFUN(1)(z);"), "MAKEFUN(1)(z)".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertMacroLocation(decls[0], code.indexOf("MAKEFUN(1)(z);"), "MAKEFUN(1)(z)".length()); //$NON-NLS-1$ //$NON-NLS-2$
assertExpressionLocation(decls[1], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertExpressionLocation(decls[1], code.indexOf("whatever;"), "whatever".length()); //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -22,7 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
@ -32,7 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
@ -297,9 +297,9 @@ public class DOMLocationTests extends AST2BaseTest {
} }
assertSoleLocation(decl, start, length); assertSoleLocation(decl, start, length);
} }
IASTInitializerExpression initializer = (IASTInitializerExpression) ((IASTSimpleDeclaration) declarations[2]) IASTEqualsInitializer initializer = (IASTEqualsInitializer) ((IASTSimpleDeclaration) declarations[2])
.getDeclarators()[0].getInitializer(); .getDeclarators()[0].getInitializer();
IASTCastExpression castExpression = (IASTCastExpression) initializer.getExpression(); IASTCastExpression castExpression = (IASTCastExpression) initializer.getInitializerClause();
IASTTypeId typeId = castExpression.getTypeId(); IASTTypeId typeId = castExpression.getTypeId();
assertSoleLocation(typeId, code.indexOf("(jc)") + 1, "jc".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertSoleLocation(typeId, code.indexOf("(jc)") + 1, "jc".length()); //$NON-NLS-1$ //$NON-NLS-2$
} }
@ -326,9 +326,9 @@ public class DOMLocationTests extends AST2BaseTest {
IASTCompoundStatement statement = (IASTCompoundStatement) main.getBody(); IASTCompoundStatement statement = (IASTCompoundStatement) main.getBody();
IASTDeclarationStatement decl = (IASTDeclarationStatement) statement.getStatements()[0]; IASTDeclarationStatement decl = (IASTDeclarationStatement) statement.getStatements()[0];
IASTSimpleDeclaration b = (IASTSimpleDeclaration) decl.getDeclaration(); IASTSimpleDeclaration b = (IASTSimpleDeclaration) decl.getDeclaration();
IASTInitializerExpression initializerExpression = (IASTInitializerExpression) b.getDeclarators()[0].getInitializer(); IASTEqualsInitializer initializerExpression = (IASTEqualsInitializer) b.getDeclarators()[0].getInitializer();
assertSoleLocation(initializerExpression,code.indexOf("new B()"), "new B()".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertSoleLocation(initializerExpression.getInitializerClause(),code.indexOf("new B()"), "new B()".length()); //$NON-NLS-1$ //$NON-NLS-2$
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) initializerExpression.getExpression(); ICPPASTNewExpression newExpression = (ICPPASTNewExpression) initializerExpression.getInitializerClause();
assertSoleLocation(newExpression, code.indexOf("new B()"), "new B()".length()); //$NON-NLS-1$ //$NON-NLS-2$ assertSoleLocation(newExpression, code.indexOf("new B()"), "new B()".length()); //$NON-NLS-1$ //$NON-NLS-2$
} }
@ -620,8 +620,8 @@ public class DOMLocationTests extends AST2BaseTest {
IASTDeclarator[] declarators= simpleDecl.getDeclarators(); IASTDeclarator[] declarators= simpleDecl.getDeclarators();
assertEquals(1, declarators.length); assertEquals(1, declarators.length);
IASTInitializer initializer= declarators[0].getInitializer(); IASTInitializer initializer= declarators[0].getInitializer();
assertTrue(initializer instanceof IASTInitializerExpression); assertTrue(initializer instanceof IASTEqualsInitializer);
IASTExpression expr= ((IASTInitializerExpression)initializer).getExpression(); IASTInitializerClause expr= ((IASTEqualsInitializer)initializer).getInitializerClause();
assertTrue(expr instanceof IASTTypeIdExpression); assertTrue(expr instanceof IASTTypeIdExpression);
assertSoleLocation(expr, buffer.indexOf("sizeof"), "sizeof(int)".length()); assertSoleLocation(expr, buffer.indexOf("sizeof"), "sizeof(int)".length());
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others. * Rapperswil, University of applied sciences and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -12,7 +12,8 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorEndifStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorEndifStatement;
@ -177,7 +178,9 @@ public class DOMPreprocessorInformationTest extends AST2BaseTest {
assertTrue(st[0] instanceof IASTPreprocessorFunctionStyleMacroDefinition); assertTrue(st[0] instanceof IASTPreprocessorFunctionStyleMacroDefinition);
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTInitializer init = decl.getDeclarators()[0].getInitializer(); IASTEqualsInitializer einit = (IASTEqualsInitializer) decl.getDeclarators()[0].getInitializer();
IASTInitializerClause init= einit.getInitializerClause();
IASTNodeLocation[] nodeLocations = init.getNodeLocations(); IASTNodeLocation[] nodeLocations = init.getNodeLocations();
assertEquals(1, nodeLocations.length); assertEquals(1, nodeLocations.length);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -17,8 +17,9 @@ import java.io.Writer;
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil; import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
@ -89,12 +90,12 @@ public class GCCCompleteParseExtensionsTest extends AST2BaseTest {
public void testBug39698A() throws Exception public void testBug39698A() throws Exception
{ {
IASTDeclaration[] decls = parseGPP("int a=0; \n int b=1; \n int c = a <? b;").getDeclarations(); //$NON-NLS-1$ IASTDeclaration[] decls = parseGPP("int a=0; \n int b=1; \n int c = a <? b;").getDeclarations(); //$NON-NLS-1$
assertEquals( ASTSignatureUtil.getExpressionString( ((IASTInitializerExpression)((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getInitializer()).getExpression() ), "a <? b" ); //$NON-NLS-1$ assertEquals( ASTSignatureUtil.getExpressionString( (IASTExpression) ((IASTEqualsInitializer)((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getInitializer()).getInitializerClause() ), "a <? b" ); //$NON-NLS-1$
} }
public void testBug39698B() throws Exception public void testBug39698B() throws Exception
{ {
IASTDeclaration[] decls = parseGPP("int a=0; \n int b=1; \n int c = a >? b;").getDeclarations(); //$NON-NLS-1$ IASTDeclaration[] decls = parseGPP("int a=0; \n int b=1; \n int c = a >? b;").getDeclarations(); //$NON-NLS-1$
assertEquals( ASTSignatureUtil.getExpressionString( ((IASTInitializerExpression)((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getInitializer()).getExpression() ), "a >? b" ); //$NON-NLS-1$ assertEquals( ASTSignatureUtil.getExpressionString( (IASTExpression) ((IASTEqualsInitializer)((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getInitializer()).getInitializerClause() ), "a >? b" ); //$NON-NLS-1$
} }
public void testPredefinedSymbol_bug69791() throws Exception { public void testPredefinedSymbol_bug69791() throws Exception {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -54,7 +54,8 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition)decl; CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition)decl;
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$ CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr); ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, null);
newInitializer.setInitializerValue(initExpr);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, fdef, newInitializer, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, fdef, newInitializer, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -53,7 +53,8 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
ICPPASTConstructorChainInitializer ctorInitializer = functionDeclarator.getConstructorChain()[0]; ICPPASTConstructorChainInitializer ctorInitializer = functionDeclarator.getConstructorChain()[0];
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$ CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr); ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, null);
newInitializer.setInitializerValue(initExpr);
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, ctorInitializer, newInitializer, null); ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, ctorInitializer, newInitializer, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -14,7 +14,9 @@ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
@ -49,7 +51,8 @@ public class NewInitializerExpressionTest extends ChangeGeneratorTest {
public int visit(IASTExpression expression) { public int visit(IASTExpression expression) {
if (expression instanceof ICPPASTNewExpression) { if (expression instanceof ICPPASTNewExpression) {
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression; ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, newExpression.getNewInitializer(), null, null); final IASTNode lit = ((ICPPASTConstructorInitializer) newExpression.getInitializer()).getArguments()[0];
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, lit, null, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -58,7 +58,8 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
for(ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){ for(ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$ CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr); ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, null);
newInitializer.setInitializerValue(initExpr);
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curInitializer, newInitializer, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE, curInitializer, newInitializer, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -18,7 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTInitializerExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
@ -57,7 +57,7 @@ public class InitializerTest extends ChangeGeneratorTest {
IASTInitializer initializer = fieldDeclarator.getInitializer(); IASTInitializer initializer = fieldDeclarator.getInitializer();
CPPASTLiteralExpression litEx = new CPPASTLiteralExpression(0, "999"); //$NON-NLS-1$ CPPASTLiteralExpression litEx = new CPPASTLiteralExpression(0, "999"); //$NON-NLS-1$
CPPASTInitializerExpression initExpr = new CPPASTInitializerExpression(litEx); CPPASTEqualsInitializer initExpr = new CPPASTEqualsInitializer(litEx);
ASTModification modification = new ASTModification(ModificationKind.REPLACE, initializer, initExpr, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE, initializer, initExpr, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -14,7 +14,9 @@ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
@ -54,7 +56,8 @@ public class NewInitializerExpressionTest extends ChangeGeneratorTest {
public int visit(IASTExpression expression) { public int visit(IASTExpression expression) {
if (expression instanceof ICPPASTNewExpression) { if (expression instanceof ICPPASTNewExpression) {
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression; ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, newExpression.getNewInitializer(), new CPPASTLiteralExpression(0, "6"), null); //$NON-NLS-1$ final IASTNode lit = ((ICPPASTConstructorInitializer) newExpression.getInitializer()).getArguments()[0];
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, lit, new CPPASTLiteralExpression(0, "6".toCharArray()), null); //$NON-NLS-1$
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -50,13 +50,18 @@ int fun3(int i, const char *a, ...);
//!CPPFunctionDeclaratorTest //!CPPFunctionDeclaratorTest
//%CPP //%CPP
char & operator [](unsigned int); char & operator [](unsigned int);
class TestClass
{
int alpha;
TestClass(int a);
virtual void pure() =0;
};
TestClass::TestClass(int a) TestClass::TestClass(int a)
:alpha(a) :alpha(a)
{ {
} }
void undefPar(const char *c) throw (int); void undefPar(const char *c) throw (int);
virtual void pure() = 0;
int getV() const; int getV() const;
int vol() volatile; int vol() volatile;

View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.cdt.core" version="2">
<resource path="parser/org/eclipse/cdt/core/dom/ast/IASTImplicitName.java" type="org.eclipse.cdt.core.dom.ast.IASTImplicitName">
<filter id="403853384">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.dom.ast.IASTImplicitName"/>
</message_arguments>
</filter>
</resource>
<resource path="parser/org/eclipse/cdt/core/dom/ast/IASTImplicitNameOwner.java" type="org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner">
<filter id="403853384">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner"/>
</message_arguments>
</filter>
</resource>
<resource path="parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTArraySubscriptExpression.java" type="org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArraySubscriptExpression">
<filter id="403853384">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArraySubscriptExpression"/>
</message_arguments>
</filter>
</resource>
<resource path="parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTExpressionList.java" type="org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpressionList">
<filter id="403853384">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpressionList"/>
</message_arguments>
</filter>
</resource>
<resource path="parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionCallExpression.java" type="org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression">
<filter id="403853384">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression"/>
</message_arguments>
</filter>
</resource>
<resource path="parser/org/eclipse/cdt/core/parser/IInactiveCodeToken.java" type="org.eclipse.cdt.core.parser.IInactiveCodeToken">
<filter id="403853384">
<message_arguments>
<message_argument value="org.eclipse.cdt.core.parser.IInactiveCodeToken"/>
</message_arguments>
</filter>
</resource>
</component>

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
@ -26,7 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -51,12 +52,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; 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.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.Keywords;
@ -324,20 +325,20 @@ public class ASTStringUtil {
} }
private static StringBuilder appendInitializerString(StringBuilder buffer, IASTInitializer initializer) { private static StringBuilder appendInitializerString(StringBuilder buffer, IASTInitializer initializer) {
if (initializer instanceof IASTInitializerExpression) { if (initializer instanceof IASTEqualsInitializer) {
final IASTInitializerExpression initializerExpression= (IASTInitializerExpression)initializer; final IASTEqualsInitializer initializerExpression= (IASTEqualsInitializer)initializer;
buffer.append(Keywords.cpASSIGN); buffer.append(Keywords.cpASSIGN);
appendExpressionString(buffer, initializerExpression.getExpression()); appendInitClauseString(buffer, initializerExpression.getInitializerClause());
} else if (initializer instanceof IASTInitializerList) { } else if (initializer instanceof IASTInitializerList) {
final IASTInitializerList initializerList= (IASTInitializerList)initializer; final IASTInitializerList initializerList= (IASTInitializerList)initializer;
final IASTInitializer[] initializers= initializerList.getInitializers(); final IASTInitializerClause[] initializers= initializerList.getClauses();
buffer.append(Keywords.cpASSIGN); buffer.append(Keywords.cpASSIGN);
buffer.append(Keywords.cpLBRACE); buffer.append(Keywords.cpLBRACE);
for (int i= 0; i < initializers.length; i++) { for (int i= 0; i < initializers.length; i++) {
if (i > 0) { if (i > 0) {
buffer.append(COMMA_SPACE); buffer.append(COMMA_SPACE);
} }
appendInitializerString(buffer, initializers[i]); appendInitClauseString(buffer, initializers[i]);
} }
trimRight(buffer); trimRight(buffer);
buffer.append(Keywords.cpRBRACE); buffer.append(Keywords.cpRBRACE);
@ -347,9 +348,14 @@ public class ASTStringUtil {
// final ICASTDesignator[] designator= designatedInitializer.getDesignators(); // final ICASTDesignator[] designator= designatedInitializer.getDesignators();
} else if (initializer instanceof ICPPASTConstructorInitializer) { } else if (initializer instanceof ICPPASTConstructorInitializer) {
final ICPPASTConstructorInitializer constructorInitializer= (ICPPASTConstructorInitializer)initializer; final ICPPASTConstructorInitializer constructorInitializer= (ICPPASTConstructorInitializer)initializer;
final IASTExpression expression= constructorInitializer.getExpression(); final IASTInitializerClause[] clauses= constructorInitializer.getArguments();
buffer.append(Keywords.cpLPAREN); buffer.append(Keywords.cpLPAREN);
appendExpressionString(buffer, expression); for (int i= 0; i < clauses.length; i++) {
if (i > 0) {
buffer.append(COMMA_SPACE);
}
appendInitClauseString(buffer, clauses[i]);
}
trimRight(buffer); trimRight(buffer);
buffer.append(Keywords.cpRPAREN); buffer.append(Keywords.cpRPAREN);
} else if (initializer != null) { } else if (initializer != null) {
@ -358,6 +364,14 @@ public class ASTStringUtil {
return buffer; return buffer;
} }
private static void appendInitClauseString(StringBuilder buffer, IASTInitializerClause initializerClause) {
if (initializerClause instanceof IASTExpression) {
appendExpressionString(buffer, (IASTExpression) initializerClause);
} else if (initializerClause instanceof IASTInitializer) {
appendInitializerString(buffer, (IASTInitializer) initializerClause);
}
}
private static StringBuilder appendTypeIdString(StringBuilder buffer, IASTTypeId typeId) { private static StringBuilder appendTypeIdString(StringBuilder buffer, IASTTypeId typeId) {
appendDeclSpecifierString(buffer, typeId.getDeclSpecifier()); appendDeclSpecifierString(buffer, typeId.getDeclSpecifier());
appendDeclaratorString(buffer, typeId.getAbstractDeclarator(), false, null); appendDeclaratorString(buffer, typeId.getAbstractDeclarator(), false, null);
@ -681,14 +695,12 @@ public class ASTStringUtil {
} }
appendExpressionString(buffer, expressions[i]); appendExpressionString(buffer, expressions[i]);
} }
} else if (expression instanceof ICPPASTTypenameExpression) { } else if (expression instanceof ICPPASTSimpleTypeConstructorExpression) {
final ICPPASTTypenameExpression typenameExpression= (ICPPASTTypenameExpression)expression; final ICPPASTSimpleTypeConstructorExpression typeCast= (ICPPASTSimpleTypeConstructorExpression)expression;
buffer.append(Keywords.TYPENAME).append(' '); appendDeclSpecifierString(buffer, typeCast.getDeclSpecifier());
appendQualifiedNameString(buffer, typenameExpression.getName()); final IASTInitializer init= typeCast.getInitializer();
final IASTExpression initialValue= typenameExpression.getInitialValue(); if (init != null) {
if (initialValue != null) { appendInitializerString(buffer, init);
buffer.append(Keywords.cpASSIGN);
appendExpressionString(buffer, initialValue);
} }
} else if (expression instanceof IASTLiteralExpression) { } else if (expression instanceof IASTLiteralExpression) {
buffer.append(ASTSignatureUtil.getExpressionString(expression)); buffer.append(ASTSignatureUtil.getExpressionString(expression));

View file

@ -28,7 +28,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
@ -324,16 +323,12 @@ public class ASTSignatureUtil {
public static String getInitializerString(IASTInitializer init) { public static String getInitializerString(IASTInitializer init) {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
if (init instanceof IASTInitializerExpression) { if (init instanceof IASTEqualsInitializer) {
result.append(getExpressionString(((IASTInitializerExpression) init).getExpression())); result.append(Keywords.cpASSIGN);
result.append(getInitializerClauseString(((IASTEqualsInitializer) init).getInitializerClause()));
} else if (init instanceof IASTInitializerList) { } else if (init instanceof IASTInitializerList) {
result.append(Keywords.cpLBRACE); result.append(Keywords.cpLBRACE);
IASTInitializer[] inits = ((IASTInitializerList) init).getInitializers(); appendExpressionList(result, ((IASTInitializerList) init).getClauses());
for (int i = 0; i < inits.length; i++) {
result.append(getInitializerString(inits[i]));
if (i < inits.length - 1)
result.append(COMMA_SPACE);
}
result.append(Keywords.cpRBRACE); result.append(Keywords.cpRBRACE);
} else if (init instanceof ICASTDesignatedInitializer) { } else if (init instanceof ICASTDesignatedInitializer) {
ICASTDesignator[] designators = ((ICASTDesignatedInitializer) init).getDesignators(); ICASTDesignator[] designators = ((ICASTDesignatedInitializer) init).getDesignators();
@ -343,16 +338,34 @@ public class ASTSignatureUtil {
result.append(COMMA_SPACE); result.append(COMMA_SPACE);
} }
result.append(Keywords.cpASSIGN); result.append(Keywords.cpASSIGN);
result.append(getInitializerString(((ICASTDesignatedInitializer) init).getOperandInitializer())); result.append(getInitializerClauseString(((ICASTDesignatedInitializer) init).getOperand()));
} else if (init instanceof ICPPASTConstructorInitializer) { } else if (init instanceof ICPPASTConstructorInitializer) {
result.append("("); //$NON-NLS-1$ result.append("("); //$NON-NLS-1$
result.append(getExpressionString(((ICPPASTConstructorInitializer) init).getExpression())); appendExpressionList(result, ((ICPPASTConstructorInitializer) init).getArguments());
result.append(")"); //$NON-NLS-1$ result.append(")"); //$NON-NLS-1$
} }
return result.toString(); return result.toString();
} }
private static void appendExpressionList(StringBuffer result, IASTInitializerClause[] inits) {
for (int i = 0; i < inits.length; i++) {
result.append(getInitializerClauseString(inits[i]));
if (i < inits.length - 1)
result.append(COMMA_SPACE);
}
}
private static String getInitializerClauseString(IASTInitializerClause initializerClause) {
if (initializerClause instanceof IASTExpression) {
return getExpressionString((IASTExpression) initializerClause);
}
if (initializerClause instanceof IASTInitializer) {
return getInitializerString((IASTInitializer) initializerClause);
}
return ""; //$NON-NLS-1$
}
private static String getDesignatorSignature(ICASTDesignator designator) { private static String getDesignatorSignature(ICASTDesignator designator) {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
@ -796,8 +809,6 @@ public class ASTSignatureUtil {
return getNewExpression((ICPPASTNewExpression)expression); return getNewExpression((ICPPASTNewExpression)expression);
else if (expression instanceof ICPPASTSimpleTypeConstructorExpression) else if (expression instanceof ICPPASTSimpleTypeConstructorExpression)
return getSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression)expression); return getSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression)expression);
else if (expression instanceof ICPPASTTypenameExpression)
return getTypenameExpression((ICPPASTTypenameExpression)expression);
else if (expression instanceof IGNUASTCompoundStatementExpression) else if (expression instanceof IGNUASTCompoundStatementExpression)
return getCompoundStatementExpression((IGNUASTCompoundStatementExpression)expression); return getCompoundStatementExpression((IGNUASTCompoundStatementExpression)expression);
else if (expression instanceof ICPPASTPackExpansionExpression) else if (expression instanceof ICPPASTPackExpansionExpression)
@ -856,7 +867,13 @@ public class ASTSignatureUtil {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
result.append(getExpressionString(expression.getFunctionNameExpression())); result.append(getExpressionString(expression.getFunctionNameExpression()));
result.append(Keywords.cpLPAREN); result.append(Keywords.cpLPAREN);
result.append(getExpressionString(expression.getParameterExpression())); IASTInitializerClause[] clauses = expression.getArguments();
for (int i= 0; i < clauses.length; i++) {
if (i > 0) {
result.append(COMMA_SPACE);
}
result.append(getInitializerClauseString(clauses[i]));
}
result.append(Keywords.cpRPAREN); result.append(Keywords.cpRPAREN);
return result.toString(); return result.toString();
} }
@ -881,58 +898,8 @@ public class ASTSignatureUtil {
private static String getSimpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression expression) { private static String getSimpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression expression) {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
switch (expression.getSimpleType()) { result.append(getSignature(expression.getDeclSpecifier()));
case ICPPASTSimpleTypeConstructorExpression.t_bool: result.append(getInitializerString(expression.getInitializer()));
result.append(Keywords.BOOL);
break;
case ICPPASTSimpleTypeConstructorExpression.t_char:
result.append(Keywords.CHAR);
break;
case ICPPASTSimpleTypeConstructorExpression.t_double:
result.append(Keywords.DOUBLE);
break;
case ICPPASTSimpleTypeConstructorExpression.t_float:
result.append(Keywords.FLOAT);
break;
case ICPPASTSimpleTypeConstructorExpression.t_int:
result.append(Keywords.INT);
break;
case ICPPASTSimpleTypeConstructorExpression.t_long:
result.append(Keywords.LONG);
break;
case ICPPASTSimpleTypeConstructorExpression.t_short:
result.append(Keywords.SHORT);
break;
case ICPPASTSimpleTypeConstructorExpression.t_signed:
result.append(Keywords.SIGNED);
break;
case ICPPASTSimpleTypeConstructorExpression.t_unsigned:
result.append(Keywords.UNSIGNED);
break;
case ICPPASTSimpleTypeConstructorExpression.t_void:
result.append(Keywords.VOID);
break;
case ICPPASTSimpleTypeConstructorExpression.t_wchar_t:
result.append(Keywords.WCHAR_T);
break;
}
result.append(Keywords.cpLPAREN);
result.append(expression.getInitialValue());
result.append(Keywords.cpRPAREN);
return result.toString();
}
private static String getTypenameExpression(ICPPASTTypenameExpression expression) {
StringBuffer result = new StringBuffer();
result.append(Keywords.TYPENAME);
result.append(SPACE);
result.append(expression.getName().toString());
IASTExpression initValue = expression.getInitialValue();
result.append(Keywords.cpLPAREN);
if (initValue != null) {
result.append(getExpressionString(initValue));
}
result.append(Keywords.cpRPAREN);
return result.toString(); return result.toString();
} }
@ -1004,13 +971,16 @@ public class ASTSignatureUtil {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
result.append(Keywords.NEW); result.append(Keywords.NEW);
result.append(SPACE); result.append(SPACE);
if (expression.getNewPlacement() != null) { final IASTInitializerClause[] args = expression.getPlacementArguments();
result.append(getExpressionString(expression.getNewPlacement())); if (args != null) {
result.append("("); //$NON-NLS-1$
appendExpressionList(result, args);
result.append(")"); //$NON-NLS-1$
} }
result.append(getSignature(expression.getTypeId())); result.append(getSignature(expression.getTypeId()));
result.append(Keywords.cpLPAREN); final IASTInitializer initializer = expression.getInitializer();
result.append(getExpressionString(expression.getNewInitializer())); if (initializer != null)
result.append(Keywords.cpRPAREN); result.append(getInitializerString(initializer));
return result.toString(); return result.toString();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -19,15 +19,18 @@ package org.eclipse.cdt.core.dom.ast;
*/ */
public interface IASTArraySubscriptExpression extends IASTExpression { public interface IASTArraySubscriptExpression extends IASTExpression {
/** public static final ASTNodeProperty ARRAY = new ASTNodeProperty(
* Node property that describes the relationship between an "IASTArraySubscriptExpression.ARRAY [IASTExpression]"); //$NON-NLS-1$
* <code>IASTArraySubscriptExpression</code> and an public static final ASTNodeProperty SUBSCRIPT = new ASTNodeProperty(
* <code>IASTExpression</code> representing the subscript. "IASTArraySubscriptExpression.SUBSCRIPT - [IASTFunctionArgument]"); //$NON-NLS-1$
*/
public static final ASTNodeProperty ARRAY = new ASTNodeProperty("IASTArraySubscriptExpression.ARRAY - IASTExpression representing the Array"); //$NON-NLS-1$
/** /**
* Get the expression that represents the array. * @since 5.1
*/
IASTArraySubscriptExpression copy();
/**
* Get the expression that represents the array
* *
* @return <code>IASTExpression</code> that represents the array. * @return <code>IASTExpression</code> that represents the array.
*/ */
@ -42,30 +45,24 @@ public interface IASTArraySubscriptExpression extends IASTExpression {
public void setArrayExpression(IASTExpression expression); public void setArrayExpression(IASTExpression expression);
/** /**
* Node property that describes the relationship between an * Returns the operand of this expression. In c++ the operand can be a braced initializer list.
* <code>IASTArraySubscriptExpression</code> and an * @since 5.2
* <code>IASTExpression</code> representing the array.
*/ */
public static final ASTNodeProperty SUBSCRIPT = new ASTNodeProperty( public IASTInitializerClause getArgument();
"IASTArraySubscriptExpression.SUBSCRIPT - IASTExpression representing the Subscript"); //$NON-NLS-1$
/** /**
* Get the subscript expression. * Not allowed on frozen ast.
* * @since 5.2
* @return <code>IASTExpression</code> that represents the subscript. */
public void setArgument(IASTInitializerClause expression);
/**
* Returns the subscript expression, or <code>null</code>. Consider using {@link #getArgument()}.
*/ */
public IASTExpression getSubscriptExpression(); public IASTExpression getSubscriptExpression();
/** /**
* Set the subscript expression. * Not allowed on frozen ast.
*
* @param expression
* <code>IASTExpression</code> to be set.
*/ */
public void setSubscriptExpression(IASTExpression expression); public void setSubscriptExpression(IASTExpression expression);
/**
* @since 5.1
*/
public IASTArraySubscriptExpression copy();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Doug Schaefer (IBM) - Initial API and implementation * Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
@ -254,6 +255,13 @@ public interface IASTBinaryExpression extends IASTExpression {
*/ */
public IASTExpression getOperand2(); public IASTExpression getOperand2();
/**
* Returns the second operand of the expression. For c++ assignment expressions this can be
* a braced list initializer.
* @since 5.2
*/
public IASTInitializerClause getInitOperand2();
/** /**
* @param expression * @param expression
* <code>IASTExpression</code> value * <code>IASTExpression</code> value

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. and others. * Copyright (c) 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,17 +8,28 @@
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
/** /**
* Initializer expression for c++. * Initializer with equals sign (copy initialization) as in <code>int x= 0;</code>.
* * @since 5.2
*
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
* @since 5.2
*/ */
public interface ICPPASTInitializerExpression extends IASTInitializerExpression, ICPPASTInitializer { public interface IASTEqualsInitializer extends IASTInitializer {
ASTNodeProperty INITIALIZER = new ASTNodeProperty(
"IASTEqualsInitializer - INITIALIZER [IASTInitializerClause]"); //$NON-NLS-1$
/**
* Returns the expression or braced initializer list of this initializer.
*/
IASTInitializerClause getInitializerClause();
/**
* Not allowed on frozen ast.
*/
void setInitializerClause(IASTInitializerClause clause);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -17,7 +17,7 @@ package org.eclipse.cdt.core.dom.ast;
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTExpression extends IASTNode { public interface IASTExpression extends IASTInitializerClause {
/** /**
* Empty expression array. * Empty expression array.
*/ */

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* John Camelon (IBM Rational Software) - Initial API and implementation * John Camelon (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
@ -19,55 +20,54 @@ package org.eclipse.cdt.core.dom.ast;
*/ */
public interface IASTFunctionCallExpression extends IASTExpression { public interface IASTFunctionCallExpression extends IASTExpression {
/**
* <code>FUNCTION_NAME</code> represents the relationship between a
* <code>IASTFunctionCallExpression</code> and its
* <code>IASTExpression</code> (function name).
*/
public static final ASTNodeProperty FUNCTION_NAME = new ASTNodeProperty( public static final ASTNodeProperty FUNCTION_NAME = new ASTNodeProperty(
"IASTFunctionCallExpression.FUNCTION_Name - IASTExpression (name) for IASTFunctionCallExpression"); //$NON-NLS-1$ "IASTFunctionCallExpression.FUNCTION_NAME [IASTExpression]"); //$NON-NLS-1$
/** /**
* Set the function name expression. * @since 5.2
*
* @param expression
* <code>IASTExpression</code> representing the function name
*/ */
public void setFunctionNameExpression(IASTExpression expression); public static final ASTNodeProperty ARGUMENT = new ASTNodeProperty(
"IASTFunctionCallExpression.ARGUMENT [IASTInitializerClause]"); //$NON-NLS-1$
/** /**
* Get the function name expression. * Get the function name expression.
*
* @return <code>IASTExpression</code> representing the function name
*/ */
public IASTExpression getFunctionNameExpression(); public IASTExpression getFunctionNameExpression();
/** /**
* <code>PARAMETERS</code> represents the relationship between a * Returns the arguments for this function call, never <code>null</code>.
* <code>IASTFunctionCallExpression</code> and its * @since 5.2
* <code>IASTExpression</code> (parameters).
*/ */
public static final ASTNodeProperty PARAMETERS = new ASTNodeProperty( public IASTInitializerClause[] getArguments();
"IASTFunctionCallExpression.PARAMETERS - IASTExpression (parameters) for IASTFunctionCallExpression"); //$NON-NLS-1$
/**
* Set the parameters expression.
*
* @param expression
* <code>IASTExpression</code> representing the parameters
*/
public void setParameterExpression(IASTExpression expression);
/**
* Get the parameter expression.
*
* @return <code>IASTExpression</code> representing the parameters
*/
public IASTExpression getParameterExpression();
/** /**
* @since 5.1 * @since 5.1
*/ */
public IASTFunctionCallExpression copy(); public IASTFunctionCallExpression copy();
/**
* Not allowed on frozen ast.
*/
public void setFunctionNameExpression(IASTExpression expression);
/**
* Not allowed on frozen ast.
* @since 5.2
*/
public void setArguments(IASTInitializerClause[] args);
@Deprecated
public static final ASTNodeProperty PARAMETERS = ARGUMENT;
/**
* @deprecated Replaced by {@link #setArguments(IASTInitializerClause[])}.
*/
@Deprecated
public void setParameterExpression(IASTExpression expression);
/**
* @deprecated Replaced by {@link #getArguments()}.
*/
@Deprecated
public IASTExpression getParameterExpression();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others. * Copyright (c) 2009, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -18,6 +18,8 @@ package org.eclipse.cdt.core.dom.ast;
* *
* @see ASTVisitor#shouldVisitImplicitNames * @see ASTVisitor#shouldVisitImplicitNames
* @since 5.1 * @since 5.1
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTImplicitName extends IASTName { public interface IASTImplicitName extends IASTName {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others. * Copyright (c) 2009, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,6 +14,8 @@ package org.eclipse.cdt.core.dom.ast;
/** /**
* An implicit name generated on demand. * An implicit name generated on demand.
* @since 5.1 * @since 5.1
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTImplicitNameOwner extends IASTNode { public interface IASTImplicitNameOwner extends IASTNode {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. and others. * Copyright (c) 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,15 +8,15 @@
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
/** /**
* Initializer for c++ * Interface for ast nodes that can nest in initializer lists.
* * @since 5.2
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
* @since 5.2
*/ */
public interface ICPPASTInitializer extends IASTInitializer, ICPPASTPackExpandable {} public interface IASTInitializerClause extends IASTNode {
IASTInitializerClause copy();
}

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -15,15 +15,16 @@ package org.eclipse.cdt.core.dom.ast;
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
* @deprecated Replaced by {@link IASTEqualsInitializer}.
*/ */
public interface IASTInitializerExpression extends IASTInitializer { @Deprecated
public interface IASTInitializerExpression extends IASTEqualsInitializer {
/** /**
* <code>INITIALIZER_EXPRESSION</code> represents the relationship between * <code>INITIALIZER_EXPRESSION</code> represents the relationship between
* an <code>IASTInitializerExpression</code>. and its <code></code>IASTExpression</code>. * an <code>IASTInitializerExpression</code>. and its <code></code>IASTExpression</code>.
*/ */
public static final ASTNodeProperty INITIALIZER_EXPRESSION = new ASTNodeProperty( public static final ASTNodeProperty INITIALIZER_EXPRESSION = INITIALIZER;
"IASTInitializerExpression.INITIALIZER_EXPRESSION - IASTExpression for IASTInitializerExpression"); //$NON-NLS-1$
/** /**
* Get the expression for the initializer. * Get the expression for the initializer.

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,25 +7,21 @@
* *
* Contributors: * Contributors:
* Doug Schaefer (IBM) - Initial API and implementation * Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* This is an an initializer that is a list of initializers. * Braced initializer list, for example as in:
* For example as in:
* <pre> int a[]= {1,2,3}; </pre> * <pre> int a[]= {1,2,3}; </pre>
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTInitializerList extends IASTInitializer { public interface IASTInitializerList extends IASTInitializer, IASTInitializerClause {
/**
* <code>NESTED_INITIALIZER</code> describes the relationship between an
* <code>IASTInitializerList</code> and its sub-<code>IASTInitializer</code>s.
*/
public static final ASTNodeProperty NESTED_INITIALIZER = new ASTNodeProperty( public static final ASTNodeProperty NESTED_INITIALIZER = new ASTNodeProperty(
"IASTInitializerList.NESTED_INITIALIZER - sub-IASTInitializer for IASTInitializerList"); //$NON-NLS-1$ "IASTInitializerList.NESTED_INITIALIZER [IASTInitializerClause]"); //$NON-NLS-1$
/** /**
* Returns the size of the initializer list, including trivial initializers. This size may * Returns the size of the initializer list, including trivial initializers. This size may
@ -37,18 +33,34 @@ public interface IASTInitializerList extends IASTInitializer {
/** /**
* Returns the list of initializers. Depending on how the ast was created, this may omit * Returns the list of initializers. Depending on how the ast was created, this may omit
* trivial initializers in order to save memory. * trivial initializers in order to save memory.
* @since 5.2
*/ */
public IASTInitializer[] getInitializers(); public IASTInitializerClause[] getClauses();
/** /**
* Add an initializer to the initializer list. Depending on how the AST is created the * Add an initializer clause to the initializer list. Depending on how the AST is created the
* initializer may be <code>null</code>. A <code>null</code> initializer will not be returned * initializer may be <code>null</code>. A <code>null</code> initializer will not be returned
* by {@link #getInitializers()}, however it contributes to the actual element count (#getSize()). * by {@link #getInitializers()}, however it contributes to the actual element count (#getSize()).
* @since 5.2
*/ */
public void addInitializer(IASTInitializer initializer); public void addClause(IASTInitializerClause clause);
/** /**
* @since 5.1 * @since 5.1
*/ */
public IASTInitializerList copy(); public IASTInitializerList copy();
/**
* @deprecated Replaced by {@link #getClauses()}.
*/
@Deprecated
public IASTInitializer[] getInitializers();
/**
* @deprecated Replaced by {@link #addClause(IASTInitializerClause)}.
*/
@Deprecated
public void addInitializer(IASTInitializer initializer);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Doug Schaefer (IBM) - Initial API and implementation * Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
@ -16,13 +17,8 @@ package org.eclipse.cdt.core.dom.ast;
*/ */
public interface IASTReturnStatement extends IASTStatement { public interface IASTReturnStatement extends IASTStatement {
/**
* <code>RETURNVALUE</code> represents the relationship between an
* <code>IASTReturnStatement</code> and it's nested
* <code>IASTExpression</code>.
*/
public static final ASTNodeProperty RETURNVALUE = new ASTNodeProperty( public static final ASTNodeProperty RETURNVALUE = new ASTNodeProperty(
"IASTReturnValue.RETURNVALUE - IASTExpression (returnValue) for IASTReturnStatement"); //$NON-NLS-1$ "IASTReturnValue.RETURNVALUE - [IASTInitializerClause]"); //$NON-NLS-1$
/** /**
* This is the optional return value for this function. * This is the optional return value for this function.
@ -32,10 +28,20 @@ public interface IASTReturnStatement extends IASTStatement {
public IASTExpression getReturnValue(); public IASTExpression getReturnValue();
/** /**
* Set the return value. * Returns the return value as {@link IASTInitializerClause}, or <code>null</code>.
* * In c++ this can be an braced initializer list.
* @param returnValue * @since 5.2
* <code>IASTExpression</code> */
public IASTInitializerClause getReturnArgument();
/**
* Not allowed on frozen ast.
* @since 5.2
*/
public void setReturnArgument(IASTInitializerClause returnValue);
/**
* Not allowed on frozen ast.
*/ */
public void setReturnValue(IASTExpression returnValue); public void setReturnValue(IASTExpression returnValue);

View file

@ -1,12 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2009 IBM Corporation and others. * Copyright (c) 2006, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * Mike Kucera (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
@ -15,7 +16,6 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
/** /**
* Factory for creating AST nodes. This interface contains factory methods * Factory for creating AST nodes. This interface contains factory methods
* for nodes that are available for both C and C++. * for nodes that are available for both C and C++.
@ -33,13 +33,102 @@ import org.eclipse.cdt.core.parser.IToken;
* *
* None of the factory methods should return null. * None of the factory methods should return null.
* *
* @author Mike Kucera
* @since 5.1 * @since 5.1
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface INodeFactory { public interface INodeFactory {
public IASTArrayDeclarator newArrayDeclarator(IASTName name);
public IASTArrayModifier newArrayModifier(IASTExpression expr);
public IASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript);
public IASTASMDeclaration newASMDeclaration(String assembly);
public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2);
public IASTBreakStatement newBreakStatement();
public IASTCaseStatement newCaseStatement(IASTExpression expr);
public IASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand);
public IASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
public IASTCompoundStatement newCompoundStatement();
public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3);
public IASTContinueStatement newContinueStatement();
public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration);
public IASTDeclarator newDeclarator(IASTName name);
public IASTDefaultStatement newDefaultStatement();
public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition);
public IASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
public IASTEnumerationSpecifier newEnumerationSpecifier(IASTName name);
public IASTEnumerator newEnumerator(IASTName name, IASTExpression value);
/**
* @since 5.2
*/
public IASTEqualsInitializer newEqualsInitializer(IASTInitializerClause initClause);
public IASTExpressionList newExpressionList();
public IASTExpressionStatement newExpressionStatement(IASTExpression expression);
public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize);
public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner);
public IASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpression, IASTStatement body);
/**
* @deprecated Replaced by {@link #newFunctionCallExpression(IASTExpression, IASTInitializerClause[])}
*/
@Deprecated
public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList);
/**
* @since 5.2
*/
public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTInitializerClause[] arguments);
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name);
public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement);
public IASTGotoStatement newGotoStatement(IASTName name);
public IASTIdExpression newIdExpression(IASTName name);
public IASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause);
/**
* @deprecated Replaced by {@link #newEqualsInitializer(IASTInitializerClause)}.
*/
@Deprecated
public IASTInitializerExpression newInitializerExpression(IASTExpression expression);
public IASTInitializerList newInitializerList();
public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement);
public IASTLiteralExpression newLiteralExpression(int kind, String rep);
/** /**
* Creates a "dummy" name using an empty char array. * Creates a "dummy" name using an empty char array.
*/ */
@ -47,12 +136,34 @@ public interface INodeFactory {
public IASTName newName(char[] name); public IASTName newName(char[] name);
public IASTNullStatement newNullStatement();
public IASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator);
public IASTPointer newPointer();
public IASTProblem newProblem(int id, char[] arg, boolean error);
public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem);
public IASTProblemExpression newProblemExpression(IASTProblem problem);
public IASTProblemStatement newProblemStatement(IASTProblem problem);
public IASTReturnStatement newReturnStatement(IASTExpression retValue);
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier);
public IASTSimpleDeclSpecifier newSimpleDeclSpecifier();
public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body);
/** /**
* @deprecated use {@link #newTranslationUnit(IScanner)}, instead. * @deprecated Replaced by {@link #newTranslationUnit(IScanner)}.
*/ */
@Deprecated @Deprecated
public IASTTranslationUnit newTranslationUnit(); public IASTTranslationUnit newTranslationUnit();
/** /**
* Creates a new translation unit that cooperates with the given scanner in order * Creates a new translation unit that cooperates with the given scanner in order
* to track macro-expansions and location information. * to track macro-expansions and location information.
@ -60,112 +171,40 @@ public interface INodeFactory {
* @since 5.2 * @since 5.2
*/ */
public IASTTranslationUnit newTranslationUnit(IScanner scanner); public IASTTranslationUnit newTranslationUnit(IScanner scanner);
public IASTLiteralExpression newLiteralExpression(int kind, String rep);
public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand);
public IASTIdExpression newIdExpression(IASTName name);
public IASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript);
public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList);
public IASTExpressionList newExpressionList();
public IASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand);
public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2);
public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3);
public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer);
public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement);
public IASTCaseStatement newCaseStatement(IASTExpression expr);
public IASTDefaultStatement newDefaultStatement();
public IASTExpressionStatement newExpressionStatement(IASTExpression expression);
public IASTNullStatement newNullStatement();
public IASTCompoundStatement newCompoundStatement();
public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body);
public IASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause);
public IASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition);
public IASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpression, IASTStatement body);
public IASTGotoStatement newGotoStatement(IASTName name);
public IASTContinueStatement newContinueStatement();
public IASTBreakStatement newBreakStatement();
public IASTReturnStatement newReturnStatement(IASTExpression retValue);
public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration);
public IASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId);
public IASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator);
public IASTDeclarator newDeclarator(IASTName name);
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier);
public IASTInitializerExpression newInitializerExpression(IASTExpression expression);
public IASTInitializerList newInitializerList();
public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name);
public IASTASMDeclaration newASMDeclaration(String assembly);
public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem);
public IASTProblemStatement newProblemStatement(IASTProblem problem);
public IASTProblemExpression newProblemExpression(IASTProblem problem);
public IASTProblem newProblem(int id, char[] arg, boolean error);
public IASTEnumerationSpecifier newEnumerationSpecifier(IASTName name);
public IASTEnumerator newEnumerator(IASTName name, IASTExpression value);
public IASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
public IASTArrayModifier newArrayModifier(IASTExpression expr);
public IASTArrayDeclarator newArrayDeclarator(IASTName name);
public IASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator);
public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize);
public IASTSimpleDeclSpecifier newSimpleDeclSpecifier();
public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement);
public IASTPointer newPointer();
public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner);
public IASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name); public IASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name);
public IASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name); public IASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator);
public IASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId);
public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer);
public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand);
public IASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
/**
* Adjusts the end-offset of a node to be the same as the end-offset of a given node.
* <par> May throw an exception when either one of the nodes provided was not created by this factory.
* @param node a node created by this factory
* @param endNode a node created by this factory defining the end for the other node.
* @since 5.2
*/
void setEndOffset(IASTNode node, IASTNode endNode);
/**
* Provides the end offset for a node. The offset is an artificial numbers that identifies the
* position of a node in the translation unit. It is not a file-offset. You can obtain a
* valid offset via {@link IToken#getEndOffset()} from a token provided by the scanner for
* this translation unit.
* <par> May throw an exception when the node provided was not created by this factory.
* @param node a node created by this factory
* @param endOffset the end offset (exclusive) for the node
* @see #newTranslationUnit(IScanner)
* @since 5.2
*/
void setEndOffset(IASTNode node, int endOffset);
/** /**
* Provides the offsets for a node. The offsets are artificial numbers that identify the * Provides the offsets for a node. The offsets are artificial numbers that identify the
@ -180,26 +219,4 @@ public interface INodeFactory {
* @since 5.2 * @since 5.2
*/ */
public void setOffsets(IASTNode node, int offset, int endOffset); public void setOffsets(IASTNode node, int offset, int endOffset);
/**
* Provides the end offset for a node. The offset is an artificial numbers that identifies the
* position of a node in the translation unit. It is not a file-offset. You can obtain a
* valid offset via {@link IToken#getEndOffset()} from a token provided by the scanner for
* this translation unit.
* <par> May throw an exception when the node provided was not created by this factory.
* @param node a node created by this factory
* @param endOffset the end offset (exclusive) for the node
* @see #newTranslationUnit(IScanner)
* @since 5.2
*/
void setEndOffset(IASTNode node, int endOffset);
/**
* Adjusts the end-offset of a node to be the same as the end-offset of a given node.
* <par> May throw an exception when either one of the nodes provided was not created by this factory.
* @param node a node created by this factory
* @param endNode a node created by this factory defining the end for the other node.
* @since 5.2
*/
void setEndOffset(IASTNode node, IASTNode endNode);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,11 +7,13 @@
* *
* Contributors: * Contributors:
* John Camelon (IBM) - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.c; package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
/** /**
* This interface represents a designated initializer. e.g. struct x y = { .z=4, * This interface represents a designated initializer. e.g. struct x y = { .z=4,
@ -20,61 +22,53 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICASTDesignatedInitializer extends IASTInitializer { public interface ICASTDesignatedInitializer extends IASTInitializer, IASTInitializerClause {
/**
* Constant.
*/
public static final ICASTDesignator[] EMPTY_DESIGNATOR_ARRAY = new ICASTDesignator[0]; public static final ICASTDesignator[] EMPTY_DESIGNATOR_ARRAY = new ICASTDesignator[0];
/**
* <code>DESIGNATOR</code> represents the relationship between an
* <code>ICASTDesignatedInitializer</code> and
* <code>ICASTDesignator</code>.
*/
public static final ASTNodeProperty DESIGNATOR = new ASTNodeProperty( public static final ASTNodeProperty DESIGNATOR = new ASTNodeProperty(
"ICASTDesignatedInitializer.DESIGNATOR - relationship between ICASTDesignatedInitializer and ICASTDesignator"); //$NON-NLS-1$ "ICASTDesignatedInitializer.DESIGNATOR [ICASTDesignator]"); //$NON-NLS-1$
public static final ASTNodeProperty OPERAND = new ASTNodeProperty(
"ICASTDesignatedInitializer.OPERAND - [IASTInitializerClause]"); //$NON-NLS-1$
/** /**
* Add a designator to this initializer. * Add a designator to this initializer.
*
* @param designator
* <code>ICASTDesignator</code>
*/ */
public void addDesignator(ICASTDesignator designator); public void addDesignator(ICASTDesignator designator);
/** /**
* Get all of the designators. * Get all of the designators.
*
* @return <code>ICASTDesignator []</code>
*/ */
public ICASTDesignator[] getDesignators(); public ICASTDesignator[] getDesignators();
/** /**
* <code>OPERAND</code> represents the relationship between * Returns the operand initializer.
* <code>ICASTDesignatedInitializer</code> and its * @since 5.2
* <code>IASTInitializer</code>.
*/ */
public static final ASTNodeProperty OPERAND = new ASTNodeProperty( public IASTInitializerClause getOperand();
"ICASTDesignatedInitializer.OPERAND - RHS IASTInitializer for ICASTDesignatedInitializer"); //$NON-NLS-1$
/** /**
* Get the nested initializer. * Not allowed on frozen ast
* * @since 5.2
* @return <code>IASTInitializer</code>
*/ */
public IASTInitializer getOperandInitializer(); void setOperand(IASTInitializerClause operand);
/**
* Set the nested initializer.
*
* @param rhs
* <code>IASTInitializer</code>
*/
public void setOperandInitializer(IASTInitializer rhs);
/** /**
* @since 5.1 * @since 5.1
*/ */
public ICASTDesignatedInitializer copy(); public ICASTDesignatedInitializer copy();
/**
* @deprecated Replaced by {@link #getOperand()};
*/
@Deprecated
public IASTInitializer getOperandInitializer();
/**
* @deprecated Replaced by setOperand();
*/
@Deprecated
public void setOperandInitializer(IASTInitializer rhs);
} }

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.INodeFactory;
@ -30,35 +31,44 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
*/ */
public interface ICNodeFactory extends INodeFactory { public interface ICNodeFactory extends INodeFactory {
public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name); public ICASTArrayDesignator newArrayDesignator(IASTExpression exp);
public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier();
public ICASTPointer newPointer();
public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name);
public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
public ICASTArrayModifier newArrayModifier(IASTExpression expr); public ICASTArrayModifier newArrayModifier(IASTExpression expr);
public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer); public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling);
public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations); public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
/**
* @deprecated Replaced by {@link #newDesignatedInitializer(IASTInitializerClause)}.
*/
@Deprecated
public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer rhs); public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer rhs);
public ICASTArrayDesignator newArrayDesignator(IASTExpression exp); /**
* @since 5.2
*/
public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializerClause initializer);
public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name);
public ICASTFieldDesignator newFieldDesignator(IASTName name); public ICASTFieldDesignator newFieldDesignator(IASTName name);
public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling); public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations);
public ICASTPointer newPointer();
public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier();
/** /**
* @deprecated Replaced by {@link #newSimpleDeclSpecifier()} * @deprecated Replaced by {@link #newSimpleDeclSpecifier()}
*/ */
@Deprecated @Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression); public org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression);
public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name);
public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others. * Copyright (c) 2009, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -15,6 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
/** /**
* @since 5.1 * @since 5.1
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTArraySubscriptExpression extends IASTArraySubscriptExpression, IASTImplicitNameOwner { public interface ICPPASTArraySubscriptExpression extends IASTArraySubscriptExpression, IASTImplicitNameOwner {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,70 +13,67 @@ package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
/** /**
* Represents a member initializer:
* <pre> class X { * <pre> class X {
* int a; * int a;
* X(); * X();
* }; * };
* X::X : a(0) {} // a(0) is a constructor chain initializer. * X::X : a(0) {} // a(0) is a member initializer.
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTConstructorChainInitializer extends ICPPASTInitializer, IASTNameOwner { public interface ICPPASTConstructorChainInitializer extends IASTInitializer, ICPPASTPackExpandable,
/** IASTNameOwner {
* Constant.
*/
public static final ICPPASTConstructorChainInitializer[] EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY = new ICPPASTConstructorChainInitializer[0]; public static final ICPPASTConstructorChainInitializer[] EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY = new ICPPASTConstructorChainInitializer[0];
/**
* <code>MEMBER_ID</code> represents the class field name being
* initialized.
*/
public static final ASTNodeProperty MEMBER_ID = new ASTNodeProperty( public static final ASTNodeProperty MEMBER_ID = new ASTNodeProperty(
"ICPPASTConstructorChainInitializer.MEMBER_ID - Class field name initialized"); //$NON-NLS-1$ "ICPPASTConstructorChainInitializer.MEMBER_ID [IASTName]"); //$NON-NLS-1$
public static final ASTNodeProperty INITIALIZER = new ASTNodeProperty(
"ICPPASTConstructorChainInitializer.INITIALIZER [IASTInitializer]"); //$NON-NLS-1$
/** /**
* Get the field name. * Returns the name of the member.
*
* @return <code>IASTName</code>
*/ */
public IASTName getMemberInitializerId(); public IASTName getMemberInitializerId();
/** /**
* Set the field name. * Returns the initializer for the member
* * @since 5.2
* @param name
* <code>IASTName</code>
*/ */
public void setMemberInitializerId(IASTName name); public IASTInitializer getInitializer();
/**
* <code>Expression field is being initialized to.</code>
*/
public static final ASTNodeProperty INITIALIZER = new ASTNodeProperty(
"ICPPASTConstructorChainInitializer.INITIALIZER - Expression Field Initializer"); //$NON-NLS-1$
/**
* Get the initializer value.
*
* @return <code>IASTExpression</code>
*/
public IASTExpression getInitializerValue();
/**
* Set the initializer value.
*
* @param expression
* <code>IASTExpression</code>
*/
public void setInitializerValue(IASTExpression expression);
/** /**
* @since 5.1 * @since 5.1
*/ */
public ICPPASTConstructorChainInitializer copy(); public ICPPASTConstructorChainInitializer copy();
/**
* Not allowed on frozen ast.
*/
public void setMemberInitializerId(IASTName name);
/**
* Not allowed on frozen ast.
* @since 5.2
*/
public void setInitializer(IASTInitializer initializer);
/**
* @deprecated Replaced by {@link #getInitializer()}.
*/
@Deprecated
public IASTExpression getInitializerValue();
/**
* @deprecated Replaced by {@link #setInitializer(IASTInitializer)}.
*/
@Deprecated
public void setInitializerValue(IASTExpression expression);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,38 +13,56 @@ package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
/** /**
* This is an initializer that is a call to the constructor for the declarator. * Represents a potentially empty list of initializers in parenthesis: ( initializer-list? )
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTConstructorInitializer extends ICPPASTInitializer { public interface ICPPASTConstructorInitializer extends IASTInitializer {
/** /**
* <code>EXPRESSION</code> represents the expression being conusmed in a * @since 5.2
* constructor.
*/ */
public static final ASTNodeProperty EXPRESSION = new ASTNodeProperty( public static final ASTNodeProperty ARGUMENT = new ASTNodeProperty(
"ICPPASTConstructorInitializer.EXPRESSION - Expression consumed in constructor"); //$NON-NLS-1$ "ICPPASTConstructorInitializer.ARGUMENT - [IASTInitializerClause]"); //$NON-NLS-1$
/** /**
* Get the arguments to the constructor. * Returns the arguments of this initializer, never <code>null</code>.
* An argument can be of type {@link IASTInitializerList}.
* *
* @return IASTExpression * @since 5.2
*/ */
public IASTExpression getExpression(); public IASTInitializerClause[] getArguments();
/**
* Set the arguments to the constructor.
*
* @param expression
*/
public void setExpression(IASTExpression expression);
/** /**
* @since 5.1 * @since 5.1
*/ */
public ICPPASTConstructorInitializer copy(); public ICPPASTConstructorInitializer copy();
/**
* Not allowed on frozen ast.
* @since 5.2
*/
public void setArguments(IASTInitializerClause[] args);
/**
* @deprecated Replaced by {@link #getArguments()}.
*/
@Deprecated
public IASTExpression getExpression();
/**
* @deprecated Replaced by {@link #setArguments(IASTInitializerClause[])}.
*/
@Deprecated
public void setExpression(IASTExpression expression);
@Deprecated
public static final ASTNodeProperty EXPRESSION = ARGUMENT;
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others. * Copyright (c) 2009, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -15,6 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
/** /**
* @since 5.1 * @since 5.1
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTExpressionList extends IASTExpressionList, IASTImplicitNameOwner { public interface ICPPASTExpressionList extends IASTExpressionList, IASTImplicitNameOwner {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others. * Copyright (c) 2009, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -15,6 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
/** /**
* @since 5.1 * @since 5.1
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTFunctionCallExpression extends IASTFunctionCallExpression, IASTImplicitNameOwner { public interface ICPPASTFunctionCallExpression extends IASTFunctionCallExpression, IASTImplicitNameOwner {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. and others. * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,12 +13,13 @@ package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
/** /**
* Initializer expression for c++. * Braced initializer list.
* *
* @since 5.2
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
* @since 5.2
*/ */
public interface ICPPASTInitializerList extends IASTInitializerList, ICPPASTInitializer { public interface ICPPASTInitializerList extends IASTInitializerList, ICPPASTPackExpandable {
ICPPASTInitializerList copy();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,8 +14,10 @@ package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
/** /**
* This interface represents a new expression. * This interface represents a new expression.
@ -25,79 +27,38 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
*/ */
public interface ICPPASTNewExpression extends IASTExpression, IASTImplicitNameOwner { public interface ICPPASTNewExpression extends IASTExpression, IASTImplicitNameOwner {
public static final ASTNodeProperty NEW_PLACEMENT = new ASTNodeProperty(
"ICPPASTNewExpression.NEW_PLACEMENT [IASTExpression]"); //$NON-NLS-1$
public static final ASTNodeProperty TYPE_ID = new ASTNodeProperty(
"ICPPASTNewExpression.TYPE_ID - [IASTTypeId]"); //$NON-NLS-1$
public static final ASTNodeProperty NEW_INITIALIZER = new ASTNodeProperty(
"ICPPASTNewExpression.NEW_INITIALIZER - [IASTInitializer]"); //$NON-NLS-1$
/** /**
* Is this a ::new expression? * Is this a ::new expression?
*
* @return boolean
*/ */
public boolean isGlobal(); public boolean isGlobal();
/** /**
* Set this expression to bea global ::new expression (or not). * Returns true if this expression is allocating an array.
* * @since 5.1
* @param value
* boolean
*/ */
public void setIsGlobal(boolean value); public boolean isArrayAllocation();
/** /**
* NEW_PLACEMENT is a role for an expression to represent the location of * Returns the additional arguments for the new placement, or <code>null</code>.
* where the memory should be allocated. * A placement argument can be of type {@link ICPPASTInitializerList}.
* @since 5.2
*/ */
public static final ASTNodeProperty NEW_PLACEMENT = new ASTNodeProperty( public IASTInitializerClause[] getPlacementArguments();
"ICPPASTNewExpression.NEW_PLACEMENT - Location where memory should be allocated"); //$NON-NLS-1$
/**
* Get the new placement (optional).
*
* @return <code>IASTExpression</code>
*/
public IASTExpression getNewPlacement();
/**
* Set the new placement expression.
*
* @param expression
* <code>IASTExpression</code>
*/
public void setNewPlacement(IASTExpression expression);
/**
* <code>NEW_INITIALIZER</code>
*/
public static final ASTNodeProperty NEW_INITIALIZER = new ASTNodeProperty(
"ICPPASTNewExpression.NEW_INITIALIZER - New Initializer"); //$NON-NLS-1$
/**
* @return <code>IASTExpression</code>
*/
public IASTExpression getNewInitializer();
/**
* @param expression
* <code>IASTExpression</code>
*/
public void setNewInitializer(IASTExpression expression);
/**
* TYPE_ID is the type being 'newed'.
*/
public static final ASTNodeProperty TYPE_ID = new ASTNodeProperty("ICPPASTNewExpression.TYPE_ID - The type being 'newed'"); //$NON-NLS-1$
/** /**
* Get the type Id. The type-id includes the optional array modifications. * Get the type Id. The type-id includes the optional array modifications.
* @return <code>IASTTypeId</code>
*/ */
public IASTTypeId getTypeId(); public IASTTypeId getTypeId();
/**
* Set the type Id.
*
* @param typeId
* <code>IASTTypeId</code>
*/
public void setTypeId(IASTTypeId typeId);
/** /**
* Returns whether the the typeID a new type ID, which is the case when * Returns whether the the typeID a new type ID, which is the case when
* the type-id is provided without parenthesis. * the type-id is provided without parenthesis.
@ -105,24 +66,49 @@ public interface ICPPASTNewExpression extends IASTExpression, IASTImplicitNameOw
public boolean isNewTypeId(); public boolean isNewTypeId();
/** /**
* Set the type ID to be a new type ID. * Returns the initializer or <code>null</code>.
* * @since 5.2
* @param value
* boolean
*/ */
public void setIsNewTypeId(boolean value); public IASTInitializer getInitializer();
/**
* @since 5.1
*/
public ICPPASTNewExpression copy();
/** /**
* Returns true if this expression is allocating an array. * Not allowed on frozen ast.
* @since 5.1
*/ */
public boolean isArrayAllocation(); public void setIsGlobal(boolean value);
/** /**
* Expressions that go inside array brackets. * Not allowed on frozen ast.
* @since 5.2
*/ */
public void setPlacementArguments(IASTInitializerClause[] expression);
/**
* Not allowed on frozen ast.
*/
public void setTypeId(IASTTypeId typeId);
/**
* Not allowed on frozen ast.
*/
public void setIsNewTypeId(boolean value);
/**
* Not allowed on frozen ast.
* @since 5.2
*/
public void setInitializer(IASTInitializer init);
/**
* @deprecated the id-expressions are part of the type-id.
*/
@Deprecated
public static final ASTNodeProperty NEW_TYPEID_ARRAY_EXPRESSION = new ASTNodeProperty( public static final ASTNodeProperty NEW_TYPEID_ARRAY_EXPRESSION = new ASTNodeProperty(
"ICPPASTNewExpression.NEW_TYPEID_ARRAY_EXPRESSION - Expressions inside array brackets"); //$NON-NLS-1$ "ICPPASTNewExpression.NEW_TYPEID_ARRAY_EXPRESSION - Expressions inside array brackets"); //$NON-NLS-1$
@ -138,10 +124,27 @@ public interface ICPPASTNewExpression extends IASTExpression, IASTImplicitNameOw
@Deprecated @Deprecated
public void addNewTypeIdArrayExpression(IASTExpression expression); public void addNewTypeIdArrayExpression(IASTExpression expression);
/**
* @deprecated Replaced by {@link #getPlacementArguments()}
*/
@Deprecated
public IASTExpression getNewPlacement();
/** /**
* @since 5.1 * @deprecated Replaced by {@link #setPlacementArguments(IASTInitializerClause[])}
*/ */
public ICPPASTNewExpression copy(); @Deprecated
public void setNewPlacement(IASTExpression expression);
/**
* @deprecated Replaced by {@link #getInitializer()}
*/
@Deprecated
public IASTExpression getNewInitializer();
/**
* @deprecated Replaced by {@link #setInitializer(IASTInitializer)}
*/
@Deprecated
public void setNewInitializer(IASTExpression expression);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,123 +7,108 @@
* *
* Contributors: * Contributors:
* John Camelon (IBM) - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
/** /**
* Simple type constructor postfix expression. * Functional cast expressions:
* * simple-type-specifier (expression-list?)
* simple-type-specifier braced-init-list
* typename-specifier (expression-list?)
* typename-specifier braced-init-list
*
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTSimpleTypeConstructorExpression extends IASTExpression { public interface ICPPASTSimpleTypeConstructorExpression extends IASTExpression {
/**
* @since 5.2
*/
public static final ASTNodeProperty TYPE_SPECIFIER = new ASTNodeProperty(
"ICPPASTSimpleTypeConstructorExpression.TYPE_SPECIFIER [ICPPASTSimpleDeclSpecifier]"); //$NON-NLS-1$
/**
* @since 5.2
*/
public static final ASTNodeProperty INITIALIZER = new ASTNodeProperty(
"ICPPASTSimpleTypeConstructorExpression.INITIALIZER [IASTInitializer]"); //$NON-NLS-1$
/** /**
* t_unspecified (error) * Returns the declaration specifier that specifies the type.
* @since 5.2
*/ */
public static final int t_unspecified = 0; public ICPPASTDeclSpecifier getDeclSpecifier();
/** /**
* t_void == void * Returns the argument for initialization. Can be {@link ICPPASTConstructorInitializer} or
* {@link ICPPASTInitializerList}
* @since 5.2
*/ */
public static final int t_void = 1; public IASTInitializer getInitializer();
/**
* t_char == char
*/
public static final int t_char = 2;
/**
* t_int == int
*/
public static final int t_int = 3;
/**
* t_float == float
*/
public static final int t_float = 4;
/**
* t_double == double
*/
public static final int t_double = 5;
/**
* t_bool = bool
*/
public static final int t_bool = 6;
/**
* t_wchar_t = wchar_t
*/
public static final int t_wchar_t = 7;
/**
* t_short = short
*/
public static final int t_short = 8;
/**
* t_long = long
*/
public static final int t_long = 9;
/**
* t_signed = signed
*/
public static final int t_signed = 10;
/**
* t_unsigned = unsigned
*/
public static final int t_unsigned = 11;
/**
* t_last is provided for subinterfaces.
*/
public static final int t_last = t_unsigned;
/**
* Get the simple type.
*
* @return int
*/
public int getSimpleType();
/**
* Set the simple type.
*
* @param value
* int
*/
public void setSimpleType(int value);
/**
* INITIALIZER_VALUE is the value passed into the constructor.
*/
public static final ASTNodeProperty INITIALIZER_VALUE = new ASTNodeProperty(
"ICPPASTSimpleTypeConstructorExpression.INITIALIZER_VALUE - Value passed into constructor"); //$NON-NLS-1$
/**
* Get the initial value.
*
* @return <code>IASTExpression</code>
*/
public IASTExpression getInitialValue();
/**
* Set the initial value.
*
* @param expression
* <code>IASTExpression</code>
*/
public void setInitialValue(IASTExpression expression);
/** /**
* @since 5.1 * @since 5.1
*/ */
public ICPPASTSimpleTypeConstructorExpression copy(); public ICPPASTSimpleTypeConstructorExpression copy();
/**
* Not allowed on frozen ast.
* @since 5.2
*/
public void setDeclSpecifier(ICPPASTDeclSpecifier declSpec);
/**
* Not allowed on frozen ast.
* @since 5.2
*/
public void setInitializer(IASTInitializer initializer);
@Deprecated public static final int t_unspecified = 0;
@Deprecated public static final int t_void = 1;
@Deprecated public static final int t_char = 2;
@Deprecated public static final int t_int = 3;
@Deprecated public static final int t_float = 4;
@Deprecated public static final int t_double = 5;
@Deprecated public static final int t_bool = 6;
@Deprecated public static final int t_wchar_t = 7;
@Deprecated public static final int t_short = 8;
@Deprecated public static final int t_long = 9;
@Deprecated public static final int t_signed = 10;
@Deprecated public static final int t_unsigned = 11;
@Deprecated public static final int t_last = t_unsigned;
/**
* @deprecated Replaced by {@link #getDeclSpecifier()}.
*/
@Deprecated
public int getSimpleType();
/**
* @deprecated Replaced by {@link #setDeclSpecifier(ICPPASTDeclSpecifier)}
*/
@Deprecated
public void setSimpleType(int value);
/**
* @deprecated Replaced by {@link #INITIALIZER}.
*/
@Deprecated
public static final ASTNodeProperty INITIALIZER_VALUE = INITIALIZER;
/**
* @deprecated Replaced by {@link #getInitializer()}
*/
@Deprecated
public IASTExpression getInitialValue();
/**
* @deprecated Replaced by {@link #setInitializer(IASTInitializer)}
*/
@Deprecated
public void setInitialValue(IASTExpression expression);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* John Camelon (IBM) - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
@ -18,8 +19,10 @@ import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
/** /**
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
* @deprecated Unified with {@link ICPPASTSimpleTypeConstructorExpression}.
*/ */
public interface ICPPASTTypenameExpression extends IASTExpression, IASTNameOwner { @Deprecated
public interface ICPPASTTypenameExpression extends ICPPASTSimpleTypeConstructorExpression, IASTNameOwner {
/** /**
* Was template token consumed? * Was template token consumed?
@ -60,8 +63,7 @@ public interface ICPPASTTypenameExpression extends IASTExpression, IASTNameOwner
/** /**
* <code>INITIAL_VALUE</code> is an expression. * <code>INITIAL_VALUE</code> is an expression.
*/ */
public static final ASTNodeProperty INITIAL_VALUE = new ASTNodeProperty( public static final ASTNodeProperty INITIAL_VALUE = INITIALIZER;
"ICPPASTTypenameExpression.INITIAL_VALUE - Initial Value is an expression"); //$NON-NLS-1$
/** /**
* Set initial value. * Set initial value.

View file

@ -16,9 +16,12 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId; import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.INodeFactory;
@ -37,188 +40,177 @@ import org.eclipse.cdt.core.parser.IScanner;
public interface ICPPNodeFactory extends INodeFactory { public interface ICPPNodeFactory extends INodeFactory {
/** /**
* Creates a new translation unit that cooperates with the given scanner in order
* to track macro-expansions and location information.
* @scanner the preprocessor the translation unit interacts with.
* @since 5.2 * @since 5.2
*/ */
public ICPPASTTranslationUnit newTranslationUnit(IScanner scanner); public ICPPASTArrayDeclarator newArrayDeclarator(IASTName name);
public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep); public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript);
public ICPPASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand); /**
* @since 5.2
*/
public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTInitializerClause subscript);
public ICPPASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand); public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual);
public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2); public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2);
public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId); /**
* @since 5.2
*/
public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTInitializerClause expr2);
public ICPPASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand);
public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body);
IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
/**
* @deprecated Replaced by {@link #newConstructorChainInitializer(IASTName, IASTInitializer)}
*/
@Deprecated
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName memberInitializerId, IASTExpression initializerValue);
/**
* @since 5.2
*/
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName id, IASTInitializer initializer);
/**
* @deprecated Replaced by {@link #newConstructorInitializer(IASTInitializerClause[])}.
*/
@Deprecated
public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp);
/**
* @since 5.2
*/
public ICPPASTConstructorInitializer newConstructorInitializer(IASTInitializerClause[] args);
public ICPPASTConversionName newConversionName(IASTTypeId typeId);
/** /**
* @since 5.2 * @since 5.2
*/ */
public ICPPASTDeclarator newDeclarator(IASTName name); public ICPPASTDeclarator newDeclarator(IASTName name);
public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name); public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand);
public ICPPASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
public ICPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiation(IASTDeclaration declaration);
/** /**
* @since 5.2 * @deprecated Replaced by {@link #newExplicitTemplateInstantiation(IASTDeclaration)}.
*/ */
public ICPPASTArrayDeclarator newArrayDeclarator(IASTName name); @Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiationGPP(IASTDeclaration declaration);
public ICPPASTExpressionList newExpressionList();
/** /**
* @since 5.2 * @since 5.2
*/ */
public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize); public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize);
public ICPPASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
public ICPPASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator);
public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier();
public ICPPASTOperatorName newOperatorName(char[] name);
public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, IASTTypeId typeId);
public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner); public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner);
public ICPPASTTemplateId newTemplateId(IASTName templateName); public ICPPASTForStatement newForStatement();
public ICPPASTConversionName newConversionName(IASTTypeId typeId);
public ICPPASTQualifiedName newQualifiedName();
public ICPPASTSwitchStatement newSwitchStatement(IASTExpression controlloer, IASTStatement body);
public ICPPASTSwitchStatement newSwitchStatement(IASTDeclaration controller, IASTStatement body);
public ICPPASTSwitchStatement newSwitchStatement();
public ICPPASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause);
public ICPPASTIfStatement newIfStatement(IASTDeclaration condition, IASTStatement then, IASTStatement elseClause);
public ICPPASTIfStatement newIfStatement();
public ICPPASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpression, IASTStatement body);
public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition, public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition,
IASTExpression iterationExpression, IASTStatement body); IASTExpression iterationExpression, IASTStatement body);
public ICPPASTForStatement newForStatement();
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
public ICPPASTWhileStatement newWhileStatement(IASTDeclaration condition, IASTStatement body);
public ICPPASTWhileStatement newWhileStatement();
public ICPPASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpression, IASTStatement body);
/**
* @deprecated Replaced by {@link #newFunctionCallExpression(IASTExpression, IASTInitializerClause[])}.
*/
@Deprecated
public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList);
/** /**
* @since 5.2 * @since 5.2
*/ */
public ICPPASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator); public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTInitializerClause[] arguments);
public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name);
public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
IASTStatement bodyStatement);
public ICPPASTIfStatement newIfStatement();
public ICPPASTIfStatement newIfStatement(IASTDeclaration condition, IASTStatement then, IASTStatement elseClause);
public ICPPASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause);
public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand);
public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(int type, IASTExpression expression);
public ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, IASTExpression expr, boolean isTemplate);
public ICPPASTNamespaceAlias newNamespaceAlias(IASTName alias, IASTName qualifiedName);
public ICPPASTUsingDeclaration newUsingDeclaration(IASTName name);
public ICPPASTUsingDirective newUsingDirective(IASTName name);
public ICPPASTLinkageSpecification newLinkageSpecification(String literal);
public ICPPASTNamespaceDefinition newNamespaceDefinition(IASTName name);
public ICPPASTTemplateDeclaration newTemplateDeclaration(IASTDeclaration declaration);
public ICPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiation(IASTDeclaration declaration);
public ICPPASTTemplateSpecialization newTemplateSpecialization(IASTDeclaration declaration);
public ICPPASTTryBlockStatement newTryBlockStatement(IASTStatement body);
public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body);
public ICPPASTVisibilityLabel newVisibilityLabel(int visibility);
public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual);
public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
public ICPPASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name);
public IGPPASTPointer newPointerGPP();
/**
* Creates an lvalue or rvalue reference operator.
* @since 5.2
*/
public ICPPASTReferenceOperator newReferenceOperator(boolean isRValueReference);
public ICPPASTPointerToMember newPointerToMember(IASTName name);
public IGPPASTPointerToMember newPointerToMemberGPP(IASTName name);
/**
* @since 5.2
*/
public ICPPASTInitializerExpression newInitializerExpression(IASTExpression expression);
/** /**
* @since 5.2 * @since 5.2
*/ */
public ICPPASTInitializerList newInitializerList(); public ICPPASTInitializerList newInitializerList();
public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp); public ICPPASTLinkageSpecification newLinkageSpecification(String literal);
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName memberInitializerId, IASTExpression initializerValue); public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep);
public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, public ICPPASTNamespaceAlias newNamespaceAlias(IASTName alias, IASTName qualifiedName);
IASTStatement bodyStatement);
public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId); public ICPPASTNamespaceDefinition newNamespaceDefinition(IASTName name);
public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue); /**
* @deprecated Replaced by {@link #newNewExpression(IASTInitializerClause[], IASTInitializer, IASTTypeId)}
*/
@Deprecated
public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, IASTTypeId typeId);
public IASTProblemTypeId newProblemTypeId(IASTProblem problem);
public ICPPASTExpressionList newExpressionList();
public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript);
public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList);
/** /**
* Creates a new static assertion declaration with the given condition and message.
* @since 5.2 * @since 5.2
*/ */
public ICPPASTStaticAssertDeclaration newStaticAssertion(IASTExpression condition, ICPPASTLiteralExpression message); public ICPPASTNewExpression newNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, IASTTypeId typeId);
public ICPPASTOperatorName newOperatorName(char[] name);
/** /**
* Creates a new pack expansion expression for the given pattern. * Creates a new pack expansion expression for the given pattern.
* @since 5.2 * @since 5.2
*/ */
public ICPPASTPackExpansionExpression newPackExpansionExpression(IASTExpression pattern); public ICPPASTPackExpansionExpression newPackExpansionExpression(IASTExpression pattern);
public ICPPASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator);
public IGPPASTPointer newPointerGPP();
public ICPPASTPointerToMember newPointerToMember(IASTName name);
public IGPPASTPointerToMember newPointerToMemberGPP(IASTName name);
public IASTProblemTypeId newProblemTypeId(IASTProblem problem);
public ICPPASTQualifiedName newQualifiedName();
/** /**
* @deprecated Replaced by {@link #newReferenceOperator(boolean)}. * @deprecated Replaced by {@link #newReferenceOperator(boolean)}.
*/ */
@Deprecated public ICPPASTReferenceOperator newReferenceOperator(); @Deprecated public ICPPASTReferenceOperator newReferenceOperator();
/** /**
* @deprecated Replaced by {@link #newTranslationUnit(IScanner)}. * Creates an lvalue or rvalue reference operator.
* @since 5.2
*/ */
@Deprecated public ICPPASTReferenceOperator newReferenceOperator(boolean isRValueReference);
public ICPPASTTranslationUnit newTranslationUnit();
/**
* @since 5.2
*/
public IASTReturnStatement newReturnStatement(IASTInitializerClause retValue);
public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier();
/** /**
* @deprecated Replaced by {@link #newSimpleDeclSpecifier()} * @deprecated Replaced by {@link #newSimpleDeclSpecifier()}
*/ */
@ -226,10 +218,81 @@ public interface ICPPNodeFactory extends INodeFactory {
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP(); public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP();
/** /**
* @deprecated Replaced by {@link #newExplicitTemplateInstantiation(IASTDeclaration)}. * @deprecated Replaced by {@link #newSimpleTypeConstructorExpression(ICPPASTDeclSpecifier, IASTInitializer)}
*/
@Deprecated
public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(int type, IASTExpression expression);
/**
* @since 5.2
*/
public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec, IASTInitializer initializer);
public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId);
/**
* Creates a new static assertion declaration with the given condition and message.
* @since 5.2
*/
public ICPPASTStaticAssertDeclaration newStaticAssertion(IASTExpression condition, ICPPASTLiteralExpression message);
public ICPPASTSwitchStatement newSwitchStatement();
public ICPPASTSwitchStatement newSwitchStatement(IASTDeclaration controller, IASTStatement body);
public ICPPASTSwitchStatement newSwitchStatement(IASTExpression controlloer, IASTStatement body);
public ICPPASTTemplateDeclaration newTemplateDeclaration(IASTDeclaration declaration);
public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue);
public ICPPASTTemplateId newTemplateId(IASTName templateName);
public ICPPASTTemplateSpecialization newTemplateSpecialization(IASTDeclaration declaration);
/**
* @deprecated Replaced by {@link #newTranslationUnit(IScanner)}.
*/ */
@Deprecated @Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiationGPP(IASTDeclaration declaration); public ICPPASTTranslationUnit newTranslationUnit();
/**
* Creates a new translation unit that cooperates with the given scanner in order
* to track macro-expansions and location information.
* @scanner the preprocessor the translation unit interacts with.
* @since 5.2
*/
public ICPPASTTranslationUnit newTranslationUnit(IScanner scanner);
public ICPPASTTryBlockStatement newTryBlockStatement(IASTStatement body);
public ICPPASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name);
/**
* @since 5.2
*/
public ICPPASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator);
public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId);
/**
* @deprecated Replaced by {@link #newSimpleTypeConstructorExpression(ICPPASTDeclSpecifier, IASTInitializer)}
*/
@Deprecated
public ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, IASTExpression expr, boolean isTemplate);
public ICPPASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand);
public ICPPASTUsingDeclaration newUsingDeclaration(IASTName name);
public ICPPASTUsingDirective newUsingDirective(IASTName name);
public ICPPASTVisibilityLabel newVisibilityLabel(int visibility);
public ICPPASTWhileStatement newWhileStatement();
public ICPPASTWhileStatement newWhileStatement(IASTDeclaration condition, IASTStatement body);
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
} }

View file

@ -14,6 +14,9 @@ import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
/** /**
* @deprecated Replaced by {@link IASTUnaryExpression}. * @deprecated Replaced by {@link IASTUnaryExpression}.
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/ */
@Deprecated @Deprecated
public interface IGNUASTUnaryExpression extends IASTUnaryExpression { public interface IGNUASTUnaryExpression extends IASTUnaryExpression {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. and others. * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,6 +14,8 @@ package org.eclipse.cdt.core.parser;
* Interface for tokens of kind {@link IToken#tINACTIVE_CODE_START}, {@link IToken#tINACTIVE_CODE_SEPARATOR} and * Interface for tokens of kind {@link IToken#tINACTIVE_CODE_START}, {@link IToken#tINACTIVE_CODE_SEPARATOR} and
* {@link IToken#tINACTIVE_CODE_END}. * {@link IToken#tINACTIVE_CODE_END}.
* @since 5.1 * @since 5.1
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IInactiveCodeToken extends IToken { public interface IInactiveCodeToken extends IToken {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,8 +14,10 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
@ -104,7 +106,15 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu
if (!hasIssue) if (!hasIssue)
return nodeToReplace; return nodeToReplace;
fFunctionCallExpression.setParameterExpression(primaryWithParenthesis.getOperand()); final IASTExpression operand = primaryWithParenthesis.getOperand();
if (operand instanceof IASTExpressionList) {
final IASTExpressionList list= (IASTExpressionList) operand;
fFunctionCallExpression.setArguments(list.getExpressions());
} else if (operand != null) {
fFunctionCallExpression.setArguments(new IASTInitializerClause[] {operand});
} else {
fFunctionCallExpression.setArguments(IASTExpression.EMPTY_EXPRESSION_ARRAY);
}
setRange(fFunctionCallExpression, fCastExpression, primaryWithParenthesis); setRange(fFunctionCallExpression, fCastExpression, primaryWithParenthesis);
IASTExpression result= fFunctionCallExpression; IASTExpression result= fFunctionCallExpression;

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode;
/**
* Initializer with equals sign (copy initialization)
*/
public abstract class ASTEqualsInitializer extends ASTNode implements IASTEqualsInitializer,
IASTAmbiguityParent {
private IASTInitializerClause fArgument;
public ASTEqualsInitializer() {
}
public ASTEqualsInitializer(IASTInitializerClause arg) {
setInitializerClause(arg);
}
public IASTInitializerClause getInitializerClause() {
return fArgument;
}
public void setInitializerClause(IASTInitializerClause clause) {
assertNotFrozen();
fArgument = clause;
if (clause != null) {
clause.setParent(this);
clause.setPropertyInParent(INITIALIZER);
}
}
@Override
public boolean accept( ASTVisitor action ){
if( action.shouldVisitInitializers ){
switch( action.visit( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
if (fArgument != null && !fArgument.accept(action))
return false;
if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
return true;
}
public void replace(IASTNode child, IASTNode other) {
if (child == fArgument) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
fArgument = (IASTInitializerClause) other;
}
}
@Deprecated
public IASTExpression getExpression() {
if (fArgument instanceof IASTExpression)
return (IASTExpression) fArgument;
return null;
}
@Deprecated
public void setExpression(IASTExpression expression) {
setInitializerClause(expression);
}
}

View file

@ -43,8 +43,8 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -55,7 +55,6 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
@ -67,7 +66,6 @@ import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
@ -633,6 +631,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throw backtrack; throw backtrack;
} }
protected final void throwBacktrack(IASTNode node) throws BacktrackException {
final ASTNode n= (ASTNode) node;
throwBacktrack(n.getOffset(), n.getLength());
}
public IASTTranslationUnit parse() { public IASTTranslationUnit parse() {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
translationUnit(); translationUnit();
@ -900,16 +903,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
protected IASTExpression possiblyEmptyExpressionList(int endToken) throws BacktrackException, EndOfFileException {
IToken la1= LA(1);
if (la1.getType() == endToken) {
IASTExpressionList expressionList = nodeFactory.newExpressionList();
((ASTNode) expressionList).setOffsetAndLength(la1.getOffset(), 0);
return expressionList;
}
return expression();
}
/** /**
* Models a cast expression followed by an operator. Can be linked into a chain. * Models a cast expression followed by an operator. Can be linked into a chain.
* This is done right to left, such that a tree of variants can be built. * This is done right to left, such that a tree of variants can be built.
@ -919,10 +912,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
final int fLeftPrecedence; final int fLeftPrecedence;
final int fRightPrecedence; final int fRightPrecedence;
BinaryOperator fNext; BinaryOperator fNext;
IASTExpression fExpression; IASTInitializerClause fExpression;
final CastAmbiguityMarker fAmbiguityMarker; final CastAmbiguityMarker fAmbiguityMarker;
public BinaryOperator(BinaryOperator nextOp, IASTExpression expression, int operatorToken, int leftPrecedence, int rightPrecedence) { public BinaryOperator(BinaryOperator nextOp, IASTInitializerClause expression, int operatorToken, int leftPrecedence, int rightPrecedence) {
fNext= nextOp; fNext= nextOp;
fOperatorToken= operatorToken; fOperatorToken= operatorToken;
fLeftPrecedence= leftPrecedence; fLeftPrecedence= leftPrecedence;
@ -937,24 +930,24 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
} }
public IASTExpression exchange(IASTExpression expr) { public IASTInitializerClause exchange(IASTInitializerClause expr) {
IASTExpression e= fExpression; IASTInitializerClause e= fExpression;
fExpression= expr; fExpression= expr;
return e; return e;
} }
} }
protected final IASTExpression buildExpression(BinaryOperator leftChain, IASTExpression expr) throws BacktrackException { protected final IASTExpression buildExpression(BinaryOperator leftChain, IASTInitializerClause expr) throws BacktrackException {
BinaryOperator rightChain= null; BinaryOperator rightChain= null;
for (;;) { for (;;) {
if (leftChain == null) { if (leftChain == null) {
if (rightChain == null) if (rightChain == null)
return expr; return (IASTExpression) expr;
expr= buildExpression(expr, rightChain); expr= buildExpression((IASTExpression) expr, rightChain);
rightChain= rightChain.fNext; rightChain= rightChain.fNext;
} else if (rightChain != null && leftChain.fRightPrecedence < rightChain.fLeftPrecedence) { } else if (rightChain != null && leftChain.fRightPrecedence < rightChain.fLeftPrecedence) {
expr= buildExpression(expr, rightChain); expr= buildExpression((IASTExpression) expr, rightChain);
rightChain= rightChain.fNext; rightChain= rightChain.fNext;
} else { } else {
BinaryOperator op= leftChain; BinaryOperator op= leftChain;
@ -968,7 +961,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
private IASTExpression buildExpression(IASTExpression left, BinaryOperator operator) throws BacktrackException { private IASTExpression buildExpression(IASTExpression left, BinaryOperator operator) throws BacktrackException {
int op, unaryOp= 0; int op, unaryOp= 0;
final IASTExpression right= operator.fExpression; final IASTInitializerClause right= operator.fExpression;
switch(operator.fOperatorToken) { switch(operator.fOperatorToken) {
case IToken.tQUESTION: case IToken.tQUESTION:
if (operator.fNext == null || operator.fNext.fOperatorToken != IToken.tCOLON) { if (operator.fNext == null || operator.fNext.fOperatorToken != IToken.tCOLON) {
@ -977,26 +970,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throwBacktrack(node.getOffset(), node.getLength()); throwBacktrack(node.getOffset(), node.getLength());
return null; // Will never be reached. return null; // Will never be reached.
} }
IASTExpression negative= operator.fNext.fExpression; IASTInitializerClause negative= operator.fNext.fExpression;
operator.fNext= operator.fNext.fNext; operator.fNext= operator.fNext.fNext;
IASTConditionalExpression conditionalEx = nodeFactory.newConditionalExpession(left, right, negative); IASTConditionalExpression conditionalEx = nodeFactory.newConditionalExpession(left, (IASTExpression) right, (IASTExpression) negative);
setRange(conditionalEx, left); setRange(conditionalEx, left);
if (negative != null) { if (negative != null) {
adjustLength(conditionalEx, negative); adjustLength(conditionalEx, negative);
} }
return conditionalEx; return conditionalEx;
case IToken.tELLIPSIS:
if (right instanceof ICPPASTPackExpansionExpression) {
((ICPPASTPackExpansionExpression) right).setPattern(left);
int endOffset= ((ASTNode) right).getLength();
setRange(right, left);
adjustEndOffset(right, endOffset);
return right;
}
assert false;
return left;
case IToken.tCOMMA: case IToken.tCOMMA:
IASTExpressionList list; IASTExpressionList list;
if (left instanceof IASTExpressionList) { if (left instanceof IASTExpressionList) {
@ -1006,7 +988,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
list.addExpression(left); list.addExpression(left);
setRange(list, left); setRange(list, left);
} }
list.addExpression(right); list.addExpression((IASTExpression) right);
adjustLength(list, right); adjustLength(list, right);
return list; return list;
@ -1220,7 +1202,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
backup(mark); backup(mark);
try { try {
IASTExpression expr= primaryExpression(ctx); IASTExpression expr= primaryExpression(ctx);
IASTFunctionCallExpression fcall = nodeFactory.newFunctionCallExpression(expr, null); IASTFunctionCallExpression fcall = nodeFactory.newFunctionCallExpression(expr, (IASTExpression[]) null);
IASTAmbiguousExpression ambiguity = createAmbiguousCastVsFunctionCallExpression(result, fcall); IASTAmbiguousExpression ambiguity = createAmbiguousCastVsFunctionCallExpression(result, fcall);
((ASTNode) ambiguity).setOffsetAndLength((ASTNode) result); ((ASTNode) ambiguity).setOffsetAndLength((ASTNode) result);
return ca == null ? ambiguity : ca.updateExpression(ambiguity); return ca == null ? ambiguity : ca.updateExpression(ambiguity);
@ -1346,12 +1328,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
parent.addDeclaration(declaration); parent.addDeclaration(declaration);
} }
protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTExpression expr2, int lastOffset) { abstract protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset);
IASTBinaryExpression result = nodeFactory.newBinaryExpression(operator, expr1, expr2);
int o = ((ASTNode) expr1).getOffset();
((ASTNode) result).setOffsetAndLength(o, lastOffset - o);
return result;
}
private IASTExpression createCastVsBinaryExpressionAmbiguity(IASTBinaryExpression expr, final IASTTypeId typeid, int unaryOperator, int unaryOpOffset) { private IASTExpression createCastVsBinaryExpressionAmbiguity(IASTBinaryExpression expr, final IASTTypeId typeid, int unaryOperator, int unaryOpOffset) {
IASTUnaryExpression unary= nodeFactory.newUnaryExpression(unaryOperator, null); IASTUnaryExpression unary= nodeFactory.newUnaryExpression(unaryOperator, null);
@ -1829,6 +1806,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
((ASTNode) ds).setOffsetAndLength(((ASTNode) d).getOffset(), ((ASTNode) d).getLength()); ((ASTNode) ds).setOffsetAndLength(((ASTNode) d).getOffset(), ((ASTNode) d).getLength());
} catch (BacktrackException b) { } catch (BacktrackException b) {
if (expressionStatement == null) { if (expressionStatement == null) {
backup(mark);
throw b; throw b;
} }
} }
@ -1974,40 +1952,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException { protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException {
int startOffset; final int offset= consume(IToken.t_return).getOffset();
startOffset = consume().getOffset(); // t_return
IASTExpression result = null;
// See if there is a return expression // Optional expression
switch (LT(1)) { IASTExpression expr = null;
case IToken.tEOC: if (LT(1) != IToken.tSEMI) {
// We're trying to start one expr = expression();
IASTName name = identifier();
IASTIdExpression idExpr = nodeFactory.newIdExpression(name);
result = idExpr;
break;
case IToken.tSEMI:
// None
break;
default:
// Yes
result = expression();
break;
} }
// Semicolon
final int endOffset= consumeOrEOC(IToken.tSEMI).getEndOffset();
int lastOffset = 0; return setRange(nodeFactory.newReturnStatement(expr), offset, endOffset);
switch (LT(1)) {
case IToken.tSEMI:
case IToken.tEOC:
lastOffset = consume().getEndOffset();
break;
default:
throwBacktrack(LA(1));
}
IASTReturnStatement return_statement = nodeFactory.newReturnStatement(result);
((ASTNode) return_statement).setOffsetAndLength(startOffset, lastOffset - startOffset);
return return_statement;
} }
protected IASTStatement parseDoStatement() throws EndOfFileException, BacktrackException { protected IASTStatement parseDoStatement() throws EndOfFileException, BacktrackException {
@ -2316,7 +2271,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
// Allow empty attribute // Allow empty attribute
if (lt1 != IToken.tCOMMA) { if (lt1 != IToken.tCOMMA) {
singelAttribute(); singleAttribute();
} }
// Require comma // Require comma
@ -2330,7 +2285,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
} }
private void singelAttribute() throws EndOfFileException, BacktrackException { private void singleAttribute() throws EndOfFileException, BacktrackException {
// Check if we have an identifier including keywords // Check if we have an identifier including keywords
if (!isIdentifier(LA(1))) if (!isIdentifier(LA(1)))
throw backtrack; throw backtrack;

View file

@ -12,33 +12,33 @@ package org.eclipse.cdt.internal.core.dom.parser;
/** /**
* Configures the parsing of a declaration in various contexts. * Configures the parsing of a declaration in various contexts.
* @since 5.0
*/ */
public class DeclarationOptions { public class DeclarationOptions {
final public static int ALLOW_EMPTY_SPECIFIER= 0x01; final public static int ALLOW_EMPTY_SPECIFIER= 0x01;
final public static int ALLOW_ABSTRACT= 0x02; final public static int ALLOW_ABSTRACT= 0x02;
final public static int REQUIRE_ABSTRACT= 0x04; final public static int REQUIRE_ABSTRACT= 0x04;
final public static int ALLOW_BITFIELD= 0x08; final public static int ALLOW_BITFIELD= 0x08;
final public static int NO_INITIALIZER= 0x10; final public static int NO_INITIALIZER= 0x10;
final public static int ALLOW_CONSTRUCTOR_INITIALIZER= 0x20; final public static int NO_CTOR_STYLE_INITIALIZER= 0x20;
final public static int NO_FUNCTIONS= 0x40; final public static int NO_BRACED_INITIALIZER= 0x40;
final public static int NO_ARRAYS= 0x80; final public static int NO_FUNCTIONS= 0x80;
final public static int NO_NESTED= 0x100; final public static int NO_ARRAYS= 0x100;
final public static int ALLOW_PARAMETER_PACKS= 0x200; final public static int NO_NESTED= 0x200;
final public static int REQUIRE_SIMPLE_NAME= 0x400; final public static int ALLOW_PARAMETER_PACKS= 0x400;
final public static int REQUIRE_SIMPLE_NAME= 0x800;
public static final DeclarationOptions public static final DeclarationOptions
GLOBAL= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_CONSTRUCTOR_INITIALIZER), GLOBAL= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER),
FUNCTION_STYLE_ASM= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | NO_INITIALIZER | ALLOW_ABSTRACT), FUNCTION_STYLE_ASM= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | NO_INITIALIZER | ALLOW_ABSTRACT),
C_MEMBER= new DeclarationOptions(ALLOW_BITFIELD | ALLOW_ABSTRACT), C_MEMBER= new DeclarationOptions(ALLOW_BITFIELD | ALLOW_ABSTRACT),
CPP_MEMBER= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_BITFIELD), CPP_MEMBER= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_BITFIELD | NO_CTOR_STYLE_INITIALIZER),
LOCAL= new DeclarationOptions(ALLOW_CONSTRUCTOR_INITIALIZER), LOCAL= new DeclarationOptions(0),
PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS | REQUIRE_SIMPLE_NAME), PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS | REQUIRE_SIMPLE_NAME | NO_BRACED_INITIALIZER | NO_CTOR_STYLE_INITIALIZER),
TYPEID= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER), TYPEID= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER),
TYPEID_NEW= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED), TYPEID_NEW= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED),
TYPEID_CONVERSION= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED), TYPEID_CONVERSION= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED),
EXCEPTION= new DeclarationOptions(ALLOW_ABSTRACT | NO_INITIALIZER), EXCEPTION= new DeclarationOptions(ALLOW_ABSTRACT | NO_INITIALIZER),
CONDITION= new DeclarationOptions(ALLOW_CONSTRUCTOR_INITIALIZER), CONDITION= new DeclarationOptions(NO_CTOR_STYLE_INITIALIZER),
C_PARAMETER_NON_ABSTRACT= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_EMPTY_SPECIFIER); C_PARAMETER_NON_ABSTRACT= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_EMPTY_SPECIFIER);
final public boolean fAllowEmptySpecifier; final public boolean fAllowEmptySpecifier;
@ -46,7 +46,8 @@ public class DeclarationOptions {
final public boolean fRequireAbstract; final public boolean fRequireAbstract;
final public boolean fAllowBitField; final public boolean fAllowBitField;
final public boolean fAllowInitializer; final public boolean fAllowInitializer;
final public boolean fAllowConstructorInitializer; final public boolean fAllowBracedInitializer;
final public boolean fAllowCtorStyleInitializer;
final public boolean fAllowFunctions; final public boolean fAllowFunctions;
final public boolean fAllowNested; final public boolean fAllowNested;
final public boolean fAllowParameterPacks; final public boolean fAllowParameterPacks;
@ -58,7 +59,8 @@ public class DeclarationOptions {
fAllowAbstract= fRequireAbstract || (options & ALLOW_ABSTRACT) != 0; fAllowAbstract= fRequireAbstract || (options & ALLOW_ABSTRACT) != 0;
fAllowBitField= (options & ALLOW_BITFIELD) != 0; fAllowBitField= (options & ALLOW_BITFIELD) != 0;
fAllowInitializer= (options & NO_INITIALIZER) == 0; fAllowInitializer= (options & NO_INITIALIZER) == 0;
fAllowConstructorInitializer= fAllowInitializer && (options & ALLOW_CONSTRUCTOR_INITIALIZER) != 0; fAllowBracedInitializer= fAllowInitializer && (options & NO_BRACED_INITIALIZER) == 0;
fAllowCtorStyleInitializer= fAllowInitializer && (options & NO_CTOR_STYLE_INITIALIZER) == 0;
fAllowFunctions= (options & NO_FUNCTIONS) == 0; fAllowFunctions= (options & NO_FUNCTIONS) == 0;
fAllowNested= (options & NO_NESTED) == 0; fAllowNested= (options & NO_NESTED) == 0;
fAllowParameterPacks= (options & ALLOW_PARAMETER_PACKS) != 0; fAllowParameterPacks= (options & ALLOW_PARAMETER_PACKS) != 0;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. and others. * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,7 +14,6 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
/** /**
* Needed to handle the ambiguity for simple declarations in plain C * Needed to handle the ambiguity for simple declarations in plain C
* @since 5.1
*/ */
public interface IASTAmbiguousSimpleDeclaration extends IASTSimpleDeclaration { public interface IASTAmbiguousSimpleDeclaration extends IASTSimpleDeclaration {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Wind River Systems, Inc. and others. * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,7 +14,6 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
/** /**
* Internal interface for c- or c++ enumeration specifiers. * Internal interface for c- or c++ enumeration specifiers.
* @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTInternalEnumerationSpecifier extends IASTEnumerationSpecifier { public interface IASTInternalEnumerationSpecifier extends IASTEnumerationSpecifier {
/** /**

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -28,7 +29,6 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
@ -65,7 +65,7 @@ public abstract class VariableReadWriteFlags {
else if (parent instanceof IASTStatement) { else if (parent instanceof IASTStatement) {
return rwInStatement(node, (IASTStatement) parent, indirection); return rwInStatement(node, (IASTStatement) parent, indirection);
} }
else if (parent instanceof IASTInitializerExpression) { else if (parent instanceof IASTEqualsInitializer) {
return rwInInitializerExpression(indirection, parent); return rwInInitializerExpression(indirection, parent);
} }
else if (parent instanceof IASTArrayModifier) { else if (parent instanceof IASTArrayModifier) {
@ -113,7 +113,7 @@ public abstract class VariableReadWriteFlags {
if (expr instanceof IASTExpressionList) { if (expr instanceof IASTExpressionList) {
final IASTExpressionList exprList = (IASTExpressionList)expr; final IASTExpressionList exprList = (IASTExpressionList)expr;
final IASTNode grand= expr.getParent(); final IASTNode grand= expr.getParent();
if (grand instanceof IASTFunctionCallExpression && expr.getPropertyInParent() == IASTFunctionCallExpression.PARAMETERS) { if (grand instanceof IASTFunctionCallExpression && expr.getPropertyInParent() == IASTFunctionCallExpression.ARGUMENT) {
final IASTFunctionCallExpression funcCall = (IASTFunctionCallExpression) grand; final IASTFunctionCallExpression funcCall = (IASTFunctionCallExpression) grand;
return rwArgumentForFunctionCall(node, exprList, funcCall, indirection); return rwArgumentForFunctionCall(node, exprList, funcCall, indirection);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
@ -73,7 +74,20 @@ public class CASTArraySubscriptExpression extends ASTNode implements
} }
} }
@Override
public IASTInitializerClause getArgument() {
return getSubscriptExpression();
}
public void setArgument(IASTInitializerClause expression) {
if (expression instanceof IASTExpression) {
setSubscriptExpression((IASTExpression) expression);
} else {
setSubscriptExpression(null);
}
}
@Override
public boolean accept( ASTVisitor action ){ public boolean accept( ASTVisitor action ){
if( action.shouldVisitExpressions ){ if( action.shouldVisitExpressions ){
switch( action.visit( this ) ){ switch( action.visit( this ) ){

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -62,7 +63,11 @@ public class CASTBinaryExpression extends ASTNode implements
return operand2; return operand2;
} }
/** public IASTInitializerClause getInitOperand2() {
return operand2;
}
/**
* @param op An op_X field from {@link IASTBinaryExpression} * @param op An op_X field from {@link IASTBinaryExpression}
*/ */
public void setOperator(int op) { public void setOperator(int op) {

View file

@ -1,36 +1,43 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research) * Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/** /**
* @author jcamelon * Implementation for designated initializers
*/ */
public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignatedInitializer { public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignatedInitializer, IASTAmbiguityParent {
private IASTInitializer rhs; private IASTInitializerClause rhs;
private ICASTDesignator [] designators = null;
private int designatorsPos=-1;
public CASTDesignatedInitializer() { public CASTDesignatedInitializer() {
} }
public CASTDesignatedInitializer(IASTInitializer operandInitializer) { public CASTDesignatedInitializer(IASTInitializerClause init) {
setOperandInitializer(operandInitializer); setOperand(init);
} }
public CASTDesignatedInitializer copy() { public CASTDesignatedInitializer copy() {
@ -57,22 +64,44 @@ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignate
return designators; return designators;
} }
private ICASTDesignator [] designators = null;
int designatorsPos=-1;
public IASTInitializer getOperandInitializer() { public IASTInitializerClause getOperand() {
return rhs; return rhs;
} }
public void setOperand(IASTInitializerClause operand) {
public void setOperandInitializer(IASTInitializer rhs) {
assertNotFrozen(); assertNotFrozen();
this.rhs = rhs; this.rhs = operand;
if (rhs != null) { if (rhs != null) {
rhs.setParent(this); rhs.setParent(this);
rhs.setPropertyInParent(OPERAND); rhs.setPropertyInParent(OPERAND);
} }
}
@Deprecated
public IASTInitializer getOperandInitializer() {
if (rhs instanceof IASTInitializer) {
return (IASTInitializer) rhs;
}
if (rhs instanceof IASTExpression) {
CASTEqualsInitializer init = new CASTEqualsInitializer(((IASTExpression)rhs).copy());
init.setParent(this);
init.setPropertyInParent(OPERAND);
return init;
}
return null;
}
@Deprecated
public void setOperandInitializer(IASTInitializer rhs) {
if (rhs instanceof IASTEqualsInitializer) {
setOperand(((IASTEqualsInitializer) rhs).getInitializerClause());
} else if (rhs instanceof IASTInitializerClause) {
setOperand((IASTInitializerClause) rhs);
} else {
setOperand(null);
}
} }
@Override @Override
@ -100,4 +129,11 @@ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignate
return true; return true;
} }
public void replace(IASTNode child, IASTNode other) {
if (child == rhs) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
rhs = (IASTInitializerClause) other;
}
}
} }

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.internal.core.dom.parser.ASTEqualsInitializer;
/**
* Initializer with equals sign (copy initialization)
*/
public class CASTEqualsInitializer extends ASTEqualsInitializer {
public CASTEqualsInitializer() {
}
public CASTEqualsInitializer(IASTInitializerClause arg) {
super(arg);
}
public CASTEqualsInitializer copy() {
IASTInitializerClause arg = getInitializerClause();
CASTEqualsInitializer copy = new CASTEqualsInitializer(arg == null ? null : arg.copy());
copy.setOffsetAndLength(this);
return copy;
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,6 +14,8 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
@ -29,21 +31,29 @@ public class CASTFunctionCallExpression extends ASTNode implements
IASTFunctionCallExpression, IASTAmbiguityParent { IASTFunctionCallExpression, IASTAmbiguityParent {
private IASTExpression functionName; private IASTExpression functionName;
private IASTExpression parameter; private IASTInitializerClause[] fArguments;
public CASTFunctionCallExpression() { public CASTFunctionCallExpression() {
setArguments(null);
} }
public CASTFunctionCallExpression(IASTExpression functionName, IASTExpression parameter) { public CASTFunctionCallExpression(IASTExpression functionName, IASTInitializerClause[] args) {
setFunctionNameExpression(functionName); setFunctionNameExpression(functionName);
setParameterExpression(parameter); setArguments(args);
} }
public CASTFunctionCallExpression copy() { public CASTFunctionCallExpression copy() {
CASTFunctionCallExpression copy = new CASTFunctionCallExpression(); IASTInitializerClause[] args = null;
if (fArguments.length > 0) {
args= new IASTInitializerClause[fArguments.length];
for (int i=0; i<fArguments.length; i++) {
args[i]= fArguments[i].copy();
}
}
CASTFunctionCallExpression copy = new CASTFunctionCallExpression(null, args);
copy.setFunctionNameExpression(functionName == null ? null : functionName.copy()); copy.setFunctionNameExpression(functionName == null ? null : functionName.copy());
copy.setParameterExpression(parameter == null ? null : parameter.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
return copy; return copy;
} }
@ -61,17 +71,21 @@ public class CASTFunctionCallExpression extends ASTNode implements
return functionName; return functionName;
} }
public void setParameterExpression(IASTExpression expression) { public IASTInitializerClause[] getArguments() {
assertNotFrozen(); return fArguments;
this.parameter = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(PARAMETERS);
}
} }
public IASTExpression getParameterExpression() { public void setArguments(IASTInitializerClause[] arguments) {
return parameter; assertNotFrozen();
if (arguments == null) {
fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY;
} else {
fArguments= arguments;
for (IASTInitializerClause arg : arguments) {
arg.setParent(this);
arg.setPropertyInParent(ARGUMENT);
}
}
} }
@Override @Override
@ -84,33 +98,34 @@ public class CASTFunctionCallExpression extends ASTNode implements
} }
} }
if( functionName != null ) if( !functionName.accept( action ) ) return false; if (functionName != null && !functionName.accept(action))
if( parameter != null ) if( !parameter.accept( action ) ) return false; return false;
if( action.shouldVisitExpressions ){ for (IASTInitializerClause arg : fArguments) {
switch( action.leave( this ) ){ if (!arg.accept(action))
case ASTVisitor.PROCESS_ABORT : return false; return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
} }
return true;
if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
return true;
} }
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( child == functionName ) if (child == functionName) {
{ other.setPropertyInParent(child.getPropertyInParent());
other.setPropertyInParent( child.getPropertyInParent() ); other.setParent(child.getParent());
other.setParent( child.getParent() ); functionName = (IASTExpression) other;
functionName = (IASTExpression) other; }
} for (int i = 0; i < fArguments.length; ++i) {
if( child == parameter) if (child == fArguments[i]) {
{ other.setPropertyInParent(child.getPropertyInParent());
other.setPropertyInParent( child.getPropertyInParent() ); other.setParent(child.getParent());
other.setParent( child.getParent() ); fArguments[i] = (IASTInitializerClause) other;
parameter = (IASTExpression) other; }
} }
} }
public IType getExpressionType() { public IType getExpressionType() {
IType type = getFunctionNameExpression().getExpressionType(); IType type = getFunctionNameExpression().getExpressionType();
@ -124,4 +139,38 @@ public class CASTFunctionCallExpression extends ASTNode implements
public boolean isLValue() { public boolean isLValue() {
return false; return false;
} }
@Deprecated
public IASTExpression getParameterExpression() {
if (fArguments.length == 0)
return null;
if (fArguments.length == 1) {
IASTInitializerClause arg = fArguments[0];
if (arg instanceof IASTExpression)
return (IASTExpression) arg;
return null;
}
CASTExpressionList result= new CASTExpressionList();
for (IASTInitializerClause arg : fArguments) {
if (arg instanceof IASTExpression) {
result.addExpression(((IASTExpression) arg).copy());
}
}
result.setParent(this);
result.setPropertyInParent(ARGUMENT);
return result;
}
@Deprecated
public void setParameterExpression(IASTExpression expression) {
assertNotFrozen();
if (expression == null) {
setArguments(null);
} else if (expression instanceof IASTExpressionList) {
setArguments(((IASTExpressionList) expression).getExpressions());
} else {
setArguments(new IASTExpression[] {expression});
}
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,77 +11,26 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/** @Deprecated
* @author jcamelon public class CASTInitializerExpression extends CASTEqualsInitializer implements IASTInitializerExpression {
*/
public class CASTInitializerExpression extends ASTNode implements
IASTInitializerExpression, IASTAmbiguityParent {
private IASTExpression expression;
public CASTInitializerExpression() { public CASTInitializerExpression() {
} }
public CASTInitializerExpression(IASTExpression expression) { public CASTInitializerExpression(IASTExpression expression) {
setExpression(expression); setExpression(expression);
} }
@Override
public CASTInitializerExpression copy() { public CASTInitializerExpression copy() {
CASTInitializerExpression copy = new CASTInitializerExpression(); CASTInitializerExpression copy= new CASTInitializerExpression();
copy.setExpression(expression == null ? null : expression.copy()); IASTInitializerClause init= getInitializerClause();
copy.setInitializerClause(init == null ? null : init.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
return copy; return copy;
} }
public IASTExpression getExpression() {
return expression;
}
public void setExpression(IASTExpression expression) {
assertNotFrozen();
this.expression = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(INITIALIZER_EXPRESSION);
}
}
@Override
public boolean accept( ASTVisitor action ){
if( action.shouldVisitInitializers ){
switch( action.visit( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
if( expression != null ) if( !expression.accept( action ) ) return false;
if( action.shouldVisitInitializers ){
switch( action.leave( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
return true;
}
public void replace(IASTNode child, IASTNode other) {
if( child == expression )
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
expression = (IASTExpression) other;
}
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,24 +13,29 @@
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/** /**
* e.g.: int a[]= {1,2,3}; * e.g.: int a[]= {1,2,3};
*/ */
public class CASTInitializerList extends ASTNode implements IASTInitializerList { public class CASTInitializerList extends ASTNode implements IASTInitializerList, IASTAmbiguityParent {
private IASTInitializer [] initializers = null; private IASTInitializerClause[] initializers = null;
private int initializersPos=-1; private int initializersPos=-1;
private int actualSize; private int actualSize;
public CASTInitializerList copy() { public CASTInitializerList copy() {
CASTInitializerList copy = new CASTInitializerList(); CASTInitializerList copy = new CASTInitializerList();
for(IASTInitializer initializer : getInitializers()) for(IASTInitializerClause initializer : getClauses())
copy.addInitializer(initializer == null ? null : initializer.copy()); copy.addClause(initializer == null ? null : initializer.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
copy.actualSize= getSize(); copy.actualSize= getSize();
return copy; return copy;
@ -41,24 +46,56 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList
return actualSize; return actualSize;
} }
public IASTInitializer[] getInitializers() { public IASTInitializerClause[] getClauses() {
if (initializers == null) if (initializers == null)
return IASTInitializer.EMPTY_INITIALIZER_ARRAY; return IASTExpression.EMPTY_EXPRESSION_ARRAY;
initializers = ArrayUtil.trimAt(IASTInitializer.class, initializers, initializersPos); initializers = ArrayUtil.trimAt(IASTInitializerClause.class, initializers, initializersPos);
return initializers; return initializers;
} }
public void addInitializer( IASTInitializer d ) { @Deprecated
public IASTInitializer[] getInitializers() {
IASTInitializerClause[] clauses= getClauses();
if (clauses.length == 0)
return IASTInitializer.EMPTY_INITIALIZER_ARRAY;
IASTInitializer[] inits= new IASTInitializer[clauses.length];
for (int i = 0; i < inits.length; i++) {
IASTInitializerClause clause= clauses[i];
if (clause instanceof IASTInitializer) {
inits[i]= (IASTInitializer) clause;
} else if (clause instanceof IASTExpression) {
final CASTEqualsInitializer initExpr = new CASTEqualsInitializer(((IASTExpression) clause).copy());
initExpr.setParent(this);
initExpr.setPropertyInParent(NESTED_INITIALIZER);
inits[i]= initExpr;
}
}
return inits;
}
public void addClause(IASTInitializerClause d) {
assertNotFrozen(); assertNotFrozen();
if (d != null) { if (d != null) {
initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, ++initializersPos, d ); initializers = (IASTInitializerClause[]) ArrayUtil.append( IASTInitializerClause.class, initializers, ++initializersPos, d );
d.setParent(this); d.setParent(this);
d.setPropertyInParent(NESTED_INITIALIZER); d.setPropertyInParent(NESTED_INITIALIZER);
} }
actualSize++; actualSize++;
} }
@Deprecated
public void addInitializer(IASTInitializer d) {
assertNotFrozen();
if (d instanceof IASTInitializerClause) {
addClause((IASTInitializerClause) d);
} else if (d instanceof IASTEqualsInitializer) {
addClause(((IASTEqualsInitializer) d).getInitializerClause());
} else {
addClause(null);
}
}
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept( ASTVisitor action ){
if( action.shouldVisitInitializers ){ if( action.shouldVisitInitializers ){
@ -68,10 +105,11 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList
default : break; default : break;
} }
} }
IASTInitializer [] list = getInitializers(); IASTInitializerClause[] list = getClauses();
for ( int i = 0; i < list.length; i++ ) { for (IASTInitializerClause clause : list) {
if( !list[i].accept( action ) ) return false; if (!clause.accept(action))
} return false;
}
if( action.shouldVisitInitializers ){ if( action.shouldVisitInitializers ){
switch( action.leave( this ) ){ switch( action.leave( this ) ){
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT : return false;
@ -82,4 +120,15 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList
return true; return true;
} }
public void replace(IASTNode child, IASTNode other) {
if (initializers != null) {
for (int i = 0; i < initializers.length; ++i) {
if (child == initializers[i]) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
initializers[i] = (IASTInitializerClause) other;
}
}
}
}
} }

View file

@ -1,26 +1,25 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * John Camelon (IBM Rational Software) - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research) * Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* @author jcamelon
*/
public class CASTReturnStatement extends ASTNode implements public class CASTReturnStatement extends ASTNode implements
IASTReturnStatement, IASTAmbiguityParent { IASTReturnStatement, IASTAmbiguityParent {
@ -43,7 +42,6 @@ public class CASTReturnStatement extends ASTNode implements
return retValue; return retValue;
} }
public void setReturnValue(IASTExpression returnValue) { public void setReturnValue(IASTExpression returnValue) {
assertNotFrozen(); assertNotFrozen();
retValue = returnValue; retValue = returnValue;
@ -53,7 +51,19 @@ public class CASTReturnStatement extends ASTNode implements
} }
} }
@Override public IASTInitializerClause getReturnArgument() {
return getReturnValue();
}
public void setReturnArgument(IASTInitializerClause returnValue) {
if (returnValue instanceof IASTExpression) {
setReturnValue((IASTExpression) returnValue);
} else {
setReturnValue(null);
}
}
@Override
public boolean accept( ASTVisitor action ){ public boolean accept( ASTVisitor action ){
if( action.shouldVisitStatements ){ if( action.shouldVisitStatements ){
switch( action.visit( this ) ){ switch( action.visit( this ) ){

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -40,7 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -93,10 +94,251 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
return DEFAULT_INSTANCE; return DEFAULT_INSTANCE;
} }
public IASTArrayDeclarator newArrayDeclarator(IASTName name) {
return new CASTArrayDeclarator(name);
}
public ICASTArrayDesignator newArrayDesignator(IASTExpression exp) {
return new CASTArrayDesignator(exp);
}
public ICASTArrayModifier newArrayModifier(IASTExpression expr) {
return new CASTArrayModifier(expr);
}
public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling) {
return new CASTArrayRangeDesignator(floor, ceiling);
}
public IASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript) {
return new CASTArraySubscriptExpression(arrayExpr, subscript);
}
public IASTASMDeclaration newASMDeclaration(String assembly) {
return new CASTASMDeclaration(assembly);
}
public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
return new CASTBinaryExpression(op, expr1, expr2);
}
public IASTBreakStatement newBreakStatement() {
return new CASTBreakStatement();
}
public IASTCaseStatement newCaseStatement(IASTExpression expression) {
return new CASTCaseStatement(expression);
}
/**
* @param operator
*/
public IASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand) {
return new CASTCastExpression(typeId, operand);
}
public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
return new CASTCompositeTypeSpecifier(key, name);
}
public IASTCompoundStatement newCompoundStatement() {
return new CASTCompoundStatement();
}
public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3) {
return new CASTConditionalExpression(expr1, expr2, expr3);
}
public IASTContinueStatement newContinueStatement() {
return new CASTContinueStatement();
}
public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) {
return new CASTDeclarationStatement(declaration);
}
public IASTDeclarator newDeclarator(IASTName name) {
return new CASTDeclarator(name);
}
public IASTDefaultStatement newDefaultStatement() {
return new CASTDefaultStatement();
}
@Deprecated
public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer operandInitializer) {
CASTDesignatedInitializer result = new CASTDesignatedInitializer();
result.setOperandInitializer(operandInitializer);
return result;
}
public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializerClause clause) {
return new CASTDesignatedInitializer(clause);
}
public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
return new CASTDoStatement(body, condition);
}
public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
return new CASTElaboratedTypeSpecifier(kind, name);
}
public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
return new CASTEnumerationSpecifier(name);
}
public IASTEnumerator newEnumerator(IASTName name, IASTExpression value) {
return new CASTEnumerator(name, value);
}
public IASTEqualsInitializer newEqualsInitializer(IASTInitializerClause initClause) {
return new CASTEqualsInitializer(initClause);
}
public IASTExpressionList newExpressionList() {
return new CASTExpressionList();
}
public IASTExpressionStatement newExpressionStatement(IASTExpression expr) {
return new CASTExpressionStatement(expr);
}
public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) {
return new CASTFieldDeclarator(name, bitFieldSize);
}
public ICASTFieldDesignator newFieldDesignator(IASTName name) {
return new CASTFieldDesignator(name);
}
public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
return new CASTFieldReference(name, owner);
}
public IASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpression, IASTStatement body) {
return new CASTForStatement(init, condition, iterationExpression, body);
}
@Deprecated
public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) {
CASTFunctionCallExpression result = new CASTFunctionCallExpression(idExpr, null);
result.setParameterExpression(argList);
return result;
}
public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTInitializerClause[] arguments) {
return new CASTFunctionCallExpression(idExpr, arguments);
}
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) {
return new CASTFunctionDeclarator(name);
}
public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement) {
return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
}
public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
return new CASTCompoundStatementExpression(compoundStatement);
}
public IASTGotoStatement newGotoStatement(IASTName name) {
return new CASTGotoStatement(name);
}
public IASTIdExpression newIdExpression(IASTName name) {
return new CASTIdExpression(name);
}
public IASTIfStatement newIfStatement(IASTExpression expr, IASTStatement thenStat, IASTStatement elseClause) {
return new CASTIfStatement(expr, thenStat, elseClause);
}
@Deprecated
public org.eclipse.cdt.core.dom.ast.IASTInitializerExpression newInitializerExpression(IASTExpression expression) {
return new CASTInitializerExpression(expression);
}
public IASTInitializerList newInitializerList() {
return new CASTInitializerList();
}
public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations) {
return new CASTKnRFunctionDeclarator(parameterNames, parameterDeclarations);
}
public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement) {
return new CASTLabelStatement(name, nestedStatement);
}
public IASTLiteralExpression newLiteralExpression(int kind, String rep) {
return new CASTLiteralExpression(kind, rep.toCharArray());
}
public IASTName newName() {
return new CASTName();
}
public IASTName newName(char[] name) {
return new CASTName(name);
}
public IASTNullStatement newNullStatement() {
return new CASTNullStatement();
}
public IASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
return new CASTParameterDeclaration(declSpec, declarator);
}
public ICASTPointer newPointer() {
return new CASTPointer();
}
public IASTProblem newProblem(int id, char[] arg, boolean error) {
return new CASTProblem(id, arg, error);
}
public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem) {
return new CASTProblemDeclaration(problem);
}
public IASTProblemExpression newProblemExpression(IASTProblem problem) {
return new CASTProblemExpression(problem);
}
public IASTProblemStatement newProblemStatement(IASTProblem problem) {
return new CASTProblemStatement(problem);
}
public IASTReturnStatement newReturnStatement(IASTExpression retValue) {
return new CASTReturnStatement(retValue);
}
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
return new CASTSimpleDeclaration(declSpecifier);
}
public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
return new CASTSimpleDeclSpecifier();
}
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression) {
return new GCCASTSimpleDeclSpecifier(typeofExpression);
}
public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
return new CASTSwitchStatement(controller, body);
}
public IASTTranslationUnit newTranslationUnit() { public IASTTranslationUnit newTranslationUnit() {
return newTranslationUnit(null); return newTranslationUnit(null);
} }
public IASTTranslationUnit newTranslationUnit(IScanner scanner) { public IASTTranslationUnit newTranslationUnit(IScanner scanner) {
CASTTranslationUnit tu = new CASTTranslationUnit(); CASTTranslationUnit tu = new CASTTranslationUnit();
@ -106,252 +348,30 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
tu.setASTNodeFactory(this); tu.setASTNodeFactory(this);
return tu; return tu;
} }
public IASTName newName(char[] name) {
return new CASTName(name);
}
public IASTName newName() {
return new CASTName();
}
public IASTLiteralExpression newLiteralExpression(int kind, String rep) {
return new CASTLiteralExpression(kind, rep.toCharArray());
}
public IASTIdExpression newIdExpression(IASTName name) {
return new CASTIdExpression(name);
}
public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
return new CASTBinaryExpression(op, expr1, expr2);
}
public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3) {
return new CASTConditionalExpression(expr1, expr2, expr3);
}
public IASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript) {
return new CASTArraySubscriptExpression(arrayExpr, subscript);
}
public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) {
return new CASTFunctionCallExpression(idExpr, argList);
}
public IASTExpressionList newExpressionList() {
return new CASTExpressionList();
}
public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
return new CASTFieldReference(name, owner);
}
public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
return new CASTUnaryExpression(operator, operand);
}
public IASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
return new CASTTypeIdExpression(operator, typeId);
}
public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
return new CASTTypeIdInitializerExpression(typeId, initializer);
}
/**
* @param operator
*/
public IASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand) {
return new CASTCastExpression(typeId, operand);
}
public IASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
return new CASTTypeId(declSpecifier, declarator);
}
public IASTDeclarator newDeclarator(IASTName name) {
return new CASTDeclarator(name);
}
public IASTArrayDeclarator newArrayDeclarator(IASTName name) {
return new CASTArrayDeclarator(name);
}
public ICASTArrayModifier newArrayModifier(IASTExpression expr) {
return new CASTArrayModifier(expr);
}
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) {
return new CASTFunctionDeclarator(name);
}
public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations) {
return new CASTKnRFunctionDeclarator(parameterNames, parameterDeclarations);
}
public ICASTPointer newPointer() {
return new CASTPointer();
}
public IASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
return new CASTParameterDeclaration(declSpec, declarator);
}
public IASTInitializerExpression newInitializerExpression(IASTExpression expression) {
return new CASTInitializerExpression(expression);
}
public IASTInitializerList newInitializerList() {
return new CASTInitializerList();
}
public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer operandInitializer) {
return new CASTDesignatedInitializer(operandInitializer);
}
public ICASTArrayDesignator newArrayDesignator(IASTExpression exp) {
return new CASTArrayDesignator(exp);
}
public ICASTFieldDesignator newFieldDesignator(IASTName name) {
return new CASTFieldDesignator(name);
}
public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name) { public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name) {
return new CASTTypedefNameSpecifier(name); return new CASTTypedefNameSpecifier(name);
} }
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) { public IASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
return new CASTSimpleDeclaration(declSpecifier); return new CASTTypeId(declSpecifier, declarator);
} }
public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) { public IASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
return new CASTFieldDeclarator(name, bitFieldSize); return new CASTTypeIdExpression(operator, typeId);
} }
public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) { public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
return new CASTCompositeTypeSpecifier(key, name); return new CASTTypeIdInitializerExpression(typeId, initializer);
} }
public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) { public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
return new CASTElaboratedTypeSpecifier(kind, name); return new CASTUnaryExpression(operator, operand);
} }
public IASTEnumerator newEnumerator(IASTName name, IASTExpression value) {
return new CASTEnumerator(name, value);
}
public IASTCompoundStatement newCompoundStatement() {
return new CASTCompoundStatement();
}
public IASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpression, IASTStatement body) {
return new CASTForStatement(init, condition, iterationExpression, body);
}
public IASTExpressionStatement newExpressionStatement(IASTExpression expr) {
return new CASTExpressionStatement(expr);
}
public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) {
return new CASTDeclarationStatement(declaration);
}
public IASTNullStatement newNullStatement() {
return new CASTNullStatement();
}
public IASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) { public IASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
return new CASTWhileStatement(condition, body); return new CASTWhileStatement(condition, body);
} }
public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
return new CASTDoStatement(body, condition);
}
public IASTGotoStatement newGotoStatement(IASTName name) {
return new CASTGotoStatement(name);
}
public IASTContinueStatement newContinueStatement() {
return new CASTContinueStatement();
}
public IASTBreakStatement newBreakStatement() {
return new CASTBreakStatement();
}
public IASTReturnStatement newReturnStatement(IASTExpression retValue) {
return new CASTReturnStatement(retValue);
}
public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement) {
return new CASTLabelStatement(name, nestedStatement);
}
public IASTCaseStatement newCaseStatement(IASTExpression expression) {
return new CASTCaseStatement(expression);
}
public IASTDefaultStatement newDefaultStatement() {
return new CASTDefaultStatement();
}
public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
return new CASTSwitchStatement(controller, body);
}
public IASTIfStatement newIfStatement(IASTExpression expr, IASTStatement thenStat, IASTStatement elseClause) {
return new CASTIfStatement(expr, thenStat, elseClause);
}
public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement) {
return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
}
public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem) {
return new CASTProblemDeclaration(problem);
}
public IASTProblemStatement newProblemStatement(IASTProblem problem) {
return new CASTProblemStatement(problem);
}
public IASTProblemExpression newProblemExpression(IASTProblem problem) {
return new CASTProblemExpression(problem);
}
public IASTProblem newProblem(int id, char[] arg, boolean error) {
return new CASTProblem(id, arg, error);
}
public IASTASMDeclaration newASMDeclaration(String assembly) {
return new CASTASMDeclaration(assembly);
}
public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
return new CASTEnumerationSpecifier(name);
}
public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
return new CASTSimpleDeclSpecifier();
}
public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
return new CASTCompoundStatementExpression(compoundStatement);
}
public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling) {
return new CASTArrayRangeDesignator(floor, ceiling);
}
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression) {
return new GCCASTSimpleDeclSpecifier(typeofExpression);
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -16,9 +16,10 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@ -186,10 +187,11 @@ public class CVariable extends PlatformObject implements IInternalVariable, ICIn
IASTDeclarator dtor= findDeclarator(name); IASTDeclarator dtor= findDeclarator(name);
if (dtor != null) { if (dtor != null) {
IASTInitializer init= dtor.getInitializer(); IASTInitializer init= dtor.getInitializer();
if (init instanceof IASTInitializerExpression) { if (init instanceof IASTEqualsInitializer) {
IASTExpression expr= ((IASTInitializerExpression) init).getExpression(); final IASTInitializerClause initClause = ((IASTEqualsInitializer) init).getInitializerClause();
if (expr != null) if (initClause instanceof IASTExpression) {
return Value.create(expr, maxDepth); return Value.create((IASTExpression) initClause, maxDepth);
}
} }
if (init != null) if (init != null)
return Value.UNKNOWN; return Value.UNKNOWN;

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
@ -40,7 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -135,13 +136,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
protected IASTInitializer optionalCInitializer() throws EndOfFileException, BacktrackException { protected IASTInitializer optionalCInitializer() throws EndOfFileException, BacktrackException {
if (LTcatchEOF(1) == IToken.tASSIGN) { if (LTcatchEOF(1) == IToken.tASSIGN) {
consume(); final int offset= consume().getOffset();
return cInitializerClause(false); IASTInitializerClause initClause = initClause(false);
IASTEqualsInitializer result= nodeFactory.newEqualsInitializer(initClause);
return setRange(result, offset, calculateEndOffset(initClause));
} }
return null; return null;
} }
protected IASTInitializer cInitializerClause(boolean inAggregate) throws EndOfFileException, BacktrackException { private IASTInitializerClause initClause(boolean inAggregate) throws EndOfFileException, BacktrackException {
final int offset = LA(1).getOffset(); final int offset = LA(1).getOffset();
if (LT(1) != IToken.tLBRACE) { if (LT(1) != IToken.tLBRACE) {
IASTExpression assignmentExpression= expression(ExprKind.eAssignment); IASTExpression assignmentExpression= expression(ExprKind.eAssignment);
@ -149,9 +152,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (!ASTQueries.canContainName(assignmentExpression)) if (!ASTQueries.canContainName(assignmentExpression))
return null; return null;
} }
IASTInitializerExpression result= nodeFactory.newInitializerExpression(assignmentExpression); return assignmentExpression;
setRange(result, assignmentExpression);
return result;
} }
// it's an aggregate initializer // it's an aggregate initializer
@ -171,22 +172,24 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
// get designator list // get designator list
List<? extends ICASTDesignator> designator= designatorList(); List<? extends ICASTDesignator> designator= designatorList();
if (designator == null) { if (designator == null) {
IASTInitializer initializer= cInitializerClause(true); IASTInitializerClause clause= initClause(true);
// depending on value of skipTrivialItemsInCompoundInitializers initializer may be null // depending on value of skipTrivialItemsInCompoundInitializers initializer may be null
// in any way add the initializer such that the actual size can be tracked. // in any way add the initializer such that the actual size can be tracked.
result.addInitializer(initializer); result.addClause(clause);
} else { } else {
// Gnu extension: the assign operator is optional
if (LT(1) == IToken.tASSIGN) if (LT(1) == IToken.tASSIGN)
consume(); consume(IToken.tASSIGN);
IASTInitializer initializer= cInitializerClause(false);
ICASTDesignatedInitializer desigInitializer = nodeFactory.newDesignatedInitializer(initializer); IASTInitializerClause clause= initClause(false);
ICASTDesignatedInitializer desigInitializer = nodeFactory.newDesignatedInitializer(clause);
setRange(desigInitializer, designator.get(0)); setRange(desigInitializer, designator.get(0));
adjustLength(desigInitializer, initializer); adjustLength(desigInitializer, clause);
for (ICASTDesignator d : designator) { for (ICASTDesignator d : designator) {
desigInitializer.addDesignator(d); desigInitializer.addDesignator(d);
} }
result.addInitializer(desigInitializer); result.addClause(desigInitializer);
} }
// can end with ", }" or "}" // can end with ", }" or "}"
@ -566,6 +569,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
return buildExpression(lastOperator, lastExpression); return buildExpression(lastOperator, lastExpression);
} }
@Override
protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset) {
IASTBinaryExpression result = nodeFactory.newBinaryExpression(operator, expr1, (IASTExpression) expr2);
int o = ((ASTNode) expr1).getOffset();
((ASTNode) result).setOffsetAndLength(o, lastOffset - o);
return result;
}
@Override @Override
protected IASTExpression unaryExpression(CastExprCtx ctx) throws EndOfFileException, BacktrackException { protected IASTExpression unaryExpression(CastExprCtx ctx) throws EndOfFileException, BacktrackException {
switch (LT(1)) { switch (LT(1)) {
@ -609,7 +620,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (t != null) { if (t != null) {
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if (LT(1) == IToken.tLBRACE) { if (LT(1) == IToken.tLBRACE) {
IASTInitializer i = cInitializerClause(false); IASTInitializer i = (IASTInitializerList) initClause(false);
firstExpression= nodeFactory.newTypeIdInitializerExpression(t, i); firstExpression= nodeFactory.newTypeIdInitializerExpression(t, i);
setRange(firstExpression, offset, calculateEndOffset(i)); setRange(firstExpression, offset, calculateEndOffset(i));
break; break;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
@ -31,8 +32,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTArraySubscriptExpression, IASTAmbiguityParent { public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTArraySubscriptExpression, IASTAmbiguityParent {
private IASTExpression subscriptExp;
private IASTExpression arrayExpression; private IASTExpression arrayExpression;
private IASTInitializerClause subscriptExp;
private ICPPFunction overload= UNINITIALIZED_FUNCTION; private ICPPFunction overload= UNINITIALIZED_FUNCTION;
private IASTImplicitName[] implicitNames = null; private IASTImplicitName[] implicitNames = null;
@ -40,15 +41,15 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
public CPPASTArraySubscriptExpression() { public CPPASTArraySubscriptExpression() {
} }
public CPPASTArraySubscriptExpression(IASTExpression arrayExpression, IASTExpression subscriptExp) { public CPPASTArraySubscriptExpression(IASTExpression arrayExpression, IASTInitializerClause operand) {
setArrayExpression(arrayExpression); setArrayExpression(arrayExpression);
setSubscriptExpression(subscriptExp); setArgument(operand);
} }
public CPPASTArraySubscriptExpression copy() { public CPPASTArraySubscriptExpression copy() {
CPPASTArraySubscriptExpression copy = new CPPASTArraySubscriptExpression(); CPPASTArraySubscriptExpression copy = new CPPASTArraySubscriptExpression();
copy.setArrayExpression(arrayExpression == null ? null : arrayExpression.copy()); copy.setArrayExpression(arrayExpression == null ? null : arrayExpression.copy());
copy.setSubscriptExpression(subscriptExp == null ? null : subscriptExp.copy()); copy.setArgument(subscriptExp == null ? null : subscriptExp.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
return copy; return copy;
} }
@ -67,18 +68,30 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
} }
} }
public IASTExpression getSubscriptExpression() { public IASTInitializerClause getArgument() {
return subscriptExp; return subscriptExp;
} }
public void setSubscriptExpression(IASTExpression expression) { public void setArgument(IASTInitializerClause arg) {
assertNotFrozen(); assertNotFrozen();
subscriptExp = expression; subscriptExp = arg;
if (expression != null) { if (arg != null) {
expression.setParent(this); arg.setParent(this);
expression.setPropertyInParent(SUBSCRIPT); arg.setPropertyInParent(SUBSCRIPT);
} }
} }
@Deprecated
public IASTExpression getSubscriptExpression() {
if (subscriptExp instanceof IASTExpression)
return (IASTExpression) subscriptExp;
return null;
}
@Deprecated
public void setSubscriptExpression(IASTExpression expression) {
setArgument(expression);
}
public IASTImplicitName[] getImplicitNames() { public IASTImplicitName[] getImplicitNames() {
if(implicitNames == null) { if(implicitNames == null) {

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
@ -37,7 +38,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpression, IASTAmbiguityParent { public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpression, IASTAmbiguityParent {
private int op; private int op;
private IASTExpression operand1; private IASTExpression operand1;
private IASTExpression operand2; private IASTInitializerClause operand2;
private IType type; private IType type;
private ICPPFunction overload= UNINITIALIZED_FUNCTION; private ICPPFunction overload= UNINITIALIZED_FUNCTION;
private IASTImplicitName[] implicitNames = null; private IASTImplicitName[] implicitNames = null;
@ -46,17 +47,17 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
public CPPASTBinaryExpression() { public CPPASTBinaryExpression() {
} }
public CPPASTBinaryExpression(int op, IASTExpression operand1, IASTExpression operand2) { public CPPASTBinaryExpression(int op, IASTExpression operand1, IASTInitializerClause operand2) {
this.op = op; this.op = op;
setOperand1(operand1); setOperand1(operand1);
setOperand2(operand2); setInitOperand2(operand2);
} }
public CPPASTBinaryExpression copy() { public CPPASTBinaryExpression copy() {
CPPASTBinaryExpression copy = new CPPASTBinaryExpression(); CPPASTBinaryExpression copy = new CPPASTBinaryExpression();
copy.op = op; copy.op = op;
copy.setOperand1(operand1 == null ? null : operand1.copy()); copy.setOperand1(operand1 == null ? null : operand1.copy());
copy.setOperand2(operand2 == null ? null : operand2.copy()); copy.setInitOperand2(operand2 == null ? null : operand2.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
return copy; return copy;
} }
@ -69,8 +70,14 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
return operand1; return operand1;
} }
public IASTInitializerClause getInitOperand2() {
return operand2;
}
public IASTExpression getOperand2() { public IASTExpression getOperand2() {
return operand2; if (operand2 instanceof IASTExpression)
return (IASTExpression) operand2;
return null;
} }
public void setOperator(int op) { public void setOperator(int op) {
@ -87,15 +94,19 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
} }
} }
public void setOperand2(IASTExpression expression) { public void setInitOperand2(IASTInitializerClause operand) {
assertNotFrozen(); assertNotFrozen();
operand2 = expression; operand2 = operand;
if (expression != null) { if (operand != null) {
expression.setParent(this); operand.setParent(this);
expression.setPropertyInParent(OPERAND_TWO); operand.setPropertyInParent(OPERAND_TWO);
} }
} }
public void setOperand2(IASTExpression expression) {
setInitOperand2(expression);
}
public IASTImplicitName[] getImplicitNames() { public IASTImplicitName[] getImplicitNames() {
if(implicitNames == null) { if(implicitNames == null) {
ICPPFunction overload = getOverload(); ICPPFunction overload = getOverload();
@ -219,7 +230,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
if (child == operand2) { if (child == operand2) {
other.setPropertyInParent(child.getPropertyInParent()); other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent()); other.setParent(child.getParent());
operand2 = (IASTExpression) other; operand2 = (IASTInitializerClause) other;
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -16,18 +16,19 @@ import java.util.Arrays;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext; import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
/** /**
@ -39,25 +40,25 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
* {@code Base()} and {@code field()} are the constructor chain initializers.<br> * {@code Base()} and {@code field()} are the constructor chain initializers.<br>
*/ */
public class CPPASTConstructorChainInitializer extends ASTNode implements public class CPPASTConstructorChainInitializer extends ASTNode implements
ICPPASTConstructorChainInitializer, IASTAmbiguityParent, IASTCompletionContext { ICPPASTConstructorChainInitializer, IASTCompletionContext {
private IASTName name; private IASTName name;
private IASTExpression value; private IASTInitializer initializer;
private boolean fIsPackExpansion; private boolean fIsPackExpansion;
public CPPASTConstructorChainInitializer() { public CPPASTConstructorChainInitializer() {
} }
public CPPASTConstructorChainInitializer(IASTName memberInitializerid, IASTExpression initializerValue) { public CPPASTConstructorChainInitializer(IASTName id, IASTInitializer initializer) {
setMemberInitializerId(memberInitializerid); setMemberInitializerId(id);
setInitializerValue(initializerValue); setInitializer(initializer);
} }
public CPPASTConstructorChainInitializer copy() { public CPPASTConstructorChainInitializer copy() {
CPPASTConstructorChainInitializer copy = new CPPASTConstructorChainInitializer(); CPPASTConstructorChainInitializer copy = new CPPASTConstructorChainInitializer();
copy.setMemberInitializerId(name == null ? null : name.copy()); copy.setMemberInitializerId(name == null ? null : name.copy());
copy.setInitializerValue(value == null ? null : value.copy()); copy.setInitializer(initializer == null ? null : initializer.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
copy.fIsPackExpansion= fIsPackExpansion; copy.fIsPackExpansion= fIsPackExpansion;
return copy; return copy;
@ -76,17 +77,16 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
} }
} }
public IASTExpression getInitializerValue() { public IASTInitializer getInitializer() {
return value; return initializer;
} }
public void setInitializer(IASTInitializer init) {
public void setInitializerValue(IASTExpression expression) {
assertNotFrozen(); assertNotFrozen();
value = expression; initializer = init;
if(expression != null) { if(init != null) {
expression.setParent(this); init.setParent(this);
expression.setPropertyInParent(INITIALIZER); init.setPropertyInParent(INITIALIZER);
} }
} }
@ -100,17 +100,15 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
return true; return true;
} }
} }
if (name != null) if (name != null && !name.accept(action))
if (!name.accept(action)) return false;
return false;
if (value != null)
if (!value.accept(action))
return false;
if (action.shouldVisitInitializers) { if (initializer != null && !initializer.accept(action))
if (action.leave(this) == ASTVisitor.PROCESS_ABORT) return false;
return false;
} if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
return true; return true;
} }
@ -120,21 +118,12 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
return r_unclear; return r_unclear;
} }
public void replace(IASTNode child, IASTNode other) {
if (child == value) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
value = (IASTExpression) other;
}
}
public IBinding[] findBindings(IASTName n, boolean isPrefix) { public IBinding[] findBindings(IASTName n, boolean isPrefix) {
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix); IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
ICPPASTBaseSpecifier[] baseClasses = null; ICPPASTBaseSpecifier[] baseClasses = null;
for (int i = 0; i < bindings.length; i++) { for (int i = 0; i < bindings.length; i++) {
if ((bindings[i] instanceof ICPPField) || (bindings[i] instanceof ICPPNamespace)) { if ((bindings[i] instanceof ICPPField) || (bindings[i] instanceof ICPPNamespace)) {
continue; continue;
} else if (bindings[i] instanceof ICPPConstructor) { } else if (bindings[i] instanceof ICPPConstructor) {
@ -184,4 +173,36 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
assertNotFrozen(); assertNotFrozen();
fIsPackExpansion= val; fIsPackExpansion= val;
} }
@Deprecated
public IASTExpression getInitializerValue() {
if (initializer == null || initializer instanceof IASTExpression) {
return (IASTExpression) initializer;
}
if (initializer instanceof ICPPASTConstructorInitializer) {
IASTExpression expr= ((ICPPASTConstructorInitializer) initializer).getExpression();
if (expr != null) {
expr= expr.copy();
expr.setParent(this);
expr.setPropertyInParent(INITIALIZER);
}
return expr;
}
return null;
}
@Deprecated
public void setInitializerValue(IASTExpression expression) {
assertNotFrozen();
if (expression == null) {
setInitializer(null);
} else if (expression instanceof IASTInitializer) {
setInitializer((IASTInitializer) expression);
} else {
CPPASTConstructorInitializer ctorInit= new CPPASTConstructorInitializer();
ctorInit.setExpression(expression);
ctorInit.setOffsetAndLength((ASTNode) expression);
setInitializer(ctorInit);
}
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,45 +13,56 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpressionList;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/** /**
* Initializer in parenthesis. * Initializer list in parenthesis.
*/ */
public class CPPASTConstructorInitializer extends ASTNode implements public class CPPASTConstructorInitializer extends ASTNode implements ICPPASTConstructorInitializer,
ICPPASTConstructorInitializer, IASTAmbiguityParent { IASTAmbiguityParent {
private IASTExpression exp;
private boolean fIsPackExpansion;
private IASTInitializerClause[] fArguments;
public CPPASTConstructorInitializer() { public CPPASTConstructorInitializer() {
setArguments(null);
} }
public CPPASTConstructorInitializer(IASTExpression exp) { public CPPASTConstructorInitializer(IASTInitializerClause[] args) {
setExpression(exp); setArguments(args);
} }
public CPPASTConstructorInitializer copy() { public CPPASTConstructorInitializer copy() {
CPPASTConstructorInitializer copy = new CPPASTConstructorInitializer(exp == null ? null : exp.copy()); IASTInitializerClause[] args = null;
if (fArguments != null) {
args= new IASTExpression[fArguments.length];
for (int i=0; i<fArguments.length; i++) {
args[i]= fArguments[i].copy();
}
}
CPPASTConstructorInitializer copy = new CPPASTConstructorInitializer(args);
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
copy.fIsPackExpansion= fIsPackExpansion;
return copy; return copy;
} }
public IASTExpression getExpression() { public IASTInitializerClause[] getArguments() {
return exp; return fArguments;
} }
public void setExpression(IASTExpression expression) { public void setArguments(IASTInitializerClause[] arguments) {
assertNotFrozen(); assertNotFrozen();
this.exp = expression; if (arguments == null) {
if (expression != null) { fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY;
expression.setParent(this); } else {
expression.setPropertyInParent(EXPRESSION); fArguments= arguments;
for (IASTInitializerClause arg : arguments) {
arg.setParent(this);
arg.setPropertyInParent(ARGUMENT);
}
} }
} }
@ -64,31 +75,59 @@ public class CPPASTConstructorInitializer extends ASTNode implements
default : break; default : break;
} }
} }
if( exp != null ) if( !exp.accept( action ) ) return false;
if( action.shouldVisitInitializers ){ for (IASTInitializerClause arg : fArguments) {
switch( action.leave( this ) ){ if (!arg.accept(action))
case ASTVisitor.PROCESS_ABORT : return false; return false;
case ASTVisitor.PROCESS_SKIP : return true; }
default : break;
} if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
} return false;
return true;
return true;
} }
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if (child == exp) { for (int i = 0; i < fArguments.length; ++i) {
other.setPropertyInParent(child.getPropertyInParent()); if (child == fArguments[i]) {
other.setParent(child.getParent()); other.setPropertyInParent(child.getPropertyInParent());
exp = (IASTExpression) other; other.setParent(child.getParent());
fArguments[i] = (IASTExpression) other;
}
}
}
@Deprecated
public IASTExpression getExpression() {
if (fArguments.length == 0)
return null;
if (fArguments.length == 1) {
IASTInitializerClause arg = fArguments[0];
if (arg instanceof IASTExpression)
return (IASTExpression) arg;
return null;
}
CPPASTExpressionList result= new CPPASTExpressionList();
for (IASTInitializerClause arg : fArguments) {
if (arg instanceof IASTExpression) {
result.addExpression(((IASTExpression) arg).copy());
}
}
result.setParent(this);
result.setPropertyInParent(EXPRESSION);
return result;
}
@Deprecated
public void setExpression(IASTExpression expression) {
assertNotFrozen();
if (expression == null) {
setArguments(null);
} else if (expression instanceof ICPPASTExpressionList) {
setArguments(((ICPPASTExpressionList) expression).getExpressions());
} else {
setArguments(new IASTExpression[] {expression});
} }
} }
public boolean isPackExpansion() {
return fIsPackExpansion;
}
public void setIsPackExpansion(boolean val) {
assertNotFrozen();
fIsPackExpansion= val;
}
} }

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.internal.core.dom.parser.ASTEqualsInitializer;
/**
* Initializer with equals sign (copy initialization)
*/
public class CPPASTEqualsInitializer extends ASTEqualsInitializer {
public CPPASTEqualsInitializer() {
}
public CPPASTEqualsInitializer(IASTInitializerClause arg) {
super(arg);
}
public CPPASTEqualsInitializer copy() {
IASTInitializerClause arg = getInitializerClause();
CPPASTEqualsInitializer copy = new CPPASTEqualsInitializer(arg == null ? null : arg.copy());
copy.setOffsetAndLength(this);
return copy;
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException; import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpressionList;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
@ -43,7 +45,7 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
ICPPASTFunctionCallExpression, IASTAmbiguityParent { ICPPASTFunctionCallExpression, IASTAmbiguityParent {
private IASTExpression functionName; private IASTExpression functionName;
private IASTExpression parameter; private IASTInitializerClause[] fArguments;
private IASTImplicitName[] implicitNames = null; private IASTImplicitName[] implicitNames = null;
private IType type; // cached type of expression private IType type; // cached type of expression
@ -51,21 +53,33 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
public CPPASTFunctionCallExpression() { public CPPASTFunctionCallExpression() {
setArguments(null);
} }
public CPPASTFunctionCallExpression(IASTExpression functionName, IASTExpression parameter) { public CPPASTFunctionCallExpression(IASTExpression functionName, IASTInitializerClause[] args) {
setFunctionNameExpression(functionName); setFunctionNameExpression(functionName);
setParameterExpression(parameter); setArguments(args);
} }
public CPPASTFunctionCallExpression copy() { public CPPASTFunctionCallExpression copy() {
CPPASTFunctionCallExpression copy = new CPPASTFunctionCallExpression(); IASTInitializerClause[] args = null;
if (fArguments.length > 0) {
args= new IASTExpression[fArguments.length];
for (int i=0; i<fArguments.length; i++) {
args[i]= fArguments[i].copy();
}
}
CPPASTFunctionCallExpression copy = new CPPASTFunctionCallExpression(null, args);
copy.setFunctionNameExpression(functionName == null ? null : functionName.copy()); copy.setFunctionNameExpression(functionName == null ? null : functionName.copy());
copy.setParameterExpression(parameter == null ? null : parameter.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
return copy; return copy;
} }
public IASTExpression getFunctionNameExpression() {
return functionName;
}
public void setFunctionNameExpression(IASTExpression expression) { public void setFunctionNameExpression(IASTExpression expression) {
assertNotFrozen(); assertNotFrozen();
this.functionName = expression; this.functionName = expression;
@ -74,25 +88,24 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
expression.setPropertyInParent(FUNCTION_NAME); expression.setPropertyInParent(FUNCTION_NAME);
} }
} }
public IASTExpression getFunctionNameExpression() { public IASTInitializerClause[] getArguments() {
return functionName; return fArguments;
} }
public void setParameterExpression(IASTExpression expression) { public void setArguments(IASTInitializerClause[] arguments) {
assertNotFrozen(); assertNotFrozen();
this.parameter = expression; if (arguments == null) {
if (expression != null) { fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY;
expression.setParent(this); } else {
expression.setPropertyInParent(PARAMETERS); fArguments= arguments;
for (IASTInitializerClause arg : arguments) {
arg.setParent(this);
arg.setPropertyInParent(ARGUMENT);
}
} }
} }
public IASTExpression getParameterExpression() {
return parameter;
}
public IASTImplicitName[] getImplicitNames() { public IASTImplicitName[] getImplicitNames() {
if(implicitNames == null) { if(implicitNames == null) {
ICPPFunction overload = getOperator(); ICPPFunction overload = getOperator();
@ -107,7 +120,7 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
n2.setBinding(overload); n2.setBinding(overload);
n2.setAlternate(true); n2.setAlternate(true);
if(parameter == null) { if (fArguments.length == 0) {
int idEndOffset = ((ASTNode)functionName).getOffset() + ((ASTNode)functionName).getLength(); int idEndOffset = ((ASTNode)functionName).getOffset() + ((ASTNode)functionName).getLength();
try { try {
IToken lparen = functionName.getTrailingSyntax(); IToken lparen = functionName.getTrailingSyntax();
@ -126,10 +139,9 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
n1.setOffsetAndLength(idEndOffset, 0); n1.setOffsetAndLength(idEndOffset, 0);
n2.setOffsetAndLength(idEndOffset, 0); n2.setOffsetAndLength(idEndOffset, 0);
} }
} } else {
else {
n1.computeOperatorOffsets(functionName, true); n1.computeOperatorOffsets(functionName, true);
n2.computeOperatorOffsets(parameter, true); n2.computeOperatorOffsets(fArguments[fArguments.length-1], true);
} }
implicitNames = new IASTImplicitName[] { n1, n2 }; implicitNames = new IASTImplicitName[] { n1, n2 };
@ -147,43 +159,44 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
} }
} }
if( functionName != null ) if( !functionName.accept( action ) ) return false; if (functionName != null && !functionName.accept(action))
return false;
IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? getImplicitNames() : null; IASTImplicitName[] implicits = action.shouldVisitImplicitNames ? getImplicitNames() : null;
if(implicits != null && implicits.length > 0) if (implicits != null && implicits.length > 0)
if(!implicits[0].accept(action)) return false; if (!implicits[0].accept(action))
return false;
if( parameter != null ) if( !parameter.accept( action ) ) return false; for (IASTInitializerClause arg : fArguments) {
if (!arg.accept(action))
if(implicits != null && implicits.length > 0) return false;
if(!implicits[1].accept(action)) return false;
if( action.shouldVisitExpressions ){
switch( action.leave( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
} }
if (implicits != null && implicits.length > 0)
if (!implicits[1].accept(action))
return false;
if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
return true; return true;
} }
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( child == functionName ) if (child == functionName) {
{ other.setPropertyInParent(child.getPropertyInParent());
other.setPropertyInParent( child.getPropertyInParent() ); other.setParent(child.getParent());
other.setParent( child.getParent() ); functionName = (IASTExpression) other;
functionName = (IASTExpression) other; }
} for (int i = 0; i < fArguments.length; ++i) {
if( child == parameter ) if (child == fArguments[i]) {
{ other.setPropertyInParent(child.getPropertyInParent());
other.setPropertyInParent( child.getPropertyInParent() ); other.setParent(child.getParent());
other.setParent( child.getParent() ); fArguments[i] = (IASTExpression) other;
parameter = (IASTExpression) other; }
} }
} }
public ICPPFunction getOperator() { public ICPPFunction getOperator() {
if (overload == UNINITIALIZED_FUNCTION) { if (overload == UNINITIALIZED_FUNCTION) {
@ -254,4 +267,38 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
} }
return null; return null;
} }
@Deprecated
public IASTExpression getParameterExpression() {
if (fArguments.length == 0)
return null;
if (fArguments.length == 1) {
IASTInitializerClause arg = fArguments[0];
if (arg instanceof IASTExpression)
return (IASTExpression) arg;
return null;
}
CPPASTExpressionList result= new CPPASTExpressionList();
for (IASTInitializerClause arg : fArguments) {
if (arg instanceof IASTExpression) {
result.addExpression(((IASTExpression) arg).copy());
}
}
result.setParent(this);
result.setPropertyInParent(ARGUMENT);
return result;
}
@Deprecated
public void setParameterExpression(IASTExpression expression) {
assertNotFrozen();
if (expression == null) {
setArguments(null);
} else if (expression instanceof ICPPASTExpressionList) {
setArguments(((ICPPASTExpressionList) expression).getExpressions());
} else {
setArguments(new IASTExpression[] {expression});
}
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,85 +11,26 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/** @Deprecated
* Initializer expression. public class CPPASTInitializerExpression extends CPPASTEqualsInitializer implements IASTInitializerExpression {
*/
public class CPPASTInitializerExpression extends ASTNode implements
ICPPASTInitializerExpression, IASTAmbiguityParent {
private IASTExpression exp;
private boolean fIsPackExpansion;
public CPPASTInitializerExpression() { public CPPASTInitializerExpression() {
} }
public CPPASTInitializerExpression(IASTExpression exp) { public CPPASTInitializerExpression(IASTExpression expression) {
setExpression(exp); setExpression(expression);
} }
@Override
public CPPASTInitializerExpression copy() { public CPPASTInitializerExpression copy() {
CPPASTInitializerExpression copy = new CPPASTInitializerExpression(exp == null ? null : exp.copy()); CPPASTInitializerExpression copy= new CPPASTInitializerExpression();
IASTInitializerClause init= getInitializerClause();
copy.setInitializerClause(init == null ? null : init.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
copy.fIsPackExpansion= fIsPackExpansion;
return copy; return copy;
} }
public IASTExpression getExpression() {
return exp;
}
public void setExpression(IASTExpression expression) {
assertNotFrozen();
this.exp = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(INITIALIZER_EXPRESSION);
}
}
@Override
public boolean accept( ASTVisitor action ){
if( action.shouldVisitInitializers ){
switch( action.visit( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
if( exp != null ) if( !exp.accept( action ) ) return false;
if( action.shouldVisitInitializers ){
switch( action.leave( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
return true;
}
public void replace(IASTNode child, IASTNode other) {
if( child == exp ) {
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
exp = (IASTExpression) other;
}
}
public boolean isPackExpansion() {
return fIsPackExpansion;
}
public void setIsPackExpansion(boolean val) {
assertNotFrozen();
fIsPackExpansion= val;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -12,77 +12,111 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/** /**
* e.g.: int a[]= {1,2,3}; * e.g.: int a[]= {1,2,3};
*/ */
public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializerList { public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializerList, IASTAmbiguityParent {
private IASTInitializer [] initializers = null;
private IASTInitializerClause [] initializers = null;
private int initializersPos=-1; private int initializersPos=-1;
private int actualLength; private int actualSize;
private boolean fIsPackExpansion; private boolean fIsPackExpansion;
public CPPASTInitializerList copy() { public CPPASTInitializerList copy() {
CPPASTInitializerList copy = new CPPASTInitializerList(); CPPASTInitializerList copy = new CPPASTInitializerList();
for(IASTInitializer initializer : getInitializers()) for (IASTInitializerClause initializer : getClauses())
copy.addInitializer(initializer == null ? null : initializer.copy()); copy.addClause(initializer == null ? null : initializer.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
copy.actualLength= getSize(); copy.actualSize = getSize();
copy.fIsPackExpansion= fIsPackExpansion; copy.fIsPackExpansion = fIsPackExpansion;
return copy; return copy;
} }
public int getSize() { public int getSize() {
return actualLength; return actualSize;
} }
public IASTInitializer[] getInitializers() { public IASTInitializerClause[] getClauses() {
if (initializers == null) if (initializers == null)
return IASTInitializer.EMPTY_INITIALIZER_ARRAY; return IASTExpression.EMPTY_EXPRESSION_ARRAY;
initializers = ArrayUtil.trimAt(IASTInitializerClause.class, initializers, initializersPos);
initializers = ArrayUtil.trimAt(IASTInitializer.class, initializers, initializersPos);
return initializers; return initializers;
} }
public void addInitializer(IASTInitializer d) { @Deprecated
assertNotFrozen(); public IASTInitializer[] getInitializers() {
if (d != null) { IASTInitializerClause[] clauses= getClauses();
initializers = (IASTInitializer[]) ArrayUtil.append(IASTInitializer.class, initializers, if (clauses.length == 0)
++initializersPos, d); return IASTInitializer.EMPTY_INITIALIZER_ARRAY;
d.setParent(this);
d.setPropertyInParent(NESTED_INITIALIZER); IASTInitializer[] inits= new IASTInitializer[clauses.length];
for (int i = 0; i < inits.length; i++) {
IASTInitializerClause clause= clauses[i];
if (clause instanceof IASTInitializer) {
inits[i]= (IASTInitializer) clause;
} else if (clause instanceof IASTExpression) {
final CPPASTEqualsInitializer initExpr = new CPPASTEqualsInitializer(((IASTExpression) clause).copy());
initExpr.setParent(this);
initExpr.setPropertyInParent(NESTED_INITIALIZER);
inits[i]= initExpr;
}
} }
actualLength++; return inits;
} }
public void addClause(IASTInitializerClause d) {
assertNotFrozen();
if (d != null) {
initializers = (IASTInitializerClause[]) ArrayUtil.append( IASTInitializerClause.class, initializers, ++initializersPos, d );
d.setParent(this);
d.setPropertyInParent(NESTED_INITIALIZER);
}
actualSize++;
}
@Deprecated
public void addInitializer(IASTInitializer d) {
assertNotFrozen();
if (d instanceof IASTInitializerClause) {
addClause((IASTInitializerClause) d);
} else if (d instanceof IASTEqualsInitializer) {
addClause(((IASTEqualsInitializer) d).getInitializerClause());
} else {
addClause(null);
}
}
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept( ASTVisitor action ){
if( action.shouldVisitInitializers ){ if (action.shouldVisitInitializers) {
switch( action.visit( this ) ){ switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true; case ASTVisitor.PROCESS_SKIP : return true;
default : break; default : break;
} }
} }
IASTInitializer [] list = getInitializers(); IASTInitializerClause[] list = getClauses();
for ( int i = 0; i < list.length; i++ ) { for (IASTInitializerClause clause : list) {
if( !list[i].accept( action ) ) return false; if (!clause.accept(action))
} return false;
}
if( action.shouldVisitInitializers ){ if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
switch( action.leave( this ) ){ return false;
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true; return true;
default : break;
}
}
return true;
} }
public boolean isPackExpansion() { public boolean isPackExpansion() {
return fIsPackExpansion; return fIsPackExpansion;
} }
@ -91,5 +125,16 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer
assertNotFrozen(); assertNotFrozen();
fIsPackExpansion= val; fIsPackExpansion= val;
} }
public void replace(IASTNode child, IASTNode other) {
if (initializers != null) {
for (int i = 0; i < initializers.length; ++i) {
if (child == initializers[i]) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
initializers[i] = (IASTInitializerClause) other;
}
}
}
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -17,92 +17,92 @@ import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTExpressionList;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.Assert;
public class CPPASTNewExpression extends ASTNode implements public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression, IASTAmbiguityParent {
ICPPASTNewExpression, IASTAmbiguityParent { private IASTInitializerClause[] placement;
private boolean global;
private IASTExpression placement;
private IASTExpression initializer;
private IASTTypeId typeId; private IASTTypeId typeId;
private boolean isNewTypeId; private IASTInitializer initializer;
private IASTExpression [] arrayExpressions = null;
private IASTImplicitName[] implicitNames = null; private IASTImplicitName[] implicitNames = null;
private boolean isGlobal;
private boolean isNewTypeId;
private IASTExpression[] cachedArraySizes;
public CPPASTNewExpression() { public CPPASTNewExpression() {
} }
public CPPASTNewExpression(IASTExpression placement, public CPPASTNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, IASTTypeId typeId) {
IASTExpression initializer, IASTTypeId typeId) { setPlacementArguments(placement);
setNewPlacement(placement);
setNewInitializer(initializer);
setTypeId(typeId); setTypeId(typeId);
setInitializer(initializer);
} }
public CPPASTNewExpression copy() { public CPPASTNewExpression copy() {
CPPASTNewExpression copy = new CPPASTNewExpression(); CPPASTNewExpression copy = new CPPASTNewExpression();
copy.setIsGlobal(global); copy.setIsGlobal(isGlobal);
copy.setIsNewTypeId(isNewTypeId); copy.setIsNewTypeId(isNewTypeId);
copy.setNewPlacement(placement == null ? null : placement.copy()); if (placement != null) {
copy.setNewInitializer(initializer == null ? null : initializer.copy()); IASTInitializerClause[] plcmt = new IASTInitializerClause[placement.length];
copy.setTypeId(typeId == null ? null : typeId.copy()); for (int i=0; i<placement.length; i++) {
plcmt[i]= placement[i].copy();
if(arrayExpressions != null) {
copy.arrayExpressions = new IASTExpression[arrayExpressions.length];
for(int i = 0; i < arrayExpressions.length; i++) {
copy.arrayExpressions[i] = arrayExpressions[i] == null ? null : arrayExpressions[i].copy();
} }
copy.setPlacementArguments(plcmt);
} }
copy.setTypeId(typeId == null ? null : typeId.copy());
copy.setInitializer(initializer == null ? null : initializer.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
return copy; return copy;
} }
public boolean isGlobal() { public boolean isGlobal() {
return global; return isGlobal;
} }
public void setIsGlobal(boolean value) { public void setIsGlobal(boolean value) {
assertNotFrozen(); assertNotFrozen();
global = value; isGlobal = value;
} }
public IASTExpression getNewPlacement() { public IASTInitializerClause[] getPlacementArguments() {
return placement; return placement;
} }
public void setNewPlacement(IASTExpression expression) { public void setPlacementArguments(IASTInitializerClause[] args) {
assertNotFrozen(); assertNotFrozen();
placement = expression; placement = args;
if (expression != null) { if (args != null) {
expression.setParent(this); for (IASTInitializerClause arg : args) {
expression.setPropertyInParent(NEW_PLACEMENT); arg.setParent(this);
arg.setPropertyInParent(NEW_PLACEMENT);
}
} }
} }
public IASTExpression getNewInitializer() { public IASTInitializer getInitializer() {
return initializer; return initializer;
} }
public void setNewInitializer(IASTExpression expression) { public void setInitializer(IASTInitializer expression) {
assertNotFrozen(); assertNotFrozen();
initializer = expression; initializer = expression;
if (expression != null) { if (expression != null) {
@ -132,47 +132,6 @@ public class CPPASTNewExpression extends ASTNode implements
assertNotFrozen(); assertNotFrozen();
isNewTypeId = value; isNewTypeId = value;
} }
public IASTExpression [] getNewTypeIdArrayExpressions() {
if( arrayExpressions == null ) {
if (typeId != null) {
IASTDeclarator dtor= ASTQueries.findInnermostDeclarator(typeId.getAbstractDeclarator());
if (dtor instanceof IASTArrayDeclarator) {
IASTArrayDeclarator ad= (IASTArrayDeclarator) dtor;
IASTArrayModifier[] ams= ad.getArrayModifiers();
arrayExpressions= new IASTExpression[ams.length];
for (int i = 0; i < ams.length; i++) {
IASTArrayModifier am = ams[i];
arrayExpressions[i]= am.getConstantExpression();
}
return arrayExpressions;
}
}
arrayExpressions= IASTExpression.EMPTY_EXPRESSION_ARRAY;
}
return arrayExpressions;
}
public void addNewTypeIdArrayExpression(IASTExpression expression) {
assertNotFrozen();
Assert.isNotNull(typeId);
IASTDeclarator dtor= ASTQueries.findInnermostDeclarator(typeId.getAbstractDeclarator());
if (dtor instanceof IASTArrayDeclarator == false) {
Assert.isNotNull(dtor);
Assert.isTrue(dtor.getParent() == typeId);
IASTArrayDeclarator adtor= new CPPASTArrayDeclarator(dtor.getName());
IASTPointerOperator[] ptrOps= dtor.getPointerOperators();
for (IASTPointerOperator ptr : ptrOps) {
adtor.addPointerOperator(ptr);
}
typeId.setAbstractDeclarator(adtor);
dtor= adtor;
}
IASTArrayModifier mod= new CPPASTArrayModifier(expression);
((ASTNode) mod).setOffsetAndLength((ASTNode)expression);
((IASTArrayDeclarator) dtor).addArrayModifier(mod);
}
public IASTImplicitName[] getImplicitNames() { public IASTImplicitName[] getImplicitNames() {
if(implicitNames == null) { if(implicitNames == null) {
@ -219,10 +178,17 @@ public class CPPASTNewExpression extends ASTNode implements
} }
} }
if( placement != null ) if( !placement.accept( action ) ) return false; if (placement != null) {
if( typeId != null ) if( !typeId.accept( action ) ) return false; for (IASTInitializerClause arg : placement) {
if( initializer != null ) if( !initializer.accept( action ) ) return false; if (!arg.accept(action))
return false;
}
}
if (typeId != null && !typeId.accept(action))
return false;
if (initializer != null && !initializer.accept(action))
return false;
if( action.shouldVisitExpressions ){ if( action.shouldVisitExpressions ){
switch( action.leave( this ) ){ switch( action.leave( this ) ){
@ -234,20 +200,17 @@ public class CPPASTNewExpression extends ASTNode implements
return true; return true;
} }
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( child == placement ) if (placement != null) {
{ for (int i = 0; i < placement.length; ++i) {
other.setPropertyInParent( child.getPropertyInParent() ); if (child == placement[i]) {
other.setParent( child.getParent() ); other.setPropertyInParent(child.getPropertyInParent());
placement = (IASTExpression) other; other.setParent(child.getParent());
} placement[i] = (IASTExpression) other;
if( child == initializer ) }
{ }
other.setPropertyInParent( child.getPropertyInParent() ); }
other.setParent( child.getParent() ); }
initializer = (IASTExpression) other;
}
}
public IType getExpressionType() { public IType getExpressionType() {
IType t= CPPVisitor.createType(getTypeId()); IType t= CPPVisitor.createType(getTypeId());
@ -260,4 +223,113 @@ public class CPPASTNewExpression extends ASTNode implements
public boolean isLValue() { public boolean isLValue() {
return false; return false;
} }
@Deprecated
public IASTExpression[] getNewTypeIdArrayExpressions() {
if (cachedArraySizes == null) {
if (typeId != null) {
IASTDeclarator dtor = ASTQueries.findInnermostDeclarator(typeId.getAbstractDeclarator());
if (dtor instanceof IASTArrayDeclarator) {
IASTArrayDeclarator ad = (IASTArrayDeclarator) dtor;
IASTArrayModifier[] ams = ad.getArrayModifiers();
cachedArraySizes = new IASTExpression[ams.length];
for (int i = 0; i < ams.length; i++) {
IASTArrayModifier am = ams[i];
cachedArraySizes[i] = am.getConstantExpression();
}
return cachedArraySizes;
}
}
cachedArraySizes = IASTExpression.EMPTY_EXPRESSION_ARRAY;
}
return cachedArraySizes;
}
@Deprecated
public void addNewTypeIdArrayExpression(IASTExpression expression) {
assertNotFrozen();
Assert.isNotNull(typeId);
IASTDeclarator dtor= ASTQueries.findInnermostDeclarator(typeId.getAbstractDeclarator());
if (dtor instanceof IASTArrayDeclarator == false) {
Assert.isNotNull(dtor);
Assert.isTrue(dtor.getParent() == typeId);
IASTArrayDeclarator adtor= new CPPASTArrayDeclarator(dtor.getName());
IASTPointerOperator[] ptrOps= dtor.getPointerOperators();
for (IASTPointerOperator ptr : ptrOps) {
adtor.addPointerOperator(ptr);
}
typeId.setAbstractDeclarator(adtor);
dtor= adtor;
}
IASTArrayModifier mod= new CPPASTArrayModifier(expression);
((ASTNode) mod).setOffsetAndLength((ASTNode)expression);
((IASTArrayDeclarator) dtor).addArrayModifier(mod);
}
@Deprecated
public IASTExpression getNewPlacement() {
if (placement == null || placement.length == 0)
return null;
if (placement.length == 1) {
if (placement[0] instanceof IASTExpression)
return (IASTExpression) placement[0];
return null;
}
CASTExpressionList result= new CASTExpressionList();
for (IASTInitializerClause arg : placement) {
if (arg instanceof IASTExpression) {
result.addExpression(((IASTExpression) arg).copy());
}
}
result.setParent(this);
result.setPropertyInParent(NEW_PLACEMENT);
return result;
}
@Deprecated
public void setNewPlacement(IASTExpression expression) {
assertNotFrozen();
if (expression == null) {
setPlacementArguments(null);
} else if (expression instanceof IASTExpressionList) {
setPlacementArguments(((IASTExpressionList) expression).getExpressions());
} else {
setPlacementArguments(new IASTExpression[] {expression});
}
}
@Deprecated
public IASTExpression getNewInitializer() {
if (initializer == null || initializer instanceof IASTExpression) {
return (IASTExpression) initializer;
}
if (initializer instanceof ICPPASTConstructorInitializer) {
IASTExpression expr= ((ICPPASTConstructorInitializer) initializer).getExpression();
if (expr == null) {
expr= new CPPASTExpressionList();
} else {
expr= expr.copy();
}
expr.setParent(this);
expr.setPropertyInParent(NEW_INITIALIZER);
return expr;
}
return null;
}
@Deprecated
public void setNewInitializer(IASTExpression expression) {
assertNotFrozen();
if (expression == null) {
setInitializer(null);
} else if (expression instanceof IASTInitializer) {
setInitializer((IASTInitializer) expression);
} else {
CPPASTConstructorInitializer ctorInit= new CPPASTConstructorInitializer();
ctorInit.setExpression(expression);
ctorInit.setOffsetAndLength((ASTNode) expression);
setInitializer(ctorInit);
}
}
} }

View file

@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.model.IEnumeration;
import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -252,23 +253,21 @@ public class CPPASTQualifiedName extends CPPASTNameBase
IBinding binding = names[namesPos-1].resolveBinding(); IBinding binding = names[namesPos-1].resolveBinding();
if (binding instanceof ICPPClassType) { if (binding instanceof ICPPClassType) {
ICPPClassType classType = (ICPPClassType) binding; ICPPClassType classType = (ICPPClassType) binding;
if (!canBeFieldAccess(classType)) { final boolean isDeclaration = getParent().getParent() instanceof IASTSimpleDeclaration;
final boolean isDeclaration = getParent().getParent() instanceof IASTSimpleDeclaration; List<IBinding> filtered = filterClassScopeBindings(classType, bindings, isDeclaration);
List<IBinding> filtered = filterClassScopeBindings(classType, bindings, isDeclaration); if (isDeclaration && nameMatches(classType.getNameCharArray(),
if (isDeclaration && nameMatches(classType.getNameCharArray(), n.getLookupKey(), isPrefix)) {
n.getLookupKey(), isPrefix)) { try {
try { ICPPConstructor[] constructors = classType.getConstructors();
ICPPConstructor[] constructors = classType.getConstructors(); for (int i = 0; i < constructors.length; i++) {
for (int i = 0; i < constructors.length; i++) { if (!constructors[i].isImplicit()) {
if (!constructors[i].isImplicit()) { filtered.add(constructors[i]);
filtered.add(constructors[i]);
}
} }
} catch (DOMException e) {
} }
} catch (DOMException e) {
} }
return filtered.toArray(new IBinding[filtered.size()]);
} }
return filtered.toArray(new IBinding[filtered.size()]);
} }
} }
@ -301,22 +300,24 @@ public class CPPASTQualifiedName extends CPPASTNameBase
private List<IBinding> filterClassScopeBindings(ICPPClassType classType, private List<IBinding> filterClassScopeBindings(ICPPClassType classType,
IBinding[] bindings, final boolean isDeclaration) { IBinding[] bindings, final boolean isDeclaration) {
List<IBinding> filtered = new ArrayList<IBinding>(); List<IBinding> filtered = new ArrayList<IBinding>();
final boolean canBeFieldAccess= canBeFieldAccess(classType);
try { try {
for (final IBinding binding : bindings) { for (final IBinding binding : bindings) {
if (binding instanceof IField) { if (binding instanceof IField) {
IField field = (IField) binding; IField field = (IField) binding;
if (!field.isStatic()) if (!canBeFieldAccess && !field.isStatic())
continue; continue;
} else if (binding instanceof ICPPMethod) { } else if (binding instanceof ICPPMethod) {
ICPPMethod method = (ICPPMethod) binding; ICPPMethod method = (ICPPMethod) binding;
if (method.isImplicit()) if (method.isImplicit())
continue; continue;
if (!isDeclaration) { if (!isDeclaration) {
if (method.isDestructor() || method instanceof ICPPConstructor || !method.isStatic()) if (method.isDestructor() || method instanceof ICPPConstructor
|| (!canBeFieldAccess && !method.isStatic()))
continue; continue;
} }
} else if (binding instanceof IEnumerator || binding instanceof IEnumerator) { } else if (binding instanceof IEnumerator || binding instanceof IEnumeration) {
if (isDeclaration) if (isDeclaration)
continue; continue;
} else if (binding instanceof IType) { } else if (binding instanceof IType) {

View file

@ -1,34 +1,33 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* @author jcamelon
*/
public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatement, IASTAmbiguityParent { public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatement, IASTAmbiguityParent {
private IASTExpression retValue; private IASTInitializerClause retValue;
public CPPASTReturnStatement() { public CPPASTReturnStatement() {
} }
public CPPASTReturnStatement(IASTExpression retValue) { public CPPASTReturnStatement(IASTInitializerClause retValue) {
setReturnValue(retValue); setReturnArgument(retValue);
} }
public CPPASTReturnStatement copy() { public CPPASTReturnStatement copy() {
@ -37,16 +36,28 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen
return copy; return copy;
} }
public IASTInitializerClause getReturnArgument() {
return retValue;
}
public IASTExpression getReturnValue() { public IASTExpression getReturnValue() {
return retValue; if (retValue instanceof IASTExpression) {
return (IASTExpression) retValue;
}
return null;
} }
public void setReturnValue(IASTExpression returnValue) { public void setReturnValue(IASTExpression returnValue) {
setReturnArgument(returnValue);
}
public void setReturnArgument(IASTInitializerClause arg) {
assertNotFrozen(); assertNotFrozen();
retValue = returnValue; retValue = arg;
if (returnValue != null) { if (arg != null) {
returnValue.setParent(this); arg.setParent(this);
returnValue.setPropertyInParent(RETURNVALUE); arg.setPropertyInParent(RETURNVALUE);
} }
} }
@ -62,9 +73,8 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen
break; break;
} }
} }
if (retValue != null) if (retValue != null && !retValue.accept(action))
if (!retValue.accept(action)) return false;
return false;
if( action.shouldVisitStatements ){ if( action.shouldVisitStatements ){
switch( action.leave( this ) ){ switch( action.leave( this ) ){
@ -80,7 +90,7 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen
if (child == retValue) { if (child == retValue) {
other.setPropertyInParent(child.getPropertyInParent()); other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent()); other.setParent(child.getParent());
retValue = (IASTExpression) other; retValue = (IASTInitializerClause) other;
} }
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,56 +13,76 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements
ICPPASTSimpleTypeConstructorExpression, IASTAmbiguityParent { ICPPASTSimpleTypeConstructorExpression {
private int st; private ICPPASTDeclSpecifier fDeclSpec;
private IASTExpression init; private IASTInitializer fInitializer;
private IType fType;
public CPPASTSimpleTypeConstructorExpression() { public CPPASTSimpleTypeConstructorExpression() {
} }
public CPPASTSimpleTypeConstructorExpression(int st, IASTExpression init) { public CPPASTSimpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec, IASTInitializer init) {
this.st = st; setDeclSpecifier(declSpec);
setInitialValue(init); setInitializer(init);
} }
public CPPASTSimpleTypeConstructorExpression copy() { public CPPASTSimpleTypeConstructorExpression copy() {
CPPASTSimpleTypeConstructorExpression copy = new CPPASTSimpleTypeConstructorExpression(); CPPASTSimpleTypeConstructorExpression copy = new CPPASTSimpleTypeConstructorExpression();
copy.st = st; copy.setDeclSpecifier(fDeclSpec == null ? null : fDeclSpec.copy());
copy.setInitialValue(init == null ? null : init.copy()); copy.setInitializer(fInitializer == null ? null : fInitializer.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
return copy; return copy;
} }
public int getSimpleType() { public ICPPASTDeclSpecifier getDeclSpecifier() {
return st; return fDeclSpec;
}
public IASTInitializer getInitializer() {
return fInitializer;
}
public void setDeclSpecifier(ICPPASTDeclSpecifier declSpec) {
assertNotFrozen();
fDeclSpec = declSpec;
if (declSpec != null) {
declSpec.setParent(this);
declSpec.setPropertyInParent(TYPE_SPECIFIER);
}
} }
public void setSimpleType(int value) { public void setInitializer(IASTInitializer initializer) {
assertNotFrozen(); assertNotFrozen();
st = value; fInitializer = initializer;
if (initializer != null) {
initializer.setParent(this);
initializer.setPropertyInParent(INITIALIZER);
}
} }
public IASTExpression getInitialValue() { public IType getExpressionType() {
return init; if (fType == null) {
} fType= CPPVisitor.createType(fDeclSpec);
public void setInitialValue(IASTExpression expression) {
assertNotFrozen();
init = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(INITIALIZER_VALUE);
} }
} return fType;
}
public boolean isLValue() {
return false;
}
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept( ASTVisitor action ){
if( action.shouldVisitExpressions ){ if( action.shouldVisitExpressions ){
@ -72,8 +92,12 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements
default : break; default : break;
} }
} }
if( init != null ) if( !init.accept( action ) ) return false; if (fDeclSpec != null && !fDeclSpec.accept(action))
return false;
if (fInitializer != null && !fInitializer.accept(action))
return false;
if( action.shouldVisitExpressions ){ if( action.shouldVisitExpressions ){
switch( action.leave( this ) ){ switch( action.leave( this ) ){
@ -85,20 +109,102 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements
return true; return true;
} }
public void replace(IASTNode child, IASTNode other) { @Deprecated
if( child == init ) public int getSimpleType() {
{ IType type= getExpressionType();
other.setPropertyInParent( child.getPropertyInParent() ); if (type instanceof ICPPBasicType) {
other.setParent( child.getParent() ); ICPPBasicType bt= (ICPPBasicType) type;
init = (IASTExpression) other; Kind kind = bt.getKind();
} switch(kind) {
case eBoolean:
return t_bool;
case eChar:
return t_char;
case eDouble:
return t_double;
case eFloat:
return t_float;
case eInt:
if (bt.isShort())
return t_short;
if (bt.isLong())
return t_long;
if (bt.isSigned())
return t_signed;
if (bt.isUnsigned())
return t_unsigned;
return t_int;
case eVoid:
return t_void;
case eWChar:
return t_wchar_t;
default:
break;
}
}
return t_unspecified;
} }
public IType getExpressionType() { @Deprecated
return new CPPBasicType(CPPBasicType.getKind(st), 0); public void setSimpleType(int value) {
CPPASTSimpleDeclSpecifier declspec = new CPPASTSimpleDeclSpecifier();
switch(value) {
case t_bool:
declspec.setType(Kind.eBoolean);
break;
case t_char:
declspec.setType(Kind.eChar);
break;
case t_double:
declspec.setType(Kind.eDouble);
break;
case t_float:
declspec.setType(Kind.eFloat);
break;
case t_int:
declspec.setType(Kind.eInt);
break;
case t_long:
declspec.setType(Kind.eInt);
declspec.setLong(true);
break;
case t_short:
declspec.setType(Kind.eInt);
declspec.setShort(true);
break;
case t_signed:
declspec.setType(Kind.eInt);
declspec.setSigned(true);
break;
case t_unsigned:
declspec.setType(Kind.eInt);
declspec.setUnsigned(true);
break;
case t_void:
declspec.setType(Kind.eVoid);
break;
case t_wchar_t:
declspec.setType(Kind.eWChar);
break;
default:
declspec.setType(Kind.eUnspecified);
break;
}
setDeclSpecifier(declspec);
}
@Deprecated
public IASTExpression getInitialValue() {
if (fInitializer instanceof ICPPASTConstructorInitializer) {
return ((ICPPASTConstructorInitializer) fInitializer).getExpression();
}
return null;
}
@Deprecated
public void setInitialValue(IASTExpression expression) {
ICPPASTConstructorInitializer init= new CPPASTConstructorInitializer();
init.setExpression(expression);
setInitializer(init);
} }
public boolean isLValue() {
return false;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,130 +11,63 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
public class CPPASTTypenameExpression extends ASTNode implements @Deprecated
ICPPASTTypenameExpression, IASTAmbiguityParent { public class CPPASTTypenameExpression extends CPPASTSimpleTypeConstructorExpression implements ICPPASTTypenameExpression {
private boolean isTemplate;
private IASTName name;
private IASTExpression init;
public CPPASTTypenameExpression() { public CPPASTTypenameExpression() {
} }
public CPPASTTypenameExpression(IASTName name, IASTExpression init) { public CPPASTTypenameExpression(IASTName name, IASTExpression expr) {
this(name, init, false);
}
public CPPASTTypenameExpression(IASTName name, IASTExpression init, boolean isTemplate) {
setName(name); setName(name);
setInitialValue(init); setInitialValue(expr);
this.isTemplate = isTemplate;
} }
@Override
public CPPASTTypenameExpression copy() { public CPPASTTypenameExpression copy() {
super.copy();
CPPASTTypenameExpression copy = new CPPASTTypenameExpression(); CPPASTTypenameExpression copy = new CPPASTTypenameExpression();
copy.setName(name == null ? null : name.copy()); ICPPASTDeclSpecifier declSpec = getDeclSpecifier();
copy.setInitialValue(init == null ? null : init.copy()); IASTInitializer init = getInitializer();
copy.isTemplate = isTemplate; copy.setDeclSpecifier(declSpec == null ? null : declSpec.copy());
copy.setInitializer(init == null ? null : init.copy());
copy.setOffsetAndLength(this); copy.setOffsetAndLength(this);
return copy; return copy;
} }
public void setIsTemplate(boolean templateTokenConsumed) {
assertNotFrozen();
isTemplate = templateTokenConsumed;
}
public boolean isTemplate() {
return isTemplate;
}
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen(); CPPASTNamedTypeSpecifier spec= new CPPASTNamedTypeSpecifier(name);
this.name = name; spec.setOffsetAndLength(this);
if (name != null) { setDeclSpecifier(spec);
name.setParent(this);
name.setPropertyInParent(TYPENAME);
}
} }
public IASTName getName() { public IASTName getName() {
return name; IASTDeclSpecifier spec= getDeclSpecifier();
if (spec instanceof ICPPASTNamedTypeSpecifier) {
return ((ICPPASTNamedTypeSpecifier) spec).getName();
}
return null;
} }
public void setInitialValue(IASTExpression expressionList) {
assertNotFrozen();
init = expressionList;
if (expressionList != null) {
expressionList.setParent(this);
expressionList.setPropertyInParent(INITIAL_VALUE);
}
}
public IASTExpression getInitialValue() {
return init;
}
@Override
public boolean accept( ASTVisitor action ){
if( action.shouldVisitExpressions ){
switch( action.visit( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
if( name != null ) if( !name.accept( action ) ) return false;
if( init != null ) if( !init.accept( action ) ) return false;
if( action.shouldVisitExpressions ){
switch( action.leave( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
return true;
}
public int getRoleForName(IASTName n) { public int getRoleForName(IASTName n) {
if( n == name ) if (n == getName())
return r_reference; return r_reference;
return r_unclear; return r_unclear;
} }
public void replace(IASTNode child, IASTNode other) { @Deprecated
if( child == init ) public void setIsTemplate(boolean val) {
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
init = (IASTExpression) other;
}
}
public IType getExpressionType() {
IBinding binding = getName().resolvePreBinding();
if (binding instanceof IType) {
return (IType) binding;
}
return null;
} }
public boolean isLValue() { @Deprecated
return false; public boolean isTemplate() {
} return false;
}
} }

View file

@ -25,12 +25,14 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNullStatement; import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
@ -55,6 +57,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
@ -68,7 +71,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
@ -95,7 +97,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
@ -121,32 +122,302 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return DEFAULT_INSTANCE; return DEFAULT_INSTANCE;
} }
public ICPPASTTranslationUnit newTranslationUnit() { public ICPPASTArrayDeclarator newArrayDeclarator(IASTName name) {
return newTranslationUnit(null); return new CPPASTArrayDeclarator(name);
} }
public ICPPASTTranslationUnit newTranslationUnit(IScanner scanner) { public IASTArrayModifier newArrayModifier(IASTExpression expr) {
CPPASTTranslationUnit tu = new CPPASTTranslationUnit(); return new CPPASTArrayModifier(expr);
if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver());
}
tu.setASTNodeFactory(this);
return tu;
} }
public IASTName newName(char[] name) { public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript) {
return new CPPASTName(name); return new CPPASTArraySubscriptExpression(arrayExpr, subscript);
} }
public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr,
IASTInitializerClause subscript) {
return new CPPASTArraySubscriptExpression(arrayExpr, subscript);
}
public IASTASMDeclaration newASMDeclaration(String assembly) {
return new CPPASTASMDeclaration(assembly);
}
public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual) {
return new CPPASTBaseSpecifier(name, visibility, isVirtual);
}
public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
return new CPPASTBinaryExpression(op, expr1, expr2);
}
public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTInitializerClause expr2) {
return new CPPASTBinaryExpression(op, expr1, expr2);
}
public IASTBreakStatement newBreakStatement() {
return new CPPASTBreakStatement();
}
public IASTCaseStatement newCaseStatement(IASTExpression expr) {
return new CPPASTCaseStatement(expr);
}
public ICPPASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand) {
return new CPPASTCastExpression(operator, typeId, operand);
}
public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body) {
return new CPPASTCatchHandler(decl, body);
}
public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
return new CPPASTCompositeTypeSpecifier(key, name);
}
public IASTCompoundStatement newCompoundStatement() {
return new CPPASTCompoundStatement();
}
public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3) {
return new CPPASTConditionalExpression(expr1, expr2, expr3);
}
@Deprecated
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName id, IASTExpression expression) {
ICPPASTConstructorChainInitializer result= new CPPASTConstructorChainInitializer(id, null);
result.setInitializerValue(expression);
return result;
}
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName id, IASTInitializer init) {
return new CPPASTConstructorChainInitializer(id, init);
}
@Deprecated
public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp) {
ICPPASTConstructorInitializer result= new CPPASTConstructorInitializer(null);
result.setExpression(exp);
return result;
}
public ICPPASTConstructorInitializer newConstructorInitializer(IASTInitializerClause[] args) {
return new CPPASTConstructorInitializer(args);
}
public IASTContinueStatement newContinueStatement() {
return new CPPASTContinueStatement();
}
public ICPPASTConversionName newConversionName(IASTTypeId typeId) {
return new CPPASTConversionName(typeId);
}
public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) {
return new CPPASTDeclarationStatement(declaration);
}
public ICPPASTDeclarator newDeclarator(IASTName name) {
return new CPPASTDeclarator(name);
}
public IASTDefaultStatement newDefaultStatement() {
return new CPPASTDefaultStatement();
}
public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand) {
return new CPPASTDeleteExpression(operand);
}
public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
return new CPPASTDoStatement(body, condition);
}
public ICPPASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
return new CPPASTElaboratedTypeSpecifier(kind, name);
}
public IASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
return new CPPASTEnumerationSpecifier(name);
}
public IASTEnumerator newEnumerator(IASTName name, IASTExpression value) {
return new CPPASTEnumerator(name, value);
}
public IASTEqualsInitializer newEqualsInitializer(IASTInitializerClause initClause) {
return new CPPASTEqualsInitializer(initClause);
}
public ICPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiation(IASTDeclaration declaration) {
return new CPPASTExplicitTemplateInstantiation(declaration);
}
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiationGPP(IASTDeclaration declaration) {
return new GPPASTExplicitTemplateInstantiation(declaration);
}
public ICPPASTExpressionList newExpressionList() {
return new CPPASTExpressionList();
}
public IASTExpressionStatement newExpressionStatement(IASTExpression expression) {
return new CPPASTExpressionStatement(expression);
}
public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) {
return new CPPASTFieldDeclarator(name, bitFieldSize);
}
public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
return new CPPASTFieldReference(name, owner);
}
public ICPPASTForStatement newForStatement() {
return new CPPASTForStatement();
}
public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition,
IASTExpression iterationExpression, IASTStatement body) {
return new CPPASTForStatement(init, condition, iterationExpression, body);
}
public ICPPASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpr, IASTStatement body) {
return new CPPASTForStatement(init, condition, iterationExpr, body);
}
@Deprecated
public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) {
CPPASTFunctionCallExpression result = new CPPASTFunctionCallExpression(idExpr, null);
result.setParameterExpression(argList);
return result;
}
public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTInitializerClause[] arguments) {
return new CPPASTFunctionCallExpression(idExpr, arguments);
}
public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name) {
return new CPPASTFunctionDeclarator(name);
}
public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
IASTStatement bodyStatement) {
return new CPPASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
}
public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
IASTStatement bodyStatement) {
return new CPPASTFunctionWithTryBlock(declSpecifier, declarator, bodyStatement);
}
public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
return new CPPASTCompoundStatementExpression(compoundStatement);
}
public IASTGotoStatement newGotoStatement(IASTName name) {
return new CPPASTGotoStatement(name);
}
public IASTIdExpression newIdExpression(IASTName name) {
return new CPPASTIdExpression(name);
}
public ICPPASTIfStatement newIfStatement() {
return new CPPASTIfStatement();
}
public ICPPASTIfStatement newIfStatement(IASTDeclaration condition, IASTStatement then, IASTStatement elseClause) {
return new CPPASTIfStatement(condition, then, elseClause);
}
public ICPPASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause) {
return new CPPASTIfStatement(condition, then, elseClause);
}
@Deprecated
public org.eclipse.cdt.core.dom.ast.IASTInitializerExpression newInitializerExpression(IASTExpression expression) {
return new CPPASTInitializerExpression(expression);
}
public ICPPASTInitializerList newInitializerList() {
return new CPPASTInitializerList();
}
public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement) {
return new CPPASTLabelStatement(name, nestedStatement);
}
public ICPPASTLinkageSpecification newLinkageSpecification(String literal) {
return new CPPASTLinkageSpecification(literal);
}
public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep) {
return new CPPASTLiteralExpression(kind, rep.toCharArray());
}
public IASTName newName() { public IASTName newName() {
return new CPPASTName(); return new CPPASTName();
} }
public IASTName newName(char[] name) {
return new CPPASTName(name);
}
public ICPPASTNamespaceAlias newNamespaceAlias(IASTName alias, IASTName qualifiedName) {
return new CPPASTNamespaceAlias(alias, qualifiedName);
}
public ICPPASTNamespaceDefinition newNamespaceDefinition(IASTName name) {
return new CPPASTNamespaceDefinition(name);
}
@Deprecated
public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, IASTTypeId typeId) {
final ICPPASTNewExpression result = new CPPASTNewExpression(null, null, typeId);
result.setNewPlacement(placement);
result.setNewInitializer(initializer);
return result;
}
public ICPPASTNewExpression newNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, IASTTypeId typeId) {
return new CPPASTNewExpression(placement, initializer, typeId);
}
public IASTNullStatement newNullStatement() {
return new CPPASTNullStatement();
}
public ICPPASTOperatorName newOperatorName(char[] name) { public ICPPASTOperatorName newOperatorName(char[] name) {
return new CPPASTOperatorName(name); return new CPPASTOperatorName(name);
} }
public ICPPASTPackExpansionExpression newPackExpansionExpression(IASTExpression pattern) {
return new CPPASTPackExpansionExpression(pattern);
}
public ICPPASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
return new CPPASTParameterDeclaration(declSpec, declarator);
}
public IASTPointer newPointer() {
return new CPPASTPointer();
}
public IGPPASTPointer newPointerGPP() {
return new GPPASTPointer();
}
public ICPPASTPointerToMember newPointerToMember(IASTName name) {
return new CPPASTPointerToMember(name);
}
public IGPPASTPointerToMember newPointerToMemberGPP(IASTName name) {
return new GPPASTPointerToMember(name);
}
public IASTProblem newProblem(int id, char[] arg, boolean error) { public IASTProblem newProblem(int id, char[] arg, boolean error) {
return new CPPASTProblem(id, arg, error); return new CPPASTProblem(id, arg, error);
} }
@ -163,215 +434,134 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return new CPPASTProblemStatement(problem); return new CPPASTProblemStatement(problem);
} }
public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep) { public IASTProblemTypeId newProblemTypeId(IASTProblem problem) {
return new CPPASTLiteralExpression(kind, rep.toCharArray()); return new CPPASTProblemTypeId(problem);
}
public ICPPASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
return new CPPASTUnaryExpression(operator, operand);
}
public IASTIdExpression newIdExpression(IASTName name) {
return new CPPASTIdExpression(name);
}
public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript) {
return new CPPASTArraySubscriptExpression(arrayExpr, subscript);
}
public ICPPASTExpressionList newExpressionList() {
return new CPPASTExpressionList();
}
public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) {
return new CPPASTFunctionCallExpression(idExpr, argList);
}
public ICPPASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand) {
return new CPPASTCastExpression(operator, typeId, operand);
}
public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, IASTTypeId typeId) {
return new CPPASTNewExpression(placement, initializer, typeId);
}
public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
return new CPPASTBinaryExpression(op, expr1, expr2);
}
public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3) {
return new CPPASTConditionalExpression(expr1, expr2, expr3);
}
public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
return new CPPASTTypeIdInitializerExpression(typeId, initializer);
}
public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
return new CPPASTFieldReference(name, owner);
}
public ICPPASTTemplateId newTemplateId(IASTName templateName) {
return new CPPASTTemplateId(templateName);
}
public ICPPASTConversionName newConversionName(IASTTypeId typeId) {
return new CPPASTConversionName(typeId);
} }
public ICPPASTQualifiedName newQualifiedName() { public ICPPASTQualifiedName newQualifiedName() {
return new CPPASTQualifiedName(); return new CPPASTQualifiedName();
} }
public IASTCaseStatement newCaseStatement(IASTExpression expr) { public ICPPASTReferenceOperator newReferenceOperator() {
return new CPPASTCaseStatement(expr); return new CPPASTReferenceOperator(false);
} }
public IASTDefaultStatement newDefaultStatement() { public ICPPASTReferenceOperator newReferenceOperator(boolean isRValueReference) {
return new CPPASTDefaultStatement(); return new CPPASTReferenceOperator(isRValueReference);
}
public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement) {
return new CPPASTLabelStatement(name, nestedStatement);
}
public IASTExpressionStatement newExpressionStatement(IASTExpression expression) {
return new CPPASTExpressionStatement(expression);
}
public IASTNullStatement newNullStatement() {
return new CPPASTNullStatement();
}
public IASTCompoundStatement newCompoundStatement() {
return new CPPASTCompoundStatement();
}
public ICPPASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause) {
return new CPPASTIfStatement(condition, then, elseClause);
}
public ICPPASTIfStatement newIfStatement(IASTDeclaration condition, IASTStatement then, IASTStatement elseClause) {
return new CPPASTIfStatement(condition, then, elseClause);
}
public ICPPASTIfStatement newIfStatement() {
return new CPPASTIfStatement();
}
public ICPPASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
return new CPPASTSwitchStatement(controller, body);
}
public ICPPASTSwitchStatement newSwitchStatement(IASTDeclaration controller, IASTStatement body) {
return new CPPASTSwitchStatement(controller, body);
}
public ICPPASTSwitchStatement newSwitchStatement() {
return new CPPASTSwitchStatement();
}
public ICPPASTWhileStatement newWhileStatement(IASTDeclaration condition, IASTStatement body) {
return new CPPASTWhileStatement(condition, body);
}
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
return new CPPASTWhileStatement(condition, body);
}
public ICPPASTWhileStatement newWhileStatement() {
return new CPPASTWhileStatement();
}
public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
return new CPPASTDoStatement(body, condition);
}
public IASTBreakStatement newBreakStatement() {
return new CPPASTBreakStatement();
}
public IASTContinueStatement newContinueStatement() {
return new CPPASTContinueStatement();
}
public IASTGotoStatement newGotoStatement(IASTName name) {
return new CPPASTGotoStatement(name);
} }
public IASTReturnStatement newReturnStatement(IASTExpression retValue) { public IASTReturnStatement newReturnStatement(IASTExpression retValue) {
return new CPPASTReturnStatement(retValue); return new CPPASTReturnStatement(retValue);
} }
public ICPPASTForStatement newForStatement(IASTStatement init, IASTExpression condition, public IASTReturnStatement newReturnStatement(IASTInitializerClause retValue) {
IASTExpression iterationExpr, IASTStatement body) { return new CPPASTReturnStatement(retValue);
return new CPPASTForStatement(init, condition, iterationExpr, body);
} }
public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition, public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
IASTExpression iterationExpression, IASTStatement body) { return new CPPASTSimpleDeclaration(declSpecifier);
return new CPPASTForStatement(init, condition, iterationExpression, body);
} }
public ICPPASTForStatement newForStatement() { public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
return new CPPASTForStatement(); return new CPPASTSimpleDeclSpecifier();
}
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP() {
return new GPPASTSimpleDeclSpecifier();
}
@Deprecated
public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(int type, IASTExpression expression) {
CPPASTSimpleTypeConstructorExpression result = new CPPASTSimpleTypeConstructorExpression();
result.setSimpleType(type);
result.setInitialValue(expression);
return result;
} }
public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) { public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(
return new CPPASTDeclarationStatement(declaration); ICPPASTDeclSpecifier declSpec, IASTInitializer initializer) {
return new CPPASTSimpleTypeConstructorExpression(declSpec, initializer);
} }
public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) { public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId) {
return new CPPASTTypeIdExpression(operator, typeId); return new CPPASTSimpleTypeTemplateParameter(type, name, typeId);
} }
public ICPPASTDeclarator newDeclarator(IASTName name) { public ICPPASTStaticAssertDeclaration newStaticAssertion(IASTExpression condition,
return new CPPASTDeclarator(name); ICPPASTLiteralExpression message) {
return new CPPASTStaticAssertionDeclaration(condition, message);
}
public ICPPASTSwitchStatement newSwitchStatement() {
return new CPPASTSwitchStatement();
}
public ICPPASTSwitchStatement newSwitchStatement(IASTDeclaration controller, IASTStatement body) {
return new CPPASTSwitchStatement(controller, body);
}
public ICPPASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
return new CPPASTSwitchStatement(controller, body);
}
public ICPPASTTemplateDeclaration newTemplateDeclaration(IASTDeclaration declaration) {
return new CPPASTTemplateDeclaration(declaration);
}
public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue) {
return new CPPASTTemplatedTypeTemplateParameter(name, defaultValue);
}
public ICPPASTTemplateId newTemplateId(IASTName templateName) {
return new CPPASTTemplateId(templateName);
}
public ICPPASTTemplateSpecialization newTemplateSpecialization(IASTDeclaration declaration) {
return new CPPASTTemplateSpecialization(declaration);
}
public ICPPASTTranslationUnit newTranslationUnit() {
return newTranslationUnit(null);
}
public ICPPASTTranslationUnit newTranslationUnit(IScanner scanner) {
CPPASTTranslationUnit tu = new CPPASTTranslationUnit();
if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver());
}
tu.setASTNodeFactory(this);
return tu;
}
public ICPPASTTryBlockStatement newTryBlockStatement(IASTStatement body) {
return new CPPASTTryBlockStatement(body);
}
public ICPPASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name) {
return new CPPASTNamedTypeSpecifier(name);
} }
public ICPPASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) { public ICPPASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
return new CPPASTTypeId(declSpecifier, declarator); return new CPPASTTypeId(declSpecifier, declarator);
} }
public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand) { public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
return new CPPASTDeleteExpression(operand); return new CPPASTTypeIdExpression(operator, typeId);
} }
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) { public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
return new CPPASTSimpleDeclaration(declSpecifier); return new CPPASTTypeIdInitializerExpression(typeId, initializer);
} }
public ICPPASTInitializerExpression newInitializerExpression(IASTExpression expression) { @Deprecated
return new CPPASTInitializerExpression(expression); public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, IASTExpression expr, boolean isTemplate) {
return new CPPASTTypenameExpression(qualifiedName, expr);
} }
public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, public ICPPASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
IASTStatement bodyStatement) { return new CPPASTUnaryExpression(operator, operand);
return new CPPASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
}
public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
return new CPPASTSimpleDeclSpecifier();
}
public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name) {
return new CPPASTFunctionDeclarator(name);
}
public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(int type, IASTExpression expression) {
return new CPPASTSimpleTypeConstructorExpression(type, expression);
}
public ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, IASTExpression expr, boolean isTemplate) {
return new CPPASTTypenameExpression(qualifiedName, expr, isTemplate);
}
public IASTASMDeclaration newASMDeclaration(String assembly) {
return new CPPASTASMDeclaration(assembly);
}
public ICPPASTNamespaceAlias newNamespaceAlias(IASTName alias, IASTName qualifiedName) {
return new CPPASTNamespaceAlias(alias, qualifiedName);
} }
public ICPPASTUsingDeclaration newUsingDeclaration(IASTName name) { public ICPPASTUsingDeclaration newUsingDeclaration(IASTName name) {
@ -382,156 +572,19 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return new CPPASTUsingDirective(name); return new CPPASTUsingDirective(name);
} }
public ICPPASTLinkageSpecification newLinkageSpecification(String literal) {
return new CPPASTLinkageSpecification(literal);
}
public ICPPASTNamespaceDefinition newNamespaceDefinition(IASTName name) {
return new CPPASTNamespaceDefinition(name);
}
public ICPPASTTemplateDeclaration newTemplateDeclaration(IASTDeclaration declaration) {
return new CPPASTTemplateDeclaration(declaration);
}
public ICPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiation(IASTDeclaration declaration) {
return new CPPASTExplicitTemplateInstantiation(declaration);
}
public ICPPASTTemplateSpecialization newTemplateSpecialization(IASTDeclaration declaration) {
return new CPPASTTemplateSpecialization(declaration);
}
public ICPPASTTryBlockStatement newTryBlockStatement(IASTStatement body) {
return new CPPASTTryBlockStatement(body);
}
public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body) {
return new CPPASTCatchHandler(decl, body);
}
public IASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
return new CPPASTEnumerationSpecifier(name);
}
public IASTEnumerator newEnumerator(IASTName name, IASTExpression value) {
return new CPPASTEnumerator(name, value);
}
public ICPPASTVisibilityLabel newVisibilityLabel(int visibility) { public ICPPASTVisibilityLabel newVisibilityLabel(int visibility) {
return new CPPASTVisibilityLabel(visibility); return new CPPASTVisibilityLabel(visibility);
} }
public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual) { public ICPPASTWhileStatement newWhileStatement() {
return new CPPASTBaseSpecifier(name, visibility, isVirtual); return new CPPASTWhileStatement();
} }
public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) { public ICPPASTWhileStatement newWhileStatement(IASTDeclaration condition, IASTStatement body) {
return new CPPASTCompositeTypeSpecifier(key, name); return new CPPASTWhileStatement(condition, body);
} }
public ICPPASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name) { public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
return new CPPASTNamedTypeSpecifier(name); return new CPPASTWhileStatement(condition, body);
} }
public ICPPASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
return new CPPASTElaboratedTypeSpecifier(kind, name);
}
public IASTPointer newPointer() {
return new CPPASTPointer();
}
public IGPPASTPointer newPointerGPP() {
return new GPPASTPointer();
}
public ICPPASTReferenceOperator newReferenceOperator() {
return new CPPASTReferenceOperator(false);
}
public ICPPASTReferenceOperator newReferenceOperator(boolean isRValueReference) {
return new CPPASTReferenceOperator(isRValueReference);
}
public ICPPASTPointerToMember newPointerToMember(IASTName name) {
return new CPPASTPointerToMember(name);
}
public IGPPASTPointerToMember newPointerToMemberGPP(IASTName name) {
return new GPPASTPointerToMember(name);
}
public ICPPASTInitializerList newInitializerList() {
return new CPPASTInitializerList();
}
public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp) {
return new CPPASTConstructorInitializer(exp);
}
public IASTArrayModifier newArrayModifier(IASTExpression expr) {
return new CPPASTArrayModifier(expr);
}
public ICPPASTArrayDeclarator newArrayDeclarator(IASTName name) {
return new CPPASTArrayDeclarator(name);
}
public ICPPASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
return new CPPASTParameterDeclaration(declSpec, declarator);
}
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName memberInitializerid, IASTExpression initializerValue) {
return new CPPASTConstructorChainInitializer(memberInitializerid, initializerValue);
}
public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
IASTStatement bodyStatement) {
return new CPPASTFunctionWithTryBlock(declSpecifier, declarator, bodyStatement);
}
public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) {
return new CPPASTFieldDeclarator(name, bitFieldSize);
}
public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId) {
return new CPPASTSimpleTypeTemplateParameter(type, name, typeId);
}
public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue) {
return new CPPASTTemplatedTypeTemplateParameter(name, defaultValue);
}
public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
return new CPPASTCompoundStatementExpression(compoundStatement);
}
public IASTProblemTypeId newProblemTypeId(IASTProblem problem) {
return new CPPASTProblemTypeId(problem);
}
public ICPPASTStaticAssertDeclaration newStaticAssertion(IASTExpression condition,
ICPPASTLiteralExpression message) {
return new CPPASTStaticAssertionDeclaration(condition, message);
}
public ICPPASTPackExpansionExpression newPackExpansionExpression(IASTExpression pattern) {
return new CPPASTPackExpansionExpression(pattern);
}
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP() {
return new GPPASTSimpleDeclSpecifier();
}
/**
* @deprecated Replaced by {@link #newExplicitTemplateInstantiation(IASTDeclaration)}.
*/
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiationGPP(IASTDeclaration declaration) {
return new GPPASTExplicitTemplateInstantiation(declaration);
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others. * Copyright (c) 2005, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -13,9 +13,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -51,8 +53,14 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
if (parent instanceof IASTDeclarator) { if (parent instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) parent; IASTDeclarator dtor = (IASTDeclarator) parent;
IASTInitializer initializer = dtor.getInitializer(); IASTInitializer initializer = dtor.getInitializer();
if (initializer instanceof IASTInitializerExpression) if (initializer instanceof IASTEqualsInitializer) {
return ((IASTInitializerExpression) initializer).getExpression(); IASTInitializerClause clause= ((IASTEqualsInitializer) initializer).getInitializerClause();
if (clause instanceof IASTExpression)
return (IASTExpression) clause;
if (clause instanceof IASTInitializerList) {
// mstodo handle braced init list
}
}
} }
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -26,7 +26,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
@ -117,8 +116,7 @@ public class CPPUnknownScope implements ICPPInternalUnknownScope {
} }
if (!type) { if (!type) {
if (parent instanceof ICPPASTBaseSpecifier || if (parent instanceof ICPPASTBaseSpecifier ||
parent instanceof ICPPASTConstructorChainInitializer || parent instanceof ICPPASTConstructorChainInitializer) {
parent instanceof ICPPASTTypenameExpression) {
type= true; type= true;
} else if (parent instanceof ICPPASTNamedTypeSpecifier) { } else if (parent instanceof ICPPASTNamedTypeSpecifier) {
ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) parent; ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) parent;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others. * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -17,9 +17,10 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@ -396,20 +397,25 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
IASTDeclarator dtor= findDeclarator(name); IASTDeclarator dtor= findDeclarator(name);
if (dtor != null) { if (dtor != null) {
IASTInitializer init= dtor.getInitializer(); IASTInitializer init= dtor.getInitializer();
if (init instanceof IASTInitializerExpression) { if (init != null) {
IASTExpression expr= ((IASTInitializerExpression) init).getExpression(); IASTInitializerClause clause= null;
if (expr != null) if (init instanceof IASTEqualsInitializer) {
return Value.create(expr, maxDepth); clause= ((IASTEqualsInitializer) init).getInitializerClause();
} else if (init instanceof ICPPASTConstructorInitializer) { } else if (init instanceof ICPPASTConstructorInitializer) {
IType type= SemanticUtil.getUltimateTypeUptoPointers(getType()); IASTInitializerClause[] args= ((ICPPASTConstructorInitializer) init).getArguments();
if (type instanceof IPointerType || type instanceof IBasicType) { if (args.length == 1 && args[0] instanceof IASTExpression) {
IASTExpression expr= ((ICPPASTConstructorInitializer) init).getExpression(); IType type= SemanticUtil.getUltimateTypeUptoPointers(getType());
if (expr != null) if (type instanceof IPointerType || type instanceof IBasicType) {
return Value.create(expr, maxDepth); clause= args[0];
}
}
} }
} if (clause instanceof IASTExpression) {
if (init != null) return Value.create((IASTExpression) clause, maxDepth);
}
// mstodo handle braced init list
return Value.UNKNOWN; return Value.UNKNOWN;
}
} }
return null; return null;
} }

View file

@ -41,15 +41,15 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -83,6 +83,7 @@ import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
@ -554,8 +555,8 @@ public class CPPSemantics {
} }
if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
parent = parent.getParent(); parent = parent.getParent();
IASTExpression exp = ((IASTFunctionCallExpression)parent).getParameterExpression(); IASTInitializerClause[] args = ((IASTFunctionCallExpression)parent).getArguments();
data.setFunctionArguments(exp); data.setFunctionArguments(args);
} }
} else if (parent instanceof ICPPASTFieldReference) { } else if (parent instanceof ICPPASTFieldReference) {
IASTNode grand= parent.getParent(); IASTNode grand= parent.getParent();
@ -565,20 +566,30 @@ public class CPPSemantics {
grand = grand.getParent(); grand = grand.getParent();
} }
if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
IASTExpression exp = ((IASTFunctionCallExpression)parent.getParent()).getParameterExpression(); IASTInitializerClause[] exp = ((IASTFunctionCallExpression)parent.getParent()).getArguments();
data.setFunctionArguments(exp); data.setFunctionArguments(exp);
} }
} else if (parent instanceof ICPPASTNamedTypeSpecifier && parent.getParent() instanceof IASTTypeId) { } else if (parent instanceof ICPPASTNamedTypeSpecifier && parent.getParent() instanceof IASTTypeId) {
IASTTypeId typeId = (IASTTypeId) parent.getParent(); IASTTypeId typeId = (IASTTypeId) parent.getParent();
if (typeId.getParent() instanceof ICPPASTNewExpression) { if (typeId.getParent() instanceof ICPPASTNewExpression) {
ICPPASTNewExpression newExp = (ICPPASTNewExpression) typeId.getParent(); ICPPASTNewExpression newExp = (ICPPASTNewExpression) typeId.getParent();
IASTExpression init = newExp.getNewInitializer(); IASTInitializer init = newExp.getInitializer();
data.setFunctionArguments(init); if (init == null) {
data.setFunctionArguments();
} else if (init instanceof ICPPASTConstructorInitializer) {
data.setFunctionArguments(((ICPPASTConstructorInitializer) init).getArguments());
} else {
// mstodo handle braced init list
}
} }
} else if (parent instanceof ICPPASTConstructorChainInitializer) { } else if (parent instanceof ICPPASTConstructorChainInitializer) {
ICPPASTConstructorChainInitializer ctorinit = (ICPPASTConstructorChainInitializer) parent; ICPPASTConstructorChainInitializer ctorinit = (ICPPASTConstructorChainInitializer) parent;
IASTExpression val = ctorinit.getInitializerValue(); IASTInitializer init = ctorinit.getInitializer();
data.setFunctionArguments(val); if (init instanceof ICPPASTConstructorInitializer) {
data.setFunctionArguments(((ICPPASTConstructorInitializer) init).getArguments());
} else {
// mstodo handle braced init list
}
} }
return data; return data;
@ -2350,8 +2361,8 @@ public class CPPSemantics {
// target is an object or reference being initialized // target is an object or reference being initialized
IASTDeclarator dtor = (IASTDeclarator) node.getParent(); IASTDeclarator dtor = (IASTDeclarator) node.getParent();
return CPPVisitor.createType(dtor); return CPPVisitor.createType(dtor);
} else if (prop == IASTInitializerExpression.INITIALIZER_EXPRESSION) { } else if (prop == IASTEqualsInitializer.INITIALIZER) {
IASTInitializerExpression initExp = (IASTInitializerExpression) node.getParent(); IASTEqualsInitializer initExp = (IASTEqualsInitializer) node.getParent();
if (initExp.getParent() instanceof IASTDeclarator) { if (initExp.getParent() instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) initExp.getParent(); IASTDeclarator dtor = (IASTDeclarator) initExp.getParent();
return CPPVisitor.createType(dtor); return CPPVisitor.createType(dtor);
@ -2363,30 +2374,24 @@ public class CPPSemantics {
IASTBinaryExpression binaryExp = (IASTBinaryExpression) node.getParent(); IASTBinaryExpression binaryExp = (IASTBinaryExpression) node.getParent();
IASTExpression exp = binaryExp.getOperand1(); IASTExpression exp = binaryExp.getOperand1();
return exp.getExpressionType(); return exp.getExpressionType();
} else if (prop == IASTFunctionCallExpression.PARAMETERS || } else if (prop == IASTFunctionCallExpression.ARGUMENT) {
(prop == IASTExpressionList.NESTED_EXPRESSION &&
node.getParent().getPropertyInParent() == IASTFunctionCallExpression.PARAMETERS)) {
// target is a parameter of a function // target is a parameter of a function
// if this function call refers to an overloaded function, there is more than one possibility // if this function call refers to an overloaded function, there is more than one possibility
// for the target type // for the target type
IASTFunctionCallExpression fnCall = null; IASTFunctionCallExpression fnCall = (IASTFunctionCallExpression) node.getParent();
int idx = -1; int idx = 0;
if (prop == IASTFunctionCallExpression.PARAMETERS) { final IASTInitializerClause[] arguments = fnCall.getArguments();
fnCall = (IASTFunctionCallExpression) node.getParent(); for (IASTInitializerClause arg : arguments) {
idx = 0; if (arg == node)
} else { break;
IASTExpressionList list = (IASTExpressionList) node.getParent(); idx++;
fnCall = (IASTFunctionCallExpression) list.getParent(); }
IASTExpression[] exps = list.getExpressions(); if (idx >= arguments.length)
for (int i = 0; i < exps.length; i++) { return null;
if (exps[i] == node) {
idx = i;
break;
}
}
}
IFunctionType[] types = getPossibleFunctions(fnCall); IFunctionType[] types = getPossibleFunctions(fnCall);
if (types == null) return null; if (types == null)
return null;
IType[] result = null; IType[] result = null;
for (int i = 0; i < types.length && types[i] != null; i++) { for (int i = 0; i < types.length && types[i] != null; i++) {
IType[] pts = null; IType[] pts = null;
@ -2596,21 +2601,13 @@ public class CPPSemantics {
public static ICPPFunction findOverloadedOperator(IASTFunctionCallExpression exp, ICPPClassType type) { public static ICPPFunction findOverloadedOperator(IASTFunctionCallExpression exp, ICPPClassType type) {
char[] name = OverloadableOperator.PAREN.toCharArray(); char[] name = OverloadableOperator.PAREN.toCharArray();
IASTExpression param = exp.getParameterExpression(); IASTInitializerClause[] args = exp.getArguments();
IASTExpression[] args; ArrayList<IASTInitializerClause> argsToPass = new ArrayList<IASTInitializerClause>(args.length + 1);
if (param instanceof IASTExpressionList) { argsToPass.add(exp.getFunctionNameExpression());
IASTExpression[] actualArgs = ((IASTExpressionList)param).getExpressions(); for (IASTInitializerClause e : args) {
ArrayList<IASTExpression> argsToPass = new ArrayList<IASTExpression>(actualArgs.length + 1); argsToPass.add(e);
argsToPass.add(exp.getFunctionNameExpression());
for (IASTExpression e : actualArgs) {
argsToPass.add(e);
}
args = argsToPass.toArray(new IASTExpression[argsToPass.size()]);
} else if (param != null) {
args = new IASTExpression[] { exp.getFunctionNameExpression(), param };
} else {
args = new IASTExpression[] { exp.getFunctionNameExpression() };
} }
args = argsToPass.toArray(new IASTInitializerClause[argsToPass.size()]);
return findOverloadedOperator(exp, args, type, name, NonMemberMode.none); return findOverloadedOperator(exp, args, type, name, NonMemberMode.none);
} }
@ -2627,17 +2624,15 @@ public class CPPSemantics {
IASTExpression sizeExpression = new CPPASTTypeIdExpression(IASTTypeIdExpression.op_sizeof, typeId); IASTExpression sizeExpression = new CPPASTTypeIdExpression(IASTTypeIdExpression.op_sizeof, typeId);
sizeExpression.setParent(exp); sizeExpression.setParent(exp);
IASTExpression placement = exp.getNewPlacement(); IASTInitializerClause[] placement = exp.getPlacementArguments();
List<IASTExpression> args = new ArrayList<IASTExpression>(); List<IASTInitializerClause> args = new ArrayList<IASTInitializerClause>();
args.add(sizeExpression); args.add(sizeExpression);
if (placement instanceof IASTExpressionList) { if (placement != null) {
for (IASTExpression p : ((IASTExpressionList) placement).getExpressions()) for (IASTInitializerClause p : placement) {
args.add(p); args.add(p);
} else if (placement != null) { }
args.add(placement); }
} IASTInitializerClause[] argArray = args.toArray(new IASTInitializerClause[args.size()]);
IASTExpression[] argArray = args.toArray(new IASTExpression[args.size()]);
return findOverloadedOperator(exp, argArray, type, op.toCharArray(), NonMemberMode.all); return findOverloadedOperator(exp, argArray, type, op.toCharArray(), NonMemberMode.all);
} }
@ -2758,7 +2753,7 @@ public class CPPSemantics {
} }
enum NonMemberMode {none, limited, all} enum NonMemberMode {none, limited, all}
private static ICPPFunction findOverloadedOperator(IASTExpression parent, IASTExpression[] args, IType methodLookupType, private static ICPPFunction findOverloadedOperator(IASTExpression parent, IASTInitializerClause[] args, IType methodLookupType,
char[] operatorName, NonMemberMode mode) { char[] operatorName, NonMemberMode mode) {
ICPPClassType callToObjectOfClassType= null; ICPPClassType callToObjectOfClassType= null;
@ -2820,7 +2815,10 @@ public class CPPSemantics {
// 13.3.1.2.3 // 13.3.1.2.3
// However, if no operand type has class type, only those non-member functions ... // However, if no operand type has class type, only those non-member functions ...
if (mode == NonMemberMode.limited) { if (mode == NonMemberMode.limited) {
IType type2= args.length < 2 ? null : getUltimateTypeUptoPointers(args[1].getExpressionType()); IType type2= null;
if (args.length >= 2 && args[1] instanceof IASTExpression) {
type2= getUltimateTypeUptoPointers(((IASTExpression) args[1]).getExpressionType());
}
if (funcData.foundItems != null && !(methodLookupType instanceof ICPPClassType) && !(type2 instanceof ICPPClassType)) { if (funcData.foundItems != null && !(methodLookupType instanceof ICPPClassType) && !(type2 instanceof ICPPClassType)) {
IEnumeration enum1= null; IEnumeration enum1= null;
IEnumeration enum2= null; IEnumeration enum2= null;

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
@ -39,7 +40,6 @@ import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -56,7 +56,6 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
@ -106,7 +105,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
@ -817,26 +815,37 @@ public class CPPVisitor extends ASTQueries {
} else if (parent instanceof ICPPASTTemplateDeclaration) { } else if (parent instanceof ICPPASTTemplateDeclaration) {
return CPPTemplates.getContainingScope(node); return CPPTemplates.getContainingScope(node);
} }
} else if (node instanceof IASTInitializerExpression) { } else if (node instanceof IASTInitializer) {
IASTNode parent = node.getParent(); if (node instanceof ICPPASTConstructorChainInitializer) {
while (!(parent instanceof IASTDeclarator || parent instanceof IASTTypeIdInitializerExpression)) // The name of the member initializer is resolved in the scope of the
parent = parent.getParent(); // owner of the ctor.
if(parent instanceof IASTDeclarator) { ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) node;
IASTDeclarator dtor = (IASTDeclarator) parent; IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent();
IASTName name = dtor.getName(); IBinding binding = fdef.getDeclarator().getName().resolveBinding();
if (name instanceof ICPPASTQualifiedName) { try {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames(); return binding.getScope();
return getContainingScope(ns[ns.length - 1]); } catch (DOMException e) {
} }
} else {
IASTNode parent = node.getParent();
if (parent instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) parent;
IASTName name = dtor.getName();
if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
return getContainingScope(ns[ns.length - 1]);
}
} else if (parent instanceof ICPPASTConstructorChainInitializer) {
// The initializer for the member initializer is resolved in
// the body of the ctor.
IASTNode temp = getContainingBlockItem(node);
if (temp instanceof IASTFunctionDefinition) {
IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)temp).getBody();
return body.getScope();
}
node= parent;
}
} }
} else if (node instanceof ICPPASTConstructorChainInitializer) {
ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) node;
IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent();
IBinding binding = fdef.getDeclarator().getName().resolveBinding();
try {
return binding.getScope();
} catch (DOMException e) {
}
} else if (node instanceof IASTExpression) { } else if (node instanceof IASTExpression) {
IASTNode parent = node.getParent(); IASTNode parent = node.getParent();
if (parent instanceof IASTForStatement) { if (parent instanceof IASTForStatement) {
@ -849,27 +858,21 @@ public class CPPVisitor extends ASTQueries {
return ((ICPPASTWhileStatement) parent).getScope(); return ((ICPPASTWhileStatement) parent).getScope();
} else if (parent instanceof IASTCompoundStatement) { } else if (parent instanceof IASTCompoundStatement) {
return ((IASTCompoundStatement) parent).getScope(); return ((IASTCompoundStatement) parent).getScope();
} else if (parent instanceof ICPPASTConstructorChainInitializer) { } else if (parent instanceof IASTArrayModifier) {
IASTNode temp = getContainingBlockItem(parent);
if (temp instanceof IASTFunctionDefinition) {
IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)temp).getBody();
return body.getScope();
}
} else if (parent instanceof IASTArrayModifier || parent instanceof IASTInitializer) {
IASTNode d = parent.getParent(); IASTNode d = parent.getParent();
while (!(d instanceof IASTDeclarator || d instanceof IASTTypeIdInitializerExpression)) { while (!(d instanceof IASTDeclarator || d instanceof IASTExpression)) {
d = d.getParent(); d = d.getParent();
} }
if(d instanceof IASTDeclarator) { if (d instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) d; IASTDeclarator dtor = (IASTDeclarator) d;
while (dtor.getNestedDeclarator() != null) while (dtor.getNestedDeclarator() != null)
dtor = dtor.getNestedDeclarator(); dtor = dtor.getNestedDeclarator();
IASTName name = dtor.getName(); IASTName name = dtor.getName();
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames(); IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
return getContainingScope(ns[ns.length - 1]); return getContainingScope(ns[ns.length - 1]);
} }
} }
} else if (parent instanceof ICPPASTTemplateId && } else if (parent instanceof ICPPASTTemplateId &&
node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
node= parent; // template-id node= parent; // template-id
@ -1433,7 +1436,6 @@ public class CPPVisitor extends ASTQueries {
case KIND_COMPOSITE: case KIND_COMPOSITE:
if (prop == IASTNamedTypeSpecifier.NAME || if (prop == IASTNamedTypeSpecifier.NAME ||
prop == ICPPASTPointerToMember.NAME || prop == ICPPASTPointerToMember.NAME ||
prop == ICPPASTTypenameExpression.TYPENAME ||
prop == ICPPASTUsingDeclaration.NAME || prop == ICPPASTUsingDeclaration.NAME ||
prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME || prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME ||
prop == ICPPASTTemplateId.TEMPLATE_NAME || prop == ICPPASTTemplateId.TEMPLATE_NAME ||
@ -1707,13 +1709,16 @@ public class CPPVisitor extends ASTQueries {
type = createType(type, declarator); type = createType(type, declarator);
// C++ specification 8.3.4.3 and 8.5.1.4 // C++ specification 8.3.4.3 and 8.5.1.4
IASTInitializer initializer= declarator.getInitializer(); IASTNode initClause= declarator.getInitializer();
if (initializer instanceof IASTInitializerList) { if (initClause instanceof IASTEqualsInitializer) {
initClause= ((IASTEqualsInitializer) initClause).getInitializerClause();
}
if (initClause instanceof IASTInitializerList) {
IType t= SemanticUtil.getNestedType(type, TDEF); IType t= SemanticUtil.getNestedType(type, TDEF);
if (t instanceof IArrayType) { if (t instanceof IArrayType) {
IArrayType at= (IArrayType) t; IArrayType at= (IArrayType) t;
if (at.getSize() == null) { if (at.getSize() == null) {
type= new CPPArrayType(at.getType(), Value.create(((IASTInitializerList) initializer).getSize())); type= new CPPArrayType(at.getType(), Value.create(((IASTInitializerList) initClause).getSize()));
} }
} }
} }

View file

@ -27,12 +27,12 @@ import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -556,25 +556,7 @@ public class LookupData {
return false; return false;
} }
public void setFunctionArguments(IASTExpression args) { public void setFunctionArguments(IASTInitializerClause... exprs) {
IASTExpression[] exprs;
if (args instanceof IASTExpressionList) {
ASTNodeProperty prop = args.getPropertyInParent();
if (prop == IASTFunctionCallExpression.PARAMETERS || prop == ICPPASTNewExpression.NEW_INITIALIZER
|| prop == ICPPASTConstructorChainInitializer.INITIALIZER) {
exprs= ((IASTExpressionList) args).getExpressions();
} else {
exprs= new IASTExpression[] {args};
}
} else if (args != null) {
exprs= new IASTExpression[] { args };
} else {
exprs = IASTExpression.EMPTY_EXPRESSION_ARRAY;
}
setFunctionArguments(exprs);
}
public void setFunctionArguments(IASTExpression... exprs) {
functionArgs= exprs; functionArgs= exprs;
if (exprs.length != 0) { if (exprs.length != 0) {
IASTNode node= exprs[0]; IASTNode node= exprs[0];
@ -607,13 +589,17 @@ public class LookupData {
functionArgTypes[i] = SemanticUtil.getSimplifiedType(CPPVisitor.createParameterType( functionArgTypes[i] = SemanticUtil.getSimplifiedType(CPPVisitor.createParameterType(
pdecls[i], true)); pdecls[i], true));
} }
} else if (functionArgs instanceof IASTExpression[]) { } else if (functionArgs instanceof IASTInitializerClause[]) {
IASTExpression[] exprs= (IASTExpression[]) functionArgs; IASTInitializerClause[] exprs= (IASTInitializerClause[]) functionArgs;
functionArgTypes= new IType[exprs.length]; functionArgTypes= new IType[exprs.length];
for (int i = 0; i < exprs.length; i++) { for (int i = 0; i < exprs.length; i++) {
IASTExpression e = exprs[i]; IASTInitializerClause e = exprs[i];
IType etype= e.getExpressionType(); if (e instanceof IASTExpression) {
functionArgTypes[i]= SemanticUtil.getSimplifiedType(etype); IType etype= ((IASTExpression) e).getExpressionType();
functionArgTypes[i]= SemanticUtil.getSimplifiedType(etype);
} else {
// mstodo handle braced init list
}
} }
} }
} }
@ -623,12 +609,14 @@ public class LookupData {
public BitSet getFunctionArgumentLValues() { public BitSet getFunctionArgumentLValues() {
if (functionArgLValues == null) { if (functionArgLValues == null) {
functionArgLValues= new BitSet(); functionArgLValues= new BitSet();
IASTExpression[] args= getFunctionArguments(); IASTInitializerClause[] args= getFunctionArguments();
if (args != null) { if (args != null) {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
final IASTExpression arg = args[i]; final IASTInitializerClause arg = args[i];
if (arg != null) { if (arg instanceof IASTExpression) {
functionArgLValues.set(i, arg.isLValue()); functionArgLValues.set(i, ((IASTExpression) arg).isLValue());
} else {
// mstodo handle braced init list
} }
} }
} else { } else {
@ -653,9 +641,9 @@ public class LookupData {
functionArgs= parameters; functionArgs= parameters;
} }
public IASTExpression[] getFunctionArguments() { public IASTInitializerClause[] getFunctionArguments() {
if (functionArgs instanceof IASTExpression[]) if (functionArgs instanceof IASTInitializerClause[])
return (IASTExpression[]) functionArgs; return (IASTInitializerClause[]) functionArgs;
return null; return null;
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -27,7 +27,6 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
@ -81,9 +80,6 @@ public class DeclaratorWriter extends NodeWriter {
name.accept(visitor); name.accept(visitor);
IASTInitializer init = getInitializer(declarator); IASTInitializer init = getInitializer(declarator);
if(init!= null) { if(init!= null) {
if (! (init instanceof ICPPASTConstructorInitializer)) {
scribe.print(EQUALS);
}
init.accept(visitor); init.accept(visitor);
} }
} }
@ -109,7 +105,6 @@ public class DeclaratorWriter extends NodeWriter {
private void writeInitializer(IASTStandardFunctionDeclarator funcDec) { private void writeInitializer(IASTStandardFunctionDeclarator funcDec) {
IASTInitializer init = getInitializer(funcDec); IASTInitializer init = getInitializer(funcDec);
if(init != null) { if(init != null) {
scribe.print(EQUALS);
init.accept(visitor); init.accept(visitor);
} }
} }
@ -219,7 +214,6 @@ public class DeclaratorWriter extends NodeWriter {
writeArrayModifiers(arrDecl, arrMods); writeArrayModifiers(arrDecl, arrMods);
IASTInitializer initializer = getInitializer(arrDecl); IASTInitializer initializer = getInitializer(arrDecl);
if(initializer != null) { if(initializer != null) {
scribe.print(EQUALS);
initializer.accept(visitor); initializer.accept(visitor);
} }
} }
@ -253,7 +247,6 @@ public class DeclaratorWriter extends NodeWriter {
fieldDecl.getBitFieldSize().accept(visitor); fieldDecl.getBitFieldSize().accept(visitor);
IASTInitializer initializer = getInitializer(fieldDecl); IASTInitializer initializer = getInitializer(fieldDecl);
if(initializer != null) { if(initializer != null) {
scribe.print(EQUALS);
initializer.accept(visitor); initializer.accept(visitor);
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -12,8 +12,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
@ -43,8 +44,8 @@ public class InitializerWriter extends NodeWriter{
} }
protected void writeInitializer(IASTInitializer initializer) { protected void writeInitializer(IASTInitializer initializer) {
if (initializer instanceof IASTInitializerExpression) { if (initializer instanceof IASTEqualsInitializer) {
((IASTInitializerExpression) initializer).getExpression().accept(visitor); writeEqualsInitializer((IASTEqualsInitializer) initializer);
}else if (initializer instanceof IASTInitializerList) { }else if (initializer instanceof IASTInitializerList) {
writeInitializerList((IASTInitializerList) initializer); writeInitializerList((IASTInitializerList) initializer);
}else if (initializer instanceof ICPPASTConstructorInitializer) { }else if (initializer instanceof ICPPASTConstructorInitializer) {
@ -59,23 +60,29 @@ public class InitializerWriter extends NodeWriter{
} }
private void writeEqualsInitializer(IASTEqualsInitializer initializer) {
scribe.print(EQUALS);
IASTInitializerClause init = initializer.getInitializerClause();
if (init != null) {
init.accept(visitor);
}
}
private void writeConstructorChainInitializer(ICPPASTConstructorChainInitializer initializer) { private void writeConstructorChainInitializer(ICPPASTConstructorChainInitializer initializer) {
initializer.getMemberInitializerId().accept(visitor); initializer.getMemberInitializerId().accept(visitor);
scribe.print('('); initializer.getInitializer().accept(visitor);
initializer.getInitializerValue().accept(visitor);
scribe.print(')');
} }
private void writeInitializerList(IASTInitializerList initList) { private void writeInitializerList(IASTInitializerList initList) {
scribe.printLBrace(); scribe.printLBrace();
IASTInitializer[] inits = initList.getInitializers(); IASTInitializerClause[] inits = initList.getClauses();
writeNodeList(inits); writeNodeList(inits);
scribe.printRBrace(); scribe.printRBrace();
} }
private void writeConstructorInitializer(ICPPASTConstructorInitializer ctorInit) { private void writeConstructorInitializer(ICPPASTConstructorInitializer ctorInit) {
scribe.print('('); scribe.print('(');
ctorInit.getExpression().accept(visitor); writeNodeList(ctorInit.getArguments());
scribe.print(')'); scribe.print(')');
} }
@ -85,7 +92,7 @@ public class InitializerWriter extends NodeWriter{
writeDesignator(designator); writeDesignator(designator);
} }
scribe.print(EQUALS); scribe.print(EQUALS);
desigInit.getOperandInitializer().accept(visitor); desigInit.getOperand().accept(visitor);
} }
private void writeDesignator(ICASTDesignator designator) { private void writeDesignator(ICASTDesignator designator) {

View file

@ -40,6 +40,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -53,7 +54,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -408,8 +409,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (!startNode(node)) { return PROCESS_SKIP; } if (!startNode(node)) { return PROCESS_SKIP; }
try { try {
if (node instanceof IASTInitializerExpression) { if (node instanceof IASTEqualsInitializer) {
visit((IASTInitializerExpression)node); visit((IASTEqualsInitializer) node);
} else if (node instanceof IASTInitializerList) { } else if (node instanceof IASTInitializerList) {
visit((IASTInitializerList)node); visit((IASTInitializerList)node);
} else if (node instanceof ICASTDesignatedInitializer) { } else if (node instanceof ICASTDesignatedInitializer) {
@ -956,7 +957,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (!startNode(node)) { return PROCESS_SKIP; } if (!startNode(node)) { return PROCESS_SKIP; }
try { try {
// format like a function call // format like a function call
formatFunctionCallArguments(node.getExpression()); formatFunctionCallArguments(node.getArguments());
} finally { } finally {
endOfNode(node); endOfNode(node);
} }
@ -965,10 +966,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(ICPPASTConstructorChainInitializer node) { private int visit(ICPPASTConstructorChainInitializer node) {
final IASTName member= node.getMemberInitializerId(); final IASTName member= node.getMemberInitializerId();
if (member!= null) { final IASTInitializer init= node.getInitializer();
if (member!= null && init != null) {
member.accept(this); member.accept(this);
// format like a function call init.accept(this);
formatFunctionCallArguments(node.getInitializerValue());
} else { } else {
formatRaw(node); formatRaw(node);
} }
@ -1825,9 +1826,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(IASTFunctionCallExpression node) { private int visit(IASTFunctionCallExpression node) {
node.getFunctionNameExpression().accept(this); node.getFunctionNameExpression().accept(this);
IASTExpression paramExpr= node.getParameterExpression(); IASTInitializerClause[] paramExpr= node.getArguments();
if (peekNextToken() == Token.tIDENTIFIER) { if (peekNextToken() == Token.tIDENTIFIER) {
skipNode(paramExpr); skipNode(node);
} else { } else {
formatFunctionCallArguments(paramExpr); formatFunctionCallArguments(paramExpr);
} }
@ -1839,17 +1840,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
* *
* @param argumentExpr the argument expression, may be <code>null</code> * @param argumentExpr the argument expression, may be <code>null</code>
*/ */
private void formatFunctionCallArguments(IASTExpression argumentExpr) { private void formatFunctionCallArguments(IASTInitializerClause[] args) {
final List<IASTExpression> expressions; final List<IASTInitializerClause> expressions;
if (argumentExpr != null) { if (args != null) {
if (argumentExpr instanceof IASTExpressionList) { expressions= Arrays.asList(args);
// argument list
final IASTExpressionList exprList= (IASTExpressionList)argumentExpr;
expressions= Arrays.asList(exprList.getExpressions());
} else {
// single argument
expressions= Collections.singletonList(argumentExpr);
}
} else { } else {
// no arguments // no arguments
expressions= Collections.emptyList(); expressions= Collections.emptyList();
@ -1941,10 +1935,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int visit(IASTInitializerExpression node) { private int visit(IASTEqualsInitializer node) {
if (node.getPropertyInParent() == IASTInitializerList.NESTED_INITIALIZER) { if (node.getPropertyInParent() == IASTInitializerList.NESTED_INITIALIZER) {
assert false;
// nested initializer expression, no need to apply extra alignment // nested initializer expression, no need to apply extra alignment
node.getExpression().accept(this); // node.getExpression().accept(this);
} else { } else {
// declaration initializer // declaration initializer
Alignment expressionAlignment= scribe.createAlignment( Alignment expressionAlignment= scribe.createAlignment(
@ -1960,7 +1955,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
try { try {
scribe.alignFragment(expressionAlignment, 0); scribe.alignFragment(expressionAlignment, 0);
node.getExpression().accept(this); node.getInitializerClause().accept(this);
ok = true; ok = true;
} catch (AlignmentException e) { } catch (AlignmentException e) {
@ -1975,7 +1970,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(IASTInitializerList node) { private int visit(IASTInitializerList node) {
scribe.printComment(); scribe.printComment();
final List<IASTInitializer> initializers = Arrays.asList(node.getInitializers()); final List<IASTInitializerClause> initializers = Arrays.asList(node.getClauses());
if (initializers.isEmpty() && preferences.keep_empty_initializer_list_on_one_line) { if (initializers.isEmpty() && preferences.keep_empty_initializer_list_on_one_line) {
scribe.printNextToken(Token.tLBRACE, preferences.insert_space_before_opening_brace_in_initializer_list); scribe.printNextToken(Token.tLBRACE, preferences.insert_space_before_opening_brace_in_initializer_list);
scribe.printNextToken(Token.tRBRACE, preferences.insert_space_between_empty_braces_in_initializer_list); scribe.printNextToken(Token.tRBRACE, preferences.insert_space_between_empty_braces_in_initializer_list);
@ -2071,7 +2066,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
operand.accept(this); operand.accept(this);
break; break;
case IASTUnaryExpression.op_typeof:
case IASTUnaryExpression.op_alignOf: case IASTUnaryExpression.op_alignOf:
default: default:
int operatorToken= peekNextToken(); int operatorToken= peekNextToken();
@ -2277,9 +2271,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.space(); scribe.space();
// placement // placement
final IASTExpression newPlacement= node.getNewPlacement(); final IASTInitializerClause[] newPlacement= node.getPlacementArguments();
if (newPlacement != null) { if (newPlacement != null) {
formatParenthesizedExpression(newPlacement); formatFunctionCallArguments(newPlacement);
} }
// type-id // type-id
@ -2295,9 +2289,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
// initializer // initializer
final IASTExpression newInitializer= node.getNewInitializer(); final IASTInitializer newInitializer= node.getInitializer();
if (newInitializer != null || peekNextToken() == Token.tLPAREN) { if (newInitializer != null) {
formatFunctionCallArguments(newInitializer); visit(newInitializer);
} }
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -2324,6 +2318,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
private int visit(ICPPASTSimpleTypeConstructorExpression node) { private int visit(ICPPASTSimpleTypeConstructorExpression node) {
// tletodo The first part of the expression can consist of multiple tokens
scribe.printNextToken(peekNextToken()); scribe.printNextToken(peekNextToken());
final IASTExpression operand= node.getInitialValue(); final IASTExpression operand= node.getInitialValue();
formatParenthesizedExpression(operand); formatParenthesizedExpression(operand);

View file

@ -118,7 +118,6 @@ public class MachOParser64 extends AbstractCExtension implements IBinaryParser {
return cppfilt; return cppfilt;
} }
@SuppressWarnings("deprecation")
protected IPath getCPPFiltPath() { protected IPath getCPPFiltPath() {
ICConfigExtensionReference ref = getConfigExtensionReference(); ICConfigExtensionReference ref = getConfigExtensionReference();
String value = ref.getExtensionData("c++filt"); //$NON-NLS-1$ String value = ref.getExtensionData("c++filt"); //$NON-NLS-1$

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -33,9 +33,9 @@ import org.eclipse.text.edits.TextEditGroup;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation; import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -52,8 +52,8 @@ import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTInitializerExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
@ -373,12 +373,12 @@ public class ExtractConstantRefactoring extends CRefactoring {
declSpec.setType(IASTSimpleDeclSpecifier.t_int); declSpec.setType(IASTSimpleDeclSpecifier.t_int);
break; break;
case IASTLiteralExpression.lk_string_literal: case IASTLiteralExpression.lk_string_literal:
declSpec.setType(ICPPASTSimpleDeclSpecifier.t_wchar_t); declSpec.setType(IASTSimpleDeclSpecifier.t_wchar_t);
break; break;
case IASTLiteralExpression.lk_false: case IASTLiteralExpression.lk_false:
//Like lk_true a boolean type //Like lk_true a boolean type
case IASTLiteralExpression.lk_true: case IASTLiteralExpression.lk_true:
declSpec.setType(ICPPASTSimpleDeclSpecifier.t_bool); declSpec.setType(IASTSimpleDeclSpecifier.t_bool);
break; break;
case IASTLiteralExpression.lk_this: case IASTLiteralExpression.lk_this:
break; break;
@ -390,13 +390,13 @@ public class ExtractConstantRefactoring extends CRefactoring {
IASTDeclarator decl = new CPPASTDeclarator(); IASTDeclarator decl = new CPPASTDeclarator();
IASTName name = new CPPASTName(newName.toCharArray()); IASTName name = new CPPASTName(newName.toCharArray());
decl.setName(name); decl.setName(name);
IASTInitializerExpression init = new CPPASTInitializerExpression(); IASTEqualsInitializer init = new CPPASTEqualsInitializer();
if (target.getParent() instanceof IASTUnaryExpression) { if (target.getParent() instanceof IASTUnaryExpression) {
IASTUnaryExpression unary = (IASTUnaryExpression) target.getParent(); IASTUnaryExpression unary = (IASTUnaryExpression) target.getParent();
init.setExpression(unary); init.setInitializerClause(unary);
} else { } else {
CPPASTLiteralExpression expression = new CPPASTLiteralExpression(target.getKind(), target.getValue()); CPPASTLiteralExpression expression = new CPPASTLiteralExpression(target.getKind(), target.getValue());
init.setExpression(expression); init.setInitializerClause(expression);
} }
decl.setInitializer(init); decl.setInitializer(init);
simple.addDeclarator(decl); simple.addDeclarator(decl);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -49,7 +50,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -85,12 +85,12 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionList; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionList;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTInitializerExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement;
@ -831,8 +831,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
declarator.addPointerOperator(pointer.copy()); declarator.addPointerOperator(pointer.copy());
} }
IASTInitializerExpression initializer = new CPPASTInitializerExpression(); IASTEqualsInitializer initializer = new CPPASTEqualsInitializer();
initializer.setExpression(callExpression); initializer.setInitializerClause(callExpression);
declarator.setInitializer(initializer); declarator.setInitializer(initializer);
decl.addDeclarator(declarator); decl.addDeclarator(declarator);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 Google and others. All rights reserved. This program and * Copyright (c) 2008, 2010 Google and others. All rights reserved. This program and
* the accompanying materials are made available under the terms of the Eclipse * the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at * Public License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
@ -32,11 +32,11 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -52,8 +52,8 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTInitializerExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
@ -308,8 +308,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
IASTName name = new CPPASTName(newName.toCharArray()); IASTName name = new CPPASTName(newName.toCharArray());
decl.setName(name); decl.setName(name);
IASTInitializerExpression init = new CPPASTInitializerExpression(); IASTEqualsInitializer init = new CPPASTEqualsInitializer();
init.setExpression(deblock(target.copy())); init.setInitializerClause(deblock(target.copy()));
decl.setInitializer(init); decl.setInitializer(init);
simple.addDeclarator(decl); simple.addDeclarator(decl);