@@ -9,7 +9,7 @@ open Shared
9
9
// Global Pt.print target
10
10
let Pt = StringPrinter()
11
11
12
- // When dump webworker interfaces dom types are ignored
12
+ // When emit webworker interfaces dom types are ignored
13
13
let mutable ignoreDomType = false
14
14
15
15
/// Return a stringbuilder
@@ -117,8 +117,8 @@ let GetDefaultValue jsType =
117
117
118
118
let GetJsDefaultValueForDomType ( domType : string ) = domType |> DomTypeToJsType |> GetDefaultValue
119
119
120
- /// Dump event handlers that associated with an interface
121
- let DumpEvents ( i : Browser.Interface ) =
120
+ /// Emit event handlers that associated with an interface
121
+ let EmitEvents ( i : Browser.Interface ) =
122
122
match iNameToEhList.TryFind i.Name with
123
123
| Some ehList ->
124
124
ehList
@@ -132,7 +132,7 @@ let DumpEvents (i:Browser.Interface) =
132
132
else ())
133
133
| None -> ()
134
134
135
- let DumpProperties flavor ( i : Browser.Interface ) =
135
+ let EmitProperties flavor ( i : Browser.Interface ) =
136
136
let propNameToElmentMap = function
137
137
| " images" -> Some " img"
138
138
| " rows" -> Some " tr"
@@ -146,7 +146,7 @@ let DumpProperties flavor (i:Browser.Interface) =
146
146
| " tBodies" -> Some " tbody"
147
147
| _ -> None
148
148
149
- let DumpProperty ( p : Browser.Property ) =
149
+ let EmitProperty ( p : Browser.Property ) =
150
150
let value = p.Type |> DomTypeToJsType |> GetDefaultValue
151
151
match p with
152
152
| _ when p.Type = " EventHandler" -> ()
@@ -179,10 +179,10 @@ let DumpProperties flavor (i:Browser.Interface) =
179
179
| Some propCollection ->
180
180
propCollection.Properties
181
181
|> Array.filter ( ShouldKeep flavor)
182
- |> Array.iter DumpProperty
182
+ |> Array.iter EmitProperty
183
183
| None -> ()
184
184
185
- let DumpConstants suffix ( i : Browser.Interface ) =
185
+ let EmitConstants suffix ( i : Browser.Interface ) =
186
186
match i.Constants with
187
187
| Some cCollection ->
188
188
for c in cCollection.Constants do
@@ -192,26 +192,26 @@ let DumpConstants suffix (i:Browser.Interface) =
192
192
| _ -> Pt.printl " %s%s .%s = %s ;" i.Name suffix c.Name c.Value.Value
193
193
| None -> ()
194
194
195
- let DumpSignatureCommentDocs ( jsFunction : Function ) =
196
- let DumpSignatureDocForSingleParam ( p : Param ) =
195
+ let EmitSignatureCommentDocs ( jsFunction : Function ) =
196
+ let EmitSignatureDocForSingleParam ( p : Param ) =
197
197
let pJsType = DomTypeToJsType p.Type
198
198
199
199
( sprintf " /// <param name='%s ' type='%s '" p.Name pJsType) +
200
200
( if pJsType = " Array" then sprintf " elementType='%s ' " ( GetElementTypeForArray p.Type) else " " ) +
201
201
( if p.Optional then " optional='true' " else " " ) + " />"
202
202
|> Pt.printl " %s "
203
203
204
- let DumpSignatureDocForSingleOverload ( ol : Overload ) =
204
+ let EmitSignatureDocForSingleOverload ( ol : Overload ) =
205
205
if not ol.IsEmpty then
206
206
Pt.increaseIndent()
207
207
match ol.ReturnTypes.Length with
208
208
| 0 ->
209
209
Pt.printl " /// <signature>"
210
- ol.ParamCombinations |> List.iter DumpSignatureDocForSingleParam
210
+ ol.ParamCombinations |> List.iter EmitSignatureDocForSingleParam
211
211
Pt.printl " /// </signature>"
212
212
| 1 ->
213
213
Pt.printl " /// <signature>"
214
- ol.ParamCombinations |> List.iter DumpSignatureDocForSingleParam
214
+ ol.ParamCombinations |> List.iter EmitSignatureDocForSingleParam
215
215
match ol.ReturnTypes.[ 0 ] with
216
216
| " void" | " " -> ()
217
217
| arrayType when arrayType.StartsWith( " sequence<" ) -> Pt.printl " /// <returns type='Array' elementType='%s '/>" ( GetElementTypeForArray arrayType)
@@ -222,7 +222,7 @@ let DumpSignatureCommentDocs (jsFunction:Function) =
222
222
|> List.iter
223
223
( fun r ->
224
224
Pt.printl " /// <signature>"
225
- ol.ParamCombinations |> List.iter DumpSignatureDocForSingleParam
225
+ ol.ParamCombinations |> List.iter EmitSignatureDocForSingleParam
226
226
match r with
227
227
| " void" | " " -> ()
228
228
| arrayType when arrayType.StartsWith( " sequence<" ) -> Pt.printl " /// <returns type='Array' elementType='%s '/>" ( GetElementTypeForArray arrayType)
@@ -233,15 +233,15 @@ let DumpSignatureCommentDocs (jsFunction:Function) =
233
233
else ()
234
234
235
235
let overloads = GetOverloads jsFunction true
236
- if not overloads.IsEmpty then List.iter DumpSignatureDocForSingleOverload overloads
236
+ if not overloads.IsEmpty then List.iter EmitSignatureDocForSingleOverload overloads
237
237
238
- let DumpMethods ( i : Browser.Interface ) =
239
- let DumpMethod ( m : Browser.Method ) =
238
+ let EmitMethods ( i : Browser.Interface ) =
239
+ let EmitMethod ( m : Browser.Method ) =
240
240
// print declaration
241
241
let paramsStr = String.concat " , " [ for p in m.Params do yield AdjustParamName p.Name]
242
242
Pt.printl " %s .%s = function(%s ) {" i.Name m.Name.Value paramsStr
243
243
// print comment docs
244
- DumpSignatureCommentDocs ( Method m)
244
+ EmitSignatureCommentDocs ( Method m)
245
245
// print body
246
246
match i.Name, m.Name.Value with
247
247
| " EventTarget" , " addEventListener" -> Pt.printWithAddedIndent " _eventManager.add(this, type, listener);"
@@ -337,7 +337,7 @@ let DumpMethods (i:Browser.Interface) =
337
337
Pt.printl " };"
338
338
339
339
match i.Methods with
340
- | Some ms -> Seq.iter DumpMethod ms.Methods
340
+ | Some ms -> Seq.iter EmitMethod ms.Methods
341
341
| _ -> ()
342
342
343
343
// Explicitly expose 'toString' method for 'window'
@@ -353,7 +353,7 @@ let DumpMethods (i:Browser.Interface) =
353
353
return '';
354
354
};"
355
355
356
- let DumpInterfaceInit ( i : Browser.Interface ) =
356
+ let EmitInterfaceInit ( i : Browser.Interface ) =
357
357
let nodeType , nodeName =
358
358
match i.Name with
359
359
| " Text" -> " TEXT_NODE" , " #text"
@@ -431,24 +431,24 @@ let RegisterPublicInterfaces flavor =
431
431
i.NoInterfaceObject.IsNone then
432
432
Pt.printl " _publicInterface('%s ', {" i.Name
433
433
434
- // Dump constants
435
- let cDump =
434
+ // Emit constants
435
+ let cEmit =
436
436
match i.Constants with
437
437
| Some ( cs) ->
438
438
[ for c in cs.Constants do
439
439
yield " '" + c.Name + " ' : " + c.Value.String.Value]
440
440
| _ -> []
441
441
442
- // Dump static methods
443
- let mDump =
442
+ // Emit static methods
443
+ let mEmit =
444
444
match i.Methods with
445
445
| Some ( ms) ->
446
446
[ for m in ms.Methods do
447
447
if m.Static.IsSome then
448
448
yield String.Format( " '{0}' : {1}.{0}" , m.Name.Value, i.Name)]
449
449
| _ -> []
450
450
451
- let combined = String.concat " ," ( List.append cDump mDump )
451
+ let combined = String.concat " ," ( List.append cEmit mEmit )
452
452
Pt.print " %s " ( combined.Trim( ',' ))
453
453
Pt.print " }, %s );" i.Name
454
454
@@ -459,29 +459,29 @@ let RegisterConstructors flavor =
459
459
| Some _ -> Pt.printl " _publicInterface('%s ', %s Ctor , %s );" i.Name i.Name i.Name
460
460
| _ -> ()
461
461
462
- let DumpConstructor ( i : Browser.Interface ) =
462
+ let EmitConstructor ( i : Browser.Interface ) =
463
463
match i.Constructor with
464
- | Some _ -> DumpConstants " Ctor" i
464
+ | Some _ -> EmitConstants " Ctor" i
465
465
| None -> ()
466
466
467
- let DumpInterface flavor ( i : Browser.Interface ) =
467
+ let EmitInterface flavor ( i : Browser.Interface ) =
468
468
Pt.printl " "
469
469
Pt.printl " /* -- type: %s -- */" i.Name
470
470
Pt.printl " "
471
471
472
- // Dump impletented interfaces
472
+ // Emit impletented interfaces
473
473
i.Implements |> Array.iter ( fun im -> Pt.printl " _$implement(%s , %s );" i.Name im)
474
474
if i.Name = GetGlobalPollutorName flavor then
475
475
// if the interface is the global pollutor, inherits becomes implements
476
476
Pt.printl " _$implement(%s , %s );" i.Name i.Extends
477
477
478
- // Dump other contents
479
- DumpConstructor i
480
- DumpProperties flavor i
481
- DumpConstants " " i
482
- DumpMethods i
483
- DumpInterfaceInit i
484
- DumpEvents i
478
+ // Emit other contents
479
+ EmitConstructor i
480
+ EmitProperties flavor i
481
+ EmitConstants " " i
482
+ EmitMethods i
483
+ EmitInterfaceInit i
484
+ EmitEvents i
485
485
486
486
// Deal with array types
487
487
if i.Name.EndsWith( " List" ) || i.Name.EndsWith( " Collection" ) then
@@ -497,15 +497,15 @@ let DumpInterface flavor (i:Browser.Interface) =
497
497
| None -> ()
498
498
| None -> ()
499
499
500
- let DumpCallBackFunctions flavor =
501
- let DumpCallBackFunction ( cb : Browser.CallbackFunction ) =
500
+ let EmitCallBackFunctions flavor =
501
+ let EmitCallBackFunction ( cb : Browser.CallbackFunction ) =
502
502
let paramsStr = cb.Params |> Array.map ( fun p -> p.Name) |> String.concat " , "
503
503
Pt.printl " var %s = function(%s ) {" cb.Name paramsStr
504
- DumpSignatureCommentDocs ( CallBackFun cb)
504
+ EmitSignatureCommentDocs ( CallBackFun cb)
505
505
if cb.Type <> " void" then Pt.printWithAddedIndent " return %s ;" ( DomTypeToJsType cb.Type)
506
506
Pt.printl " };"
507
507
GetCallbackFuncsByFlavor flavor
508
- |> Array.iter DumpCallBackFunction
508
+ |> Array.iter EmitCallBackFunction
509
509
510
510
let RegisterCallBackFunctions flavor =
511
511
let RegisterCallBackFunction ( cb : Browser.CallbackFunction ) =
@@ -521,26 +521,26 @@ let RegisterDictionaries () =
521
521
browser.Dictionaries
522
522
|> Array.iter RegisterDictionary
523
523
524
- let DumpDictionaries () =
525
- let DumpDictionary ( d : Browser.Dictionary ) =
524
+ let EmitDictionaries () =
525
+ let EmitDictionary ( d : Browser.Dictionary ) =
526
526
Pt.printl " "
527
527
Pt.printl " /* -- type: %s -- */" d.Name
528
528
Pt.printl " "
529
529
530
- // Dump members
530
+ // Emit members
531
531
for m in d.Members do
532
532
let defaultValue = match m.Default.String with
533
533
| Some dv -> dv
534
534
| None -> GetJsDefaultValueForDomType m.Type
535
535
Pt.printl " %s .%s = %s ;" d.Name m.Name defaultValue
536
536
537
- browser.Dictionaries |> Array.iter DumpDictionary
537
+ browser.Dictionaries |> Array.iter EmitDictionary
538
538
539
- let DumpInterfaces flavor =
539
+ let EmitInterfaces flavor =
540
540
let sortedTypes = SortInterfaces ( GetAllInterfacesByFlavor flavor)
541
- for t in sortedTypes do DumpInterface flavor t
541
+ for t in sortedTypes do EmitInterface flavor t
542
542
543
- let DumpEventTypeToObjSwitchStatement flavor ignoreCase =
543
+ let EmitEventTypeToObjSwitchStatement flavor ignoreCase =
544
544
Pt.printl " switch (type) {"
545
545
Pt.increaseIndent()
546
546
@@ -570,7 +570,7 @@ let DumpEventTypeToObjSwitchStatement flavor ignoreCase =
570
570
Pt.decreaseIndent()
571
571
Pt.printl " }"
572
572
573
- let DumpGetElementByTagNameSwitchStatement () =
573
+ let EmitGetElementByTagNameSwitchStatement () =
574
574
Pt.printl " switch (tagName.toLowerCase()) {"
575
575
576
576
Pt.increaseIndent()
@@ -581,9 +581,9 @@ let DumpGetElementByTagNameSwitchStatement () =
581
581
582
582
Pt.print " }"
583
583
584
- /// Dump the _createEvent function
585
- let DumpCreateEventSwitchStatement () =
586
- // Dump the switch statements
584
+ /// Emit the _createEvent function
585
+ let EmitCreateEventSwitchStatement () =
586
+ // Emit the switch statements
587
587
Pt.printl " switch(eventType.toLowerCase()) {"
588
588
589
589
distinctETypeList
@@ -603,8 +603,8 @@ let DumpCreateEventSwitchStatement () =
603
603
604
604
Pt.printl " }"
605
605
606
- let DumpDeclarations flavor =
607
- let DumpInterfaceDeclaration ( i : Browser.Interface ) =
606
+ let EmitDeclarations flavor =
607
+ let EmitInterfaceDeclaration ( i : Browser.Interface ) =
608
608
let init =
609
609
match i.Name with
610
610
| name when name = GetGlobalPollutorName flavor -> " this"
@@ -623,7 +623,7 @@ let DumpDeclarations flavor =
623
623
" function(" + pList + " )"
624
624
Pt.printl " var %s Ctor = %s { " i.Name functionDeclare
625
625
if ctor.Params.Length > 0 then
626
- DumpSignatureCommentDocs ( Ctor ctor)
626
+ EmitSignatureCommentDocs ( Ctor ctor)
627
627
Pt.printWithAddedIndent " return Object.create(%s );" i.Name
628
628
Pt.printl " };"
629
629
else
@@ -633,30 +633,30 @@ let DumpDeclarations flavor =
633
633
634
634
GetAllInterfacesByFlavor flavor
635
635
|> SortInterfaces
636
- |> Array.iter DumpInterfaceDeclaration
636
+ |> Array.iter EmitInterfaceDeclaration
637
637
638
638
if flavor <> Worker then
639
- let DumpDictDeclaration ( d : Browser.Dictionary ) =
639
+ let EmitDictDeclaration ( d : Browser.Dictionary ) =
640
640
match d.Extends with
641
641
| " Object" -> Pt.printl " var %s = {};" d.Name
642
642
| _ -> Pt.printl " var %s = _$inherit(%s );" d.Name d.Extends
643
643
browser.Dictionaries
644
644
|> SortDicts
645
- |> Array.iter DumpDictDeclaration
645
+ |> Array.iter EmitDictDeclaration
646
646
647
- let DumpXmlContent flavor =
648
- DumpDeclarations flavor
649
- DumpCallBackFunctions flavor
650
- DumpInterfaces flavor
647
+ let EmitXmlContent flavor =
648
+ EmitDeclarations flavor
649
+ EmitCallBackFunctions flavor
650
+ EmitInterfaces flavor
651
651
if flavor <> Worker then
652
- DumpDictionaries ()
652
+ EmitDictionaries ()
653
653
654
654
655
655
let RegisterPublicObjs flavor =
656
656
RegisterPublicInterfaces flavor
657
657
RegisterConstructors flavor
658
658
659
- /// Adjust the indention of the printer, and dump the indented content in the printer,
659
+ /// Adjust the indention of the printer, and emit the indented content in the printer,
660
660
/// and then replace the place holder text with the content in printer
661
661
let ReplaceWithIndentedFuncResult ( placeHolder : String ) func ( sb : StringBuilder ) =
662
662
let curText = sb.ToString()
@@ -667,23 +667,23 @@ let ReplaceWithIndentedFuncResult (placeHolder: String) func (sb: StringBuilder)
667
667
func() |> ignore
668
668
sb.Replace( placeHolder, Pt.getResult())
669
669
670
- let DumpTheWholeThing flavor ( target : TextWriter ) =
670
+ let EmitTheWholeThing flavor ( target : TextWriter ) =
671
671
Pt.reset()
672
672
673
673
let template = LoadTemplate ( __ SOURCE_ DIRECTORY__ + @" \inputfiles\jsTemplate.js" )
674
674
675
675
let content =
676
676
template
677
677
|> ReplaceWithIndentedFuncResult " <@ EventTypeToObjSwitchStatements @>"
678
- ( fun () -> DumpEventTypeToObjSwitchStatement flavor false )
678
+ ( fun () -> EmitEventTypeToObjSwitchStatement flavor false )
679
679
|> ReplaceWithIndentedFuncResult " <@ EventTypeToObjSwitchStatementsIgnoreCase @>"
680
- ( fun () -> DumpEventTypeToObjSwitchStatement flavor true )
680
+ ( fun () -> EmitEventTypeToObjSwitchStatement flavor true )
681
681
|> ReplaceWithIndentedFuncResult " <@ CreateEventSwitchStatements @>"
682
- DumpCreateEventSwitchStatement
682
+ EmitCreateEventSwitchStatement
683
683
|> ReplaceWithIndentedFuncResult " <@ GetElementsByTagNameSwitchStatements @>"
684
- DumpGetElementByTagNameSwitchStatement
684
+ EmitGetElementByTagNameSwitchStatement
685
685
|> ReplaceWithIndentedFuncResult " <@ XMLContents @>"
686
- ( fun () -> DumpXmlContent flavor)
686
+ ( fun () -> EmitXmlContent flavor)
687
687
|> ReplaceWithIndentedFuncResult " <@ Public Interfaces @>"
688
688
( fun () -> RegisterPublicObjs flavor)
689
689
|> ( fun sb -> sb.Replace( " <@ GlobalPolluter @>" , GetGlobalPollutorName flavor))
@@ -692,13 +692,13 @@ let DumpTheWholeThing flavor (target: TextWriter) =
692
692
fprintf target " %s " content
693
693
target.Flush()
694
694
695
- let DumpDomWeb () =
696
- DumpTheWholeThing Web GlobalVars.jsWebOutput
695
+ let EmitDomWeb () =
696
+ EmitTheWholeThing Flavor. Web GlobalVars.jsWebOutput
697
697
698
- let DumpDomWin () =
699
- DumpTheWholeThing Windows GlobalVars.jsWinOutput
698
+ let EmitDomWin () =
699
+ EmitTheWholeThing Flavor.All GlobalVars.jsWinOutput
700
700
701
- let DumpDomWorker () =
701
+ let EmitDomWorker () =
702
702
Pt.reset()
703
703
704
704
ignoreDomType <- true
@@ -707,9 +707,9 @@ let DumpDomWorker () =
707
707
let content =
708
708
template
709
709
|> ReplaceWithIndentedFuncResult " <@ EventTypeToObjSwitchStatements @>"
710
- ( fun () -> DumpEventTypeToObjSwitchStatement Worker false )
710
+ ( fun () -> EmitEventTypeToObjSwitchStatement Worker false )
711
711
|> ReplaceWithIndentedFuncResult " <@ XMLContents @>"
712
- ( fun () -> DumpXmlContent Worker)
712
+ ( fun () -> EmitXmlContent Worker)
713
713
|> ReplaceWithIndentedFuncResult " <@ Public Interfaces @>"
714
714
( fun () -> RegisterPublicObjs Worker)
715
715
|> ( fun sb -> sb.Replace( " <@ GlobalPolluter @>" , GetGlobalPollutorName Worker))
0 commit comments