public override IRppExpr RewriteCaseClause(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx) { if (Name == "_") { return Block(Assign(outOut, thenExpr), Break); } throw new NotImplementedException(); }
private IRppExpr ProcessCases(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx, string localOptionVar, int patternIndex) { if (patternIndex >= _patterns.Length) { List<IRppNode> nodes = new List<IRppNode>(); // Binding to a variable if it exists varid@Foo... if (BindedVariableToken != null) { var varId = Val(BindedVariableToken, _type.Value, inVar); nodes.Add(varId); } nodes.Add(thenExpr); nodes.Add(Break); return Block(nodes); } IRppExpr classParamValue = GetClassParam(localOptionVar, patternIndex, _patterns.Length); RppMatchPattern pattern = _patterns[patternIndex]; int nextPatternIndex = patternIndex + 1; if (pattern is RppLiteralPattern) { RppLiteralPattern literalPattern = (RppLiteralPattern) pattern; return If(BinOp("==", literalPattern.Literal, classParamValue), ProcessCases(inVar, outOut, thenExpr, ctx, localOptionVar, nextPatternIndex)); } RType classParamType = _classParamTypes[patternIndex]; if (pattern is RppVariablePattern) { RType patternType = classParamType; RppVar var = Val(pattern.Token.Text, patternType, classParamValue); var.Token = pattern.Token; return Block(var, ProcessCases(inVar, outOut, thenExpr, ctx, localOptionVar, nextPatternIndex)); } if (pattern is RppConstructorPattern) { RppConstructorPattern constructorPattern = (RppConstructorPattern) pattern; string classParamArg = ctx.CreateLocal(classParamType.Name); RppVar classParamArgVar = Val(classParamArg, classParamType, classParamValue); RppId classParamInput = StaticId(classParamArgVar); IRppExpr nextPattern = ProcessCases(inVar, outOut, thenExpr, ctx, localOptionVar, nextPatternIndex); return Block(classParamArgVar, constructorPattern.MatchInstance(classParamInput, outOut, nextPattern, ctx)); } return ProcessCases(inVar, outOut, thenExpr, ctx, localOptionVar, nextPatternIndex); }
private IRppExpr MatchInstance(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx) { // If type of input variable do not match pattern type, we need to cast it if (!inVar.Type.Equals(_type)) { string localVar = ctx.CreateLocal(_type.Name.Name); var castedVariable = Val(localVar, _type.Value, new RppAsInstanceOf(inVar, _type)); return If(BinOp("!=", new RppAsInstanceOf(inVar, _type), NullTy), Block(castedVariable, ProcessMatchExpr(Id(localVar), outOut, thenExpr, ctx))); } return ProcessMatchExpr(inVar, outOut, thenExpr, ctx); }
private static RppSelector Selector(IRppExpr expr, RppMember member) { return new RppSelector(expr, member); }
public abstract IRppExpr RewriteCaseClause(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx);
private static IRppExpr Create(RppMember declInId, RppMember declOutId, IEnumerable<RppCaseClause> caseClauses, RppMatchingContext ctx) { return Block(caseClauses.Select(c => c.RewriteCaseClause(declInId, declOutId, ctx)).ToList<IRppNode>()); }
public override IRppExpr RewriteCaseClause(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx) { return If(BinOp("==", inVar, Literal), Block(Assign(outOut, thenExpr), Break)); }
private IRppExpr ProcessMatchExpr(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx) { string localOptionVar = ctx.CreateLocalOption(); RppVar localOption = Val(localOptionVar, _unapplyMethod.ReturnType, CallMethod(_type.Value.Name, _unapplyMethod.Name, inVar)); return Block(localOption, If(GetIsValidExpression(localOption), ProcessCases(inVar, outOut, thenExpr, ctx, localOptionVar, 0))); }
public override IRppExpr RewriteCaseClause(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx) { return MatchInstance(inVar, outOut, Assign(outOut, thenExpr), ctx); }
public ClosureResolveResults(RppMember expr, RppMethodInfo resolvedFunc) : base(resolvedFunc) { _expr = expr; }
public IRppExpr RewriteCaseClause(RppMember inVar, RppMember outOut, RppMatchingContext ctx) { return Pattern.RewriteCaseClause(inVar, outOut, Expr, ctx); }
public static RppSelector Selector(IRppExpr target, RppMember path) { return new RppSelector(target, path); }
public override IRppExpr RewriteCaseClause(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx) { throw new NotImplementedException(); }
public override IRppExpr RewriteCaseClause(RppMember inVar, RppMember outOut, IRppExpr thenExpr, RppMatchingContext ctx) { RppVar variable = new RppVar(MutabilityFlag.MfVal, Name, _resolvableType, new RppAsInstanceOf(inVar, _resolvableType)) {Token = Token}; RppIf ifCond = If(BinOp("!=", Id(Name), NullTy), Block(Assign(outOut, thenExpr), Break), EmptyExpr); return Block(variable, ifCond); }