improved PHP parser
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / DefaultCase.java
1 /***********************************************************************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3  * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4  * http://www.eclipse.org/legal/cpl-v10.html
5  * 
6  * Contributors: IBM Corporation - initial API and implementation
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpeclipse.internal.compiler.ast;
9
10 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
11 import net.sourceforge.phpdt.internal.compiler.codegen.CaseLabel;
12 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
13 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
14 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
15 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
16 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
17
18 public class DefaultCase extends Statement {
19
20   public CaseLabel targetLabel;
21
22   /**
23    * DefautCase constructor comment.
24    */
25   public DefaultCase(int sourceEnd, int sourceStart) {
26
27     this.sourceStart = sourceStart;
28     this.sourceEnd = sourceEnd;
29   }
30
31   public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
32
33     return flowInfo;
34   }
35
36   /**
37    * Default case code generation
38    * 
39    * @param currentScope
40    *          net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
41    * @param codeStream
42    *          net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
43    */
44   //    public void generateCode(BlockScope currentScope, CodeStream codeStream) {
45   //
46   //            if ((bits & IsReachableMASK) == 0) {
47   //                    return;
48   //            }
49   //            int pc = codeStream.position;
50   //            targetLabel.place();
51   //            codeStream.recordPositionsFrom(pc, this.sourceStart);
52   //
53   //    }
54   /**
55    * No-op : should use resolveCase(...) instead.
56    */
57   public void resolve(BlockScope scope) {
58   }
59
60   public Constant resolveCase(BlockScope scope, TypeBinding testType, SwitchStatement switchStatement) {
61
62     // remember the default case into the associated switch statement
63     if (switchStatement.defaultCase != null)
64       scope.problemReporter().duplicateDefaultCase(this);
65
66     // on error the last default will be the selected one .... (why not) ....
67     switchStatement.defaultCase = this;
68     resolve(scope);
69     return null;
70   }
71
72   public StringBuffer printStatement(int tab, StringBuffer output) {
73
74     printIndent(tab, output);
75     output.append("default : "); //$NON-NLS-1$
76     return output.append(';');
77   }
78
79   public String toString(int tab) {
80
81     String s = tabString(tab);
82     s = s + "default : "; //$NON-NLS-1$
83     return s;
84   }
85
86   public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
87
88     visitor.visit(this, blockScope);
89     visitor.endVisit(this, blockScope);
90   }
91 }