本文整理汇总了C#中DiagnosticBag.HasAnyErrors方法的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticBag.HasAnyErrors方法的具体用法?C# DiagnosticBag.HasAnyErrors怎么用?C# DiagnosticBag.HasAnyErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiagnosticBag
的用法示例。
在下文中一共展示了DiagnosticBag.HasAnyErrors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseAssignment
internal static ExpressionSyntax ParseAssignment(
this string target,
string expr,
DiagnosticBag diagnostics)
{
var text = SourceText.From(expr);
var expression = SyntaxHelpers.ParseDebuggerExpressionInternal(text, consumeFullText: true);
// We're creating a SyntaxTree for just the RHS so that the Diagnostic spans for parse errors
// will be correct (with respect to the original input text). If we ever expose a SemanticModel
// for debugger expressions, we should use this SyntaxTree.
var syntaxTree = expression.CreateSyntaxTree(text);
diagnostics.AddRange(syntaxTree.GetDiagnostics());
if (diagnostics.HasAnyErrors())
{
return null;
}
// Any Diagnostic spans produced in binding will be offset by the length of the "target" expression text.
// If we want to support live squiggles in debugger windows, SemanticModel, etc, we'll want to address this.
var targetSyntax = SyntaxHelpers.ParseDebuggerExpressionInternal(SourceText.From(target), consumeFullText: true);
Debug.Assert(!targetSyntax.GetDiagnostics().Any(), "The target of an assignment should never contain Diagnostics if we're being allowed to assign to it in the debugger.");
var assignment = InternalSyntax.SyntaxFactory.AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression,
targetSyntax,
InternalSyntax.SyntaxFactory.Token(SyntaxKind.EqualsToken),
expression);
return assignment.MakeDebuggerExpression(SourceText.From(assignment.ToString()));
}
示例2: ParseExpression
/// <summary>
/// Parse expression. Returns null if there are any errors.
/// </summary>
internal static ExpressionSyntax ParseExpression(
this string expr,
DiagnosticBag diagnostics,
bool allowFormatSpecifiers,
out ReadOnlyCollection<string> formatSpecifiers)
{
// Remove trailing semi-colon if any. This is to support copy/paste
// of (simple cases of) RHS of assignment in Watch window, not to
// allow arbitrary syntax after the semi-colon, not even comments.
if (RemoveSemicolonIfAny(ref expr))
{
// Format specifiers are not expected before a semi-colon.
allowFormatSpecifiers = false;
}
var syntax = ParseDebuggerExpression(expr, consumeFullText: !allowFormatSpecifiers);
diagnostics.AddRange(syntax.GetDiagnostics());
formatSpecifiers = null;
if (allowFormatSpecifiers)
{
var builder = ArrayBuilder<string>.GetInstance();
if (ParseFormatSpecifiers(builder, expr, syntax.FullWidth, diagnostics) &&
(builder.Count > 0))
{
formatSpecifiers = new ReadOnlyCollection<string>(builder.ToArray());
}
builder.Free();
}
return diagnostics.HasAnyErrors() ? null : syntax;
}
示例3: CreateCompilation
internal override CommonCompilation CreateCompilation(IText code, string path, bool isInteractive, Session session, Type returnType, DiagnosticBag diagnostics)
{
Compilation previousSubmission = (Compilation) session.LastSubmission;
IEnumerable<MetadataReference> referencesForCompilation = session.GetReferencesForCompilation();
ReadOnlyArray<string> namespacesForCompilation = session.GetNamespacesForCompilation();
ParseOptions options = isInteractive ? ScriptEngine.DefaultInteractive : ScriptEngine.DefaultScript;
SyntaxTree syntaxTree = SyntaxTree.ParseText(code, path, options, new CancellationToken());
diagnostics.Add((IEnumerable<CommonDiagnostic>) syntaxTree.GetDiagnostics(new CancellationToken()));
if (diagnostics.HasAnyErrors())
return (CommonCompilation) null;
string assemblyName;
string typeName;
this.GenerateSubmissionId(out assemblyName, out typeName);
Compilation submission = Compilation.CreateSubmission(assemblyName, new CompilationOptions(OutputKind.DynamicallyLinkedLibrary, (string) null, typeName, (IEnumerable<string>) namespacesForCompilation.ToList(), DebugInformationKind.None, false, true, false, true, (string) null, (string) null, new bool?(), 0, 0UL, Platform.AnyCPU, ReportWarning.Default, 4, (IReadOnlyDictionary<int, ReportWarning>) null, false, new SubsystemVersion()), syntaxTree, previousSubmission, referencesForCompilation, session.FileResolver, this.metadataFileProvider, returnType, session.HostObjectType);
this.ValidateReferences((CommonCompilation) submission, diagnostics);
if (diagnostics.HasAnyErrors())
return (CommonCompilation) null;
else
return (CommonCompilation) submission;
}
示例4: BindExpression
private static BoundStatement BindExpression(Binder binder, ExpressionSyntax syntax, DiagnosticBag diagnostics, out ResultProperties resultProperties)
{
var flags = DkmClrCompilationResultFlags.None;
// In addition to C# expressions, the native EE also supports
// type names which are bound to a representation of the type
// (but not System.Type) that the user can expand to see the
// base type. Instead, we only allow valid C# expressions.
var expression = binder.BindValue(syntax, diagnostics, Binder.BindValueKind.RValue);
if (diagnostics.HasAnyErrors())
{
resultProperties = default(ResultProperties);
return null;
}
try
{
if (MayHaveSideEffectsVisitor.MayHaveSideEffects(expression))
{
flags |= DkmClrCompilationResultFlags.PotentialSideEffect;
}
}
catch (BoundTreeVisitor.CancelledByStackGuardException ex)
{
ex.AddAnError(diagnostics);
resultProperties = default(ResultProperties);
return null;
}
var expressionType = expression.Type;
if ((object)expressionType == null)
{
expression = binder.CreateReturnConversion(
syntax,
diagnostics,
expression,
binder.Compilation.GetSpecialType(SpecialType.System_Object));
if (diagnostics.HasAnyErrors())
{
resultProperties = default(ResultProperties);
return null;
}
}
else if (expressionType.SpecialType == SpecialType.System_Void)
{
flags |= DkmClrCompilationResultFlags.ReadOnlyResult;
Debug.Assert(expression.ConstantValue == null);
resultProperties = expression.ExpressionSymbol.GetResultProperties(flags, isConstant: false);
return new BoundExpressionStatement(syntax, expression) { WasCompilerGenerated = true };
}
else if (expressionType.SpecialType == SpecialType.System_Boolean)
{
flags |= DkmClrCompilationResultFlags.BoolResult;
}
if (!IsAssignableExpression(binder, expression))
{
flags |= DkmClrCompilationResultFlags.ReadOnlyResult;
}
resultProperties = expression.ExpressionSymbol.GetResultProperties(flags, expression.ConstantValue != null);
return new BoundReturnStatement(syntax, expression) { WasCompilerGenerated = true };
}
示例5: CompileGetLocals
//.........这里部分代码省略.........
}
}
// "this" for non-static methods that are not display class methods or
// display class methods where the display class contains "<>4__this".
if (!m.IsStatic && (!IsDisplayClassType(m.ContainingType) || _displayClassVariables.ContainsKey(GeneratedNames.ThisProxyFieldName())))
{
var methodName = GetNextMethodName(methodBuilder);
var method = this.GetThisMethod(container, methodName);
localBuilder.Add(new CSharpLocalAndMethod("this", "this", method, DkmClrCompilationResultFlags.None)); // Note: writable in dev11.
methodBuilder.Add(method);
}
}
// Hoisted method parameters (represented as locals in the EE).
if (!_hoistedParameterNames.IsEmpty)
{
int localIndex = 0;
foreach (var local in _localsForBinding)
{
// Since we are showing hoisted method parameters first, the parameters may appear out of order
// in the Locals window if only some of the parameters are hoisted. This is consistent with the
// behavior of the old EE.
if (_hoistedParameterNames.Contains(local.Name))
{
AppendLocalAndMethod(localBuilder, methodBuilder, local, container, localIndex, GetLocalResultFlags(local));
}
localIndex++;
}
}
// Method parameters (except those that have been hoisted).
int parameterIndex = m.IsStatic ? 0 : 1;
foreach (var parameter in m.Parameters)
{
var parameterName = parameter.Name;
if (!_hoistedParameterNames.Contains(parameterName) && GeneratedNames.GetKind(parameterName) == GeneratedNameKind.None)
{
AppendParameterAndMethod(localBuilder, methodBuilder, parameter, container, parameterIndex);
}
parameterIndex++;
}
if (!argumentsOnly)
{
// Locals.
int localIndex = 0;
foreach (var local in _localsForBinding)
{
if (!_hoistedParameterNames.Contains(local.Name))
{
AppendLocalAndMethod(localBuilder, methodBuilder, local, container, localIndex, GetLocalResultFlags(local));
}
localIndex++;
}
// "Type variables".
if ((object)typeVariablesType != null)
{
var methodName = GetNextMethodName(methodBuilder);
var returnType = typeVariablesType.Construct(allTypeParameters.Cast<TypeParameterSymbol, TypeSymbol>());
var method = this.GetTypeVariablesMethod(container, methodName, returnType);
localBuilder.Add(new CSharpLocalAndMethod(
ExpressionCompilerConstants.TypeVariablesLocalName,
ExpressionCompilerConstants.TypeVariablesLocalName,
method,
DkmClrCompilationResultFlags.ReadOnlyResult));
methodBuilder.Add(method);
}
}
return methodBuilder.ToImmutableAndFree();
});
additionalTypes.Add(synthesizedType);
var module = CreateModuleBuilder(
this.Compilation,
synthesizedType.Methods,
additionalTypes: additionalTypes.ToImmutableAndFree(),
synthesizedType: synthesizedType,
testData: testData,
diagnostics: diagnostics);
Debug.Assert(module != null);
this.Compilation.Compile(
module,
win32Resources: null,
xmlDocStream: null,
emittingPdb: false,
diagnostics: diagnostics,
filterOpt: null,
cancellationToken: CancellationToken.None);
return diagnostics.HasAnyErrors() ? null : module;
}
示例6: CompileAssignment
internal CommonPEModuleBuilder CompileAssignment(
string typeName,
string methodName,
ImmutableArray<Alias> aliases,
Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData,
DiagnosticBag diagnostics,
out ResultProperties resultProperties)
{
var objectType = this.Compilation.GetSpecialType(SpecialType.System_Object);
var synthesizedType = new EENamedTypeSymbol(
Compilation.SourceModule.GlobalNamespace,
objectType,
_syntax,
_currentFrame,
typeName,
methodName,
this,
(method, diags) =>
{
var hasDisplayClassThis = _displayClassVariables.ContainsKey(GeneratedNames.ThisProxyFieldName());
var binder = ExtendBinderChain(
_syntax,
aliases,
method,
this.NamespaceBinder,
hasDisplayClassThis,
methodNotType: true);
return BindAssignment(binder, (ExpressionSyntax)_syntax, diags);
});
var module = CreateModuleBuilder(
this.Compilation,
synthesizedType.Methods,
additionalTypes: ImmutableArray.Create((NamedTypeSymbol)synthesizedType),
synthesizedType: synthesizedType,
testData: testData,
diagnostics: diagnostics);
Debug.Assert(module != null);
this.Compilation.Compile(
module,
win32Resources: null,
xmlDocStream: null,
emittingPdb: false,
diagnostics: diagnostics,
filterOpt: null,
cancellationToken: CancellationToken.None);
if (diagnostics.HasAnyErrors())
{
resultProperties = default(ResultProperties);
return null;
}
// Should be no name mangling since the caller provided explicit names.
Debug.Assert(synthesizedType.MetadataName == typeName);
Debug.Assert(synthesizedType.GetMembers()[0].MetadataName == methodName);
resultProperties = new ResultProperties(DkmClrCompilationResultFlags.PotentialSideEffect);
return module;
}
示例7: CreateCompilation
internal override CommonCompilation CreateCompilation(IText code, string path, bool isInteractive, Session session, Type returnType, DiagnosticBag diagnostics)
{
Debug.Assert(code != null && path != null && diagnostics != null);
Compilation previousSubmission = (session != null) ? (Compilation)session.LastSubmission : null;
IEnumerable<MetadataReference> references = GetReferences(session);
ReadOnlyArray<string> usings = GetImportedNamespaces(session);
// TODO (tomat): BaseDirectory should be a property on ScriptEngine?
var fileResolver = Session.GetFileResolver(session, Directory.GetCurrentDirectory());
// parse:
var parseOptions = isInteractive ? DefaultInteractive : DefaultScript;
var tree = SyntaxTree.ParseText(code, path, parseOptions);
diagnostics.Add(tree.GetDiagnostics());
if (diagnostics.HasAnyErrors())
{
return null;
}
// create compilation:
string assemblyName, submissionTypeName;
GenerateSubmissionId(out assemblyName, out submissionTypeName);
var compilation = Compilation.CreateSubmission(
assemblyName,
new CompilationOptions(
outputKind: OutputKind.DynamicallyLinkedLibrary,
mainTypeName: null,
scriptClassName: submissionTypeName,
usings: usings.ToList(),
optimize: false, // TODO (tomat)
checkOverflow: true, // TODO (tomat)
allowUnsafe: false, // TODO (tomat)
cryptoKeyContainer: null,
cryptoKeyFile: null,
delaySign: null,
fileAlignment: 0,
baseAddress: 0L,
platform: Platform.AnyCPU,
generalWarningOption: ReportWarning.Default,
warningLevel: 4,
specificWarningOptions: null,
highEntropyVirtualAddressSpace: false
),
tree,
previousSubmission,
references,
fileResolver,
this.metadataFileProvider,
returnType,
(session != null) ? session.HostObjectType : null
);
ValidateReferences(compilation, diagnostics);
if (diagnostics.HasAnyErrors())
{
return null;
}
return compilation;
}
示例8: CompileGetLocals
internal override ReadOnlyCollection<byte> CompileGetLocals(
ReadOnlyCollection<Alias> aliases,
ArrayBuilder<LocalAndMethod> locals,
bool argumentsOnly,
DiagnosticBag diagnostics,
out string typeName,
Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
{
var context = this.CreateCompilationContext(null);
var moduleBuilder = context.CompileGetLocals(aliases, TypeName, locals, argumentsOnly, testData, diagnostics);
ReadOnlyCollection<byte> assembly = null;
if ((moduleBuilder != null) && (locals.Count > 0))
{
using (var stream = new MemoryStream())
{
Cci.PeWriter.WritePeToStream(
new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics),
context.MessageProvider,
() => stream,
nativePdbWriterOpt: null,
pdbPathOpt: null,
allowMissingMethodBodies: false,
deterministic: false,
cancellationToken: default(CancellationToken));
if (!diagnostics.HasAnyErrors())
{
assembly = new ReadOnlyCollection<byte>(stream.ToArray());
}
}
}
if (assembly == null)
{
locals.Clear();
assembly = s_emptyBytes;
}
typeName = TypeName;
return assembly;
}
示例9: Parse
private static CSharpSyntaxNode Parse(
string expr,
bool treatAsExpression,
DiagnosticBag diagnostics,
out ReadOnlyCollection<string> formatSpecifiers)
{
if (treatAsExpression)
{
return expr.ParseExpression(diagnostics, allowFormatSpecifiers: true, formatSpecifiers: out formatSpecifiers);
}
else
{
// Try to parse as an expression. If that fails, parse as a statement.
var exprDiagnostics = DiagnosticBag.GetInstance();
ReadOnlyCollection<string> exprFormatSpecifiers;
CSharpSyntaxNode syntax = expr.ParseExpression(exprDiagnostics, allowFormatSpecifiers: true, formatSpecifiers: out exprFormatSpecifiers);
Debug.Assert((syntax == null) || !exprDiagnostics.HasAnyErrors());
exprDiagnostics.Free();
if (syntax != null)
{
Debug.Assert(!diagnostics.HasAnyErrors());
formatSpecifiers = exprFormatSpecifiers;
return syntax;
}
formatSpecifiers = null;
syntax = expr.ParseStatement(diagnostics);
if ((syntax != null) && (syntax.Kind() != SyntaxKind.LocalDeclarationStatement))
{
diagnostics.Add(ErrorCode.ERR_ExpressionOrDeclarationExpected, Location.None);
return null;
}
return syntax;
}
}
示例10: GenerateMethodBody
internal static MethodBody GenerateMethodBody(TypeCompilationState compilationState, MethodSymbol method, BoundStatement block, DiagnosticBag diagnostics,
bool optimize, DebugDocumentProvider debugDocumentProvider, ImmutableArray<NamespaceScope> namespaceScopes)
{
// Note: don't call diagnostics.HasAnyErrors() in release; could be expensive if compilation has many warnings.
Debug.Assert(!diagnostics.HasAnyErrors(), "Running code generator when errors exist might be dangerous; code generator not well hardened");
bool emitSequencePoints = !namespaceScopes.IsDefault && !method.IsAsync;
var module = compilationState.ModuleBuilder;
var compilation = module.Compilation;
var localSlotManager = module.CreateLocalSlotManager(method);
ILBuilder builder = new ILBuilder(module, localSlotManager, optimize);
DiagnosticBag diagnosticsForThisMethod = DiagnosticBag.GetInstance();
try
{
AsyncMethodBodyDebugInfo asyncDebugInfo = null;
if ((object)method.AsyncKickoffMethod == null) // is this the MoveNext of an async method?
{
CodeGen.CodeGenerator.Run(
method, block, builder, module, diagnosticsForThisMethod, optimize, emitSequencePoints);
}
else
{
int asyncCatchHandlerOffset;
ImmutableArray<int> asyncYieldPoints;
ImmutableArray<int> asyncResumePoints;
CodeGen.CodeGenerator.Run(
method, block, builder, module, diagnosticsForThisMethod, optimize, emitSequencePoints,
out asyncCatchHandlerOffset, out asyncYieldPoints, out asyncResumePoints);
asyncDebugInfo = new AsyncMethodBodyDebugInfo(method.AsyncKickoffMethod, asyncCatchHandlerOffset, asyncYieldPoints, asyncResumePoints);
}
var localVariables = builder.LocalSlotManager.LocalsInOrder();
if (localVariables.Length > 0xFFFE)
{
diagnosticsForThisMethod.Add(ErrorCode.ERR_TooManyLocals, method.Locations.First());
}
if (diagnosticsForThisMethod.HasAnyErrors())
{
// we are done here. Since there were errors we should not emit anything.
return null;
}
// We will only save the IL builders when running tests.
if (module.SaveTestData)
{
module.SetMethodTestData(method, builder.GetSnapshot());
}
// Only compiler-generated MoveNext methods have iterator scopes. See if this is one.
bool hasIteratorScopes =
method.Locations.IsEmpty && method.Name == "MoveNext" &&
(method.ExplicitInterfaceImplementations.Contains(compilation.GetSpecialTypeMember(SpecialMember.System_Collections_IEnumerator__MoveNext) as MethodSymbol) ||
method.ExplicitInterfaceImplementations.Contains(compilation.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_IAsyncStateMachine_MoveNext) as MethodSymbol));
var iteratorScopes = hasIteratorScopes ? builder.GetIteratorScopes() : ImmutableArray<LocalScope>.Empty;
var iteratorOrAsyncImplementation = compilationState.GetIteratorOrAsyncImplementationClass(method);
return new MethodBody(
builder.RealizedIL,
builder.MaxStack,
method,
localVariables,
builder.RealizedSequencePoints,
debugDocumentProvider,
builder.RealizedExceptionHandlers,
builder.GetAllScopes(),
Microsoft.Cci.CustomDebugInfoKind.CSharpStyle,
builder.HasDynamicLocal,
namespaceScopes,
(object)iteratorOrAsyncImplementation == null ? null : iteratorOrAsyncImplementation.MetadataName,
iteratorScopes,
asyncMethodDebugInfo: asyncDebugInfo
);
}
finally
{
// Basic blocks contain poolable builders for IL and sequence points. Free those back
// to their pools.
builder.FreeBasicBlocks();
// Remember diagnostics.
diagnostics.AddRange(diagnosticsForThisMethod);
diagnosticsForThisMethod.Free();
}
}
示例11: GenerateMethodBody
internal override void GenerateMethodBody(TypeCompilationState compilationState, DiagnosticBag diagnostics)
{
var body = _generateMethodBody(this, diagnostics);
var compilation = compilationState.Compilation;
_lazyReturnType = CalculateReturnType(compilation, body);
// Can't do this until the return type has been computed.
TypeParameterChecker.Check(this, _allTypeParameters);
if (diagnostics.HasAnyErrors())
{
return;
}
DiagnosticsPass.IssueDiagnostics(compilation, body, diagnostics, this);
if (diagnostics.HasAnyErrors())
{
return;
}
// Check for use-site diagnostics (e.g. missing types in the signature).
DiagnosticInfo useSiteDiagnosticInfo = null;
this.CalculateUseSiteDiagnostic(ref useSiteDiagnosticInfo);
if (useSiteDiagnosticInfo != null && useSiteDiagnosticInfo.Severity == DiagnosticSeverity.Error)
{
diagnostics.Add(useSiteDiagnosticInfo, this.Locations[0]);
return;
}
var declaredLocals = PooledHashSet<LocalSymbol>.GetInstance();
try
{
// Rewrite local declaration statement.
body = (BoundStatement)LocalDeclarationRewriter.Rewrite(compilation, _container, declaredLocals, body);
// Verify local declaration names.
foreach (var local in declaredLocals)
{
Debug.Assert(local.Locations.Length > 0);
var name = local.Name;
if (name.StartsWith("$", StringComparison.Ordinal))
{
diagnostics.Add(ErrorCode.ERR_UnexpectedCharacter, local.Locations[0], name[0]);
return;
}
}
// Rewrite references to placeholder "locals".
body = (BoundStatement)PlaceholderLocalRewriter.Rewrite(compilation, _container, declaredLocals, body);
}
finally
{
declaredLocals.Free();
}
var syntax = body.Syntax;
var statementsBuilder = ArrayBuilder<BoundStatement>.GetInstance();
statementsBuilder.Add(body);
// Insert an implicit return statement if necessary.
if (body.Kind != BoundKind.ReturnStatement)
{
statementsBuilder.Add(new BoundReturnStatement(syntax, expressionOpt: null));
}
var localsBuilder = ArrayBuilder<LocalSymbol>.GetInstance();
var localsSet = PooledHashSet<LocalSymbol>.GetInstance();
foreach (var local in this.LocalsForBinding)
{
Debug.Assert(!localsSet.Contains(local));
localsBuilder.Add(local);
localsSet.Add(local);
}
foreach (var local in this.Locals)
{
if (!localsSet.Contains(local))
{
localsBuilder.Add(local);
}
}
localsSet.Free();
body = new BoundBlock(syntax, localsBuilder.ToImmutableAndFree(), statementsBuilder.ToImmutableAndFree()) { WasCompilerGenerated = true };
Debug.Assert(!diagnostics.HasAnyErrors());
Debug.Assert(!body.HasErrors);
bool sawLambdas;
bool sawAwaitInExceptionHandler;
body = LocalRewriter.Rewrite(
compilation: this.DeclaringCompilation,
method: this,
methodOrdinal: _methodOrdinal,
containingType: _container,
statement: body,
compilationState: compilationState,
previousSubmissionFields: null,
allowOmissionOfConditionalCalls: false,
diagnostics: diagnostics,
sawLambdas: out sawLambdas,
//.........这里部分代码省略.........
示例12: BindAssignment
private static BoundStatement BindAssignment(Binder binder, ExpressionSyntax syntax, DiagnosticBag diagnostics)
{
binder = binder.GetBinder(syntax);
Debug.Assert(binder != null);
var expression = binder.BindValue(syntax, diagnostics, Binder.BindValueKind.RValue);
if (diagnostics.HasAnyErrors())
{
return null;
}
return binder.WrapWithVariablesIfAny(syntax,
new BoundExpressionStatement(expression.Syntax, expression) { WasCompilerGenerated = true });
}
示例13: CompileExpression
internal CommonPEModuleBuilder CompileExpression(
InspectionContext inspectionContext,
string typeName,
string methodName,
Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData,
DiagnosticBag diagnostics,
out ResultProperties resultProperties)
{
Debug.Assert(inspectionContext != null);
var properties = default(ResultProperties);
var objectType = this.Compilation.GetSpecialType(SpecialType.System_Object);
var synthesizedType = new EENamedTypeSymbol(
this.Compilation.SourceModule.GlobalNamespace,
objectType,
_syntax,
_currentFrame,
typeName,
methodName,
this,
(method, diags) =>
{
var hasDisplayClassThis = _displayClassVariables.ContainsKey(GeneratedNames.ThisProxyFieldName());
var binder = ExtendBinderChain(
inspectionContext,
this.Compilation,
_metadataDecoder,
_syntax,
method,
this.NamespaceBinder,
hasDisplayClassThis,
_methodNotType);
var statementSyntax = _syntax as StatementSyntax;
return (statementSyntax == null) ?
BindExpression(binder, (ExpressionSyntax)_syntax, diags, out properties) :
BindStatement(binder, statementSyntax, diags, out properties);
});
var module = CreateModuleBuilder(
this.Compilation,
synthesizedType.Methods,
additionalTypes: ImmutableArray.Create((NamedTypeSymbol)synthesizedType),
testData: testData,
diagnostics: diagnostics);
Debug.Assert(module != null);
this.Compilation.Compile(
module,
win32Resources: null,
xmlDocStream: null,
generateDebugInfo: false,
diagnostics: diagnostics,
filterOpt: null,
cancellationToken: CancellationToken.None);
if (diagnostics.HasAnyErrors())
{
resultProperties = default(ResultProperties);
return null;
}
// Should be no name mangling since the caller provided explicit names.
Debug.Assert(synthesizedType.MetadataName == typeName);
Debug.Assert(synthesizedType.GetMembers()[0].MetadataName == methodName);
resultProperties = properties;
return module;
}
示例14: CompileGetLocals
//.........这里部分代码省略.........
_syntax,
_currentFrame,
typeName,
(m, container) =>
{
var methodBuilder = ArrayBuilder<MethodSymbol>.GetInstance();
if (!argumentsOnly)
{
// "this" for non-static methods that are not display class methods or
// display class methods where the display class contains "<>4__this".
if (!m.IsStatic && (!IsDisplayClassType(m.ContainingType) || _displayClassVariables.ContainsKey(GeneratedNames.ThisProxyFieldName())))
{
var methodName = GetNextMethodName(methodBuilder);
var method = this.GetThisMethod(container, methodName);
localBuilder.Add(new LocalAndMethod("this", methodName, DkmClrCompilationResultFlags.None)); // Note: writable in dev11.
methodBuilder.Add(method);
}
}
// Hoisted method parameters (represented as locals in the EE).
int ordinal = 0;
if (!_hoistedParameterNames.IsEmpty)
{
foreach (var local in _localsForBinding)
{
// Since we are showing hoisted method parameters first, the parameters may appear out of order
// in the Locals window if only some of the parameters are hoisted. This is consistent with the
// behavior of the old EE.
var localName = local.Name;
if (_hoistedParameterNames.Contains(local.Name))
{
AppendLocalAndMethod(localBuilder, methodBuilder, localName, this.GetLocalMethod, container, ordinal, GetLocalResultFlags(local));
}
ordinal++;
}
}
// Method parameters (except those that have been hoisted).
ordinal = m.IsStatic ? 0 : 1;
foreach (var parameter in m.Parameters)
{
var parameterName = parameter.Name;
if (!_hoistedParameterNames.Contains(parameterName))
{
AppendLocalAndMethod(localBuilder, methodBuilder, parameterName, this.GetParameterMethod, container, ordinal, DkmClrCompilationResultFlags.None);
}
ordinal++;
}
if (!argumentsOnly)
{
// Locals.
ordinal = 0;
foreach (var local in _localsForBinding)
{
var localName = local.Name;
if (!_hoistedParameterNames.Contains(localName))
{
AppendLocalAndMethod(localBuilder, methodBuilder, localName, this.GetLocalMethod, container, ordinal, GetLocalResultFlags(local));
}
ordinal++;
}
// "Type variables".
if ((object)typeVariablesType != null)
{
var methodName = GetNextMethodName(methodBuilder);
var returnType = typeVariablesType.Construct(allTypeParameters.Cast<TypeParameterSymbol, TypeSymbol>());
var method = this.GetTypeVariablesMethod(container, methodName, returnType);
localBuilder.Add(new LocalAndMethod(ExpressionCompilerConstants.TypeVariablesLocalName, methodName, DkmClrCompilationResultFlags.ReadOnlyResult));
methodBuilder.Add(method);
}
}
return methodBuilder.ToImmutableAndFree();
});
additionalTypes.Add(synthesizedType);
var module = CreateModuleBuilder(
this.Compilation,
synthesizedType.Methods,
additionalTypes: additionalTypes.ToImmutableAndFree(),
testData: testData,
diagnostics: diagnostics);
Debug.Assert(module != null);
this.Compilation.Compile(
module,
win32Resources: null,
xmlDocStream: null,
generateDebugInfo: false,
diagnostics: diagnostics,
filterOpt: null,
cancellationToken: CancellationToken.None);
return diagnostics.HasAnyErrors() ? null : module;
}
示例15: BindAssignment
private static BoundStatement BindAssignment(Binder binder, ExpressionSyntax syntax, DiagnosticBag diagnostics)
{
var expression = binder.BindValue(syntax, diagnostics, Binder.BindValueKind.RValue);
if (diagnostics.HasAnyErrors())
{
return null;
}
return new BoundExpressionStatement(expression.Syntax, expression) { WasCompilerGenerated = true };
}