public IAssignableExpression ToAssignableExpr(IVariableInitializer csExpr, IList <IStatement> body) { IAssignableExpression result = new UnknownExpression(); Execute.AndSupressExceptions( () => { var exprInit = csExpr as IExpressionInitializer; if (exprInit != null && exprInit.Value != null) { result = exprInit.Value.Accept(this, body) ?? new UnknownExpression(); } }); return(result); }
public ExpressionKind Eat([NotNull] ISnapshot snapshot, [NotNull] IVariableInitializer initializer) { if (snapshot == null) { throw new ArgumentNullException("snapshot"); } if (initializer == null) { throw new ArgumentNullException("initializer"); } if (initializer is IArrayInitializer) { foreach (IVariableInitializer variableInitializer in (initializer as IArrayInitializer).ElementInitializers) { ExpressionKind kind = Eat(snapshot, variableInitializer); // TODO : what if stubcandidate snapshot.Add(kind, variableInitializer); } // TODO : array of target? return(ExpressionKind.StubCandidate); } ICSharpExpression initialExpression = null; if (initializer is IExpressionInitializer) { initialExpression = (initializer as IExpressionInitializer).Value; } if (initializer is IUnsafeCodeFixedPointerInitializer) { initialExpression = (initializer as IUnsafeCodeFixedPointerInitializer).Value; } if (initializer is IUnsafeCodeStackAllocInitializer) { initialExpression = (initializer as IUnsafeCodeStackAllocInitializer).DimExpr; } return(EatResults(snapshot, initialExpression)); }
public static IVariableDeclaration CreateVariableDeclaration(ILocalSymbol variable, IVariableInitializer initializer, SemanticModel semanticModel, SyntaxNode syntax) { return(CreateVariableDeclaration(ImmutableArray.Create(variable), initializer, semanticModel, syntax)); }
public static VariableDeclaration CreateVariableDeclaration(ImmutableArray <ILocalSymbol> variables, IVariableInitializer initializer, SemanticModel semanticModel, SyntaxNode syntax) { return(new VariableDeclaration( variables, initializer, semanticModel, syntax, type: null, constantValue: default(Optional <object>), isImplicit: false)); // variable declaration is always explicit }
public IVariableInitializer SetInitial(IVariableInitializer param) { return(_fieldDeclaration.SetInitial(param)); }
public override void VisitVariableInitializer(IVariableInitializer operation) { base.VisitVariableInitializer(operation); }
public override IOperation VisitVariableInitializer(IVariableInitializer operation, object argument) { return(new VariableInitializer(Visit(operation.Value), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit)); }
public sealed override void Initialize(AnalysisContext context) { context.RegisterCompilationStartAction( (compilationContext) => { Dictionary <IFieldSymbol, HashSet <INamedTypeSymbol> > fieldsSourceTypes = new Dictionary <IFieldSymbol, HashSet <INamedTypeSymbol> >(); compilationContext.RegisterOperationBlockStartAction( (operationBlockContext) => { if (operationBlockContext.OwningSymbol is IMethodSymbol containingMethod) { Dictionary <ILocalSymbol, HashSet <INamedTypeSymbol> > localsSourceTypes = new Dictionary <ILocalSymbol, HashSet <INamedTypeSymbol> >(); // Track explicit assignments. operationBlockContext.RegisterOperationAction( (operationContext) => { if (operationContext.Operation is IAssignmentExpression assignment) { AssignTo(assignment.Target, localsSourceTypes, fieldsSourceTypes, assignment.Value); } else if (operationContext.Operation is IIncrementOrDecrementExpression increment) { SyntaxNode syntax = increment.Syntax; ITypeSymbol type = increment.Type; Optional <object> constantValue = new Optional <object>(1); bool isImplicit = increment.IsImplicit; var value = new LiteralExpression(operationContext.Compilation.GetSemanticModel(syntax.SyntaxTree), syntax, type, constantValue, isImplicit); AssignTo(increment.Target, localsSourceTypes, fieldsSourceTypes, value); } else { throw TestExceptionUtilities.UnexpectedValue(operationContext.Operation); } }, OperationKind.SimpleAssignmentExpression, OperationKind.CompoundAssignmentExpression, OperationKind.IncrementExpression); // Track arguments that match out or ref parameters. operationBlockContext.RegisterOperationAction( (operationContext) => { IInvocationExpression invocation = (IInvocationExpression)operationContext.Operation; foreach (IArgument argument in invocation.Arguments) { if (argument.Parameter.RefKind == RefKind.Out || argument.Parameter.RefKind == RefKind.Ref) { AssignTo(argument.Value, localsSourceTypes, fieldsSourceTypes, argument.Parameter.Type); } } }, OperationKind.InvocationExpression); // Track local variable initializations. operationBlockContext.RegisterOperationAction( (operationContext) => { IVariableInitializer initializer = (IVariableInitializer)operationContext.Operation; if (initializer.Parent is IVariableDeclaration variableDeclaration) { foreach (ILocalSymbol local in variableDeclaration.Variables) { AssignTo(local, local.Type, localsSourceTypes, initializer.Value); } } }, OperationKind.VariableInitializer); // Report locals that could have more specific types. operationBlockContext.RegisterOperationBlockEndAction( (operationBlockEndContext) => { foreach (ILocalSymbol local in localsSourceTypes.Keys) { if (HasMoreSpecificSourceType(local, local.Type, localsSourceTypes, out var mostSpecificSourceType)) { Report(operationBlockEndContext, local, mostSpecificSourceType, LocalCouldHaveMoreSpecificTypeDescriptor); } } }); } }); // Track field initializations. compilationContext.RegisterOperationAction( (operationContext) => { IFieldInitializer initializer = (IFieldInitializer)operationContext.Operation; foreach (IFieldSymbol initializedField in initializer.InitializedFields) { AssignTo(initializedField, initializedField.Type, fieldsSourceTypes, initializer.Value); } }, OperationKind.FieldInitializer); // Report fields that could have more specific types. compilationContext.RegisterCompilationEndAction( (compilationEndContext) => { foreach (IFieldSymbol field in fieldsSourceTypes.Keys) { if (HasMoreSpecificSourceType(field, field.Type, fieldsSourceTypes, out var mostSpecificSourceType)) { Report(compilationEndContext, field, mostSpecificSourceType, FieldCouldHaveMoreSpecificTypeDescriptor); } } }); }); }
public virtual void VisitVariableInitializer(IVariableInitializer operation) { DefaultVisit(operation); }