Exemplo n.º 1
0
        public override void EnterAtomic_field(DcParser.Atomic_fieldContext context)
        {
            var field = new DcAtomicField(context.name.Text, _currentClass, false);

            // Read keywords
            ReadKeywordsIntoList(context.keywords, field.KeywordList);

            var hasDefaultValue = false;

            // Read each parameter
            var parameters = context.parameters;

            while (parameters != null)
            {
                var parameter = BuildDcParameterFromContext(parameters.p);
                hasDefaultValue = parameter.HasDefaultValue;
                field.AddElement(parameter);
                parameters = parameters.next;
            }

            if (hasDefaultValue)
            {
                var bw = new SpanBufferWriter(stackalloc byte[512]);
                foreach (var element in field.Elements)
                {
                    bw.WriteBytes(element.DefaultValue.Span);
                }
                field.DefaultValue    = bw.Data.ToArray();
                field.HasDefaultValue = true;
            }

            if (!_currentClass.AddField(field))
            {
                throw new Exception($"Failed to add field {context.name.Text} to class {_currentClass.Name}");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="DcParser.atomic_field"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitAtomic_field([NotNull] DcParser.Atomic_fieldContext context)
 {
 }