com.svincent.smalljava
Class Expr

java.lang.Object
  |
  +--com.svincent.util.BaseObject
        |
        +--com.svincent.smalljava.Expr
Direct Known Subclasses:
Expr.Begin, com.svincent.smalljava.Expr.BinaryExpr, Expr.BooleanConst, Expr.Call, Expr.Comment, Expr.DoubleConst, Expr.GetField, Expr.GetLocal, Expr.GetStatic, Expr.If, Expr.IntConst, Expr.New, Expr.NewArray, Expr.NullConst, Expr.Return, Expr.SetArray, Expr.SetField, Expr.SetLocal, Expr.StringConst, Expr.SuperConstructor, Expr.This, Expr.While

public abstract class Expr
extends BaseObject

Expr represents an executable expression. Most of the expression types you've come to know and love are here: ifs, whiles, arithmetic, field manipulation, etc. They're all right here, in Texas.

Author:
Shawn Vincent

Inner Class Summary
static class Expr.Begin
          Execute a series of expressions, one after another.
static class Expr.BooleanConst
          Return the given boolean constant.
static class Expr.Call
          Call a method.
static class Expr.Comment
          A comment.
static class Expr.DoubleConst
          Return the given double constant.
static class Expr.EQ
          The normal == binary operator.
static class Expr.GE
          The normal >= binary operator.
static class Expr.GetField
          Get the value from an instance field
static class Expr.GetLocal
          Get the value from a local variable
static class Expr.GetStatic
          Get the value from a static field
static class Expr.GT
          The normal > binary operator.
static class Expr.If
          If condition evaluates to true, evaluate the then clase.
static class Expr.IntConst
          Return the given integer constant.
static class Expr.LE
          The normal <= binary operator.
static class Expr.LT
          The normal < binary operator.
static class Expr.Minus
          The normal - binary operator.
static class Expr.NE
          The normal != binary operator.
static class Expr.New
          Construct a new instance of the named class.
static class Expr.NewArray
          Construct a new array instance for containing the given type (Only makes single-dimensional arrays, for now) Also ignores types of initializer things.
static class Expr.NullConst
          Return the null constant..
static class Expr.Plus
          The normal + binary operator.
static class Expr.Return
          Return a value from a method.
static class Expr.SetArray
          Assign a value to an array slot
static class Expr.SetField
          Assign a value to an instance field
static class Expr.SetLocal
          Assign a value to a local variable
static class Expr.StringConst
          Return the given String constant.
static class Expr.SuperConstructor
          call the null-arg super constructor..
static class Expr.This
          Access the magic variable 'this'.
static class Expr.While
          Loop around, executing instructions until the given condition evaluates to 'true'.
 
Field Summary
static boolean debugTypecheck
          Set to true to debug typecheck algorithms
static Expr[] EmptyArray
          A convenient empty Expression array.
 
Constructor Summary
Expr()
           
 
Method Summary
protected abstract  SmallType deriveType(SmallMethod m)
          Actually do the work.
protected  SmallType evalType(SmallMethod m)
          Not to be called by users.
protected abstract  void generateInstructions(ClassFileWriter out, VariableTable vars)
          Generate a list of JVM instructions for this expression node.
 SmallType getResultType()
          Get the type of the result of this expression.
protected  boolean printTrailingSemi()
          Returns true if, after printing this expression as a statement, there should be a trailing semicolon printed.
 java.lang.String tag()
           
abstract  void writeAsJava(IndentPrintWriter out)
          Write this expression out as Java source code.
 
Methods inherited from class com.svincent.util.BaseObject
dump, dump, dumpToString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugTypecheck

public static final boolean debugTypecheck
Set to true to debug typecheck algorithms

EmptyArray

public static final Expr[] EmptyArray
A convenient empty Expression array.
Constructor Detail

Expr

public Expr()
Method Detail

evalType

protected SmallType evalType(SmallMethod m)
                      throws SmallJavaValidationException
Not to be called by users. Evaluates the type of this expression, and caches the value, so that 'getResultType' can work.
See Also:
getResultType()

deriveType

protected abstract SmallType deriveType(SmallMethod m)
                                 throws SmallJavaValidationException
Actually do the work. deriveType should call 'evalType' for recursion, and super.deriveType to repeat parent work. These simple rules for you and me will result in a happy world where the type returned is always cached appropriately.
See Also:
evalType(SmallMethod), getResultType()

getResultType

public SmallType getResultType()
Get the type of the result of this expression. Can only be called after the declaring class has been finalized.

tag

public java.lang.String tag()
Overrides:
tag in class BaseObject

writeAsJava

public abstract void writeAsJava(IndentPrintWriter out)
Write this expression out as Java source code.

generateInstructions

protected abstract void generateInstructions(ClassFileWriter out,
                                             VariableTable vars)
Generate a list of JVM instructions for this expression node.

printTrailingSemi

protected boolean printTrailingSemi()
Returns true if, after printing this expression as a statement, there should be a trailing semicolon printed. Notable exceptions are {...} constructs, and ifs and whiles.



This is documentation for Moksa Prolog, which can be found at http://www.svincent.com/moksa/

Copyright © 1999 Shawn P. Vincent.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.