Exemplo n.º 1
0
        /*
         * CODE FOR ALTERNATE IMPL : please ignore.  I will remove when comfortable with current.
         */

        /// <summary>  not used in current impl
        /// *
        /// Constructor for alternate impl where VelProxy class would make new
        /// VMProxyArg objects, and use this constructor to avoid re-parsing the
        /// reference args
        /// *
        /// that impl also had the VMProxyArg carry it's context
        /// </summary>
        public VMProxyArg(VMProxyArg model, IInternalContextAdapter c)
        {
            userContext      = c;
            contextReference = model.ContextReference;
            callerReference  = model.CallerReference;
            nodeTree         = model.NodeTree;
            staticObject     = model.StaticObject;
            type             = model.Type;

            if (nodeTree != null)
            {
                numTreeChildren = nodeTree.ChildrenCount;
            }

            if (type == ParserTreeConstants.REFERENCE)
            {
                if (numTreeChildren == 0)
                {
                    /*
                     *  use the reference node to do this...
                     */
                    singleLevelRef = ((ASTReference)nodeTree).RootString;
                }
            }
        }
 private void setupProxyArgs(String[] callArgs, int[] callArgTypes)
 {
     // for each of the args, make a ProxyArg
     for (int i = 1; i < argArray.Length; i++)
     {
         VMProxyArg arg = new VMProxyArg(runtimeServices, argArray[i], callArgs[i - 1], callArgTypes[i - 1]);
         proxyArgHash[argArray[i]] = arg;
     }
 }
        /// <summary>
        /// Renders the macro using the context
        /// </summary>
        public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
        {
            try
            {
                // it's possible the tree hasn't been parsed yet, so get
                // the VMManager to parse and init it
                if (nodeTree == null)
                {
                    runtimeServices.Error(string.Format("VM error : {0}. Null AST", macroName));
                }
                else
                {
                    if (!init)
                    {
                        nodeTree.Init(context, runtimeServices);
                        init = true;
                    }

                    // wrap the current context and add the VMProxyArg objects
                    VMContext vmContext = new VMContext(context, runtimeServices);

                    for (int i = 1; i < argArray.Length; i++)
                    {
                        // we can do this as VMProxyArgs don't change state. They change
                        // the context.
                        VMProxyArg arg = (VMProxyArg)proxyArgHash[argArray[i]];
                        vmContext.AddVMProxyArg(arg);
                    }

                    // now render the VM
                    nodeTree.Render(vmContext, writer);
                }
            }
            catch (Exception e)
            {
                // if it's a MIE, it came from the render.... throw it...
                if (e is MethodInvocationException)
                {
                    throw;
                }

                runtimeServices.Error(string.Format("VelocimacroProxy.render() : exception VM = #{0}() : {1}", macroName, e));
            }

            return(true);
        }