public override AstNode?VisitExplicitTag(ExplicitTagContext context) { if (_currentParameter == null) { _contracts.AddError(context, "Tags can be defined only inside parameters"); return(null); } if (!int.TryParse(context.tagNumber?.Text, out var tag)) { _contracts.AddError(context, "Invalid tag value for parameter '{0}': {1}", _currentParameter.Name, context.tagNumber?.Text); return(null); } if (!AstValidator.IsValidTag(tag)) { _contracts.AddError(context, "Tag for parameter '{0}' is not within the valid range ({1})", _currentParameter.Name, context.tagNumber?.Text); return(null); } if (_currentParameter.Tag != 0) { _contracts.AddError(context, "The parameter '{0}' already has an explicit tag ({1})", _currentParameter.Name, _currentParameter.Tag); return(null); } _currentParameter.Tag = tag; return(null); }
private void ProcessProtoMemberAttribute(ParameterDefinition param) { var attr = param.Attributes.GetAttribute(KnownTypes.ProtoMemberAttribute); if (attr == null) { return; } if (string.IsNullOrWhiteSpace(attr.Parameters)) { _contracts.AddError(attr.ParseContext, "The [{0}] attribute must have parameters", KnownTypes.ProtoMemberAttribute); return; } var match = Regex.Match(attr.Parameters, @"^\s*(?<nb>[0-9]+)\s*(?:,|$)"); if (!match.Success || !int.TryParse(match.Groups["nb"].Value, out var tagNb)) { _contracts.AddError(attr.ParseContext, "Invalid [{0}] parameters", KnownTypes.ProtoMemberAttribute); return; } if (param.Tag != 0) { _contracts.AddError(attr.ParseContext, "The parameter '{0}' already has an explicit tag ({1})", param.Name, param.Tag); return; } if (!AstValidator.IsValidTag(tagNb)) { _contracts.AddError(attr.ParseContext, "Tag for parameter '{0}' is not within the valid range ({1})", param.Name, tagNb); return; } param.Tag = tagNb; }