Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-04-08 11:41:44 +0000
committerMarkus Schorn2008-04-08 11:41:44 +0000
commit3c78f0d8e1326454c4670664f5c1c691e970379c (patch)
treea629647723d8dc5801fbe141d6850971e2aaa99a /core/org.eclipse.cdt.core/parser
parentb7b91190f550f3b87a54984c0c216f5928d52712 (diff)
downloadorg.eclipse.cdt-3c78f0d8e1326454c4670664f5c1c691e970379c.tar.gz
org.eclipse.cdt-3c78f0d8e1326454c4670664f5c1c691e970379c.tar.xz
org.eclipse.cdt-3c78f0d8e1326454c4670664f5c1c691e970379c.zip
Fix for omitted positive expression in conditional expression, bug 212905.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java12
6 files changed, 37 insertions, 14 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java
index 29ef5306721..e6fa57385fa 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java
@@ -736,8 +736,11 @@ public class ASTSignatureUtil {
result.append(SPACE);
result.append(Keywords.cpQUESTION);
result.append(SPACE);
- result.append(getExpressionString(expression.getPositiveResultExpression()));
- result.append(SPACE);
+ final IASTExpression positiveExpression = expression.getPositiveResultExpression();
+ if (positiveExpression != null) {
+ result.append(getExpressionString(positiveExpression));
+ result.append(SPACE);
+ }
result.append(Keywords.cpCOLON);
result.append(SPACE);
result.append(getExpressionString(expression.getNegativeResultExpression()));
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java
index a518b98df13..5f157cda823 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 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
+ * IBM Rational Software - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@@ -58,9 +58,10 @@ public interface IASTConditionalExpression extends IASTExpression {
public void setLogicalConditionExpression(IASTExpression expression);
/**
- * Get the positive result expression.
+ * Get the positive result expression, or <code>null</code> in case the positive condition was omitted (this is
+ * a gcc extension).
*
- * @return <code>IASTExpression</code>
+ * @return <code>IASTExpression</code>, or <code>null</code>.
*/
public IASTExpression getPositiveResultExpression();
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 b99ec621b60..27717a5bedd 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 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
@@ -860,7 +860,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
IASTExpression firstExpression = logicalOrExpression();
if (LT(1) == IToken.tQUESTION) {
consume();
- IASTExpression secondExpression = expression();
+ IASTExpression secondExpression= null;
+ if (LT(1) != IToken.tCOLON) {
+ secondExpression = expression();
+ }
IASTExpression thirdExpression = null;
if (LT(1) != IToken.tEOC) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index b5c7b4e7938..c8be960dcd0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -799,8 +799,12 @@ public class CVisitor {
return getExpressionType( ((IASTExpressionStatement)st).getExpression() );
}
} else if( expression instanceof IASTConditionalExpression ){
- IASTConditionalExpression conditional = (IASTConditionalExpression) expression;
- IType t2 = getExpressionType( conditional.getPositiveResultExpression() );
+ final IASTConditionalExpression conditional = (IASTConditionalExpression) expression;
+ IASTExpression positiveExpression = conditional.getPositiveResultExpression();
+ if (positiveExpression == null) {
+ positiveExpression= conditional.getLogicalConditionExpression();
+ }
+ IType t2 = getExpressionType(positiveExpression);
IType t3 = getExpressionType( conditional.getNegativeResultExpression() );
if( t3 instanceof IPointerType || t2 == null )
return t3;
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 2697e722d33..ec5f111c02b 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
@@ -2008,8 +2008,12 @@ public class CPPVisitor {
return getExpressionType(((IASTExpressionStatement)st).getExpression());
}
} else if (expression instanceof IASTConditionalExpression) {
- IASTConditionalExpression conditional = (IASTConditionalExpression) expression;
- IType t2 = getExpressionType(conditional.getPositiveResultExpression());
+ final IASTConditionalExpression conditional = (IASTConditionalExpression) expression;
+ IASTExpression positiveExpression = conditional.getPositiveResultExpression();
+ if (positiveExpression == null) {
+ positiveExpression= conditional.getLogicalConditionExpression();
+ }
+ IType t2 = getExpressionType(positiveExpression);
IType t3 = getExpressionType(conditional.getNegativeResultExpression());
if (t3 instanceof IPointerType || t2 == null)
return t3;
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 ea8c206d909..ba99ccf56ba 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
@@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@@ -456,7 +457,14 @@ public class ExpressionWriter extends NodeWriter{
private void writeConditionalExpression(IASTConditionalExpression condExp) {
condExp.getLogicalConditionExpression().accept(visitor);
scribe.print(SPACE_QUESTIONMARK_SPACE);
- condExp.getPositiveResultExpression().accept(visitor);
+ final IASTExpression positiveExpression = condExp.getPositiveResultExpression();
+ // gcc extension allows to omit the positive expression.
+ if (positiveExpression == null) {
+ scribe.print(' ');
+ }
+ else {
+ positiveExpression.accept(visitor);
+ }
scribe.print(SPACE_COLON_SPACE);
condExp.getNegativeResultExpression().accept(visitor);

Back to the top