KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > TrueLiteral


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.ast;
12
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
15 import org.eclipse.jdt.internal.compiler.codegen.BranchLabel;
16 import org.eclipse.jdt.internal.compiler.impl.BooleanConstant;
17 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
18 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
19
20 public class TrueLiteral extends MagicLiteral {
21     static final char[] source = {'t' , 'r' , 'u' , 'e'};
22 public TrueLiteral(int s , int e) {
23     super(s,e);
24 }
25 public void computeConstant() {
26     this.constant = BooleanConstant.fromValue(true);
27 }
28 /**
29  * Code generation for the true literal
30  *
31  * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
32  * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
33  * @param valueRequired boolean
34  */

35 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
36     int pc = codeStream.position;
37     if (valueRequired) {
38         codeStream.generateConstant(constant, implicitConversion);
39     }
40     codeStream.recordPositionsFrom(pc, this.sourceStart);
41 }
42 public void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStream, BranchLabel trueLabel, BranchLabel falseLabel, boolean valueRequired) {
43
44     // trueLabel being not nil means that we will not fall through into the TRUE case
45

46     int pc = codeStream.position;
47     // constant == true
48
if (valueRequired) {
49         if (falseLabel == null) {
50             // implicit falling through the FALSE case
51
if (trueLabel != null) {
52                 codeStream.goto_(trueLabel);
53             }
54         }
55     }
56     codeStream.recordPositionsFrom(pc, this.sourceStart);
57 }
58 public TypeBinding literalType(BlockScope scope) {
59     return TypeBinding.BOOLEAN;
60 }
61 /**
62  *
63  */

64 public char[] source() {
65     return source;
66 }
67 public void traverse(ASTVisitor visitor, BlockScope scope) {
68     visitor.visit(this, scope);
69     visitor.endVisit(this, scope);
70 }
71 }
72
Popular Tags