示例#1
0
 public ALittleScriptMethodReturnDecElement GetMethodReturnDec()
 {
     if (m_flag_MethodReturnDec)
     {
         return(m_cache_MethodReturnDec);
     }
     m_flag_MethodReturnDec = true;
     foreach (var child in m_childs)
     {
         if (child is ALittleScriptMethodReturnDecElement)
         {
             m_cache_MethodReturnDec = child as ALittleScriptMethodReturnDecElement;
             break;
         }
     }
     return(m_cache_MethodReturnDec);
 }
示例#2
0
        public override ABnfGuessError CheckError()
        {
            var parent = m_element.GetParent();

            if (parent is ALittleScriptClassCtorDecElement)
            {
                return(null);
            }
            if (parent is ALittleScriptClassSetterDecElement)
            {
                return(null);
            }

            var return_list = new List <ABnfGuess>();
            ALittleScriptMethodReturnDecElement return_dec = null;
            ALittleScriptMethodNameDecElement   name_dec   = null;

            if (parent is ALittleScriptClassGetterDecElement)
            {
                var getter_dec = parent as ALittleScriptClassGetterDecElement;
                name_dec = getter_dec.GetMethodNameDec();
                if (name_dec == null)
                {
                    return(null);
                }

                var all_type = getter_dec.GetAllType();
                if (all_type == null)
                {
                    return(null);
                }
                var error = all_type.GuessType(out ABnfGuess all_type_guess);
                if (error != null)
                {
                    return(error);
                }
                return_list.Add(all_type_guess);
                return(CheckMethodBody(return_list, name_dec, m_element));
            }

            if (parent is ALittleScriptClassMethodDecElement)
            {
                var method_dec = parent as ALittleScriptClassMethodDecElement;
                name_dec = method_dec.GetMethodNameDec();
                if (name_dec == null)
                {
                    return(null);
                }
                return_dec = method_dec.GetMethodReturnDec();
            }

            if (parent is ALittleScriptClassStaticDecElement)
            {
                var static_dec = parent as ALittleScriptClassStaticDecElement;
                name_dec = static_dec.GetMethodNameDec();
                if (name_dec == null)
                {
                    return(null);
                }
                return_dec = static_dec.GetMethodReturnDec();
            }

            if (parent is ALittleScriptGlobalMethodDecElement)
            {
                var global_method_dec = parent as ALittleScriptGlobalMethodDecElement;
                name_dec = global_method_dec.GetMethodNameDec();
                if (name_dec == null)
                {
                    return(null);
                }
                return_dec = global_method_dec.GetMethodReturnDec();
            }

            if (name_dec == null)
            {
                return(null);
            }

            if (return_dec != null)
            {
                var return_one_list = return_dec.GetMethodReturnOneDecList();
                for (int i = 0; i < return_one_list.Count; ++i)
                {
                    var return_one  = return_one_list[i];
                    var all_type    = return_one.GetAllType();
                    var return_tail = return_one.GetMethodReturnTailDec();
                    if (all_type != null)
                    {
                        var error = all_type.GuessType(out ABnfGuess all_type_guess);
                        if (error != null)
                        {
                            return(error);
                        }
                        return_list.Add(all_type_guess);
                    }
                    else if (return_tail != null)
                    {
                        if (i + 1 != return_one_list.Count)
                        {
                            return(new ABnfGuessError(return_one, "返回值占位符必须定义在最后"));
                        }
                        var error = return_tail.GuessType(out ABnfGuess return_tail_guess);
                        if (error != null)
                        {
                            return(error);
                        }
                        return_list.Add(return_tail_guess);
                    }
                }
            }

            return(CheckMethodBody(return_list, name_dec, m_element));
        }