1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.internal.compiler.ASTVisitor; 14 import org.eclipse.jdt.internal.compiler.impl.*; 15 import org.eclipse.jdt.internal.compiler.codegen.*; 16 import org.eclipse.jdt.internal.compiler.lookup.*; 17 import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; 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 30 constant = CharConstant.fromValue(value); 31 } 32 private void computeValue() { 33 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 : int number = ScannerHelper.getNumericValue(digit); 67 if ((digit = source[3]) != '\'') 68 number = (number * 8) + ScannerHelper.getNumericValue(digit); 69 else { 70 constant = CharConstant.fromValue(value = (char) number); 71 break; 72 } 73 if ((digit = source[4]) != '\'') 74 number = (number * 8) + ScannerHelper.getNumericValue(digit); 75 value = (char) number; 76 break; 77 } 78 } 79 86 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { 87 int pc = codeStream.position; 88 if (valueRequired) { 89 codeStream.generateConstant(constant, implicitConversion); 90 } 91 codeStream.recordPositionsFrom(pc, this.sourceStart); 92 } 93 public TypeBinding literalType(BlockScope scope) { 94 return TypeBinding.CHAR; 95 } 96 public void traverse(ASTVisitor visitor, BlockScope blockScope) { 97 visitor.visit(this, blockScope); 98 visitor.endVisit(this, blockScope); 99 } 100 } 101 | Popular Tags |