Skip to content

Commit

Permalink
apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyme committed Jun 3, 2022
1 parent ceb30f8 commit a054464
Show file tree
Hide file tree
Showing 22 changed files with 10,115 additions and 7,156 deletions.
69 changes: 34 additions & 35 deletions src/Compiler/Service/ExternalSymbol.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ open System.Diagnostics

module Option =

let ofOptionList (xs : 'a option list) : 'a list option =
let ofOptionList (xs: 'a option list) : 'a list option =

if xs |> List.forall Option.isSome then
xs |> List.map Option.get |> Some
else
None

/// Represents a type in an external (non F#) assembly.
[<RequireQualifiedAccess>]
type FindDeclExternalType =
Expand All @@ -36,36 +36,29 @@ type FindDeclExternalType =
| Type (name, genericArgs) ->
match genericArgs with
| [] -> ""
| args ->
args
|> List.map (sprintf "%O")
|> String.concat ", "
|> sprintf "<%s>"
| args -> args |> List.map (sprintf "%O") |> String.concat ", " |> sprintf "<%s>"
|> sprintf "%s%s" name
| Array inner -> sprintf "%O[]" inner
| Pointer inner -> sprintf "&%O" inner
| TypeVar name -> sprintf "'%s" name

module FindDeclExternalType =
let rec tryOfILType (typeVarNames: string array) (ilType: ILType) =

match ilType with
| ILType.Array (_, inner) ->
tryOfILType typeVarNames inner |> Option.map FindDeclExternalType.Array
| ILType.Array (_, inner) -> tryOfILType typeVarNames inner |> Option.map FindDeclExternalType.Array
| ILType.Boxed tyspec
| ILType.Value tyspec ->
tyspec.GenericArgs
|> List.map (tryOfILType typeVarNames)
|> Option.ofOptionList
|> Option.map (fun genericArgs -> FindDeclExternalType.Type (tyspec.FullName, genericArgs))
| ILType.Ptr inner ->
tryOfILType typeVarNames inner |> Option.map FindDeclExternalType.Pointer
|> Option.map (fun genericArgs -> FindDeclExternalType.Type(tyspec.FullName, genericArgs))
| ILType.Ptr inner -> tryOfILType typeVarNames inner |> Option.map FindDeclExternalType.Pointer
| ILType.TypeVar ordinal ->
typeVarNames
|> Array.tryItem (int ordinal)
|> Option.map (fun typeVarName -> FindDeclExternalType.TypeVar typeVarName)
| _ ->
None
| _ -> None

[<RequireQualifiedAccess>]
type FindDeclExternalParam =
Expand All @@ -74,27 +67,37 @@ type FindDeclExternalParam =

| Byref of parameterType: FindDeclExternalType

member c.IsByRef = match c with Byref _ -> true | _ -> false
member c.IsByRef =
match c with
| Byref _ -> true
| _ -> false

member c.ParameterType = match c with Byref ty -> ty | Param ty -> ty
member c.ParameterType =
match c with
| Byref ty -> ty
| Param ty -> ty

static member Create(parameterType, isByRef) =
static member Create(parameterType, isByRef) =
if isByRef then Byref parameterType else Param parameterType

override this.ToString () =
override this.ToString() =
match this with
| Param t -> t.ToString()
| Byref t -> sprintf "ref %O" t

module FindDeclExternalParam =
let tryOfILType (typeVarNames : string array) =
let tryOfILType (typeVarNames: string array) =
function
| ILType.Byref inner -> FindDeclExternalType.tryOfILType typeVarNames inner |> Option.map FindDeclExternalParam.Byref
| ilType -> FindDeclExternalType.tryOfILType typeVarNames ilType |> Option.map FindDeclExternalParam.Param
| ILType.Byref inner ->
FindDeclExternalType.tryOfILType typeVarNames inner
|> Option.map FindDeclExternalParam.Byref
| ilType ->
FindDeclExternalType.tryOfILType typeVarNames ilType
|> Option.map FindDeclExternalParam.Param

let tryOfILTypes typeVarNames ilTypes =
ilTypes |> List.map (tryOfILType typeVarNames) |> Option.ofOptionList

[<RequireQualifiedAccess>]
[<DebuggerDisplay "{ToDebuggerDisplay(),nq}">]
type FindDeclExternalSymbol =
Expand All @@ -105,7 +108,7 @@ type FindDeclExternalSymbol =
| Event of typeName: string * name: string
| Property of typeName: string * name: string

override this.ToString () =
override this.ToString() =
match this with
| Type fullName -> fullName
| Constructor (typeName, args) ->
Expand All @@ -114,25 +117,22 @@ type FindDeclExternalSymbol =
|> String.concat ", "
|> sprintf "%s..ctor(%s)" typeName
| Method (typeName, name, args, genericArity) ->
let genericAritySuffix =
if genericArity > 0 then sprintf "`%d" genericArity
else ""
let genericAritySuffix = if genericArity > 0 then sprintf "`%d" genericArity else ""

args
|> List.map (sprintf "%O")
|> String.concat ", "
|> sprintf "%s.%s%s(%s)" typeName name genericAritySuffix
| Field (typeName, name)
| Event (typeName, name)
| Property (typeName, name) ->
sprintf "%s.%s" typeName name
| Property (typeName, name) -> sprintf "%s.%s" typeName name

member this.ToDebuggerDisplay () =
member this.ToDebuggerDisplay() =
let caseInfo, _ = FSharpValue.GetUnionFields(this, typeof<FindDeclExternalSymbol>)
sprintf "%s %O" caseInfo.Name this

[<RequireQualifiedAccess>]
type FindDeclFailureReason =
type FindDeclFailureReason =

// generic reason: no particular information about error
| Unknown of message: string
Expand All @@ -147,7 +147,7 @@ type FindDeclFailureReason =
| ProvidedMember of memberName: string

[<RequireQualifiedAccess>]
type FindDeclResult =
type FindDeclResult =

/// declaration not found + reason
| DeclNotFound of FindDeclFailureReason
Expand All @@ -156,5 +156,4 @@ type FindDeclResult =
| DeclFound of location: range

/// Indicates an external declaration was found
| ExternalDecl of assembly : string * externalSym : FindDeclExternalSymbol

| ExternalDecl of assembly: string * externalSym: FindDeclExternalSymbol
Loading

0 comments on commit a054464

Please sign in to comment.