private DynamicSignature CompileExpression(IExpression expression, Type ownerType, Import[] imports, Type[] identifierTypes, BoundExpressionOptions options, Resolver resolver)
        {
            var method = new DynamicMethod(
                "DynamicMethod",
                typeof(object),
                new[] { typeof(object[]) },
                options.RestrictedSkipVisibility
            );

            var il = method.GetILGenerator();

            new Compiler(il, resolver).Compile(expression);

#if DEBUG
            //WriteToDisk(expression, resolver);
#endif

            return (DynamicSignature)method.CreateDelegate(typeof(DynamicSignature));
        }
        internal BoundExpression(CachedDynamicExpression dynamicExpression, Type ownerType, Import[] imports, Type[] identifierTypes, BoundExpressionOptions options)
        {
            Require.NotNull(dynamicExpression, "dynamicExpression");
            Require.NotNull(imports, "imports");
            Require.NotNull(identifierTypes, "identifierTypes");

            _dynamicExpression = dynamicExpression;

            _parameterMap = BuildParameterMap(ownerType, identifierTypes);

            var resolver = new Resolver(_dynamicExpression, ownerType, imports, identifierTypes, _parameterMap, options);

            var resolvedTree = resolver.Resolve(_dynamicExpression.ParseResult.RootNode);

#if DEBUG
            ResolvedExpression = resolvedTree;
#endif

            _compiledMethod = CompileExpression(resolvedTree, ownerType, imports, identifierTypes, options, resolver);
        }
Beispiel #3
0
        public Resolver(CachedDynamicExpression dynamicExpression, Type ownerType, Import[] imports, Type[] identifierTypes, int[] parameterMap, BoundExpressionOptions options)
        {
            Require.NotNull(dynamicExpression, "dynamicExpression");
            Require.NotNull(imports, "imports");
            Require.NotNull(identifierTypes, "identifierTypes");
            Require.NotNull(parameterMap, "parameterMap");

            DynamicExpression = dynamicExpression;
            OwnerType = ownerType;
            Imports = imports;
            IdentifierTypes = identifierTypes;
            Options = options;

            // Inverse the parameter map.

            IdentifierIndexes = new int[IdentifierTypes.Length];

            for (int i = 0; i < IdentifierTypes.Length; i++)
            {
                IdentifierIndexes[i] = -1;

                if (IdentifierTypes[i] != null)
                {
                    for (int j = 0; j < parameterMap.Length; j++)
                    {
                        if (parameterMap[j] == i)
                        {
                            IdentifierIndexes[i] = j;
                            break;
                        }
                    }

                    Debug.Assert(IdentifierIndexes[i] != -1);
                }
            }

            IgnoreCase = !global::Expressions.DynamicExpression.IsLanguageCaseSensitive(DynamicExpression.Language);
        }
            public CacheKey(IdentifierCollection identifiers, bool ignoreCase, IBindingContext bindingContext, BoundExpressionOptions options)
            {
                Options = options;

                OwnerType = bindingContext.OwnerType;

                var imports = bindingContext.Imports;

                Imports = new Import[imports == null ? 0 : imports.Count];

                if (Imports.Length > 0)
                    imports.CopyTo(Imports, 0);

                IdentifierTypes = new Type[identifiers.Count];

                for (int i = 0; i < identifiers.Count; i++)
                {
                    IdentifierTypes[i] = bindingContext.GetVariableType(
                        identifiers[i].Name,
                        ignoreCase
                    );
                }
            }