Some minor changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Case.java
index 6e885e0..751f223 100644 (file)
-/*******************************************************************************
- * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
- * All rights reserved. This program and the accompanying materials 
- * are made available under the terms of the Common Public License v0.5 
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- * 
- * Contributors:
- *     IBM Corporation - initial API and implementation
- ******************************************************************************/
 package net.sourceforge.phpdt.internal.compiler.ast;
 
-import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
-import net.sourceforge.phpdt.internal.compiler.codegen.CaseLabel;
-import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream;
-import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
-import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
-import net.sourceforge.phpdt.internal.compiler.impl.Constant;
-import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
-import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
-
-public class Case extends Statement {
-       
-       public Expression constantExpression;
-       public CaseLabel targetLabel;
-       public Case(int sourceStart, Expression constantExpression) {
-               this.constantExpression = constantExpression;
-               this.sourceEnd = constantExpression.sourceEnd;
-               this.sourceStart = sourceStart;
-       }
-
-       public FlowInfo analyseCode(
-               BlockScope currentScope,
-               FlowContext flowContext,
-               FlowInfo flowInfo) {
-
-               if (constantExpression.constant == NotAConstant)
-                       currentScope.problemReporter().caseExpressionMustBeConstant(constantExpression);
-
-               this.constantExpression.analyseCode(currentScope, flowContext, flowInfo);
-               return flowInfo;
-       }
-
-       /**
-        * Case code generation
-        *
-        */
-       public void generateCode(BlockScope currentScope, CodeStream codeStream) {
-
-               if ((bits & IsReachableMASK) == 0) {
-                       return;
-               }
-               int pc = codeStream.position;
-               targetLabel.place();
-               codeStream.recordPositionsFrom(pc, this.sourceStart);
-       }
-
-       public void resolve(BlockScope scope) {
-
-               // error....use resolveCase....
-               throw new NullPointerException();
-       }
-
-       public Constant resolveCase(
-               BlockScope scope,
-               TypeBinding testTb,
-               SwitchStatement switchStatement) {
-
-               // add into the collection of cases of the associated switch statement
-               switchStatement.cases[switchStatement.caseCount++] = this;
-               TypeBinding caseTb = constantExpression.resolveType(scope);
-               if (caseTb == null || testTb == null)
-                       return null;
-               if (constantExpression.isConstantValueOfTypeAssignableToType(caseTb, testTb))
-                       return constantExpression.constant;
-               if (BlockScope.areTypesCompatible(caseTb, testTb))
-                       return constantExpression.constant;
-               scope.problemReporter().typeMismatchErrorActualTypeExpectedType(
-                       constantExpression,
-                       caseTb,
-                       testTb);
-               return null;
-       }
-
-       public String toString(int tab) {
-
-               String s = tabString(tab);
-               s = s + "case " + constantExpression.toStringExpression() + " : "; //$NON-NLS-1$ //$NON-NLS-2$
-               return s;
-       }
-
-       public void traverse(
-               IAbstractSyntaxTreeVisitor visitor,
-               BlockScope blockScope) {
-
-               if (visitor.visit(this, blockScope)) {
-                       constantExpression.traverse(visitor, blockScope);
-               }
-               visitor.endVisit(this, blockScope);
-       }
-}
\ No newline at end of file
+import java.util.List;
+
+/**
+ * A Case statement for a Switch.
+ * @author Matthieu Casanova
+ */
+public final class Case extends AbstractCase {
+
+  private final Expression value;
+
+  public Case(final Expression value,
+              final Statement[] statements,
+              final int sourceStart,
+              final int sourceEnd) {
+    super(statements, sourceStart, sourceEnd);
+    this.value = value;
+  }
+
+  /**
+   * Return the object into String.
+   * @param tab how many tabs (not used here
+   * @return a String
+   */
+  public String toString(final int tab) {
+    final StringBuffer buff = new StringBuffer(tabString(tab));
+    buff.append("case ");
+    buff.append(value.toStringExpression());
+    buff.append(" :\n");
+    if (statements != null) {
+      for (int i = 0; i < statements.length; i++) {
+        final Statement statement = statements[i];
+        buff.append(statement.toString(tab + 1));
+      }
+    }
+    return buff.toString();
+  }
+
+  /**
+   * get the modified variables.
+   *
+   * @param list the list where we will put variables
+   */
+  public void getModifiedVariable(final List list) {
+    super.getModifiedVariable(list);
+    value.getModifiedVariable(list);
+  }
+
+  /**
+   * Get the variables used.
+   *
+   * @param list the list where we will put variables
+   */
+  public void getUsedVariable(final List list) {
+    super.getUsedVariable(list);
+    value.getUsedVariable(list);
+  }
+}