Esempio n. 1
0
  public static Operation newOperation(SourceRange sourceRange, Operation... ops)
      throws SyntaxException {

    assert (ops.length == 1);

    Operation result = null;

    // Attempt to optimize this operation.
    if (ops[0] instanceof Element) {

      try {
        LongProperty a = (LongProperty) ops[0];
        result = execute(a);
      } catch (ClassCastException cce) {
        throw new EvaluationException(MessageUtils.format(MSG_INVALID_ARGS_BITNOT), sourceRange);
      } catch (EvaluationException ee) {
        throw SyntaxException.create(sourceRange, ee);
      }

    } else {
      result = new BitNot(sourceRange, ops);
    }

    return result;
  }
Esempio n. 2
0
  @Override
  public Element execute(Context context) {

    try {
      Element[] args = calculateArgs(context);
      LongProperty a = (LongProperty) args[0];
      return execute(a);
    } catch (ClassCastException cce) {
      throw new EvaluationException(MessageUtils.format(MSG_INVALID_ARGS_BITNOT), sourceRange);
    }
  }
Esempio n. 3
0
  @Override
  public Element execute(Context context) {

    // Look up the variable.
    Element result = context.getVariable(identifier);

    // Return an error if the variable doesn't exist.
    if (result == null && !lookupOnly) {
      throw new EvaluationException(
          MessageUtils.format(MSG_UNDEFINED_VAR, identifier), sourceRange, context);
    }

    return result;
  }
Esempio n. 4
0
  /**
   * Associate the given type with the given name within this ObjectContext. This will throw an
   * EvaluationException if the type is already defined.
   *
   * @param name name to associate to the type
   * @param fullType data type to use for the definition
   * @param template template where the type is defined (used for error handling)
   * @param sourceRange location in the template where the type is defined (used for error handling)
   * @throws EvaluationException if there is already a type associated with the given name
   */
  public void put(String name, FullType fullType, Template template, SourceRange sourceRange)
      throws EvaluationException {

    assert (name != null);
    assert (fullType != null);

    // Ensure that all referenced types are already defined. This must be
    // done before adding this type to the table to avoid type definition
    // loops.
    fullType.verifySubtypesDefined(this);

    // Set the type in the types hash.
    FullType previous = types.put(name, fullType);

    // Oops, the type was already defined. Create a descriptive error
    // message and abort the processing.
    if (previous != null) {
      String msg =
          MessageUtils.format(
              MSG_DUPLICATE_TYPE, name, previous.getSource(), previous.getSourceRange());
      throw new EvaluationException(msg);
    }
  }