public override IRppNode Analyze(SymbolTable scope, Diagnostic diagnostic) { Value = (IRppExpr) Value.Analyze(scope, diagnostic); RppVar declIn = new RppVar(MutabilityFlag.MfVal, "<in>", Value.Type, Value); declIn.Analyze(scope, diagnostic); CaseClauses = NodeUtils.Analyze(scope, CaseClauses, diagnostic); Type = CheckCommonType(CaseClauses, Token).AsResolvable(); RppVar declOut = new RppVar(MutabilityFlag.MfVar, "<out>", Type, new RppDefaultExpr(Type)); RppId declInId = new RppId("<in>", declIn); declInId.Analyze(scope, diagnostic); RppId declOutId = new RppId("<out>", declOut); RppMatchingContext ctx = new RppMatchingContext(); var ifC = Create(declInId, declOutId, CaseClauses, ctx); var expr = new RppBlockExpr(List<IRppNode>(declIn, ifC)) {Exitable = true}; SymbolTable matchScope = new SymbolTable(scope); RppBlockExpr matchBlock = new RppBlockExpr(List<IRppNode>(declOut, expr, declOutId)); return matchBlock.Analyze(matchScope, diagnostic); }
protected bool Equals(RppVar other) { Debug.Assert(other.Type != null, "other.Type != null"); return Name.Equals(other.Name) && Type.Equals(other.Type); }
/// <summary> /// For Option we call isDefined method, for bools, just return the variable content itself /// </summary> /// <param name="localOption">variable which has bool or Option</param> private static IRppExpr GetIsValidExpression(RppVar localOption) { string localOptionVar = localOption.Name; if (Equals(localOption.Type.Value, RppTypeSystem.BooleanTy)) { return Id(localOptionVar); } return CallMethod(localOptionVar, "isDefined", Collections.NoExprs); }
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); }
public override IEnumerable<IRppExpr> DeclareVariables(RType inputType) { RppVar variable = new RppVar(MutabilityFlag.MfVal, Name, _resolvableType, new RppDefaultExpr(_resolvableType)) {Token = Token}; return List(variable); }
public virtual void Visit(RppVar node) { }
public override void Visit(RppVar node) { node.InitExpr.Accept(this); }