Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ let rec TcSynRationalConst c =
| SynRationalConst.Integer(value = i) -> intToRational i
| SynRationalConst.Negate(rationalConst = c2) -> NegRational (TcSynRationalConst c2)
| SynRationalConst.Rational(numerator = p; denominator = q) -> DivRational (intToRational p) (intToRational q)
| SynRationalConst.Paren(rationalConst = c) -> TcSynRationalConst c

/// Typecheck constant terms in expressions and patterns
let TcConst (cenv: cenv) (overallTy: TType) m env synConst =
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Service/ServiceInterfaceStubGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ type InterfaceData =
let rec (|RationalConst|) =
function
| SynRationalConst.Integer (value = i) -> string i
| SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "(%i/%i)" numerator denominator
| SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "%i/%i" numerator denominator
| SynRationalConst.Negate (rationalConst = (RationalConst s)) -> sprintf "- %s" s
| SynRationalConst.Paren (rationalConst = (RationalConst s)) -> sprintf "(%s)" s

let rec (|TypeIdent|_|) =
function
Expand Down
4 changes: 3 additions & 1 deletion src/Compiler/SyntaxTree/SyntaxTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ type SynRationalConst =

| Integer of value: int32 * range: range

| Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range
| Rational of numerator: int32 * numeratorRange: range * divRange: range * denominator: int32 * denominatorRange: range * range: range

| Negate of rationalConst: SynRationalConst * range: range

| Paren of rationalConst: SynRationalConst * range: range

[<RequireQualifiedAccess>]
type SynAccess =
| Public of range: range
Expand Down
10 changes: 9 additions & 1 deletion src/Compiler/SyntaxTree/SyntaxTree.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,18 @@ type SynRationalConst =

| Integer of value: int32 * range: range

| Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range
| Rational of
numerator: int32 *
numeratorRange: range *
divRange: range *
denominator: int32 *
denominatorRange: range *
range: range

| Negate of rationalConst: SynRationalConst * range: range

| Paren of rationalConst: SynRationalConst * range: range

/// Represents an accessibility modifier in F# syntax
[<RequireQualifiedAccess>]
type SynAccess =
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -3314,13 +3314,13 @@ rationalConstant:
{ if $2 <> "/" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure())
if fst $3 = 0 then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsIllegalDenominatorForMeasureExponent())
if (snd $1) || (snd $3) then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState))
SynRationalConst.Rational(fst $1, rhs parseState 1, fst $3, rhs parseState 3, lhs parseState) }
SynRationalConst.Rational(fst $1, rhs parseState 1, rhs parseState 2, fst $3, rhs parseState 3, lhs parseState) }

| MINUS INT32 INFIX_STAR_DIV_MOD_OP INT32
{ if $3 <> "/" then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure())
if fst $4 = 0 then reportParseErrorAt (rhs parseState 4) (FSComp.SR.parsIllegalDenominatorForMeasureExponent())
if (snd $2) || (snd $4) then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState))
SynRationalConst.Negate(SynRationalConst.Rational(fst $2, rhs parseState 2, fst $4, rhs parseState 4, lhs parseState), lhs parseState) }
SynRationalConst.Negate(SynRationalConst.Rational(fst $2, rhs parseState 2, rhs parseState 3, fst $4, rhs parseState 4, lhs parseState), lhs parseState) }

| INT32
{ if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState))
Expand All @@ -3335,7 +3335,7 @@ atomicUnsignedRationalConstant:
SynRationalConst.Integer(fst $1, lhs parseState) }

| LPAREN rationalConstant rparen
{ $2 }
{ SynRationalConst.Paren($2, rhs2 parseState 1 3) }

atomicRationalConstant:
| atomicUnsignedRationalConstant { $1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8238,8 +8238,14 @@ FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRation
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst rationalConst
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range range
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst get_rationalConst()
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst rationalConst
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range range
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range denominatorRange
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range divRange
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_divRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_numeratorRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range numeratorRange
Expand All @@ -8250,18 +8256,23 @@ FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 get_numerator()
FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 numerator
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Integer
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Negate
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Paren
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Rational
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsInteger
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsNegate
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsParen
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsRational
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsInteger()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsParen()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsRational()
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewInteger(Int32, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewNegate(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewParen(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Integer
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Paren
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Rational
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Tags
FSharp.Compiler.Syntax.SynRationalConst: Int32 Tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8238,8 +8238,14 @@ FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRation
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst rationalConst
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range range
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst get_rationalConst()
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst rationalConst
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range range
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range denominatorRange
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range divRange
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_divRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_numeratorRange()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_range()
FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range numeratorRange
Expand All @@ -8250,18 +8256,23 @@ FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 get_numerator()
FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 numerator
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Integer
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Negate
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Paren
FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Rational
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsInteger
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsNegate
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsParen
FSharp.Compiler.Syntax.SynRationalConst: Boolean IsRational
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsInteger()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsParen()
FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsRational()
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewInteger(Int32, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewNegate(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewParen(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range)
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Integer
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Paren
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Rational
FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Tags
FSharp.Compiler.Syntax.SynRationalConst: Int32 Tag
Expand Down
8 changes: 5 additions & 3 deletions tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ ImplFile
Seq
([Power
(Named ([kg], (3,3--3,5)), (3,8--3,9),
Rational
(-12345, (3,21--3,27), 123, (3,28--3,31),
(3,21--3,31)), (3,3--3,32))], (3,3--3,32)),
Paren
(Rational
(-12345, (3,21--3,27), (3,27--3,28), 123,
(3,28--3,31), (3,21--3,31)), (3,20--3,32)),
(3,3--3,32))], (3,3--3,32)),
{ LessRange = (3,2--3,3)
GreaterRange = (3,32--3,33) }), (3,0--3,33)), (3,0--3,33))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
Expand Down
13 changes: 7 additions & 6 deletions tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ ImplFile
([Power
(Named ([kg], (3,3--3,5)), (3,5--3,6),
Negate
(Rational
(12345, (3,13--3,18), 123, (3,19--3,22),
(3,13--3,22)), (3,6--3,23)), (3,3--3,23))],
(3,3--3,23)), { LessRange = (3,2--3,3)
GreaterRange = (3,23--3,24) }),
(3,0--3,24)), (3,0--3,24))],
(Paren
(Rational
(12345, (3,13--3,18), (3,18--3,19), 123,
(3,19--3,22), (3,13--3,22)), (3,12--3,23)),
(3,6--3,23)), (3,3--3,23))], (3,3--3,23)),
{ LessRange = (3,2--3,3)
GreaterRange = (3,23--3,24) }), (3,0--3,24)), (3,0--3,24))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,24), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
Expand Down
13 changes: 7 additions & 6 deletions tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ ImplFile
([Power
(Named ([kg], (3,3--3,5)), (3,5--3,6),
Negate
(Rational
(12345, (3,10--3,15), 123, (3,16--3,19),
(3,10--3,19)), (3,7--3,20)), (3,3--3,20))],
(3,3--3,20)), { LessRange = (3,2--3,3)
GreaterRange = (3,20--3,21) }),
(3,0--3,21)), (3,0--3,21))],
(Paren
(Rational
(12345, (3,10--3,15), (3,15--3,16), 123,
(3,16--3,19), (3,10--3,19)), (3,9--3,20)),
(3,7--3,20)), (3,3--3,20))], (3,3--3,20)),
{ LessRange = (3,2--3,3)
GreaterRange = (3,20--3,21) }), (3,0--3,21)), (3,0--3,21))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
Expand Down