protected override void WalkNonNull(IAbstractSyntax syntax, BindingScope bindingScope) { switch (syntax) { case IConcreteInvocableDeclaration syn: foreach (var parameter in syn.Parameters.OfType <INamedParameter>()) { bindingScope = new VariableBindingScope(bindingScope, parameter); } break; case IFieldDeclaration syn: WalkChildren(syn, bindingScope); break; case IBodyOrBlock syn: foreach (var statement in syn.Statements) { WalkNonNull(statement, bindingScope); // Each variable declaration establishes a new binding scope if (statement is IVariableDeclarationStatement variableDeclaration) { bindingScope = new VariableBindingScope(bindingScope, variableDeclaration); } } return; case IVariableDeclarationStatement syn: { WalkChildren(syn, bindingScope); if (!bindingScope.Lookup(syn.Symbol.Name, out var binding)) { return; } if (binding.MutableBinding) { diagnostics.Add(SemanticError.CantRebindMutableBinding(file, syn.NameSpan)); } else if (syn.Symbol.IsMutableBinding) { diagnostics.Add(SemanticError.CantRebindAsMutableBinding(file, syn.NameSpan)); } return; } case INameExpression syn: { // This checks for cases where a variable was shadowed, but then used later if (!bindingScope.Lookup(syn.ReferencedSymbol.Name, out var binding)) { return; } if (binding.WasShadowedBy.Any()) { diagnostics.Add(SemanticError.CantShadow(file, binding.WasShadowedBy[^ 1].NameSpan, syn.Span));
protected override void WalkNonNull(ISyntax syntax) { switch (syntax) { case INamedParameterSyntax syn: if (!(syn.DefaultValue is null)) { diagnostics.Add(ParseError.NotImplemented(file, syn.DefaultValue.Span, "Default values")); } break; case IFieldParameterSyntax syn: if (!(syn.DefaultValue is null)) { diagnostics.Add(ParseError.NotImplemented(file, syn.DefaultValue.Span, "Default values")); } break; case IConstructorDeclarationSyntax syn: if (!(syn.Name is null)) { diagnostics.Add(ParseError.NotImplemented(file, syn.Span, "Named constructors")); } break; case IFieldDeclarationSyntax syn: if (!(syn.Initializer is null)) { diagnostics.Add(ParseError.NotImplemented(file, syn.Initializer.Span, "Field initializers")); } break; case IForeachExpressionSyntax syn: { var inExpression = syn.InExpression; if (!(inExpression is IBinaryOperatorExpressionSyntax exp) || (exp.Operator != BinaryOperator.DotDot && exp.Operator != BinaryOperator.LessThanDotDot && exp.Operator != BinaryOperator.DotDotLessThan && exp.Operator != BinaryOperator.LessThanDotDotLessThan)) { diagnostics.Add(ParseError.NotImplemented(file, inExpression.Span, "Foreach in non range expressions")); } } break; } WalkChildren(syntax); }
/// <summary> /// Renders diagnostics for the player networking /// </summary> void LateUpdate() { m_networkDiagnostics.SetActive( Diagnostics.IsActive() && !photonView.isMine); if (Diagnostics.IsActive()) { if (m_networkDiagnostics.activeSelf) { m_networkDiagnostics.GetComponent <SpriteRenderer>().color = m_colour; m_networkDiagnostics.transform.position = m_networkedPosition; m_networkDiagnostics.transform.rotation = m_networkedRotation; } string playerConnection; if (photonView.isMine) { Diagnostics.Add("Player Spawn Index", m_spawnIndex); playerConnection = "Client"; } else { playerConnection = "Enemy [" + (m_recievedValidData ? "x" : " ") + "]"; } Diagnostics.Add("Player" + m_ID, m_name + "|" + m_playerScore + "|" + m_health + "|" + PlayerHue + "|" + m_initialised + "|" + playerConnection); } }
protected override ImmutableArray <PendingBranch> RemoveReturns() { var result = base.RemoveReturns(); foreach (var pending in result) { switch (pending.Branch.Kind) { case BoundKind.GotoStatement: { var leave = pending.Branch; var loc = new SourceLocation(leave.Syntax.GetFirstToken()); Diagnostics.Add(ErrorCode.ERR_LabelNotFound, loc, ((BoundGotoStatement)pending.Branch).Label.Name); break; } case BoundKind.BreakStatement: case BoundKind.ContinueStatement: { var leave = pending.Branch; var loc = new SourceLocation(leave.Syntax.GetFirstToken()); Diagnostics.Add(ErrorCode.ERR_BadDelegateLeave, loc); break; } case BoundKind.ReturnStatement: break; default: break; // what else could it be? } } return(result); }
protected override void VisitFinallyBlock(BoundStatement finallyBlock, ref LocalState endState) { var oldPending1 = SavePending(); // we do not support branches into a finally block var oldPending2 = SavePending(); // track only the branches out of the finally block base.VisitFinallyBlock(finallyBlock, ref endState); RestorePending(oldPending2); // resolve branches that remain within the finally block foreach (var branch in PendingBranches) { if (branch.Branch == null) { continue; // a tracked exception } var location = new SourceLocation(branch.Branch.Syntax.GetFirstToken()); switch (branch.Branch.Kind) { case BoundKind.YieldBreakStatement: case BoundKind.YieldReturnStatement: // ERR_BadYieldInFinally reported during initial binding break; default: Diagnostics.Add(ErrorCode.ERR_BadFinallyLeave, location); break; } } RestorePending(oldPending1); }
private IEnumerable <ICompileModule> LoadModules() { var compilationSection = PrecompilerSection.Current; if (compilationSection == null) { yield break; } foreach (var module in compilationSection.CompileModules.Cast <CompileModuleElement>()) { ICompileModule compileModule = null; try { var type = Type.GetType(module.Type, true); compileModule = Activator.CreateInstance(type, true) as ICompileModule; } catch (Exception ex) { Diagnostics.Add(Diagnostic.Create( FailedToCreateModule, Location.Create(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, new TextSpan(), new LinePositionSpan()), module.Type, ex.Message)); } if (compileModule != null) { yield return(compileModule); } } }
private void PopTryBlock() { var lastBlock = CurrentBlockWithExceptions; _blockWithExceptions.RemoveLast(); if (_blockWithExceptions.Count > 0) { CurrentBlockWithExceptions.MergeThrowLocations(lastBlock); } // If we are going out of the BoundTryStatement // Log an error for any catch block that will never be reached if (lastBlock.Block is BoundTryStatement boundTry) { foreach (var catchBlock in boundTry.CatchBlocks) { if (!lastBlock.CatchBlockUsed.Contains(catchBlock)) { Diagnostics.Add(ErrorCode.ERR_CatchBlockNotUsed, catchBlock.Syntax.Location, catchBlock.ExceptionTypeOpt?.ToDisplayString() ?? "(none)"); } } } lastBlock.Free(); }
protected override void UpdateStateForCall(BoundCall node) { // Are we calling a dispose method? For now, we just check if the method is named Dispose and protected or better. // TODO: we need a better way of determining if a method should be considered to dispose its receiver. bool isDispose = node.Method.Name == "Dispose" && node.Method.DeclaredAccessibility >= Accessibility.Protected; if (node.ReceiverOpt != null && isDispose) { Value v = MakeValue(node.ReceiverOpt); foreach (var e in v.creations) { this.State.possiblyUndisposedCreations.Remove(e); if (!this.State.possiblyDisposedCreations.Add(e)) { Diagnostics.Add(ErrorCode.WRN_CA2202_DoNotDisposeObjectsMultipleTimes, node.Syntax.Location, e.Syntax.ToString()); } } } else if ((object)node.Method.AssociatedSymbol != null) { foreach (var a in node.Arguments) { Value v = MakeValue(a); foreach (var c in v.creations) { this.State.possiblyUndisposedCreations.Remove(c); } } } base.UpdateStateForCall(node); }
public override BoundNode VisitGotoStatement(BoundGotoStatement node) { _labelsUsed.Add(node.Label); // check for illegal jumps across using declarations var sourceLocation = node.Syntax.Location; var sourceStart = sourceLocation.SourceSpan.Start; var targetStart = node.Label.Locations[0].SourceSpan.Start; foreach (var usingDecl in _usingDeclarations) { var usingStart = usingDecl.symbol.Locations[0].SourceSpan.Start; if (sourceStart < usingStart && targetStart > usingStart) { // No forward jumps Diagnostics.Add(ErrorCode.ERR_GoToForwardJumpOverUsingVar, sourceLocation); break; } else if (sourceStart > usingStart && targetStart < usingStart) { // Backwards jump, so we must have already seen the label Debug.Assert(_labelsDefined.ContainsKey(node.Label)); // Error if label and using are part of the same block if (_labelsDefined[node.Label] == usingDecl.block) { Diagnostics.Add(ErrorCode.ERR_GoToBackwardJumpOverUsingVar, sourceLocation); break; } } } return(base.VisitGotoStatement(node)); }
/// <summary> /// Updates an existing template in current Templates instance. /// </summary> /// <param name="templateName">Original template name. The only id of a template.</param> /// <param name="newTemplateName">New template Name.</param> /// <param name="parameters">New params.</param> /// <param name="templateBody">New template body.</param> /// <returns>Updated LG file.</returns> public Templates UpdateTemplate(string templateName, string newTemplateName, List <string> parameters, string templateBody) { var template = this.FirstOrDefault(u => u.Name == templateName); if (template != null) { ClearDiagnostics(); var templateNameLine = BuildTemplateNameLine(newTemplateName, parameters); var newTemplateBody = ConvertTemplateBody(templateBody); var content = $"{templateNameLine}{_newLine}{newTemplateBody}"; // update content Content = ReplaceRangeContent( Content, template.SourceRange.Range.Start.Line - 1, template.SourceRange.Range.End.Line - 1, content); var updatedTemplates = new Templates(content: string.Empty, id: Id, importResolver: ImportResolver, expressionParser: ExpressionParser); updatedTemplates = new TemplatesTransformer(updatedTemplates).Transform(AntlrParseTemplates(content, Id)); var originStartLine = template.SourceRange.Range.Start.Line - 1; AppendDiagnosticsWithOffset(updatedTemplates.Diagnostics, originStartLine); var newTemplate = updatedTemplates.FirstOrDefault(); if (newTemplate != null) { AdjustRangeForUpdateTemplate(template, newTemplate); new StaticChecker(this).Check().ForEach(u => Diagnostics.Add(u)); } } return(this); }
private void AddMessage(IAssetsLogMessage message) { var logToMsBuild = true; var targetGraphs = message.GetTargetGraphs(LockFile); targetGraphs = targetGraphs.Any() ? targetGraphs : new LockFileTarget[] { null }; foreach (var target in targetGraphs) { var targetLib = message.LibraryId == null ? null : target?.GetTargetLibrary(message.LibraryId); Diagnostics.Add( message.Code.ToString(), message.Message, message.FilePath, FromLogLevel(message.Level), message.StartLineNumber, message.StartColumnNumber, message.EndLineNumber, message.EndColumnNumber, target?.Name, targetLib == null ? null : $"{targetLib.Name}/{targetLib.Version.ToNormalizedString()}", logToMsBuild); logToMsBuild = false; // only write first instance of this diagnostic to msbuild } }
/// <summary> /// Renders diagnostics for the player networking /// </summary> void LateUpdate() { if (Diagnostics.IsActive()) { Diagnostics.Add("AI " + name, m_health); } }
public ComponentAttributeIntermediateNode(TagHelperDirectiveAttributeParameterIntermediateNode directiveAttributeParameterNode) { if (directiveAttributeParameterNode == null) { throw new ArgumentNullException(nameof(directiveAttributeParameterNode)); } AttributeName = directiveAttributeParameterNode.AttributeNameWithoutParameter; AttributeStructure = directiveAttributeParameterNode.AttributeStructure; BoundAttribute = directiveAttributeParameterNode.BoundAttribute; PropertyName = directiveAttributeParameterNode.BoundAttributeParameter.GetPropertyName(); Source = directiveAttributeParameterNode.Source; TagHelper = directiveAttributeParameterNode.TagHelper; TypeName = directiveAttributeParameterNode.BoundAttributeParameter.TypeName; for (var i = 0; i < directiveAttributeParameterNode.Children.Count; i++) { Children.Add(directiveAttributeParameterNode.Children[i]); } for (var i = 0; i < directiveAttributeParameterNode.Diagnostics.Count; i++) { Diagnostics.Add(directiveAttributeParameterNode.Diagnostics[i]); } }
public ComponentAttributeIntermediateNode(TagHelperPropertyIntermediateNode propertyNode) { if (propertyNode == null) { throw new ArgumentNullException(nameof(propertyNode)); } var attributeName = propertyNode.AttributeName; if (propertyNode.IsDirectiveAttribute && attributeName.StartsWith("@")) { // Directive attributes start with a "@" but we don't want that to be included in the output attribute name. // E.g, <input @onclick="..." /> should result in the creation of 'onclick' attribute. attributeName = attributeName.Substring(1); } AttributeName = attributeName; AttributeStructure = propertyNode.AttributeStructure; BoundAttribute = propertyNode.BoundAttribute; PropertyName = propertyNode.BoundAttribute.GetPropertyName(); Source = propertyNode.Source; TagHelper = propertyNode.TagHelper; TypeName = propertyNode.BoundAttribute.IsWeaklyTyped() ? null : propertyNode.BoundAttribute.TypeName; for (var i = 0; i < propertyNode.Children.Count; i++) { Children.Add(propertyNode.Children[i]); } for (var i = 0; i < propertyNode.Diagnostics.Count; i++) { Diagnostics.Add(propertyNode.Diagnostics[i]); } }
public ComponentAttributeIntermediateNode(TagHelperPropertyIntermediateNode propertyNode) { if (propertyNode == null) { throw new ArgumentNullException(nameof(propertyNode)); } var attributeName = propertyNode.AttributeName; AttributeName = attributeName; AttributeStructure = propertyNode.AttributeStructure; BoundAttribute = propertyNode.BoundAttribute; PropertyName = propertyNode.BoundAttribute.GetPropertyName(); Source = propertyNode.Source; TagHelper = propertyNode.TagHelper; TypeName = propertyNode.BoundAttribute.IsWeaklyTyped() ? null : propertyNode.BoundAttribute.TypeName; for (var i = 0; i < propertyNode.Children.Count; i++) { Children.Add(propertyNode.Children[i]); } for (var i = 0; i < propertyNode.Diagnostics.Count; i++) { Diagnostics.Add(propertyNode.Diagnostics[i]); } }
public VariableFlags IdentifierName( INameExpression nameExpression, VariableFlags possiblyMoved) { var symbol = nameExpression.ReferencedSymbol; if (possiblyMoved[symbol] == true) { diagnostics.Add(SemanticError.UseOfPossiblyMovedValue(file, nameExpression.Span)); } var valueSemantics = nameExpression.Semantics; // TODO this isn't correct, but for now fields don't have proper move, borrow handling //?? nameExpression.Type.Assigned().OldValueSemantics; switch (valueSemantics) { case ExpressionSemantics.Move: case ExpressionSemantics.Acquire: return(possiblyMoved.Set(symbol, true)); case ExpressionSemantics.Copy: case ExpressionSemantics.Borrow: case ExpressionSemantics.Share: case ExpressionSemantics.Void: case ExpressionSemantics.Never: case ExpressionSemantics.CreateReference: // If it were move or copy, that would have been set to the ExpressionSemantics // Not moving value return(possiblyMoved); default: throw ExhaustiveMatch.Failed(valueSemantics); } }
/// <summary> /// Updates the network matchmaker /// </summary> void Update() { if (Diagnostics.IsActive()) { Diagnostics.Add("Network Status", m_networkDiagnostic); Diagnostics.Add("Disconnect Status", m_disconnectCause); Diagnostics.Add("Ping", PhotonNetwork.GetPing()); Diagnostics.Add("Server Time", PhotonNetwork.time); } // Attempt to reconnect when disconnected if (m_reconnectTimer != 0.0f) { m_reconnectTimer -= Time.deltaTime; if (m_reconnectTimer <= 0.0f) { m_reconnectTimer = 0.0f; ConnectToMatchmaker(); } } // Creates a new player when the level has fully initialised if (!m_synchedPrefabs.IsInitialised() && IsConnectedToLevel() && Utilities.IsLevelLoaded() && !Utilities.IsGameOver()) { m_synchedPrefabs.Create(); } }
/// <summary> /// Updates the manager /// </summary> void Update() { if (Diagnostics.IsActive()) { Diagnostics.Add("Player Manager Count", sm_allplayers.Count); } }
/// <inheritdoc/> public override SyntaxNode?VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node) { var updatedNode = (AnonymousObjectCreationExpressionSyntax)base.VisitAnonymousObjectCreationExpression(node) !; Diagnostics.Add(AnonymousObjectCreationExpression, node); return(updatedNode); }
/// <summary> /// Renders diagnostics for the fog of war /// </summary> void RenderDiagnostics() { if (Diagnostics.IsActive()) { Diagnostics.Add("Fog Tiles Static", m_staticTiles.Count); Diagnostics.Add("Fog Tiles Active", m_activeTiles.Count); } }
public override void VisitVariableDeclarationStatement(VariableDeclarationStatementSyntax variableDeclaration, BindingScope bindingScope) { base.VisitVariableDeclarationStatement(variableDeclaration, bindingScope); if (bindingScope.Lookup(variableDeclaration.Name, out var binding)) { if (binding.MutableBinding) { diagnostics.Add(SemanticError.CantRebindMutableBinding(function.File, variableDeclaration.NameSpan)); function.Poison(); } else if (variableDeclaration.MutableBinding) { diagnostics.Add(SemanticError.CantRebindAsMutableBinding(function.File, variableDeclaration.NameSpan)); function.Poison(); } } }
public void AddDiagnostic(DiagnosticSeverity severity, SyntaxNode node, string message) { Diagnostics.Add(new CompileDiagnostic(severity, node?.GetLocation(), message)); if (severity == DiagnosticSeverity.Error) { Interlocked.Increment(ref _errorCount); } }
private void GetDependencyDiagnostics() { Dictionary <string, string> projectDeps = LockFile.GetProjectFileDependencies(); // Temporarily suppress MSBuild logging because these diagnostics are also // reported by NuGet. This will no longer be necessary when NuGet moves // these diagnostics into the lockfile: // - https://github.com/NuGet/Home/issues/1599 // - https://github.com/dotnet/sdk/issues/585 bool logToMsBuild = false; // if a project dependency is not in the list of libs, then it is an unresolved reference var unresolvedDeps = projectDeps.Where(dep => null == LockFile.Libraries.FirstOrDefault(lib => string.Equals(lib.Name, dep.Key, StringComparison.OrdinalIgnoreCase))); foreach (var target in LockFile.Targets) { foreach (var dep in unresolvedDeps) { string packageId = dep.Key; packageId += dep.Value == null ? string.Empty : $"/{dep.Value}"; Diagnostics.Add(nameof(Strings.NU1001), string.Format(CultureInfo.CurrentCulture, Strings.NU1001, packageId), ProjectPath, DiagnosticMessageSeverity.Warning, 1, 0, target.Name, packageId, logToMSBuild: logToMsBuild ); } // report diagnostic if project dependency version does not match library version foreach (var dep in projectDeps) { var library = target.Libraries.FirstOrDefault(lib => string.Equals(lib.Name, dep.Key, StringComparison.OrdinalIgnoreCase)); var libraryVersion = library?.Version?.ToNormalizedString(); if (libraryVersion != null && dep.Value != null && !string.Equals(libraryVersion, dep.Value, StringComparison.OrdinalIgnoreCase)) { Diagnostics.Add(nameof(Strings.NU1012), string.Format(CultureInfo.CurrentCulture, Strings.NU1012, library.Name, dep.Value, libraryVersion), ProjectPath, DiagnosticMessageSeverity.Warning, 1, 0, target.Name, $"{library.Name}/{libraryVersion}", logToMSBuild: logToMsBuild ); } } } }
public void AddDiagnostic(DiagnosticSeverity severity, Location location, string message) { Diagnostics.Add(new CompileDiagnostic(severity, location, message)); if (severity == DiagnosticSeverity.Error) { Interlocked.Increment(ref _errorCount); } }
private void CheckReachable(BoundStatement statement) { if (!this.State.Alive && !this.State.Reported && !statement.WasCompilerGenerated && statement.Syntax.Span.Length != 0) { var firstToken = statement.Syntax.GetFirstToken(); Diagnostics.Add(ErrorCode.WRN_UnreachableCode, new SourceLocation(firstToken)); this.State.Reported = true; } }
public override void VisitIdentifierName(IdentifierNameSyntax identifierName, bool lvalue) { if (!lvalue || identifierName.ReferencedSymbol.MutableBinding) { return; } diagnostics.Add(SemanticError.CantAssignToImmutable(function.File, identifierName.Span)); function.Poison(); }
/// <summary> /// Renders the diagnostics /// </summary> protected virtual void RenderDiagnostics() { if (Diagnostics.IsActive()) { Diagnostics.Add("Mouse Cursor Angle", m_mouseCursorAngle); Diagnostics.Add("Fired Cannons Left", m_firedCannonLeft); Diagnostics.Add("Fired Cannons Right", m_firedCannonRight); } }
private void CheckCanMove(int objectId, HashSet <Claim> claims, TextSpan span) { var cantTake = claims.OfType <Loan>().SelectMany(l => l.Restrictions) .Any(r => r.Place == objectId && !r.CanTake); if (cantTake) { diagnostics.Add(BorrowError.BorrowedValueDoesNotLiveLongEnough(file, span)); } }
private static Diagnostics AllDiagnostics(PackageSyntax packageSyntax) { var diagnostics = new Diagnostics(); foreach (var compilationUnit in packageSyntax.CompilationUnits) { diagnostics.Add(compilationUnit.Diagnostics); } return(diagnostics); }
/// <summary> /// Report a given variable as not definitely assigned. Once a variable has been so /// reported, we suppress further reports of that variable. /// </summary> /// <param name="local"></param> /// <param name="node"></param> protected virtual void ReportUnassigned(Symbol local, SyntaxNode node) { int slot = VariableSlot(local); if (!alreadyReported[slot]) { Diagnostics.Add(ErrorCode.ERR_UseDefViolation, new SourceLocation(tree, node), local.Name); } alreadyReported[slot] = true; // mark the variable's slot so that we don't complain about the variable again }