-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding fix to process 64 bit integers correctly. (#5791)
* Adding fix to process 64 bit integers correctly. * Adding fix to process 64 bit integers correctly. * Adding fix to process 64 bit integers correctly. * Adding baseline tests update. * Added changes * Fixed test for positive 64 bit integer.
- Loading branch information
1 parent
b777a99
commit 1faac71
Showing
16 changed files
with
192 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Bicep.Core.Diagnostics; | ||
using Bicep.Core.Syntax; | ||
|
||
namespace Bicep.Core.Emit | ||
{ | ||
public class IntegerValidatorVisitor : SyntaxVisitor | ||
{ | ||
private readonly IDiagnosticWriter diagnosticWriter; | ||
|
||
private IntegerValidatorVisitor(IDiagnosticWriter diagnosticWriter) | ||
{ | ||
this.diagnosticWriter = diagnosticWriter; | ||
} | ||
|
||
public static void Validate(ProgramSyntax programSyntax, IDiagnosticWriter diagnosticWriter) | ||
{ | ||
var visitor = new IntegerValidatorVisitor(diagnosticWriter); | ||
// visiting writes diagnostics in some cases | ||
visitor.Visit(programSyntax); | ||
} | ||
|
||
public override void VisitIntegerLiteralSyntax(IntegerLiteralSyntax syntax) | ||
{ | ||
// syntax.Value is always positive and can't be greater than the greatest 64 bit integer | ||
if (syntax.Value > long.MaxValue) | ||
{ | ||
diagnosticWriter.Write(DiagnosticBuilder.ForPosition(syntax).InvalidInteger()); | ||
} | ||
base.VisitIntegerLiteralSyntax(syntax); | ||
} | ||
|
||
public override void VisitUnaryOperationSyntax(UnaryOperationSyntax syntax) | ||
{ | ||
// a negative integer is parsed into a minus token and an integer token which is always positive | ||
// so for the most negative valid signed 64 bit integer -9,223,372,036,854,775,808, we need to compare its positive integer token (9,223,372,036,854,775,808) to long.MaxValue (9,223,372,036,854,775,807) + 1 | ||
if (syntax.Operator == UnaryOperator.Minus && syntax.Expression is IntegerLiteralSyntax integerLiteral) | ||
{ | ||
if (integerLiteral.Value > (ulong)long.MaxValue + 1) | ||
{ | ||
diagnosticWriter.Write(DiagnosticBuilder.ForPosition(syntax).InvalidInteger()); | ||
} | ||
} | ||
else | ||
{ | ||
base.VisitUnaryOperationSyntax(syntax); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters