Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 protected bool Equals(RppVar other)
 {
     Debug.Assert(other.Type != null, "other.Type != null");
     return Name.Equals(other.Name) && Type.Equals(other.Type);
 }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 public override IEnumerable<IRppExpr> DeclareVariables(RType inputType)
 {
     RppVar variable = new RppVar(MutabilityFlag.MfVal, Name, _resolvableType, new RppDefaultExpr(_resolvableType)) {Token = Token};
     return List(variable);
 }
Ejemplo n.º 6
0
 public virtual void Visit(RppVar node)
 {
 }
Ejemplo n.º 7
0
 public override void Visit(RppVar node)
 {
     node.InitExpr.Accept(this);
 }