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.BranchLabel;
14: import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
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 FalseLiteral extends MagicLiteral {
20: static final char[] source = { 'f', 'a', 'l', 's', 'e' };
21:
22: public FalseLiteral(int s, int e) {
23: super (s, e);
24: }
25:
26: public void computeConstant() {
27: constant = BooleanConstant.fromValue(false);
28: }
29:
30: /**
31: * Code generation for false 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(this .constant,
42: this .implicitConversion);
43: }
44: codeStream.recordPositionsFrom(pc, this .sourceStart);
45: }
46:
47: public void generateOptimizedBoolean(BlockScope currentScope,
48: CodeStream codeStream, BranchLabel trueLabel,
49: BranchLabel falseLabel, boolean valueRequired) {
50:
51: // falseLabel being not nil means that we will not fall through into the FALSE case
52:
53: int pc = codeStream.position;
54: if (valueRequired) {
55: if (falseLabel != null) {
56: // implicit falling through the TRUE case
57: if (trueLabel == null) {
58: codeStream.goto_(falseLabel);
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: }
|