コード例 #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);
        }
コード例 #3
0
        public override CompiledFragment Compile(CompiledMethod function)
        {
            if (Value == "null")
            {
                return(new CompiledFragment(null));
            }
            else if (Value == "base")
            {
                return(new BaseOperation(function));
            }
            else if (Value == "true" || Value == "false")
            {
                return(new CompiledFragment(Value == "true"));
            }
            else if (Value == "new")
            {
                Error("A constructor is missing its brackets.");
                return(null);
            }
            else if (IsKeyword())
            {
                return(KeyWords.Compile(this, function));
            }
            else
            {
                // It isn't a keyword (if,for..)

                bool isSet = (
                    GivenType != null ||
                    (
                        AfterVar && NextChild != null &&
                        Types.IsTypeOf(NextChild, typeof(OperatorFragment)) &&
                        ((OperatorFragment)NextChild).IsSetOperator
                    )
                    );

                Variable var = function.GetVariable(Value);

                if (isSet)
                {
                    if (var == null)
                    {
                        Type varType = null;

                        if (GivenType != null)
                        {
                            // Find it:
                            varType = GivenType.FindType(function.Script);

                            // Got it?
                            if (varType == null)
                            {
                                Error("Type '" + GivenType.Value + "' was not found.");
                            }
                        }

                        // Create the local:
                        var = function.GetVariable(Value, true, varType);
                    }
                }

                if (var != null)
                {
                    return(new CompiledFragment(var));
                }

                return(new PropertyOperation(function, Value));
            }
        }