Class FunDefBase

    • Field Detail

      • flags

        protected final int flags
      • returnCategory

        protected final int returnCategory
      • parameterCategories

        protected final int[] parameterCategories
    • Constructor Detail

      • FunDefBase

        protected FunDefBase​(String name,
                             String signature,
                             String description,
                             String flags)
        Creates an operator with an explicit signature.

        In most cases, the signature can be generated automatically, and you should use the constructor which creates an implicit signature, FunDefBase(String, String, String, String) instead.

        Parameters:
        name - Name of the function, for example "Members".
        signature - Signature of the function, for example "<Dimension>.Members".
        description - Description of the function, for example "Returns the set of all members in a dimension."
        flags - Encoding of the syntactic type, return type, and parameter types of this operator. The "Members" operator has a syntactic type "pxd" which means "an operator with property syntax (p) which returns a set (x) and takes a dimension (d) as its argument". See FunUtil.decodeSyntacticType(String), FunUtil.decodeReturnCategory(String), FunUtil.decodeParameterCategories(String).
    • Method Detail

      • getName

        public String getName()
        Description copied from interface: FunDef
        Returns the name of this function.
        Specified by:
        getName in interface FunDef
      • getDescription

        public String getDescription()
        Description copied from interface: FunDef
        Returns the description of this function.
        Specified by:
        getDescription in interface FunDef
      • getSyntax

        public Syntax getSyntax()
        Description copied from interface: FunDef
        Returns the syntactic type of the function.
        Specified by:
        getSyntax in interface FunDef
      • getReturnCategory

        public int getReturnCategory()
        Description copied from interface: FunDef
        Returns the Category code of the value returned by this function.
        Specified by:
        getReturnCategory in interface FunDef
      • getParameterCategories

        public int[] getParameterCategories()
        Description copied from interface: FunDef
        Returns the types of the arguments of this function. Values are the same as those returned by Exp.getCategory(). The 0th argument of methods and properties are the object they are applied to. Infix operators have two arguments, and prefix operators have one argument.
        Specified by:
        getParameterCategories in interface FunDef
      • createCall

        public Exp createCall​(Validator validator,
                              Exp[] args)
        Description copied from interface: FunDef
        Creates an expression which represents a call to this function with a given set of arguments. The result is usually a ResolvedFunCall but not always.
        Specified by:
        createCall in interface FunDef
      • validateArg

        protected Exp validateArg​(Validator validator,
                                  Exp[] args,
                                  int i,
                                  int category)
        Validates an argument to a call to this function.

        The default implementation of this method adds an implicit conversion to the correct type. Derived classes may override.

        Parameters:
        validator - Validator
        args - Arguments to this function
        i - Ordinal of argument
        category - Expected category of argument
        Returns:
        Validated argument
      • getResultType

        public Type getResultType​(Validator validator,
                                  Exp[] args)
        Returns the type of a call to this function with a given set of arguments.

        The default implementation makes the coarse assumption that the return type is in some way related to the type of the first argument. Operators whose arguments don't follow the requirements of this implementation should override this method.

        If the function definition says it returns a literal type (numeric, string, symbol) then it's a fair guess that the function call returns the same kind of value.

        If the function definition says it returns an object type (cube, dimension, hierarchy, level, member) then we check the first argument of the function. Suppose that the function definition says that it returns a hierarchy, and the first argument of the function happens to be a member. Then it's reasonable to assume that this function returns a member.

        Parameters:
        validator - Validator
        args - Arguments to the call to this operator
        Returns:
        result type of a call this function
      • compileCall

        public Calc compileCall​(ResolvedFunCall call,
                                ExpCompiler compiler)
        Description copied from interface: FunDef
        Converts a call to this function into executable objects.

        The result must implement the appropriate interface for the result type. For example, a function which returns an integer must return an object which implements IntegerCalc.

        Specified by:
        compileCall in interface FunDef
      • getSignature

        public String getSignature()
        Description copied from interface: FunDef
        Returns an English description of the signature of the function, for example "<Numeric Expression> / <Numeric Expression>".
        Specified by:
        getSignature in interface FunDef
      • unparse

        public void unparse​(Exp[] args,
                            PrintWriter pw)
        Description copied from interface: FunDef
        Converts a function call into MDX source code.
        Specified by:
        unparse in interface FunDef