Beispiel #1
0
 public void Add(VariableSymbol symbol)
 {
     Definitions.Add(symbol);
 }
        public static void EmitVariableDefinition(VariableSymbol vSymbol, SymbolTable table, ILGenerator ilGen)
        {
            Type localType = GetTypeForCompilerType(vSymbol.VariableType);

            LocalBuilder localBuilder = ilGen.DeclareLocal(localType);
            if (vSymbol.InitExpression != null)
            {
                if (vSymbol.InitExpression.ResultType.TypeEnum == VariableTypeEnum.NULL)
                {
                    Type arrayType = GetTypeForCompilerType(vSymbol.VariableType);
                    ilGen.Emit(OpCodes.Call, GetArrayNullGetter(arrayType));
                }
                else
                {
                    EmitExpression(vSymbol.InitExpression, table, ilGen);
                }
            }
            else
            {
                if (vSymbol.VariableType.TypeEnum == VariableTypeEnum.Array)
                {
                    MethodInfo mi = GetArrayNullGetter(localType);
                    ilGen.Emit(OpCodes.Call, mi);
                }
                else
                {
                    ilGen.Emit(OpCodes.Ldc_I4_0);
                }
            }
            ilGen.Emit(OpCodes.Stloc, localBuilder);

            table.AddSymbol(vSymbol.Name, localType, localBuilder);
        }