public void Add(int functionIndex, String functionName, int minParams, int maxParams,
                byte returnClassCode, byte[] parameterClassCodes, bool hasFootnote)
        {
            FunctionMetadata fm = new FunctionMetadata(functionIndex, functionName, minParams, maxParams,
                    returnClassCode, parameterClassCodes);

            int indexKey = functionIndex;


            if (functionIndex > _maxFunctionIndex)
            {
                _maxFunctionIndex = functionIndex;
            }
            // allow function definitions to Change only if both previous and the new items have footnotes
            FunctionMetadata prevFM;
            prevFM = (FunctionMetadata)_functionDataByName[functionName];
            if (prevFM != null)
            {
                if (!hasFootnote || !_mutatingFunctionIndexes.Contains(indexKey))
                {
                    throw new Exception("Multiple entries for function name '" + functionName + "'");
                }
                _functionDataByIndex.Remove(prevFM.Index);
            }
            prevFM = (FunctionMetadata)_functionDataByIndex[indexKey];
            if (prevFM != null)
            {
                if (!hasFootnote || !_mutatingFunctionIndexes.Contains(indexKey))
                {
                    throw new Exception("Multiple entries for function index (" + functionIndex + ")");
                }
                _functionDataByName.Remove(prevFM.Name);
            }
            if (hasFootnote)
            {
                _mutatingFunctionIndexes.Add(indexKey);
            }
            _functionDataByIndex[indexKey]=fm;
            _functionDataByName[functionName]=fm;
        }
        public FunctionMetadataRegistry Build()
        {

            FunctionMetadata[] jumbledArray = new FunctionMetadata[_functionDataByName.Count];
            IEnumerator values = _functionDataByName.Values.GetEnumerator();
            FunctionMetadata[] fdIndexArray = new FunctionMetadata[_maxFunctionIndex + 1];
            while (values.MoveNext())
            {
                FunctionMetadata fd = (FunctionMetadata)values.Current;
                fdIndexArray[fd.Index] = fd;
            }

            return new FunctionMetadataRegistry(fdIndexArray, _functionDataByName);
        }
Ejemplo n.º 3
0
 private void ValidateNumArgs(int numArgs, FunctionMetadata fm)
 {
     if (numArgs < fm.MinParams)
     {
         String msg = "Too few arguments To function '" + fm.Name + "'. ";
         if (fm.HasFixedArgsLength)
         {
             msg += "Expected " + fm.MinParams;
         }
         else
         {
             msg += "At least " + fm.MinParams + " were expected";
         }
         msg += " but got " + numArgs + ".";
         throw new FormulaParseException(msg);
     }
     if (numArgs > fm.MaxParams)
     {
         String msg = "Too many arguments To function '" + fm.Name + "'. ";
         if (fm.HasFixedArgsLength)
         {
             msg += "Expected " + fm.MaxParams;
         }
         else
         {
             msg += "At most " + fm.MaxParams + " were expected";
         }
         msg += " but got " + numArgs + ".";
         throw new FormulaParseException(msg);
     }
 }
 /* package */
 public FunctionMetadataRegistry(FunctionMetadata[] functionDataByIndex, Hashtable functionDataByName)
 {
     _functionDataByIndex = functionDataByIndex;
     _functionDataByName = functionDataByName;
 }