private static bool FindEnumTypeDef(MessageDef messageDef, string enumName, out EnumTypeDef ret) { bool find = messageDef.m_EnumTypes.TryGetValue(enumName, out ret); if (!find) { foreach (var pair in messageDef.m_Messages) { find = FindEnumTypeDef(pair.Value, enumName, out ret); if(find) { break; } } } return find; }
private static void ParseEnum(string dslFile, FunctionData funcData, string defGroupName, SortedDictionary<string, EnumTypeDef> enumTypes, ref bool haveError) { if (null != funcData) { CallData callData = funcData.Call; if (null != callData && callData.GetParamNum() >= 1) { string enumName, groupName; enumName = callData.GetParamId(0); if (callData.GetParamNum() > 1) { groupName = callData.GetParamId(1); } else { groupName = defGroupName; } EnumTypeDef enumTypeDef = new EnumTypeDef(); enumTypeDef.m_EnumName = enumName; enumTypeDef.m_GroupName = groupName; if (enumTypes.ContainsKey(enumName)) { enumTypes[enumName] = enumTypeDef; } else { enumTypes.Add(enumName, enumTypeDef); } int nextValue = 0; foreach (ISyntaxComponent comp in funcData.Statements) { ValueData val = comp as ValueData; if (null != val) { if (val.HaveId()) { enumTypeDef.m_EnumMembers.Add(val.GetId(), nextValue); ++nextValue; } else { LogSystem.Error("enum member {0} must have name ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile); haveError = true; } } else { CallData field = comp as CallData; if (null != field) { if (field.HaveId()) { if (field.GetParamNum() >= 1) { ISyntaxComponent param = field.GetParam(0); string id = param.GetId(); int idType = param.GetIdType(); if (idType == ValueData.NUM_TOKEN) { nextValue = int.Parse(id); } else { LogSystem.Error("enum member {0} value must be number ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile); haveError = true; } enumTypeDef.m_EnumMembers.Add(field.GetId(), nextValue); } else { enumTypeDef.m_EnumMembers.Add(field.GetId(), nextValue); } ++nextValue; } else { LogSystem.Error("enum member {0} must have name ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile); haveError = true; } } else { LogSystem.Error("enum member {0} must end with ';' ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile); haveError = true; } } } } else { LogSystem.Error("enum {0} must have 1 or 2 params (name and group) ! line {1} file {2}", funcData.ToScriptString(), funcData.GetLine(), dslFile); haveError = true; } } }
private void GenEnumTypeProto(EnumTypeDef enumTypeDef, int indent, TextWriter sw) { const string c_Indents = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; string indentStr = c_Indents.Substring(0, indent); try { sw.WriteLine(); sw.WriteLine("{0}enum {1}", indentStr, enumTypeDef.m_EnumName); sw.WriteLine("{0}{{", indentStr); foreach (var pair in enumTypeDef.m_EnumMembers) { sw.WriteLine("{0}\t{1} = {2};", indentStr, pair.Key, pair.Value); } sw.WriteLine("{0}}}", indentStr); } catch (Exception ex) { Console.WriteLine(ex); } }