コード例 #1
0
        public override CompiledFragment Compile(CompiledMethod method)
        {
            if (!IsParent)
            {
                return(null);
            }

            CodeFragment child = FirstChild;

            while (child != null)
            {
                CodeFragment     next  = child.NextChild;
                CompiledFragment cfrag = child.Compile(method);

                if (cfrag != null)
                {
                    cfrag.AddAfter(child);
                }

                child.Remove();
                child = next;
            }

            if (GivenType != null)
            {
                Type toType = GivenType.FindType(method.Script);

                if (toType == null)
                {
                    Error("Type not found: " + GivenType.ToString() + ".");
                }

                CompiledFragment compiledKid = (CompiledFragment)FirstChild;
                CompiledFragment result      = Types.TryCast(method, compiledKid, toType);

                if (result == null)
                {
                    Error("Cannot cast " + compiledKid.OutputType() + " to " + toType + ".");
                }

                return(result);
            }

            return((CompiledFragment)FirstChild);
        }
コード例 #2
0
        public override CompiledFragment Compile(CompiledMethod method)
        {
            if (!IsParent)
            {
                return(null);
            }

            CodeFragment child = FirstChild;

            while (child != null)
            {
                CodeFragment     next  = child.NextChild;
                CompiledFragment cfrag = child.Compile(method);

                if (cfrag != null)
                {
                    cfrag.AddAfter(child);
                }

                child.Remove();
                child = next;
            }

            // Is this a cast?
            if (GivenType != null)
            {
                // Get the type being cast to:
                Type toType = GivenType.FindType(method.Script);

                if (toType == null)
                {
                    Error("Type to cast to was not found: " + GivenType.ToString() + ".");
                }

                // Get the object being cast:
                CompiledFragment compiledKid = (CompiledFragment)FirstChild;

                // Create a cast operation with it:
                return(new CastOperation(method, compiledKid, toType));
            }

            return((CompiledFragment)FirstChild);
        }