Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJohn Camelon2005-06-21 15:12:00 +0000
committerJohn Camelon2005-06-21 15:12:00 +0000
commit629a1ea3503ba3daeba179a4d60e3d224c902349 (patch)
treeb9b455f52746053817da6dfe21dd95b17bcb26bf /core
parent58615beb775000b73acc80d42e0ca707c406d5ae (diff)
downloadorg.eclipse.cdt-629a1ea3503ba3daeba179a4d60e3d224c902349.tar.gz
org.eclipse.cdt-629a1ea3503ba3daeba179a4d60e3d224c902349.tar.xz
org.eclipse.cdt-629a1ea3503ba3daeba179a4d60e3d224c902349.zip
Fixed Bug 84478 [C++ Parser] does not support declarations inside while condition
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTSwitchStatement.java42
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java32
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java25
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java24
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java37
9 files changed, 137 insertions, 44 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 59fb3edbabe..77d7133f333 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -4763,4 +4763,11 @@ public class AST2CPPTests extends AST2BaseTest {
assertNoProblemBindings( col );
}
+ public void testBug84478_3() throws Exception {
+ IASTTranslationUnit tu = parse( "void foo() { switch( int x = 4 ) { case 4: break; default: break;} }", ParserLanguage.CPP ); //$NON-NLS-1$
+ CPPNameCollector col = new CPPNameCollector();
+ tu.accept( col );
+ assertNoProblemBindings( col );
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java
index 358d54a5c6c..ce4198da318 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java
@@ -42,7 +42,7 @@ public interface IASTForStatement extends IASTStatement {
public static final ASTNodeProperty BODY = new ASTNodeProperty("IASTForStatement.BODY - IASTStatement body of IASTForStatement"); //$NON-NLS-1$
/**
- * <code>INITDECLARATION</code> represents the relationship between a
+ * <code>INITIALIZER</code> represents the relationship between a
* <code>IASTForStatement</code> and its <code>IASTDeclaration</code>
* initializer.
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java
index 0b5fdc01fd4..995ce9eef3d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java
@@ -18,11 +18,11 @@ package org.eclipse.cdt.core.dom.ast;
public interface IASTSwitchStatement extends IASTStatement {
/**
- * <code>CONTROLLER</code> represents the relationship between an
+ * <code>CONTROLLER_EXP</code> represents the relationship between an
* <code>IASTSwitchStatement</code> and it's nested
* <code>IASTExpression</code>.
*/
- public static final ASTNodeProperty CONTROLLER = new ASTNodeProperty(
+ public static final ASTNodeProperty CONTROLLER_EXP = new ASTNodeProperty(
"IASTSwitchStatement.CONTROLLER - IASTExpression (controller) for IASTSwitchExpression"); //$NON-NLS-1$
/**
@@ -37,7 +37,7 @@ public interface IASTSwitchStatement extends IASTStatement {
*
* @return the controller expression
*/
- public IASTExpression getController();
+ public IASTExpression getControllerExpression();
/**
* Set the controlling expression for the switch.
@@ -45,7 +45,7 @@ public interface IASTSwitchStatement extends IASTStatement {
* @param controller
* <code>IASTExpression</code>
*/
- public void setController(IASTExpression controller);
+ public void setControllerExpression(IASTExpression controller);
/**
* Returns the body of the switch statement.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTSwitchStatement.java
new file mode 100644
index 00000000000..f5cbfde95f4
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTSwitchStatement.java
@@ -0,0 +1,42 @@
+/**********************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.core.dom.ast.cpp;
+
+import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
+
+public interface ICPPASTSwitchStatement extends IASTSwitchStatement {
+
+ /**
+ * <code>CONTROLLER_DECLARATION</code> represents the relationship between an
+ * <code>IASTSwitchStatement</code> and it's nested
+ * <code>IASTDeclaration</code>.
+ */
+ public static final ASTNodeProperty CONTROLLER_DECLARATION = new ASTNodeProperty(
+ "IASTSwitchStatement.CONTROLLER - IASTDeclaration (controller) for IASTSwitchExpression"); //$NON-NLS-1$
+
+ /**
+ * In C++, a switch statement can be contorller by a declaration.
+ *
+ * @return <code>IASTDeclaration</code>
+ */
+ public IASTDeclaration getControllerDeclaration();
+
+ /**
+ * In C++, a switch statement can be contorller by a declaration.
+ *
+ * @param d <code>IASTDeclaration</code>
+ */
+ public void setControllerDeclaration( IASTDeclaration d );
+
+
+}
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 68a41c143a1..8fb0353e3db 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
@@ -49,7 +49,6 @@ 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;
-import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
@@ -1415,11 +1414,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
/**
* @return
*/
- protected abstract IASTSwitchStatement createSwitchStatement();
-
- /**
- * @return
- */
protected abstract IASTIdExpression createIdExpression();
/**
@@ -1930,32 +1924,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
/**
- * @return
- * @throws EndOfFileException
- * @throws BacktrackException
- */
- protected IASTStatement parseSwitchStatement() throws EndOfFileException,
- BacktrackException {
- int startOffset;
- startOffset = consume(IToken.t_switch).getOffset();
- consume(IToken.tLPAREN);
- IASTExpression switch_condition = condition();
- consume(IToken.tRPAREN);
- IASTStatement switch_body = statement();
-
- IASTSwitchStatement switch_statement = createSwitchStatement();
- ((ASTNode) switch_statement).setOffsetAndLength(startOffset,
- calculateEndOffset(switch_body) - startOffset);
- switch_statement.setController(switch_condition);
- switch_condition.setParent(switch_statement);
- switch_condition.setPropertyInParent(IASTSwitchStatement.CONTROLLER);
- switch_statement.setBody(switch_body);
- switch_body.setParent(switch_statement);
- switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
- return switch_statement;
- }
-
- /**
* @param result
*/
protected void reconcileLengths(IASTIfStatement result) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java
index 2fc2e021258..0caedf4893b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java
@@ -28,14 +28,14 @@ public class CASTSwitchStatement extends CASTNode implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#getController()
*/
- public IASTExpression getController() {
+ public IASTExpression getControllerExpression() {
return controller;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#setController(org.eclipse.cdt.core.dom.ast.IASTExpression)
*/
- public void setController(IASTExpression controller) {
+ public void setControllerExpression(IASTExpression controller) {
this.controller = controller;
}
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 06330a65cea..451edbf5a07 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
@@ -2792,5 +2792,30 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
calculateEndOffset(castExpression));
}
+ /**
+ * @return
+ * @throws EndOfFileException
+ * @throws BacktrackException
+ */
+ protected IASTStatement parseSwitchStatement() throws EndOfFileException, BacktrackException {
+ int startOffset;
+ startOffset = consume(IToken.t_switch).getOffset();
+ consume(IToken.tLPAREN);
+ IASTExpression switch_condition = condition();
+ consume(IToken.tRPAREN);
+ IASTStatement switch_body = statement();
+
+ IASTSwitchStatement switch_statement = createSwitchStatement();
+ ((ASTNode) switch_statement).setOffsetAndLength(startOffset,
+ calculateEndOffset(switch_body) - startOffset);
+ switch_statement.setControllerExpression(switch_condition);
+ switch_condition.setParent(switch_statement);
+ switch_condition.setPropertyInParent(IASTSwitchStatement.CONTROLLER_EXP);
+ switch_statement.setBody(switch_body);
+ switch_body.setParent(switch_statement);
+ switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
+ return switch_statement;
+ }
+
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java
index 816b7e7b1aa..1fd4e30a66b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java
@@ -11,32 +11,34 @@
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.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
-import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* @author jcamelon
*/
public class CPPASTSwitchStatement extends CPPASTNode implements
- IASTSwitchStatement, IASTAmbiguityParent {
+ ICPPASTSwitchStatement, IASTAmbiguityParent {
private IASTExpression controller;
private IASTStatement body;
+ private IASTDeclaration decl;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#getController()
*/
- public IASTExpression getController() {
+ public IASTExpression getControllerExpression() {
return controller;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#setController(org.eclipse.cdt.core.dom.ast.IASTExpression)
*/
- public void setController(IASTExpression controller) {
+ public void setControllerExpression(IASTExpression controller) {
this.controller = controller;
}
@@ -80,7 +82,21 @@ public class CPPASTSwitchStatement extends CPPASTNode implements
other.setParent( child.getParent() );
controller = (IASTExpression) other;
}
+ if( child == decl )
+ {
+ other.setPropertyInParent( child.getPropertyInParent() );
+ other.setParent( child.getParent() );
+ decl = (IASTDeclaration) other;
+ }
}
+ public IASTDeclaration getControllerDeclaration() {
+ return decl;
+ }
+
+ public void setControllerDeclaration(IASTDeclaration d) {
+ decl = d;
+ }
+
}
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 d7aa3dafb1c..96a68c43a16 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
@@ -108,6 +108,7 @@ 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;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
@@ -4893,7 +4894,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
/**
* @return
*/
- protected IASTSwitchStatement createSwitchStatement() {
+ protected ICPPASTSwitchStatement createSwitchStatement() {
return new CPPASTSwitchStatement();
}
@@ -5334,4 +5335,38 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return buildUnaryExpression(operator, castExpression, offset,
calculateEndOffset(castExpression));
}
+
+ /**
+ * @return
+ * @throws EndOfFileException
+ * @throws BacktrackException
+ */
+ protected IASTStatement parseSwitchStatement() throws EndOfFileException, BacktrackException {
+ int startOffset;
+ startOffset = consume(IToken.t_switch).getOffset();
+ consume(IToken.tLPAREN);
+ IASTNode switch_condition = cppStyleCondition();
+ consume(IToken.tRPAREN);
+ IASTStatement switch_body = statement();
+
+ ICPPASTSwitchStatement switch_statement = createSwitchStatement();
+ ((ASTNode) switch_statement).setOffsetAndLength(startOffset,
+ calculateEndOffset(switch_body) - startOffset);
+ if( switch_condition instanceof IASTExpression )
+ {
+ switch_statement.setControllerExpression((IASTExpression) switch_condition);
+ switch_condition.setParent(switch_statement);
+ switch_condition.setPropertyInParent(IASTSwitchStatement.CONTROLLER_EXP);
+ }
+ else if( switch_condition instanceof IASTDeclaration )
+ {
+ switch_statement.setControllerDeclaration((IASTDeclaration) switch_condition);
+ switch_condition.setParent(switch_statement);
+ switch_condition.setPropertyInParent(ICPPASTSwitchStatement.CONTROLLER_DECLARATION);
+ }
+ switch_statement.setBody(switch_body);
+ switch_body.setParent(switch_statement);
+ switch_body.setPropertyInParent(IASTSwitchStatement.BODY);
+ return switch_statement;
+ }
}

Back to the top