Skip to content

Commit

Permalink
Merge pull request #202 from dawedawe/silence_warnings
Browse files Browse the repository at this point in the history
Silence warnings about obsolete ref cell handling and wrongly placed xml comments
  • Loading branch information
nojaf authored Apr 8, 2024
2 parents da71444 + 62a77e0 commit 444b890
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 80 deletions.
38 changes: 19 additions & 19 deletions src/Common/Arg.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,40 +79,40 @@ type ArgParser() =
pendline "display this list of options"
sbuf.ToString()

static member ParsePartial(cursor, argv, arguments: seq<ArgInfo>, ?otherArgs, ?usageText) =
static member ParsePartial(cursor: ref<int>, argv, arguments: seq<ArgInfo>, ?otherArgs, ?usageText) =
let other = defaultArg otherArgs (fun _ -> ())
let usageText = defaultArg usageText ""
let nargs = Array.length argv
incr cursor
cursor.Value <- cursor.Value + 1
let argSpecs = arguments |> Seq.toList
let specs = argSpecs |> List.map (fun (arg: ArgInfo) -> arg.Name, arg.ArgType)

while !cursor < nargs do
let arg = argv.[!cursor]
while cursor.Value < nargs do
let arg = argv.[cursor.Value]

let rec findMatchingArg args =
match args with
| (s, action) :: _ when s = arg ->
let getSecondArg () =
if !cursor + 1 >= nargs then
if cursor.Value + 1 >= nargs then
raise (Bad("option " + s + " needs an argument.\n" + getUsage argSpecs usageText))

argv.[!cursor + 1]
argv.[cursor.Value + 1]

match action with
| UnitArg f ->
f ()
incr cursor
cursor.Value <- cursor.Value + 1
| SetArg f ->
f := true
incr cursor
f.Value <- true
cursor.Value <- cursor.Value + 1
| ClearArg f ->
f := false
incr cursor
f.Value <- false
cursor.Value <- cursor.Value + 1
| StringArg f ->
let arg2 = getSecondArg ()
f arg2
cursor := !cursor + 2
cursor.Value <- cursor.Value + 2
| IntArg f ->
let arg2 = getSecondArg ()

Expand All @@ -123,7 +123,7 @@ type ArgParser() =
raise (Bad(getUsage argSpecs usageText)) in

f arg2
cursor := !cursor + 2
cursor.Value <- cursor.Value + 2
| FloatArg f ->
let arg2 = getSecondArg ()

Expand All @@ -134,13 +134,13 @@ type ArgParser() =
raise (Bad(getUsage argSpecs usageText)) in

f arg2
cursor := !cursor + 2
cursor.Value <- cursor.Value + 2
| RestArg f ->
incr cursor
cursor.Value <- cursor.Value + 1

while !cursor < nargs do
f argv.[!cursor]
incr cursor
while cursor.Value < nargs do
f argv.[cursor.Value]
cursor.Value <- cursor.Value + 1

| _ :: more -> findMatchingArg more
| [] ->
Expand All @@ -156,7 +156,7 @@ type ArgParser() =
raise (Bad("unrecognized argument: " + arg + "\n" + getUsage argSpecs usageText))
else
other arg
incr cursor
cursor.Value <- cursor.Value + 1

findMatchingArg specs

Expand Down
2 changes: 1 addition & 1 deletion src/Common/Arg.fsi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// (c) Microsoft Corporation 2005-2009.

/// A simple command-line argument processor.
// A simple command-line argument processor.
namespace FSharp.Text

/// The spec value describes the action of the argument,
Expand Down
4 changes: 2 additions & 2 deletions src/FsLex.Core/fslexast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ let newDfaNodeId =
let i = ref 0

fun () ->
let res = !i in
incr i
let res = i.Value in
i.Value <- i.Value + 1
res

let NfaToDfa (nfaNodeMap: NfaNodeMap) nfaStartNode =
Expand Down
8 changes: 4 additions & 4 deletions src/FsLexYacc.Runtime/Lexing.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ type Position =
/// Get a position corresponding to the first line (line number 1) in a given file
static member FirstLine: filename: string -> Position

[<Sealed>]
/// Input buffers consumed by lexers generated by <c>fslex.exe </c>
[<Sealed>]
type LexBuffer<'char> =
/// The start position for the lexeme
member StartPos: Position with get, set
Expand Down Expand Up @@ -135,8 +135,8 @@ type AsciiTables =
/// Interpret tables for an ascii lexer generated by fslex.
member Interpret: initialState: int * LexBuffer<byte> -> int

[<System.Obsolete("Async interretation of lexer tables is now obsolete and will be removed. Please use a background thread if you want async lexing")>]
/// Interpret tables for an ascii lexer generated by fslex, processing input asynchronously
[<System.Obsolete("Async interretation of lexer tables is now obsolete and will be removed. Please use a background thread if you want async lexing")>]
member AsyncInterpret: initialState: int * LexBuffer<byte> -> Async<int>

