コード例 #1
0
        private void Visit(AssignmentStmt assign)
        {
            var il        = CurrentMethodIL;
            var varSymbol = assign.VariableSymbol;

            if (varSymbol.Type.IsArray)
            {
                var arrVar = assign.Variable as ArrayVariableExpr;
                if (varSymbol is GlobalSymbol)
                {
                    var globalVar = varSymbol as GlobalSymbol;
                    il.Emit(OpCodes.Ldsfld, globalVar.CILField);
                    Visit((dynamic)arrVar.SubscriptExpr);
                    Visit((dynamic)assign.AssignmentExpr);
                    il.Emit(OpCodes.Stelem, varSymbol.Type.CILType.GetElementType());
                }
                else if (varSymbol is VariableSymbol)
                {
                    var localVar = varSymbol as VariableSymbol;
                    il.Emit(OpCodes.Ldloc, localVar.CILLocal);
                    Visit((dynamic)arrVar.SubscriptExpr);
                    Visit((dynamic)assign.AssignmentExpr);
                    il.Emit(OpCodes.Stelem, varSymbol.Type.CILType.GetElementType());
                }
                else if (varSymbol is ParameterSymbol)
                {
                    var localVar = varSymbol as ParameterSymbol;
                    il.Emit(OpCodes.Ldarg, localVar.CILParameter.Position - 1);
                    Visit((dynamic)arrVar.SubscriptExpr);
                    Visit((dynamic)assign.AssignmentExpr);
                    il.Emit(OpCodes.Stelem, varSymbol.Type.CILType.GetElementType());
                }
                else
                {
                    throw new Exception("Unexpected symboltype " + varSymbol.GetType());
                }
            }
            else
            {
                Visit((dynamic)assign.AssignmentExpr);
                if (varSymbol is GlobalSymbol)
                {
                    var globalVar = varSymbol as GlobalSymbol;
                    CurrentMethodIL.Emit(OpCodes.Stsfld, globalVar.CILField);
                }
                else if (varSymbol is VariableSymbol)
                {
                    var localVar = varSymbol as VariableSymbol;
                    CurrentMethodIL.Emit(OpCodes.Stloc, localVar.CILLocal);
                }
                else if (varSymbol is ParameterSymbol)
                {
                    var localVar = varSymbol as ParameterSymbol;
                    CurrentMethodIL.Emit(OpCodes.Starg, localVar.CILParameter.Position - 1);
                }
                else
                {
                    throw new Exception("Unexpected symboltype " + varSymbol.GetType());
                }
            }
        }