Beispiel #1
0
 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;
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 public TypeInfo typeCheckForAssign(TypeEnv tenv, TypeInfo valueType) throws TypeException {
   type = tenv.get(nest, index);
   if (type == null) {
     type = valueType;
     tenv.put(0, index, valueType);
     return valueType;
   } else {
     valueType.assertSubtypeOf(type, tenv, this);
     return type;
   }
 }