public override ABnfGuess Clone() { var guess = new ALittleScriptGuessList(sub_type, is_const, is_native); guess.UpdateValue(); return(guess); }
public override ABnfGuessError GuessTypes(out List <ABnfGuess> guess_list) { guess_list = null; var value_stat_list = m_element.GetValueStatList(); if (value_stat_list.Count == 0) { return(new ABnfGuessError(m_element, "List列表不能为空")); } var error = value_stat_list[0].GuessType(out ABnfGuess guess); if (error != null) { return(error); } var info = new ALittleScriptGuessList(guess, false, false); info.UpdateValue(); guess_list = new List <ABnfGuess>() { info }; return(null); }
public override ABnfGuess ReplaceTemplate(Dictionary <string, ABnfGuess> fill_map) { var replace = sub_type.ReplaceTemplate(fill_map); if (replace == null) { return(null); } var guess = new ALittleScriptGuessList(replace, is_const, is_native); guess.UpdateValue(); return(guess); }
public override ABnfGuessError GuessTypes(out List <ABnfGuess> guess_list) { guess_list = new List <ABnfGuess>(); // 处理List if (m_element.GetGenericListType() != null) { var dec = m_element.GetGenericListType(); var all_type = dec.GetAllType(); if (all_type == null) { return(null); } var error = all_type.GuessType(out ABnfGuess guess); if (error != null) { return(error); } var info = new ALittleScriptGuessList(guess, false, false); info.UpdateValue(); guess_list.Add(info); } // 处理Map else if (m_element.GetGenericMapType() != null) { var dec = m_element.GetGenericMapType(); var all_type_list = dec.GetAllTypeList(); if (all_type_list.Count != 2) { return(null); } var error = all_type_list[0].GuessType(out ABnfGuess key_guess); if (error != null) { return(error); } error = all_type_list[1].GuessType(out ABnfGuess value_guess); if (error != null) { return(error); } var info = new ALittleScriptGuessMap(key_guess, value_guess, false); info.UpdateValue(); guess_list.Add(info); } // 处理函数 else if (m_element.GetGenericFunctorType() != null) { var dec = m_element.GetGenericFunctorType(); if (dec != null) { var info = new ALittleScriptGuessFunctor(m_element); // 处理是不是const info.const_modifier = dec.GetAllTypeConst() != null; // 处理是不是await info.await_modifier = (dec.GetCoroutineModifier() != null && dec.GetCoroutineModifier().GetElementText() == "await"); // 处理参数 var param_type = dec.GetGenericFunctorParamType(); if (param_type != null) { var param_one_list = param_type.GetGenericFunctorParamOneTypeList(); for (int i = 0; i < param_one_list.Count; ++i) { var param_one = param_one_list[i]; var all_type = param_one.GetAllType(); if (all_type != null) { var error = all_type.GuessType(out ABnfGuess guess); if (error != null) { return(error); } info.param_list.Add(guess); info.param_nullable_list.Add(false); info.param_name_list.Add(guess.GetValue()); } else { var param_tail = param_one.GetGenericFunctorParamTail(); if (param_tail == null) { return(new ABnfGuessError(param_one, "未知类型")); } if (i + 1 != param_one_list.Count) { return(new ABnfGuessError(param_one, "参数占位符必须定义在最后")); } info.param_tail = new ALittleScriptGuessParamTail(param_tail.GetElementText()); } } } // 处理返回值 var return_type = dec.GetGenericFunctorReturnType(); if (return_type != null) { var return_one_list = return_type.GetGenericFunctorReturnOneTypeList(); for (int i = 0; i < return_one_list.Count; ++i) { var return_one = return_one_list[i]; var all_type = return_one.GetAllType(); if (all_type != null) { var error = all_type.GuessType(out ABnfGuess guess); if (error != null) { return(error); } info.return_list.Add(guess); } else { var return_tail = return_one.GetGenericFunctorReturnTail(); if (return_tail == null) { return(new ABnfGuessError(return_one, "未知类型")); } if (i + 1 != return_one_list.Count) { return(new ABnfGuessError(return_one, "返回值占位符必须定义在最后")); } info.return_tail = new ALittleScriptGuessReturnTail(return_tail.GetElementText()); } } } info.UpdateValue(); guess_list.Add(info); } } return(null); }
private ABnfGuessError ReplaceTemplate(ABnfGuess guess, out ABnfGuess result) { result = null; if (m_class_guess == null) { result = guess; return(null); } if (guess is ALittleScriptGuessTemplate && m_class_guess.template_map.Count > 0) { if (m_class_guess.template_map.TryGetValue(guess.GetValueWithoutConst(), out ABnfGuess guess_template)) { if (guess.is_const && !guess_template.is_const) { guess_template = guess_template.Clone(); guess_template.is_const = true; guess_template.UpdateValue(); } result = guess_template; } else { result = guess; } return(null); } if (guess is ALittleScriptGuessFunctor) { var guess_functor = guess as ALittleScriptGuessFunctor; var info = new ALittleScriptGuessFunctor(guess_functor.element); info.await_modifier = guess_functor.await_modifier; info.const_modifier = guess_functor.const_modifier; info.proto = guess_functor.proto; info.template_param_list.AddRange(guess_functor.template_param_list); info.param_tail = guess_functor.param_tail; info.param_name_list.AddRange(guess_functor.param_name_list); info.return_tail = guess_functor.return_tail; int start_index = 0; if (guess_functor.element is ALittleScriptClassMethodDecElement || guess_functor.element is ALittleScriptClassSetterDecElement || guess_functor.element is ALittleScriptClassGetterDecElement) { info.param_list.Add(m_class_guess); info.param_nullable_list.Add(false); if (info.param_name_list.Count > 0) { info.param_name_list[0] = m_class_guess.GetValue(); } start_index = 1; } for (int i = start_index; i < guess_functor.param_list.Count; ++i) { var error = ReplaceTemplate(guess_functor.param_list[i], out ABnfGuess guess_info); if (error != null) { return(error); } info.param_list.Add(guess_info); } for (int i = start_index; i < guess_functor.param_nullable_list.Count; ++i) { info.param_nullable_list.Add(guess_functor.param_nullable_list[i]); } for (int i = 0; i < guess_functor.return_list.Count; ++i) { var error = ReplaceTemplate(guess_functor.return_list[i], out ABnfGuess guess_info); if (error != null) { return(error); } info.return_list.Add(guess_info); } info.UpdateValue(); result = info; return(null); } if (guess is ALittleScriptGuessList) { var guess_list = guess as ALittleScriptGuessList; var error = ReplaceTemplate(guess_list.sub_type, out ABnfGuess sub_info); if (error != null) { return(error); } var info = new ALittleScriptGuessList(sub_info, guess_list.is_const, guess_list.is_native); info.UpdateValue(); result = info; return(null); } if (guess is ALittleScriptGuessMap) { var guess_map = guess as ALittleScriptGuessMap; var error = ReplaceTemplate(guess_map.key_type, out ABnfGuess key_info); if (error != null) { return(error); } error = ReplaceTemplate(guess_map.value_type, out ABnfGuess value_info); if (error != null) { return(error); } var info = new ALittleScriptGuessMap(key_info, value_info, guess.is_const); info.UpdateValue(); result = info; return(null); } if (guess is ALittleScriptGuessClass) { var guess_class = guess as ALittleScriptGuessClass; var info = new ALittleScriptGuessClass(guess_class.namespace_name, guess_class.class_name, guess_class.class_dec, guess_class.using_name, guess_class.is_const, guess_class.is_native); info.template_list.AddRange(guess_class.template_list); foreach (var pair in guess_class.template_map) { if (info.template_map.ContainsKey(pair.Key)) { info.template_map.Remove(pair.Key); } var error = ReplaceTemplate(pair.Value, out ABnfGuess replace_guess); if (error != null) { return(error); } info.template_map.Add(pair.Key, replace_guess); } var src_class_dec = guess_class.class_dec; var src_class_name_dec = src_class_dec.GetClassNameDec(); if (src_class_name_dec == null) { return(new ABnfGuessError(m_element, "类模板没有定义类名")); } info.UpdateValue(); result = info; return(null); } result = guess; return(null); }