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
* are made available under the terms of the Eclipse Public License v1.0
* 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 {
private static Set<String> methodsToIgnore = new HashSet<String>(Arrays.asList(
// prevent infinite recursion
// Prevent infinite recursion
"getParent",
"getTranslationUnit",
"getLastName",
// original is usually frozen but copy must not be
"isFrozen",
// these methods are problematic
// Exponential complexity
"getOperand2", // duplicates getInitOperand2()
"getChildren",
"getProblem",
// Can be different in copy
"isFrozen",
"getContainingFilename",
// ignore preprocessor nodes
// These methods are problematic
"getProblem",
// Ignore preprocessor nodes
"getMacroDefinitions",
"getBuiltinMacroDefinitions",
"getIncludeDirectives",
@ -45,7 +51,8 @@ public class ASTComparer extends Assert {
"getMacroExpansions",
"getPreprocessorProblems",
"getComments",
// avoid name resolution
// Avoid name resolution
"isDeclaration",
"isDefinition",
"isReference",
@ -86,6 +93,9 @@ public class ASTComparer extends Assert {
if(methodsToIgnore.contains(getter.getName()))
continue;
if (getter.getAnnotation(Deprecated.class) != null)
continue;
try {
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTImplicitName;
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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
@ -356,6 +357,11 @@ public class AST2BaseTest extends BaseTestCase {
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) {
String expressionString = ASTSignatureUtil.getExpressionString(exp);
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.IASTDeclarator;
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.IASTExpressionList;
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.IASTIdExpression;
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.IASTLiteralExpression;
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$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
IASTSimpleDeclaration x = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTInitializerExpression e = (IASTInitializerExpression) x
.getDeclarators()[0].getInitializer();
IASTIdExpression id = (IASTIdExpression) e.getExpression();
IASTEqualsInitializer e = (IASTEqualsInitializer) x.getDeclarators()[0].getInitializer();
IASTIdExpression id = (IASTIdExpression) e.getInitializerClause();
ICPPASTQualifiedName name = (ICPPASTQualifiedName) id.getName();
assertTrue(name.isFullyQualified());
assertEquals(name.getNames().length, 3);
@ -4435,10 +4434,10 @@ public class AST2CPPTests extends AST2BaseTest {
// }
public void testBug84466() throws Exception {
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])
.getDeclaration()).getDeclarators()[0].getInitializer())
.getExpression();
.getInitializerClause();
assertEquals(dynamic_cast.getOperator(),
ICPPASTCastExpression.op_dynamic_cast);
@ -5580,8 +5579,8 @@ public class AST2CPPTests extends AST2BaseTest {
public void testLongLiteral_225534() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
IASTDeclarator decltor= ((IASTSimpleDeclaration)tu.getDeclarations()[0]).getDeclarators()[0];
IASTInitializerExpression init= (IASTInitializerExpression) decltor.getInitializer();
ICPPASTLiteralExpression exp= (ICPPASTLiteralExpression) init.getExpression();
IASTEqualsInitializer init= (IASTEqualsInitializer) decltor.getInitializer();
ICPPASTLiteralExpression exp= (ICPPASTLiteralExpression) init.getInitializerClause();
ICPPBasicType type= (ICPPBasicType) exp.getExpressionType();
assertTrue(type.isLong());
}
@ -8045,5 +8044,38 @@ public class AST2CPPTests extends AST2BaseTest {
f= bh.assertNonProblem("t8", 2);
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
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.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -186,17 +186,17 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest {
int length = "argc".length(); //$NON-NLS-1$
IASTNode node = parse( code, ParserLanguage.C, offset1, length ).getParent().getParent();
assertNotNull(node);
assertTrue( node instanceof IASTInitializerExpression );
assertEquals( ((IASTIdExpression)((IASTInitializerExpression)node).getExpression()).getName().toString(), "argc" ); //$NON-NLS-1$
IASTName name = ((IASTIdExpression)((IASTInitializerExpression)node).getExpression()).getName();
assertTrue( node instanceof IASTEqualsInitializer );
assertEquals( ((IASTIdExpression)((IASTEqualsInitializer)node).getInitializerClause()).getName().toString(), "argc" ); //$NON-NLS-1$
IASTName name = ((IASTIdExpression)((IASTEqualsInitializer)node).getInitializerClause()).getName();
assertNotNull(name.resolveBinding());
assertTrue(name.resolveBinding() instanceof IParameter);
assertEquals(((IParameter)name.resolveBinding()).getName(), "argc"); //$NON-NLS-1$
node = parse( code, ParserLanguage.CPP, offset1, length ).getParent().getParent();
assertNotNull(node);
assertTrue( node instanceof IASTInitializerExpression );
assertEquals( ((IASTIdExpression)((IASTInitializerExpression)node).getExpression()).getName().toString(), "argc" ); //$NON-NLS-1$
name = ((IASTIdExpression)((IASTInitializerExpression)node).getExpression()).getName();
assertTrue( node instanceof IASTEqualsInitializer );
assertEquals( ((IASTIdExpression)((IASTEqualsInitializer)node).getInitializerClause()).getName().toString(), "argc" ); //$NON-NLS-1$
name = ((IASTIdExpression)((IASTEqualsInitializer)node).getInitializerClause()).getName();
assertNotNull(name.resolveBinding());
assertTrue(name.resolveBinding() instanceof IParameter);
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.IASTElaboratedTypeSpecifier;
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.IASTExpressionList;
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.IASTImageLocation;
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.IASTLabelStatement;
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$
// = x + y
IASTInitializerExpression initializer = (IASTInitializerExpression) declor_z
IASTEqualsInitializer initializer = (IASTEqualsInitializer) declor_z
.getInitializer();
IASTBinaryExpression init_z = (IASTBinaryExpression) initializer
.getExpression();
IASTBinaryExpression init_z = (IASTBinaryExpression) initializer.getInitializerClause();
assertEquals(IASTBinaryExpression.op_plus, init_z.getOperator());
IASTIdExpression ref_x = (IASTIdExpression) init_z.getOperand1();
IASTName name_ref_x = ref_x.getName();
@ -2038,8 +2037,8 @@ public class AST2Tests extends AST2BaseTest {
.getName();
IASTName name_xy = xy.getDeclarators()[0].getName();
IASTDeclarator declarator_xy = xy.getDeclarators()[0];
IASTInitializer[] initializers1 = ((IASTInitializerList) declarator_xy
.getInitializer()).getInitializers();
IASTInitializer[] initializers1 = ((IASTInitializerList) ((IASTEqualsInitializer) declarator_xy.getInitializer())
.getInitializerClause()).getInitializers();
IASTName name_y2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers1[0])
.getDesignators()[0]).getName();
@ -2056,14 +2055,14 @@ public class AST2Tests extends AST2BaseTest {
.getDeclSpecifier()).getName();
IASTName name_point = point.getDeclarators()[0].getName();
IASTDeclarator declarator_point = point.getDeclarators()[0];
IASTInitializer[] initializers2 = ((IASTInitializerList) declarator_point
.getInitializer()).getInitializers();
IASTInitializer[] initializers2 = ((IASTInitializerList) ((IASTEqualsInitializer) declarator_point
.getInitializer()).getInitializerClause()).getInitializers();
IASTName name_width2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers2[0])
.getDesignators()[0]).getName();
IASTName name_pos2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers2[1])
.getDesignators()[0]).getName();
IASTName name_xy2 = ((IASTIdExpression) ((IASTUnaryExpression) ((IASTInitializerExpression) ((ICASTDesignatedInitializer) initializers2[1])
.getOperandInitializer()).getExpression()).getOperand())
IASTName name_xy2 = ((IASTIdExpression) ((IASTUnaryExpression) ((IASTEqualsInitializer) ((ICASTDesignatedInitializer) initializers2[1])
.getOperandInitializer()).getInitializerClause()).getOperand())
.getName();
for (int j = 0; j < 2; ++j) {
@ -2136,13 +2135,12 @@ public class AST2Tests extends AST2BaseTest {
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
.getName();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def
.getBody()).getStatements()[0]).getDeclaration())
.getDeclarators()[0].getInitializer()).getInitializers()[0])
final IASTDeclarator dtor = ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def
.getBody()).getStatements()[0]).getDeclaration()).getDeclarators()[0];
final IASTInitializerList initializerList = (IASTInitializerList) ((IASTEqualsInitializer)dtor.getInitializer()).getInitializerClause();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializerList.getInitializers()[0])
.getDesignators()[0]).getName();
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) ((IASTCompoundStatement) f_def
.getBody()).getStatements()[0]).getDeclaration())
.getDeclarators()[0].getInitializer()).getInitializers()[1])
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializerList.getInitializers()[1])
.getDesignators()[0]).getName();
assertEquals(a1.resolveBinding(), a2.resolveBinding());
@ -2177,11 +2175,11 @@ public class AST2Tests extends AST2BaseTest {
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
.getName();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) S_decl
.getDeclarators()[0].getInitializer()).getInitializers()[0])
final IASTInitializer[] initializers = ((IASTInitializerList) ((IASTEqualsInitializer) S_decl
.getDeclarators()[0].getInitializer()).getInitializerClause()).getInitializers();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers[0])
.getDesignators()[0]).getName();
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) S_decl
.getDeclarators()[0].getInitializer()).getInitializers()[1])
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) initializers[1])
.getDesignators()[0]).getName();
assertEquals(a1.resolveBinding(), a2.resolveBinding());
@ -2219,11 +2217,11 @@ public class AST2Tests extends AST2BaseTest {
IASTName b1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) S_decl
.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0]
.getName();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) x_decl
.getDeclarators()[0].getInitializer()).getInitializers()[0])
IASTInitializer initializer = x_decl.getDeclarators()[0].getInitializer();
initializer= (IASTInitializer) ((IASTEqualsInitializer) initializer).getInitializerClause();
IASTName a2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) initializer).getInitializers()[0])
.getDesignators()[0]).getName();
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) x_decl
.getDeclarators()[0].getInitializer()).getInitializers()[1])
IASTName b2 = ((ICASTFieldDesignator) ((ICASTDesignatedInitializer) ((IASTInitializerList) initializer).getInitializers()[1])
.getDesignators()[0]).getName();
assertEquals(a1.resolveBinding(), a2.resolveBinding());
@ -5483,7 +5481,7 @@ public class AST2Tests extends AST2BaseTest {
final IASTFunctionDefinition fdef= getDeclaration(tu, 1);
IASTFunctionDeclarator fdtor= fdef.getDeclarator();
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(exprStr, expr.getRawSignature());
checkOffsets(exprStr, expr);
@ -6425,7 +6423,7 @@ public class AST2Tests extends AST2BaseTest {
*/
private IBasicType getTypeForDeclaration(IASTDeclaration[] declarations, int index) {
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());
}
}
// 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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -11,8 +11,8 @@
package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
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$
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
public void testPrimaryIntegerLiteral() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(1, 2+3);".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testPrimaryCharLiteral() throws Exception
{
IASTTranslationUnit tu = parse("int x = f('c');".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testPrimaryFloatLiteral() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(1.13);".toString(), ParserLanguage.C); //$NON-NLS-1$
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*
public void testPrimaryStringLiteral() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(\"str\");".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testPrimaryBooleanLiteral() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(true);".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testPrimaryThis() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(this);".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testPrimaryBracketedExpression() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(1, (2+3));".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testIdExpression() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(a);".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testPostfixSubscript() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(pa[1]);".toString(), ParserLanguage.C); //$NON-NLS-1$
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
{
IASTTranslationUnit tu = parse("int x = f(pa[1][2]);".toString(), ParserLanguage.C); //$NON-NLS-1$
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
@ -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$
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
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$
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
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$
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
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$
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
public void testPostfixIncrement() throws Exception
{
IASTTranslationUnit tu = parse("int y = foo( x++ );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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
public void testPostfixDecrement() throws Exception
{
IASTTranslationUnit tu = parse("int y = foo( x-- );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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
public void testPostfixDynamicCast() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( dynamic_cast<B*>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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
public void testPostfixReinterpretCast() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( reinterpret_cast<double *>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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
public void testPostfixStaticCast() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( static_cast<char>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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
public void testPostfixConstCast() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( const_cast<int *>(&a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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
public void testPostfixTypeIdExpression() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( typeid(5) );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testPostfixTypeIdExpression2() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( typeid(a) );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
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$
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
public void testUnaryIncrement() throws Exception
{
IASTTranslationUnit tu = parse("int y = foo( ++x );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testUnaryDecrement() throws Exception
{
IASTTranslationUnit tu = parse("int y = foo( --x );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testUnaryStarCastExpression() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(*pa);".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testUnaryAmpersandCastExpression() throws Exception
{
IASTTranslationUnit tu = parse("int x = f(&pa);".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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
public void testUnaryPlusCastExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( +5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testUnaryMinusCastExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( -5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testUnaryNotCastExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( !b );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testTildeNotCastExpression() throws Exception {
IASTTranslationUnit tu = parse("int y = foo( ~x );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testUnarySizeofUnaryExpression() throws Exception {
IASTTranslationUnit tu = parse("int y = foo( sizeof(5) );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testUnarySizeofTypeId() throws Exception {
IASTTranslationUnit tu = parse("int x, y = foo( sizeof(x) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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$
}
// Kind NEW_TYPEID
public void testNewTypeId() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( new A() );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
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
public void testCastExpression() throws Exception{
IASTTranslationUnit tu = parse("int x = foo( (A*)b );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testMultiplicativeMultiply() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a * b );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testMultiplicativeDivide() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b / a );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testMultiplicativeModulus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b % a );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAdditivePlus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b + a );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAdditiveMinus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b - a );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testShiftLeft() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a << 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testShiftRight() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a >> 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testRelationalLessThan() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b < 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testRelationalGreaterThan() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b > 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testRelationalLessThanOrEqual() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b <= 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testRelationalGreaterThanOrEqual() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b >= 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testEqualityEquals() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b == 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testEqualityNotEquals() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( b != 3 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAndExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a & b );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testExclusiveOrExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a ^ b );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testInclusiveOrExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a | b );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testLogicalAndExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a && b );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testLogicalOrExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a || b );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testConditionalExpression() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a > 5 ? b : c );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionNormal() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a = 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionPlus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a += 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionMinus() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a -= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionMulti() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a *= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionDiv() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a /= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionMod() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a %= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionLShift() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a >>= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionRShift() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a <<= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionAnd() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a &= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionOr() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a |= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
public void testAssignmentExpressionXOr() throws Exception {
IASTTranslationUnit tu = parse("int x = foo( a ^= 5 );".toString(), ParserLanguage.C); //$NON-NLS-1$
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTCompoundStatement;
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.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -51,16 +51,16 @@ public class AST2UtilTests extends AST2BaseTest {
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C);
IASTDeclaration[] d = tu.getDeclarations();
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[2].getInitializer()).getExpression(), "0"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[1]).getDeclarators()[0].getInitializer()).getExpression(), "l ? m : n"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getExpression(), "l ^ m"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[3]).getDeclarators()[0].getInitializer()).getExpression(), "i <<= j"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getExpression(), "sizeof (int)"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[5]).getDeclarators()[0].getInitializer()).getExpression(), "~f"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getExpression(), "++e"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[7]).getDeclarators()[0].getInitializer()).getExpression(), "d++"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[8]).getDeclarators()[0].getInitializer()).getExpression(), "sizeof b"); //$NON-NLS-1$
isExpressionStringEqual(((IASTInitializerExpression)((IASTSimpleDeclaration)d[9]).getDeclarators()[0].getInitializer()).getExpression(), "b + c"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[2].getInitializer()).getInitializerClause(), "0"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[1]).getDeclarators()[0].getInitializer()).getInitializerClause(), "l ? m : n"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getInitializerClause(), "l ^ m"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[3]).getDeclarators()[0].getInitializer()).getInitializerClause(), "i <<= j"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getInitializerClause(), "sizeof (int)"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[5]).getDeclarators()[0].getInitializer()).getInitializerClause(), "~f"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getInitializerClause(), "++e"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[7]).getDeclarators()[0].getInitializer()).getInitializerClause(), "d++"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[8]).getDeclarators()[0].getInitializer()).getInitializerClause(), "sizeof b"); //$NON-NLS-1$
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[9]).getDeclarators()[0].getInitializer()).getInitializerClause(), "b + c"); //$NON-NLS-1$
}
public void testSimpleParameter() throws Exception {
@ -141,14 +141,14 @@ public class AST2UtilTests extends AST2BaseTest {
IASTDeclaration[] d = tu.getDeclarations();
// 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( ((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
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( ((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 {

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
* are made available under the terms of the Eclipse Public License v1.0
* 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.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.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.IASTName;
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$
buffer.append( "int ABC;"); //$NON-NLS-1$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition ABC = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[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$
buffer.append( "int ABC;"); //$NON-NLS-1$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition ABC = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[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$
buffer.append( "XYZ int var;"); //$NON-NLS-1$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition defXYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTSimpleDeclSpecifier declSpec = (IASTSimpleDeclSpecifier) var.getDeclSpecifier();
@ -154,8 +154,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
buffer.append( "int C_PO var;"); //$NON-NLS-1$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions();
IASTPreprocessorMacroDefinition XYZ = macroDefinitions[0];
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$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition XYZ = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
// IASTPreprocessorObjectStyleMacroDefinition PO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[1];
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$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i], true, true);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language, true, true);
final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions();
IASTPreprocessorObjectStyleMacroDefinition _PTR = (IASTPreprocessorObjectStyleMacroDefinition) macroDefinitions[0];
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( "int ABC;\n"); //$NON-NLS-1$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorMacroDefinition [] macros = tu.getMacroDefinitions();
assertEquals( macros.length, 2 );
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$
buffer.append( "int MACRO;\n"); //$NON-NLS-1$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTPreprocessorObjectStyleMacroDefinition MACRO = (IASTPreprocessorObjectStyleMacroDefinition) tu.getMacroDefinitions()[0];
IASTName macro_name = MACRO.getName();
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( "MYAPI void func() {}" ); //$NON-NLS-1$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
assertNotNull( f.getFileLocation() );
}
@ -350,11 +350,11 @@ public class DOMLocationMacroTests extends AST2BaseTest {
buffer.append( "int var= FUNCTION(1);"); //$NON-NLS-1$
String code = buffer.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTSimpleDeclaration var = (IASTSimpleDeclaration) tu.getDeclarations()[0];
IASTInitializerExpression initializer= (IASTInitializerExpression)var.getDeclarators()[0].getInitializer();
IASTExpression expr= initializer.getExpression();
IASTEqualsInitializer initializer= (IASTEqualsInitializer)var.getDeclarators()[0].getInitializer();
IASTInitializerClause expr= initializer.getInitializerClause();
assertNotNull(expr.getFileLocation());
IASTNodeLocation [] locations = expr.getNodeLocations();
assertEquals(1, locations.length);
@ -369,8 +369,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
private void assertMacroLocation(IASTDeclaration decl, int index, int length) {
IASTSimpleDeclaration var = (IASTSimpleDeclaration) decl;
IASTInitializerExpression initializer= (IASTInitializerExpression)var.getDeclarators()[0].getInitializer();
IASTExpression expr= initializer.getExpression();
IASTEqualsInitializer initializer= (IASTEqualsInitializer)var.getDeclarators()[0].getInitializer();
IASTInitializerClause expr= initializer.getInitializerClause();
assertNotNull(expr.getFileLocation());
IASTNodeLocation [] locations = expr.getNodeLocations();
assertEquals(1, locations.length);
@ -384,8 +384,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
private void assertExpressionLocation(IASTDeclaration decl, int index, int length) {
IASTSimpleDeclaration var = (IASTSimpleDeclaration) decl;
IASTInitializerExpression initializer= (IASTInitializerExpression)var.getDeclarators()[0].getInitializer();
IASTExpression expr= initializer.getExpression();
IASTEqualsInitializer initializer= (IASTEqualsInitializer)var.getDeclarators()[0].getInitializer();
IASTInitializerClause expr= initializer.getInitializerClause();
IASTFileLocation fileLocation = expr.getFileLocation();
assertNotNull(fileLocation);
assertEquals(index, fileLocation.getNodeOffset());
@ -402,8 +402,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations();
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$
@ -421,8 +421,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations();
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$
@ -438,8 +438,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations();
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$
@ -455,8 +455,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations();
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$
@ -472,8 +472,8 @@ public class DOMLocationMacroTests extends AST2BaseTest {
sb.append("int y = whatever; \n"); //$NON-NLS-1$
String code = sb.toString();
for(int i = 0; i < languages.length; i++) {
IASTTranslationUnit tu = parse(code, languages[i]);
for (ParserLanguage language : languages) {
IASTTranslationUnit tu = parse(code, language);
IASTDeclaration[] decls = tu.getDeclarations();
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$

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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTElaboratedTypeSpecifier;
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.IASTFileLocation;
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.IASTIfStatement;
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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
@ -297,9 +297,9 @@ public class DOMLocationTests extends AST2BaseTest {
}
assertSoleLocation(decl, start, length);
}
IASTInitializerExpression initializer = (IASTInitializerExpression) ((IASTSimpleDeclaration) declarations[2])
IASTEqualsInitializer initializer = (IASTEqualsInitializer) ((IASTSimpleDeclaration) declarations[2])
.getDeclarators()[0].getInitializer();
IASTCastExpression castExpression = (IASTCastExpression) initializer.getExpression();
IASTCastExpression castExpression = (IASTCastExpression) initializer.getInitializerClause();
IASTTypeId typeId = castExpression.getTypeId();
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();
IASTDeclarationStatement decl = (IASTDeclarationStatement) statement.getStatements()[0];
IASTSimpleDeclaration b = (IASTSimpleDeclaration) decl.getDeclaration();
IASTInitializerExpression initializerExpression = (IASTInitializerExpression) b.getDeclarators()[0].getInitializer();
assertSoleLocation(initializerExpression,code.indexOf("new B()"), "new B()".length()); //$NON-NLS-1$ //$NON-NLS-2$
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) initializerExpression.getExpression();
IASTEqualsInitializer initializerExpression = (IASTEqualsInitializer) b.getDeclarators()[0].getInitializer();
assertSoleLocation(initializerExpression.getInitializerClause(),code.indexOf("new B()"), "new B()".length()); //$NON-NLS-1$ //$NON-NLS-2$
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) initializerExpression.getInitializerClause();
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();
assertEquals(1, declarators.length);
IASTInitializer initializer= declarators[0].getInitializer();
assertTrue(initializer instanceof IASTInitializerExpression);
IASTExpression expr= ((IASTInitializerExpression)initializer).getExpression();
assertTrue(initializer instanceof IASTEqualsInitializer);
IASTInitializerClause expr= ((IASTEqualsInitializer)initializer).getInitializerClause();
assertTrue(expr instanceof IASTTypeIdExpression);
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.
* All rights reserved. This program and the accompanying materials
* 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;
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.IASTPreprocessorElifStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorEndifStatement;
@ -177,7 +178,9 @@ public class DOMPreprocessorInformationTest extends AST2BaseTest {
assertTrue(st[0] instanceof IASTPreprocessorFunctionStyleMacroDefinition);
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();
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTASMDeclaration;
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.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
@ -89,12 +90,12 @@ public class GCCCompleteParseExtensionsTest extends AST2BaseTest {
public void testBug39698A() throws Exception
{
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
{
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 {

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
* All rights reserved. This program and the accompanying materials
* 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;
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".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);
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
* All rights reserved. This program and the accompanying materials
* 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];
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".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);
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
* All rights reserved. This program and the accompanying materials
* 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 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.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
@ -49,7 +51,8 @@ public class NewInitializerExpressionTest extends ChangeGeneratorTest {
public int visit(IASTExpression expression) {
if (expression instanceof ICPPASTNewExpression) {
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);
}
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
* All rights reserved. This program and the accompanying materials
* 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){
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".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);
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
* All rights reserved. This program and the accompanying materials
* 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.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
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.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
@ -57,7 +57,7 @@ public class InitializerTest extends ChangeGeneratorTest {
IASTInitializer initializer = fieldDeclarator.getInitializer();
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);
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
* All rights reserved. This program and the accompanying materials
* 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 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.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
@ -54,7 +56,8 @@ public class NewInitializerExpressionTest extends ChangeGeneratorTest {
public int visit(IASTExpression expression) {
if (expression instanceof ICPPASTNewExpression) {
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);
}
return PROCESS_CONTINUE;

View file

@ -50,13 +50,18 @@ int fun3(int i, const char *a, ...);
//!CPPFunctionDeclaratorTest
//%CPP
char & operator [](unsigned int);
class TestClass
{
int alpha;
TestClass(int a);
virtual void pure() =0;
};
TestClass::TestClass(int a)
:alpha(a)
{
}
void undefPar(const char *c) throw (int);
virtual void pure() = 0;
int getV() const;
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.IASTElaboratedTypeSpecifier;
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.IASTExpressionList;
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.IASTIdExpression;
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.IASTLiteralExpression;
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.ICPPASTQualifiedName;
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.ICPPASTTemplateId;
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.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.cpp.IGPPASTPointer;
import org.eclipse.cdt.core.parser.Keywords;
@ -324,20 +325,20 @@ public class ASTStringUtil {
}
private static StringBuilder appendInitializerString(StringBuilder buffer, IASTInitializer initializer) {
if (initializer instanceof IASTInitializerExpression) {
final IASTInitializerExpression initializerExpression= (IASTInitializerExpression)initializer;
if (initializer instanceof IASTEqualsInitializer) {
final IASTEqualsInitializer initializerExpression= (IASTEqualsInitializer)initializer;
buffer.append(Keywords.cpASSIGN);
appendExpressionString(buffer, initializerExpression.getExpression());
appendInitClauseString(buffer, initializerExpression.getInitializerClause());
} else if (initializer instanceof IASTInitializerList) {
final IASTInitializerList initializerList= (IASTInitializerList)initializer;
final IASTInitializer[] initializers= initializerList.getInitializers();
final IASTInitializerClause[] initializers= initializerList.getClauses();
buffer.append(Keywords.cpASSIGN);
buffer.append(Keywords.cpLBRACE);
for (int i= 0; i < initializers.length; i++) {
if (i > 0) {
buffer.append(COMMA_SPACE);
}
appendInitializerString(buffer, initializers[i]);
appendInitClauseString(buffer, initializers[i]);
}
trimRight(buffer);
buffer.append(Keywords.cpRBRACE);
@ -347,9 +348,14 @@ public class ASTStringUtil {
// final ICASTDesignator[] designator= designatedInitializer.getDesignators();
} else if (initializer instanceof ICPPASTConstructorInitializer) {
final ICPPASTConstructorInitializer constructorInitializer= (ICPPASTConstructorInitializer)initializer;
final IASTExpression expression= constructorInitializer.getExpression();
final IASTInitializerClause[] clauses= constructorInitializer.getArguments();
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);
buffer.append(Keywords.cpRPAREN);
} else if (initializer != null) {
@ -358,6 +364,14 @@ public class ASTStringUtil {
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) {
appendDeclSpecifierString(buffer, typeId.getDeclSpecifier());
appendDeclaratorString(buffer, typeId.getAbstractDeclarator(), false, null);
@ -681,14 +695,12 @@ public class ASTStringUtil {
}
appendExpressionString(buffer, expressions[i]);
}
} else if (expression instanceof ICPPASTTypenameExpression) {
final ICPPASTTypenameExpression typenameExpression= (ICPPASTTypenameExpression)expression;
buffer.append(Keywords.TYPENAME).append(' ');
appendQualifiedNameString(buffer, typenameExpression.getName());
final IASTExpression initialValue= typenameExpression.getInitialValue();
if (initialValue != null) {
buffer.append(Keywords.cpASSIGN);
appendExpressionString(buffer, initialValue);
} else if (expression instanceof ICPPASTSimpleTypeConstructorExpression) {
final ICPPASTSimpleTypeConstructorExpression typeCast= (ICPPASTSimpleTypeConstructorExpression)expression;
appendDeclSpecifierString(buffer, typeCast.getDeclSpecifier());
final IASTInitializer init= typeCast.getInitializer();
if (init != null) {
appendInitializerString(buffer, init);
}
} else if (expression instanceof IASTLiteralExpression) {
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.ICPPASTSimpleTypeConstructorExpression;
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.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
@ -324,16 +323,12 @@ public class ASTSignatureUtil {
public static String getInitializerString(IASTInitializer init) {
StringBuffer result = new StringBuffer();
if (init instanceof IASTInitializerExpression) {
result.append(getExpressionString(((IASTInitializerExpression) init).getExpression()));
if (init instanceof IASTEqualsInitializer) {
result.append(Keywords.cpASSIGN);
result.append(getInitializerClauseString(((IASTEqualsInitializer) init).getInitializerClause()));
} else if (init instanceof IASTInitializerList) {
result.append(Keywords.cpLBRACE);
IASTInitializer[] inits = ((IASTInitializerList) init).getInitializers();
for (int i = 0; i < inits.length; i++) {
result.append(getInitializerString(inits[i]));
if (i < inits.length - 1)
result.append(COMMA_SPACE);
}
appendExpressionList(result, ((IASTInitializerList) init).getClauses());
result.append(Keywords.cpRBRACE);
} else if (init instanceof ICASTDesignatedInitializer) {
ICASTDesignator[] designators = ((ICASTDesignatedInitializer) init).getDesignators();
@ -343,16 +338,34 @@ public class ASTSignatureUtil {
result.append(COMMA_SPACE);
}
result.append(Keywords.cpASSIGN);
result.append(getInitializerString(((ICASTDesignatedInitializer) init).getOperandInitializer()));
result.append(getInitializerClauseString(((ICASTDesignatedInitializer) init).getOperand()));
} else if (init instanceof ICPPASTConstructorInitializer) {
result.append("("); //$NON-NLS-1$
result.append(getExpressionString(((ICPPASTConstructorInitializer) init).getExpression()));
appendExpressionList(result, ((ICPPASTConstructorInitializer) init).getArguments());
result.append(")"); //$NON-NLS-1$
}
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) {
StringBuffer result = new StringBuffer();
@ -796,8 +809,6 @@ public class ASTSignatureUtil {
return getNewExpression((ICPPASTNewExpression)expression);
else if (expression instanceof ICPPASTSimpleTypeConstructorExpression)
return getSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression)expression);
else if (expression instanceof ICPPASTTypenameExpression)
return getTypenameExpression((ICPPASTTypenameExpression)expression);
else if (expression instanceof IGNUASTCompoundStatementExpression)
return getCompoundStatementExpression((IGNUASTCompoundStatementExpression)expression);
else if (expression instanceof ICPPASTPackExpansionExpression)
@ -856,7 +867,13 @@ public class ASTSignatureUtil {
StringBuffer result = new StringBuffer();
result.append(getExpressionString(expression.getFunctionNameExpression()));
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);
return result.toString();
}
@ -881,58 +898,8 @@ public class ASTSignatureUtil {
private static String getSimpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression expression) {
StringBuffer result = new StringBuffer();
switch (expression.getSimpleType()) {
case ICPPASTSimpleTypeConstructorExpression.t_bool:
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);
result.append(getSignature(expression.getDeclSpecifier()));
result.append(getInitializerString(expression.getInitializer()));
return result.toString();
}
@ -1004,13 +971,16 @@ public class ASTSignatureUtil {
StringBuffer result = new StringBuffer();
result.append(Keywords.NEW);
result.append(SPACE);
if (expression.getNewPlacement() != null) {
result.append(getExpressionString(expression.getNewPlacement()));
final IASTInitializerClause[] args = expression.getPlacementArguments();
if (args != null) {
result.append("("); //$NON-NLS-1$
appendExpressionList(result, args);
result.append(")"); //$NON-NLS-1$
}
result.append(getSignature(expression.getTypeId()));
result.append(Keywords.cpLPAREN);
result.append(getExpressionString(expression.getNewInitializer()));
result.append(Keywords.cpRPAREN);
final IASTInitializer initializer = expression.getInitializer();
if (initializer != null)
result.append(getInitializerString(initializer));
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -19,15 +19,18 @@ package org.eclipse.cdt.core.dom.ast;
*/
public interface IASTArraySubscriptExpression extends IASTExpression {
/**
* Node property that describes the relationship between an
* <code>IASTArraySubscriptExpression</code> and an
* <code>IASTExpression</code> representing the subscript.
*/
public static final ASTNodeProperty ARRAY = new ASTNodeProperty("IASTArraySubscriptExpression.ARRAY - IASTExpression representing the Array"); //$NON-NLS-1$
public static final ASTNodeProperty ARRAY = new ASTNodeProperty(
"IASTArraySubscriptExpression.ARRAY [IASTExpression]"); //$NON-NLS-1$
public static final ASTNodeProperty SUBSCRIPT = new ASTNodeProperty(
"IASTArraySubscriptExpression.SUBSCRIPT - [IASTFunctionArgument]"); //$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.
*/
@ -42,30 +45,24 @@ public interface IASTArraySubscriptExpression extends IASTExpression {
public void setArrayExpression(IASTExpression expression);
/**
* Node property that describes the relationship between an
* <code>IASTArraySubscriptExpression</code> and an
* <code>IASTExpression</code> representing the array.
* Returns the operand of this expression. In c++ the operand can be a braced initializer list.
* @since 5.2
*/
public static final ASTNodeProperty SUBSCRIPT = new ASTNodeProperty(
"IASTArraySubscriptExpression.SUBSCRIPT - IASTExpression representing the Subscript"); //$NON-NLS-1$
public IASTInitializerClause getArgument();
/**
* Get the subscript expression.
*
* @return <code>IASTExpression</code> that represents the subscript.
* Not allowed on frozen ast.
* @since 5.2
*/
public void setArgument(IASTInitializerClause expression);
/**
* Returns the subscript expression, or <code>null</code>. Consider using {@link #getArgument()}.
*/
public IASTExpression getSubscriptExpression();
/**
* Set the subscript expression.
*
* @param expression
* <code>IASTExpression</code> to be set.
* Not allowed on frozen ast.
*/
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@ -254,6 +255,13 @@ public interface IASTBinaryExpression extends IASTExpression {
*/
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
* <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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,17 +8,28 @@
* Contributors:
* 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.
* @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
* are made available under the terms of the Eclipse Public License v1.0
* 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.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTExpression extends IASTNode {
public interface IASTExpression extends IASTInitializerClause {
/**
* 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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* John Camelon (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@ -19,55 +20,54 @@ package org.eclipse.cdt.core.dom.ast;
*/
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(
"IASTFunctionCallExpression.FUNCTION_Name - IASTExpression (name) for IASTFunctionCallExpression"); //$NON-NLS-1$
"IASTFunctionCallExpression.FUNCTION_NAME [IASTExpression]"); //$NON-NLS-1$
/**
* Set the function name expression.
*
* @param expression
* <code>IASTExpression</code> representing the function name
* @since 5.2
*/
public void setFunctionNameExpression(IASTExpression expression);
public static final ASTNodeProperty ARGUMENT = new ASTNodeProperty(
"IASTFunctionCallExpression.ARGUMENT [IASTInitializerClause]"); //$NON-NLS-1$
/**
* Get the function name expression.
*
* @return <code>IASTExpression</code> representing the function name
*/
public IASTExpression getFunctionNameExpression();
/**
* <code>PARAMETERS</code> represents the relationship between a
* <code>IASTFunctionCallExpression</code> and its
* <code>IASTExpression</code> (parameters).
* Returns the arguments for this function call, never <code>null</code>.
* @since 5.2
*/
public static final ASTNodeProperty PARAMETERS = new ASTNodeProperty(
"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();
public IASTInitializerClause[] getArguments();
/**
* @since 5.1
*/
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -18,6 +18,8 @@ package org.eclipse.cdt.core.dom.ast;
*
* @see ASTVisitor#shouldVisitImplicitNames
* @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 {

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
* are made available under the terms of the Eclipse Public License v1.0
* 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.
* @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 {

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,15 +8,15 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
package org.eclipse.cdt.core.dom.ast;
/**
* 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.
* @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
* are made available under the terms of the Eclipse Public License v1.0
* 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.
* @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
* an <code>IASTInitializerExpression</code>. and its <code></code>IASTExpression</code>.
*/
public static final ASTNodeProperty INITIALIZER_EXPRESSION = new ASTNodeProperty(
"IASTInitializerExpression.INITIALIZER_EXPRESSION - IASTExpression for IASTInitializerExpression"); //$NON-NLS-1$
public static final ASTNodeProperty INITIALIZER_EXPRESSION = 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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,25 +7,21 @@
*
* Contributors:
* Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
/**
* This is an an initializer that is a list of initializers.
* For example as in:
* Braced initializer list, for example as in:
* <pre> int a[]= {1,2,3}; </pre>
*
* @noextend This interface is not intended to be extended 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(
"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
@ -37,18 +33,34 @@ public interface IASTInitializerList extends IASTInitializer {
/**
* Returns the list of initializers. Depending on how the ast was created, this may omit
* 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
* 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
*/
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@ -16,13 +17,8 @@ package org.eclipse.cdt.core.dom.ast;
*/
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(
"IASTReturnValue.RETURNVALUE - IASTExpression (returnValue) for IASTReturnStatement"); //$NON-NLS-1$
"IASTReturnValue.RETURNVALUE - [IASTInitializerClause]"); //$NON-NLS-1$
/**
* This is the optional return value for this function.
@ -32,10 +28,20 @@ public interface IASTReturnStatement extends IASTStatement {
public IASTExpression getReturnValue();
/**
* Set the return value.
*
* @param returnValue
* <code>IASTExpression</code>
* Returns the return value as {@link IASTInitializerClause}, or <code>null</code>.
* In c++ this can be an braced initializer list.
* @since 5.2
*/
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);

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
* 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:
* 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;
@ -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.IToken;
/**
* Factory for creating AST nodes. This interface contains factory methods
* 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.
*
* @author Mike Kucera
* @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 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.
*/
@ -47,8 +136,30 @@ public interface INodeFactory {
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
public IASTTranslationUnit newTranslationUnit();
@ -61,125 +172,26 @@ public interface INodeFactory {
*/
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 IASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name);
public IASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator);
public IASTDeclarator newDeclarator(IASTName name);
public IASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId);
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier);
public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer);
public IASTInitializerExpression newInitializerExpression(IASTExpression expression);
public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand);
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 IASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
public IASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
/**
* Provides the offsets for a node. The offsets are artificial numbers that identify the
* position of a node in the translation unit. They are not file-offsets. You can obtain
* valid offsets via {@link IToken#getOffset()} or {@link IToken#getEndOffset()} from tokens
* provided by the scanner for this translation unit.
* <par> May throw an exception when the node provided was not created by this factory.
* 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 offset the offset (inclusive) for the node
* @param endOffset the end offset (exclusive) for the node
* @see #newTranslationUnit(IScanner)
* @param endNode a node created by this factory defining the end for the other node.
* @since 5.2
*/
public void setOffsets(IASTNode node, int offset, int endOffset);
void setEndOffset(IASTNode node, IASTNode endNode);
/**
* Provides the end offset for a node. The offset is an artificial numbers that identifies the
@ -195,11 +207,16 @@ public interface INodeFactory {
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.
* Provides the offsets for a node. The offsets are artificial numbers that identify the
* position of a node in the translation unit. They are not file-offsets. You can obtain
* valid offsets via {@link IToken#getOffset()} or {@link IToken#getEndOffset()} from tokens
* 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 endNode a node created by this factory defining the end for the other node.
* @param offset the offset (inclusive) for the node
* @param endOffset the end offset (exclusive) for the node
* @see #newTranslationUnit(IScanner)
* @since 5.2
*/
void setEndOffset(IASTNode node, IASTNode endNode);
public void setOffsets(IASTNode node, int offset, int endOffset);
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,11 +7,13 @@
*
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
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,
@ -20,61 +22,53 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
* @noextend This interface is not intended to be extended 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];
/**
* <code>DESIGNATOR</code> represents the relationship between an
* <code>ICASTDesignatedInitializer</code> and
* <code>ICASTDesignator</code>.
*/
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.
*
* @param designator
* <code>ICASTDesignator</code>
*/
public void addDesignator(ICASTDesignator designator);
/**
* Get all of the designators.
*
* @return <code>ICASTDesignator []</code>
*/
public ICASTDesignator[] getDesignators();
/**
* <code>OPERAND</code> represents the relationship between
* <code>ICASTDesignatedInitializer</code> and its
* <code>IASTInitializer</code>.
* Returns the operand initializer.
* @since 5.2
*/
public static final ASTNodeProperty OPERAND = new ASTNodeProperty(
"ICASTDesignatedInitializer.OPERAND - RHS IASTInitializer for ICASTDesignatedInitializer"); //$NON-NLS-1$
public IASTInitializerClause getOperand();
/**
* Get the nested initializer.
*
* @return <code>IASTInitializer</code>
* Not allowed on frozen ast
* @since 5.2
*/
public IASTInitializer getOperandInitializer();
/**
* Set the nested initializer.
*
* @param rhs
* <code>IASTInitializer</code>
*/
public void setOperandInitializer(IASTInitializer rhs);
void setOperand(IASTInitializerClause operand);
/**
* @since 5.1
*/
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.IASTExpression;
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.IASTTypeId;
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 ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name);
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 ICASTArrayDesignator newArrayDesignator(IASTExpression exp);
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 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 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
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -15,6 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
/**
* @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 {

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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
/**
* Represents a member initializer:
* <pre> class X {
* int a;
* 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.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPASTConstructorChainInitializer extends ICPPASTInitializer, IASTNameOwner {
/**
* Constant.
*/
public interface ICPPASTConstructorChainInitializer extends IASTInitializer, ICPPASTPackExpandable,
IASTNameOwner {
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(
"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.
*
* @return <code>IASTName</code>
* Returns the name of the member.
*/
public IASTName getMemberInitializerId();
/**
* Set the field name.
*
* @param name
* <code>IASTName</code>
* Returns the initializer for the member
* @since 5.2
*/
public void setMemberInitializerId(IASTName name);
/**
* <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);
public IASTInitializer getInitializer();
/**
* @since 5.1
*/
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.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.
* @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
* constructor.
* @since 5.2
*/
public static final ASTNodeProperty EXPRESSION = new ASTNodeProperty(
"ICPPASTConstructorInitializer.EXPRESSION - Expression consumed in constructor"); //$NON-NLS-1$
public static final ASTNodeProperty ARGUMENT = new ASTNodeProperty(
"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();
/**
* Set the arguments to the constructor.
*
* @param expression
*/
public void setExpression(IASTExpression expression);
public IASTInitializerClause[] getArguments();
/**
* @since 5.1
*/
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -15,6 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
/**
* @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 {

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -15,6 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
/**
* @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 {

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
* are made available under the terms of the Eclipse Public License v1.0
* 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;
/**
* Initializer expression for c++.
* Braced initializer list.
*
* @since 5.2
* @noextend This interface is not intended to be extended 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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
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.
@ -25,79 +27,38 @@ import org.eclipse.cdt.core.dom.ast.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?
*
* @return boolean
*/
public boolean isGlobal();
/**
* Set this expression to bea global ::new expression (or not).
*
* @param value
* boolean
* Returns true if this expression is allocating an array.
* @since 5.1
*/
public void setIsGlobal(boolean value);
public boolean isArrayAllocation();
/**
* NEW_PLACEMENT is a role for an expression to represent the location of
* where the memory should be allocated.
* Returns the additional arguments for the new placement, or <code>null</code>.
* A placement argument can be of type {@link ICPPASTInitializerList}.
* @since 5.2
*/
public static final ASTNodeProperty NEW_PLACEMENT = new ASTNodeProperty(
"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$
public IASTInitializerClause[] getPlacementArguments();
/**
* Get the type Id. The type-id includes the optional array modifications.
* @return <code>IASTTypeId</code>
*/
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
* the type-id is provided without parenthesis.
@ -105,24 +66,49 @@ public interface ICPPASTNewExpression extends IASTExpression, IASTImplicitNameOw
public boolean isNewTypeId();
/**
* Set the type ID to be a new type ID.
*
* @param value
* boolean
* Returns the initializer or <code>null</code>.
* @since 5.2
*/
public IASTInitializer getInitializer();
/**
* @since 5.1
*/
public ICPPASTNewExpression copy();
/**
* Not allowed on frozen ast.
*/
public void setIsGlobal(boolean value);
/**
* 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);
/**
* Returns true if this expression is allocating an array.
* @since 5.1
* Not allowed on frozen ast.
* @since 5.2
*/
public boolean isArrayAllocation();
public void setInitializer(IASTInitializer init);
/**
* Expressions that go inside array brackets.
* @deprecated the id-expressions are part of the type-id.
*/
@Deprecated
public static final ASTNodeProperty NEW_TYPEID_ARRAY_EXPRESSION = new ASTNodeProperty(
"ICPPASTNewExpression.NEW_TYPEID_ARRAY_EXPRESSION - Expressions inside array brackets"); //$NON-NLS-1$
@ -138,10 +124,27 @@ public interface ICPPASTNewExpression extends IASTExpression, IASTImplicitNameOw
@Deprecated
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,123 +7,108 @@
*
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
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.
* @noimplement This interface is not intended to be implemented by clients.
*/
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;
/**
* 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);
public IASTInitializer getInitializer();
/**
* @since 5.1
*/
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
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.
* @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?
@ -60,8 +63,7 @@ public interface ICPPASTTypenameExpression extends IASTExpression, IASTNameOwner
/**
* <code>INITIAL_VALUE</code> is an expression.
*/
public static final ASTNodeProperty INITIAL_VALUE = new ASTNodeProperty(
"ICPPASTTypenameExpression.INITIAL_VALUE - Initial Value is an expression"); //$NON-NLS-1$
public static final ASTNodeProperty INITIAL_VALUE = INITIALIZER;
/**
* 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.IASTExpression;
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.IASTProblem;
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.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
@ -37,199 +40,259 @@ import org.eclipse.cdt.core.parser.IScanner;
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
*/
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 ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId);
/**
* @since 5.2
*/
public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTInitializerClause expr2);
public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
public ICPPASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand);
public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body);
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
*/
public ICPPASTDeclarator newDeclarator(IASTName name);
public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name);
/**
* @since 5.2
*/
public ICPPASTArrayDeclarator newArrayDeclarator(IASTName name);
/**
* @since 5.2
*/
public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize);
public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand);
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 ICPPASTTemplateId newTemplateId(IASTName templateName);
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,
IASTExpression iterationExpression, IASTStatement body);
public ICPPASTForStatement newForStatement();
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
public ICPPASTWhileStatement newWhileStatement(IASTDeclaration condition, IASTStatement body);
public ICPPASTWhileStatement newWhileStatement();
/**
* @since 5.2
*/
public ICPPASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator);
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
*/
public ICPPASTInitializerList newInitializerList();
public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp);
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName memberInitializerId, IASTExpression initializerValue);
public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
IASTStatement bodyStatement);
public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId);
public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue);
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
*/
public ICPPASTStaticAssertDeclaration newStaticAssertion(IASTExpression condition, ICPPASTLiteralExpression message);
/**
* Creates a new pack expansion expression for the given pattern.
* @since 5.2
*/
public ICPPASTPackExpansionExpression newPackExpansionExpression(IASTExpression pattern);
/**
* @deprecated Replaced by {@link #newReferenceOperator(boolean)}.
*/
@Deprecated public ICPPASTReferenceOperator newReferenceOperator();
/**
* @deprecated Replaced by {@link #newTranslationUnit(IScanner)}.
*/
@Deprecated
public ICPPASTTranslationUnit newTranslationUnit();
/**
* @deprecated Replaced by {@link #newSimpleDeclSpecifier()}
*/
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP();
/**
* @deprecated Replaced by {@link #newExplicitTemplateInstantiation(IASTDeclaration)}.
*/
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiationGPP(IASTDeclaration declaration);
public ICPPASTExpressionList newExpressionList();
/**
* @since 5.2
*/
public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize);
public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner);
public ICPPASTForStatement newForStatement();
public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition,
IASTExpression iterationExpression, IASTStatement body);
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
*/
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);
/**
* @since 5.2
*/
public ICPPASTInitializerList newInitializerList();
public ICPPASTLinkageSpecification newLinkageSpecification(String literal);
public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep);
public ICPPASTNamespaceAlias newNamespaceAlias(IASTName alias, IASTName qualifiedName);
public ICPPASTNamespaceDefinition newNamespaceDefinition(IASTName name);
/**
* @deprecated Replaced by {@link #newNewExpression(IASTInitializerClause[], IASTInitializer, IASTTypeId)}
*/
@Deprecated
public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, IASTTypeId typeId);
/**
* @since 5.2
*/
public ICPPASTNewExpression newNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, IASTTypeId typeId);
public ICPPASTOperatorName newOperatorName(char[] name);
/**
* Creates a new pack expansion expression for the given pattern.
* @since 5.2
*/
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 public ICPPASTReferenceOperator newReferenceOperator();
/**
* Creates an lvalue or rvalue reference operator.
* @since 5.2
*/
public ICPPASTReferenceOperator newReferenceOperator(boolean isRValueReference);
/**
* @since 5.2
*/
public IASTReturnStatement newReturnStatement(IASTInitializerClause retValue);
public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier();
/**
* @deprecated Replaced by {@link #newSimpleDeclSpecifier()}
*/
@Deprecated
public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP();
/**
* @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
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}.
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
@Deprecated
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
* are made available under the terms of the Eclipse Public License v1.0
* 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
* {@link IToken#tINACTIVE_CODE_END}.
* @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 {

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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTCastExpression;
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.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
@ -104,7 +106,15 @@ public abstract class ASTAmbiguousCastVsFunctionCallExpression extends ASTAmbigu
if (!hasIssue)
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);
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.IASTFunctionDefinition;
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.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
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.IASTProblemExpression;
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.IASTSimpleDeclaration;
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.IType;
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.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
@ -633,6 +631,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throw backtrack;
}
protected final void throwBacktrack(IASTNode node) throws BacktrackException {
final ASTNode n= (ASTNode) node;
throwBacktrack(n.getOffset(), n.getLength());
}
public IASTTranslationUnit parse() {
long startTime = System.currentTimeMillis();
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.
* 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 fRightPrecedence;
BinaryOperator fNext;
IASTExpression fExpression;
IASTInitializerClause fExpression;
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;
fOperatorToken= operatorToken;
fLeftPrecedence= leftPrecedence;
@ -937,24 +930,24 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
}
public IASTExpression exchange(IASTExpression expr) {
IASTExpression e= fExpression;
public IASTInitializerClause exchange(IASTInitializerClause expr) {
IASTInitializerClause e= fExpression;
fExpression= expr;
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;
for (;;) {
if (leftChain == null) {
if (rightChain == null)
return expr;
return (IASTExpression) expr;
expr= buildExpression(expr, rightChain);
expr= buildExpression((IASTExpression) expr, rightChain);
rightChain= rightChain.fNext;
} else if (rightChain != null && leftChain.fRightPrecedence < rightChain.fLeftPrecedence) {
expr= buildExpression(expr, rightChain);
expr= buildExpression((IASTExpression) expr, rightChain);
rightChain= rightChain.fNext;
} else {
BinaryOperator op= leftChain;
@ -968,7 +961,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
private IASTExpression buildExpression(IASTExpression left, BinaryOperator operator) throws BacktrackException {
int op, unaryOp= 0;
final IASTExpression right= operator.fExpression;
final IASTInitializerClause right= operator.fExpression;
switch(operator.fOperatorToken) {
case IToken.tQUESTION:
if (operator.fNext == null || operator.fNext.fOperatorToken != IToken.tCOLON) {
@ -977,26 +970,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throwBacktrack(node.getOffset(), node.getLength());
return null; // Will never be reached.
}
IASTExpression negative= operator.fNext.fExpression;
IASTInitializerClause negative= operator.fNext.fExpression;
operator.fNext= operator.fNext.fNext;
IASTConditionalExpression conditionalEx = nodeFactory.newConditionalExpession(left, right, negative);
IASTConditionalExpression conditionalEx = nodeFactory.newConditionalExpession(left, (IASTExpression) right, (IASTExpression) negative);
setRange(conditionalEx, left);
if (negative != null) {
adjustLength(conditionalEx, negative);
}
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:
IASTExpressionList list;
if (left instanceof IASTExpressionList) {
@ -1006,7 +988,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
list.addExpression(left);
setRange(list, left);
}
list.addExpression(right);
list.addExpression((IASTExpression) right);
adjustLength(list, right);
return list;
@ -1220,7 +1202,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
backup(mark);
try {
IASTExpression expr= primaryExpression(ctx);
IASTFunctionCallExpression fcall = nodeFactory.newFunctionCallExpression(expr, null);
IASTFunctionCallExpression fcall = nodeFactory.newFunctionCallExpression(expr, (IASTExpression[]) null);
IASTAmbiguousExpression ambiguity = createAmbiguousCastVsFunctionCallExpression(result, fcall);
((ASTNode) ambiguity).setOffsetAndLength((ASTNode) result);
return ca == null ? ambiguity : ca.updateExpression(ambiguity);
@ -1346,12 +1328,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
parent.addDeclaration(declaration);
}
protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTExpression expr2, int lastOffset) {
IASTBinaryExpression result = nodeFactory.newBinaryExpression(operator, expr1, expr2);
int o = ((ASTNode) expr1).getOffset();
((ASTNode) result).setOffsetAndLength(o, lastOffset - o);
return result;
}
abstract protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset);
private IASTExpression createCastVsBinaryExpressionAmbiguity(IASTBinaryExpression expr, final IASTTypeId typeid, int unaryOperator, int unaryOpOffset) {
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());
} catch (BacktrackException b) {
if (expressionStatement == null) {
backup(mark);
throw b;
}
}
@ -1974,40 +1952,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException {
int startOffset;
startOffset = consume().getOffset(); // t_return
IASTExpression result = null;
final int offset= consume(IToken.t_return).getOffset();
// See if there is a return expression
switch (LT(1)) {
case IToken.tEOC:
// We're trying to start one
IASTName name = identifier();
IASTIdExpression idExpr = nodeFactory.newIdExpression(name);
result = idExpr;
break;
case IToken.tSEMI:
// None
break;
default:
// Yes
result = expression();
break;
// Optional expression
IASTExpression expr = null;
if (LT(1) != IToken.tSEMI) {
expr = expression();
}
// Semicolon
final int endOffset= consumeOrEOC(IToken.tSEMI).getEndOffset();
int lastOffset = 0;
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;
return setRange(nodeFactory.newReturnStatement(expr), offset, endOffset);
}
protected IASTStatement parseDoStatement() throws EndOfFileException, BacktrackException {
@ -2316,7 +2271,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
// Allow empty attribute
if (lt1 != IToken.tCOMMA) {
singelAttribute();
singleAttribute();
}
// 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
if (!isIdentifier(LA(1)))
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.
* @since 5.0
*/
public class DeclarationOptions {
final public static int ALLOW_EMPTY_SPECIFIER= 0x01;
final public static int ALLOW_ABSTRACT= 0x02;
final public static int REQUIRE_ABSTRACT= 0x04;
final public static int ALLOW_BITFIELD= 0x08;
final public static int NO_INITIALIZER= 0x10;
final public static int ALLOW_CONSTRUCTOR_INITIALIZER= 0x20;
final public static int NO_FUNCTIONS= 0x40;
final public static int NO_ARRAYS= 0x80;
final public static int NO_NESTED= 0x100;
final public static int ALLOW_PARAMETER_PACKS= 0x200;
final public static int REQUIRE_SIMPLE_NAME= 0x400;
final public static int ALLOW_EMPTY_SPECIFIER= 0x01;
final public static int ALLOW_ABSTRACT= 0x02;
final public static int REQUIRE_ABSTRACT= 0x04;
final public static int ALLOW_BITFIELD= 0x08;
final public static int NO_INITIALIZER= 0x10;
final public static int NO_CTOR_STYLE_INITIALIZER= 0x20;
final public static int NO_BRACED_INITIALIZER= 0x40;
final public static int NO_FUNCTIONS= 0x80;
final public static int NO_ARRAYS= 0x100;
final public static int NO_NESTED= 0x200;
final public static int ALLOW_PARAMETER_PACKS= 0x400;
final public static int REQUIRE_SIMPLE_NAME= 0x800;
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),
C_MEMBER= new DeclarationOptions(ALLOW_BITFIELD | ALLOW_ABSTRACT),
CPP_MEMBER= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_BITFIELD),
LOCAL= new DeclarationOptions(ALLOW_CONSTRUCTOR_INITIALIZER),
PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS | REQUIRE_SIMPLE_NAME),
CPP_MEMBER= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_BITFIELD | NO_CTOR_STYLE_INITIALIZER),
LOCAL= new DeclarationOptions(0),
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= 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),
CONDITION= new DeclarationOptions(ALLOW_CONSTRUCTOR_INITIALIZER),
CONDITION= new DeclarationOptions(NO_CTOR_STYLE_INITIALIZER),
C_PARAMETER_NON_ABSTRACT= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_EMPTY_SPECIFIER);
final public boolean fAllowEmptySpecifier;
@ -46,7 +46,8 @@ public class DeclarationOptions {
final public boolean fRequireAbstract;
final public boolean fAllowBitField;
final public boolean fAllowInitializer;
final public boolean fAllowConstructorInitializer;
final public boolean fAllowBracedInitializer;
final public boolean fAllowCtorStyleInitializer;
final public boolean fAllowFunctions;
final public boolean fAllowNested;
final public boolean fAllowParameterPacks;
@ -58,7 +59,8 @@ public class DeclarationOptions {
fAllowAbstract= fRequireAbstract || (options & ALLOW_ABSTRACT) != 0;
fAllowBitField= (options & ALLOW_BITFIELD) != 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;
fAllowNested= (options & NO_NESTED) == 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
* are made available under the terms of the Eclipse Public License v1.0
* 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
* @since 5.1
*/
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.
* @noimplement This interface is not intended to be implemented by clients.
*/
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.IASTDeclarator;
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.IASTExpressionList;
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.IASTIdExpression;
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.IASTProblemExpression;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
@ -65,7 +65,7 @@ public abstract class VariableReadWriteFlags {
else if (parent instanceof IASTStatement) {
return rwInStatement(node, (IASTStatement) parent, indirection);
}
else if (parent instanceof IASTInitializerExpression) {
else if (parent instanceof IASTEqualsInitializer) {
return rwInInitializerExpression(indirection, parent);
}
else if (parent instanceof IASTArrayModifier) {
@ -113,7 +113,7 @@ public abstract class VariableReadWriteFlags {
if (expr instanceof IASTExpressionList) {
final IASTExpressionList exprList = (IASTExpressionList)expr;
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;
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTArraySubscriptExpression;
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.IArrayType;
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 ){
if( action.shouldVisitExpressions ){
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.IASTBinaryExpression;
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.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
@ -62,7 +63,11 @@ public class CASTBinaryExpression extends ASTNode implements
return operand2;
}
/**
public IASTInitializerClause getInitOperand2() {
return operand2;
}
/**
* @param op An op_X field from {@link IASTBinaryExpression}
*/
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
* 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:
* IBM - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* John Camelon (IBM) - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
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.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.ICASTDesignator;
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.IASTAmbiguityParent;
/**
* @author jcamelon
* Implementation for designated initializers
*/
public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignatedInitializer {
private IASTInitializer rhs;
public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignatedInitializer, IASTAmbiguityParent {
private IASTInitializerClause rhs;
private ICASTDesignator [] designators = null;
private int designatorsPos=-1;
public CASTDesignatedInitializer() {
}
public CASTDesignatedInitializer(IASTInitializer operandInitializer) {
setOperandInitializer(operandInitializer);
public CASTDesignatedInitializer(IASTInitializerClause init) {
setOperand(init);
}
public CASTDesignatedInitializer copy() {
@ -57,22 +64,44 @@ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignate
return designators;
}
private ICASTDesignator [] designators = null;
int designatorsPos=-1;
public IASTInitializer getOperandInitializer() {
public IASTInitializerClause getOperand() {
return rhs;
}
}
public void setOperandInitializer(IASTInitializer rhs) {
public void setOperand(IASTInitializerClause operand) {
assertNotFrozen();
this.rhs = rhs;
this.rhs = operand;
if (rhs != null) {
rhs.setParent(this);
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
@ -100,4 +129,11 @@ public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignate
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
@ -29,21 +31,29 @@ public class CASTFunctionCallExpression extends ASTNode implements
IASTFunctionCallExpression, IASTAmbiguityParent {
private IASTExpression functionName;
private IASTExpression parameter;
private IASTInitializerClause[] fArguments;
public CASTFunctionCallExpression() {
setArguments(null);
}
public CASTFunctionCallExpression(IASTExpression functionName, IASTExpression parameter) {
public CASTFunctionCallExpression(IASTExpression functionName, IASTInitializerClause[] args) {
setFunctionNameExpression(functionName);
setParameterExpression(parameter);
setArguments(args);
}
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.setParameterExpression(parameter == null ? null : parameter.copy());
copy.setOffsetAndLength(this);
return copy;
}
@ -61,17 +71,21 @@ public class CASTFunctionCallExpression extends ASTNode implements
return functionName;
}
public void setParameterExpression(IASTExpression expression) {
assertNotFrozen();
this.parameter = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(PARAMETERS);
}
public IASTInitializerClause[] getArguments() {
return fArguments;
}
public IASTExpression getParameterExpression() {
return parameter;
public void setArguments(IASTInitializerClause[] arguments) {
assertNotFrozen();
if (arguments == null) {
fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY;
} else {
fArguments= arguments;
for (IASTInitializerClause arg : arguments) {
arg.setParent(this);
arg.setPropertyInParent(ARGUMENT);
}
}
}
@Override
@ -84,33 +98,34 @@ public class CASTFunctionCallExpression extends ASTNode implements
}
}
if( functionName != null ) if( !functionName.accept( action ) ) return false;
if( parameter != null ) if( !parameter.accept( action ) ) return false;
if (functionName != null && !functionName.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;
}
for (IASTInitializerClause arg : fArguments) {
if (!arg.accept(action))
return false;
}
return true;
if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
return true;
}
public void replace(IASTNode child, IASTNode other) {
if( child == functionName )
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
functionName = (IASTExpression) other;
}
if( child == parameter)
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
parameter = (IASTExpression) other;
}
}
if (child == functionName) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
functionName = (IASTExpression) other;
}
for (int i = 0; i < fArguments.length; ++i) {
if (child == fArguments[i]) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
fArguments[i] = (IASTInitializerClause) other;
}
}
}
public IType getExpressionType() {
IType type = getFunctionNameExpression().getExpressionType();
@ -124,4 +139,38 @@ public class CASTFunctionCallExpression extends ASTNode implements
public boolean isLValue() {
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -11,21 +11,12 @@
*******************************************************************************/
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.IASTInitializerClause;
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;
/**
* @author jcamelon
*/
public class CASTInitializerExpression extends ASTNode implements
IASTInitializerExpression, IASTAmbiguityParent {
private IASTExpression expression;
@Deprecated
public class CASTInitializerExpression extends CASTEqualsInitializer implements IASTInitializerExpression {
public CASTInitializerExpression() {
}
@ -34,54 +25,12 @@ public class CASTInitializerExpression extends ASTNode implements
setExpression(expression);
}
@Override
public CASTInitializerExpression copy() {
CASTInitializerExpression copy = new CASTInitializerExpression();
copy.setExpression(expression == null ? null : expression.copy());
CASTInitializerExpression copy= new CASTInitializerExpression();
IASTInitializerClause init= getInitializerClause();
copy.setInitializerClause(init == null ? null : init.copy());
copy.setOffsetAndLength(this);
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -13,24 +13,29 @@
package org.eclipse.cdt.internal.core.dom.parser.c;
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.IASTInitializerClause;
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.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* 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 actualSize;
public CASTInitializerList copy() {
CASTInitializerList copy = new CASTInitializerList();
for(IASTInitializer initializer : getInitializers())
copy.addInitializer(initializer == null ? null : initializer.copy());
for(IASTInitializerClause initializer : getClauses())
copy.addClause(initializer == null ? null : initializer.copy());
copy.setOffsetAndLength(this);
copy.actualSize= getSize();
return copy;
@ -41,23 +46,55 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList
return actualSize;
}
public IASTInitializer[] getInitializers() {
public IASTInitializerClause[] getClauses() {
if (initializers == null)
return IASTInitializer.EMPTY_INITIALIZER_ARRAY;
initializers = ArrayUtil.trimAt(IASTInitializer.class, initializers, initializersPos);
return IASTExpression.EMPTY_EXPRESSION_ARRAY;
initializers = ArrayUtil.trimAt(IASTInitializerClause.class, initializers, initializersPos);
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();
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.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
public boolean accept( ASTVisitor action ){
@ -68,10 +105,11 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList
default : break;
}
}
IASTInitializer [] list = getInitializers();
for ( int i = 0; i < list.length; i++ ) {
if( !list[i].accept( action ) ) return false;
}
IASTInitializerClause[] list = getClauses();
for (IASTInitializerClause clause : list) {
if (!clause.accept(action))
return false;
}
if( action.shouldVisitInitializers ){
switch( action.leave( this ) ){
case ASTVisitor.PROCESS_ABORT : return false;
@ -82,4 +120,15 @@ public class CASTInitializerList extends ASTNode implements IASTInitializerList
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
* 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:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* John Camelon (IBM Rational Software) - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
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.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode;
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.IASTAmbiguityParent;
/**
* @author jcamelon
*/
public class CASTReturnStatement extends ASTNode implements
IASTReturnStatement, IASTAmbiguityParent {
@ -43,7 +42,6 @@ public class CASTReturnStatement extends ASTNode implements
return retValue;
}
public void setReturnValue(IASTExpression returnValue) {
assertNotFrozen();
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 ){
if( action.shouldVisitStatements ){
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.IASTDefaultStatement;
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.IASTExpressionList;
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.IASTIfStatement;
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.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -93,6 +94,247 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
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() {
return newTranslationUnit(null);
}
@ -107,48 +349,12 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
return tu;
}
public IASTName newName(char[] name) {
return new CASTName(name);
public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name) {
return new CASTTypedefNameSpecifier(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 IASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
return new CASTTypeId(declSpecifier, declarator);
}
public IASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
@ -159,199 +365,13 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
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) {
return new CASTTypedefNameSpecifier(name);
}
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
return new CASTSimpleDeclaration(declSpecifier);
}
public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) {
return new CASTFieldDeclarator(name, bitFieldSize);
}
public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
return new CASTCompositeTypeSpecifier(key, name);
}
public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
return new CASTElaboratedTypeSpecifier(kind, name);
}
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 IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
return new CASTUnaryExpression(operator, operand);
}
public IASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement 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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTDeclaration;
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.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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@ -186,10 +187,11 @@ public class CVariable extends PlatformObject implements IInternalVariable, ICIn
IASTDeclarator dtor= findDeclarator(name);
if (dtor != null) {
IASTInitializer init= dtor.getInitializer();
if (init instanceof IASTInitializerExpression) {
IASTExpression expr= ((IASTInitializerExpression) init).getExpression();
if (expr != null)
return Value.create(expr, maxDepth);
if (init instanceof IASTEqualsInitializer) {
final IASTInitializerClause initClause = ((IASTEqualsInitializer) init).getInitializerClause();
if (initClause instanceof IASTExpression) {
return Value.create((IASTExpression) initClause, maxDepth);
}
}
if (init != null)
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.IASTDeclarator;
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.IASTFieldDeclarator;
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.IASTIfStatement;
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.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
@ -135,13 +136,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
protected IASTInitializer optionalCInitializer() throws EndOfFileException, BacktrackException {
if (LTcatchEOF(1) == IToken.tASSIGN) {
consume();
return cInitializerClause(false);
final int offset= consume().getOffset();
IASTInitializerClause initClause = initClause(false);
IASTEqualsInitializer result= nodeFactory.newEqualsInitializer(initClause);
return setRange(result, offset, calculateEndOffset(initClause));
}
return null;
}
protected IASTInitializer cInitializerClause(boolean inAggregate) throws EndOfFileException, BacktrackException {
private IASTInitializerClause initClause(boolean inAggregate) throws EndOfFileException, BacktrackException {
final int offset = LA(1).getOffset();
if (LT(1) != IToken.tLBRACE) {
IASTExpression assignmentExpression= expression(ExprKind.eAssignment);
@ -149,9 +152,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (!ASTQueries.canContainName(assignmentExpression))
return null;
}
IASTInitializerExpression result= nodeFactory.newInitializerExpression(assignmentExpression);
setRange(result, assignmentExpression);
return result;
return assignmentExpression;
}
// it's an aggregate initializer
@ -171,22 +172,24 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
// get designator list
List<? extends ICASTDesignator> designator= designatorList();
if (designator == null) {
IASTInitializer initializer= cInitializerClause(true);
IASTInitializerClause clause= initClause(true);
// depending on value of skipTrivialItemsInCompoundInitializers initializer may be null
// in any way add the initializer such that the actual size can be tracked.
result.addInitializer(initializer);
result.addClause(clause);
} else {
// Gnu extension: the assign operator is optional
if (LT(1) == IToken.tASSIGN)
consume();
IASTInitializer initializer= cInitializerClause(false);
ICASTDesignatedInitializer desigInitializer = nodeFactory.newDesignatedInitializer(initializer);
consume(IToken.tASSIGN);
IASTInitializerClause clause= initClause(false);
ICASTDesignatedInitializer desigInitializer = nodeFactory.newDesignatedInitializer(clause);
setRange(desigInitializer, designator.get(0));
adjustLength(desigInitializer, initializer);
adjustLength(desigInitializer, clause);
for (ICASTDesignator d : designator) {
desigInitializer.addDesignator(d);
}
result.addInitializer(desigInitializer);
result.addClause(desigInitializer);
}
// can end with ", }" or "}"
@ -566,6 +569,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
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
protected IASTExpression unaryExpression(CastExprCtx ctx) throws EndOfFileException, BacktrackException {
switch (LT(1)) {
@ -609,7 +620,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (t != null) {
consume(IToken.tRPAREN);
if (LT(1) == IToken.tLBRACE) {
IASTInitializer i = cInitializerClause(false);
IASTInitializer i = (IASTInitializerList) initClause(false);
firstExpression= nodeFactory.newTypeIdInitializerExpression(t, i);
setRange(firstExpression, offset, calculateEndOffset(i));
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTExpression;
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.IArrayType;
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 {
private IASTExpression subscriptExp;
private IASTExpression arrayExpression;
private IASTInitializerClause subscriptExp;
private ICPPFunction overload= UNINITIALIZED_FUNCTION;
private IASTImplicitName[] implicitNames = null;
@ -40,15 +41,15 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
public CPPASTArraySubscriptExpression() {
}
public CPPASTArraySubscriptExpression(IASTExpression arrayExpression, IASTExpression subscriptExp) {
public CPPASTArraySubscriptExpression(IASTExpression arrayExpression, IASTInitializerClause operand) {
setArrayExpression(arrayExpression);
setSubscriptExpression(subscriptExp);
setArgument(operand);
}
public CPPASTArraySubscriptExpression copy() {
CPPASTArraySubscriptExpression copy = new CPPASTArraySubscriptExpression();
copy.setArrayExpression(arrayExpression == null ? null : arrayExpression.copy());
copy.setSubscriptExpression(subscriptExp == null ? null : subscriptExp.copy());
copy.setArgument(subscriptExp == null ? null : subscriptExp.copy());
copy.setOffsetAndLength(this);
return copy;
}
@ -67,19 +68,31 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
}
}
public IASTExpression getSubscriptExpression() {
public IASTInitializerClause getArgument() {
return subscriptExp;
}
public void setSubscriptExpression(IASTExpression expression) {
public void setArgument(IASTInitializerClause arg) {
assertNotFrozen();
subscriptExp = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(SUBSCRIPT);
subscriptExp = arg;
if (arg != null) {
arg.setParent(this);
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() {
if(implicitNames == null) {
ICPPFunction overload = getOverload();

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.IASTImplicitName;
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.IPointerType;
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 {
private int op;
private IASTExpression operand1;
private IASTExpression operand2;
private IASTInitializerClause operand2;
private IType type;
private ICPPFunction overload= UNINITIALIZED_FUNCTION;
private IASTImplicitName[] implicitNames = null;
@ -46,17 +47,17 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
public CPPASTBinaryExpression() {
}
public CPPASTBinaryExpression(int op, IASTExpression operand1, IASTExpression operand2) {
public CPPASTBinaryExpression(int op, IASTExpression operand1, IASTInitializerClause operand2) {
this.op = op;
setOperand1(operand1);
setOperand2(operand2);
setInitOperand2(operand2);
}
public CPPASTBinaryExpression copy() {
CPPASTBinaryExpression copy = new CPPASTBinaryExpression();
copy.op = op;
copy.setOperand1(operand1 == null ? null : operand1.copy());
copy.setOperand2(operand2 == null ? null : operand2.copy());
copy.setInitOperand2(operand2 == null ? null : operand2.copy());
copy.setOffsetAndLength(this);
return copy;
}
@ -69,8 +70,14 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
return operand1;
}
public IASTInitializerClause getInitOperand2() {
return operand2;
}
public IASTExpression getOperand2() {
return operand2;
if (operand2 instanceof IASTExpression)
return (IASTExpression) operand2;
return null;
}
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();
operand2 = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(OPERAND_TWO);
operand2 = operand;
if (operand != null) {
operand.setParent(this);
operand.setPropertyInParent(OPERAND_TWO);
}
}
public void setOperand2(IASTExpression expression) {
setInitOperand2(expression);
}
public IASTImplicitName[] getImplicitNames() {
if(implicitNames == null) {
ICPPFunction overload = getOverload();
@ -219,7 +230,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
if (child == operand2) {
other.setPropertyInParent(child.getPropertyInParent());
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTCompletionContext;
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.IASTNode;
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.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.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
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.IASTAmbiguityParent;
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>
*/
public class CPPASTConstructorChainInitializer extends ASTNode implements
ICPPASTConstructorChainInitializer, IASTAmbiguityParent, IASTCompletionContext {
ICPPASTConstructorChainInitializer, IASTCompletionContext {
private IASTName name;
private IASTExpression value;
private IASTInitializer initializer;
private boolean fIsPackExpansion;
public CPPASTConstructorChainInitializer() {
}
public CPPASTConstructorChainInitializer(IASTName memberInitializerid, IASTExpression initializerValue) {
setMemberInitializerId(memberInitializerid);
setInitializerValue(initializerValue);
public CPPASTConstructorChainInitializer(IASTName id, IASTInitializer initializer) {
setMemberInitializerId(id);
setInitializer(initializer);
}
public CPPASTConstructorChainInitializer copy() {
CPPASTConstructorChainInitializer copy = new CPPASTConstructorChainInitializer();
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.fIsPackExpansion= fIsPackExpansion;
return copy;
@ -76,17 +77,16 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
}
}
public IASTExpression getInitializerValue() {
return value;
public IASTInitializer getInitializer() {
return initializer;
}
public void setInitializerValue(IASTExpression expression) {
public void setInitializer(IASTInitializer init) {
assertNotFrozen();
value = expression;
if(expression != null) {
expression.setParent(this);
expression.setPropertyInParent(INITIALIZER);
initializer = init;
if(init != null) {
init.setParent(this);
init.setPropertyInParent(INITIALIZER);
}
}
@ -100,17 +100,15 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
return true;
}
}
if (name != null)
if (!name.accept(action))
return false;
if (value != null)
if (!value.accept(action))
return false;
if (name != null && !name.accept(action))
return false;
if (initializer != null && !initializer.accept(action))
return false;
if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
if (action.shouldVisitInitializers) {
if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
}
return true;
}
@ -120,21 +118,12 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
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) {
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
ICPPASTBaseSpecifier[] baseClasses = null;
for (int i = 0; i < bindings.length; i++) {
if ((bindings[i] instanceof ICPPField) || (bindings[i] instanceof ICPPNamespace)) {
continue;
} else if (bindings[i] instanceof ICPPConstructor) {
@ -184,4 +173,36 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
assertNotFrozen();
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
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.ICPPASTExpressionList;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* Initializer in parenthesis.
* Initializer list in parenthesis.
*/
public class CPPASTConstructorInitializer extends ASTNode implements
ICPPASTConstructorInitializer, IASTAmbiguityParent {
private IASTExpression exp;
private boolean fIsPackExpansion;
public class CPPASTConstructorInitializer extends ASTNode implements ICPPASTConstructorInitializer,
IASTAmbiguityParent {
private IASTInitializerClause[] fArguments;
public CPPASTConstructorInitializer() {
setArguments(null);
}
public CPPASTConstructorInitializer(IASTExpression exp) {
setExpression(exp);
public CPPASTConstructorInitializer(IASTInitializerClause[] args) {
setArguments(args);
}
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.fIsPackExpansion= fIsPackExpansion;
return copy;
}
public IASTExpression getExpression() {
return exp;
public IASTInitializerClause[] getArguments() {
return fArguments;
}
public void setExpression(IASTExpression expression) {
public void setArguments(IASTInitializerClause[] arguments) {
assertNotFrozen();
this.exp = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(EXPRESSION);
if (arguments == null) {
fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY;
} else {
fArguments= arguments;
for (IASTInitializerClause arg : arguments) {
arg.setParent(this);
arg.setPropertyInParent(ARGUMENT);
}
}
}
@ -64,31 +75,59 @@ public class CPPASTConstructorInitializer extends ASTNode implements
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;
for (IASTInitializerClause arg : fArguments) {
if (!arg.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 == exp) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
exp = (IASTExpression) other;
public void replace(IASTNode child, IASTNode other) {
for (int i = 0; i < fArguments.length; ++i) {
if (child == fArguments[i]) {
other.setPropertyInParent(child.getPropertyInParent());
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.ExpansionOverlapsBoundaryException;
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.IASTImplicitName;
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.IType;
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.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
@ -43,7 +45,7 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
ICPPASTFunctionCallExpression, IASTAmbiguityParent {
private IASTExpression functionName;
private IASTExpression parameter;
private IASTInitializerClause[] fArguments;
private IASTImplicitName[] implicitNames = null;
private IType type; // cached type of expression
@ -51,21 +53,33 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
public CPPASTFunctionCallExpression() {
setArguments(null);
}
public CPPASTFunctionCallExpression(IASTExpression functionName, IASTExpression parameter) {
public CPPASTFunctionCallExpression(IASTExpression functionName, IASTInitializerClause[] args) {
setFunctionNameExpression(functionName);
setParameterExpression(parameter);
setArguments(args);
}
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.setParameterExpression(parameter == null ? null : parameter.copy());
copy.setOffsetAndLength(this);
return copy;
}
public IASTExpression getFunctionNameExpression() {
return functionName;
}
public void setFunctionNameExpression(IASTExpression expression) {
assertNotFrozen();
this.functionName = expression;
@ -75,24 +89,23 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
}
}
public IASTExpression getFunctionNameExpression() {
return functionName;
public IASTInitializerClause[] getArguments() {
return fArguments;
}
public void setParameterExpression(IASTExpression expression) {
public void setArguments(IASTInitializerClause[] arguments) {
assertNotFrozen();
this.parameter = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(PARAMETERS);
if (arguments == null) {
fArguments= IASTExpression.EMPTY_EXPRESSION_ARRAY;
} else {
fArguments= arguments;
for (IASTInitializerClause arg : arguments) {
arg.setParent(this);
arg.setPropertyInParent(ARGUMENT);
}
}
}
public IASTExpression getParameterExpression() {
return parameter;
}
public IASTImplicitName[] getImplicitNames() {
if(implicitNames == null) {
ICPPFunction overload = getOperator();
@ -107,7 +120,7 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
n2.setBinding(overload);
n2.setAlternate(true);
if(parameter == null) {
if (fArguments.length == 0) {
int idEndOffset = ((ASTNode)functionName).getOffset() + ((ASTNode)functionName).getLength();
try {
IToken lparen = functionName.getTrailingSyntax();
@ -126,10 +139,9 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
n1.setOffsetAndLength(idEndOffset, 0);
n2.setOffsetAndLength(idEndOffset, 0);
}
}
else {
} else {
n1.computeOperatorOffsets(functionName, true);
n2.computeOperatorOffsets(parameter, true);
n2.computeOperatorOffsets(fArguments[fArguments.length-1], true);
}
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;
if(implicits != null && implicits.length > 0)
if(!implicits[0].accept(action)) return false;
if (implicits != null && implicits.length > 0)
if (!implicits[0].accept(action))
return false;
if( parameter != null ) if( !parameter.accept( action ) ) return false;
if(implicits != null && implicits.length > 0)
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;
}
for (IASTInitializerClause arg : fArguments) {
if (!arg.accept(action))
return false;
}
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;
}
public void replace(IASTNode child, IASTNode other) {
if( child == functionName )
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
functionName = (IASTExpression) other;
}
if( child == parameter )
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
parameter = (IASTExpression) other;
}
}
public void replace(IASTNode child, IASTNode other) {
if (child == functionName) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
functionName = (IASTExpression) other;
}
for (int i = 0; i < fArguments.length; ++i) {
if (child == fArguments[i]) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
fArguments[i] = (IASTExpression) other;
}
}
}
public ICPPFunction getOperator() {
if (overload == UNINITIALIZED_FUNCTION) {
@ -254,4 +267,38 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
}
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -11,85 +11,26 @@
*******************************************************************************/
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.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerExpression;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* Initializer expression.
*/
public class CPPASTInitializerExpression extends ASTNode implements
ICPPASTInitializerExpression, IASTAmbiguityParent {
private IASTExpression exp;
private boolean fIsPackExpansion;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
@Deprecated
public class CPPASTInitializerExpression extends CPPASTEqualsInitializer implements IASTInitializerExpression {
public CPPASTInitializerExpression() {
}
public CPPASTInitializerExpression(IASTExpression exp) {
setExpression(exp);
public CPPASTInitializerExpression(IASTExpression expression) {
setExpression(expression);
}
@Override
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.fIsPackExpansion= fIsPackExpansion;
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -12,75 +12,109 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
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.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList;
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.IASTAmbiguityParent;
/**
* e.g.: int a[]= {1,2,3};
*/
public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializerList {
private IASTInitializer [] initializers = null;
public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializerList, IASTAmbiguityParent {
private IASTInitializerClause [] initializers = null;
private int initializersPos=-1;
private int actualLength;
private int actualSize;
private boolean fIsPackExpansion;
public CPPASTInitializerList copy() {
CPPASTInitializerList copy = new CPPASTInitializerList();
for(IASTInitializer initializer : getInitializers())
copy.addInitializer(initializer == null ? null : initializer.copy());
for (IASTInitializerClause initializer : getClauses())
copy.addClause(initializer == null ? null : initializer.copy());
copy.setOffsetAndLength(this);
copy.actualLength= getSize();
copy.fIsPackExpansion= fIsPackExpansion;
copy.actualSize = getSize();
copy.fIsPackExpansion = fIsPackExpansion;
return copy;
}
public int getSize() {
return actualLength;
return actualSize;
}
public IASTInitializer[] getInitializers() {
public IASTInitializerClause[] getClauses() {
if (initializers == null)
return IASTInitializer.EMPTY_INITIALIZER_ARRAY;
initializers = ArrayUtil.trimAt(IASTInitializer.class, initializers, initializersPos);
return IASTExpression.EMPTY_EXPRESSION_ARRAY;
initializers = ArrayUtil.trimAt(IASTInitializerClause.class, initializers, initializersPos);
return initializers;
}
public void addInitializer(IASTInitializer d) {
assertNotFrozen();
if (d != null) {
initializers = (IASTInitializer[]) ArrayUtil.append(IASTInitializer.class, initializers,
++initializersPos, d);
d.setParent(this);
d.setPropertyInParent(NESTED_INITIALIZER);
@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 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
public boolean accept( ASTVisitor action ){
if( action.shouldVisitInitializers ){
switch( action.visit( this ) ){
if (action.shouldVisitInitializers) {
switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
IASTInitializer [] list = getInitializers();
for ( int i = 0; i < list.length; i++ ) {
if( !list[i].accept( action ) ) return false;
}
IASTInitializerClause[] list = getClauses();
for (IASTInitializerClause clause : list) {
if (!clause.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;
if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
return true;
}
public boolean isPackExpansion() {
@ -92,4 +126,15 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTDeclarator;
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.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IArrayType;
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.ICPPFunction;
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.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.CPPVisitor;
import org.eclipse.core.runtime.Assert;
public class CPPASTNewExpression extends ASTNode implements
ICPPASTNewExpression, IASTAmbiguityParent {
private boolean global;
private IASTExpression placement;
private IASTExpression initializer;
public class CPPASTNewExpression extends ASTNode implements ICPPASTNewExpression, IASTAmbiguityParent {
private IASTInitializerClause[] placement;
private IASTTypeId typeId;
private IASTInitializer initializer;
private IASTImplicitName[] implicitNames = null;
private boolean isGlobal;
private boolean isNewTypeId;
private IASTExpression [] arrayExpressions = null;
private IASTImplicitName[] implicitNames = null;
private IASTExpression[] cachedArraySizes;
public CPPASTNewExpression() {
}
public CPPASTNewExpression(IASTExpression placement,
IASTExpression initializer, IASTTypeId typeId) {
setNewPlacement(placement);
setNewInitializer(initializer);
public CPPASTNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, IASTTypeId typeId) {
setPlacementArguments(placement);
setTypeId(typeId);
setInitializer(initializer);
}
public CPPASTNewExpression copy() {
CPPASTNewExpression copy = new CPPASTNewExpression();
copy.setIsGlobal(global);
copy.setIsGlobal(isGlobal);
copy.setIsNewTypeId(isNewTypeId);
copy.setNewPlacement(placement == null ? null : placement.copy());
copy.setNewInitializer(initializer == null ? null : initializer.copy());
copy.setTypeId(typeId == null ? null : typeId.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();
if (placement != null) {
IASTInitializerClause[] plcmt = new IASTInitializerClause[placement.length];
for (int i=0; i<placement.length; i++) {
plcmt[i]= placement[i].copy();
}
copy.setPlacementArguments(plcmt);
}
copy.setTypeId(typeId == null ? null : typeId.copy());
copy.setInitializer(initializer == null ? null : initializer.copy());
copy.setOffsetAndLength(this);
return copy;
}
public boolean isGlobal() {
return global;
return isGlobal;
}
public void setIsGlobal(boolean value) {
assertNotFrozen();
global = value;
isGlobal = value;
}
public IASTExpression getNewPlacement() {
return placement;
public IASTInitializerClause[] getPlacementArguments() {
return placement;
}
public void setNewPlacement(IASTExpression expression) {
public void setPlacementArguments(IASTInitializerClause[] args) {
assertNotFrozen();
placement = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(NEW_PLACEMENT);
placement = args;
if (args != null) {
for (IASTInitializerClause arg : args) {
arg.setParent(this);
arg.setPropertyInParent(NEW_PLACEMENT);
}
}
}
public IASTExpression getNewInitializer() {
public IASTInitializer getInitializer() {
return initializer;
}
public void setNewInitializer(IASTExpression expression) {
public void setInitializer(IASTInitializer expression) {
assertNotFrozen();
initializer = expression;
if (expression != null) {
@ -133,47 +133,6 @@ public class CPPASTNewExpression extends ASTNode implements
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() {
if(implicitNames == null) {
ICPPFunction operatorFunction = CPPSemantics.findOverloadedOperator(this);
@ -219,10 +178,17 @@ public class CPPASTNewExpression extends ASTNode implements
}
}
if( placement != null ) if( !placement.accept( action ) ) return false;
if( typeId != null ) if( !typeId.accept( action ) ) return false;
if( initializer != null ) if( !initializer.accept( action ) ) return false;
if (placement != null) {
for (IASTInitializerClause arg : placement) {
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 ){
switch( action.leave( this ) ){
@ -234,20 +200,17 @@ public class CPPASTNewExpression extends ASTNode implements
return true;
}
public void replace(IASTNode child, IASTNode other) {
if( child == placement )
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
placement = (IASTExpression) other;
}
if( child == initializer )
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
initializer = (IASTExpression) other;
}
}
public void replace(IASTNode child, IASTNode other) {
if (placement != null) {
for (int i = 0; i < placement.length; ++i) {
if (child == placement[i]) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
placement[i] = (IASTExpression) other;
}
}
}
}
public IType getExpressionType() {
IType t= CPPVisitor.createType(getTypeId());
@ -260,4 +223,113 @@ public class CPPASTNewExpression extends ASTNode implements
public boolean isLValue() {
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.ICPPConstructor;
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.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -252,23 +253,21 @@ public class CPPASTQualifiedName extends CPPASTNameBase
IBinding binding = names[namesPos-1].resolveBinding();
if (binding instanceof ICPPClassType) {
ICPPClassType classType = (ICPPClassType) binding;
if (!canBeFieldAccess(classType)) {
final boolean isDeclaration = getParent().getParent() instanceof IASTSimpleDeclaration;
List<IBinding> filtered = filterClassScopeBindings(classType, bindings, isDeclaration);
if (isDeclaration && nameMatches(classType.getNameCharArray(),
n.getLookupKey(), isPrefix)) {
try {
ICPPConstructor[] constructors = classType.getConstructors();
for (int i = 0; i < constructors.length; i++) {
if (!constructors[i].isImplicit()) {
filtered.add(constructors[i]);
}
final boolean isDeclaration = getParent().getParent() instanceof IASTSimpleDeclaration;
List<IBinding> filtered = filterClassScopeBindings(classType, bindings, isDeclaration);
if (isDeclaration && nameMatches(classType.getNameCharArray(),
n.getLookupKey(), isPrefix)) {
try {
ICPPConstructor[] constructors = classType.getConstructors();
for (int i = 0; i < constructors.length; i++) {
if (!constructors[i].isImplicit()) {
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,
IBinding[] bindings, final boolean isDeclaration) {
List<IBinding> filtered = new ArrayList<IBinding>();
final boolean canBeFieldAccess= canBeFieldAccess(classType);
try {
for (final IBinding binding : bindings) {
if (binding instanceof IField) {
IField field = (IField) binding;
if (!field.isStatic())
if (!canBeFieldAccess && !field.isStatic())
continue;
} else if (binding instanceof ICPPMethod) {
ICPPMethod method = (ICPPMethod) binding;
if (method.isImplicit())
continue;
if (!isDeclaration) {
if (method.isDestructor() || method instanceof ICPPConstructor || !method.isStatic())
if (method.isDestructor() || method instanceof ICPPConstructor
|| (!canBeFieldAccess && !method.isStatic()))
continue;
}
} else if (binding instanceof IEnumerator || binding instanceof IEnumerator) {
} else if (binding instanceof IEnumerator || binding instanceof IEnumeration) {
if (isDeclaration)
continue;
} 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
* 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:
* 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;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
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.IASTReturnStatement;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* @author jcamelon
*/
public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatement, IASTAmbiguityParent {
private IASTExpression retValue;
private IASTInitializerClause retValue;
public CPPASTReturnStatement() {
}
public CPPASTReturnStatement(IASTExpression retValue) {
setReturnValue(retValue);
public CPPASTReturnStatement(IASTInitializerClause retValue) {
setReturnArgument(retValue);
}
public CPPASTReturnStatement copy() {
@ -37,16 +36,28 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen
return copy;
}
public IASTInitializerClause getReturnArgument() {
return retValue;
}
public IASTExpression getReturnValue() {
return retValue;
if (retValue instanceof IASTExpression) {
return (IASTExpression) retValue;
}
return null;
}
public void setReturnValue(IASTExpression returnValue) {
setReturnArgument(returnValue);
}
public void setReturnArgument(IASTInitializerClause arg) {
assertNotFrozen();
retValue = returnValue;
if (returnValue != null) {
returnValue.setParent(this);
returnValue.setPropertyInParent(RETURNVALUE);
retValue = arg;
if (arg != null) {
arg.setParent(this);
arg.setPropertyInParent(RETURNVALUE);
}
}
@ -62,9 +73,8 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen
break;
}
}
if (retValue != null)
if (!retValue.accept(action))
return false;
if (retValue != null && !retValue.accept(action))
return false;
if( action.shouldVisitStatements ){
switch( action.leave( this ) ){
@ -80,7 +90,7 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen
if (child == retValue) {
other.setPropertyInParent(child.getPropertyInParent());
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -13,55 +13,75 @@ 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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
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.ICPPBasicType;
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
ICPPASTSimpleTypeConstructorExpression, IASTAmbiguityParent {
ICPPASTSimpleTypeConstructorExpression {
private int st;
private IASTExpression init;
private ICPPASTDeclSpecifier fDeclSpec;
private IASTInitializer fInitializer;
private IType fType;
public CPPASTSimpleTypeConstructorExpression() {
}
public CPPASTSimpleTypeConstructorExpression(int st, IASTExpression init) {
this.st = st;
setInitialValue(init);
public CPPASTSimpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec, IASTInitializer init) {
setDeclSpecifier(declSpec);
setInitializer(init);
}
public CPPASTSimpleTypeConstructorExpression copy() {
CPPASTSimpleTypeConstructorExpression copy = new CPPASTSimpleTypeConstructorExpression();
copy.st = st;
copy.setInitialValue(init == null ? null : init.copy());
copy.setDeclSpecifier(fDeclSpec == null ? null : fDeclSpec.copy());
copy.setInitializer(fInitializer == null ? null : fInitializer.copy());
copy.setOffsetAndLength(this);
return copy;
}
public int getSimpleType() {
return st;
public ICPPASTDeclSpecifier getDeclSpecifier() {
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) {
assertNotFrozen();
st = value;
public void setInitializer(IASTInitializer initializer) {
assertNotFrozen();
fInitializer = initializer;
if (initializer != null) {
initializer.setParent(this);
initializer.setPropertyInParent(INITIALIZER);
}
}
public IASTExpression getInitialValue() {
return init;
}
public void setInitialValue(IASTExpression expression) {
assertNotFrozen();
init = expression;
if (expression != null) {
expression.setParent(this);
expression.setPropertyInParent(INITIALIZER_VALUE);
public IType getExpressionType() {
if (fType == null) {
fType= CPPVisitor.createType(fDeclSpec);
}
}
return fType;
}
public boolean isLValue() {
return false;
}
@Override
public boolean accept( ASTVisitor action ){
@ -73,7 +93,11 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements
}
}
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 ){
switch( action.leave( this ) ){
@ -85,20 +109,102 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements
return true;
}
public void replace(IASTNode child, IASTNode other) {
if( child == init )
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
init = (IASTExpression) other;
}
@Deprecated
public int getSimpleType() {
IType type= getExpressionType();
if (type instanceof ICPPBasicType) {
ICPPBasicType bt= (ICPPBasicType) type;
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() {
return new CPPBasicType(CPPBasicType.getKind(st), 0);
@Deprecated
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);
}
public boolean isLValue() {
return false;
}
@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);
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -11,130 +11,63 @@
*******************************************************************************/
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.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
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
ICPPASTTypenameExpression, IASTAmbiguityParent {
private boolean isTemplate;
private IASTName name;
private IASTExpression init;
@Deprecated
public class CPPASTTypenameExpression extends CPPASTSimpleTypeConstructorExpression implements ICPPASTTypenameExpression {
public CPPASTTypenameExpression() {
}
public CPPASTTypenameExpression(IASTName name, IASTExpression init) {
this(name, init, false);
}
public CPPASTTypenameExpression(IASTName name, IASTExpression init, boolean isTemplate) {
public CPPASTTypenameExpression(IASTName name, IASTExpression expr) {
setName(name);
setInitialValue(init);
this.isTemplate = isTemplate;
setInitialValue(expr);
}
@Override
public CPPASTTypenameExpression copy() {
super.copy();
CPPASTTypenameExpression copy = new CPPASTTypenameExpression();
copy.setName(name == null ? null : name.copy());
copy.setInitialValue(init == null ? null : init.copy());
copy.isTemplate = isTemplate;
ICPPASTDeclSpecifier declSpec = getDeclSpecifier();
IASTInitializer init = getInitializer();
copy.setDeclSpecifier(declSpec == null ? null : declSpec.copy());
copy.setInitializer(init == null ? null : init.copy());
copy.setOffsetAndLength(this);
return copy;
}
public void setIsTemplate(boolean templateTokenConsumed) {
assertNotFrozen();
isTemplate = templateTokenConsumed;
}
public boolean isTemplate() {
return isTemplate;
}
public void setName(IASTName name) {
assertNotFrozen();
this.name = name;
if (name != null) {
name.setParent(this);
name.setPropertyInParent(TYPENAME);
}
CPPASTNamedTypeSpecifier spec= new CPPASTNamedTypeSpecifier(name);
spec.setOffsetAndLength(this);
setDeclSpecifier(spec);
}
public IASTName getName() {
return name;
}
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;
IASTDeclSpecifier spec= getDeclSpecifier();
if (spec instanceof ICPPASTNamedTypeSpecifier) {
return ((ICPPASTNamedTypeSpecifier) spec).getName();
}
return null;
}
public int getRoleForName(IASTName n) {
if( n == name )
if (n == getName())
return r_reference;
return r_unclear;
}
public void replace(IASTNode child, IASTNode other) {
if( child == init )
{
other.setPropertyInParent( child.getPropertyInParent() );
other.setParent( child.getParent() );
init = (IASTExpression) other;
}
@Deprecated
public void setIsTemplate(boolean val) {
}
public IType getExpressionType() {
IBinding binding = getName().resolvePreBinding();
if (binding instanceof IType) {
return (IType) binding;
}
return null;
@Deprecated
public boolean isTemplate() {
return false;
}
public boolean isLValue() {
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.IASTDoStatement;
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.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
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.IASTName;
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.ICPPASTConstructorInitializer;
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.ICPPASTDeleteExpression;
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.ICPPASTFunctionWithTryBlock;
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.ICPPASTLinkageSpecification;
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.ICPPASTTypeId;
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.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
@ -121,32 +122,302 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return DEFAULT_INSTANCE;
}
public ICPPASTTranslationUnit newTranslationUnit() {
return newTranslationUnit(null);
public ICPPASTArrayDeclarator newArrayDeclarator(IASTName name) {
return new CPPASTArrayDeclarator(name);
}
public ICPPASTTranslationUnit newTranslationUnit(IScanner scanner) {
CPPASTTranslationUnit tu = new CPPASTTranslationUnit();
if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver());
}
tu.setASTNodeFactory(this);
return tu;
public IASTArrayModifier newArrayModifier(IASTExpression expr) {
return new CPPASTArrayModifier(expr);
}
public IASTName newName(char[] name) {
return new CPPASTName(name);
public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript) {
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() {
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) {
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) {
return new CPPASTProblem(id, arg, error);
}
@ -163,289 +434,14 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return new CPPASTProblemStatement(problem);
}
public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep) {
return new CPPASTLiteralExpression(kind, rep.toCharArray());
}
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 IASTProblemTypeId newProblemTypeId(IASTProblem problem) {
return new CPPASTProblemTypeId(problem);
}
public ICPPASTQualifiedName newQualifiedName() {
return new CPPASTQualifiedName();
}
public IASTCaseStatement newCaseStatement(IASTExpression expr) {
return new CPPASTCaseStatement(expr);
}
public IASTDefaultStatement newDefaultStatement() {
return new CPPASTDefaultStatement();
}
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) {
return new CPPASTReturnStatement(retValue);
}
public ICPPASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpr, IASTStatement body) {
return new CPPASTForStatement(init, condition, iterationExpr, body);
}
public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition,
IASTExpression iterationExpression, IASTStatement body) {
return new CPPASTForStatement(init, condition, iterationExpression, body);
}
public ICPPASTForStatement newForStatement() {
return new CPPASTForStatement();
}
public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) {
return new CPPASTDeclarationStatement(declaration);
}
public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
return new CPPASTTypeIdExpression(operator, typeId);
}
public ICPPASTDeclarator newDeclarator(IASTName name) {
return new CPPASTDeclarator(name);
}
public ICPPASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
return new CPPASTTypeId(declSpecifier, declarator);
}
public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand) {
return new CPPASTDeleteExpression(operand);
}
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
return new CPPASTSimpleDeclaration(declSpecifier);
}
public ICPPASTInitializerExpression newInitializerExpression(IASTExpression expression) {
return new CPPASTInitializerExpression(expression);
}
public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
IASTStatement bodyStatement) {
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) {
return new CPPASTUsingDeclaration(name);
}
public ICPPASTUsingDirective newUsingDirective(IASTName 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) {
return new CPPASTVisibilityLabel(visibility);
}
public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual) {
return new CPPASTBaseSpecifier(name, visibility, isVirtual);
}
public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
return new CPPASTCompositeTypeSpecifier(key, name);
}
public ICPPASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name) {
return new CPPASTNamedTypeSpecifier(name);
}
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);
}
@ -454,70 +450,20 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return new CPPASTReferenceOperator(isRValueReference);
}
public ICPPASTPointerToMember newPointerToMember(IASTName name) {
return new CPPASTPointerToMember(name);
public IASTReturnStatement newReturnStatement(IASTExpression retValue) {
return new CPPASTReturnStatement(retValue);
}
public IGPPASTPointerToMember newPointerToMemberGPP(IASTName name) {
return new GPPASTPointerToMember(name);
public IASTReturnStatement newReturnStatement(IASTInitializerClause retValue) {
return new CPPASTReturnStatement(retValue);
}
public ICPPASTInitializerList newInitializerList() {
return new CPPASTInitializerList();
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
return new CPPASTSimpleDeclaration(declSpecifier);
}
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);
public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
return new CPPASTSimpleDeclSpecifier();
}
@Deprecated
@ -525,13 +471,120 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
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);
public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(int type, IASTExpression expression) {
CPPASTSimpleTypeConstructorExpression result = new CPPASTSimpleTypeConstructorExpression();
result.setSimpleType(type);
result.setInitialValue(expression);
return result;
}
public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(
ICPPASTDeclSpecifier declSpec, IASTInitializer initializer) {
return new CPPASTSimpleTypeConstructorExpression(declSpec, initializer);
}
public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId) {
return new CPPASTSimpleTypeTemplateParameter(type, name, typeId);
}
public ICPPASTStaticAssertDeclaration newStaticAssertion(IASTExpression condition,
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) {
return new CPPASTTypeId(declSpecifier, declarator);
}
public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
return new CPPASTTypeIdExpression(operator, typeId);
}
public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
return new CPPASTTypeIdInitializerExpression(typeId, initializer);
}
@Deprecated
public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, IASTExpression expr, boolean isTemplate) {
return new CPPASTTypenameExpression(qualifiedName, expr);
}
public ICPPASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
return new CPPASTUnaryExpression(operator, operand);
}
public ICPPASTUsingDeclaration newUsingDeclaration(IASTName name) {
return new CPPASTUsingDeclaration(name);
}
public ICPPASTUsingDirective newUsingDirective(IASTName name) {
return new CPPASTUsingDirective(name);
}
public ICPPASTVisibilityLabel newVisibilityLabel(int visibility) {
return new CPPASTVisibilityLabel(visibility);
}
public ICPPASTWhileStatement newWhileStatement() {
return new CPPASTWhileStatement();
}
public ICPPASTWhileStatement newWhileStatement(IASTDeclaration condition, IASTStatement body) {
return new CPPASTWhileStatement(condition, body);
}
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
return new CPPASTWhileStatement(condition, body);
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTDeclarator;
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.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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IType;
@ -51,8 +53,14 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
if (parent instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) parent;
IASTInitializer initializer = dtor.getInitializer();
if (initializer instanceof IASTInitializerExpression)
return ((IASTInitializerExpression) initializer).getExpression();
if (initializer instanceof IASTEqualsInitializer) {
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.ICPPASTQualifiedName;
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.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
@ -117,8 +116,7 @@ public class CPPUnknownScope implements ICPPInternalUnknownScope {
}
if (!type) {
if (parent instanceof ICPPASTBaseSpecifier ||
parent instanceof ICPPASTConstructorChainInitializer ||
parent instanceof ICPPASTTypenameExpression) {
parent instanceof ICPPASTConstructorChainInitializer) {
type= true;
} else if (parent instanceof ICPPASTNamedTypeSpecifier) {
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IASTDeclaration;
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.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.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@ -396,20 +397,25 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
IASTDeclarator dtor= findDeclarator(name);
if (dtor != null) {
IASTInitializer init= dtor.getInitializer();
if (init instanceof IASTInitializerExpression) {
IASTExpression expr= ((IASTInitializerExpression) init).getExpression();
if (expr != null)
return Value.create(expr, maxDepth);
} else if (init instanceof ICPPASTConstructorInitializer) {
IType type= SemanticUtil.getUltimateTypeUptoPointers(getType());
if (type instanceof IPointerType || type instanceof IBasicType) {
IASTExpression expr= ((ICPPASTConstructorInitializer) init).getExpression();
if (expr != null)
return Value.create(expr, maxDepth);
if (init != null) {
IASTInitializerClause clause= null;
if (init instanceof IASTEqualsInitializer) {
clause= ((IASTEqualsInitializer) init).getInitializerClause();
} else if (init instanceof ICPPASTConstructorInitializer) {
IASTInitializerClause[] args= ((ICPPASTConstructorInitializer) init).getArguments();
if (args.length == 1 && args[0] instanceof IASTExpression) {
IType type= SemanticUtil.getUltimateTypeUptoPointers(getType());
if (type instanceof IPointerType || type instanceof IBasicType) {
clause= args[0];
}
}
}
}
if (init != null)
if (clause instanceof IASTExpression) {
return Value.create((IASTExpression) clause, maxDepth);
}
// mstodo handle braced init list
return Value.UNKNOWN;
}
}
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.IASTElaboratedTypeSpecifier;
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.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
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.IASTLiteralExpression;
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.ICPPASTCompositeTypeSpecifier;
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.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
@ -554,8 +555,8 @@ public class CPPSemantics {
}
if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
parent = parent.getParent();
IASTExpression exp = ((IASTFunctionCallExpression)parent).getParameterExpression();
data.setFunctionArguments(exp);
IASTInitializerClause[] args = ((IASTFunctionCallExpression)parent).getArguments();
data.setFunctionArguments(args);
}
} else if (parent instanceof ICPPASTFieldReference) {
IASTNode grand= parent.getParent();
@ -565,20 +566,30 @@ public class CPPSemantics {
grand = grand.getParent();
}
if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
IASTExpression exp = ((IASTFunctionCallExpression)parent.getParent()).getParameterExpression();
IASTInitializerClause[] exp = ((IASTFunctionCallExpression)parent.getParent()).getArguments();
data.setFunctionArguments(exp);
}
} else if (parent instanceof ICPPASTNamedTypeSpecifier && parent.getParent() instanceof IASTTypeId) {
IASTTypeId typeId = (IASTTypeId) parent.getParent();
if (typeId.getParent() instanceof ICPPASTNewExpression) {
ICPPASTNewExpression newExp = (ICPPASTNewExpression) typeId.getParent();
IASTExpression init = newExp.getNewInitializer();
data.setFunctionArguments(init);
IASTInitializer init = newExp.getInitializer();
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) {
ICPPASTConstructorChainInitializer ctorinit = (ICPPASTConstructorChainInitializer) parent;
IASTExpression val = ctorinit.getInitializerValue();
data.setFunctionArguments(val);
IASTInitializer init = ctorinit.getInitializer();
if (init instanceof ICPPASTConstructorInitializer) {
data.setFunctionArguments(((ICPPASTConstructorInitializer) init).getArguments());
} else {
// mstodo handle braced init list
}
}
return data;
@ -2350,8 +2361,8 @@ public class CPPSemantics {
// target is an object or reference being initialized
IASTDeclarator dtor = (IASTDeclarator) node.getParent();
return CPPVisitor.createType(dtor);
} else if (prop == IASTInitializerExpression.INITIALIZER_EXPRESSION) {
IASTInitializerExpression initExp = (IASTInitializerExpression) node.getParent();
} else if (prop == IASTEqualsInitializer.INITIALIZER) {
IASTEqualsInitializer initExp = (IASTEqualsInitializer) node.getParent();
if (initExp.getParent() instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) initExp.getParent();
return CPPVisitor.createType(dtor);
@ -2363,30 +2374,24 @@ public class CPPSemantics {
IASTBinaryExpression binaryExp = (IASTBinaryExpression) node.getParent();
IASTExpression exp = binaryExp.getOperand1();
return exp.getExpressionType();
} else if (prop == IASTFunctionCallExpression.PARAMETERS ||
(prop == IASTExpressionList.NESTED_EXPRESSION &&
node.getParent().getPropertyInParent() == IASTFunctionCallExpression.PARAMETERS)) {
} else if (prop == IASTFunctionCallExpression.ARGUMENT) {
// target is a parameter of a function
// if this function call refers to an overloaded function, there is more than one possibility
// for the target type
IASTFunctionCallExpression fnCall = null;
int idx = -1;
if (prop == IASTFunctionCallExpression.PARAMETERS) {
fnCall = (IASTFunctionCallExpression) node.getParent();
idx = 0;
} else {
IASTExpressionList list = (IASTExpressionList) node.getParent();
fnCall = (IASTFunctionCallExpression) list.getParent();
IASTExpression[] exps = list.getExpressions();
for (int i = 0; i < exps.length; i++) {
if (exps[i] == node) {
idx = i;
break;
}
}
}
IASTFunctionCallExpression fnCall = (IASTFunctionCallExpression) node.getParent();
int idx = 0;
final IASTInitializerClause[] arguments = fnCall.getArguments();
for (IASTInitializerClause arg : arguments) {
if (arg == node)
break;
idx++;
}
if (idx >= arguments.length)
return null;
IFunctionType[] types = getPossibleFunctions(fnCall);
if (types == null) return null;
if (types == null)
return null;
IType[] result = null;
for (int i = 0; i < types.length && types[i] != null; i++) {
IType[] pts = null;
@ -2596,21 +2601,13 @@ public class CPPSemantics {
public static ICPPFunction findOverloadedOperator(IASTFunctionCallExpression exp, ICPPClassType type) {
char[] name = OverloadableOperator.PAREN.toCharArray();
IASTExpression param = exp.getParameterExpression();
IASTExpression[] args;
if (param instanceof IASTExpressionList) {
IASTExpression[] actualArgs = ((IASTExpressionList)param).getExpressions();
ArrayList<IASTExpression> argsToPass = new ArrayList<IASTExpression>(actualArgs.length + 1);
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() };
IASTInitializerClause[] args = exp.getArguments();
ArrayList<IASTInitializerClause> argsToPass = new ArrayList<IASTInitializerClause>(args.length + 1);
argsToPass.add(exp.getFunctionNameExpression());
for (IASTInitializerClause e : args) {
argsToPass.add(e);
}
args = argsToPass.toArray(new IASTInitializerClause[argsToPass.size()]);
return findOverloadedOperator(exp, args, type, name, NonMemberMode.none);
}
@ -2627,17 +2624,15 @@ public class CPPSemantics {
IASTExpression sizeExpression = new CPPASTTypeIdExpression(IASTTypeIdExpression.op_sizeof, typeId);
sizeExpression.setParent(exp);
IASTExpression placement = exp.getNewPlacement();
List<IASTExpression> args = new ArrayList<IASTExpression>();
IASTInitializerClause[] placement = exp.getPlacementArguments();
List<IASTInitializerClause> args = new ArrayList<IASTInitializerClause>();
args.add(sizeExpression);
if (placement instanceof IASTExpressionList) {
for (IASTExpression p : ((IASTExpressionList) placement).getExpressions())
if (placement != null) {
for (IASTInitializerClause p : placement) {
args.add(p);
} else if (placement != null) {
args.add(placement);
}
}
IASTExpression[] argArray = args.toArray(new IASTExpression[args.size()]);
IASTInitializerClause[] argArray = args.toArray(new IASTInitializerClause[args.size()]);
return findOverloadedOperator(exp, argArray, type, op.toCharArray(), NonMemberMode.all);
}
@ -2758,7 +2753,7 @@ public class CPPSemantics {
}
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) {
ICPPClassType callToObjectOfClassType= null;
@ -2820,7 +2815,10 @@ public class CPPSemantics {
// 13.3.1.2.3
// However, if no operand type has class type, only those non-member functions ...
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)) {
IEnumeration enum1= 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.IASTElaboratedTypeSpecifier;
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.IASTFieldReference;
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.IASTImplicitNameOwner;
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.IASTLabelStatement;
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.IASTTranslationUnit;
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.IArrayType;
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.ICPPASTTemplatedTypeTemplateParameter;
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.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
@ -817,26 +815,37 @@ public class CPPVisitor extends ASTQueries {
} else if (parent instanceof ICPPASTTemplateDeclaration) {
return CPPTemplates.getContainingScope(node);
}
} else if (node instanceof IASTInitializerExpression) {
IASTNode parent = node.getParent();
while (!(parent instanceof IASTDeclarator || parent instanceof IASTTypeIdInitializerExpression))
parent = parent.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 (node instanceof IASTInitializer) {
if (node instanceof ICPPASTConstructorChainInitializer) {
// The name of the member initializer is resolved in the scope of the
// owner of the ctor.
ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) node;
IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent();
IBinding binding = fdef.getDeclarator().getName().resolveBinding();
try {
return binding.getScope();
} 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) {
IASTNode parent = node.getParent();
if (parent instanceof IASTForStatement) {
@ -849,27 +858,21 @@ public class CPPVisitor extends ASTQueries {
return ((ICPPASTWhileStatement) parent).getScope();
} else if (parent instanceof IASTCompoundStatement) {
return ((IASTCompoundStatement) parent).getScope();
} else if (parent instanceof ICPPASTConstructorChainInitializer) {
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) {
} else if (parent instanceof IASTArrayModifier) {
IASTNode d = parent.getParent();
while (!(d instanceof IASTDeclarator || d instanceof IASTTypeIdInitializerExpression)) {
while (!(d instanceof IASTDeclarator || d instanceof IASTExpression)) {
d = d.getParent();
}
if(d instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) d;
while (dtor.getNestedDeclarator() != null)
dtor = dtor.getNestedDeclarator();
IASTName name = dtor.getName();
if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
return getContainingScope(ns[ns.length - 1]);
}
}
if (d instanceof IASTDeclarator) {
IASTDeclarator dtor = (IASTDeclarator) d;
while (dtor.getNestedDeclarator() != null)
dtor = dtor.getNestedDeclarator();
IASTName name = dtor.getName();
if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
return getContainingScope(ns[ns.length - 1]);
}
}
} else if (parent instanceof ICPPASTTemplateId &&
node.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
node= parent; // template-id
@ -1433,7 +1436,6 @@ public class CPPVisitor extends ASTQueries {
case KIND_COMPOSITE:
if (prop == IASTNamedTypeSpecifier.NAME ||
prop == ICPPASTPointerToMember.NAME ||
prop == ICPPASTTypenameExpression.TYPENAME ||
prop == ICPPASTUsingDeclaration.NAME ||
prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME ||
prop == ICPPASTTemplateId.TEMPLATE_NAME ||
@ -1707,13 +1709,16 @@ public class CPPVisitor extends ASTQueries {
type = createType(type, declarator);
// C++ specification 8.3.4.3 and 8.5.1.4
IASTInitializer initializer= declarator.getInitializer();
if (initializer instanceof IASTInitializerList) {
IASTNode initClause= declarator.getInitializer();
if (initClause instanceof IASTEqualsInitializer) {
initClause= ((IASTEqualsInitializer) initClause).getInitializerClause();
}
if (initClause instanceof IASTInitializerList) {
IType t= SemanticUtil.getNestedType(type, TDEF);
if (t instanceof IArrayType) {
IArrayType at= (IArrayType) t;
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.IASTDeclarator;
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.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
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.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -556,25 +556,7 @@ public class LookupData {
return false;
}
public void setFunctionArguments(IASTExpression args) {
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) {
public void setFunctionArguments(IASTInitializerClause... exprs) {
functionArgs= exprs;
if (exprs.length != 0) {
IASTNode node= exprs[0];
@ -607,13 +589,17 @@ public class LookupData {
functionArgTypes[i] = SemanticUtil.getSimplifiedType(CPPVisitor.createParameterType(
pdecls[i], true));
}
} else if (functionArgs instanceof IASTExpression[]) {
IASTExpression[] exprs= (IASTExpression[]) functionArgs;
} else if (functionArgs instanceof IASTInitializerClause[]) {
IASTInitializerClause[] exprs= (IASTInitializerClause[]) functionArgs;
functionArgTypes= new IType[exprs.length];
for (int i = 0; i < exprs.length; i++) {
IASTExpression e = exprs[i];
IType etype= e.getExpressionType();
functionArgTypes[i]= SemanticUtil.getSimplifiedType(etype);
IASTInitializerClause e = exprs[i];
if (e instanceof IASTExpression) {
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() {
if (functionArgLValues == null) {
functionArgLValues= new BitSet();
IASTExpression[] args= getFunctionArguments();
IASTInitializerClause[] args= getFunctionArguments();
if (args != null) {
for (int i = 0; i < args.length; i++) {
final IASTExpression arg = args[i];
if (arg != null) {
functionArgLValues.set(i, arg.isLValue());
final IASTInitializerClause arg = args[i];
if (arg instanceof IASTExpression) {
functionArgLValues.set(i, ((IASTExpression) arg).isLValue());
} else {
// mstodo handle braced init list
}
}
} else {
@ -653,9 +641,9 @@ public class LookupData {
functionArgs= parameters;
}
public IASTExpression[] getFunctionArguments() {
if (functionArgs instanceof IASTExpression[])
return (IASTExpression[]) functionArgs;
public IASTInitializerClause[] getFunctionArguments() {
if (functionArgs instanceof IASTInitializerClause[])
return (IASTInitializerClause[]) functionArgs;
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
* All rights reserved. This program and the accompanying materials
* 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.c.ICASTPointer;
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.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
@ -81,9 +80,6 @@ public class DeclaratorWriter extends NodeWriter {
name.accept(visitor);
IASTInitializer init = getInitializer(declarator);
if(init!= null) {
if (! (init instanceof ICPPASTConstructorInitializer)) {
scribe.print(EQUALS);
}
init.accept(visitor);
}
}
@ -109,7 +105,6 @@ public class DeclaratorWriter extends NodeWriter {
private void writeInitializer(IASTStandardFunctionDeclarator funcDec) {
IASTInitializer init = getInitializer(funcDec);
if(init != null) {
scribe.print(EQUALS);
init.accept(visitor);
}
}
@ -219,7 +214,6 @@ public class DeclaratorWriter extends NodeWriter {
writeArrayModifiers(arrDecl, arrMods);
IASTInitializer initializer = getInitializer(arrDecl);
if(initializer != null) {
scribe.print(EQUALS);
initializer.accept(visitor);
}
}
@ -253,7 +247,6 @@ public class DeclaratorWriter extends NodeWriter {
fieldDecl.getBitFieldSize().accept(visitor);
IASTInitializer initializer = getInitializer(fieldDecl);
if(initializer != null) {
scribe.print(EQUALS);
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
* All rights reserved. This program and the accompanying materials
* 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;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
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.c.ICASTArrayDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
@ -43,8 +44,8 @@ public class InitializerWriter extends NodeWriter{
}
protected void writeInitializer(IASTInitializer initializer) {
if (initializer instanceof IASTInitializerExpression) {
((IASTInitializerExpression) initializer).getExpression().accept(visitor);
if (initializer instanceof IASTEqualsInitializer) {
writeEqualsInitializer((IASTEqualsInitializer) initializer);
}else if (initializer instanceof IASTInitializerList) {
writeInitializerList((IASTInitializerList) initializer);
}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) {
initializer.getMemberInitializerId().accept(visitor);
scribe.print('(');
initializer.getInitializerValue().accept(visitor);
scribe.print(')');
initializer.getInitializer().accept(visitor);
}
private void writeInitializerList(IASTInitializerList initList) {
scribe.printLBrace();
IASTInitializer[] inits = initList.getInitializers();
IASTInitializerClause[] inits = initList.getClauses();
writeNodeList(inits);
scribe.printRBrace();
}
private void writeConstructorInitializer(ICPPASTConstructorInitializer ctorInit) {
scribe.print('(');
ctorInit.getExpression().accept(visitor);
writeNodeList(ctorInit.getArguments());
scribe.print(')');
}
@ -85,7 +92,7 @@ public class InitializerWriter extends NodeWriter{
writeDesignator(designator);
}
scribe.print(EQUALS);
desigInit.getOperandInitializer().accept(visitor);
desigInit.getOperand().accept(visitor);
}
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.IASTElaboratedTypeSpecifier;
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.IASTExpressionList;
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.IASTIfStatement;
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.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -408,8 +409,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (!startNode(node)) { return PROCESS_SKIP; }
try {
if (node instanceof IASTInitializerExpression) {
visit((IASTInitializerExpression)node);
if (node instanceof IASTEqualsInitializer) {
visit((IASTEqualsInitializer) node);
} else if (node instanceof IASTInitializerList) {
visit((IASTInitializerList)node);
} else if (node instanceof ICASTDesignatedInitializer) {
@ -956,7 +957,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (!startNode(node)) { return PROCESS_SKIP; }
try {
// format like a function call
formatFunctionCallArguments(node.getExpression());
formatFunctionCallArguments(node.getArguments());
} finally {
endOfNode(node);
}
@ -965,10 +966,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(ICPPASTConstructorChainInitializer node) {
final IASTName member= node.getMemberInitializerId();
if (member!= null) {
final IASTInitializer init= node.getInitializer();
if (member!= null && init != null) {
member.accept(this);
// format like a function call
formatFunctionCallArguments(node.getInitializerValue());
init.accept(this);
} else {
formatRaw(node);
}
@ -1825,9 +1826,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(IASTFunctionCallExpression node) {
node.getFunctionNameExpression().accept(this);
IASTExpression paramExpr= node.getParameterExpression();
IASTInitializerClause[] paramExpr= node.getArguments();
if (peekNextToken() == Token.tIDENTIFIER) {
skipNode(paramExpr);
skipNode(node);
} else {
formatFunctionCallArguments(paramExpr);
}
@ -1839,17 +1840,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
*
* @param argumentExpr the argument expression, may be <code>null</code>
*/
private void formatFunctionCallArguments(IASTExpression argumentExpr) {
final List<IASTExpression> expressions;
if (argumentExpr != null) {
if (argumentExpr instanceof IASTExpressionList) {
// argument list
final IASTExpressionList exprList= (IASTExpressionList)argumentExpr;
expressions= Arrays.asList(exprList.getExpressions());
} else {
// single argument
expressions= Collections.singletonList(argumentExpr);
}
private void formatFunctionCallArguments(IASTInitializerClause[] args) {
final List<IASTInitializerClause> expressions;
if (args != null) {
expressions= Arrays.asList(args);
} else {
// no arguments
expressions= Collections.emptyList();
@ -1941,10 +1935,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
return PROCESS_SKIP;
}
private int visit(IASTInitializerExpression node) {
private int visit(IASTEqualsInitializer node) {
if (node.getPropertyInParent() == IASTInitializerList.NESTED_INITIALIZER) {
assert false;
// nested initializer expression, no need to apply extra alignment
node.getExpression().accept(this);
// node.getExpression().accept(this);
} else {
// declaration initializer
Alignment expressionAlignment= scribe.createAlignment(
@ -1960,7 +1955,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
try {
scribe.alignFragment(expressionAlignment, 0);
node.getExpression().accept(this);
node.getInitializerClause().accept(this);
ok = true;
} catch (AlignmentException e) {
@ -1975,7 +1970,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(IASTInitializerList node) {
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) {
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);
@ -2071,7 +2066,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
operand.accept(this);
break;
case IASTUnaryExpression.op_typeof:
case IASTUnaryExpression.op_alignOf:
default:
int operatorToken= peekNextToken();
@ -2277,9 +2271,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.space();
// placement
final IASTExpression newPlacement= node.getNewPlacement();
final IASTInitializerClause[] newPlacement= node.getPlacementArguments();
if (newPlacement != null) {
formatParenthesizedExpression(newPlacement);
formatFunctionCallArguments(newPlacement);
}
// type-id
@ -2295,9 +2289,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
// initializer
final IASTExpression newInitializer= node.getNewInitializer();
if (newInitializer != null || peekNextToken() == Token.tLPAREN) {
formatFunctionCallArguments(newInitializer);
final IASTInitializer newInitializer= node.getInitializer();
if (newInitializer != null) {
visit(newInitializer);
}
return PROCESS_SKIP;
}
@ -2324,6 +2318,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
private int visit(ICPPASTSimpleTypeConstructorExpression node) {
// tletodo The first part of the expression can consist of multiple tokens
scribe.printNextToken(peekNextToken());
final IASTExpression operand= node.getInitialValue();
formatParenthesizedExpression(operand);

View file

@ -118,7 +118,6 @@ public class MachOParser64 extends AbstractCExtension implements IBinaryParser {
return cppfilt;
}
@SuppressWarnings("deprecation")
protected IPath getCPPFiltPath() {
ICConfigExtensionReference ref = getConfigExtensionReference();
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
* All rights reserved. This program and the accompanying materials
* 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.IASTDeclaration;
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.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
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.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.CPPASTInitializerExpression;
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.CPPASTNamespaceDefinition;
@ -373,12 +373,12 @@ public class ExtractConstantRefactoring extends CRefactoring {
declSpec.setType(IASTSimpleDeclSpecifier.t_int);
break;
case IASTLiteralExpression.lk_string_literal:
declSpec.setType(ICPPASTSimpleDeclSpecifier.t_wchar_t);
declSpec.setType(IASTSimpleDeclSpecifier.t_wchar_t);
break;
case IASTLiteralExpression.lk_false:
//Like lk_true a boolean type
case IASTLiteralExpression.lk_true:
declSpec.setType(ICPPASTSimpleDeclSpecifier.t_bool);
declSpec.setType(IASTSimpleDeclSpecifier.t_bool);
break;
case IASTLiteralExpression.lk_this:
break;
@ -390,13 +390,13 @@ public class ExtractConstantRefactoring extends CRefactoring {
IASTDeclarator decl = new CPPASTDeclarator();
IASTName name = new CPPASTName(newName.toCharArray());
decl.setName(name);
IASTInitializerExpression init = new CPPASTInitializerExpression();
IASTEqualsInitializer init = new CPPASTEqualsInitializer();
if (target.getParent() instanceof IASTUnaryExpression) {
IASTUnaryExpression unary = (IASTUnaryExpression) target.getParent();
init.setExpression(unary);
init.setInitializerClause(unary);
} else {
CPPASTLiteralExpression expression = new CPPASTLiteralExpression(target.getKind(), target.getValue());
init.setExpression(expression);
init.setInitializerClause(expression);
}
decl.setInitializer(init);
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
* All rights reserved. This program and the accompanying materials
* 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.IASTDeclaration;
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.IASTExpressionList;
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.IASTFunctionDefinition;
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.IASTNamedTypeSpecifier;
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.CPPASTDeclarationStatement;
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.CPPASTExpressionStatement;
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.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.CPPASTQualifiedName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement;
@ -831,8 +831,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
declarator.addPointerOperator(pointer.copy());
}
IASTInitializerExpression initializer = new CPPASTInitializerExpression();
initializer.setExpression(callExpression);
IASTEqualsInitializer initializer = new CPPASTEqualsInitializer();
initializer.setInitializerClause(callExpression);
declarator.setInitializer(initializer);
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
* Public License v1.0 which accompanies this distribution, and is available at
* 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.IASTDeclarationStatement;
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.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
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.IASTName;
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.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.CPPASTInitializerExpression;
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.CPPASTSimpleDeclaration;
@ -308,8 +308,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
IASTName name = new CPPASTName(newName.toCharArray());
decl.setName(name);
IASTInitializerExpression init = new CPPASTInitializerExpression();
init.setExpression(deblock(target.copy()));
IASTEqualsInitializer init = new CPPASTEqualsInitializer();
init.setInitializerClause(deblock(target.copy()));
decl.setInitializer(init);
simple.addDeclarator(decl);