public EnumDef AddEnum(string name, BaseType t) { if (!t.IsInteger()) { throw new InvalidEnumArgumentException("Underlying enum type must be integral."); } var def = new EnumDef { Name = name, IsUnion = t == BaseType.UType, TypeBuilder = this, }; if (Enums.Add(name, def)) { throw new Exception("enum already exists!"); } def.UnderlyingType.BaseType = t; def.UnderlyingType.EnumDef = def; if (def.IsUnion) { def.Values.Add("NONE", new EnumVal { Name = "NONE", Value = 0, }); } return(def); }
private int ParseEnumValDecl(int offset, string schemaStr, EnumDef enumDef, bool isUnion) { string identifier; string constantValue = null; offset = ParseIdentifier(offset, schemaStr, out identifier); offset = SkipWhitespace(offset, schemaStr); if (schemaStr[offset] == '=') { offset++; offset = ParseConstant(offset, schemaStr, out constantValue); } var enumVal = new EnumVal(); enumVal.Name = identifier; if (constantValue != null) { enumVal.Value = long.Parse(constantValue); } if (isUnion && enumVal.Value.Value != 0) { enumVal.StructDef = TypeBuilder.LookupOrCreateStruct(identifier); } enumDef.Add(enumVal); return(offset); }
public FlatBuffersType(BaseType baseType = BaseType.None, StructDef structDef = null, EnumDef enumDef = null) { BaseType = baseType; ElementType = BaseType.None; StructDef = structDef; EnumDef = enumDef; }
private int ParseEnumValDeclStar(int offset, string schemaStr, EnumDef enumDef, bool isUnion) { var finished = false; var expectComma = false; while (offset < schemaStr.Length && !finished) { offset = SkipWhitespace(offset, schemaStr); if (schemaStr[offset] == '}') { finished = true; offset++; } else { if (expectComma) { offset = Consume(",", offset, schemaStr); offset = SkipWhitespace(offset, schemaStr); } else { expectComma = true; } offset = ParseEnumValDecl(offset, schemaStr, enumDef, isUnion); } } return(offset); }