class JVariable extends JExpression implements JLhs
isStatementExpression, type
compilationUnit, line
Constructor and Description |
---|
JVariable(int line,
String name)
Construct the AST node for a variable given its line number and name.
|
Modifier and Type | Method and Description |
---|---|
JExpression |
analyze(Context context)
Analyzing identifiers involves resolving them in the context.
|
JExpression |
analyzeLhs(Context context)
Analyze the identifier as used on the lhs of an assignment.
|
void |
codegen(CLEmitter output)
Generate code to load value of variable on stack.
|
void |
codegen(CLEmitter output,
String targetLabel,
boolean onTrue)
The semantics of j-- require that we implement short-circuiting branching
in implementing the identifier expression.
|
void |
codegenDuplicateRvalue(CLEmitter output)
Generate the code required for duplicating the Rvalue that is on the
stack becuase it is to be used in a surrounding expression, as in a[i] =
x =
|
void |
codegenLoadLhsLvalue(CLEmitter output)
Generate the code required for setting up an Lvalue, eg for use in an
assignment.
|
void |
codegenLoadLhsRvalue(CLEmitter output)
Generate the code required for loading an Rvalue for this variable, eg
for use in a +=.
|
void |
codegenStore(CLEmitter output)
Generate the code required for doing the actual assignment.
|
IDefn |
iDefn()
Return the identifier's definition.
|
String |
name()
Return the identifier name.
|
void |
writeToStdOut(PrettyPrinter p)
Write the information pertaining to this AST to STDOUT.
|
isStatementExpression, type
line, partialCodegen
public JVariable(int line, String name)
line
- line in which the variable occurs in the source file.name
- the name.public String name()
public IDefn iDefn()
public JExpression analyze(Context context)
analyze
in class JExpression
context
- context in which names are resolved.public JExpression analyzeLhs(Context context)
analyzeLhs
in interface JLhs
context
- context in which names are resolved.public void codegen(CLEmitter output)
public void codegen(CLEmitter output, String targetLabel, boolean onTrue)
codegen
in class JExpression
output
- the code emitter (basically an abstraction for producing the
.class file).targetLabel
- the label to which we should branch.onTrue
- do we branch on true?public void codegenLoadLhsLvalue(CLEmitter output)
codegenLoadLhsLvalue
in interface JLhs
output
- the emitter (an abstraction of the class file.public void codegenLoadLhsRvalue(CLEmitter output)
codegenLoadLhsRvalue
in interface JLhs
output
- the emitter (an abstraction of the class file).public void codegenDuplicateRvalue(CLEmitter output)
codegenDuplicateRvalue
in interface JLhs
output
- the code emitter (basically an abstraction for producing the
.class file).public void codegenStore(CLEmitter output)
codegenStore
in interface JLhs
output
- the code emitter (basically an abstraction for producing the
.class file).public void writeToStdOut(PrettyPrinter p)
JAST
writeToStdOut
in class JAST
p
- for pretty printing with indentation.