delete finally
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / CharLiteral.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
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
19 public class CharLiteral extends NumberLiteral {
20         char value;
21 public CharLiteral(char[] token, int s, int e) {
22         super(token, s, e);
23         computeValue();
24 }
25 public void computeConstant() {
26         //The source is a  char[3] first and last char are '
27         //This is true for both regular char AND unicode char
28         //BUT not for escape char like '\b' which are char[4]....
29
30         constant = Constant.fromValue(value);
31 }
32 private void computeValue() {
33         //The source is a  char[3] first and last char are '
34         //This is true for both regular char AND unicode char
35         //BUT not for escape char like '\b' which are char[4]....
36
37         if ((value = source[1]) != '\\')
38                 return;
39         char digit;
40         switch (digit = source[2]) {
41                 case 'b' :
42                         value = '\b';
43                         break;
44                 case 't' :
45                         value = '\t';
46                         break;
47                 case 'n' :
48                         value = '\n';
49                         break;
50                 case 'f' :
51                         value = '\f';
52                         break;
53                 case 'r' :
54                         value = '\r';
55                         break;
56                 case '\"' :
57                         value = '\"';
58                         break;
59                 case '\'' :
60                         value = '\'';
61                         break;
62                 case '\\' :
63                         value = '\\';
64                         break;
65                 default : //octal (well-formed: ended by a ' )
66                         int number = Character.getNumericValue(digit);
67                         if ((digit = source[3]) != '\'')
68                                 number = (number * 8) + Character.getNumericValue(digit);
69                         else {
70                                 constant = Constant.fromValue(value = (char) number);
71                                 break;
72                         };
73                         if ((digit = source[4]) != '\'')
74                                 number = (number * 8) + Character.getNumericValue(digit);
75                         value = (char) number;
76                         break;
77         }
78 }
79 /**
80  * CharLiteral code generation
81  *
82  * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
83  * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
84  * @param valueRequired boolean
85  */
86 //public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
87 //      int pc = codeStream.position;
88 //      if (valueRequired)
89 //              if ((implicitConversion >> 4) == T_char)
90 //                      codeStream.generateInlinedValue(value);
91 //              else
92 //                      codeStream.generateConstant(constant, implicitConversion);
93 //      codeStream.recordPositionsFrom(pc, this.sourceStart);
94 //}
95 public TypeBinding literalType(BlockScope scope) {
96         return CharBinding;
97 }
98 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
99         visitor.visit(this, blockScope);
100         visitor.endVisit(this, blockScope);
101 }
102 }