KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
35   * @grammar doubleLiteral
36   * @property double doubleValue
37   */

38 public class DoubleLiteralExpr extends NumericLiteralExpr {
39
40     public int getIntValue() { return (int)doubleValue; }
41     public long getLongValue() { return (long)doubleValue; }
42     public float getFloatValue() { return (float)doubleValue; }
43     public String JavaDoc getStringValue() { return "" + doubleValue; }
44
45     public DoubleLiteralExpr(SourceLocation source, double _doubleValue) {
46         this(source, source.getCompiler().getTypeManager().doubleType, createUsefulString(_doubleValue), _doubleValue);
47     }
48
49     private static String JavaDoc createUsefulString(double d) {
50         if (Double.isNaN(d)) {
51             return "(0.0 / 0.0)";
52         } else if (Double.isInfinite(d)) {
53             return d > 0 ? "(1.0 / 0.0)" : "(-1.0 / 0.0)";
54         } else {
55             return d + "d";
56         }
57     }
58
59     // ------------------------------
60
// bcg
61
protected void cgValue(CodeBuilder cb) {
62         cb.emitDoubleConstant(doubleValue);
63     }
64     public void addConstant(FieldBuilder fb) {
65         fb.setConstantValue(doubleValue);
66     }
67     public boolean isConstantZero() { return doubleValue == 0.0d; }
68     // end bcg
69

70     //BEGIN: Generated from @child and @property
71
protected double doubleValue;
72     public double getDoubleValue() { return doubleValue; }
73     public void setDoubleValue(double _doubleValue) { doubleValue = _doubleValue; }
74
75     public DoubleLiteralExpr(SourceLocation location, Type _type, String JavaDoc _value, double _doubleValue) {
76         super(location, _type, _value);
77         setDoubleValue(_doubleValue);
78     }
79     protected DoubleLiteralExpr(SourceLocation source) {
80         super(source);
81     }
82
83     public ASTObject copyWalk(CopyWalker walker) {
84         DoubleLiteralExpr ret = new DoubleLiteralExpr(getSourceLocation());
85         ret.preCopy(walker, this);
86         ret.type = type;
87         ret.value = value;
88         ret.doubleValue = doubleValue;
89         return ret;
90     }
91
92
93     public String JavaDoc getDefaultDisplayName() {
94         return "DoubleLiteralExpr(type: "+type+", "+"value: "+value+", "+"doubleValue: "+doubleValue+")";
95     }
96
97     //END: Generated from @child and @property
98
}
99
Popular Tags