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"); } }
private static void CheckParams(RppFunc function, RppFunc foundFunc) { if (!foundFunc.Params.SequenceEqual(function.Params)) { throw new Exception("Duplicated function with the same signature"); } }
private static void CheckTheSameAmountOfParams(RppFunc function, RppFunc foundFunc) { if (foundFunc.Params.SequenceEqual(function.Params)) { throw new Exception("Functions have the same amount of parameters"); } }
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"); } */ }
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"); } }); }
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); } }
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; } }
public override void VisitExit(RppFunc node) { RppMethodInfo method = node.MethodInfo; UpdateParameters(node, method); UpdateReturnType(node, method); }
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; }
public override void VisitEnter(RppFunc node) { node.ResolveTypes(_currentClass.Scope, _diagnostic); }
public override void VisitExit(RppFunc node) { GenerateRet(node, _body); Console.WriteLine("Func generated"); }
public override void VisitEnter(RppFunc node) { Console.WriteLine("Generating func: " + node.Name); _body = GetGenerator(node.MethodInfo.Native); _func = node.MethodInfo.Native; }
private static void UpdateReturnType(RppFunc node, RppMethodInfo method) { if (!node.IsConstructor) { method.ReturnType = node.ReturnType.Value; } }
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; }
private void DefineFunc(RppFunc func) { func.IsStatic = Kind == ClassKind.Object; func.Class = this; }
public virtual void VisitExit(RppFunc node) { }
public virtual void VisitEnter(RppFunc node) { }
public override void VisitEnter(RppFunc node) { if (node.Name == "main" && node.IsStatic) { MainFunctions.Add(node); } }
public override void VisitEnter(RppFunc node) { TypeShouldBeDeclaredAbstractOrMethodShouldBeImplemented(node); }