Exemplo n.º 1
0
        public override void VisitExit(RppFunc node)
        {
            string methodName = node.IsConstructor ? "ctor" : node.Name;
            var rMethodAttributes = GetMethodAttributes(node.Modifiers);
            if (node.IsAbstract)
            {
                rMethodAttributes |= RMethodAttributes.Abstract;
            }

            if (node.IsPropertyAccessor)
            {
                rMethodAttributes |= RMethodAttributes.Final;
            }

            if (node.IsSynthesized)
            {
                rMethodAttributes |= RMethodAttributes.Synthesized;
            }

            RppMethodInfo method = _currentType.DefineMethod(methodName, rMethodAttributes);
            node.MethodInfo = method;

            if (node.TypeParams.Any())
            {
                string[] genericArgumentsNames = node.TypeParams.Select(tp => tp.Name).ToArray();
                var genericParameters = method.DefineGenericParameters(genericArgumentsNames);

                node.ResolveGenericTypeConstraints(_currentClass.Scope, _diagnostic);
                ProcessGenerics(node.TypeParams, genericParameters);
            }

            node.ResolveTypes(_currentClass.Scope, _diagnostic);

            RppParameterInfo[] parameters = node.Params.Select(p => new RppParameterInfo(p.Name, p.Type.Value, p.IsVariadic)).ToArray();
            node.Params.ForEachWithIndex((index, p) => p.Index = index + 1); // Assign index to each parameter, 1 is for 'this'

            method.Parameters = parameters;
            method.ReturnType = node.ReturnType.Value;
        }
Exemplo n.º 2
0
 public override void VisitEnter(RppFunc node)
 {
     node.ResolveTypes(_currentClass.Scope, _diagnostic);
 }