Skip to content

Commit

Permalink
Standard binding updates (#1278)
Browse files Browse the repository at this point in the history
* #1275 - Add warning capability on properties and constructors as well

* #1274 #1276 #1277

* Minor cleanup
  • Loading branch information
Jooseppi12 authored Oct 27, 2022
1 parent 4c03314 commit 84d0d5a
Show file tree
Hide file tree
Showing 6 changed files with 955 additions and 175 deletions.
6 changes: 5 additions & 1 deletion src/compiler/WebSharper.Compiler/WIGCompile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ type MemberConverter
attr.ConstructorArguments.Add(CustomAttributeArgument(tB.String, warning))
attr

let setWarnAttribute (x: CodeModel.MethodBase) (attrs: Mono.Collections.Generic.Collection<CustomAttribute>) =
let setWarnAttribute (x: CodeModel.Entity) (attrs: Mono.Collections.Generic.Collection<CustomAttribute>) =
match x.Warning with
| Some warning -> attrs.Add (warnAttribute warning)
| _ -> ()
Expand Down Expand Up @@ -985,6 +985,7 @@ type MemberConverter
pD.SetMethod <- mD
setObsoleteAttribute p pD.CustomAttributes
addDependencies p pD.CustomAttributes
setWarnAttribute p pD.CustomAttributes
dT.Properties.Add pD

let withGenerics (generics: Code.TypeParameter list, td: Code.TypeDeclaration, owner) =
Expand Down Expand Up @@ -1019,6 +1020,7 @@ type MemberConverter
if x.Generics.Length > 0 then
tD.Name <- tD.Name + "`" + string x.Generics.Length
k (withGenerics (x.Generics, x, tD)) tD
setWarnAttribute x tD.CustomAttributes
| _ -> ()

member private c.AddMethod(dT: TypeDefinition, td: Code.TypeDeclaration, x: Code.Method) =
Expand Down Expand Up @@ -1095,6 +1097,7 @@ type MemberConverter
if not (propNames.Add name) then failwithf "Duplicate property definition: %s on %s" name x.Name
addProperty tD x name p
addDependencies x tD.CustomAttributes
setWarnAttribute x tD.CustomAttributes

member d.AddDependencies(ent: Code.IResourceDependable, prov: ICustomAttributeProvider) =
addDependencies ent prov.CustomAttributes
Expand Down Expand Up @@ -1122,6 +1125,7 @@ type MemberConverter
for ctor in x.Constructors do
addConstructor tD x ctor
setObsoleteAttribute x tD.CustomAttributes
setWarnAttribute x tD.CustomAttributes
c.AddTypeMembers(x, tD)

member c.Interface(x: Code.Interface) =
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/WebSharper.InterfaceGenerator/CodeModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module CodeModel =
val mutable DependsOn : list<Dependency>
val mutable Comment : option<string>
val mutable ObsoleteStatus : ObsoleteStatus
val mutable Warning : option<string>

internal new (name, t) =
{
Expand All @@ -50,6 +51,7 @@ module CodeModel =
DependsOn = []
Comment = None
ObsoleteStatus = NotObsolete
Warning = None
}

/// On type definitions, applies the update.
Expand Down Expand Up @@ -289,15 +291,13 @@ module CodeModel =
val mutable Inline : option<Inline>
val mutable IsPure : bool
val mutable Macro : option<T>
val mutable Warning : option<string>

internal new (name, t) =
{
inherit Member(name, t)
Inline = None
IsPure = false
Macro = None
Warning = None
}

and Constructor =
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/WebSharper.InterfaceGenerator/Pervasives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ module Pervasives =
let Pure (x: #Code.MethodBase) =
x |> Code.Entity.Update (fun x -> x.IsPure <- true)

/// Marks an method as a pure function call.
let WithWarning s (x: #Code.MethodBase) =
/// Adds a warning for the given code entity.
let WithWarning s (x: #Code.Entity) =
x |> Code.Entity.Update (fun x -> x.Warning <- Some s)

/// Adds an inline.
Expand Down
Loading

0 comments on commit 84d0d5a

Please # to comment.