// 移除命名域 public void RemoveRoot(ALittleScriptRootElement root) { // 清除标记 m_guess_type_map.Remove(root.GetFile()); m_guess_error_map.Remove(root.GetFile()); m_class_data_map.Remove(root.GetFile()); m_struct_data_map.Remove(root.GetFile()); m_enum_data_map.Remove(root.GetFile()); var namespace_dec = root.GetNamespaceDec(); if (namespace_dec == null) { return; } var namespace_name_dec = namespace_dec.GetNamespaceNameDec(); if (namespace_name_dec == null) { return; } var name = namespace_name_dec.GetElementText(); if (!m_all_data_map.TryGetValue(name, out Dictionary <ALittleScriptNamespaceNameDecElement, ALittleScriptAccessData> all_data_map)) { return; } if (!all_data_map.TryGetValue(namespace_name_dec, out ALittleScriptAccessData all_access_data)) { return; } if (all_data_map.ContainsKey(namespace_name_dec)) { all_data_map.Remove(namespace_name_dec); } if (all_data_map.Count == 0) { m_all_data_map.Remove(name); } m_global_access_map.TryGetValue(name, out ALittleScriptAccessData global_access_data); m_namespace_access_map.TryGetValue(name, out ALittleScriptAccessData namespace_access_data); m_file_access_map.TryGetValue(root.GetFile(), out ALittleScriptAccessData file_access_data); foreach (var pair in all_access_data.GetElementMap()) { foreach (var element_pair in pair.Value) { foreach (var name_dec in element_pair.Value) { if (global_access_data != null) { global_access_data.RemoveNameDec(name_dec); } if (namespace_access_data != null) { namespace_access_data.RemoveNameDec(name_dec); } if (file_access_data != null) { file_access_data.RemoveNameDec(name_dec); } } } } }
// 添加命名域 public void AddRoot(ALittleScriptRootElement root) { // 清除标记 m_guess_type_map.Remove(root.GetFile()); m_guess_error_map.Remove(root.GetFile()); m_class_data_map.Remove(root.GetFile()); m_struct_data_map.Remove(root.GetFile()); m_enum_data_map.Remove(root.GetFile()); var namespace_dec = root.GetNamespaceDec(); if (namespace_dec == null) { return; } var namespace_name_dec = namespace_dec.GetNamespaceNameDec(); if (namespace_name_dec == null) { return; } // 获取命名域名 string name = namespace_name_dec.GetElementText(); if (!m_all_data_map.TryGetValue(name, out Dictionary <ALittleScriptNamespaceNameDecElement, ALittleScriptAccessData> all_data_map)) { all_data_map = new Dictionary <ALittleScriptNamespaceNameDecElement, ALittleScriptAccessData>(); m_all_data_map.Add(name, all_data_map); } ALittleScriptAccessData all_access_data = new ALittleScriptAccessData(); if (all_data_map.ContainsKey(namespace_name_dec)) { all_data_map.Remove(namespace_name_dec); } all_data_map.Add(namespace_name_dec, all_access_data); if (!m_global_access_map.TryGetValue(name, out ALittleScriptAccessData global_access_data)) { global_access_data = new ALittleScriptAccessData(); m_global_access_map.Add(name, global_access_data); } if (!m_namespace_access_map.TryGetValue(name, out ALittleScriptAccessData namespace_access_data)) { namespace_access_data = new ALittleScriptAccessData(); m_namespace_access_map.Add(name, namespace_access_data); } if (!m_file_access_map.TryGetValue(root.GetFile(), out ALittleScriptAccessData file_access_data)) { file_access_data = new ALittleScriptAccessData(); m_file_access_map.Add(root.GetFile(), file_access_data); } var element_dec_list = namespace_dec.GetNamespaceElementDecList(); foreach (var child in element_dec_list) { // 添加类 if (child.GetClassDec() != null) { var class_dec = child.GetClassDec(); var name_dec = class_dec.GetClassNameDec(); if (name_dec == null) { continue; } // 添加类数据 AddClassData(class_dec); // 添加到全权限 all_access_data.AddNameDec(name_dec); // 按访问权限划分 var access_type = ALittleScriptUtility.CalcAccessType(child.GetModifierList()); if (access_type == ALittleScriptUtility.ClassAccessType.PUBLIC) { global_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PROTECTED) { namespace_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PRIVATE) { file_access_data.AddNameDec(name_dec); } } // 添加枚举 else if (child.GetEnumDec() != null) { var enum_dec = child.GetEnumDec(); var name_dec = enum_dec.GetEnumNameDec(); if (name_dec == null) { continue; } // 添加枚举数据 AddEnumData(enum_dec); // 添加到全权限 all_access_data.AddNameDec(name_dec); // 按访问权限划分 var access_type = ALittleScriptUtility.CalcAccessType(child.GetModifierList()); if (access_type == ALittleScriptUtility.ClassAccessType.PUBLIC) { global_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PROTECTED) { namespace_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PRIVATE) { file_access_data.AddNameDec(name_dec); } } // 添加结构体 else if (child.GetStructDec() != null) { var struct_dec = child.GetStructDec(); var name_dec = struct_dec.GetStructNameDec(); if (name_dec == null) { continue; } // 添加结构体数据 AddStructData(struct_dec); // 添加到全权限 all_access_data.AddNameDec(name_dec); // 按访问权限划分 var access_type = ALittleScriptUtility.CalcAccessType(child.GetModifierList()); if (access_type == ALittleScriptUtility.ClassAccessType.PUBLIC) { global_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PROTECTED) { namespace_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PRIVATE) { file_access_data.AddNameDec(name_dec); } } // 添加全局函数 else if (child.GetGlobalMethodDec() != null) { var method_dec = child.GetGlobalMethodDec(); var name_dec = method_dec.GetMethodNameDec(); if (name_dec == null) { continue; } // 添加到全权限 all_access_data.AddNameDec(name_dec); // 按访问权限划分 var access_type = ALittleScriptUtility.CalcAccessType(child.GetModifierList()); if (access_type == ALittleScriptUtility.ClassAccessType.PUBLIC) { global_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PROTECTED) { namespace_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PRIVATE) { file_access_data.AddNameDec(name_dec); } } // 添加单例 else if (child.GetInstanceDec() != null) { var instance_dec = child.GetInstanceDec(); var access_type = ALittleScriptUtility.CalcAccessType(child.GetModifierList()); var var_assign_expr = instance_dec.GetVarAssignExpr(); if (var_assign_expr == null) { continue; } var var_assign_dec_list = var_assign_expr.GetVarAssignDecList(); foreach (var var_assign_dec in var_assign_dec_list) { var name_dec = var_assign_dec.GetVarAssignNameDec(); if (name_dec == null) { continue; } // 添加到全权限 all_access_data.AddNameDec(name_dec); // 按访问权限划分 if (access_type == ALittleScriptUtility.ClassAccessType.PUBLIC) { global_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PROTECTED) { namespace_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PRIVATE) { file_access_data.AddNameDec(name_dec); } } } // 添加using else if (child.GetUsingDec() != null) { var using_dec = child.GetUsingDec(); var name_dec = using_dec.GetUsingNameDec(); if (name_dec == null) { continue; } // 添加到全权限 all_access_data.AddNameDec(name_dec); // 按访问权限划分 var access_type = ALittleScriptUtility.CalcAccessType(child.GetModifierList()); if (access_type == ALittleScriptUtility.ClassAccessType.PUBLIC) { global_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PROTECTED) { namespace_access_data.AddNameDec(name_dec); } else if (access_type == ALittleScriptUtility.ClassAccessType.PRIVATE) { file_access_data.AddNameDec(name_dec); } } } }