You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
44 lines
1.5 KiB
package chocopy.common.astnodes;
|
|
|
|
import chocopy.common.analysis.types.Type;
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
import java_cup.runtime.ComplexSymbolFactory.Location;
|
|
|
|
/**
|
|
* Base of all AST nodes representing expressions.
|
|
*
|
|
* <p>There is nothing in this class, but there will be many AST node types that have fields that
|
|
* are *any expression*. For those cases, having a field of this type will encompass all types of
|
|
* expressions such as binary expressions and literals that subclass this class.
|
|
*/
|
|
public abstract class Expr extends Node {
|
|
|
|
/** A Python expression spanning source locations [LEFT..RIGHT]. */
|
|
public Expr(Location left, Location right) {
|
|
super(left, right);
|
|
}
|
|
|
|
/**
|
|
* The type of the value that this expression evaluates to.
|
|
*
|
|
* <p>This field is always <tt>null</tt> after the parsing stage, but is populated by the
|
|
* typechecker in the semantic analysis stage.
|
|
*
|
|
* <p>After typechecking this field may be <tt>null</tt> only for expressions that cannot be
|
|
* assigned a type. In particular, {@link NoneLiteral} expressions will not have a typed
|
|
* assigned to them.
|
|
*/
|
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
|
private Type inferredType;
|
|
|
|
/** Set getInferredType() to TYPE, returning TYPE. */
|
|
public Type setInferredType(Type type) {
|
|
inferredType = type;
|
|
return type;
|
|
}
|
|
|
|
public Type getInferredType() {
|
|
return inferredType;
|
|
}
|
|
}
|