예제 #1
0
  void generate() {
    try {
      rtnType = Definition.getType(rtnTypeStr);
    } catch (IllegalArgumentException exception) {
      throw createError(
          new IllegalArgumentException(
              "Illegal return type [" + rtnTypeStr + "] for function [" + name + "]."));
    }

    if (paramTypeStrs.size() != paramNameStrs.size()) {
      throw createError(new IllegalStateException("Illegal tree structure."));
    }

    Class<?>[] paramClasses = new Class<?>[this.paramTypeStrs.size()];
    List<Type> paramTypes = new ArrayList<>();

    for (int param = 0; param < this.paramTypeStrs.size(); ++param) {
      try {
        Type paramType = Definition.getType(this.paramTypeStrs.get(param));

        paramClasses[param] = paramType.clazz;
        paramTypes.add(paramType);
        parameters.add(new Parameter(location, paramNameStrs.get(param), paramType));
      } catch (IllegalArgumentException exception) {
        throw createError(
            new IllegalArgumentException(
                "Illegal parameter type ["
                    + this.paramTypeStrs.get(param)
                    + "] for function ["
                    + name
                    + "]."));
      }
    }

    org.objectweb.asm.commons.Method method =
        new org.objectweb.asm.commons.Method(
            name, MethodType.methodType(rtnType.clazz, paramClasses).toMethodDescriptorString());
    this.method =
        new Method(
            name,
            null,
            false,
            rtnType,
            paramTypes,
            method,
            Modifier.STATIC | Modifier.PRIVATE,
            null);
  }
 private boolean TYPE_sempred(RuleContext _localctx, int predIndex) {
   switch (predIndex) {
     case 2:
       return Definition.isSimpleType(getText());
   }
   return true;
 }
 @Override
 void analyze(Locals variables) {
   captured = variables.getVariable(location, variable);
   if (expected == null) {
     if (captured.type.sort == Definition.Sort.DEF) {
       // dynamic implementation
       defPointer = "D" + variable + "." + call + ",1";
     } else {
       // typed implementation
       defPointer = "S" + captured.type.name + "." + call + ",1";
     }
     actual = Definition.getType("String");
   } else {
     defPointer = null;
     // static case
     if (captured.type.sort != Definition.Sort.DEF) {
       try {
         ref = new FunctionRef(expected, captured.type.name, call, 1);
       } catch (IllegalArgumentException e) {
         throw createError(e);
       }
     }
     actual = expected;
   }
 }
예제 #4
0
  @Override
  ALink analyze(Variables variables) {
    if (before == null) {
      throw new IllegalArgumentException(error("Illegal array access made without target."));
    }

    final Sort sort = before.sort;

    if (sort == Sort.ARRAY) {
      index.expected = Definition.INT_TYPE;
      index.analyze(variables);
      index = index.cast(variables);

      after = Definition.getType(before.struct, before.dimensions - 1);

      return this;
    } else if (sort == Sort.DEF) {
      return new LDefArray(line, offset, location, index).copy(this).analyze(variables);
    } else if (Map.class.isAssignableFrom(before.clazz)) {
      return new LMapShortcut(line, offset, location, index).copy(this).analyze(variables);
    } else if (List.class.isAssignableFrom(before.clazz)) {
      return new LListShortcut(line, offset, location, index).copy(this).analyze(variables);
    }

    throw new IllegalArgumentException(
        error("Illegal array access on type [" + before.name + "]."));
  }