コード例 #1
0
        protected override void generate(EmitterBase emitter)
        {
            var namespaces = _declaringAssembly.GetNamespaces(_compositionAttribute.Element as CodeElement);


            var initializerMethodInfo = new TypeMethodInfo(_compositionPoint.DeclaringType, ParsingActivation.InlineMethodName,
                                                           TypeDescriptor.Void, ParameterTypeInfo.NoParams, false, TypeDescriptor.NoDescriptors);

            var code = new StringBuilder();

            code.AppendLine("{");
            for (var i = 0; i < _compositionPoint.Parameters.Length; ++i)
            {
                var parameter = _compositionPoint.Parameters[i];
                var argument  = _compositionAttribute.GetArgument(i);

                if (argument == null)
                {
                    argument = "null";
                }

                code.AppendLine(" var arg" + i + " = " + argument + ";");
            }
            code.AppendLine("}");

            var activation = new ParsingActivation(code.ToString(), initializerMethodInfo, new string[0], namespaces);

            _declaringAssembly.ParsingProvider(activation, emitter);
        }
コード例 #2
0
        /// <summary>
        /// Build <see cref="MethodItem" /> from given <see cref="CodeFunction" />.
        /// </summary>
        /// <param name="element">Method definition element.</param>
        /// <returns>Built method.</returns>
        public MethodItem BuildFrom(CodeFunction element)
        {
            var sourceCode = element.MustImplement ? null : GetSourceCode(element);
            var isCtor     = MethodInfo.MethodName == Naming.CtorName;

            if (isCtor)
            {
                //ctor can have precode
                sourceCode = GetPreCode(element) + sourceCode;
            }

            var namespaces = DeclaringAssembly.GetNamespaces(element as CodeElement);

            //get generic parameters info
            var fullname    = element.FullName;
            var genericPath = new PathInfo(fullname);

            var activation = new ParsingActivation(sourceCode, MethodInfo, genericPath.GenericArgs, namespaces);

            RegisterActivation(activation, element as CodeElement);

            var generator = new SourceMethodGenerator(activation, DeclaringAssembly.ParsingProvider);
            var item      = new MethodItem(generator, MethodInfo);

            return(item);
        }
コード例 #3
0
ファイル: CSharpAssembly.cs プロジェクト: m9ra/MEFEditor_v2.0
        /// <inheritdoc />
        public override void ParsingProvider(ParsingActivation activation, EmitterBase emitter)
        {
            var w = Stopwatch.StartNew();

            var source = Compiler.GenerateInstructions(activation, emitter, TypeServices);

            var methodID = activation.Method == null ? new MethodID("$inline", false) : activation.Method.MethodID;

            VS.Log.Message("Parsing time for {0} {1}ms", methodID, w.ElapsedMilliseconds);
        }
コード例 #4
0
        /// <summary>
        /// Build implicit ctor or initializer method from given source.
        /// </summary>
        /// <param name="element">Element which method is built.</param>
        /// <param name="sourceCode">Code of method.</param>
        /// <returns>Built method.</returns>
        private MethodItem buildFromSource(CodeClass2 element, string sourceCode)
        {
            var namespaces = DeclaringAssembly.GetNamespaces(element as CodeElement);

            var activation = new ParsingActivation(sourceCode, MethodInfo, new string[0], namespaces);

            RegisterActivation(activation, element as CodeElement);
            var generator = new SourceMethodGenerator(activation, DeclaringAssembly.ParsingProvider);

            return(new MethodItem(generator, MethodInfo));
        }
コード例 #5
0
        /// <summary>
        /// Register handlers on activation for purposes of binding with source.
        /// </summary>
        /// <param name="activation">Activation which bindings will be registered.</param>
        /// <param name="element">Element where bindings will be applied.</param>
        protected void RegisterActivation(ParsingActivation activation, CodeElement element)
        {
            var fn = element as CodeFunction;

            if (fn != null)
            {
                activation.SourceChangeCommited += (source, ns) => { Write(fn, source, ns); }
            }
            ;
            activation.NavigationRequested += (offset) => Navigate(element, offset);
        }
コード例 #6
0
        /// <inheritdoc />
        public MethodItem Make(PathInfo methodPath, TypeMethodInfo methodDefinition)
        {
            var specializedMethod = Activation.Method.MakeGenericMethod(methodPath);

            var activation = new ParsingActivation(Activation.SourceCode, specializedMethod, Activation.GenericParameters, Activation.Namespaces);

            activation.NavigationRequested  += Activation.OnNavigated;
            activation.SourceChangeCommited += Activation.OnCommited;

            var specializedGenerator = new SourceMethodGenerator(activation, _parsingProvider);

            return(new MethodItem(specializedGenerator, specializedMethod));
        }
コード例 #7
0
        /// <summary>
        /// Initialize <see cref="SourceMethodGenerator"/> object from given activation.
        /// </summary>
        /// <param name="activation">Activation of parser for generated method</param>
        /// <param name="parsingProvider">Provider of parsing service for method</param>
        internal SourceMethodGenerator(ParsingActivation activation, ParsingProvider parsingProvider)
        {
            if (parsingProvider == null)
            {
                throw new ArgumentNullException("parsingProvider");
            }

            if (activation == null)
            {
                throw new ArgumentNullException("activation");
            }

            _parsingProvider = parsingProvider;
            Activation       = activation;
        }
コード例 #8
0
        protected override void generate(EmitterBase emitter)
        {
            var activation = new ParsingActivation(SourceCode, Method, _genericParameters);

            Source = Compiler.GenerateInstructions(activation, emitter, _services);
        }