Package jminusminus

Class JVariable

All Implemented Interfaces:
JLhs

class JVariable extends JExpression implements JLhs
The AST node for an identifier used as a primary expression.
  • Constructor Details

    • JVariable

      public JVariable(int line, String name)
      Constructs the AST node for a variable.
      Parameters:
      line - line in which the variable occurs in the source file.
      name - the name.
  • Method Details

    • name

      public String name()
      Returns the identifier name.
      Returns:
      the identifier name.
    • iDefn

      public IDefn iDefn()
      Returns the identifier's definition.
      Returns:
      the identifier's definition.
    • analyze

      public JExpression analyze(Context context)
      Analyzes and returns a JExpression.
      Specified by:
      analyze in class JExpression
      Parameters:
      context - context in which names are resolved.
      Returns:
      the analyzed (and possibly rewritten) AST subtree.
    • analyzeLhs

      public JExpression analyzeLhs(Context context)
      Analyzes the lhs of an assignment. This is very much like the analyze() methods, but perhaps a little more selective here and there.
      Specified by:
      analyzeLhs in interface JLhs
      Parameters:
      context - context in which names are resolved.
      Returns:
      the analyzed (and possibly rewritten) AST subtree.
    • codegen

      public void codegen(CLEmitter output)
      Performs code generation for this AST.
      Specified by:
      codegen in class JAST
      Parameters:
      output - the code emitter.
    • codegen

      public void codegen(CLEmitter output, String targetLabel, boolean onTrue)
      Performs short-circuit code generation for a boolean expression, given the code emitter, a target label, and whether we branch to that label on true or on false.
      Overrides:
      codegen in class JExpression
      Parameters:
      output - the code emitter.
      targetLabel - the label to which we should branch.
      onTrue - do we branch on true?
    • codegenLoadLhsLvalue

      public void codegenLoadLhsLvalue(CLEmitter output)
      Generates code to load onto the stack any part of the lhs that must be there, as in a[i] = x.
      Specified by:
      codegenLoadLhsLvalue in interface JLhs
      Parameters:
      output - the code emitter.
    • codegenLoadLhsRvalue

      public void codegenLoadLhsRvalue(CLEmitter output)
      Generates code to load an Rvalue of the lhs, as in a += x.
      Specified by:
      codegenLoadLhsRvalue in interface JLhs
      Parameters:
      output - the code emitter.
    • codegenDuplicateRvalue

      public void codegenDuplicateRvalue(CLEmitter output)
      Generates the code to duplicate the Rvalue that is on the stack because it is to be used in a surrounding expression, as in a[i] = x--.
      Specified by:
      codegenDuplicateRvalue in interface JLhs
      Parameters:
      output - the code emitter.
    • codegenStore

      public void codegenStore(CLEmitter output)
      Generates the code to do the actual assignment.
      Specified by:
      codegenStore in interface JLhs
      Parameters:
      output - the code emitter.
    • toJSON

      public void toJSON(JSONElement json)
      Stores information about this AST in JSON format.
      Overrides:
      toJSON in class JAST
      Parameters:
      json - the JSON emitter.