KickJava   Java API By Example, From Geeks To Geeks.

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


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 intLiteral
35   * @property int intValue
36   */

37 public class IntLiteralExpr extends NumericLiteralExpr {
38
39     public long getLongValue() { return (long)intValue; }
40     public float getFloatValue() { return (float)intValue; }
41     public double getDoubleValue() { return (double)intValue; }
42     public String JavaDoc getStringValue() {
43         if (getType() instanceof CharType)
44             return "" + (char) intValue;
45         else
46             return "" + intValue;
47     }
48
49     public IntLiteralExpr(SourceLocation source, int _intValue) {
50         this(source, source.getCompiler().getTypeManager().intType, "" + _intValue, _intValue);
51     }
52
53     public IntLiteralExpr(SourceLocation source, Type type, int _intValue) {
54         this(source, type, createUsefulString(type, _intValue), _intValue);
55     }
56
57     private static String JavaDoc createUsefulString(Type type, int i) {
58         if (type instanceof IntType) return "" + i;
59         return "((" + type.getString() + ")" + i + ")";
60     }
61
62     public boolean isAssignableTo(Type type) {
63         if (type instanceof ByteType) {
64             return (Byte.MIN_VALUE <= intValue) && (intValue <= Byte.MAX_VALUE);
65         } else if (type instanceof ShortType) {
66             return (Short.MIN_VALUE <= intValue) && (intValue <= Short.MAX_VALUE);
67         } else if (type instanceof CharType) {
68             return (Character.MIN_VALUE <= intValue) && (intValue <= Character.MAX_VALUE);
69         } else if (type instanceof NumericType) {
70             return true;
71         } else {
72             return false;
73         }
74     }
75
76     // ------------------------------
77
// bcg
78
protected void cgValue(CodeBuilder cb) {
79         cb.emitIntConstant(intValue);
80     }
81     public void addConstant(FieldBuilder fb) {
82         fb.setConstantValue(intValue);
83     }
84     public boolean isConstantZero() { return intValue == 0; }
85
86     //BEGIN: Generated from @child and @property
87
protected int intValue;
88     public int getIntValue() { return intValue; }
89     public void setIntValue(int _intValue) { intValue = _intValue; }
90
91     public IntLiteralExpr(SourceLocation location, Type _type, String JavaDoc _value, int _intValue) {
92         super(location, _type, _value);
93         setIntValue(_intValue);
94     }
95     protected IntLiteralExpr(SourceLocation source) {
96         super(source);
97     }
98
99     public ASTObject copyWalk(CopyWalker walker) {
100         IntLiteralExpr ret = new IntLiteralExpr(getSourceLocation());
101         ret.preCopy(walker, this);
102         ret.type = type;
103         ret.value = value;
104         ret.intValue = intValue;
105         return ret;
106     }
107
108
109     public String JavaDoc getDefaultDisplayName() {
110         return "IntLiteralExpr(type: "+type+", "+"value: "+value+", "+"intValue: "+intValue+")";
111     }
112
113     //END: Generated from @child and @property
114
}
115
Popular Tags