/// The type of tables for an unicode lexer generated by fslex.
Expand All @@ -148,13 +148,13 @@ type UnicodeTables =
/// Interpret tables for a unicode lexer generated by fslex.
member Interpret: initialState: int * LexBuffer<char> -> int

[<System.Obsolete("Async interretation of lexer tables is now obsolete and will be removed. Please use a background thread if you want async lexing")>]
/// Interpret tables for a unicode lexer generated by fslex, processing input asynchronously
[<System.Obsolete("Async interretation of lexer tables is now obsolete and will be removed. Please use a background thread if you want async lexing")>]
member AsyncInterpret: initialState: int * LexBuffer<char> -> Async<int>

/// Standard utility to create a Unicode LexBuffer
///
/// One small annoyance is that LexBuffers and not IDisposable. This means
/// One small annoyance is that LexBuffers are not IDisposable. This means
/// we can't just return the LexBuffer object, since the file it wraps wouldn't
/// get closed when we're finished with the LexBuffer. Hence we return the stream,
/// the reader and the LexBuffer. The caller should dispose the first two when done.
Expand Down
2 changes: 1 addition & 1 deletion src/FsLexYacc.Runtime/Parsing.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type IParseState =
/// Raise an error in this parse context
abstract RaiseError<'b> : unit -> 'b

[<Sealed>]
/// The context provided when a parse error occurs
[<Sealed>]
type ParseErrorContext<'tok> =
/// The stack of state indexes active at the parse error
member StateStack: int list
Expand Down
60 changes: 30 additions & 30 deletions src/FsYacc.Core/fsyaccast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ let (|GotoItemIdx|) (i64: uint64) =
/// to the worker function
let ProcessWorkList start f =
let work = ref (start: 'a list)
let queueWork = (fun x -> work := x :: !work)
let queueWork = (fun x -> work.Value <- x :: work.Value)

let rec loop () =
match !work with
match work.Value with
| [] -> ()
| x :: t ->
work := t
work.Value <- t
f queueWork x
loop ()

Expand All @@ -268,11 +268,11 @@ let LeastFixedPoint f set =
ProcessWorkList (Set.toList set) (fun queueWork item ->
f (item)
|> List.iter (fun i2 ->
if not (Set.contains i2 !acc) then
(acc := Set.add i2 !acc
if not (Set.contains i2 acc.Value) then
(acc.Value <- Set.add i2 acc.Value
queueWork i2)))

!acc
acc.Value

/// A general standard memoization utility. Be sure to apply to only one (function) argument to build the
/// residue function!
Expand Down Expand Up @@ -508,13 +508,13 @@ let CompilerLalrParserSpec logf (spec: ProcessedParserSpec) : CompiledSpec =
Set.empty)
]

let add changed ss (x, y) =
let add (changed: ref<bool>) ss (x, y) =
let s = Map.find x ss

