parent
92e6688289
commit
79be979e13
@ -0,0 +1,56 @@
|
||||
package chocopy.common.analysis.types;
|
||||
|
||||
import chocopy.common.astnodes.ClassType;
|
||||
import chocopy.common.astnodes.Identifier;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import chocopy.common.analysis.SymbolTable;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Represents the semantic value of a simple class reference. */
|
||||
public class ClassVType extends ValueType {
|
||||
|
||||
/** The name of the class. */
|
||||
private final String className;
|
||||
public SymbolTable<Type> scope;
|
||||
public Identifier super_class;
|
||||
/** A class type for the class named CLASSNAME. */
|
||||
@JsonCreator
|
||||
public ClassVType(@JsonProperty String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
/** A class type for the class referenced by CLASSTYPEANNOTATION. */
|
||||
public ClassVType(ClassType classTypeAnnotation) {
|
||||
this.className = classTypeAnnotation.className;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonProperty
|
||||
public String className() {
|
||||
return className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ClassVType classType = (ClassVType) o;
|
||||
return Objects.equals(className, classType.className);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(className);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return className;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package chocopy.common.analysis.types;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Semantic information for a function or method. */
|
||||
public class FuncValueType extends Type {
|
||||
|
||||
/** Function's name. */
|
||||
//public final String name;
|
||||
|
||||
/** Types of parameters. */
|
||||
public List<ValueType> parameters;
|
||||
/** Function's return type. */
|
||||
public final ValueType returnType;
|
||||
|
||||
|
||||
/** Create a FuncType returning RETURNTYPE0, initially parameterless. */
|
||||
public FuncValueType(ValueType returnType0) {
|
||||
this(new ArrayList<>(), returnType0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a FuncType for NAME0 with formal parameter types PARAMETERS0, returning type
|
||||
* RETURNTYPE0.
|
||||
*/
|
||||
@JsonCreator
|
||||
public FuncValueType(List<ValueType> parameters0, ValueType returnType0) {
|
||||
this.parameters = parameters0;
|
||||
this.returnType = returnType0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFuncType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Return the type of the K-th parameter. */
|
||||
public ValueType getParamType(int k) {
|
||||
return parameters.get(k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<function>";
|
||||
}
|
||||
}
|
Loading…
Reference in new issue