public override ABnfGuess Clone() { var guess = new ALittleScriptGuessStructName(namespace_name, struct_name, struct_name_dec); guess.UpdateValue(); return(guess); }
public override ABnfGuessError GuessTypes(out List <ABnfGuess> guess_list) { guess_list = new List <ABnfGuess>(); // 标记是否已经包含了命名域,命名域的guess不要重复 bool has_namespace = false; var result_list = CalcResolve(); foreach (var result in result_list) { ABnfGuess guess = null; if (result is ALittleScriptNamespaceNameDecElement) { if (!has_namespace) { var error = result.GuessType(out ABnfGuess result_guess); if (error != null) { return(error); } has_namespace = true; var guess_namespace_name = new ALittleScriptGuessNamespaceName( result_guess.GetValue(), (ALittleScriptNamespaceNameDecElement)result ); guess_namespace_name.UpdateValue(); guess = guess_namespace_name; } } else if (result is ALittleScriptClassNameDecElement) { var error = result.GuessType(out ABnfGuess class_guess); if (error != null) { return(error); } if (!(class_guess is ALittleScriptGuessClass)) { return(new ABnfGuessError(m_element, "ALittleClassNameDec.guessType()的结果不是ALittleScriptGuessClass")); } var class_guess_class = class_guess as ALittleScriptGuessClass; if (class_guess_class.template_list.Count > 0) { return(new ABnfGuessError(m_element, "模板类" + class_guess_class.GetValue() + "不能直接使用")); } var guess_class_name = new ALittleScriptGuessClassName(class_guess_class.namespace_name, class_guess_class.class_name, result as ALittleScriptClassNameDecElement); guess_class_name.UpdateValue(); guess = guess_class_name; } else if (result is ALittleScriptStructNameDecElement) { var error = result.GuessType(out ABnfGuess struct_guess); if (error != null) { return(error); } if (!(struct_guess is ALittleScriptGuessStruct)) { return(new ABnfGuessError(m_element, "ALittleStructNameDec.guessType()的结果不是ALittleScriptGuessStruct")); } var struct_guess_struct = struct_guess as ALittleScriptGuessStruct; var guess_struct_name = new ALittleScriptGuessStructName(struct_guess_struct.namespace_name, struct_guess_struct.struct_name, result as ALittleScriptStructNameDecElement); guess_struct_name.UpdateValue(); guess = guess_struct_name; } else if (result is ALittleScriptEnumNameDecElement) { var error = result.GuessType(out ABnfGuess enum_guess); if (error != null) { return(error); } if (!(enum_guess is ALittleScriptGuessEnum)) { return(new ABnfGuessError(m_element, "ALittleEnumNameDec.guessType()的结果不是ALittleScriptGuessEnum")); } var enum_guess_enum = enum_guess as ALittleScriptGuessEnum; var guess_enum_name = new ALittleScriptGuessEnumName(enum_guess_enum.namespace_name, enum_guess_enum.enum_name, result as ALittleScriptEnumNameDecElement); guess_enum_name.UpdateValue(); guess = guess_enum_name; } else if (result is ALittleScriptMethodParamNameDecElement) { var error = result.GuessType(out guess); if (error != null) { return(error); } } else if (result is ALittleScriptVarAssignNameDecElement) { var error = result.GuessType(out guess); if (error != null) { return(error); } } else if (result is ALittleScriptMethodNameDecElement) { var error = result.GuessType(out guess); if (error != null) { return(error); } } else if (result is ALittleScriptUsingNameDecElement) { var error = result.GuessType(out guess); if (error != null) { return(error); } } if (guess != null) { guess_list.Add(guess); } } return(null); }
public override ABnfGuessError GuessTypes(out List <ABnfGuess> guess_list) { guess_list = new List <ABnfGuess>(); m_getter_list = null; m_setter_list = null; m_class_guess = null; var error = CalcResolve(out List <ABnfElement> result_list, out ABnfGuess pre_type); if (error != null) { return(error); } foreach (var result in result_list) { ABnfGuess guess = null; if (result is ALittleScriptClassVarDecElement) { error = result.GuessType(out guess); if (error != null) { return(error); } if (m_class_guess != null && guess is ALittleScriptGuessTemplate) { if (!m_class_guess.template_map.TryGetValue(guess.GetValueWithoutConst(), out ABnfGuess guess_template)) { for (int i = 0; i < m_class_guess.template_list.Count; ++i) { guess_template = m_class_guess.template_list[i]; if (guess_template.GetValueWithoutConst() == guess.GetValueWithoutConst()) { break; } } } if (guess_template != null) { if (guess.is_const && !guess_template.is_const) { guess_template = guess_template.Clone(); guess_template.is_const = true; guess_template.UpdateValue(); } guess = guess_template; } } } else if (result is ALittleScriptStructVarDecElement) { error = result.GuessType(out guess); if (error != null) { return(error); } } else if (result is ALittleScriptEnumVarDecElement) { error = result.GuessType(out guess); if (error != null) { return(error); } } else if (result is ALittleScriptMethodNameDecElement) { error = result.GuessType(out guess); if (error != null) { return(error); } // 如果前一个数据是const,那么调用的函数也必须是const if (pre_type != null && pre_type.is_const) { var guess_functor = guess as ALittleScriptGuessFunctor; if (guess_functor != null && !guess_functor.const_modifier) { return(new ABnfGuessError(m_element, "请使用带Const修饰的函数")); } } if (result.GetParent() is ALittleScriptClassGetterDecElement) { if (m_getter_list != null && m_getter_list.IndexOf(result) >= 0 && guess is ALittleScriptGuessFunctor) { guess = ((ALittleScriptGuessFunctor)guess).return_list[0]; } } else if (result.GetParent() is ALittleScriptClassSetterDecElement) { if (m_setter_list != null && m_setter_list.IndexOf(result) >= 0 && guess is ALittleScriptGuessFunctor) { guess = ((ALittleScriptGuessFunctor)guess).param_list[1]; } } error = ReplaceTemplate(guess, out guess); if (error != null) { return(error); } } else if (result is ALittleScriptVarAssignNameDecElement) { error = result.GuessType(out guess); if (error != null) { return(error); } } else if (result is ALittleScriptEnumNameDecElement) { error = result.GuessType(out ABnfGuess enum_guess); if (error != null) { return(error); } if (!(enum_guess is ALittleScriptGuessEnum)) { return(new ABnfGuessError(m_element, "ALittleEnumNameDec.guessType的结果不是ALittleGuessEnum")); } var enum_guess_enum = enum_guess as ALittleScriptGuessEnum; var info = new ALittleScriptGuessEnumName(enum_guess_enum.namespace_name, enum_guess_enum.enum_name, result as ALittleScriptEnumNameDecElement); info.UpdateValue(); guess = info; } else if (result is ALittleScriptStructNameDecElement) { error = result.GuessType(out ABnfGuess struct_guess); if (error != null) { return(error); } if (!(struct_guess is ALittleScriptGuessStruct)) { return(new ABnfGuessError(m_element, "ALittleStructNameDec.guessType的结果不是ALittleGuessStruct")); } var struct_guess_struct = struct_guess as ALittleScriptGuessStruct; var info = new ALittleScriptGuessStructName(struct_guess_struct.namespace_name, struct_guess_struct.struct_name, result as ALittleScriptStructNameDecElement); info.UpdateValue(); guess = info; } else if (result is ALittleScriptClassNameDecElement) { error = result.GuessType(out ABnfGuess class_guess); if (error != null) { return(error); } if (!(class_guess is ALittleScriptGuessClass)) { return(new ABnfGuessError(m_element, "ALittleClassNameDec.guessType的结果不是ALittleGuessClass")); } var class_guess_class = class_guess as ALittleScriptGuessClass; if (class_guess_class.template_list.Count > 0) { return(new ABnfGuessError(m_element, "模板类" + class_guess_class.GetValue() + "不能直接使用")); } var info = new ALittleScriptGuessClassName(class_guess_class.namespace_name, class_guess_class.class_name, result as ALittleScriptClassNameDecElement); info.UpdateValue(); guess = info; } if (guess != null) { if (pre_type != null && pre_type.is_const && !guess.is_const) { if (guess is ALittleScriptGuessPrimitive) { var guess_value = guess.GetValue(); ALittleScriptIndex.inst.sPrimitiveGuessMap.TryGetValue("const " + guess.GetValue(), out guess); if (guess == null) { return(new ABnfGuessError(m_element, "找不到const " + guess_value)); } } else { guess = guess.Clone(); guess.is_const = true; guess.UpdateValue(); } } guess_list.Add(guess); } } m_getter_list = null; m_setter_list = null; m_class_guess = null; return(null); }