public override void VisitVariableDeclarator([NotNull] IVariableDeclaratorOperation operation) { if (local.Equals(operation.Symbol) && operation.Initializer != null) { TrySetEvent(operation.Initializer.Value); } base.VisitVariableDeclarator(operation); }
public override void VisitVariableDeclarator([NotNull] IVariableDeclaratorOperation operation) { if (operation.Initializer != null) { IdentifiersAssigned.Add(operation.Symbol.Name); } base.VisitVariableDeclarator(operation); }
/// <summary> /// Gets the variable initializer for the given <paramref name="declarationOperation"/>, checking to see if there is a parent initializer /// if the single variable initializer is null. /// </summary> /// <param name="declarationOperation">Single variable declaration to retrieve initializer for.</param> public static IVariableInitializerOperation GetVariableInitializer(this IVariableDeclaratorOperation declarationOperation) { if (declarationOperation == null) { throw new ArgumentNullException(nameof(declarationOperation)); } return(declarationOperation.Initializer ?? (declarationOperation.Parent as IVariableDeclarationOperation)?.Initializer); }
public override void VisitVariableDeclarator([NotNull] IVariableDeclaratorOperation operation) { base.VisitVariableDeclarator(operation); if (currentLocal.Equals(operation.Symbol) && operation.Initializer != null) { AnalyzeAssignmentValue(operation.Initializer.Value); } }
/// <summary> /// コンストラクタ /// </summary> /// <param name="operation">IOperationインスタンス</param> /// <param name="container">イベントコンテナ</param> public VariableDeclarator(IVariableDeclaratorOperation operation, EventContainer container) : base(container) { Expressions.Add(new Expression(operation.Symbol.Name, Expression.GetSymbolTypeName(operation.Symbol))); if (!(operation.Initializer is null)) { Expressions.Add(new Expression("=", string.Empty)); Expressions.AddRange(OperationFactory.GetExpressionList(operation.Initializer.Value, container)); } }
public override void VisitVariableDeclarator([NotNull] IVariableDeclaratorOperation operation) { base.VisitVariableDeclarator(operation); if (currentLocal.Equals(operation.Symbol) && EndsBeforeMaxLocation(operation)) { IVariableInitializerOperation initializer = operation.GetVariableInitializer(); if (initializer != null) { AnalyzeAssignmentValue(initializer.Value); } } }
public override void VisitVariableDeclarator([NotNull] IVariableDeclaratorOperation operation) { if (local.Equals(operation.Symbol)) { IVariableInitializerOperation initializer = operation.GetVariableInitializer(); if (initializer != null) { TrySetEvent(initializer.Value); } } base.VisitVariableDeclarator(operation); }
public override void VisitVariableDeclarator(IVariableDeclaratorOperation operation) { Assert.Equal(OperationKind.VariableDeclarator, operation.Kind); Assert.NotNull(operation.Symbol); IEnumerable <IOperation> children = operation.IgnoredArguments; var initializer = operation.Initializer; if (initializer != null) { children = children.Concat(new[] { initializer }); } AssertEx.Equal(children, operation.Children); }
public override TAbstractAnalysisValue VisitVariableDeclarator(IVariableDeclaratorOperation operation, object argument) { var value = base.VisitVariableDeclarator(operation, argument); // Handle variable declarations without initializer (IVariableInitializerOperation). var initializer = operation.GetVariableInitializer(); if (initializer == null) { value = ValueDomain.Bottom; SetAbstractValue(operation.Symbol, value); } return(value); }
public override TAbstractAnalysisValue VisitVariableDeclarator(IVariableDeclaratorOperation operation, object argument) { var value = base.VisitVariableDeclarator(operation, argument); // Handle variable declarations without initializer (IVariableInitializerOperation). var initializer = operation.GetVariableInitializer(); if (initializer == null) { value = ValueDomain.Bottom; if (AnalysisEntityFactory.TryCreateForSymbolDeclaration(operation.Symbol, out AnalysisEntity analysisEntity)) { SetAbstractValue(analysisEntity, value); } } return(value); }
private LocalFunctionStatementSyntax CreateLocalFunction(IAnonymousFunctionOperation operation, IVariableDeclaratorOperation variableDeclaratorOperation, ParameterListSyntax param, BlockSyntax block, ArrowExpressionClauseSyntax arrow) { string symbolName = variableDeclaratorOperation.Symbol.Name; LocalFunctionStatementSyntax localFunc = SyntaxFactory.LocalFunctionStatement( SyntaxFactory.TokenList(), CommonConversions.GetTypeSyntax(operation.Symbol.ReturnType), SyntaxFactory.Identifier(symbolName), null, param, SyntaxFactory.List <TypeParameterConstraintClauseSyntax>(), block, arrow, SyntaxFactory.Token(SyntaxKind.SemicolonToken)); if (operation.Symbol.IsAsync) { localFunc = localFunc.AddModifiers(SyntaxFactory.Token(SyntaxKind.AsyncKeyword)); } return(localFunc); }
static async Task <Document?> HandleVariableDeclarator(IVariableDeclaratorOperation variableDeclaratorOperation, Document doc, SyntaxNode root, CancellationToken cancellationToken) { IVariableDeclarationOperation variableDeclarationOperation = (IVariableDeclarationOperation)variableDeclaratorOperation.Parent; IVariableDeclarationGroupOperation variableGroupDeclarationOperation = (IVariableDeclarationGroupOperation)variableDeclarationOperation.Parent; DocumentEditor editor = await DocumentEditor.CreateAsync(doc, cancellationToken).ConfigureAwait(false); SyntaxGenerator generator = editor.Generator; ILocalSymbol currentSymbol = variableDeclaratorOperation.Symbol; var variableInitializerOperation = variableDeclaratorOperation.GetVariableInitializer(); string unitString = (string)variableInitializerOperation.Value.ConstantValue.Value; char charValue = unitString[0]; SyntaxNode charLiteralExpressionNode = generator.LiteralExpression(charValue); var charTypeNode = generator.TypeExpression(SpecialType.System_Char); var charSyntaxNode = generator.LocalDeclarationStatement(charTypeNode, currentSymbol.Name, charLiteralExpressionNode, isConst: true); charSyntaxNode = charSyntaxNode.WithTriviaFrom(variableGroupDeclarationOperation.Syntax); var newRoot = generator.ReplaceNode(root, variableGroupDeclarationOperation.Syntax, charSyntaxNode); return(doc.WithSyntaxRoot(newRoot)); }
protected abstract TVariableDeclaratorSyntax GetDeclaratorSyntax(IVariableDeclaratorOperation declarator);
protected override VariableDeclaratorSyntax GetDeclaratorSyntax(IVariableDeclaratorOperation declarator) => (VariableDeclaratorSyntax)declarator.Syntax;
public override IOperation VisitVariableDeclarator(IVariableDeclaratorOperation operation, object argument) { return(new VariableDeclarator(operation.Symbol, Visit(operation.Initializer), VisitArray(operation.IgnoredArguments), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit)); }
private bool TryFindMatchingLocalDeclarationImmediatelyAbove( IConditionalOperation ifOperation, ISimpleAssignmentOperation trueAssignment, ISimpleAssignmentOperation falseAssignment, out IVariableDeclarationGroupOperation localDeclaration, out IVariableDeclaratorOperation declarator) { localDeclaration = null; declarator = null; // See if both assignments are to the same local. if (!(trueAssignment.Target is ILocalReferenceOperation trueLocal) || !(falseAssignment.Target is ILocalReferenceOperation falseLocal) || !Equals(trueLocal.Local, falseLocal.Local)) { return(false); } // If so, see if that local was declared immediately above the if-statement. var parentBlock = ifOperation.Parent as IBlockOperation; if (parentBlock == null) { return(false); } var ifIndex = parentBlock.Operations.IndexOf(ifOperation); if (ifIndex <= 0) { return(false); } localDeclaration = parentBlock.Operations[ifIndex - 1] as IVariableDeclarationGroupOperation; if (localDeclaration == null) { return(false); } if (localDeclaration.Declarations.Length != 1) { return(false); } var declaration = localDeclaration.Declarations[0]; var declarators = declaration.Declarators; if (declarators.Length != 1) { return(false); } declarator = declarators[0]; var variable = declarator.Symbol; if (!Equals(variable, trueLocal.Local)) { // wasn't a declaration of the local we're assigning to. return(false); } var variableName = variable.Name; var variableInitializer = declarator.Initializer ?? declaration.Initializer; if (variableInitializer?.Value != null) { var unwrapped = UnwrapImplicitConversion(variableInitializer.Value); // the variable has to either not have an initializer, or it needs to be basic // literal/default expression. if (!(unwrapped is ILiteralOperation) && !(unwrapped is IDefaultValueOperation)) { return(false); } } // If the variable is referenced in the condition of the 'if' block, we can't merge the // declaration and assignments. return(!ReferencesLocalVariable(ifOperation.Condition, variable)); }
public virtual void VisitVariableDeclarator(IVariableDeclaratorOperation operation) { DefaultVisit(operation); }
public override bool VisitVariableDeclarator([NotNull] IVariableDeclaratorOperation operation1, [CanBeNull] IOperation argument) { return(argument is IVariableDeclaratorOperation operation2 && AreBaseOperationsEqual(operation1, operation2) && AreSymbolsEqual(operation1.Symbol, operation2.Symbol)); }
public override void VisitVariableDeclarator([NotNull] IVariableDeclaratorOperation operation) { base.VisitVariableDeclarator(operation); }
public override void VisitVariableDeclarator(IVariableDeclaratorOperation operation) { base.VisitVariableDeclarator(operation); throw new NotImplementedException(); }
public override void VisitVariableDeclarator(IVariableDeclaratorOperation operation) { var symbol = operation.Symbol; base.VisitVariableDeclarator(operation); }
public override void VisitVariableDeclarator(IVariableDeclaratorOperation operation) { Callback(operation.Symbol.Type); base.VisitVariableDeclarator(operation); }