if Set.contains y s then
ss
else
(changed := true
(changed.Value <- true
Map.add x (Set.add y s) ss)

let oneRound (ss: Map<_, _>) =
Expand All @@ -530,24 +530,24 @@ let CompilerLalrParserSpec logf (spec: ProcessedParserSpec) : CompiledSpec =
let rec place l =
match l with
| yi :: t ->
res
:= List.choose
(function
| None -> None
| Some a -> Some(PNonTerminal nonTermX, Some a))
(Set.toList ss.[yi])
@ !res
res.Value <-
List.choose
(function
| None -> None
| Some a -> Some(PNonTerminal nonTermX, Some a))
(Set.toList ss.[yi])
@ res.Value

if ss.[yi].Contains(None) then
place t
| [] -> res := (PNonTerminal nonTermX, None) :: !res
| [] -> res.Value <- (PNonTerminal nonTermX, None) :: res.Value

place rhs

!res
res.Value

let ss' = List.fold (add changed) ss frontier
!changed, ss'
changed.Value, ss'

let rec loop ss =
let changed, ss' = oneRound ss
Expand Down Expand Up @@ -781,15 +781,15 @@ let CompilerLalrParserSpec logf (spec: ProcessedParserSpec) : CompiledSpec =
let acc = ref Set.empty

ProcessWorkList startKernels (fun addToWorkList kernel ->
if not ((!acc).Contains(kernel)) then
acc := (!acc).Add(kernel)
if not ((acc.Value).Contains(kernel)) then
acc.Value <- (acc.Value).Add(kernel)

for csym in RelevantSymbolsOfKernel kernel do
let gotoKernel = ComputeGotosOfKernel kernel csym
assert (gotoKernel.Count > 0)
addToWorkList gotoKernel)

!acc |> Seq.toList |> List.map (Set.filter IsKernelItem)
acc.Value |> Seq.toList |> List.map (Set.filter IsKernelItem)

reportTime ()
printf "building kernel table..."
Expand Down Expand Up @@ -887,7 +887,7 @@ let CompilerLalrParserSpec logf (spec: ProcessedParserSpec) : CompiledSpec =
let jset = closure1OfItem0WithDummy item0
//printf "#jset = %d\n" jset.Count; stdout.Flush();
for KeyValue(closureItem0, lookaheadTokens) in jset.IEnumerable do
incr count
count.Value <- count.Value + 1

match rsym_of_item0 closureItem0 with
| None -> ()
Expand Down Expand Up @@ -1026,11 +1026,11 @@ let CompilerLalrParserSpec logf (spec: ProcessedParserSpec) : CompiledSpec =
| RightAssoc -> shiftItem
| NonAssoc ->
reportConflict shiftItem reduceItem "we prefer shift on equal precedences"
incr shiftReduceConflicts
shiftReduceConflicts.Value <- shiftReduceConflicts.Value + 1
shiftItem
| _ ->
reportConflict shiftItem reduceItem "we prefer shift when unable to compare precedences"
incr shiftReduceConflicts
shiftReduceConflicts.Value <- shiftReduceConflicts.Value + 1
shiftItem
| (_, Reduce prodIdx1), (_, Reduce prodIdx2) ->
"we prefer the rule earlier in the file"
Expand All @@ -1039,7 +1039,7 @@ let CompilerLalrParserSpec logf (spec: ProcessedParserSpec) : CompiledSpec =
else
reportConflict itemNew itemSoFar

incr reduceReduceConflicts
reduceReduceConflicts.Value <- reduceReduceConflicts.Value + 1
if prodIdx1 < prodIdx2 then itemSoFar else itemNew
| _ -> itemNew

Expand Down Expand Up @@ -1161,15 +1161,15 @@ let CompilerLalrParserSpec logf (spec: ProcessedParserSpec) : CompiledSpec =
printfn " returning tables."
stdout.Flush()

if !shiftReduceConflicts > 0 then
printfn " %d shift/reduce conflicts" !shiftReduceConflicts
if shiftReduceConflicts.Value > 0 then
printfn " %d shift/reduce conflicts" shiftReduceConflicts.Value
stdout.Flush()

if !reduceReduceConflicts > 0 then
printfn " %d reduce/reduce conflicts" !reduceReduceConflicts
if reduceReduceConflicts.Value > 0 then
printfn " %d reduce/reduce conflicts" reduceReduceConflicts.Value
stdout.Flush()

if !shiftReduceConflicts > 0 || !reduceReduceConflicts > 0 then
if shiftReduceConflicts.Value > 0 || reduceReduceConflicts.Value > 0 then
printfn
" consider setting precedences explicitly using %%left %%right and %%nonassoc on terminals and/or setting explicit precedence on rules using %%prec"

Expand Down
26 changes: 13 additions & 13 deletions src/FsYacc.Core/fsyaccdriver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -481,23 +481,23 @@ let writeSpecToFile (generatorState: GeneratorState) (spec: ParserSpec) (compile
let max = ref 0

for KeyValue(x, y) in countPerAction do
if y > !max then
(mostCommon := x
max := y)
if y > max.Value then
(mostCommon.Value <- x
max.Value <- y)

!mostCommon
mostCommon.Value

(* Count the number of entries in the association table. *)
let count = ref 0

for KeyValue(action, terminals) in terminalsByAction do
for terminal in terminals do
if action <> mostCommonAction then
incr count
count.Value <- count.Value + 1

(* Write the head of the table (i.e. the number of entries and the default value) *)
actionTableCurrIndex <- actionTableCurrIndex + 1
writer.WriteUInt16 !count
writer.WriteUInt16 count.Value
writer.WriteUInt16(generatorState.map_action_to_int mostCommonAction)

(* Write the pairs of entries in incremental order by key *)
Expand Down Expand Up @@ -585,14 +585,14 @@ let writeSpecToFile (generatorState: GeneratorState) (spec: ParserSpec) (compile
let c =
code
|> String.collect (fun c ->
if not !dollar && c = '$' then
(dollar := true
if not dollar.Value && c = '$' then
(dollar.Value <- true
"")
elif !dollar && c >= '0' && c <= '9' then
(dollar := false
elif dollar.Value && c >= '0' && c <= '9' then
(dollar.Value <- false
"_" + String(c, 1))
elif !dollar then
(dollar := false
elif dollar.Value then
(dollar.Value <- false
"$" + String(c, 1))
else
String(c, 1))
Expand All @@ -602,7 +602,7 @@ let writeSpecToFile (generatorState: GeneratorState) (spec: ParserSpec) (compile
for line in lines do
writer.WriteLine " %s" line

if !dollar then
if dollar.Value then
writer.Write "$"
| None -> writer.WriteLine " raise (%s.Accept(Microsoft.FSharp.Core.Operators.box _1))" generatorState.parslib

Expand Down
Loading

0 comments on commit 444b890

Please sign in to comment.