Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanuel Graf2010-12-06 04:02:48 -0500
committerEmanuel Graf2010-12-06 04:02:48 -0500
commit501fad33d6d81e6893b313351960c0c2b893f479 (patch)
treea0ae788c34e90d5f5ff7cbca44de0e8a6c7cc8d4 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite
parent60281e5c58bad47aa59b04f9cee6a91c09d50ec8 (diff)
downloadorg.eclipse.cdt-501fad33d6d81e6893b313351960c0c2b893f479.tar.gz
org.eclipse.cdt-501fad33d6d81e6893b313351960c0c2b893f479.tar.xz
org.eclipse.cdt-501fad33d6d81e6893b313351960c0c2b893f479.zip
Bug: 331637 - ExpressionWriter & DeclaratorWriter do not support ICPPASTLambdaExpression patch by Pascal Kesseli
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java47
2 files changed, 63 insertions, 1 deletions
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 171f370ee4..53c2655397 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
@@ -49,6 +49,8 @@ public class DeclaratorWriter extends NodeWriter {
private static final String AMPERSAND__AMPERSAND_SPACE = "&& "; //$NON-NLS-1$
private static final String STAR_SPACE = "* "; //$NON-NLS-1$
private static final String PURE_VIRTUAL = " =0"; //$NON-NLS-1$
+ private static final String MUTABLE = "mutable"; //$NON-NLS-1$
+ private static final String ARROW_OPERATOR = "->"; //$NON-NLS-1$
public DeclaratorWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap);
@@ -93,7 +95,10 @@ public class DeclaratorWriter extends NodeWriter {
private void writeFunctionDeclarator(IASTStandardFunctionDeclarator funcDec) {
IASTPointerOperator[] pointOps = funcDec.getPointerOperators();
writePointerOperators(funcDec, pointOps);
- funcDec.getName().accept(visitor);
+ // XXX: Lambda declarators happen to have null names rather than empty ones when parsed
+ if (funcDec.getName() != null) {
+ funcDec.getName().accept(visitor);
+ }
writeNestedDeclarator(funcDec);
writeParameters(funcDec);
writeInitializer(funcDec);
@@ -134,10 +139,20 @@ public class DeclaratorWriter extends NodeWriter {
scribe.printSpace();
scribe.print(VOLATILE);
}
+ if (funcDec.isMutable()) {
+ scribe.printSpace();
+ scribe.print(MUTABLE);
+ }
if(funcDec.isPureVirtual()) {
scribe.print(PURE_VIRTUAL);
}
writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification());
+ if (funcDec.getTrailingReturnType() != null) {
+ scribe.printSpace();
+ scribe.print(ARROW_OPERATOR);
+ scribe.printSpace();
+ funcDec.getTrailingReturnType().accept(visitor);
+ }
}
protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
index 8dbf6b354d..c72974ca3d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
@@ -30,9 +30,11 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
@@ -112,6 +114,9 @@ public class ExpressionWriter extends NodeWriter{
private static final String MODULO_OP = " % "; //$NON-NLS-1$
private static final String DIVIDE_OP = " / "; //$NON-NLS-1$
private static final String MULTIPLY_OP = " * "; //$NON-NLS-1$
+ private static final String OPENING_SQUARE_BRACKET = "["; //$NON-NLS-1$
+ private static final String CLOSING_SQUARE_BRACKET = "]"; //$NON-NLS-1$
+ private static final String THIS = "this"; //$NON-NLS-1$
private final MacroExpansionHandler macroHandler;
public ExpressionWriter(Scribe scribe, CPPASTVisitor visitor, MacroExpansionHandler macroHandler, NodeCommentMap commentMap) {
@@ -150,6 +155,8 @@ public class ExpressionWriter extends NodeWriter{
writeDeleteExpression((ICPPASTDeleteExpression) expression);
}else if (expression instanceof ICPPASTSimpleTypeConstructorExpression) {
writeSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression) expression);
+ } else if (expression instanceof ICPPASTLambdaExpression) {
+ writeLambdaExpression((ICPPASTLambdaExpression) expression);
}
}
@@ -525,5 +532,45 @@ public class ExpressionWriter extends NodeWriter{
simpTypeCtorExp.getDeclSpecifier().accept(visitor);
visitNodeIfNotNull(simpTypeCtorExp.getInitializer());
}
+
+ private void writeLambdaExpression(ICPPASTLambdaExpression lambdaExpression) {
+ writeLambdaIntroducer(lambdaExpression);
+ if (lambdaExpression.getDeclarator() != null) {
+ lambdaExpression.getDeclarator().accept(visitor);
+ }
+ scribe.printSpace();
+ lambdaExpression.getBody().accept(visitor);
+ }
+
+ private void writeLambdaIntroducer(ICPPASTLambdaExpression lambdaExpression) {
+ scribe.print(OPENING_SQUARE_BRACKET);
+ ICPPASTLambdaExpression.CaptureDefault captureDefault = lambdaExpression.getCaptureDefault();
+ if (captureDefault.equals(ICPPASTLambdaExpression.CaptureDefault.BY_COPY)) {
+ scribe.print('=');
+ } else if (captureDefault.equals(ICPPASTLambdaExpression.CaptureDefault.BY_REFERENCE)) {
+ scribe.print('&');
+ }
+ for (ICPPASTCapture capture : lambdaExpression.getCaptures()) {
+ boolean isNotFirst = capture != lambdaExpression.getCaptures()[0];
+ boolean hasDefaultCapture = captureDefault != ICPPASTLambdaExpression.CaptureDefault.UNSPECIFIED;
+ if (isNotFirst || hasDefaultCapture) {
+ scribe.print(COMMA_SPACE);
+ }
+ writeCapture(capture);
+ }
+ scribe.print(CLOSING_SQUARE_BRACKET);
+ }
+
+ private void writeCapture(ICPPASTCapture capture) {
+ if (capture.capturesThisPointer()) {
+ scribe.print(THIS);
+ } else {
+ if (capture.isByReference()) {
+ scribe.print(AMPERSAND_OP);
+ }
+ capture.getIdentifier().accept(visitor);
+ }
+ }
+
}

Back to the top