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