示例#1
0
        internal virtual void StoreArguments(TemplateFrame frame, int nargs, Template st)
        {
            if (nargs > 0 && !st.impl.HasFormalArgs && st.impl.FormalArguments == null)
            {
                st.Add(Template.ImplicitArgumentName, null); // pretend we have "it" arg
            }

            int nformalArgs = 0;
            if (st.impl.FormalArguments != null)
                nformalArgs = st.impl.FormalArguments.Count;
            int firstArg = sp - (nargs - 1);
            int numToStore = Math.Min(nargs, nformalArgs);
            if (st.impl.IsAnonSubtemplate)
                nformalArgs -= predefinedAnonSubtemplateAttributes.Length;

            if (nargs < (nformalArgs - st.impl.NumberOfArgsWithDefaultValues) ||
                 nargs > nformalArgs)
            {
                _errorManager.RuntimeError(frame,
                                    ErrorType.ARGUMENT_COUNT_MISMATCH,
                                    nargs,
                                    st.impl.Name,
                                    nformalArgs);
            }

            if (st.impl.FormalArguments == null)
                return;

            for (int i = 0; i < numToStore; i++)
            {
                object o = operands[firstArg + i];
                string argName = st.impl.FormalArguments[i].Name;
                st.RawSetAttribute(argName, o);
            }
        }
示例#2
0
        internal virtual void StoreArguments(TemplateFrame frame, IDictionary<string, object> attrs, Template st)
        {
            if (attrs != null && attrs.Count > 0 &&
                 !st.impl.HasFormalArgs && st.impl.FormalArguments == null)
            {
                st.Add(Template.ImplicitArgumentName, null); // pretend we have "it" arg
            }

            int nformalArgs = 0;
            if (st.impl.FormalArguments != null)
                nformalArgs = st.impl.FormalArguments.Count;
            int nargs = 0;
            if (attrs != null)
                nargs = attrs.Count;

            if (nargs < (nformalArgs - st.impl.NumberOfArgsWithDefaultValues) || nargs > nformalArgs)
            {
                _errorManager.RuntimeError(frame,
                                    ErrorType.ARGUMENT_COUNT_MISMATCH,
                                    nargs,
                                    st.impl.Name,
                                    nformalArgs);
            }

            foreach (string argName in attrs.Keys)
            {
                // don't let it throw an exception in RawSetAttribute
                if (st.impl.FormalArguments == null || !st.impl.FormalArguments.Exists(i => i.Name == argName))
                {
                    _errorManager.RuntimeError(frame, ErrorType.NO_SUCH_ATTRIBUTE, argName);
                    continue;
                }

                object o = attrs[argName];
                st.RawSetAttribute(argName, o);
            }
        }