public EnumFieldContext FieldFromLean(IntegerEnumField field)
 {
     return new EnumFieldContext(MangleJavaConstantName(field.Name), field.Value);
 }
 public void Visit(IntegerEnumField integerEnumField)
 {
     sb.Append("  ");
     sb.Append(integerEnumField.Name);
     sb.Append(" : ");
     sb.Append(integerEnumField.Value);
 }
 public EnumFieldContext FieldFromTrip(IntegerEnumField field)
 {
     return new EnumFieldContext(MangleCSharpConstantName(field.Name), field.Value);
 }
Esempio n. 4
0
 public void Visit(IntegerEnumField integerEnumField)
 {
     throw new NotImplementedException();
 }
        public static List<Definition> BuildDefinitions(ParseTreeNodeList definitionNodes)
        {
            var definitions = new List<Definition>();
            foreach (var definitionNode in definitionNodes)
            {
                var definitionChildNode = definitionNode.ChildNodes[0];
                if (definitionChildNode.Term.Name == IdlGrammar.NTNAME_TENUM)
                {
                    var enumId = definitionChildNode.ChildNodes[0].Token.Text;
                    var enumFields = new List<IntegerEnumField>();
                    int nextDefaultEnumValue = 0; // trip enumerations start at zero by default
                    foreach (var enumFieldNode in definitionChildNode.ChildNodes[1].ChildNodes)
                    {
                        var enumFeildId = enumFieldNode.ChildNodes[0].Token.Text;
                        IntegerEnumField enumField = null;
                        if (enumFieldNode.ChildNodes.Count > 1 && 
                            enumFieldNode.ChildNodes[1].ChildNodes != null && 
                            enumFieldNode.ChildNodes[1].ChildNodes.Count > 0) // has enum value
                        {
                            var valueText = enumFieldNode.ChildNodes[1].ChildNodes[0].Token.Text;
                            int enumValue = int.Parse(valueText);
                            enumField = new IntegerEnumField(enumFeildId, enumValue, nextDefaultEnumValue);
                            nextDefaultEnumValue = ++enumValue;
                        }
                        else
                        {
                            enumField = new IntegerEnumField(enumFeildId, null, nextDefaultEnumValue);
                            ++nextDefaultEnumValue;
                        }
                        enumFields.Add(enumField);
                    }
                    var integerEnum = new IntegerEnum(enumId, enumFields);
                    definitions.Add(integerEnum);
                }
                else if (definitionChildNode.Term.Name == IdlGrammar.NTNAME_TSTRUCT)
                {
                    var name = definitionChildNode.ChildNodes[0].Token.Text;
                    var tripFields = BuildTripFields(definitionChildNode.ChildNodes[1], name);

                    var tripStruct = new Struct(name, tripFields);
                    definitions.Add(tripStruct);
                }
                else if (definitionChildNode.Term.Name == IdlGrammar.NTNAME_TSERVICE)
                {
                    var name = definitionChildNode.ChildNodes[0].Token.Text;
                    List<TripMethod> methods = new List<TripMethod>();

                    var firstChild = definitionChildNode.ChildNodes[1];
                    if (firstChild.Term.Name == IdlGrammar.NTNAME_FUNCTIONS)
                    {
                        methods = BuildTripMethods(definitionChildNode.ChildNodes[1]);
                    }
                    var service = new Service(name, methods);
                    definitions.Add(service);
                }
            }


            return definitions;
        }