internal static CompileResult CompileAssignment(
            this EvaluationContextBase context,
            InspectionContext inspectionContext,
            string target,
            string expr,
            DiagnosticFormatter formatter,
            out ResultProperties resultProperties,
            out string error,
            out ImmutableArray <AssemblyIdentity> missingAssemblyIdentities,
            CultureInfo preferredUICulture,
            CompilationTestData testData)
        {
            var diagnostics = DiagnosticBag.GetInstance();
            var result      = context.CompileAssignment(inspectionContext, target, expr, diagnostics, out resultProperties, testData);

            if (diagnostics.HasAnyErrors())
            {
                bool useReferencedModulesOnly;
                error = context.GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out useReferencedModulesOnly, out missingAssemblyIdentities);
            }
            else
            {
                error = null;
                missingAssemblyIdentities = ImmutableArray <AssemblyIdentity> .Empty;
            }
            diagnostics.Free();
            return(result);
        }
Example #2
0
        /// <summary>
        /// Compile C# expression and emit assembly with evaluation method.
        /// </summary>
        /// <returns>
        /// Result containing generated assembly, type and method names, and any format specifiers.
        /// </returns>
        static internal CompileResult CompileExpression(
            this EvaluationContextBase evaluationContext,
            string expr,
            DkmEvaluationFlags compilationFlags,
            ImmutableArray <Alias> aliases,
            DiagnosticFormatter formatter,
            out ResultProperties resultProperties,
            out string error,
            out ImmutableArray <AssemblyIdentity> missingAssemblyIdentities,
            CultureInfo preferredUICulture,
            CompilationTestData testData)
        {
            var diagnostics = DiagnosticBag.GetInstance();
            var result      = evaluationContext.CompileExpression(expr, compilationFlags, aliases, diagnostics, out resultProperties, testData);

            if (diagnostics.HasAnyErrors())
            {
                bool useReferencedModulesOnly;
                error = evaluationContext.GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out useReferencedModulesOnly, out missingAssemblyIdentities);
            }
            else
            {
                error = null;
                missingAssemblyIdentities = ImmutableArray <AssemblyIdentity> .Empty;
            }
            diagnostics.Free();
            return(result);
        }
Example #3
0
        static internal CompileResult CompileExpression(
            this EvaluationContextBase evaluationContext,
            string expr,
            DkmEvaluationFlags compilationFlags,
            ImmutableArray <Alias> aliases,
            out string error,
            CompilationTestData testData  = null,
            DiagnosticFormatter formatter = null)
        {
            ResultProperties resultProperties;
            ImmutableArray <AssemblyIdentity> missingAssemblyIdentities;
            var result = evaluationContext.CompileExpression(
                expr,
                compilationFlags,
                aliases,
                formatter ?? DiagnosticFormatter.Instance,
                out resultProperties,
                out error,
                out missingAssemblyIdentities,
                EnsureEnglishUICulture.PreferredOrNull,
                testData);

            Assert.Empty(missingAssemblyIdentities);
            return(result);
        }
Example #4
0
        internal static CompileResult CompileExpression(
            this EvaluationContextBase context,
            string expr,
            out string error,
            CompilationTestData testData  = null,
            DiagnosticFormatter formatter = null)
        {
            ResultProperties resultProperties;

            return(CompileExpression(context, expr, out resultProperties, out error, testData, formatter));
        }
        internal static ReadOnlyCollection <byte> CompileGetLocals(
            this EvaluationContextBase context,
            ArrayBuilder <LocalAndMethod> locals,
            bool argumentsOnly,
            out string typeName,
            CompilationTestData testData)
        {
            var diagnostics = DiagnosticBag.GetInstance();
            var result      = context.CompileGetLocals(locals, argumentsOnly, diagnostics, out typeName, testData);

            diagnostics.Free();
            return(result);
        }
 internal static CompileResult CompileExpressionWithRetry(
     ImmutableArray <MetadataBlock> metadataBlocks,
     EvaluationContextBase context,
     ExpressionCompiler.CompileDelegate <CompileResult> compile,
     DkmUtilities.GetMetadataBytesPtrFunction getMetaDataBytesPtr,
     out string errorMessage)
 {
     return(ExpressionCompiler.CompileWithRetry(
                metadataBlocks,
                DiagnosticFormatter.Instance,
                (blocks, useReferencedModulesOnly) => context,
                compile,
                getMetaDataBytesPtr,
                out errorMessage));
 }
        internal static ReadOnlyCollection <byte> CompileGetLocals(
            this EvaluationContextBase context,
            ArrayBuilder <LocalAndMethod> locals,
            bool argumentsOnly,
            out string typeName,
            CompilationTestData testData,
            DiagnosticDescription[] expectedDiagnostics = null)
        {
            var diagnostics = DiagnosticBag.GetInstance();
            var result      = context.CompileGetLocals(
                argumentsOnly ? null : s_NoAliases,
                locals,
                argumentsOnly,
                diagnostics,
                out typeName,
                testData);

            diagnostics.Verify(expectedDiagnostics ?? DiagnosticDescription.None);
            diagnostics.Free();
            return(result);
        }
Example #8
0
        internal static CompileResult CompileExpression(
            this EvaluationContextBase context,
            string expr,
            out ResultProperties resultProperties,
            out string error,
            CompilationTestData testData  = null,
            DiagnosticFormatter formatter = null)
        {
            ImmutableArray <AssemblyIdentity> missingAssemblyIdentities;
            var result = context.CompileExpression(
                DefaultInspectionContext.Instance,
                expr,
                DkmEvaluationFlags.TreatAsExpression,
                formatter ?? DiagnosticFormatter.Instance,
                out resultProperties,
                out error,
                out missingAssemblyIdentities,
                EnsureEnglishUICulture.PreferredOrNull,
                testData);

            Assert.Empty(missingAssemblyIdentities);
            return(result);
        }
Example #9
0
        internal static CompileResult CompileAssignment(
            this EvaluationContextBase context,
            string target,
            string expr,
            out string error,
            CompilationTestData testData  = null,
            DiagnosticFormatter formatter = null)
        {
            ResultProperties resultProperties;
            ImmutableArray <AssemblyIdentity> missingAssemblyIdentities;
            var result = context.CompileAssignment(
                target,
                expr,
                ImmutableArray <Alias> .Empty,
                formatter ?? DiagnosticFormatter.Instance,
                out resultProperties,
                out error,
                out missingAssemblyIdentities,
                EnsureEnglishUICulture.PreferredOrNull,
                testData);

            Assert.Empty(missingAssemblyIdentities);
            // This is a crude way to test the language, but it's convenient to share this test helper.
            var isCSharp      = context.GetType().Namespace.IndexOf("csharp", StringComparison.OrdinalIgnoreCase) >= 0;
            var expectedFlags = error != null
                ? DkmClrCompilationResultFlags.None
                : isCSharp
                    ? DkmClrCompilationResultFlags.PotentialSideEffect
                    : DkmClrCompilationResultFlags.PotentialSideEffect | DkmClrCompilationResultFlags.ReadOnlyResult;

            Assert.Equal(expectedFlags, resultProperties.Flags);
            Assert.Equal(default(DkmEvaluationResultCategory), resultProperties.Category);
            Assert.Equal(default(DkmEvaluationResultAccessType), resultProperties.AccessType);
            Assert.Equal(default(DkmEvaluationResultStorageType), resultProperties.StorageType);
            Assert.Equal(default(DkmEvaluationResultTypeModifierFlags), resultProperties.ModifierFlags);
            return(result);
        }