01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
11:
12: import org.eclipse.jdt.internal.compiler.ASTVisitor;
13: import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
14: import org.eclipse.jdt.internal.compiler.codegen.BranchLabel;
15: import org.eclipse.jdt.internal.compiler.impl.BooleanConstant;
16: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17: import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
18:
19: public class TrueLiteral extends MagicLiteral {
20: static final char[] source = { 't', 'r', 'u', 'e' };
21:
22: public TrueLiteral(int s, int e) {
23: super (s, e);
24: }
25:
26: public void computeConstant() {
27: this .constant = BooleanConstant.fromValue(true);
28: }
29:
30: /**
31: * Code generation for the true literal
32: *
33: * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
34: * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
35: * @param valueRequired boolean
36: */
37: public void generateCode(BlockScope currentScope,
38: CodeStream codeStream, boolean valueRequired) {
39: int pc = codeStream.position;
40: if (valueRequired) {
41: codeStream.generateConstant(constant, implicitConversion);
42: }
43: codeStream.recordPositionsFrom(pc, this .sourceStart);
44: }
45:
46: public void generateOptimizedBoolean(BlockScope currentScope,
47: CodeStream codeStream, BranchLabel trueLabel,
48: BranchLabel falseLabel, boolean valueRequired) {
49:
50: // trueLabel being not nil means that we will not fall through into the TRUE case
51:
52: int pc = codeStream.position;
53: // constant == true
54: if (valueRequired) {
55: if (falseLabel == null) {
56: // implicit falling through the FALSE case
57: if (trueLabel != null) {
58: codeStream.goto_(trueLabel);
59: }
60: }
61: }
62: codeStream.recordPositionsFrom(pc, this .sourceStart);
63: }
64:
65: public TypeBinding literalType(BlockScope scope) {
66: return TypeBinding.BOOLEAN;
67: }
68:
69: /**
70: *
71: */
72: public char[] source() {
73: return source;
74: }
75:
76: public void traverse(ASTVisitor visitor, BlockScope scope) {
77: visitor.visit(this, scope);
78: visitor.endVisit(this, scope);
79: }
80: }
|