Beispiel #1
0
  public Type getBase(String type) {
    // TODO: what to do if the type isn't known in the current module
    while (true) {
      // Check for implicitly defined types
      if (GeneralizedTime.class.getSimpleName().equals(type)
          || UTCTime.class.getSimpleName().equals(type)) {
        return new VisibleString();
      }

      TypeAssignmentNode assignment =
          (TypeAssignmentNode) currentModule.peek().getBody().getAssignments(type);
      Type base = assignment.getType();

      if (base instanceof TypeReference) {
        type = ((TypeReference) base).getType();
      } else {
        return base;
      }
    }
  }
Beispiel #2
0
  public BigInteger resolveIntegerValue(DefinedValue ref) throws CompilerException {
    ValueOrObjectAssignmentNode<?, ?> valueAssignment = resolveDefinedValue(ref);
    Node type = valueAssignment.getType();
    Node value = valueAssignment.getValue();

    if (type instanceof IntegerType) {
      if (!(value instanceof IntegerValue)) {
        throw new CompilerException("Integer expected");
      }
      return ((IntegerValue) value).getValue();
    } else if (type instanceof TypeReference) {
      if (value instanceof IntegerValue) {
        return ((IntegerValue) value).getValue();
      } else if (value instanceof SimpleDefinedValue) {
        AssignmentNode assignment =
            getModule().getBody().getAssignments(((TypeReference) type).getType());

        if (assignment != null && assignment instanceof TypeAssignmentNode) {
          TypeAssignmentNode typeAssignment = (TypeAssignmentNode) assignment;

          if (typeAssignment.getType() instanceof IntegerType) {
            NamedNumber namedNumber =
                ((IntegerType) typeAssignment.getType())
                    .getNamedNumber(((SimpleDefinedValue) value).getValue());

            if (namedNumber.getValue() != null) {
              return namedNumber.getValue().getNumber();
            } else {
              return resolveIntegerValue(namedNumber.getRef());
            }
          }
        }
      }
    }

    throw new CompilerException("Failed to resolve an integer value");
  }