protected override void VisitLockStatementDeclarations(LockStatementSyntax node) { var expr = node.Expression; Debug.Assert(expr != null); this.builder.Add(expr); }
public override void VisitLockStatement(LockStatementSyntax node) { node.Expression?.Accept(this); node.Statement?.Accept(this); base.VisitLockStatement(node); }
public override Evaluation VisitLockStatement(LockStatementSyntax node) { node.Expression?.Accept <Evaluation>(this); node.Statement?.Accept <Evaluation>(this); return(base.VisitLockStatement(node)); }
public static Task <Document> RefactorAsync( Document document, LockStatementSyntax lockStatement, CancellationToken cancellationToken = default(CancellationToken)) { return(IntroduceFieldToLockOnRefactoring.RefactorAsync(document, lockStatement, cancellationToken)); }
private void RunLock(LockStatementSyntax node) { var obj = RunExpression(node.Expression); if (obj == null || obj.IsNull()) { throw new NullReferenceException($"lock(value) cannot be a null"); } object lockObj = obj; if (obj.IsCompiledType) { lockObj = obj.Unwrap(); } Monitor.Enter(lockObj); try { Run(node.Statement); } finally { Monitor.Exit(lockObj); } }
public override void VisitLockStatement(LockStatementSyntax node) { base.VisitLockStatement(node); StatementsAnalyzer statementsAnalyzer = this; statementsAnalyzer.counter = checked (statementsAnalyzer.counter + 1); }
public static async Task <Document> RefactorAsync( Document document, LockStatementSyntax lockStatement, CancellationToken cancellationToken = default(CancellationToken)) { return(await IntroduceFieldToLockOnRefactoring.RefactorAsync(document, lockStatement, cancellationToken).ConfigureAwait(false)); }
public static void Go(HaxeWriter writer, LockStatementSyntax statement) { if (statement.DescendantNodes().OfType <ReturnStatementSyntax>().Any()) { throw new Exception("Cannot return from within a lock statement " + Utility.Descriptor(statement)); } writer.WriteIndent(); writer.Write("CsLock.Lock("); Core.Write(writer, statement.Expression); writer.Write(", function()\r\n"); writer.WriteOpenBrace(); if (statement.Statement is BlockSyntax) { foreach (var s in statement.Statement.As <BlockSyntax>().Statements) { Core.Write(writer, s); } } else { Core.Write(writer, statement.Statement); } writer.Indent--; writer.WriteIndent(); writer.Write("});\r\n"); }
public static void Go(OutputWriter writer, LockStatementSyntax statement) { //All d objects implement a lock writer.WriteLine("synchronized(" + Core.WriteString(statement.Expression)+")"); writer.OpenBrace(); Core.WriteStatementAsBlock(writer, statement.Statement, false); writer.CloseBrace(); }
public static void Go(OutputWriter writer, LockStatementSyntax statement) { //All d objects implement a lock writer.WriteLine("synchronized(" + Core.WriteString(statement.Expression) + ")"); writer.OpenBrace(); Core.WriteStatementAsBlock(writer, statement.Statement, false); writer.CloseBrace(); }
public override BoundStatement InstrumentLockTargetCapture(BoundLockStatement original, BoundStatement lockTargetCapture) { LockStatementSyntax lockSyntax = (LockStatementSyntax)original.Syntax; return(new BoundSequencePointWithSpan(lockSyntax, base.InstrumentLockTargetCapture(original, lockTargetCapture), TextSpan.FromBounds(lockSyntax.LockKeyword.SpanStart, lockSyntax.CloseParenToken.Span.End))); }
public static LockStatementSyntax AddBraces(LockStatementSyntax lockStatement) { Debug.Assert(lockStatement != null && NeedsBraces(lockStatement)); return lockStatement .WithStatement(SyntaxFactory.Block(lockStatement.Statement)) .WithAdditionalAnnotations(Formatter.Annotation); }
private void BuildLockStatement(LockStatementSyntax lockStatement) { currentBlock = CreateBlock(currentBlock); BuildStatement(lockStatement.Statement); currentBlock = CreateJumpBlock(lockStatement, currentBlock); BuildExpression(lockStatement.Expression); }
public override BoundNode VisitLockStatement(BoundLockStatement node) { LockStatementSyntax lockSyntax = (LockStatementSyntax)node.Syntax; BoundExpression rewrittenArgument = VisitExpression(node.Argument); BoundStatement? rewrittenBody = VisitStatement(node.Body); Debug.Assert(rewrittenBody is { });
public override void VisitLockStatement(LockStatementSyntax node) { var symbol = SymbolHelper.GetSymbol(node, SemanticModel); CurrentLock.Push(symbol); base.VisitLockStatement(node); CurrentLock.Pop(); }
public static async Task <Document> RefactorAsync( Document document, LockStatementSyntax lockStatement, CancellationToken cancellationToken = default(CancellationToken)) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (lockStatement == null) { throw new ArgumentNullException(nameof(lockStatement)); } MemberDeclarationSyntax containingMember = lockStatement.FirstAncestorOrSelf <MemberDeclarationSyntax>(); if (containingMember != null) { var containingDeclaration = (MemberDeclarationSyntax)containingMember .Ancestors() .FirstOrDefault(f => f.IsKind( SyntaxKind.ClassDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.StructDeclaration)); if (containingDeclaration != null) { SyntaxList <MemberDeclarationSyntax> members = containingDeclaration.GetMembers(); int index = members.IndexOf(containingMember); SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); string name = Identifier.EnsureUniqueMemberName(LockObjectName, lockStatement.Expression.SpanStart, semanticModel, cancellationToken); LockStatementSyntax newLockStatement = lockStatement .WithExpression(IdentifierName(Identifier(name).WithRenameAnnotation())); MemberDeclarationSyntax newContainingMember = containingMember .ReplaceNode(lockStatement, newLockStatement); bool isStatic = containingMember.GetModifiers().Contains(SyntaxKind.StaticKeyword); FieldDeclarationSyntax field = CreateFieldDeclaration(name, isStatic).WithFormatterAnnotation(); SyntaxList <MemberDeclarationSyntax> newMembers = members.ReplaceAt(index, newContainingMember); newMembers = Inserter.InsertMember(newMembers, field); MemberDeclarationSyntax newNode = containingDeclaration.SetMembers(newMembers); return(await document.ReplaceNodeAsync(containingDeclaration, newNode, cancellationToken).ConfigureAwait(false)); } } return(document); }
public static bool ContainsEmbeddedStatement(LockStatementSyntax lockStatement) { if (lockStatement == null) { throw new ArgumentNullException(nameof(lockStatement)); } return(lockStatement.Statement?.IsKind(SyntaxKind.Block) == false); }
private static async Task <Document> IntroduceFieldToLockOnAsync( Document document, LockStatementSyntax lockStatement, CancellationToken cancellationToken = default(CancellationToken)) { SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); MemberDeclarationSyntax containingMember = lockStatement.FirstAncestorOrSelf <MemberDeclarationSyntax>(); if (containingMember != null) { var containingDeclaration = (MemberDeclarationSyntax)containingMember .Ancestors() .FirstOrDefault(f => f.IsKind( SyntaxKind.ClassDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.StructDeclaration)); if (containingDeclaration != null) { SyntaxList <MemberDeclarationSyntax> members = containingDeclaration.GetMembers(); int index = members.IndexOf(containingMember); string name = LockObjectName; if (document.SupportsSemanticModel) { SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); name = SyntaxUtility.GetUniqueName(name, semanticModel, lockStatement.Expression.Span.Start); } LockStatementSyntax newLockStatement = lockStatement .WithExpression(IdentifierName(name)); MemberDeclarationSyntax newContainingMember = containingMember .ReplaceNode(lockStatement, newLockStatement); bool isStatic = containingMember.GetModifiers().Contains(SyntaxKind.StaticKeyword); FieldDeclarationSyntax field = CreateField(name, isStatic).WithFormatterAnnotation(); SyntaxList <MemberDeclarationSyntax> newMembers = members .Replace(members[index], newContainingMember) .Insert(FindField(members, index) + 1, field); MemberDeclarationSyntax newNode = containingDeclaration.SetMembers(newMembers); SyntaxNode newRoot = root.ReplaceNode(containingDeclaration, newNode); return(document.WithSyntaxRoot(newRoot)); } } return(document); }
public override void VisitLockStatement(LockStatementSyntax node) { if (entryPoint.IsMethodLevel() && node.IsParent <AnonymousFunctionExpressionSyntax>()) { return; } noscounter++; base.VisitLockStatement(node); }
protected internal override object VisitLockStatement(LockStatementSyntax node, Binder enclosing) { // UNDONE: Create special binder type for "lock"? //var binder = new LockBinderContext(this.method, enclosing, node); //this.map = this.map.Add(node, binder); Visit(node.Statement, enclosing); return(null); }
public override SyntaxNode VisitLockStatement(LockStatementSyntax node) { if (node != this.ContainerOfStatementsOrFieldToReplace) { return(base.VisitLockStatement(node)); } return(node.WithExpression(VisitNode(node.Expression)) .WithStatement(ReplaceStatementIfNeeded(node.Statement))); }
public override void VisitLockStatement(LockStatementSyntax node) { string name = "LOCK_Statement"; if (ConsultingAnalysisResult.libraryUsage.ContainsKey(name)) ConsultingAnalysisResult.libraryUsage[name]++; else ConsultingAnalysisResult.libraryUsage[name] = 1; base.VisitLockStatement(node); }
public LockBlock(LockStatementSyntax lockNode, Block successor) : base(successor) { if (lockNode == null) { throw new ArgumentNullException(nameof(lockNode)); } LockNode = lockNode; }
public override LuaSyntaxNode VisitLockStatement(LockStatementSyntax node) { LuaStatementListSyntax statements = new LuaStatementListSyntax(); statements.Statements.Add(new LuaShortCommentStatement($" {node.LockKeyword}({node.Expression})")); LuaBlockStatementSyntax block = new LuaBlockStatementSyntax(); WriteStatementOrBlock(node.Statement, block); statements.Statements.Add(block); return(statements); }
public override void VisitLockStatement(LockStatementSyntax node) { if (entryPoint.IsMethodLevel() && node.IsParent <AnonymousFunctionExpressionSyntax>()) { return; } IncreaseHeight(); EmbeddednessConsideredToIncrease(); base.VisitLockStatement(node); currentNL--; EmbeddednessConsideredToDecrease(); }
public static async Task <Document> RefactorAsync( Document document, LockStatementSyntax lockStatement, CancellationToken cancellationToken = default) { MemberDeclarationSyntax containingMember = lockStatement.FirstAncestor <MemberDeclarationSyntax>(); Debug.Assert(containingMember != null); if (containingMember == null) { return(document); } TypeDeclarationSyntax containingType = containingMember.FirstAncestor <TypeDeclarationSyntax>(); Debug.Assert(containingType != null); if (containingType == null) { return(document); } SyntaxList <MemberDeclarationSyntax> members = containingType.Members; int index = members.IndexOf(containingMember); SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); string name = NameGenerator.Default.EnsureUniqueLocalName( LockObjectName, semanticModel, lockStatement.Expression.SpanStart, cancellationToken: cancellationToken); LockStatementSyntax newLockStatement = lockStatement .WithExpression(IdentifierName(Identifier(name).WithRenameAnnotation())); MemberDeclarationSyntax newContainingMember = containingMember .ReplaceNode(lockStatement, newLockStatement); bool isStatic = SyntaxInfo.ModifierListInfo(containingMember).IsStatic; FieldDeclarationSyntax field = CreateFieldDeclaration(name, isStatic).WithFormatterAnnotation(); SyntaxList <MemberDeclarationSyntax> newMembers = members.ReplaceAt(index, newContainingMember); newMembers = MemberDeclarationInserter.Default.Insert(newMembers, field); MemberDeclarationSyntax newNode = containingType.WithMembers(newMembers); return(await document.ReplaceNodeAsync(containingType, newNode, cancellationToken).ConfigureAwait(false)); }
public override void VisitLockStatement(LockStatementSyntax node) { if (entryNode is AnonymousFunctionExpressionSyntax && embeddedNode is AnonymousFunctionExpressionSyntax) { return; } if (_weComeFromMethod && _weInAnonymousMethod) { return; } InsertLLOCMap(node.GetLocation()); base.VisitLockStatement(node); }
/// <summary> /// lock(a) { b; c; } => { a; b; c; } /// </summary> /// <param name="node"></param> /// <returns></returns> public override UstNode VisitLockStatement(LockStatementSyntax node) { var statements = new List <Statement>(); var expr = new ExpressionStatement((Expression)base.Visit(node.Expression), node.Expression.GetTextSpan(), FileNode); statements.Add(expr); statements.AddRange(GetChildStatements(node.Statement)); var result = new BlockStatement(statements, node.GetTextSpan(), FileNode); return(result); }
public override void VisitLockStatement(LockStatementSyntax node) { if (!PreVisit(node)) { return; } node.Expression?.Accept(this); node.Statement?.Accept(this); base.VisitLockStatement(node); PostVisit(node); }
public override void VisitLockStatement(LockStatementSyntax node) { //Log(node, "Unsupported Syntax, ignore it !"); //忽略 if (null != node.Statement) { CodeBuilder.AppendFormat("{0}do", GetIndentString()); CodeBuilder.AppendLine(); ++m_Indent; node.Statement.Accept(this); --m_Indent; CodeBuilder.AppendFormat("{0}end;", GetIndentString()); CodeBuilder.AppendLine(); } }
public override void VisitLockStatement(LockStatementSyntax node) { var lockBinder = new LockBinder(_enclosing, node); AddToMap(node, lockBinder); StatementSyntax statement = node.Statement; var statementBinder = lockBinder.WithAdditionalFlags(BinderFlags.InLockBody); if (statementBinder != lockBinder) { AddToMap(statement, statementBinder); } VisitPossibleEmbeddedStatement(statement, statementBinder); }
private static async Task <Document> IntroduceFieldToLockOnAsync( Document document, LockStatementSyntax lockStatement, CancellationToken cancellationToken) { SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken); MemberDeclarationSyntax containingMember = lockStatement.FirstAncestorOrSelf <MemberDeclarationSyntax>(); if (containingMember != null) { var containingDeclaration = (MemberDeclarationSyntax)containingMember .Ancestors() .FirstOrDefault(f => f.IsAnyKind( SyntaxKind.ClassDeclaration, SyntaxKind.InterfaceDeclaration, SyntaxKind.StructDeclaration)); if (containingDeclaration != null) { SyntaxList <MemberDeclarationSyntax> members = containingDeclaration.GetMembers(); int index = members.IndexOf(containingMember); LockStatementSyntax newLockStatement = lockStatement .WithExpression(IdentifierName(LockObjectName)); MemberDeclarationSyntax newContainingMember = containingMember .ReplaceNode(lockStatement, newLockStatement); FieldDeclarationSyntax field = CreateField() .WithAdditionalAnnotations(Formatter.Annotation); SyntaxList <MemberDeclarationSyntax> newMembers = members .Replace(members[index], newContainingMember) .Insert(FindField(members, index) + 1, field); MemberDeclarationSyntax newNode = containingDeclaration.SetMembers(newMembers); SyntaxNode newRoot = oldRoot.ReplaceNode(containingDeclaration, newNode); return(document.WithSyntaxRoot(newRoot)); } } return(document); }
private void Analyze(SyntaxNodeAnalysisContext obj) { LockStatementSyntax lockStatementSyntax = (LockStatementSyntax)obj.Node; if (lockStatementSyntax.Expression is IdentifierNameSyntax identifier) { SymbolInfo info = obj.SemanticModel.GetSymbolInfo(identifier); if (info.Symbol is IFieldSymbol field) { if (!field.IsReadOnly) { obj.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), identifier.ToString())); } } } }
private BoundStatement BindLockStatement(LockStatementSyntax node, DiagnosticBag diagnostics) { var lockBinder = this.GetBinder(node); Debug.Assert(lockBinder != null); return lockBinder.BindLockStatementParts(diagnostics, lockBinder); }
public sealed override void VisitLockStatement(LockStatementSyntax node) { _builder.Add(node); base.VisitLockStatement(node); }
public override SyntaxNode VisitLockStatement(LockStatementSyntax node) { this.AppendCompileIssue(node, IssueType.Error, IssueId.LockNotSupport); return node; }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <remarks> /// Statements will cause an AST walker to be created, thus we don't need to go further deeper in the /// tree by visiting the node. /// </remarks> public override void VisitLockStatement(LockStatementSyntax node) { this.VisitStatement(node); }
public void Flatten(LockStatementSyntax node, List<FlatStatement> instructions) { /* public SyntaxToken CloseParenToken { get; } public ExpressionSyntax Expression { get; } public SyntaxToken LockKeyword { get; } public SyntaxToken OpenParenToken { get; } public StatementSyntax Statement { get; } */ throw new NotImplementedException("lock"); }
public static bool NeedsBraces(LockStatementSyntax lockStatement) { if (lockStatement == null) { throw new ArgumentNullException("lockStatement"); } return lockStatement.Statement != null && !lockStatement.Statement.IsKind(SyntaxKind.Block); }
private static bool AreEquivalentActiveStatements(LockStatementSyntax oldNode, LockStatementSyntax newNode) { // only check the expression, edits in the body are allowed: return AreEquivalentIgnoringLambdaBodies(oldNode.Expression, newNode.Expression); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitLockStatement(LockStatementSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitLockStatement(node); }
public LockBinder(Binder enclosing, LockStatementSyntax syntax) : base(enclosing) { this.syntax = syntax; this.expressionHandler = new LockOrUsingStatementExpressionHandler(syntax.Expression, this); }
public override void VisitLockStatement(LockStatementSyntax node) { string name = "LOCK_Statement"; var libraryUsage = Result.LibraryUsage; int temp; libraryUsage.TryGetValue(name, out temp); libraryUsage[name] = ++temp; base.VisitLockStatement(node); }
protected abstract void VisitLockStatementDeclarations(LockStatementSyntax node);
public override void VisitLockStatement(LockStatementSyntax node) { var patternBinder = new PatternVariableBinder(node, _enclosing); var lockBinder = new LockBinder(patternBinder, node); AddToMap(node, lockBinder); Visit(node.Expression, lockBinder); StatementSyntax statement = node.Statement; var statementBinder = lockBinder.WithAdditionalFlags(BinderFlags.InLockBody); if (statementBinder != lockBinder) { AddToMap(statement, statementBinder); } VisitPossibleEmbeddedStatement(statement, statementBinder); }
public sealed override void VisitLockStatement(LockStatementSyntax node) { this.VisitLockStatementDeclarations(node); base.VisitLockStatement(node); }
private IEnumerable<ITypeSymbol> InferTypeInLockStatement(LockStatementSyntax lockStatement, SyntaxToken? previousToken = null) { // If we're position based, then we have to be after the "lock(" if (previousToken.HasValue && previousToken.Value != lockStatement.OpenParenToken) { return SpecializedCollections.EmptyEnumerable<ITypeSymbol>(); } return SpecializedCollections.SingletonEnumerable(this.Compilation.GetSpecialType(SpecialType.System_Object)); }
public override void VisitLockStatement(LockStatementSyntax node) { AddExpressionTerms(node.Expression, _expressions); }
public override void VisitLockStatement(LockStatementSyntax node) { base.VisitLockStatement(node); _counter++; }
public override void VisitLockStatement(LockStatementSyntax node) { throw new NotSupportedException(); }
public void VisitLockStatement(LockStatementSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); WriteLeadingTrivia(node); _writer.WriteIndent(); _writer.WriteKeyword(PrinterKeyword.Lock); if (_writer.Configuration.Spaces.BeforeParentheses.LockParentheses) _writer.WriteSpace(); _writer.WriteSyntax(Syntax.OpenParen); if (_writer.Configuration.Spaces.WithinParentheses.LockParentheses) _writer.WriteSpace(); node.Expression.Accept(this); if (_writer.Configuration.Spaces.WithinParentheses.LockParentheses) _writer.WriteSpace(); _writer.WriteSyntax(Syntax.CloseParen); VisitBlockStatement(node.Statement); WriteTrailingTrivia(node); }
private BoundStatement MakeInitialLockSequencePoint(BoundStatement statement, LockStatementSyntax lockSyntax) { return this.GenerateDebugInfo ? new BoundSequencePointWithSpan(lockSyntax, statement, TextSpan.FromBounds(lockSyntax.LockKeyword.SpanStart, lockSyntax.CloseParenToken.Span.End)) : statement; }
public override void VisitLockStatement(LockStatementSyntax node) { Visit(node.Expression); }
protected override void VisitLockStatementDeclarations(LockStatementSyntax node) { Debug.Assert(node.Expression != null); // Expecting one or two locals depending on which overload of Monitor.Enter is used. if (TryGetSlotIndex(SynthesizedLocalKind.Lock) != null) { // If the next local is LockTaken, then the lock was emitted with the two argument // overload for Monitor.Enter(). Otherwise, the single argument overload was used. if (IsSlotIndex(SynthesizedLocalKind.LockTaken)) { AddSynthesizedLocal(SynthesizedLocalKind.LockTaken); } } this.offset++; }
public LockBinder(Binder enclosing, LockStatementSyntax syntax) : base(enclosing) { _syntax = syntax; }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitLockStatement(LockStatementSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitLockStatement(node); }
private bool AnalyzeLockStatement(LockStatementSyntax lockStatement) => !lockStatement.Statement.IsKind(SyntaxKind.Block) && !lockStatement.Statement.IsKind(SyntaxKind.LockStatement);
public override void VisitLockStatement(LockStatementSyntax node) { var saveCurrentScope = currentScope; currentScope = new DeclarationScope(currentScope); Visit(node.Expression); VisitPossibleEmbeddedStatement(node.Statement); Debug.Assert(currentScope.Parent == saveCurrentScope); currentScope = saveCurrentScope; }