KickJava   Java API By Example, From Geeks To Geeks.

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


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.FlowCheckerPass;
28 import org.aspectj.compiler.base.JavaCompiler;
29 import org.aspectj.compiler.base.CodeWriter;
30 import java.io.IOException JavaDoc;
31
32 import org.aspectj.compiler.base.bcg.FieldBuilder;
33 import org.aspectj.compiler.base.bcg.CodeBuilder;
34 import org.aspectj.compiler.base.bcg.Label;
35
36 /**
37   * @grammar literal
38   * @property Type type
39   * @property String value
40   */

41 public abstract class LiteralExpr extends Expr {
42
43
44     /** Return a string representing the Literal expr, NOT to be used
45         for unparsing purposes, but rather the string that would be
46         returned by the {@link String#valueOf} method.
47     */

48     abstract public String JavaDoc getStringValue();
49
50     // XXX these should all be exceptions!
51
public int getIntValue() { return 0; }
52     public long getLongValue() { return 0L; }
53     public float getFloatValue() { return 0.0f; }
54     public double getDoubleValue() { return 0.0; }
55     public boolean getBooleanValue() { return false; }
56
57     public Type discoverType() {
58         return type;
59     }
60
61     public Expr makeReference() { return this; }
62
63     public boolean canBeCopied() {
64         return true;
65     }
66     
67     public boolean isUltimatelyLiteral() {
68         return true;
69     }
70
71     public void unparse(CodeWriter writer) throws IOException JavaDoc {
72         writer.write(value);
73     }
74
75     // ------------------------------
76
// bcg
77
/** Leaves the value of this expression on the stack and casts the
78         value to castTo. We do a better job than for regular
79         expressions since literal expressions can be statically cast. */

80     protected void cgValue(CodeBuilder cb, Type castTo) {
81         castTo.foldCast(this).cgValue(cb);
82     }
83
84     protected void cgEffect(CodeBuilder cb) { }
85
86     abstract public void addConstant(FieldBuilder fb);
87
88     //BEGIN: Generated from @child and @property
89
protected Type type;
90     public Type getType() { return type; }
91     public void setType(Type _type) { type = _type; }
92
93     protected String JavaDoc value;
94     public String JavaDoc getValue() { return value; }
95     public void setValue(String JavaDoc _value) { value = _value; }
96
97     public LiteralExpr(SourceLocation location, Type _type, String JavaDoc _value) {
98         super(location);
99         setType(_type);
100         setValue(_value);
101     }
102     protected LiteralExpr(SourceLocation source) {
103         super(source);
104     }
105
106
107     public String JavaDoc getDefaultDisplayName() {
108         return "LiteralExpr(type: "+type+", "+"value: "+value+")";
109     }
110
111     //END: Generated from @child and @property
112
}
113
Popular Tags