Exemplo n.º 1
0
        public static void _EmitVariableDefinition(VariableDefinitionList vdl, List<ILInstuction> il)
        {
            foreach (var vd in vdl.Definitions)
            {
                if (vd.InitExpression != null) {
                    var initExprVariable = _EmitExpression(vd.InitExpression, il);

                    CurrentFunction.AddLocal(initExprVariable, vd.VariableType);

                    var ilExpr = _constructAssignExpression(vd.Name, initExprVariable);

                    CurrentFunction.AddLocal(vd.Name, vd.VariableType);

                    il.Add(ilExpr);
                }
                else
                {
                    object c;
                    if (vd.VariableType.Equals(VariableType.IntType))
                        c = 0;
                    else if (vd.VariableType.Equals(VariableType.BoolType))
                        c = false;
                    else
                        c = null;
                    var ilExpr = _constructAssignExpressionToConst(vd.Name, c);

                    CurrentFunction.AddLocal(vd.Name, vd.VariableType);

                    il.Add(ilExpr);
                }
            }
        }
Exemplo n.º 2
0
        public static void EmitVariableDefinition(VariableDefinitionList vdl, List<ILInstuction> il)
        {
            foreach (var vd in vdl.Definitions)
            {
                ILExpression initExpr = new ILExpression();
                initExpr.Type = ILExpressionType.Assign;

                ILExpression varAccess = new ILExpression();
                varAccess.Type = ILExpressionType.VariableAccess;
                varAccess.Const = vd.Name;

                initExpr.LeftNode = varAccess;
                if (vd.InitExpression != null)
                    initExpr.RightNode = ConstructILExpression(vd.InitExpression);
                else
                {
                    initExpr.RightNode = new ILExpression();
                    initExpr.RightNode.Type = ILExpressionType.Const;
                    if (vd.VariableType.Equals(VariableType.IntType))
                        initExpr.RightNode.Const = 0;
                    else if (vd.VariableType.Equals(VariableType.BoolType))
                        initExpr.RightNode.Const = false;
                    else
                        initExpr.RightNode.Const = null;
                }
                initExpr.Line = GetLabel();
                il.Add(initExpr);
            }
        }