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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.internal.compiler.ast;
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;
19 public class CharLiteral extends NumberLiteral {
21 public CharLiteral(char[] token, int s, int e) {
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]....
30 constant = Constant.fromValue(value);
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]....
37 if ((value = source[1]) != '\\')
40 switch (digit = source[2]) {
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);
70 constant = Constant.fromValue(value = (char) number);
73 if ((digit = source[4]) != '\'')
74 number = (number * 8) + Character.getNumericValue(digit);
75 value = (char) number;
80 * CharLiteral code generation
82 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
83 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
84 * @param valueRequired boolean
86 //public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
87 // int pc = codeStream.position;
89 // if ((implicitConversion >> 4) == T_char)
90 // codeStream.generateInlinedValue(value);
92 // codeStream.generateConstant(constant, implicitConversion);
93 // codeStream.recordPositionsFrom(pc, this.sourceStart);
95 public TypeBinding literalType(BlockScope scope) {
98 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
99 visitor.visit(this, blockScope);
100 visitor.endVisit(this, blockScope);