Skip to content

Commit 06128df

Browse files
committedOct 13, 2015
Merge pull request #436 from dsyme/fix-enums
first cut at C# enum fields
·
rm1.4.0.7
2 parents bdd19ea + 449ba80 commit 06128df

File tree

7 files changed

+93
-42
lines changed

7 files changed

+93
-42
lines changed
 

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,7 @@ FSharp.Core.Nuget/*.nupkg
124124
*.ldf
125125
.paket/paket.exe
126126
paket-files
127+
docs/tools/FSharp.Formatting.svclog
128+
src/fsharp/FSharp.Compiler.Service/pplex.fs
129+
src/fsharp/FSharp.Compiler.Service/pppars.fs
130+
src/fsharp/FSharp.Compiler.Service/pppars.fsi

‎src/fsharp/vs/ServiceDeclarations.fs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ module internal ItemDescriptionsImpl =
406406
| _ -> None
407407
| _ -> None
408408

409+
let GetXmlDocSigOfILFieldInfo infoReader m (finfo:ILFieldInfo) =
410+
match metaInfoOfEntityRef infoReader m (tcrefOfAppTy infoReader.g finfo.EnclosingType) with
411+
| Some (ccuFileName,_,formalTypeInfo) ->
412+
Some(ccuFileName,"F:"+formalTypeInfo.ILTypeRef.FullName+"."+finfo.FieldName)
413+
| _ -> None
414+
409415
/// This function gets the signature to pass to Visual Studio to use its lookup functions for .NET stuff.
410416
let rec GetXmlDocHelpSigOfItemForLookup (infoReader:InfoReader) m d =
411417
let g = infoReader.g
@@ -418,12 +424,7 @@ module internal ItemDescriptionsImpl =
418424
| Item.ExnCase tcref -> mkXmlComment (GetXmlDocSigOfEntityRef infoReader m tcref)
419425
| Item.RecdField rfinfo -> mkXmlComment (GetXmlDocSigOfRecdFieldInfo rfinfo)
420426
| Item.NewDef _ -> FSharpXmlDoc.None
421-
| Item.ILField(ILFieldInfo(tinfo, fdef)) ->
422-
match metaInfoOfEntityRef infoReader m tinfo.TyconRef with
423-
| Some (Some(ccuFileName),_,formalTypeInfo) ->
424-
FSharpXmlDoc.XmlDocFileSignature(ccuFileName,"F:"+formalTypeInfo.ILTypeRef.FullName+"."+fdef.Name)
425-
| _ -> FSharpXmlDoc.None
426-
427+
| Item.ILField finfo -> mkXmlComment (GetXmlDocSigOfILFieldInfo infoReader m finfo)
427428
| Item.Types(_,((TType_app(tcref,_)) :: _)) -> mkXmlComment (GetXmlDocSigOfEntityRef infoReader m tcref)
428429
| Item.CustomOperation (_,_,Some minfo) -> mkXmlComment (GetXmlDocSigOfMethInfo infoReader m minfo)
429430
| Item.TypeVar _ -> FSharpXmlDoc.None

‎src/fsharp/vs/ServiceDeclarations.fsi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ module internal ItemDescriptionsImpl =
8787

8888
val GetXmlDocSigOfEntityRef : InfoReader -> range -> EntityRef -> (string option * string) option
8989
val GetXmlDocSigOfScopedValRef : TcGlobals -> TyconRef -> ValRef -> (string option * string) option
90+
val GetXmlDocSigOfILFieldInfo : InfoReader -> range -> ILFieldInfo -> (string option * string) option
9091
val GetXmlDocSigOfRecdFieldInfo : RecdFieldInfo -> (string option * string) option
9192
val GetXmlDocSigOfUnionCaseInfo : UnionCaseInfo -> (string option * string) option
9293
val GetXmlDocSigOfMethInfo : InfoReader -> range -> MethInfo -> (string option * string) option

‎src/fsharp/vs/Symbols.fs‎

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -599,27 +599,32 @@ and FSharpUnionCase(cenv, v: UnionCaseRef) =
599599

600600

601601
and FSharpFieldData =
602-
| Recd of RecdFieldRef
602+
| ILField of TcGlobals * ILFieldInfo
603+
| RecdOrClass of RecdFieldRef
603604
| Union of UnionCaseRef * int
604-
member x.RecdField =
605+
member x.TryRecdField =
605606
match x with
606-
| Recd v -> v.RecdField
607-
| Union (v,n) -> v.FieldByIndex(n)
607+
| RecdOrClass v -> v.RecdField |> Choice1Of2
608+
| Union (v,n) -> v.FieldByIndex(n) |> Choice1Of2
609+
| ILField (_,f) -> f |> Choice2Of2
608610
member x.DeclaringTyconRef =
609611
match x with
610-
| Recd v -> v.TyconRef
612+
| RecdOrClass v -> v.TyconRef
611613
| Union (v,_) -> v.TyconRef
614+
| ILField (g,f) -> tcrefOfAppTy g f.EnclosingType
612615

613616
and FSharpField(cenv, d: FSharpFieldData) =
614617
inherit FSharpSymbol (cenv,
615618
(fun () ->
616619
match d with
617-
| Recd v ->
620+
| RecdOrClass v ->
618621
checkEntityIsResolved v.TyconRef
619622
Item.RecdField(RecdFieldInfo(generalizeTypars v.TyconRef.TyparsNoRange,v))
620623
| Union (v,_) ->
621624
// This is not correct: there is no "Item" for a named union case field
622-
Item.UnionCase(UnionCaseInfo(generalizeTypars v.TyconRef.TyparsNoRange,v),false)),
625+
Item.UnionCase(UnionCaseInfo(generalizeTypars v.TyconRef.TyparsNoRange,v),false)
626+
| ILField (_, f) ->
627+
Item.ILField(f)),
623628
(fun this thisCcu2 ad ->
624629
checkForCrossProjectAccessibility (thisCcu2, ad) (cenv.thisCcu, (this :?> FSharpField).Accessibility.Contents))
625630
//&&
@@ -629,23 +634,25 @@ and FSharpField(cenv, d: FSharpFieldData) =
629634
)
630635

631636
let isUnresolved() =
637+
entityIsUnresolved d.DeclaringTyconRef ||
632638
match d with
633-
| Recd v -> entityIsUnresolved v.TyconRef || v.TryRecdField.IsNone
634-
| Union (v,_) -> entityIsUnresolved v.TyconRef || v.TryUnionCase.IsNone
639+
| RecdOrClass v -> v.TryRecdField.IsNone
640+
| Union (v,_) -> v.TryUnionCase.IsNone
641+
| ILField _ -> false
635642

636643
let checkIsResolved() =
644+
checkEntityIsResolved d.DeclaringTyconRef
637645
match d with
638-
| Recd v ->
639-
checkEntityIsResolved v.TyconRef
646+
| RecdOrClass v ->
640647
if v.TryRecdField.IsNone then
641648
invalidOp (sprintf "The record field '%s' could not be found in the target type" v.FieldName)
642649
| Union (v,_) ->
643-
checkEntityIsResolved v.TyconRef
644650
if v.TryUnionCase.IsNone then
645651
invalidOp (sprintf "The union case '%s' could not be found in the target type" v.CaseName)
652+
| ILField _ -> ()
646653

647654
new (cenv, ucref, n) = FSharpField(cenv, FSharpFieldData.Union(ucref,n))
648-
new (cenv, rfref) = FSharpField(cenv, FSharpFieldData.Recd(rfref))
655+
new (cenv, rfref) = FSharpField(cenv, FSharpFieldData.RecdOrClass(rfref))
649656

650657
member __.DeclaringEntity =
651658
FSharpEntity(cenv, d.DeclaringTyconRef)
@@ -655,82 +662,118 @@ and FSharpField(cenv, d: FSharpFieldData) =
655662

656663
member __.IsMutable =
657664
if isUnresolved() then false else
658-
d.RecdField.IsMutable
665+
match d.TryRecdField with
666+
| Choice1Of2 r -> r.IsMutable
667+
| Choice2Of2 f -> not f.IsInitOnly
659668

660669
member __.IsLiteral =
661670
if isUnresolved() then false else
662-
d.RecdField.LiteralValue.IsSome
671+
match d.TryRecdField with
672+
| Choice1Of2 r -> r.LiteralValue.IsSome
673+
| Choice2Of2 f -> f.LiteralValue.IsSome
663674

664675
member __.LiteralValue =
665-
if isUnresolved()
666-
then None
667-
else getLiteralValue d.RecdField.LiteralValue
676+
if isUnresolved() then None else
677+
match d.TryRecdField with
678+
| Choice1Of2 r -> getLiteralValue r.LiteralValue
679+
| Choice2Of2 f -> f.LiteralValue |> Option.map AbstractIL.ILRuntimeWriter.convFieldInit
668680

669681
member __.IsVolatile =
670682
if isUnresolved() then false else
671-
d.RecdField.IsVolatile
683+
match d.TryRecdField with
684+
| Choice1Of2 r -> r.IsVolatile
685+
| Choice2Of2 _ -> false // F# doesn't actually respect "volatile" from other assemblies in any case
672686

673687
member __.IsDefaultValue =
674688
if isUnresolved() then false else
675-
d.RecdField.IsZeroInit
689+
match d.TryRecdField with
690+
| Choice1Of2 r -> r.IsZeroInit
691+
| Choice2Of2 _ -> false
676692

677693
member __.XmlDocSig =
678694
checkIsResolved()
679695
let xmlsig =
680696
match d with
681-
| Recd v ->
697+
| RecdOrClass v ->
682698
let recd = RecdFieldInfo(generalizeTypars v.TyconRef.TyparsNoRange,v)
683699
ItemDescriptionsImpl.GetXmlDocSigOfRecdFieldInfo recd
684700
| Union (v,_) ->
685701
let unionCase = UnionCaseInfo(generalizeTypars v.TyconRef.TyparsNoRange,v)
686702
ItemDescriptionsImpl.GetXmlDocSigOfUnionCaseInfo unionCase
703+
| ILField (_,f) ->
704+
ItemDescriptionsImpl.GetXmlDocSigOfILFieldInfo cenv.infoReader range0 f
687705
match xmlsig with
688706
| Some (_, docsig) -> docsig
689707
| _ -> ""
690708

691709
member __.XmlDoc =
692710
if isUnresolved() then XmlDoc.Empty |> makeXmlDoc else
693-
d.RecdField.XmlDoc |> makeXmlDoc
711+
match d.TryRecdField with
712+
| Choice1Of2 r -> r.XmlDoc
713+
| Choice2Of2 _ -> XmlDoc.Empty
714+
|> makeXmlDoc
694715

695716
member __.FieldType =
696717
checkIsResolved()
697-
FSharpType(cenv, d.RecdField.FormalType)
718+
let fty =
719+
match d.TryRecdField with
720+
| Choice1Of2 r -> r.FormalType
721+
| Choice2Of2 f -> f.FieldType(cenv.amap, range0)
722+
FSharpType(cenv, fty)
698723

699724
member __.IsStatic =
700725
if isUnresolved() then false else
701-
d.RecdField.IsStatic
726+
match d.TryRecdField with
727+
| Choice1Of2 r -> r.IsStatic
728+
| Choice2Of2 f -> f.IsStatic
702729

703730
member __.Name =
704731
checkIsResolved()
705-
d.RecdField.Name
732+
match d.TryRecdField with
733+
| Choice1Of2 r -> r.Name
734+
| Choice2Of2 f -> f.FieldName
706735

707736
member __.IsCompilerGenerated =
708737
if isUnresolved() then false else
709-
d.RecdField.IsCompilerGenerated
738+
match d.TryRecdField with
739+
| Choice1Of2 r -> r.IsCompilerGenerated
740+
| Choice2Of2 _ -> false
710741

711742
member __.DeclarationLocation =
712743
checkIsResolved()
713-
d.RecdField.Range
744+
match d.TryRecdField with
745+
| Choice1Of2 r -> r.Range
746+
| Choice2Of2 _ -> range0
714747

715748
member __.FieldAttributes =
716749
if isUnresolved() then makeReadOnlyCollection [] else
717-
d.RecdField.FieldAttribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) |> makeReadOnlyCollection
750+
match d.TryRecdField with
751+
| Choice1Of2 r -> r.FieldAttribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a)))
752+
| Choice2Of2 _ -> []
753+
|> makeReadOnlyCollection
718754

719755
member __.PropertyAttributes =
720756
if isUnresolved() then makeReadOnlyCollection [] else
721-
d.RecdField.PropertyAttribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) |> makeReadOnlyCollection
757+
match d.TryRecdField with
758+
| Choice1Of2 r -> r.PropertyAttribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a)))
759+
| Choice2Of2 _ -> []
760+
|> makeReadOnlyCollection
722761

723762
member __.Accessibility : FSharpAccessibility =
724763
if isUnresolved() then FSharpAccessibility(taccessPublic) else
725-
FSharpAccessibility(d.RecdField.Accessibility)
764+
let access =
765+
match d.TryRecdField with
766+
| Choice1Of2 r -> r.Accessibility
767+
| Choice2Of2 _ -> taccessPublic
768+
FSharpAccessibility(access)
726769

727770
member private x.V = d
728771
override x.Equals(other : obj) =
729772
box x === other ||
730773
match other with
731774
| :? FSharpField as uc ->
732775
match d, uc.V with
733-
| Recd r1, Recd r2 -> recdFieldRefOrder.Compare(r1, r2) = 0
776+
| RecdOrClass r1, RecdOrClass r2 -> recdFieldRefOrder.Compare(r1, r2) = 0
734777
| Union (u1,n1), Union (u2,n2) -> cenv.g.unionCaseRefEq u1 u2 && n1 = n2
735778
| _ -> false
736779
| _ -> false
@@ -1967,7 +2010,9 @@ type FSharpSymbol with
19672010
| Item.Value v -> FSharpMemberOrFunctionOrValue(cenv, V v, item) :> _
19682011
| Item.UnionCase (uinfo,_) -> FSharpUnionCase(cenv, uinfo.UnionCaseRef) :> _
19692012
| Item.ExnCase tcref -> FSharpEntity(cenv, tcref) :>_
1970-
| Item.RecdField rfinfo -> FSharpField(cenv, Recd rfinfo.RecdFieldRef) :> _
2013+
| Item.RecdField rfinfo -> FSharpField(cenv, RecdOrClass rfinfo.RecdFieldRef) :> _
2014+
2015+
| Item.ILField finfo -> FSharpField(cenv, ILField (cenv.g, finfo)) :> _
19712016

19722017
| Item.Event einfo ->
19732018
FSharpMemberOrFunctionOrValue(cenv, E einfo, item) :> _

‎tests/service/CSharpProjectAnalysis.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ let _ = CSharpOuterClass.InnerClass.StaticMember()
111111
|> Async.RunSynchronously
112112
|> Array.map (fun su -> su.Symbol.ToString())
113113
|> shouldEqual
114-
[|"InnerEnum"; "CSharpOuterClass"; "symbol Case1"; "InnerClass";
114+
[|"InnerEnum"; "CSharpOuterClass"; "field Case1"; "InnerClass";
115115
"CSharpOuterClass"; "member StaticMember"; "NestedEnumClass"|]

‎tests/service/InteractiveCheckerTests.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ let identsAndRanges (input: Ast.ParsedInput) =
4848
(identAndRange (longIdentToString longIdent) range) :: (moduleDecls |> List.collect extractFromModuleDecl)
4949

5050
match input with
51-
| Ast.ImplFile(Ast.ParsedImplFileInput(_, _, _, _, _, modulesOrNamespaces, _)) ->
51+
| Ast.ParsedInput.ImplFile(Ast.ParsedImplFileInput(_, _, _, _, _, modulesOrNamespaces, _)) ->
5252
modulesOrNamespaces |> List.collect extractFromModuleOrNamespace
53-
| Ast.SigFile _ -> []
53+
| Ast.ParsedInput.SigFile _ -> []
5454

5555
let parseAndExtractRanges code =
5656
let file = "/home/user/Test.fsx"

‎tests/service/ProjectAnalysisTests.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2906,7 +2906,7 @@ let ``Test Project19 all symbols`` () =
29062906
("DayOfWeek", "DayOfWeek", "file1", ((10, 15), (10, 24)), [],
29072907
["enum"; "valuetype"]);
29082908
("System", "System", "file1", ((10, 8), (10, 14)), [], ["namespace"]);
2909-
("symbol Monday", "Monday", "file1", ((10, 8), (10, 31)), [], []);
2909+
("field Monday", "Monday", "file1", ((10, 8), (10, 31)), [], ["field"; "mutable"; "static"; "1"]);
29102910
("val s", "s", "file1", ((10, 4), (10, 5)), ["defn"], ["val"]);
29112911
("Impl", "Impl", "file1", ((2, 7), (2, 11)), ["defn"], ["module"])|]
29122912

0 commit comments

Comments
 (0)
Please sign in to comment.