Пример #1
0
  private Object checkFormalsToArgs(Call call, SemanticSymbol methodSymbol) {
    MethodType methType = (MethodType) methodSymbol.getType();
    Type[] params = methType.getParamTypes();
    List<Expression> args = call.getArguments();
    int paramsLength = 0;
    if (params != null) {
      paramsLength = params.length;
    }

    if (args.size() != paramsLength) {
      System.out.println(
          "semantic error at line "
              + call.getLine()
              + ": not the correct amount of parameters in call '"
              + call.getName()
              + "'.");
      System.exit(-1);
    }
    for (int i = 0; i < paramsLength; i++) {
      if (!isSubTypeOf(args.get(i), params[i])) {
        System.out.println(
            "semantic error at line "
                + call.getLine()
                + ": parameter number "
                + (i + 1)
                + " is not of the correct type.");
        System.exit(-1);
      }
    }
    call.setSemanticType(methType.getReturnType());
    return null;
  }
Пример #2
0
 private Object handleCall(Call call) throws SemanticError {
   for (Expression arg : call.getArguments()) {
     arg.accept(this);
   }
   return null;
 }