Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2010-02-17 16:23:57 +0000
committerMarkus Schorn2010-02-17 16:23:57 +0000
commit1fc47b91e1471210836462a9c55328fa494c00b1 (patch)
tree489f37caa31ca12ceb085c6723c80a0f1e756496 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom
parent608c4287b45a669ecc363e112c1deb651d936b66 (diff)
downloadorg.eclipse.cdt-1fc47b91e1471210836462a9c55328fa494c00b1.tar.gz
org.eclipse.cdt-1fc47b91e1471210836462a9c55328fa494c00b1.tar.xz
org.eclipse.cdt-1fc47b91e1471210836462a9c55328fa494c00b1.zip
Bug 302412: Syntax for c++0x initializer lists
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java87
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java107
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java40
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalEnumerationSpecifier.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java18
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java70
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEqualsInitializer.java34
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java123
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java69
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java81
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java26
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java294
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java41
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java35
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java33
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java91
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java119
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEqualsInitializer.java34
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java149
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java81
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java119
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java266
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java35
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java44
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java188
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java127
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java493
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownScope.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java34
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java699
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java110
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java93
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java52
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java27
41 files changed, 2285 insertions, 1612 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java
index 0a5044376a4..41b01aa6ef4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAmbiguousCastVsFunctionCallExpression.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java
new file mode 100644
index 00000000000..1311303fadc
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index 70b0d5b8fe0..8c523178d8d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -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;
-
- // 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;
- }
+ final int offset= consume(IToken.t_return).getOffset();
- int lastOffset = 0;
- switch (LT(1)) {
- case IToken.tSEMI:
- case IToken.tEOC:
- lastOffset = consume().getEndOffset();
- break;
- default:
- throwBacktrack(LA(1));
+ // Optional expression
+ IASTExpression expr = null;
+ if (LT(1) != IToken.tSEMI) {
+ expr = expression();
}
+ // Semicolon
+ final int endOffset= consumeOrEOC(IToken.tSEMI).getEndOffset();
- 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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java
index 13122ad584a..ac5294f63e8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java
index 14c61f38e4b..4b59b50b0f3 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousSimpleDeclaration.java
@@ -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 {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalEnumerationSpecifier.java
index 7bc08231750..5024bdd2094 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalEnumerationSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalEnumerationSpecifier.java
@@ -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 {
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
index 88ac199cb3e..84a4b24f34e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
@@ -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);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java
index 420e0188cb8..65090f6183d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArraySubscriptExpression.java
@@ -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 ) ){
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java
index 9216dada5fd..6de2baaa096 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBinaryExpression.java
@@ -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) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java
index 0b746a82d3e..14a62cfdb37 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java
@@ -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 {
+public class CASTDesignatedInitializer extends ASTNode implements ICASTDesignatedInitializer, IASTAmbiguityParent {
- private IASTInitializer rhs;
-
-
+ private IASTInitializerClause rhs;
+ private ICASTDesignator [] designators = null;
+ private int designatorsPos=-1;
+
public CASTDesignatedInitializer() {
}
- public CASTDesignatedInitializer(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;
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEqualsInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEqualsInitializer.java
new file mode 100644
index 00000000000..41ec7663860
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEqualsInitializer.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java
index dc94acc2313..6f08ca8d85e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionCallExpression.java
@@ -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});
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java
index 34abea73a86..5828125664c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerExpression.java
@@ -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,77 +11,26 @@
*******************************************************************************/
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 {
+@Deprecated
+public class CASTInitializerExpression extends CASTEqualsInitializer implements IASTInitializerExpression {
- private IASTExpression expression;
-
-
public CASTInitializerExpression() {
}
public CASTInitializerExpression(IASTExpression expression) {
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;
- }
- }
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java
index 86c7a0a839e..4acd1b729cb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java
@@ -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,24 +46,56 @@ 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 ){
if( action.shouldVisitInitializers ){
@@ -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;
+ }
+ }
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java
index e2cb41ae187..7e8520d217d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java
@@ -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 ) ){
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
index 6a952ec16cc..ee633799221 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
@@ -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,157 +94,126 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
return DEFAULT_INSTANCE;
}
- public IASTTranslationUnit newTranslationUnit() {
- return newTranslationUnit(null);
- }
-
- public IASTTranslationUnit newTranslationUnit(IScanner scanner) {
- CASTTranslationUnit tu = new CASTTranslationUnit();
-
- if (scanner != null) {
- tu.setLocationResolver(scanner.getLocationResolver());
- }
- tu.setASTNodeFactory(this);
- return tu;
- }
-
- public IASTName newName(char[] name) {
- return new CASTName(name);
- }
-
- public IASTName newName() {
- return new CASTName();
- }
-
- public IASTLiteralExpression newLiteralExpression(int kind, String rep) {
- return new CASTLiteralExpression(kind, rep.toCharArray());
+ public IASTArrayDeclarator newArrayDeclarator(IASTName name) {
+ return new CASTArrayDeclarator(name);
}
- public IASTIdExpression newIdExpression(IASTName name) {
- return new CASTIdExpression(name);
+ public ICASTArrayDesignator newArrayDesignator(IASTExpression exp) {
+ return new CASTArrayDesignator(exp);
}
- public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
- return new CASTBinaryExpression(op, expr1, expr2);
+ public ICASTArrayModifier newArrayModifier(IASTExpression expr) {
+ return new CASTArrayModifier(expr);
}
- public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3) {
- return new CASTConditionalExpression(expr1, expr2, expr3);
+ 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 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 IASTASMDeclaration newASMDeclaration(String assembly) {
+ return new CASTASMDeclaration(assembly);
}
- public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
- return new CASTUnaryExpression(operator, operand);
+ public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
+ return new CASTBinaryExpression(op, expr1, expr2);
}
- public IASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
- return new CASTTypeIdExpression(operator, typeId);
+ public IASTBreakStatement newBreakStatement() {
+ return new CASTBreakStatement();
}
- public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
- return new CASTTypeIdInitializerExpression(typeId, initializer);
+ 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 IASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
- return new CASTTypeId(declSpecifier, declarator);
+
+ public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
+ return new CASTCompositeTypeSpecifier(key, name);
}
- public IASTDeclarator newDeclarator(IASTName name) {
- return new CASTDeclarator(name);
+ public IASTCompoundStatement newCompoundStatement() {
+ return new CASTCompoundStatement();
}
- public IASTArrayDeclarator newArrayDeclarator(IASTName name) {
- return new CASTArrayDeclarator(name);
+ public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3) {
+ return new CASTConditionalExpression(expr1, expr2, expr3);
}
- public ICASTArrayModifier newArrayModifier(IASTExpression expr) {
- return new CASTArrayModifier(expr);
+ public IASTContinueStatement newContinueStatement() {
+ return new CASTContinueStatement();
}
- public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) {
- return new CASTFunctionDeclarator(name);
+ public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) {
+ return new CASTDeclarationStatement(declaration);
}
- public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations) {
- return new CASTKnRFunctionDeclarator(parameterNames, parameterDeclarations);
+ public IASTDeclarator newDeclarator(IASTName name) {
+ return new CASTDeclarator(name);
}
- public ICASTPointer newPointer() {
- return new CASTPointer();
+ public IASTDefaultStatement newDefaultStatement() {
+ return new CASTDefaultStatement();
}
- public IASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
- return new CASTParameterDeclaration(declSpec, declarator);
+ @Deprecated
+ public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer operandInitializer) {
+ CASTDesignatedInitializer result = new CASTDesignatedInitializer();
+ result.setOperandInitializer(operandInitializer);
+ return result;
}
- public IASTInitializerExpression newInitializerExpression(IASTExpression expression) {
- return new CASTInitializerExpression(expression);
+ public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializerClause clause) {
+ return new CASTDesignatedInitializer(clause);
}
- public IASTInitializerList newInitializerList() {
- return new CASTInitializerList();
+ public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
+ return new CASTDoStatement(body, condition);
}
- public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer operandInitializer) {
- return new CASTDesignatedInitializer(operandInitializer);
+ public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
+ return new CASTElaboratedTypeSpecifier(kind, name);
}
- public ICASTArrayDesignator newArrayDesignator(IASTExpression exp) {
- return new CASTArrayDesignator(exp);
+ public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
+ return new CASTEnumerationSpecifier(name);
}
- public ICASTFieldDesignator newFieldDesignator(IASTName name) {
- return new CASTFieldDesignator(name);
+ public IASTEnumerator newEnumerator(IASTName name, IASTExpression value) {
+ return new CASTEnumerator(name, value);
}
- public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name) {
- return new CASTTypedefNameSpecifier(name);
+ public IASTEqualsInitializer newEqualsInitializer(IASTInitializerClause initClause) {
+ return new CASTEqualsInitializer(initClause);
}
- public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
- return new CASTSimpleDeclaration(declSpecifier);
+ 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 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 ICASTFieldDesignator newFieldDesignator(IASTName name) {
+ return new CASTFieldDesignator(name);
}
-
- public IASTCompoundStatement newCompoundStatement() {
- return new CASTCompoundStatement();
+
+ public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
+ return new CASTFieldReference(name, owner);
}
public IASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
@@ -251,106 +221,156 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
return new CASTForStatement(init, condition, iterationExpression, body);
}
- public IASTExpressionStatement newExpressionStatement(IASTExpression expr) {
- return new CASTExpressionStatement(expr);
+ @Deprecated
+ public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) {
+ CASTFunctionCallExpression result = new CASTFunctionCallExpression(idExpr, null);
+ result.setParameterExpression(argList);
+ return result;
}
- public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) {
- return new CASTDeclarationStatement(declaration);
+ public IASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTInitializerClause[] arguments) {
+ return new CASTFunctionCallExpression(idExpr, arguments);
}
- public IASTNullStatement newNullStatement() {
- return new CASTNullStatement();
+ public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) {
+ return new CASTFunctionDeclarator(name);
}
- public IASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
- return new CASTWhileStatement(condition, body);
+ public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
+ IASTFunctionDeclarator declarator, IASTStatement bodyStatement) {
+ return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
}
- public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
- return new CASTDoStatement(body, condition);
+ public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
+ return new CASTCompoundStatementExpression(compoundStatement);
}
public IASTGotoStatement newGotoStatement(IASTName name) {
return new CASTGotoStatement(name);
}
- public IASTContinueStatement newContinueStatement() {
- return new CASTContinueStatement();
+ public IASTIdExpression newIdExpression(IASTName name) {
+ return new CASTIdExpression(name);
}
- public IASTBreakStatement newBreakStatement() {
- return new CASTBreakStatement();
+ public IASTIfStatement newIfStatement(IASTExpression expr, IASTStatement thenStat, IASTStatement elseClause) {
+ return new CASTIfStatement(expr, thenStat, elseClause);
}
- public IASTReturnStatement newReturnStatement(IASTExpression retValue) {
- return new CASTReturnStatement(retValue);
+ @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 IASTCaseStatement newCaseStatement(IASTExpression expression) {
- return new CASTCaseStatement(expression);
+ public IASTLiteralExpression newLiteralExpression(int kind, String rep) {
+ return new CASTLiteralExpression(kind, rep.toCharArray());
}
- public IASTDefaultStatement newDefaultStatement() {
- return new CASTDefaultStatement();
+ public IASTName newName() {
+ return new CASTName();
}
- public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
- return new CASTSwitchStatement(controller, body);
+ public IASTName newName(char[] name) {
+ return new CASTName(name);
}
- public IASTIfStatement newIfStatement(IASTExpression expr, IASTStatement thenStat, IASTStatement elseClause) {
- return new CASTIfStatement(expr, thenStat, elseClause);
+ public IASTNullStatement newNullStatement() {
+ return new CASTNullStatement();
}
- public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
- IASTFunctionDeclarator declarator, IASTStatement bodyStatement) {
- return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
+ 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 IASTProblemExpression newProblemExpression(IASTProblem problem) {
- return new CASTProblemExpression(problem);
+ public IASTReturnStatement newReturnStatement(IASTExpression retValue) {
+ return new CASTReturnStatement(retValue);
}
- public IASTProblem newProblem(int id, char[] arg, boolean error) {
- return new CASTProblem(id, arg, error);
+ 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);
}
- public IASTASMDeclaration newASMDeclaration(String assembly) {
- return new CASTASMDeclaration(assembly);
+ public IASTTranslationUnit newTranslationUnit(IScanner scanner) {
+ CASTTranslationUnit tu = new CASTTranslationUnit();
+
+ if (scanner != null) {
+ tu.setLocationResolver(scanner.getLocationResolver());
+ }
+ tu.setASTNodeFactory(this);
+ return tu;
}
- public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
- return new CASTEnumerationSpecifier(name);
+ public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name) {
+ return new CASTTypedefNameSpecifier(name);
}
- public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
- return new CASTSimpleDeclSpecifier();
+ public IASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
+ return new CASTTypeId(declSpecifier, declarator);
}
- public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
- return new CASTCompoundStatementExpression(compoundStatement);
+ public IASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
+ return new CASTTypeIdExpression(operator, typeId);
}
- public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling) {
- return new CASTArrayRangeDesignator(floor, ceiling);
+ public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
+ return new CASTTypeIdInitializerExpression(typeId, initializer);
}
- @Deprecated
- public org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression) {
- return new GCCASTSimpleDeclSpecifier(typeofExpression);
+ public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
+ return new CASTUnaryExpression(operator, operand);
+ }
+
+ public IASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
+ return new CASTWhileStatement(condition, body);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java
index d428d66048c..5eb21782fbc 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index 8d19058bba6..97b5ca46b61 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -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 "}"
@@ -567,6 +570,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
@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)) {
case IToken.tSTAR:
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java
index 3ba0cd9bc45..377639ab364 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArraySubscriptExpression.java
@@ -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,18 +68,30 @@ 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) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java
index dee8ac63cc1..2131a4a4ce6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryExpression.java
@@ -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;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java
index f595db5c936..62c9d27605c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorChainInitializer.java
@@ -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 (action.shouldVisitInitializers) {
- if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
- return false;
- }
+ if (initializer != null && !initializer.accept(action))
+ return false;
+
+ if (action.shouldVisitInitializers && 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);
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java
index acc4f311e31..46730475857 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java
@@ -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;
- }
+
+ 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) {
+ for (int i = 0; i < fArguments.length; ++i) {
+ if (child == fArguments[i]) {
+ other.setPropertyInParent(child.getPropertyInParent());
+ other.setParent(child.getParent());
+ fArguments[i] = (IASTExpression) other;
+ }
}
- return true;
+ }
+
+ @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;
}
- public void replace(IASTNode child, IASTNode other) {
- if (child == exp) {
- other.setPropertyInParent(child.getPropertyInParent());
- other.setParent(child.getParent());
- exp = (IASTExpression) other;
+ @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;
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEqualsInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEqualsInitializer.java
new file mode 100644
index 00000000000..30ccf032322
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEqualsInitializer.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java
index 1fc061ced49..3155097b477 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionCallExpression.java
@@ -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;
@@ -74,25 +88,24 @@ public class CPPASTFunctionCallExpression extends ASTNode implements
expression.setPropertyInParent(FUNCTION_NAME);
}
}
-
- 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;
+ for (IASTInitializerClause arg : fArguments) {
+ if (!arg.accept(action))
+ return false;
+ }
- if(implicits != null && implicits.length > 0)
- if(!implicits[1].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;
- }
- }
+ 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});
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java
index cd9cf256770..716501b041a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerExpression.java
@@ -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;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
-/**
- * Initializer expression.
- */
-public class CPPASTInitializerExpression extends ASTNode implements
- ICPPASTInitializerExpression, IASTAmbiguityParent {
+@Deprecated
+public class CPPASTInitializerExpression extends CPPASTEqualsInitializer implements IASTInitializerExpression {
- private IASTExpression exp;
- private boolean fIsPackExpansion;
-
-
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;
- }
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java
index aaafa5126ac..39d86f66c81 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java
@@ -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,77 +12,111 @@
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 IASTExpression.EMPTY_EXPRESSION_ARRAY;
+ initializers = ArrayUtil.trimAt(IASTInitializerClause.class, initializers, initializersPos);
+ return initializers;
+ }
+
+ @Deprecated
+ public IASTInitializer[] getInitializers() {
+ IASTInitializerClause[] clauses= getClauses();
+ if (clauses.length == 0)
return IASTInitializer.EMPTY_INITIALIZER_ARRAY;
- initializers = ArrayUtil.trimAt(IASTInitializer.class, initializers, initializersPos);
- return initializers;
+ 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;
+ }
+ }
+ return inits;
}
- public void addInitializer(IASTInitializer d) {
- assertNotFrozen();
- if (d != null) {
- initializers = (IASTInitializer[]) ArrayUtil.append(IASTInitializer.class, initializers,
- ++initializersPos, d);
- d.setParent(this);
+ 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);
- }
- actualLength++;
- }
+ }
+ 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;
- }
-
- if( action.shouldVisitInitializers ){
- switch( action.leave( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
+ IASTInitializerClause[] list = getClauses();
+ for (IASTInitializerClause clause : list) {
+ if (!clause.accept(action))
+ return false;
}
- return true;
+
+ if (action.shouldVisitInitializers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
+ return false;
+
+ return true;
}
-
+
public boolean isPackExpansion() {
return fIsPackExpansion;
}
@@ -91,5 +125,16 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer
assertNotFrozen();
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;
+ }
+ }
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java
index 5d8d2493a7b..c829f575af5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java
@@ -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 boolean isNewTypeId;
-
- private IASTExpression [] arrayExpressions = null;
-
+ private IASTInitializer initializer;
private IASTImplicitName[] implicitNames = null;
-
+ private boolean isGlobal;
+ private boolean isNewTypeId;
+
+ 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) {
@@ -132,47 +132,6 @@ public class CPPASTNewExpression extends ASTNode implements
assertNotFrozen();
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) {
@@ -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);
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java
index ea60a612a82..8d4bc38fde5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java
@@ -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) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java
index 9a1721fe63b..36bea044360 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java
@@ -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;
}
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java
index 611ed09ce1a..b477eb1c8f4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleTypeConstructorExpression.java
@@ -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,56 +13,76 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.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 void setSimpleType(int value) {
- assertNotFrozen();
- st = value;
+ public IASTInitializer getInitializer() {
+ return fInitializer;
+ }
+
+ public void setDeclSpecifier(ICPPASTDeclSpecifier declSpec) {
+ assertNotFrozen();
+ fDeclSpec = declSpec;
+ if (declSpec != null) {
+ declSpec.setParent(this);
+ declSpec.setPropertyInParent(TYPE_SPECIFIER);
+ }
}
- public IASTExpression getInitialValue() {
- return init;
+ public void setInitializer(IASTInitializer initializer) {
+ assertNotFrozen();
+ fInitializer = initializer;
+ if (initializer != null) {
+ initializer.setParent(this);
+ initializer.setPropertyInParent(INITIALIZER);
+ }
}
- 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 ){
if( action.shouldVisitExpressions ){
@@ -72,8 +92,12 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements
default : break;
}
}
-
- if( init != null ) if( !init.accept( action ) ) return false;
+
+ if (fDeclSpec != null && !fDeclSpec.accept(action))
+ return false;
+
+ if (fInitializer != null && !fInitializer.accept(action))
+ return false;
if( action.shouldVisitExpressions ){
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);
+ }
+
+ @Deprecated
+ public IASTExpression getInitialValue() {
+ if (fInitializer instanceof ICPPASTConstructorInitializer) {
+ return ((ICPPASTConstructorInitializer) fInitializer).getExpression();
+ }
+ return null;
+ }
+
+ @Deprecated
+ public void setInitialValue(IASTExpression expression) {
+ ICPPASTConstructorInitializer init= new CPPASTConstructorInitializer();
+ init.setExpression(expression);
+ setInitializer(init);
}
-
- public boolean isLValue() {
- return false;
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java
index 625464d0de3..39030d0c3b0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypenameExpression.java
@@ -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 {
+@Deprecated
+public class CPPASTTypenameExpression extends CPPASTSimpleTypeConstructorExpression implements ICPPASTTypenameExpression {
- private boolean isTemplate;
- private IASTName name;
- private IASTExpression init;
-
-
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;
+ IASTDeclSpecifier spec= getDeclSpecifier();
+ if (spec instanceof ICPPASTNamedTypeSpecifier) {
+ return ((ICPPASTNamedTypeSpecifier) spec).getName();
+ }
+ return null;
}
- public void setInitialValue(IASTExpression expressionList) {
- assertNotFrozen();
- init = expressionList;
- if (expressionList != null) {
- expressionList.setParent(this);
- expressionList.setPropertyInParent(INITIAL_VALUE);
- }
- }
-
- public IASTExpression getInitialValue() {
- return init;
- }
-
- @Override
- public boolean accept( ASTVisitor action ){
- if( action.shouldVisitExpressions ){
- switch( action.visit( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
-
- if( name != null ) if( !name.accept( action ) ) return false;
- if( init != null ) if( !init.accept( action ) ) return false;
-
- if( action.shouldVisitExpressions ){
- switch( action.leave( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
- }
- }
- return true;
- }
-
public int getRoleForName(IASTName n) {
- 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;
- }
-
- }
-
- public IType getExpressionType() {
- IBinding binding = getName().resolvePreBinding();
- if (binding instanceof IType) {
- return (IType) binding;
- }
- return null;
+ @Deprecated
+ public void setIsTemplate(boolean val) {
}
- public boolean isLValue() {
- return false;
- }
+ @Deprecated
+ public boolean isTemplate() {
+ return false;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
index 5013a720675..85c5e4d0b7d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
@@ -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,417 +122,469 @@ 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 IASTName newName() {
- return new CPPASTName();
+ public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr,
+ IASTInitializerClause subscript) {
+ return new CPPASTArraySubscriptExpression(arrayExpr, subscript);
}
- public ICPPASTOperatorName newOperatorName(char[] name) {
- return new CPPASTOperatorName(name);
+ public IASTASMDeclaration newASMDeclaration(String assembly) {
+ return new CPPASTASMDeclaration(assembly);
}
- public IASTProblem newProblem(int id, char[] arg, boolean error) {
- return new CPPASTProblem(id, arg, error);
+ public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual) {
+ return new CPPASTBaseSpecifier(name, visibility, isVirtual);
}
- public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem) {
- return new CPPASTProblemDeclaration(problem);
+ public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
+ return new CPPASTBinaryExpression(op, expr1, expr2);
}
- public IASTProblemExpression newProblemExpression(IASTProblem problem) {
- return new CPPASTProblemExpression(problem);
+ public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTInitializerClause expr2) {
+ return new CPPASTBinaryExpression(op, expr1, expr2);
}
- public IASTProblemStatement newProblemStatement(IASTProblem problem) {
- return new CPPASTProblemStatement(problem);
+ public IASTBreakStatement newBreakStatement() {
+ return new CPPASTBreakStatement();
}
- public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep) {
- return new CPPASTLiteralExpression(kind, rep.toCharArray());
+ public IASTCaseStatement newCaseStatement(IASTExpression expr) {
+ return new CPPASTCaseStatement(expr);
}
- public ICPPASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
- return new CPPASTUnaryExpression(operator, operand);
+ public ICPPASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand) {
+ return new CPPASTCastExpression(operator, typeId, operand);
}
- public IASTIdExpression newIdExpression(IASTName name) {
- return new CPPASTIdExpression(name);
+ public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body) {
+ return new CPPASTCatchHandler(decl, body);
}
- public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTExpression subscript) {
- return new CPPASTArraySubscriptExpression(arrayExpr, subscript);
+ public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
+ return new CPPASTCompositeTypeSpecifier(key, name);
}
- public ICPPASTExpressionList newExpressionList() {
- return new CPPASTExpressionList();
+ public IASTCompoundStatement newCompoundStatement() {
+ return new CPPASTCompoundStatement();
}
- public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) {
- return new CPPASTFunctionCallExpression(idExpr, argList);
+ public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3) {
+ return new CPPASTConditionalExpression(expr1, expr2, expr3);
}
- public ICPPASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand) {
- return new CPPASTCastExpression(operator, typeId, operand);
+ @Deprecated
+ public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName id, IASTExpression expression) {
+ ICPPASTConstructorChainInitializer result= new CPPASTConstructorChainInitializer(id, null);
+ result.setInitializerValue(expression);
+ return result;
}
- public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, IASTTypeId typeId) {
- return new CPPASTNewExpression(placement, initializer, typeId);
+ public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName id, IASTInitializer init) {
+ return new CPPASTConstructorChainInitializer(id, init);
}
- public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
- return new CPPASTBinaryExpression(op, expr1, expr2);
+ @Deprecated
+ public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp) {
+ ICPPASTConstructorInitializer result= new CPPASTConstructorInitializer(null);
+ result.setExpression(exp);
+ return result;
}
- public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3) {
- return new CPPASTConditionalExpression(expr1, expr2, expr3);
+ 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 IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
- return new CPPASTTypeIdInitializerExpression(typeId, initializer);
+ public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) {
+ return new CPPASTDeclarationStatement(declaration);
}
- public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
- return new CPPASTFieldReference(name, owner);
+ public ICPPASTDeclarator newDeclarator(IASTName name) {
+ return new CPPASTDeclarator(name);
}
- public ICPPASTTemplateId newTemplateId(IASTName templateName) {
- return new CPPASTTemplateId(templateName);
+ public IASTDefaultStatement newDefaultStatement() {
+ return new CPPASTDefaultStatement();
}
- public ICPPASTConversionName newConversionName(IASTTypeId typeId) {
- return new CPPASTConversionName(typeId);
+ public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand) {
+ return new CPPASTDeleteExpression(operand);
}
- public ICPPASTQualifiedName newQualifiedName() {
- return new CPPASTQualifiedName();
+ public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
+ return new CPPASTDoStatement(body, condition);
}
- public IASTCaseStatement newCaseStatement(IASTExpression expr) {
- return new CPPASTCaseStatement(expr);
+ public ICPPASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
+ return new CPPASTElaboratedTypeSpecifier(kind, name);
}
- public IASTDefaultStatement newDefaultStatement() {
- return new CPPASTDefaultStatement();
+ public IASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
+ return new CPPASTEnumerationSpecifier(name);
}
- public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement) {
- return new CPPASTLabelStatement(name, nestedStatement);
+ public IASTEnumerator newEnumerator(IASTName name, IASTExpression value) {
+ return new CPPASTEnumerator(name, value);
}
- public IASTExpressionStatement newExpressionStatement(IASTExpression expression) {
- return new CPPASTExpressionStatement(expression);
+ public IASTEqualsInitializer newEqualsInitializer(IASTInitializerClause initClause) {
+ return new CPPASTEqualsInitializer(initClause);
}
- public IASTNullStatement newNullStatement() {
- return new CPPASTNullStatement();
+ public ICPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiation(IASTDeclaration declaration) {
+ return new CPPASTExplicitTemplateInstantiation(declaration);
}
- public IASTCompoundStatement newCompoundStatement() {
- return new CPPASTCompoundStatement();
+ @Deprecated
+ public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiationGPP(IASTDeclaration declaration) {
+ return new GPPASTExplicitTemplateInstantiation(declaration);
}
- public ICPPASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause) {
- return new CPPASTIfStatement(condition, then, elseClause);
+ public ICPPASTExpressionList newExpressionList() {
+ return new CPPASTExpressionList();
}
- public ICPPASTIfStatement newIfStatement(IASTDeclaration condition, IASTStatement then, IASTStatement elseClause) {
- return new CPPASTIfStatement(condition, then, elseClause);
+ public IASTExpressionStatement newExpressionStatement(IASTExpression expression) {
+ return new CPPASTExpressionStatement(expression);
}
- public ICPPASTIfStatement newIfStatement() {
- return new CPPASTIfStatement();
+ public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) {
+ return new CPPASTFieldDeclarator(name, bitFieldSize);
}
- public ICPPASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
- return new CPPASTSwitchStatement(controller, body);
+ public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
+ return new CPPASTFieldReference(name, owner);
}
- public ICPPASTSwitchStatement newSwitchStatement(IASTDeclaration controller, IASTStatement body) {
- return new CPPASTSwitchStatement(controller, body);
+ public ICPPASTForStatement newForStatement() {
+ return new CPPASTForStatement();
}
- public ICPPASTSwitchStatement newSwitchStatement() {
- return new CPPASTSwitchStatement();
+ public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition,
+ IASTExpression iterationExpression, IASTStatement body) {
+ return new CPPASTForStatement(init, condition, iterationExpression, body);
}
- public ICPPASTWhileStatement newWhileStatement(IASTDeclaration condition, IASTStatement body) {
- return new CPPASTWhileStatement(condition, body);
+ public ICPPASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
+ IASTExpression iterationExpr, IASTStatement body) {
+ return new CPPASTForStatement(init, condition, iterationExpr, body);
}
- public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body) {
- return new CPPASTWhileStatement(condition, body);
- }
-
- public ICPPASTWhileStatement newWhileStatement() {
- return new CPPASTWhileStatement();
+ @Deprecated
+ public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTExpression argList) {
+ CPPASTFunctionCallExpression result = new CPPASTFunctionCallExpression(idExpr, null);
+ result.setParameterExpression(argList);
+ return result;
}
- public IASTDoStatement newDoStatement(IASTStatement body, IASTExpression condition) {
- return new CPPASTDoStatement(body, condition);
+ public ICPPASTFunctionCallExpression newFunctionCallExpression(IASTExpression idExpr, IASTInitializerClause[] arguments) {
+ return new CPPASTFunctionCallExpression(idExpr, arguments);
}
- public IASTBreakStatement newBreakStatement() {
- return new CPPASTBreakStatement();
- }
-
- public IASTContinueStatement newContinueStatement() {
- return new CPPASTContinueStatement();
+ public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name) {
+ return new CPPASTFunctionDeclarator(name);
}
- public IASTGotoStatement newGotoStatement(IASTName name) {
- return new CPPASTGotoStatement(name);
+ public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
+ IASTStatement bodyStatement) {
+ return new CPPASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
}
- public IASTReturnStatement newReturnStatement(IASTExpression retValue) {
- return new CPPASTReturnStatement(retValue);
+ public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
+ IASTStatement bodyStatement) {
+ return new CPPASTFunctionWithTryBlock(declSpecifier, declarator, bodyStatement);
}
- public ICPPASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
- IASTExpression iterationExpr, IASTStatement body) {
- return new CPPASTForStatement(init, condition, iterationExpr, body);
+ public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
+ return new CPPASTCompoundStatementExpression(compoundStatement);
}
- public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition,
- IASTExpression iterationExpression, IASTStatement body) {
- return new CPPASTForStatement(init, condition, iterationExpression, body);
+ public IASTGotoStatement newGotoStatement(IASTName name) {
+ return new CPPASTGotoStatement(name);
}
- public ICPPASTForStatement newForStatement() {
- return new CPPASTForStatement();
+ public IASTIdExpression newIdExpression(IASTName name) {
+ return new CPPASTIdExpression(name);
}
- public IASTDeclarationStatement newDeclarationStatement(IASTDeclaration declaration) {
- return new CPPASTDeclarationStatement(declaration);
+ public ICPPASTIfStatement newIfStatement() {
+ return new CPPASTIfStatement();
}
- public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
- return new CPPASTTypeIdExpression(operator, typeId);
+ public ICPPASTIfStatement newIfStatement(IASTDeclaration condition, IASTStatement then, IASTStatement elseClause) {
+ return new CPPASTIfStatement(condition, then, elseClause);
}
- public ICPPASTDeclarator newDeclarator(IASTName name) {
- return new CPPASTDeclarator(name);
+ public ICPPASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause) {
+ return new CPPASTIfStatement(condition, then, elseClause);
}
- public ICPPASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
- return new CPPASTTypeId(declSpecifier, declarator);
+ @Deprecated
+ public org.eclipse.cdt.core.dom.ast.IASTInitializerExpression newInitializerExpression(IASTExpression expression) {
+ return new CPPASTInitializerExpression(expression);
}
- public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand) {
- return new CPPASTDeleteExpression(operand);
+ public ICPPASTInitializerList newInitializerList() {
+ return new CPPASTInitializerList();
}
- public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
- return new CPPASTSimpleDeclaration(declSpecifier);
+ public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement) {
+ return new CPPASTLabelStatement(name, nestedStatement);
}
- public ICPPASTInitializerExpression newInitializerExpression(IASTExpression expression) {
- return new CPPASTInitializerExpression(expression);
+ public ICPPASTLinkageSpecification newLinkageSpecification(String literal) {
+ return new CPPASTLinkageSpecification(literal);
}
- public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
- IASTStatement bodyStatement) {
- return new CPPASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
+ public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep) {
+ return new CPPASTLiteralExpression(kind, rep.toCharArray());
}
- public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
- return new CPPASTSimpleDeclSpecifier();
+ public IASTName newName() {
+ return new CPPASTName();
}
- public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name) {
- return new CPPASTFunctionDeclarator(name);
+ public IASTName newName(char[] name) {
+ return new CPPASTName(name);
}
- public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(int type, IASTExpression expression) {
- return new CPPASTSimpleTypeConstructorExpression(type, expression);
+ public ICPPASTNamespaceAlias newNamespaceAlias(IASTName alias, IASTName qualifiedName) {
+ return new CPPASTNamespaceAlias(alias, qualifiedName);
}
- public ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, IASTExpression expr, boolean isTemplate) {
- return new CPPASTTypenameExpression(qualifiedName, expr, isTemplate);
+ public ICPPASTNamespaceDefinition newNamespaceDefinition(IASTName name) {
+ return new CPPASTNamespaceDefinition(name);
}
- public IASTASMDeclaration newASMDeclaration(String assembly) {
- return new CPPASTASMDeclaration(assembly);
+ @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 ICPPASTNamespaceAlias newNamespaceAlias(IASTName alias, IASTName qualifiedName) {
- return new CPPASTNamespaceAlias(alias, qualifiedName);
+ public ICPPASTNewExpression newNewExpression(IASTInitializerClause[] placement, IASTInitializer initializer, IASTTypeId typeId) {
+ return new CPPASTNewExpression(placement, initializer, typeId);
}
- public ICPPASTUsingDeclaration newUsingDeclaration(IASTName name) {
- return new CPPASTUsingDeclaration(name);
+ public IASTNullStatement newNullStatement() {
+ return new CPPASTNullStatement();
}
- public ICPPASTUsingDirective newUsingDirective(IASTName name) {
- return new CPPASTUsingDirective(name);
+ public ICPPASTOperatorName newOperatorName(char[] name) {
+ return new CPPASTOperatorName(name);
}
- public ICPPASTLinkageSpecification newLinkageSpecification(String literal) {
- return new CPPASTLinkageSpecification(literal);
+ public ICPPASTPackExpansionExpression newPackExpansionExpression(IASTExpression pattern) {
+ return new CPPASTPackExpansionExpression(pattern);
}
- public ICPPASTNamespaceDefinition newNamespaceDefinition(IASTName name) {
- return new CPPASTNamespaceDefinition(name);
+ public ICPPASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
+ return new CPPASTParameterDeclaration(declSpec, declarator);
}
- public ICPPASTTemplateDeclaration newTemplateDeclaration(IASTDeclaration declaration) {
- return new CPPASTTemplateDeclaration(declaration);
+ public IASTPointer newPointer() {
+ return new CPPASTPointer();
}
- public ICPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiation(IASTDeclaration declaration) {
- return new CPPASTExplicitTemplateInstantiation(declaration);
+ public IGPPASTPointer newPointerGPP() {
+ return new GPPASTPointer();
+ }
+
+ public ICPPASTPointerToMember newPointerToMember(IASTName name) {
+ return new CPPASTPointerToMember(name);
}
- public ICPPASTTemplateSpecialization newTemplateSpecialization(IASTDeclaration declaration) {
- return new CPPASTTemplateSpecialization(declaration);
+ public IGPPASTPointerToMember newPointerToMemberGPP(IASTName name) {
+ return new GPPASTPointerToMember(name);
}
- public ICPPASTTryBlockStatement newTryBlockStatement(IASTStatement body) {
- return new CPPASTTryBlockStatement(body);
+ public IASTProblem newProblem(int id, char[] arg, boolean error) {
+ return new CPPASTProblem(id, arg, error);
}
- public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body) {
- return new CPPASTCatchHandler(decl, body);
+ public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem) {
+ return new CPPASTProblemDeclaration(problem);
}
- public IASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
- return new CPPASTEnumerationSpecifier(name);
+ public IASTProblemExpression newProblemExpression(IASTProblem problem) {
+ return new CPPASTProblemExpression(problem);
}
- public IASTEnumerator newEnumerator(IASTName name, IASTExpression value) {
- return new CPPASTEnumerator(name, value);
+ public IASTProblemStatement newProblemStatement(IASTProblem problem) {
+ return new CPPASTProblemStatement(problem);
}
- public ICPPASTVisibilityLabel newVisibilityLabel(int visibility) {
- return new CPPASTVisibilityLabel(visibility);
+ public IASTProblemTypeId newProblemTypeId(IASTProblem problem) {
+ return new CPPASTProblemTypeId(problem);
}
- public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual) {
- return new CPPASTBaseSpecifier(name, visibility, isVirtual);
+ public ICPPASTQualifiedName newQualifiedName() {
+ return new CPPASTQualifiedName();
}
- public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
- return new CPPASTCompositeTypeSpecifier(key, name);
+ public ICPPASTReferenceOperator newReferenceOperator() {
+ return new CPPASTReferenceOperator(false);
}
- public ICPPASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name) {
- return new CPPASTNamedTypeSpecifier(name);
+ public ICPPASTReferenceOperator newReferenceOperator(boolean isRValueReference) {
+ return new CPPASTReferenceOperator(isRValueReference);
}
- public ICPPASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
- return new CPPASTElaboratedTypeSpecifier(kind, name);
+ public IASTReturnStatement newReturnStatement(IASTExpression retValue) {
+ return new CPPASTReturnStatement(retValue);
}
- public IASTPointer newPointer() {
- return new CPPASTPointer();
+ public IASTReturnStatement newReturnStatement(IASTInitializerClause retValue) {
+ return new CPPASTReturnStatement(retValue);
}
- public IGPPASTPointer newPointerGPP() {
- return new GPPASTPointer();
+ public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
+ return new CPPASTSimpleDeclaration(declSpecifier);
}
- public ICPPASTReferenceOperator newReferenceOperator() {
- return new CPPASTReferenceOperator(false);
+ public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
+ return new CPPASTSimpleDeclSpecifier();
}
- public ICPPASTReferenceOperator newReferenceOperator(boolean isRValueReference) {
- return new CPPASTReferenceOperator(isRValueReference);
+ @Deprecated
+ public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP() {
+ return new GPPASTSimpleDeclSpecifier();
}
- public ICPPASTPointerToMember newPointerToMember(IASTName name) {
- return new CPPASTPointerToMember(name);
+ @Deprecated
+ public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(int type, IASTExpression expression) {
+ CPPASTSimpleTypeConstructorExpression result = new CPPASTSimpleTypeConstructorExpression();
+ result.setSimpleType(type);
+ result.setInitialValue(expression);
+ return result;
}
- public IGPPASTPointerToMember newPointerToMemberGPP(IASTName name) {
- return new GPPASTPointerToMember(name);
+ public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(
+ ICPPASTDeclSpecifier declSpec, IASTInitializer initializer) {
+ return new CPPASTSimpleTypeConstructorExpression(declSpec, initializer);
}
- public ICPPASTInitializerList newInitializerList() {
- return new CPPASTInitializerList();
+ public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId) {
+ return new CPPASTSimpleTypeTemplateParameter(type, name, typeId);
}
- public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp) {
- return new CPPASTConstructorInitializer(exp);
+ public ICPPASTStaticAssertDeclaration newStaticAssertion(IASTExpression condition,
+ ICPPASTLiteralExpression message) {
+ return new CPPASTStaticAssertionDeclaration(condition, message);
}
- public IASTArrayModifier newArrayModifier(IASTExpression expr) {
- return new CPPASTArrayModifier(expr);
+ public ICPPASTSwitchStatement newSwitchStatement() {
+ return new CPPASTSwitchStatement();
}
- public ICPPASTArrayDeclarator newArrayDeclarator(IASTName name) {
- return new CPPASTArrayDeclarator(name);
+ public ICPPASTSwitchStatement newSwitchStatement(IASTDeclaration controller, IASTStatement body) {
+ return new CPPASTSwitchStatement(controller, body);
}
- public ICPPASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
- return new CPPASTParameterDeclaration(declSpec, declarator);
+ 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 ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName memberInitializerid, IASTExpression initializerValue) {
- return new CPPASTConstructorChainInitializer(memberInitializerid, initializerValue);
+ public ICPPASTTemplateId newTemplateId(IASTName templateName) {
+ return new CPPASTTemplateId(templateName);
}
- public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
- IASTStatement bodyStatement) {
- return new CPPASTFunctionWithTryBlock(declSpecifier, declarator, bodyStatement);
+ public ICPPASTTemplateSpecialization newTemplateSpecialization(IASTDeclaration declaration) {
+ return new CPPASTTemplateSpecialization(declaration);
}
- public ICPPASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) {
- return new CPPASTFieldDeclarator(name, bitFieldSize);
+ public ICPPASTTranslationUnit newTranslationUnit() {
+ return newTranslationUnit(null);
}
- public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId) {
- return new CPPASTSimpleTypeTemplateParameter(type, name, typeId);
+ public ICPPASTTranslationUnit newTranslationUnit(IScanner scanner) {
+ CPPASTTranslationUnit tu = new CPPASTTranslationUnit();
+
+ if (scanner != null) {
+ tu.setLocationResolver(scanner.getLocationResolver());
+ }
+ tu.setASTNodeFactory(this);
+ return tu;
}
- public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue) {
- return new CPPASTTemplatedTypeTemplateParameter(name, defaultValue);
+ public ICPPASTTryBlockStatement newTryBlockStatement(IASTStatement body) {
+ return new CPPASTTryBlockStatement(body);
}
- public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
- return new CPPASTCompoundStatementExpression(compoundStatement);
+ public ICPPASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name) {
+ return new CPPASTNamedTypeSpecifier(name);
}
- public IASTProblemTypeId newProblemTypeId(IASTProblem problem) {
- return new CPPASTProblemTypeId(problem);
+ public ICPPASTTypeId newTypeId(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
+ return new CPPASTTypeId(declSpecifier, declarator);
}
- public ICPPASTStaticAssertDeclaration newStaticAssertion(IASTExpression condition,
- ICPPASTLiteralExpression message) {
- return new CPPASTStaticAssertionDeclaration(condition, message);
+ public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId) {
+ return new CPPASTTypeIdExpression(operator, typeId);
}
- public ICPPASTPackExpansionExpression newPackExpansionExpression(IASTExpression pattern) {
- return new CPPASTPackExpansionExpression(pattern);
+ public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
+ return new CPPASTTypeIdInitializerExpression(typeId, initializer);
}
-
+
@Deprecated
- public org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP() {
- return new GPPASTSimpleDeclSpecifier();
+ 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);
}
- /**
- * @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 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);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java
index 75cf9a85905..55cdcaac118 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateNonTypeParameter.java
@@ -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
+ }
+ }
}
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownScope.java
index c502fddf109..f90408c2f8c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownScope.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java
index 157a94eb970..d8e851ddf60 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java
@@ -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;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index d073069b6b9..691d7fe1ef1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -32,11 +32,14 @@ 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.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
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.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
@@ -76,8 +79,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.ICPPASTInitializer;
-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;
@@ -86,6 +87,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpandable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
@@ -103,7 +105,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;
@@ -221,7 +222,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
loop: for(;;) {
boolean forceTemplate= false;
if (qname != null && LT(1) == IToken.t_template) {
- consume().getEndOffset();
+ consume();
forceTemplate= true;
}
@@ -695,11 +696,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
int lt1;
int conditionCount= 0;
BinaryOperator lastOperator= null;
- IASTExpression expr= castExpression(castCtx);
+ IASTInitializerClause expr= castExpression(castCtx);
loop: while(true) {
- // typically after a binary operator there cannot be a throw expression
+ // Typically after a binary operator there cannot be a throw expression
boolean allowThrow= false;
+ // Brace initializers are allowed on the right hand side of an expression
+ boolean allowBraceInitializer= false;
lt1= LT(1);
switch(lt1) {
case IToken.tQUESTION:
@@ -730,18 +733,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
allowAssignment= true; // assignment expressions will be subsumed by the conditional expression
allowThrow= true;
break;
-
- case IToken.tELLIPSIS:
- if ((!allowComma && conditionCount == 0))
- break loop;
-
- // Precedence: To the left just stronger than ',', to the right no other choice.
- lastOperator= new BinaryOperator(lastOperator, expr, lt1, 12, Integer.MAX_VALUE);
- expr= nodeFactory.newPackExpansionExpression(null);
- setRange(expr, 0, consume().getEndOffset());
- if (LT(1) == IToken.tCOMMA)
- continue loop;
- break loop;
case IToken.tCOMMA:
allowThrow= true;
@@ -766,6 +757,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
break loop;
// Assignments group right to left
lastOperator= new BinaryOperator(lastOperator, expr, lt1, 21, 20);
+ allowBraceInitializer= true;
break;
case IToken.tOR:
@@ -837,15 +829,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
consume(); // consume operator
if (allowThrow && LT(1) == IToken.t_throw) {
expr= throwExpression();
- switch (LT(1)) {
- case IToken.tCOLON:
- case IToken.tCOMMA:
- break;
- default:
- break loop;
- }
- }
- expr= castExpression(castCtx); // next cast expression
+ } else if (allowBraceInitializer && LT(1) == IToken.tLBRACE) {
+ expr= bracedInitList();
+ } else {
+ expr= castExpression(castCtx); // next cast expression
+ continue loop;
+ }
+
+ // For throw and braced initializers we require that the assignment expression ends.
+ lt1= LT(1);
+ if (lt1 != IToken.tCOLON && lt1 != IToken.tCOMMA)
+ break loop;
}
// Check for incomplete conditional expression
@@ -855,6 +849,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return buildExpression(lastOperator, expr);
}
+ @Override
+ protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTInitializerClause expr2, int lastOffset) {
+ IASTBinaryExpression result = nodeFactory.newBinaryExpression(operator, expr1, expr2);
+ int o = ((ASTNode) expr1).getOffset();
+ ((ASTNode) result).setOffsetAndLength(o, lastOffset - o);
+ return result;
+ }
+
private IASTExpression throwExpression() throws EndOfFileException, BacktrackException {
IToken throwToken = consume();
IASTExpression throwExpression = null;
@@ -902,7 +904,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
* and I for initializer the potential patterns (with the new omitted) are:
* easy: T, T(I)
* medium: (P) T(I), (P) (T)(I)
- * hard: (T), (P) T, (P) T, (P) (T), (T)(I)
+ * hard: (T), (P) T, (P) (T), (T)(I)
*/
protected IASTExpression newExpression() throws BacktrackException, EndOfFileException {
IToken la = LA(1);
@@ -917,15 +919,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
consume();
// consider placement first (P) ...
- IASTExpression plcmt= null;
+ List<IASTInitializerClause> plcmt= null;
IASTTypeId typeid= null;
boolean isNewTypeId= true;
- IASTExpression init= null;
+ IASTInitializer init= null;
int endOffset= 0;
IToken mark= mark();
IToken end= null;
try {
- plcmt= expression();
+ plcmt= expressionList();
endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset();
if (LT(1) == IToken.tLPAREN) {
@@ -949,18 +951,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
typeid= null;
}
- if (typeid != null && plcmt != null && LT(1) == IToken.tLPAREN) {
+ int lt1= LT(1);
+ if (typeid != null && plcmt != null && (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE)) {
// (P)(T)(I) or (P) T (I)
- consume(IToken.tLPAREN);
- init= possiblyEmptyExpressionList(IToken.tRPAREN);
- endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset();
+ init= bracedOrCtorStyleInitializer();
+ endOffset= calculateEndOffset(init);
return newExpression(isGlobal, plcmt, typeid, isNewTypeId, init, offset, endOffset);
}
// (T) ...
backup(mark);
IASTTypeId typeid2= null;
- IASTExpression init2= null;
+ IASTInitializer init2= null;
int endOffset2;
try {
typeid2= typeId(DeclarationOptions.TYPEID);
@@ -968,16 +970,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
throw backtrack;
endOffset2= consumeOrEOC(IToken.tRPAREN).getEndOffset();
- if (LT(1) == IToken.tLPAREN) {
+ lt1= LT(1);
+ if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) {
if (plcmt != null &&
ASTQueries.findTypeRelevantDeclarator(typeid2.getAbstractDeclarator()) instanceof IASTArrayDeclarator) {
throwBacktrack(LA(1));
}
// (T)(I)
- consume(IToken.tLPAREN);
- init2= possiblyEmptyExpressionList(IToken.tRPAREN);
- endOffset2= consumeOrEOC(IToken.tRPAREN).getEndOffset();
+ init2= bracedOrCtorStyleInitializer();
+ endOffset2= calculateEndOffset(init2);
}
} catch (BacktrackException e) {
if (plcmt == null)
@@ -1008,20 +1010,27 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
final IASTTypeId typeid = typeId(DeclarationOptions.TYPEID_NEW);
if (typeid == null)
throw backtrack;
+
int endOffset = calculateEndOffset(typeid);
- IASTExpression init= null;
- if (LT(1) == IToken.tLPAREN) {
+ IASTInitializer init= null;
+ final int lt1= LT(1);
+ if (lt1 == IToken.tLPAREN || lt1 == IToken.tLBRACE) {
// T(I)
- consume(IToken.tLPAREN);
- init= possiblyEmptyExpressionList(IToken.tRPAREN);
- endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset();
+ init= bracedOrCtorStyleInitializer();
+ endOffset= calculateEndOffset(init);
}
return newExpression(isGlobal, null, typeid, true, init, offset, endOffset);
}
- private IASTExpression newExpression(boolean isGlobal, IASTExpression placement, IASTTypeId typeid,
- boolean isNewTypeId, IASTExpression init, int offset, int endOffset) {
- ICPPASTNewExpression result = nodeFactory.newNewExpression(placement, init, typeid);
+
+ private IASTExpression newExpression(boolean isGlobal, List<IASTInitializerClause> plcmt, IASTTypeId typeid,
+ boolean isNewTypeId, IASTInitializer init, int offset, int endOffset) {
+
+ IASTInitializerClause[] plcmtArray= null;
+ if (plcmt != null && !plcmt.isEmpty()) {
+ plcmtArray= plcmt.toArray(new IASTInitializerClause[plcmt.size()]);
+ }
+ ICPPASTNewExpression result = nodeFactory.newNewExpression(plcmtArray, init, typeid);
result.setIsGlobal(isGlobal);
result.setIsNewTypeId(isNewTypeId);
((ASTNode) result).setOffsetAndLength(offset, endOffset - offset);
@@ -1089,12 +1098,61 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
}
+ /**
+ * postfix-expression:
+ * [gnu-extension, compound literals in c++]
+ * ( type-name ) { initializer-list }
+ * ( type-name ) { initializer-list , }
+ *
+ * primary-expression
+ * postfix-expression [ expression ]
+ * postfix-expression [ braced-init-list ]
+ * postfix-expression ( expression-list_opt )
+ * simple-type-specifier ( expression-list_opt )
+ * simple-type-specifier braced-init-list
+ * typename-specifier ( expression-list_opt )
+ * typename-specifier braced-init-list
+ * postfix-expression . templateopt id-expression
+ * postfix-expression -> templateopt id-expression
+ * postfix-expression . pseudo-destructor-name
+ * postfix-expression -> pseudo-destructor-name
+ * postfix-expression ++
+ * postfix-expression --
+ * dynamic_cast < type-id > ( expression )
+ * static_cast < type-id > ( expression )
+ * reinterpret_cast < type-id > ( expression )
+ * const_cast < type-id > ( expression )
+ * typeid ( expression )
+ * typeid ( type-id )
+ */
private IASTExpression postfixExpression(CastExprCtx ctx) throws EndOfFileException, BacktrackException {
IASTExpression firstExpression = null;
boolean isTemplate = false;
- switch (LT(1)) {
+ switch (LT(1)) {
+ case IToken.t_dynamic_cast:
+ firstExpression = specialCastExpression(ICPPASTCastExpression.op_dynamic_cast);
+ break;
+ case IToken.t_static_cast:
+ firstExpression = specialCastExpression(ICPPASTCastExpression.op_static_cast);
+ break;
+ case IToken.t_reinterpret_cast:
+ firstExpression = specialCastExpression(ICPPASTCastExpression.op_reinterpret_cast);
+ break;
+ case IToken.t_const_cast:
+ firstExpression = specialCastExpression(ICPPASTCastExpression.op_const_cast);
+ break;
+
+ case IToken.t_typeid:
+ // 'typeid' ( expression )
+ // 'typeid' ( type-id )
+ int so = consume().getOffset();
+ firstExpression = parseTypeidInParenthesisOrUnaryExpression(true, so,
+ ICPPASTTypeIdExpression.op_typeid, ICPPASTUnaryExpression.op_typeid, ctx);
+ break;
+
case IToken.tLPAREN:
+ // Gnu-extension: compound literals in c++
// ( type-name ) { initializer-list }
// ( type-name ) { initializer-list , }
IToken m = mark();
@@ -1104,7 +1162,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (t != null) {
consume(IToken.tRPAREN);
if (LT(1) == IToken.tLBRACE) {
- IASTInitializer i = initializerClause(false);
+ IASTInitializer i = bracedInitList();
firstExpression= nodeFactory.newTypeIdInitializerExpression(t, i);
setRange(firstExpression, offset, calculateEndOffset(i));
break;
@@ -1116,132 +1174,80 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
firstExpression= primaryExpression(ctx);
break;
+ // typename-specifier ( expression-list_opt )
+ // typename-specifier braced-init-list
+ // simple-type-specifier ( expression-list_opt )
+ // simple-type-specifier braced-init-list
case IToken.t_typename:
- int typenameOffset= consume().getOffset();
-
- boolean templateTokenConsumed = false;
- if (LT(1) == IToken.t_template) {
- consume();
- templateTokenConsumed = true;
- }
- IASTName name = qualifiedName(CastExprCtx.eNotBExpr); // treat as not in binary to force template arguments
- if (LT(1) != IToken.tLPAREN) {
- throwBacktrack(LA(1));
- }
-
- ICPPASTTypenameExpression result = nodeFactory.newTypenameExpression(name, null, templateTokenConsumed);
- setRange(result, typenameOffset, calculateEndOffset(name));
- firstExpression = result;
- break;
- // simple-type-specifier ( assignment-expression , .. )
case IToken.t_char:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_char);
- break;
case IToken.t_wchar_t:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_wchar_t);
- break;
case IToken.t_bool:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_bool);
- break;
case IToken.t_short:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_short);
- break;
case IToken.t_int:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_int);
- break;
case IToken.t_long:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_long);
- break;
case IToken.t_signed:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_signed);
- break;
case IToken.t_unsigned:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_unsigned);
- break;
case IToken.t_float:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_float);
- break;
case IToken.t_double:
- firstExpression = simpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression.t_double);
- break;
- case IToken.t_dynamic_cast:
- firstExpression = specialCastExpression(ICPPASTCastExpression.op_dynamic_cast);
- break;
- case IToken.t_static_cast:
- firstExpression = specialCastExpression(ICPPASTCastExpression.op_static_cast);
- break;
- case IToken.t_reinterpret_cast:
- firstExpression = specialCastExpression(ICPPASTCastExpression.op_reinterpret_cast);
- break;
- case IToken.t_const_cast:
- firstExpression = specialCastExpression(ICPPASTCastExpression.op_const_cast);
- break;
- case IToken.t_typeid:
- int so = consume().getOffset();
- firstExpression = parseTypeidInParenthesisOrUnaryExpression(true, so,
- ICPPASTTypeIdExpression.op_typeid, ICPPASTUnaryExpression.op_typeid, ctx);
- break;
-
+ case IToken.t_decltype:
+ case IGCCToken.t_typeof:
+ firstExpression = simpleTypeConstructorExpression(simpleTypeSpecifier());
+ break;
+
default:
firstExpression = primaryExpression(ctx);
+ if (firstExpression instanceof IASTIdExpression && LT(1) == IToken.tLBRACE) {
+ IASTName name = ((IASTIdExpression) firstExpression).getName();
+ ICPPASTDeclSpecifier declSpec= nodeFactory.newTypedefNameSpecifier(name);
+ firstExpression = simpleTypeConstructorExpression(setRange(declSpec, name));
+ }
break;
}
- IASTExpression secondExpression = null;
+
for (;;) {
switch (LT(1)) {
case IToken.tLBRACKET:
- // array access
- consume();
- int lastOffset;
- secondExpression = expression();
- switch (LT(1)) {
- case IToken.tRBRACKET:
- case IToken.tEOC:
- lastOffset = consume().getEndOffset();
- break;
- default:
- throw backtrack;
+ // postfix-expression [ expression ]
+ // postfix-expression [ braced-init-list ]
+ consume(IToken.tLBRACKET);
+ IASTInitializerClause expression;
+ if (LT(1) == IToken.tLBRACE) {
+ expression= bracedInitList();
+ } else {
+ expression= expression();
}
-
- IASTArraySubscriptExpression s = nodeFactory.newArraySubscriptExpression(firstExpression, secondExpression);
- ((ASTNode) s).setOffsetAndLength(((ASTNode) firstExpression)
- .getOffset(), lastOffset - ((ASTNode) firstExpression).getOffset());
- firstExpression = s;
+ int endOffset= consumeOrEOC(IToken.tRBRACKET).getEndOffset();
+ IASTArraySubscriptExpression s = nodeFactory.newArraySubscriptExpression(firstExpression, expression);
+ firstExpression= setRange(s, firstExpression, endOffset);
break;
case IToken.tLPAREN:
- // function call
- consume();
-
- if (LT(1) != IToken.tRPAREN)
- secondExpression = expression();
- else
- secondExpression = null;
- switch (LT(1)) {
- case IToken.tRPAREN:
- case IToken.tEOC:
- lastOffset = consume().getEndOffset();
- break;
- default:
- throw backtrack;
- }
+ // postfix-expression ( expression-list_opt )
+ // simple-type-specifier ( expression-list_opt ) // cannot be distinguished
+ consume(IToken.tLPAREN);
+ IASTInitializerClause[] initArray;
+ if (LT(1) == IToken.tRPAREN) {
+ initArray= IASTExpression.EMPTY_EXPRESSION_ARRAY;
+ } else {
+ final List<IASTInitializerClause> exprList = expressionList();
+ initArray = exprList.toArray(new IASTInitializerClause[exprList.size()]);
+ }
+ endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset();
- IASTFunctionCallExpression fce = nodeFactory.newFunctionCallExpression(firstExpression, secondExpression);
- ((ASTNode) fce).setOffsetAndLength(((ASTNode) firstExpression)
- .getOffset(), lastOffset - ((ASTNode) firstExpression).getOffset());
- firstExpression = fce;
+ IASTFunctionCallExpression fce = nodeFactory.newFunctionCallExpression(firstExpression, initArray);
+ firstExpression= setRange(fce, firstExpression, endOffset);
break;
+
case IToken.tINCR:
- int offset = consume().getEndOffset();
- firstExpression = buildUnaryExpression(
- IASTUnaryExpression.op_postFixIncr, firstExpression,
- ((ASTNode) firstExpression).getOffset(), offset);
+ endOffset = consume().getEndOffset();
+ firstExpression = buildUnaryExpression(IASTUnaryExpression.op_postFixIncr, firstExpression,
+ ((ASTNode) firstExpression).getOffset(), endOffset);
break;
case IToken.tDECR:
- offset = consume().getEndOffset();
- firstExpression = buildUnaryExpression(
- IASTUnaryExpression.op_postFixDecr, firstExpression,
- ((ASTNode) firstExpression).getOffset(), offset);
+ endOffset = consume().getEndOffset();
+ firstExpression = buildUnaryExpression(IASTUnaryExpression.op_postFixDecr, firstExpression,
+ ((ASTNode) firstExpression).getOffset(), endOffset);
break;
+
case IToken.tDOT:
// member access
IToken dot = consume();
@@ -1293,7 +1299,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
}
- @Override
+ @Override
protected IASTAmbiguousExpression createAmbiguousExpression() {
return new CPPASTAmbiguousExpression();
}
@@ -1313,20 +1319,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
- protected IASTExpression simpleTypeConstructorExpression(int operator) throws EndOfFileException, BacktrackException {
- int startingOffset = LA(1).getOffset();
- consume();
- consume(IToken.tLPAREN);
- IASTExpression operand = null;
- if (LT(1) != IToken.tRPAREN)
- operand = expression();
- int l = consume(IToken.tRPAREN).getEndOffset();
- ICPPASTSimpleTypeConstructorExpression result = nodeFactory.newSimpleTypeConstructorExpression(operator, operand);
- ((ASTNode) result).setOffsetAndLength(startingOffset, l - startingOffset);
- return result;
+ private IASTExpression simpleTypeConstructorExpression(ICPPASTDeclSpecifier declSpec) throws EndOfFileException, BacktrackException {
+ IASTInitializer initializer = bracedOrCtorStyleInitializer();
+ ICPPASTSimpleTypeConstructorExpression result = nodeFactory.newSimpleTypeConstructorExpression(
+ declSpec, initializer);
+ return setRange(result, declSpec, calculateEndOffset(initializer));
}
-
@Override
protected IASTExpression primaryExpression(CastExprCtx ctx) throws EndOfFileException, BacktrackException {
IToken t = null;
@@ -2063,62 +2062,44 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return fdef;
}
-
- /**
- * This method parses a constructor chain ctorinitializer: :
- * meminitializerlist meminitializerlist: meminitializer | meminitializer ,
- * meminitializerlist meminitializer: meminitializerid | ( expressionlist? )
- * meminitializerid: ::? nestednamespecifier? classname identifier
- *
- * @throws BacktrackException
- * request a backtrack
- */
+ /**
+ * ctor-initializer:
+ * : mem-initializer-list
+ * mem-initializer-list:
+ * mem-initializer ...?
+ * mem-initializer ...?, mem-initializer-list
+ * mem-initializer:
+ * mem-initializer-id ( expression-list? )
+ * mem-initializer-id braced-init-list
+ * mem-initializer-id:
+ * ::? nested-name-specifier? class-name
+ * identifier
+ */
protected void ctorInitializer(ICPPASTFunctionDefinition fdef) throws EndOfFileException, BacktrackException {
- consume();
- ctorLoop: for (;;) {
- int offset= LA(1).getOffset();
- IASTName name = qualifiedName(CastExprCtx.eNotBExpr);
-
+ consume(IToken.tCOLON);
+ loop: for(;;) {
+ final int offset= LA(1).getOffset();
+ final IASTName name = qualifiedName(CastExprCtx.eNotBExpr);
+ final IASTInitializer init;
int endOffset;
- IASTExpression expressionList = null;
- switch (LT(1)) {
- case IToken.tLPAREN:
- consume();
-
- if (LT(1) != IToken.tRPAREN)
- expressionList = expression();
-
- switch (LT(1)) {
- case IToken.tRPAREN:
- case IToken.tEOC:
- endOffset = consume().getEndOffset();
- break;
- default:
- throw backtrack;
- }
- break;
- case IToken.tEOC:
- endOffset = consume().getEndOffset();
- break;
- default:
- throw backtrack;
+ if (LT(1) != IToken.tEOC) {
+ init = bracedOrCtorStyleInitializer();
+ endOffset= calculateEndOffset(init);
+ } else {
+ init= null;
+ endOffset= calculateEndOffset(name);
}
-
- ICPPASTConstructorChainInitializer ctorInitializer = nodeFactory.newConstructorChainInitializer(name, expressionList);
+ ICPPASTConstructorChainInitializer ctorInitializer = nodeFactory.newConstructorChainInitializer(name, init);
if (LT(1) == IToken.tELLIPSIS) {
ctorInitializer.setIsPackExpansion(true);
endOffset= consume().getEndOffset();
- }
- setRange(ctorInitializer, offset, endOffset);
- fdef.addMemberInitializer(ctorInitializer);
+ }
+ fdef.addMemberInitializer(setRange(ctorInitializer, offset, endOffset));
- switch (LT(1)) {
- case IToken.tCOMMA:
- consume();
- break;
- case IToken.tLBRACE:
- case IToken.tEOC:
- break ctorLoop;
+ if (LT(1) == IToken.tCOMMA) {
+ consume();
+ } else {
+ break loop;
}
}
}
@@ -2177,6 +2158,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
*/
@Override
protected Decl declSpecifierSeq(final DeclarationOptions option) throws BacktrackException, EndOfFileException {
+ return declSpecifierSeq(option.fAllowEmptySpecifier, false);
+ }
+
+ private ICPPASTDeclSpecifier simpleTypeSpecifier() throws BacktrackException, EndOfFileException {
+ Decl d= declSpecifierSeq(false, true);
+ return (ICPPASTDeclSpecifier) d.fDeclSpec1;
+ }
+
+ private Decl declSpecifierSeq(final boolean allowEmpty, final boolean single) throws BacktrackException, EndOfFileException {
int storageClass = IASTDeclSpecifier.sc_unspecified;
int simpleType = IASTSimpleDeclSpecifier.t_unspecified;
int options= 0;
@@ -2362,7 +2352,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (encounteredRawType || encounteredTypename)
break declSpecifiers;
- if (option.fAllowEmptySpecifier && LT(1) != IToken.tCOMPLETION) {
+ if (allowEmpty && LT(1) != IToken.tCOMPLETION) {
if ((options & FORBID_IN_EMPTY_DECLSPEC) == 0 && storageClass == IASTDeclSpecifier.sc_unspecified) {
altResult= buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset);
returnToken= mark();
@@ -2456,10 +2446,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (encounteredRawType && encounteredTypename)
throwBacktrack(LA(1));
+
+ if (single)
+ break declSpecifiers;
}
// check for empty specification
- if (!encounteredRawType && !encounteredTypename && LT(1) != IToken.tEOC && !option.fAllowEmptySpecifier) {
+ if (!encounteredRawType && !encounteredTypename && LT(1) != IToken.tEOC && !allowEmpty) {
throwBacktrack(LA(1));
}
@@ -2590,14 +2583,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
switch(lt1) {
case 0:
return dtor1;
+
+ case IToken.tLBRACE:
+ if (option.fAllowBracedInitializer || option == DeclarationOptions.TYPEID_NEW
+ || ASTQueries.findTypeRelevantDeclarator(dtor1) instanceof IASTFunctionDeclarator)
+ return dtor1;
+
+ dtor1= null;
+ throwBacktrack(LA(1));
+ break;
+
case IToken.tCOLON:
// a colon can be used after a type-id in a conditional expression
if (option != DeclarationOptions.CPP_MEMBER && option != DeclarationOptions.GLOBAL)
break;
//$FALL-THROUGH$
-
- case IToken.tLBRACE:
- case IToken.t_throw: case IToken.t_try:
+ case IToken.t_throw: case IToken.t_try:
case IToken.t_const: case IToken.t_volatile:
if (ASTQueries.findTypeRelevantDeclarator(dtor1) instanceof IASTFunctionDeclarator) {
return dtor1;
@@ -2615,7 +2616,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
bt= e;
}
- if (!option.fAllowConstructorInitializer || !canHaveConstructorInitializer(declspec, dtor1)) {
+ if (!option.fAllowCtorStyleInitializer || !canHaveConstructorInitializer(declspec, dtor1)) {
if (bt != null)
throw bt;
return dtor1;
@@ -2734,15 +2735,46 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private IASTDeclarator initDeclarator(DtorStrategy strategy, IASTDeclSpecifier declspec, DeclarationOptions option)
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
final IASTDeclarator dtor= declarator(strategy, option);
- if (option.fAllowInitializer) {
- if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE)
- throw new FoundAggregateInitializer(declspec, dtor);
-
- IASTInitializer initializer= optionalCPPInitializer(dtor, option);
- if (initializer != null) {
- dtor.setInitializer(initializer);
- adjustLength(dtor, initializer);
- }
+ if (option.fAllowInitializer) {
+ final IASTDeclarator typeRelevantDtor = ASTQueries.findTypeRelevantDeclarator(dtor);
+ if (option != DeclarationOptions.PARAMETER && typeRelevantDtor instanceof IASTFunctionDeclarator) {
+ // Function declarations don't have initializers
+ // For member functions we need to consider pure-virtual syntax
+ if (option == DeclarationOptions.CPP_MEMBER && LTcatchEOF(1) == IToken.tASSIGN
+ && LTcatchEOF(2) == IToken.tINTEGER) {
+ consume();
+ IToken t = consume();
+ char[] image = t.getCharImage();
+ if (image.length != 1 || image[0] != '0') {
+ throwBacktrack(t);
+ }
+ ((ICPPASTFunctionDeclarator) typeRelevantDtor).setPureVirtual(true);
+ adjustEndOffset(dtor, t.getEndOffset()); // we can only adjust the offset of the outermost dtor.
+ }
+ } else {
+ if (LTcatchEOF(1) == IToken.tASSIGN && LTcatchEOF(2) == IToken.tLBRACE)
+ throw new FoundAggregateInitializer(declspec, dtor);
+
+ IASTInitializer initializer= optionalInitializer(option);
+ if (initializer != null) {
+ if (initializer instanceof IASTInitializerList
+ && ((IASTInitializerList) initializer).getSize() == 0) {
+ // Avoid ambiguity between constructor with body and variable with initializer
+ switch (LTcatchEOF(1)) {
+ case IToken.tCOMMA:
+ case IToken.tSEMI:
+ case IToken.tRPAREN:
+ break;
+ case 0:
+ throw backtrack;
+ default:
+ throwBacktrack(LA(1));
+ }
+ }
+ dtor.setInitializer(initializer);
+ adjustLength(dtor, initializer);
+ }
+ }
}
return dtor;
}
@@ -2751,112 +2783,175 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
protected IASTDeclarator addInitializer(FoundAggregateInitializer e, DeclarationOptions option) throws EndOfFileException {
final IASTDeclarator d = e.fDeclarator;
try {
- IASTInitializer i = optionalCPPInitializer(e.fDeclarator, option);
+ IASTInitializer i = optionalInitializer(option);
if (i != null) {
d.setInitializer(i);
((ASTNode) d).setLength(calculateEndOffset(i) - ((ASTNode) d).getOffset());
}
} catch (BacktrackException e1) {
// mstodo add problem node
+ failParse();
}
return d;
}
- protected IASTInitializer optionalCPPInitializer(IASTDeclarator d, DeclarationOptions option) throws EndOfFileException, BacktrackException {
- // handle initializer
+ /**
+ * initializer:
+ * brace-or-equal-initializer
+ * ( expression-list )
+ *
+ * brace-or-equal-initializer:
+ * = initializer-clause
+ * braced-init-list
+ */
+ private IASTInitializer optionalInitializer(DeclarationOptions option) throws EndOfFileException, BacktrackException {
final int lt1= LTcatchEOF(1);
+
+ // = initializer-clause
if (lt1 == IToken.tASSIGN) {
- consume();
- // for member functions we need to consider pure-virtual syntax
- if (option == DeclarationOptions.CPP_MEMBER && LTcatchEOF(1) == IToken.tINTEGER) {
- IASTDeclarator relDtor = ASTQueries.findTypeRelevantDeclarator(d);
- // note the declarator for a member function cannot be ambiguous because it cannot be abstract
- if (relDtor instanceof ICPPASTFunctionDeclarator) {
- // check for pure virtual
- IToken t = consume();
- char[] image = t.getCharImage();
- if (image.length != 1 || image[0] != '0') {
- throwBacktrack(t);
- }
+ int offset= consume().getOffset();
+ IASTInitializerClause initClause = initClause(false);
+ IASTEqualsInitializer initExpr= nodeFactory.newEqualsInitializer(initClause);
+ return setRange(initExpr, offset, calculateEndOffset(initClause));
+ }
- ((ICPPASTFunctionDeclarator) relDtor).setPureVirtual(true);
- adjustEndOffset(d, t.getEndOffset()); // we can only adjust the offset of the outermost dtor.
- return null;
- }
- }
- try {
- return initializerClause(false);
- } catch (EndOfFileException eof) {
- failParse();
- throw eof;
- }
- } else if (option.fAllowConstructorInitializer && lt1 == IToken.tLPAREN) {
- if (d instanceof IASTFunctionDeclarator && d.getNestedDeclarator() == null) {
- // constructor initializer doesn't make sense for a function
- // declarator,
- // we must have an object to initialize, a function doesn't
- // work.
- return null;
- }
- // initializer in constructor
- IToken t = consume(); // EAT IT!
- int o = t.getOffset();
- IASTExpression astExpression = expression();
- if( astExpression == null )
- throwBacktrack( t );
- int l = consumeOrEOC(IToken.tRPAREN).getEndOffset();
- ICPPASTConstructorInitializer result = nodeFactory.newConstructorInitializer(astExpression);
- ((ASTNode) result).setOffsetAndLength(o, l - o);
- return result;
+ // braced-init-list
+ if (option.fAllowBracedInitializer && lt1 == IToken.tLBRACE) {
+ return bracedInitList();
}
+
+ // ( expression-list )
+ if (option.fAllowCtorStyleInitializer && lt1 == IToken.tLPAREN) {
+ return ctorStyleInitializer(false);
+ }
return null;
}
+
+ private IASTInitializer bracedOrCtorStyleInitializer() throws EndOfFileException, BacktrackException {
+ final int lt1= LT(1);
+ if (lt1 == IToken.tLPAREN) {
+ return ctorStyleInitializer(true);
+ }
+ return bracedInitList();
+ }
+ /**
+ * ( expression-list_opt )
+ */
+ private ICPPASTConstructorInitializer ctorStyleInitializer(boolean optionalExpressionList)
+ throws EndOfFileException, BacktrackException {
+ IASTInitializerClause[] initArray;
+ int offset = consume(IToken.tLPAREN).getOffset();
+
+ // ( )
+ if (optionalExpressionList && LT(1) == IToken.tRPAREN) {
+ initArray= IASTExpression.EMPTY_EXPRESSION_ARRAY;
+ } else {
+ final List<IASTInitializerClause> exprList = expressionList();
+ initArray = exprList.toArray(new IASTInitializerClause[exprList.size()]);
+ }
+ int endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset();
+ return setRange(nodeFactory.newConstructorInitializer(initArray), offset, endOffset);
+ }
+
+ private List<IASTInitializerClause> expressionList() throws EndOfFileException, BacktrackException {
+ return initializerList(false);
+ }
- protected ICPPASTInitializer initializerClause(boolean inAggregateInitializer) throws EndOfFileException,
+ /**
+ * initializer-clause:
+ * assignment-expression
+ * braced-init-list
+ */
+ private IASTInitializerClause initClause(boolean inBraces) throws EndOfFileException,
BacktrackException {
+ // braced-init-list
if (LT(1) == IToken.tLBRACE) {
- return initializerList();
+ return bracedInitList();
}
- // no brace, so try an assignment expression
+ // assignment expression
final BinaryExprCtx ctx = fInTemplateParameterList ? BinaryExprCtx.eTmplID : BinaryExprCtx.eNoTmplID;
IASTExpression assignmentExpression = expression(ExprKind.eAssignment, ctx);
- if (inAggregateInitializer && skipTrivialExpressionsInAggregateInitializers) {
+ if (inBraces && skipTrivialExpressionsInAggregateInitializers) {
if (!ASTQueries.canContainName(assignmentExpression))
return null;
}
-
- ICPPASTInitializerExpression result = nodeFactory.newInitializerExpression(assignmentExpression);
- setRange(result, assignmentExpression);
- return result;
+ return assignmentExpression;
}
- private ICPPASTInitializerList initializerList() throws EndOfFileException, BacktrackException {
- int startingOffset = consume(IToken.tLBRACE).getOffset();
-
+ /**
+ * braced-init-list:
+ * { initializer-list ,opt }
+ * { }
+ */
+ private ICPPASTInitializerList bracedInitList() throws EndOfFileException, BacktrackException {
+ int offset = consume(IToken.tLBRACE).getOffset();
+
+ // { }
+ if (LT(1) == IToken.tRBRACE) {
+ return setRange(nodeFactory.newInitializerList(), offset, consume().getEndOffset());
+ }
+
+ // { initializer-list ,opt }
+ List<IASTInitializerClause> initList= initializerList(true);
+ if (LT(1) == IToken.tCOMMA)
+ consume();
+
+ int endOffset= consumeOrEOC(IToken.tRBRACE).getEndOffset();
ICPPASTInitializerList result = nodeFactory.newInitializerList();
+ for (IASTInitializerClause init : initList) {
+ result.addClause(init);
+ }
+ return setRange(result, offset, endOffset);
+ }
+
+ /**
+ * initializerList:
+ * initializer-clause ...opt
+ * initializer-list , initializer-clause ...opt
+ */
+ private List<IASTInitializerClause> initializerList(boolean inAggregateInit) throws EndOfFileException,
+ BacktrackException {
+ List<IASTInitializerClause> result= null;
// List of initializer clauses
- while (LT(1) != IToken.tRBRACE && LT(1) != IToken.tEOC) {
- // Clause may be null, add to initializer anyways, such that the
- // actual size can be computed.
- ICPPASTInitializer clause = initializerClause(true);
+ loop: for(;;) {
+ // Clause may be null, add to initializer anyways, such that the size can be computed.
+ IASTInitializerClause clause = initClause(inAggregateInit);
if (LT(1) == IToken.tELLIPSIS) {
- clause.setIsPackExpansion(true);
- adjustEndOffset(clause, consume().getEndOffset());
+ final int endOffset = consume(IToken.tELLIPSIS).getEndOffset();
+ if (clause instanceof ICPPASTPackExpandable) {
+ // Mark initializer lists directly as pack expansions
+ ((ICPPASTPackExpandable) clause).setIsPackExpansion(true);
+ adjustEndOffset(clause, endOffset);
+ } else if (clause instanceof IASTExpression){
+ // Wrap pack expanded assignment expressions
+ IASTExpression packExpansion= nodeFactory.newPackExpansionExpression((IASTExpression) clause);
+ clause= setRange(packExpansion, clause, endOffset);
+ }
}
- result.addInitializer(clause);
- if (LT(1) == IToken.tRBRACE || LT(1) == IToken.tEOC)
+ if (result == null) {
+ result= new ArrayList<IASTInitializerClause>();
+ }
+ result.add(clause);
+ if (LT(1) != IToken.tCOMMA)
break;
- consume(IToken.tCOMMA); // Allow for trailing commas
+ switch(LT(2)) {
+ case IToken.tRBRACE:
+ case IToken.tRPAREN:
+ case IToken.tEOC:
+ break loop;
+ }
+ consume(IToken.tCOMMA);
}
- int endOffset = consume().getEndOffset(); // tRBRACE
- setRange(result, startingOffset, endOffset);
+
+ if (result == null)
+ return Collections.emptyList();
+
return result;
}
-
@Override
protected ICPPASTTypeId typeId(DeclarationOptions option) throws EndOfFileException {
if (!canBeTypeSpecifier()) {
@@ -3986,4 +4081,22 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
return for_statement;
}
+
+ @Override
+ protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException {
+ final int offset= consume(IToken.t_return).getOffset(); // t_return
+
+ // Optional expression
+ IASTInitializerClause expr = null;
+ final int lt1 = LT(1);
+ if (lt1 == IToken.tLBRACE) {
+ expr= bracedInitList();
+ } else if (lt1 != IToken.tSEMI) {
+ expr = expression();
+ }
+ // Semicolon
+ final int endOffset= consumeOrEOC(IToken.tSEMI).getEndOffset();
+
+ return setRange(nodeFactory.newReturnStatement(expr), offset, endOffset);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
index fc48735332a..0d16e654ce9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index bdc3b98b0ce..42324e7a76e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -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()));
}
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java
index 3bc91ff21b5..a6739ee5254 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java
@@ -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;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java
index 75380101325..ce5714b5aa0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java
@@ -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);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java
index 33ad9d12aa3..6f3c8f2d40c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java
@@ -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) {

Back to the top