Exemplo n.º 1
0
        private static Func <TextReader, int> CreateFindMember(IEnumerable <string> names)
        {
            var nameToResults =
                names
                .Select((name, index) => NameAutomata <int> .CreateName(name, emit => emit.LoadConstant(index)))
                .ToList();

            return(NameAutomata <int> .Create(nameToResults, true, defaultValue : -1));
        }
Exemplo n.º 2
0
        private static SetterLookupThunkReaderDelegate CreateFindMemberThunkReader(IEnumerable <string> names)
        {
            var nameToResults =
                names
                .Select((name, index) => NameAutomata <int> .CreateName(typeof(ThunkReader).MakeByRefType(), name, emit => emit.LoadConstant(index)))
                .ToList();

            var ret = NameAutomata <int> .Create <SetterLookupThunkReaderDelegate>(typeof(ThunkReader).MakeByRefType(), nameToResults, true, defaultValue : -1);

            return((SetterLookupThunkReaderDelegate)ret);
        }
Exemplo n.º 3
0
        private static EnumThunkReaderDelegate <EnumType> CreateFindFlagsEnumThunkReader(IReadOnlyList <Tuple <string, object> > names)
        {
            var thunkReaderRef = typeof(ThunkReader).MakeByRefType();

            var underlyingType = Enum.GetUnderlyingType(typeof(EnumType));

            var resultValue = "result_value";

            var nameToResults =
                names
                .Select(name =>
                        NameAutomata <EnumType> .CreateName(
                            thunkReaderRef,
                            name.Item1,
                            emit =>
            {
                LoadConstantOfType(emit, name.Item2, underlyingType);
                emit.LoadLocal(resultValue);
                emit.Or();
                emit.StoreLocal(resultValue);
            }))
                .ToList();

            var underlyingDefault = underlyingType.DefaultValue();

            var ret =
                NameAutomata <EnumType> .CreateFold <EnumThunkReaderDelegate <EnumType> >(
                    thunkReaderRef,
                    nameToResults,
                    emit =>
            {
                emit.DeclareLocal(underlyingType, resultValue);
                LoadConstantOfType(emit, Convert.ChangeType(0, underlyingType), underlyingType);
                emit.StoreLocal(resultValue);
            },
                    emit =>
            {
                emit.LoadLocal(resultValue);
                emit.Return();
            },
                    true,
                    true,
                    false,
                    defaultValue : underlyingDefault
                    );

            return((EnumThunkReaderDelegate <EnumType>)ret);
        }
Exemplo n.º 4
0
        private static Func <TextReader, EnumType> CreateFindEnum(IEnumerable <Tuple <string, object> > names)
        {
            var underlyingType = Enum.GetUnderlyingType(typeof(EnumType));

            var nameToResults =
                names
                .Select(name => NameAutomata <EnumType> .CreateName(name.Item1, emit => LoadConstantOfType(emit, name.Item2, underlyingType)))
                .ToList();

            return
                (NameAutomata <EnumType> .Create(
                     nameToResults,
                     false,
                     defaultValue : null
                     ));
        }
Exemplo n.º 5
0
        private static Func <TextReader, EnumType> CreateFindFlagsEnum(IReadOnlyList <Tuple <string, object> > names)
        {
            var underlyingType = Enum.GetUnderlyingType(typeof(EnumType));

            var resultValue = "result_value";

            var nameToResults =
                names
                .Select(name =>
                        NameAutomata <EnumType> .CreateName(
                            typeof(TextReader),
                            name.Item1,
                            emit =>
            {
                LoadConstantOfType(emit, name.Item2, underlyingType);
                emit.LoadLocal(resultValue);
                emit.Or();
                emit.StoreLocal(resultValue);
            }))
                .ToList();


            var ret =
                NameAutomata <EnumType> .CreateFold <Func <TextReader, EnumType> >(
                    typeof(TextReader),
                    nameToResults,
                    emit =>
            {
                emit.DeclareLocal(underlyingType, resultValue);
                LoadConstantOfType(emit, 0, underlyingType);
                emit.StoreLocal(resultValue);
            },
                    emit =>
            {
                emit.LoadLocal(resultValue);
                emit.Return();
            },
                    true,
                    true,
                    false,
                    defaultValue : null
                    );

            return((Func <TextReader, EnumType>)ret);
        }
Exemplo n.º 6
0
        private static EnumThunkReaderDelegate <EnumType> CreateFindEnumThunkReader(IEnumerable <Tuple <string, object> > names)
        {
            var thunkReaderRef = typeof(ThunkReader).MakeByRefType();

            var underlyingType = Enum.GetUnderlyingType(typeof(EnumType));

            var nameToResults =
                names
                .Select(name => NameAutomata <EnumType> .CreateName(thunkReaderRef, name.Item1, emit => LoadConstantOfType(emit, name.Item2, underlyingType)))
                .ToList();

            var ret =
                NameAutomata <EnumType> .Create <EnumThunkReaderDelegate <EnumType> >(
                    thunkReaderRef,
                    nameToResults,
                    false,
                    defaultValue : null
                    );

            return((EnumThunkReaderDelegate <EnumType>)ret);
        }