Class CallArgument


  • public class CallArgument
    extends java.lang.Object
    Describes an optionally named call argument.
    Author:
    Holger Eichelberger
    • Field Detail

      • name

        private java.lang.String name
      • fixedValue

        private java.lang.Object fixedValue
      • fixed

        private boolean fixed
    • Constructor Detail

      • CallArgument

        CallArgument()
        Constructor for serialization.
      • CallArgument

        public CallArgument​(TypeDescriptor<?> type)
        Creates a call argument for runtime operation resolution.
        Parameters:
        type - the type of the argument
      • CallArgument

        public CallArgument​(Expression expr)
        Creates an unnamed call argument.
        Parameters:
        expr - the expression specifying the value of the argument
      • CallArgument

        public CallArgument​(java.lang.String name,
                            Expression expr)
        Creates a named call argument.
        Parameters:
        name - the name of the argument (may be null if unnamed)
        expr - the expression specifying the value of the argument (may be null, e.g., for dynamic dispatch)
      • CallArgument

        public CallArgument​(java.lang.String name,
                            TypeDescriptor<?> type)
        Creates a named call argument from a given runtime type.
        Parameters:
        name - the name
        type - the specific type
    • Method Detail

      • createUnnamedArguments

        public static CallArgument[] createUnnamedArguments​(Expression... arguments)
        Creates unnamed arguments. [helper]
        Parameters:
        arguments - the argument expressions
        Returns:
        the unnamed arguments
      • countUnnamedArguments

        public static int countUnnamedArguments​(CallArgument[] arguments)
        Returns the number of unnamed arguments. Unnamed must be given before named arguments.
        Parameters:
        arguments - the arguments to be considered
        Returns:
        the number of unnamed arguments
      • getUnnamedArguments

        public static CallArgument[] getUnnamedArguments​(CallArgument[] arguments)
        Returns the arguments.
        Parameters:
        arguments - the arguments to be considered
        Returns:
        the unnamed arguments (may be arguments)
      • hasName

        public boolean hasName()
        Returns whether this argument is named.
        Returns:
        true if it is named, false else
      • getName

        public java.lang.String getName()
        Returns the name of the argument.
        Returns:
        the name of the argument, may be null}.
      • getExpression

        public Expression getExpression()
        Returns the expression specifying the value of the argument.
        Returns:
        the expression specifying the value of the argument
      • inferType

        public TypeDescriptor<?> inferType()
                                    throws VilException
        Infers the type of this expression including the type of the contained sub-expressions.
        Returns:
        the type of this expression
        Throws:
        VilException - in case that inferring the type fails
      • insertConversion

        void insertConversion​(OperationDescriptor operation)
                       throws VilException
        Replaces the expression by a transparent CallExpression executing the conversion.
        Parameters:
        operation - the conversion operation (return type, exactly 1 argument)
        Throws:
        VilException - in case that using the conversion operation is not possible for some reason
      • insertConversion

        void insertConversion​(IMetaOperation operation)
                       throws VilException
        Replaces the expression by a transparent CallExpression executing the conversion.
        Parameters:
        operation - the conversion operation (return type, exactly 1 argument)
        Throws:
        VilException - in case that using the conversion operation is not possible for some reason
      • accept

        public java.lang.Object accept​(IExpressionVisitor visitor)
                                throws VilException
        Visits the expression in this argument. [convenience]
        Parameters:
        visitor - the visitor
        Returns:
        the result of visiting this expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • fixValue

        public CallArgument fixValue​(java.lang.Object fixedValue)
        Fixes the value of this argument. Caution: There is no type check, i.e., fixedValue must match the type of this argument.
        Parameters:
        fixedValue - the fixed value
        Returns:
        this (builder pattern)
      • resolveOperation

        public void resolveOperation​(TypeDescriptor<?> type,
                                     IMetaOperation operation)
        Resolves an operation, i.e., overwrites the expression. Handle with care.
        Parameters:
        type - the resolvable type (function pointer)
        operation - the resolving operation (actual base function)
      • setExpression

        public void setExpression​(Expression expr)
        Replaces the expression in this argument. Handle with care!
        Parameters:
        expr - the new expression
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object