KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ast > FloatLiteralExpr


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base.ast;
26
27 import org.aspectj.compiler.base.JavaCompiler;
28
29 import org.aspectj.compiler.base.bcg.FieldBuilder;
30 import org.aspectj.compiler.base.bcg.CodeBuilder;
31 import org.aspectj.compiler.base.bcg.Label;
32
33 /**
34   * @grammar floatLiteral
35   * @property float floatValue
36   */

37 public class FloatLiteralExpr extends NumericLiteralExpr {
38
39     public int getIntValue() { return (int)floatValue; }
40     public long getLongValue() { return (long)floatValue; }
41     public double getDoubleValue() { return (double)floatValue; }
42     public String JavaDoc getStringValue() { return "" + floatValue; }
43
44     public FloatLiteralExpr(SourceLocation source, float _floatValue) {
45         this(source, source.getCompiler().getTypeManager().floatType, createUsefulString(_floatValue), _floatValue);
46     }
47
48     private static String JavaDoc createUsefulString(float f) {
49         if (Float.isNaN(f)) {
50             return "(0.0f / 0.0f)";
51         } else if (Float.isInfinite(f)) {
52             return f > 0 ? "(1.0f / 0.0f)" : "(-1.0f / 0.0f)";
53         } else {
54             return f + "f";
55         }
56     }
57
58     // ------------------------------
59
// bcg
60
protected void cgValue(CodeBuilder cb) {
61         cb.emitFloatConstant(floatValue);
62     }
63     public void addConstant(FieldBuilder fb) {
64         fb.setConstantValue(floatValue);
65     }
66     public boolean isConstantZero() { return floatValue == 0.0f; }
67
68     //BEGIN: Generated from @child and @property
69
protected float floatValue;
70     public float getFloatValue() { return floatValue; }
71     public void setFloatValue(float _floatValue) { floatValue = _floatValue; }
72
73     public FloatLiteralExpr(SourceLocation location, Type _type, String JavaDoc _value, float _floatValue) {
74         super(location, _type, _value);
75         setFloatValue(_floatValue);
76     }
77     protected FloatLiteralExpr(SourceLocation source) {
78         super(source);
79     }
80
81     public ASTObject copyWalk(CopyWalker walker) {
82         FloatLiteralExpr ret = new FloatLiteralExpr(getSourceLocation());
83         ret.preCopy(walker, this);
84         ret.type = type;
85         ret.value = value;
86         ret.floatValue = floatValue;
87         return ret;
88     }
89
90
91     public String JavaDoc getDefaultDisplayName() {
92         return "FloatLiteralExpr(type: "+type+", "+"value: "+value+", "+"floatValue: "+floatValue+")";
93     }
94
95     //END: Generated from @child and @property
96
}
97
Popular Tags