示例#1
0
 private static void CheckReturnValue(RppFunc function, RppFunc foundFunc)
 {
     if (!foundFunc.ReturnType.Equals(function.ReturnType))
     {
         throw new Exception("Return type should match for the functions with the same name");
     }
 }
示例#2
0
 private static void CheckParams(RppFunc function, RppFunc foundFunc)
 {
     if (!foundFunc.Params.SequenceEqual(function.Params))
     {
         throw new Exception("Duplicated function with the same signature");
     }
 }
示例#3
0
 private static void CheckTheSameAmountOfParams(RppFunc function, RppFunc foundFunc)
 {
     if (foundFunc.Params.SequenceEqual(function.Params))
     {
         throw new Exception("Functions have the same amount of parameters");
     }
 }
示例#4
0
 private static void TypeShouldBeDeclaredAbstractOrMethodShouldBeImplemented(RppFunc node)
 {
     /*
     if (!node.Class.Modifiers.Contains(ObjectModifier.OmAbstract) && node.IsAbstract && !node.Modifiers.Contains(ObjectModifier.OmAbstract))
     {
         throw new SemanticException($"DeclaringType {node.Class.Name} needs to be abstract, since method {node.ToString()} is not defined");
     }
     */
 }
示例#5
0
 private static void Validate(RppFunc function)
 {
     function.Params.ForEachWithIndex((index, param) =>
                                      {
                                          if (RppTypeSystem.UnitTy.Equals(param.Type.Value))
                                          {
                                              throw new Exception($"Parameter {param.Name} can't be Unit");
                                          }
                                      });
 }
示例#6
0
 private static void Validate(IEnumerable<RppFunc> definedFunctions, RppFunc function)
 {
     var foundFunc = definedFunctions.First(func => func.Name == function.Name);
     if (foundFunc != null)
     {
         CheckReturnValue(function, foundFunc);
         CheckParams(function, foundFunc);
         CheckTheSameAmountOfParams(function, foundFunc);
     }
 }
示例#7
0
 private static void UpdateParameters(RppFunc node, RppMethodInfo method)
 {
     IRppParam[] funcParams = node.Params;
     if (funcParams.Length != 0)
     {
         RppParameterInfo[] funcParamsTypes = funcParams.Select(p => new RppParameterInfo(p.Name, ResolveType(p))).ToArray();
         method.Parameters = funcParamsTypes;
     }
 }
示例#8
0
 public override void VisitExit(RppFunc node)
 {
     RppMethodInfo method = node.MethodInfo;
     UpdateParameters(node, method);
     UpdateReturnType(node, method);
 }
示例#9
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;
        }
示例#10
0
 public override void VisitEnter(RppFunc node)
 {
     node.ResolveTypes(_currentClass.Scope, _diagnostic);
 }
示例#11
0
        public override void VisitExit(RppFunc node)
        {
            GenerateRet(node, _body);

            Console.WriteLine("Func generated");
        }
示例#12
0
 public override void VisitEnter(RppFunc node)
 {
     Console.WriteLine("Generating func: " + node.Name);
     _body = GetGenerator(node.MethodInfo.Native);
     _func = node.MethodInfo.Native;
 }
示例#13
0
 private static void UpdateReturnType(RppFunc node, RppMethodInfo method)
 {
     if (!node.IsConstructor)
     {
         method.ReturnType = node.ReturnType.Value;
     }
 }
示例#14
0
        private static IEnumerable<RppFunc> CreatePropertyAccessors(RppField field)
        {
            IRppParam valueParam = new RppParam("value", field.Type);

            if (field.MutabilityFlag != MutabilityFlag.MfVal)
            {
                RppFunc setter = new RppFunc(RppMethodInfo.GetSetterAccessorName(field.Name), new[] {valueParam}, ResolvableType.UnitTy,
                    new RppAssignOp(new RppId(field.MangledName), new RppId("value", valueParam)))
                {
                    IsSynthesized = true,
                    IsPropertyAccessor = true,
                    Modifiers = field.Modifiers
                };

                yield return setter;
            }

            RppFunc getter = new RppFunc(RppMethodInfo.GetGetterAccessorName(field.Name), Enumerable.Empty<IRppParam>(), field.Type,
                new RppId(field.MangledName, field))
            {
                IsSynthesized = true,
                IsPropertyAccessor = true,
                Modifiers = field.Modifiers
            };

            yield return getter;
        }
示例#15
0
 private void DefineFunc(RppFunc func)
 {
     func.IsStatic = Kind == ClassKind.Object;
     func.Class = this;
 }
示例#16
0
 public virtual void VisitExit(RppFunc node)
 {
 }
示例#17
0
 public virtual void VisitEnter(RppFunc node)
 {
 }
示例#18
0
 public override void VisitEnter(RppFunc node)
 {
     if (node.Name == "main" && node.IsStatic)
     {
         MainFunctions.Add(node);
     }
 }
示例#19
0
 public override void VisitEnter(RppFunc node)
 {
     TypeShouldBeDeclaredAbstractOrMethodShouldBeImplemented(node);
 }