public TypeInfo typeCheck(TypeEnv tenv) throws TypeException { if (tenv.get(0, index) != null) throw new TypeException("duplicate variable: " + name(), this); varType = TypeInfo.get(type()); tenv.put(0, index, varType); valueType = ((ASTreeTypeEx) initializer()).typeCheck(tenv); valueType.assertSubtypeOf(varType, tenv, this); return varType; }
public TypeInfo typeCheck(TypeEnv tenv) throws TypeException { TypeInfo[] params = ((ParamListEx2) parameters()).types(); TypeInfo retType = TypeInfo.get(type()); funcType = TypeInfo.function(retType, params); TypeInfo oldType = tenv.put(0, index, funcType); if (oldType != null) throw new TypeException("function redefinition: " + name(), this); bodyEnv = new TypeEnv(size, tenv); for (int i = 0; i < params.length; i++) bodyEnv.put(0, i, params[i]); TypeInfo bodyType = ((ASTreeTypeEx) revise(body())).typeCheck(bodyEnv); bodyType.assertSubtypeOf(retType, tenv, this); return funcType; }
public TypeInfo[] types() throws TypeException { int s = size(); TypeInfo[] result = new TypeInfo[s]; for (int i = 0; i < s; i++) result[i] = TypeInfo.get(typeTag(i)); return result; }