private void BuildMethod(ModuleBuilder moduleBuilder, MethodDescriptor meth, NyaParser.Interface_method_declarationContext context) { string methodName = context.identifier().GetText(); MethodAttributes methAttrs = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.NewSlot; foreach (var attr in context.attributes()?.children? .OfType <NyaParser.AttributeContext>() ?? new NyaParser.AttributeContext[] { }) { string attrName = attr.identifier().GetText(); switch (attrName) { case "public": break; } } var parameters = context.fixed_parameters()?.children? .OfType <NyaParser.Fixed_parameterContext>() ?? new NyaParser.Fixed_parameterContext[] { }; meth.ParameterTypes = parameters.Select(x => ParseTypeDescriptor(x.type_descriptor())).ToArray(); Type returnType = ParseTypeDescriptor(context.type_descriptor()); MethodBuilder methodBuilder; methodBuilder = _currTypeBuilder.DefineMethod(methodName, methAttrs, returnType, meth.ParameterTypes); for (int i = 0; i < parameters.Count(); i++) { var param = parameters.ElementAt(i); string paramName = param.identifier().GetText(); ParameterAttributes pAttrs = ParameterAttributes.None; ParameterBuilder pb = methodBuilder.DefineParameter(i + 1, pAttrs, paramName); meth.Parameters.Add(pb); if (param.Question() != null || param.literal() != null) { pb.SetCustomAttribute( new CustomAttributeBuilder( typeof(OptionalAttribute).GetConstructor(new Type[] { }), new object[] { }) ); if (param.literal() != null) { object o = Visit(param.literal()); if (o != null) { pb.SetConstant(o); } } } } meth.Builder = methodBuilder; }
public override object VisitInterface_method_declaration([NotNull] NyaParser.Interface_method_declarationContext context) { // TODO: Break out constructor logic to new method string methodName = context.identifier().GetText(); MethodDescriptor descriptor = new MethodDescriptor() { Name = methodName, Context = context }; _currentDescriptor.Methods.Add(descriptor); return(descriptor); }