Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2010-10-21 14:22:06 +0000
committerMarkus Schorn2010-10-21 14:22:06 +0000
commit7129cfccb07c99a68e2ae579e05f463e70a97b39 (patch)
tree27af1a2662b6b727dc27ba7edf3894b7e218d517 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal
parentbefb4d9e04c354d51a34c1408eb773080db65bdf (diff)
downloadorg.eclipse.cdt-7129cfccb07c99a68e2ae579e05f463e70a97b39.tar.gz
org.eclipse.cdt-7129cfccb07c99a68e2ae579e05f463e70a97b39.tar.xz
org.eclipse.cdt-7129cfccb07c99a68e2ae579e05f463e70a97b39.zip
Bug 327223: [C++0x] Range-based for loop.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java119
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java158
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java21
10 files changed, 263 insertions, 77 deletions
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 0a986d15408..93a7c5213db 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
@@ -28,6 +28,7 @@ public class DeclarationOptions {
final public static int REQUIRE_SIMPLE_NAME= 0x800;
final public static int ALLOW_FOLLOWED_BY_BRACE= 0x1000;
final public static int ALLOW_OPAQUE_ENUM= 0x2000;
+ final public static int SINGLE_DTOR= 0x4000;
public static final DeclarationOptions
GLOBAL= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_OPAQUE_ENUM),
@@ -42,7 +43,8 @@ public class DeclarationOptions {
TYPEID_CONVERSION= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED),
EXCEPTION= new DeclarationOptions(ALLOW_ABSTRACT | NO_INITIALIZER),
CONDITION= new DeclarationOptions(NO_CTOR_STYLE_INITIALIZER),
- C_PARAMETER_NON_ABSTRACT= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_EMPTY_SPECIFIER);
+ C_PARAMETER_NON_ABSTRACT= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_EMPTY_SPECIFIER),
+ RANGE_BASED_FOR = new DeclarationOptions(NO_INITIALIZER | REQUIRE_SIMPLE_NAME | SINGLE_DTOR);
final public boolean fAllowEmptySpecifier;
final public boolean fAllowAbstract;
@@ -57,6 +59,7 @@ public class DeclarationOptions {
final public boolean fAllowParameterPacks;
final public boolean fRequireSimpleName;
final public boolean fAllowOpaqueEnum;
+ final public boolean fSingleDtor;
public DeclarationOptions(int options) {
fAllowEmptySpecifier= (options & ALLOW_EMPTY_SPECIFIER) != 0;
@@ -72,5 +75,6 @@ public class DeclarationOptions {
fRequireSimpleName= (options & REQUIRE_SIMPLE_NAME) != 0;
fCanBeFollowedByBrace= fAllowBracedInitializer || (options & ALLOW_FOLLOWED_BY_BRACE) != 0;
fAllowOpaqueEnum= (options & ALLOW_OPAQUE_ENUM) != 0;
+ fSingleDtor= (options & SINGLE_DTOR) != 0;
}
}
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 0ea856dbd97..42c8432cb0a 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
@@ -41,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
@@ -197,11 +198,14 @@ public abstract class VariableReadWriteFlags {
if (parent instanceof IGNUASTCompoundStatementExpression) {
return rwAnyNode(parent, indirection);
}
- }
- else if (stmt instanceof IASTForStatement) {
+ } else if (stmt instanceof IASTForStatement) {
if (node.getPropertyInParent() == IASTForStatement.CONDITION) {
return READ;
}
+ } else if (stmt instanceof ICPPASTRangeBasedForStatement) {
+ if (node.getPropertyInParent() == ICPPASTRangeBasedForStatement.INITIALIZER) {
+ return READ;
+ }
}
else if (stmt instanceof IASTIfStatement) {
if (node.getPropertyInParent() == IASTIfStatement.CONDITION) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java
new file mode 100644
index 00000000000..cbfc8850406
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser.cpp;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
+
+/**
+ * Range based for loop in c++.
+ */
+public class CPPASTRangeBasedForStatement extends ASTNode implements ICPPASTRangeBasedForStatement, IASTAmbiguityParent {
+ private IScope fScope;
+ private IASTDeclaration fDeclaration;
+ private IASTInitializerClause fInitClause;
+ private IASTStatement fBody;
+
+ public CPPASTRangeBasedForStatement() {
+ }
+
+ public CPPASTRangeBasedForStatement copy() {
+ CPPASTRangeBasedForStatement copy = new CPPASTRangeBasedForStatement();
+ copy.setDeclaration(fDeclaration == null ? null : fDeclaration.copy());
+ copy.setInitializerClause(fInitClause == null ? null : fInitClause.copy());
+ copy.setBody(fBody == null ? null : fBody.copy());
+ copy.setOffsetAndLength(this);
+ return copy;
+ }
+
+ public IASTDeclaration getDeclaration() {
+ return fDeclaration;
+ }
+
+ public void setDeclaration(IASTDeclaration declaration) {
+ assertNotFrozen();
+ this.fDeclaration = declaration;
+ if (declaration != null) {
+ declaration.setParent(this);
+ declaration.setPropertyInParent(DECLARATION);
+ }
+ }
+
+ public IASTInitializerClause getInitializerClause() {
+ return fInitClause;
+ }
+
+ public void setInitializerClause(IASTInitializerClause initClause) {
+ assertNotFrozen();
+ fInitClause = initClause;
+ if (initClause != null) {
+ initClause.setParent(this);
+ initClause.setPropertyInParent(INITIALIZER);
+ }
+ }
+
+ public IASTStatement getBody() {
+ return fBody;
+ }
+
+ public void setBody(IASTStatement statement) {
+ assertNotFrozen();
+ fBody = statement;
+ if (statement != null) {
+ statement.setParent(this);
+ statement.setPropertyInParent(BODY);
+ }
+ }
+
+ public IScope getScope() {
+ if (fScope == null)
+ fScope = new CPPBlockScope(this);
+ return fScope;
+ }
+
+ @Override
+ public boolean accept( ASTVisitor action ){
+ if (action.shouldVisitStatements) {
+ switch (action.visit(this)) {
+ case ASTVisitor.PROCESS_ABORT : return false;
+ case ASTVisitor.PROCESS_SKIP : return true;
+ default : break;
+ }
+ }
+ if (fDeclaration != null && !fDeclaration.accept(action))
+ return false;
+ if (fInitClause != null && !fInitClause.accept(action))
+ return false;
+ if (fBody != null && !fBody.accept(action))
+ return false;
+
+ if (action.shouldVisitStatements && action.leave(this) == ASTVisitor.PROCESS_ABORT)
+ return false;
+ return true;
+ }
+
+ public void replace(IASTNode child, IASTNode other) {
+ if (child == fDeclaration) {
+ setDeclaration((IASTDeclaration) other);
+ } else if (child == fInitClause) {
+ setInitializerClause((IASTInitializerClause) other);
+ } else if (child == fBody) {
+ setBody((IASTStatement) other);
+ }
+ }
+}
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 cc70d0aab07..58d031926dc 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
@@ -86,6 +86,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
@@ -458,6 +459,10 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return new CPPASTQualifiedName();
}
+ public ICPPASTRangeBasedForStatement newRangeBasedForStatement() {
+ return new CPPASTRangeBasedForStatement();
+ }
+
public ICPPASTReferenceOperator newReferenceOperator() {
return new CPPASTReferenceOperator(false);
}
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 8fa51bea463..84f2c388da7 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
@@ -34,6 +34,7 @@ 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.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
@@ -95,6 +96,7 @@ 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.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
@@ -2036,19 +2038,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTDeclarator[] declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
if (dtor != null) {
declarators= new IASTDeclarator[]{dtor};
- while (LTcatchEOF(1) == IToken.tCOMMA) {
- consume();
- try {
- dtor= initDeclarator(declSpec, declOption);
- } catch (FoundAggregateInitializer e) {
- // scalability: don't keep references to tokens, initializer may be large
- declarationMark= null;
- markBeforDtor= null;
- dtor= addInitializer(e, declOption);
+ if (!declOption.fSingleDtor) {
+ while (LTcatchEOF(1) == IToken.tCOMMA) {
+ consume();
+ try {
+ dtor= initDeclarator(declSpec, declOption);
+ } catch (FoundAggregateInitializer e) {
+ // scalability: don't keep references to tokens, initializer may be large
+ declarationMark= null;
+ markBeforDtor= null;
+ dtor= addInitializer(e, declOption);
+ }
+ declarators = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, declarators, dtor);
}
- declarators = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, declarators, dtor);
+ declarators = (IASTDeclarator[]) ArrayUtil.removeNulls(IASTDeclarator.class, declarators);
}
- declarators = (IASTDeclarator[]) ArrayUtil.removeNulls(IASTDeclarator.class, declarators);
}
final int lt1= LTcatchEOF(1);
@@ -2059,8 +2063,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
case IToken.tSEMI:
endOffset= consume().getEndOffset();
break;
- case IToken.t_try:
case IToken.tCOLON:
+ if (declOption == DeclarationOptions.RANGE_BASED_FOR) {
+ endOffset= figureEndOffset(declSpec, declarators);
+ break;
+ }
+ //$FALL-THROUGH$
+ case IToken.t_try:
case IToken.tLBRACE:
case IToken.tASSIGN: // defaulted or deleted function definition
if (declarators.length != 1)
@@ -4232,70 +4241,85 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
protected IASTStatement parseForStatement() throws EndOfFileException, BacktrackException {
- int startOffset;
- startOffset = consume().getOffset();
+ final int offset= consume(IToken.t_for).getOffset();
consume(IToken.tLPAREN);
- IASTStatement init = forInitStatement();
- IASTNode for_condition = null;
- switch (LT(1)) {
- case IToken.tSEMI:
- case IToken.tEOC:
- break;
- default:
- for_condition = cppStyleCondition(IToken.tSEMI);
- }
- switch (LT(1)) {
- case IToken.tSEMI:
- consume();
- break;
- case IToken.tEOC:
- break;
- default:
- throw backtrack;
+ IToken mark= mark();
+ IASTStatement forStmt;
+ try {
+ forStmt= startRangeBasedForLoop();
+ } catch (BacktrackException e) {
+ backup(mark);
+ forStmt= startTraditionalForLoop();
}
- IASTExpression iterationExpression = null;
- switch (LT(1)) {
- case IToken.tRPAREN:
- case IToken.tEOC:
- break;
- default:
- iterationExpression = expression();
+ mark= null;
+ int endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset();
+
+ if (LT(1) != IToken.tEOC) {
+ IASTStatement body = statement();
+ if (forStmt instanceof ICPPASTRangeBasedForStatement) {
+ ((ICPPASTRangeBasedForStatement) forStmt).setBody(body);
+ } else {
+ ((IASTForStatement) forStmt).setBody(body);
+ }
+ endOffset= calculateEndOffset(body);
}
- switch (LT(1)) {
- case IToken.tRPAREN:
- consume();
- break;
+ return setRange(forStmt, offset, endOffset);
+ }
+
+ // Look for "for-range-declaration : for-range-initializer"
+ // for-range-declaration:
+ // attribute-specifier? type-specifier-seq declarator
+ // for-range-initializer:
+ // expression
+ // braced-init-list
+ private ICPPASTRangeBasedForStatement startRangeBasedForLoop() throws EndOfFileException, BacktrackException {
+ IASTDeclaration decl= simpleDeclaration(DeclarationOptions.RANGE_BASED_FOR);
+ consume(IToken.tCOLON);
+ IASTInitializerClause init= null;
+ switch (LT(1)) {
case IToken.tEOC:
- break;
+ break;
+ case IToken.tLBRACE:
+ init= bracedInitList(false);
+ break;
default:
- throw backtrack;
- }
- ICPPASTForStatement for_statement = nodeFactory.newForStatement();
- IASTStatement for_body = null;
- if (LT(1) != IToken.tEOC) {
- for_body = statement();
- ((ASTNode) for_statement).setOffsetAndLength(startOffset, calculateEndOffset(for_body) - startOffset);
+ init= expression();
}
-
- for_statement.setInitializerStatement(init);
-
- if (for_condition != null) {
- if (for_condition instanceof IASTExpression) {
- for_statement.setConditionExpression((IASTExpression) for_condition);
- } else if (for_condition instanceof IASTDeclaration) {
- for_statement.setConditionDeclaration((IASTDeclaration) for_condition);
- }
+
+ ICPPASTRangeBasedForStatement result = nodeFactory.newRangeBasedForStatement();
+ result.setDeclaration(decl);
+ result.setInitializerClause(init);
+ return result;
+ }
+
+ private IASTForStatement startTraditionalForLoop() throws BacktrackException, EndOfFileException {
+ final IASTStatement initStmt = forInitStatement();
+ IASTNode condition= null;
+ IASTExpression iterExpr= null;
+
+ int lt1 = LT(1);
+ if (lt1 != IToken.tSEMI && lt1 != IToken.tEOC) {
+ condition = cppStyleCondition(IToken.tSEMI);
}
- if (iterationExpression != null) {
- for_statement.setIterationExpression(iterationExpression);
+ consumeOrEOC(IToken.tSEMI);
+
+ lt1 = LT(1);
+ if (lt1 != IToken.tRPAREN && lt1 != IToken.tEOC) {
+ iterExpr = expression();
}
- if (for_body != null) {
- for_statement.setBody(for_body);
+
+ ICPPASTForStatement result = nodeFactory.newForStatement();
+ result.setInitializerStatement(initStmt);
+ if (condition instanceof IASTExpression) {
+ result.setConditionExpression((IASTExpression) condition);
+ } else if (condition instanceof IASTDeclaration) {
+ result.setConditionDeclaration((IASTDeclaration) condition);
}
- return for_statement;
- }
-
- @Override
+ result.setIterationExpression(iterExpr);
+ return result;
+ }
+
+ @Override
protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException {
final int offset= consume(IToken.t_return).getOffset(); // t_return
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 2ae5db912ba..1999efadc07 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
@@ -109,6 +109,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
@@ -1379,6 +1380,10 @@ public class CPPSemantics {
} else {
nodes= new IASTNode[] {initDeclaration};
}
+ } else if (parent instanceof ICPPASTRangeBasedForStatement) {
+ ICPPASTRangeBasedForStatement forStatement = (ICPPASTRangeBasedForStatement) parent;
+ final IASTDeclaration decl = forStatement.getDeclaration();
+ nodes= new IASTNode[] {decl};
} else if (parent instanceof ICPPASTEnumerationSpecifier) {
// The enumeration scope contains the enumeration items
for (IASTEnumerator enumerator : ((ICPPASTEnumerationSpecifier) parent).getEnumerators()) {
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 36bfe23719f..15a7c11e7e9 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
@@ -111,6 +111,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
@@ -842,6 +843,8 @@ public class CPPVisitor extends ASTQueries {
return getContainingScope((IASTStatement) parent);
} else if (parent instanceof IASTForStatement) {
return ((IASTForStatement) parent).getScope();
+ } else if (parent instanceof ICPPASTRangeBasedForStatement) {
+ return ((ICPPASTRangeBasedForStatement) parent).getScope();
} else if (parent instanceof IASTCompositeTypeSpecifier) {
return ((IASTCompositeTypeSpecifier) parent).getScope();
} else if (parent instanceof ICPPASTNamespaceDefinition) {
@@ -930,6 +933,8 @@ public class CPPVisitor extends ASTQueries {
IASTNode parent = node.getParent();
if (parent instanceof IASTForStatement) {
return ((IASTForStatement) parent).getScope();
+ } else if (parent instanceof ICPPASTRangeBasedForStatement) {
+ return ((ICPPASTRangeBasedForStatement) parent).getScope();
} else if (parent instanceof ICPPASTIfStatement) {
return ((ICPPASTIfStatement) parent).getScope();
} else if (parent instanceof ICPPASTSwitchStatement) {
@@ -1125,6 +1130,8 @@ public class CPPVisitor extends ASTQueries {
scope = compound.getScope();
} else if (parent instanceof IASTForStatement) {
scope = ((IASTForStatement) parent).getScope();
+ } else if (parent instanceof ICPPASTRangeBasedForStatement) {
+ scope= ((ICPPASTRangeBasedForStatement) parent).getScope();
} else if (parent instanceof ICPPASTSwitchStatement) {
scope = ((ICPPASTSwitchStatement) parent).getScope();
} else if (parent instanceof ICPPASTIfStatement) {
@@ -1164,6 +1171,8 @@ public class CPPVisitor extends ASTQueries {
IASTNode p = parent.getParent();
if (p instanceof IASTForStatement)
return parent;
+ if (p instanceof ICPPASTRangeBasedForStatement)
+ return parent;
if (p instanceof IASTStatement)
return p;
} else if (parent instanceof IASTStatement || parent instanceof IASTTranslationUnit) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java
index 32bb929125c..2c994c26dbd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@@ -20,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
-import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
@@ -61,7 +61,7 @@ public class DeclarationWriter extends NodeWriter{
private static final String USING = "using "; //$NON-NLS-1$
private boolean printSemicolon;
- public DeclarationWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ public DeclarationWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
index 369fe35e39b..700165b1bd9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.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
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@@ -58,6 +58,7 @@ public class NodeWriter {
protected static final String CLASS_SPACE = "class "; //$NON-NLS-1$
protected static final String VAR_ARGS = "..."; //$NON-NLS-1$
protected static final String COLON_COLON = "::"; //$NON-NLS-1$
+ protected static final String COLON_SPACE = ": "; //$NON-NLS-1$
public NodeWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) {
super();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java
index 36238a1cd51..2e1e6dcafd4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.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
@@ -32,10 +32,10 @@ import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
-import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
@@ -77,7 +77,7 @@ public class StatementWriter extends NodeWriter{
private boolean decrementIndentationLevelOneMore = false;
private final DeclarationWriter declWriter;
- public StatementWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ public StatementWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap);
declWriter = new DeclarationWriter(scribe, visitor, commentMap);
}
@@ -140,6 +140,9 @@ public class StatementWriter extends NodeWriter{
} else if (statement instanceof IASTForStatement) {
writeForStatement((IASTForStatement) statement);
newLine = false;
+ } else if (statement instanceof ICPPASTRangeBasedForStatement) {
+ writeForStatement((ICPPASTRangeBasedForStatement) statement);
+ newLine = false;
} else if (statement instanceof IASTDoStatement) {
writeDoStatement((IASTDoStatement) statement);
newLine = true;
@@ -204,6 +207,18 @@ public class StatementWriter extends NodeWriter{
writeBodyStatement(forStatment.getBody(), false);
}
+ private void writeForStatement(ICPPASTRangeBasedForStatement forStatment) {
+ scribe.noNewLines();
+ scribe.print(FOR);
+ writeDeclarationWithoutSemicolon(forStatment.getDeclaration());
+ scribe.print(COLON_SPACE);
+ visitNodeIfNotNull(forStatment.getInitializerClause());
+ scribe.print(')');
+ scribe.newLines();
+ nextCompoundNoNewLine();
+ writeBodyStatement(forStatment.getBody(), false);
+ }
+
private void writeIfStatement(IASTIfStatement ifStatement) {
scribe.print(IF);
scribe.noNewLines();

Back to the top