Package jminusminus

Class LocalContext

java.lang.Object
jminusminus.Context
jminusminus.LocalContext
Direct Known Subclasses:
MethodContext

class LocalContext extends Context
A local context is a context (scope) in which local variables (including formal parameters) can be declared. Local variables are allocated at fixed offsets from the base of the current method's stack frame; this is done during analysis. The definitions for local variables record these offsets. The offsets are used in code generation.
  • Field Details

    • offset

      protected int offset
      Next offset for a local variable.
  • Constructor Details

    • LocalContext

      public LocalContext(Context surrounding)
      Constructs a local context. A local context is constructed for each block.
      Parameters:
      surrounding - the surrounding context.
  • Method Details

    • offset

      public int offset()
      Returns the "next" offset. Not to be used for allocating new offsets (the nextOffset() method is used for that).
      Returns:
      the next available offset.
    • nextOffset

      public int nextOffset()
      Allocates and returns a new offset (eg, for a parameter or local variable).
      Returns:
      the next allocated offset.
    • toJSON

      public void toJSON(JSONElement json)
      Adds information pertaining to this context to the given JSON element.
      Overrides:
      toJSON in class Context
      Parameters:
      json - JSON element.