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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
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.lookup.*;
18 public class CharLiteral extends NumberLiteral {
20 public CharLiteral(char[] token, int s, int e) {
24 public void computeConstant() {
25 //The source is a char[3] first and last char are '
26 //This is true for both regular char AND unicode char
27 //BUT not for escape char like '\b' which are char[4]....
29 constant = Constant.fromValue(value);
31 private void computeValue() {
32 //The source is a char[3] first and last char are '
33 //This is true for both regular char AND unicode char
34 //BUT not for escape char like '\b' which are char[4]....
36 if ((value = source[1]) != '\\')
39 switch (digit = source[2]) {
64 default : //octal (welled formed, i.e. ended by a ' )
65 int number = Character.getNumericValue(digit);
66 if ((digit = source[3]) != '\'')
67 number = (number * 8) + Character.getNumericValue(digit);
69 constant = Constant.fromValue(value = (char) number);
72 if ((digit = source[4]) != '\'')
73 number = (number * 8) + Character.getNumericValue(digit);
74 value = (char) number;
79 * CharLiteral code generation
81 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
82 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
83 * @param valueRequired boolean
85 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
86 int pc = codeStream.position;
88 if ((implicitConversion >> 4) == T_char)
89 codeStream.generateInlinedValue(value);
91 codeStream.generateConstant(constant, implicitConversion);
92 codeStream.recordPositionsFrom(pc, this.sourceStart);
94 public TypeBinding literalType(BlockScope scope) {
97 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
98 visitor.visit(this, blockScope);
99 visitor.endVisit(this, blockScope);