示例#1
0
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);
            parser.IncrementScopeLevel(true);

            foreach (FunctionParameter param in Parameters)
            {
                if (param.HasDefaultValue)
                {
                    if (param.ParamType == ScriptVariableType.String)
                    {
                        if (!param.DefaultValue.ConvertToVariable(ScriptVariableType.String, out param.CompiledDefaultValue))
                        {
                            parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.BadDefaultForStringParameter, param.DefaultValue));
                        }
                    }
                    else if (param.ParamType == ScriptVariableType.Char)
                    {
                        if (!param.DefaultValue.ConvertToVariable(ScriptVariableType.Char, out param.CompiledDefaultValue))
                        {
                            parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.BadDefaultForCharParameter, param.DefaultValue));
                        }
                    }
                    else if (param.ParamType == ScriptVariableType.Bool)
                    {
                        if (!param.DefaultValue.ConvertToVariable(ScriptVariableType.Bool, out param.CompiledDefaultValue))
                        {
                            parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.BadDefaultForBooleanParameter, param.DefaultValue));
                        }
                    }
                    else
                    {
                        if (!param.DefaultValue.ConvertToVariable(param.ParamType, out param.CompiledDefaultValue))
                        {
                            parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.BadDefaultForNumericParameter, param.DefaultValue));
                        }
                    }
                }

                parser.AddVariable(new ScriptVariableDefinition(param.ParamType, param.Name));
            }

            parser.RequiredReturnType = ReturnType;
            Body.Process(parser, 0);
            parser.RequiredReturnType = ScriptVariableType.Undefined;

            parser.DecrementScopeLevel(true);

            return(ScriptVariableType.Undefined);
        }
 public override ScriptVariableType Process(ScriptParser parser, int level)
 {
     base.Process(parser, level);
     parser.IncrementScopeLevel(false);
     if (Init != null)
     {
         Init.Process(parser, level + 1);
     }
     if (Condition != null)
     {
         Condition = TypeCastExecutionNode.ImplicitCast(parser, level + 1, ScriptVariableType.Bool, Condition);
     }
     if (Final != null)
     {
         Final.Process(parser, level + 1);
     }
     if (Code != null)
     {
         Code.Process(parser, level + 1);
     }
     parser.DecrementScopeLevel(false);
     return(ScriptVariableType.Undefined);
 }
示例#3
0
        public override ScriptVariableType Process(ScriptParser parser, int level)
        {
            base.Process(parser, level);

            IExecutionTreeNode node = null;

            if (m_Parent != null && CreateOwnVariableScope)
            {
                parser.IncrementScopeLevel(false);
            }

            int  i, processCount = 0;
            bool exitFound = false;

            for (i = 0; i < m_Children.Count; i++)
            {
                node      = m_Children[i];
                exitFound = (node is ReturnExecutionNode || node is ExitExecutionNode);
                if (exitFound && i < m_Children.Count - 1)
                {
                    parser.Errors.Add(new ErrorInfo(ErrorLevel.Warning, ErrorCode.UnreachableCode, m_Children[i + 1]));
                    break;
                }
                processCount++;
            }
            if (level == 0 && !exitFound)
            {
                if (m_Parent != null && parser.RequiredReturnType != ScriptVariableType.Undefined && parser.RequiredReturnType != ScriptVariableType.Void)
                {
                    parser.Errors.Add(new ErrorInfo(ErrorLevel.Error, ErrorCode.NotAllCodePathsReturnAValue, this));
                    // return;
                }
                if (m_Parent == null && node != null && node.HasResult)
                {
                    // Not within a function, but at the very end of the script.
                    // Make result of the last statement to be returned as an
                    // exit data of the script. This is needed to simplify
                    // scripts that work as conditions of some scripted objects
                    // like dialogues or quests.
                    ExitExecutionNode exitNode = new ExitExecutionNode(this, node.Line, node.Character);
                    exitNode.ExitValue = node;
                    node.Parent        = exitNode;
                    m_Children[m_Children.Count - 1] = exitNode;
                }
            }

            // processing has to be done AFTER virtual exit node is incorporated
            for (i = 0; i < processCount; i++)
            {
                node = m_Children[i];

                try { node.Process(parser, level + 1); }
                catch (ScriptCriticalErrorException) {}

                if ((node is ReturnExecutionNode || node is ExitExecutionNode) && i < m_Children.Count - 1)
                {
                    break;
                }
            }

            // Don't decrement scope level for root node to keep global
            // variables in the variable stack. This is required for functions
            // to know what global variables they will have access to while
            // parsing.
            if (m_Parent != null && CreateOwnVariableScope)
            {
                parser.DecrementScopeLevel(false);
            }

            return(ScriptVariableType.Undefined);
        }