@@ -136,9 +136,15 @@ public override bool VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
136
136
return VisitPrimitiveType ( builtin . Type ) ;
137
137
}
138
138
139
+ public override bool VisitEnumItemDecl ( Enumeration . Item item )
140
+ {
141
+ var @enum = item . Namespace as Enumeration ;
142
+ return VisitPrimitiveType ( @enum . BuiltinType . Type ) ;
143
+ }
144
+
139
145
public bool VisitPrimitiveType ( PrimitiveType primitive )
140
146
{
141
- var retName = Generator . GeneratedIdentifier ( Context . ArgName ) ;
147
+ var retName = Generator . GeneratedIdentifier ( Context . ReturnVarName ) ;
142
148
Context . Before . Write ( $ "JSValue { retName } = ") ;
143
149
144
150
switch ( primitive )
@@ -341,10 +347,9 @@ public override bool VisitTypedefDecl(TypedefDecl typedef)
341
347
342
348
public override bool VisitEnumDecl ( Enumeration @enum )
343
349
{
344
- var typePrinter = new CppTypePrinter ( Context . Context ) ;
345
- typePrinter . PushContext ( TypePrinterContextKind . Managed ) ;
346
- var typeName = typePrinter . VisitDeclaration ( @enum ) ;
347
- Context . Return . Write ( $ "({ typeName } ){ Context . ReturnVarName } ") ;
350
+ var retName = Generator . GeneratedIdentifier ( Context . ReturnVarName ) ;
351
+ Context . Before . WriteLine ( $ "JSValue { retName } = JS_NewInt32(ctx, (int32_t) { Context . ReturnVarName } );") ;
352
+ Context . Return . Write ( retName ) ;
348
353
349
354
return true ;
350
355
}
@@ -492,72 +497,82 @@ public bool VisitPrimitiveType(PrimitiveType primitive)
492
497
var typePrinter = new CppTypePrinter ( Context . Context ) ;
493
498
var type = typePrinter . VisitPrimitiveType ( primitive ) ;
494
499
495
- Context . Before . WriteLine ( $ "{ type } { Context . ArgName } ;") ;
500
+ var argName = Context . Parameter . Name ;
501
+ Context . Before . WriteLine ( $ "{ type } { argName } ;") ;
496
502
497
503
switch ( primitive )
498
504
{
499
505
case PrimitiveType . Void :
500
506
return true ;
501
507
502
508
case PrimitiveType . Bool :
503
- Context . Before . WriteLine ( $ "{ Context . ArgName } = JS_ToBool(ctx, argv[{ Context . ParameterIndex } ]);") ;
504
- Context . Before . WriteLine ( $ "if ({ Context . ArgName } == -1)") ;
509
+ Context . Before . WriteLine ( $ "{ argName } = JS_ToBool(ctx, argv[{ Context . ParameterIndex } ]);") ;
510
+ Context . Before . WriteLine ( $ "if ({ argName } == -1)") ;
505
511
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
512
+ Context . Return . Write ( $ "{ argName } ") ;
506
513
return true ;
507
514
508
515
case PrimitiveType . Char :
509
516
case PrimitiveType . SChar :
510
517
case PrimitiveType . UChar :
511
- Context . Before . WriteLine ( $ "int32_t _{ Context . ArgName } ;") ;
512
- Context . Before . WriteLine ( $ "if (JS_ToInt32(ctx, &_{ Context . ArgName } , argv[{ Context . ParameterIndex } ]))") ;
518
+ Context . Before . WriteLine ( $ "int32_t _{ argName } ;") ;
519
+ Context . Before . WriteLine ( $ "if (JS_ToInt32(ctx, &_{ argName } , argv[{ Context . ParameterIndex } ]))") ;
513
520
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
514
- Context . Before . WriteLine ( $ "{ Context . ArgName } = ({ type } )_{ Context . ArgName } ;") ;
521
+ Context . Before . WriteLine ( $ "{ argName } = ({ type } )_{ argName } ;") ;
522
+ Context . Return . Write ( $ "{ argName } ") ;
515
523
return true ;
516
524
517
525
case PrimitiveType . Short :
518
526
case PrimitiveType . UShort :
519
- Context . Before . WriteLine ( $ "int32_t _{ Context . ArgName } ;") ;
520
- Context . Before . WriteLine ( $ "if (JS_ToInt32(ctx, &_{ Context . ArgName } , argv[{ Context . ParameterIndex } ]))") ;
527
+ Context . Before . WriteLine ( $ "int32_t _{ argName } ;") ;
528
+ Context . Before . WriteLine ( $ "if (JS_ToInt32(ctx, &_{ argName } , argv[{ Context . ParameterIndex } ]))") ;
521
529
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
522
- Context . Before . WriteLine ( $ "{ Context . ArgName } = ({ type } )_{ Context . ArgName } ;") ;
530
+ Context . Before . WriteLine ( $ "{ argName } = ({ type } )_{ argName } ;") ;
531
+ Context . Return . Write ( $ "{ argName } ") ;
523
532
return true ;
524
533
525
534
case PrimitiveType . Int :
526
535
case PrimitiveType . Long :
527
- Context . Before . WriteLine ( $ "if (JS_ToInt32(ctx, &{ Context . ArgName } , argv[{ Context . ParameterIndex } ]))") ;
536
+ Context . Before . WriteLine ( $ "if (JS_ToInt32(ctx, &{ argName } , argv[{ Context . ParameterIndex } ]))") ;
528
537
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
538
+ Context . Return . Write ( $ "{ argName } ") ;
529
539
return true ;
530
540
531
541
case PrimitiveType . UInt :
532
542
case PrimitiveType . ULong :
533
- Context . Before . WriteLine ( $ "if (JS_ToUint32(ctx, &{ Context . ArgName } , argv[{ Context . ParameterIndex } ]))") ;
543
+ Context . Before . WriteLine ( $ "if (JS_ToUint32(ctx, &{ argName } , argv[{ Context . ParameterIndex } ]))") ;
534
544
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
545
+ Context . Return . Write ( $ "{ argName } ") ;
535
546
return true ;
536
547
537
548
case PrimitiveType . LongLong :
538
- Context . Before . WriteLine ( $ "int64_t _{ Context . ArgName } ;") ;
539
- Context . Before . WriteLine ( $ "if (JS_ToInt64Ext(ctx, &_{ Context . ArgName } , argv[{ Context . ParameterIndex } ]))") ;
549
+ Context . Before . WriteLine ( $ "int64_t _{ argName } ;") ;
550
+ Context . Before . WriteLine ( $ "if (JS_ToInt64Ext(ctx, &_{ argName } , argv[{ Context . ParameterIndex } ]))") ;
540
551
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
541
- Context . Before . WriteLine ( $ "{ Context . ArgName } = ({ type } )_{ Context . ArgName } ;") ;
552
+ Context . Before . WriteLine ( $ "{ argName } = ({ type } )_{ argName } ;") ;
553
+ Context . Return . Write ( $ "{ argName } ") ;
542
554
return true ;
543
555
544
556
case PrimitiveType . ULongLong :
545
- Context . Before . WriteLine ( $ "int64_t _{ Context . ArgName } ;") ;
546
- Context . Before . WriteLine ( $ "if (JS_ToInt64Ext(ctx, &_{ Context . ArgName } , argv[{ Context . ParameterIndex } ]))") ;
557
+ Context . Before . WriteLine ( $ "int64_t _{ argName } ;") ;
558
+ Context . Before . WriteLine ( $ "if (JS_ToInt64Ext(ctx, &_{ argName } , argv[{ Context . ParameterIndex } ]))") ;
547
559
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
548
- Context . Before . WriteLine ( $ "{ Context . ArgName } = ({ type } )_{ Context . ArgName } ;") ;
560
+ Context . Before . WriteLine ( $ "{ argName } = ({ type } )_{ argName } ;") ;
561
+ Context . Return . Write ( $ "{ argName } ") ;
549
562
return true ;
550
563
551
564
case PrimitiveType . Float :
552
- Context . Before . WriteLine ( $ "double _{ Context . ArgName } ;") ;
553
- Context . Before . WriteLine ( $ "if (JS_ToFloat64(ctx, &_{ Context . ArgName } , argv[{ Context . ParameterIndex } ]))") ;
565
+ Context . Before . WriteLine ( $ "double _{ argName } ;") ;
566
+ Context . Before . WriteLine ( $ "if (JS_ToFloat64(ctx, &_{ argName } , argv[{ Context . ParameterIndex } ]))") ;
554
567
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
555
- Context . Before . WriteLine ( $ "{ Context . ArgName } = ({ type } )_{ Context . ArgName } ;") ;
568
+ Context . Before . WriteLine ( $ "{ argName } = ({ type } )_{ argName } ;") ;
569
+ Context . Return . Write ( $ "{ argName } ") ;
556
570
return true ;
557
571
558
572
case PrimitiveType . Double :
559
- Context . Before . WriteLine ( $ "if (JS_ToFloat64(ctx, &{ Context . ArgName } , argv[{ Context . ParameterIndex } ]))") ;
573
+ Context . Before . WriteLine ( $ "if (JS_ToFloat64(ctx, &{ argName } , argv[{ Context . ParameterIndex } ]))") ;
560
574
Context . Before . WriteLineIndent ( "return JS_EXCEPTION;" ) ;
575
+ Context . Return . Write ( $ "{ argName } ") ;
561
576
return true ;
562
577
563
578
case PrimitiveType . WideChar :
@@ -747,8 +762,11 @@ public override bool VisitTypedefDecl(TypedefDecl typedef)
747
762
748
763
public override bool VisitEnumDecl ( Enumeration @enum )
749
764
{
750
- Context . Return . Write ( "(::{0}){1}" , @enum . QualifiedOriginalName ,
751
- Context . Parameter . Name ) ;
765
+ VisitPrimitiveType ( @enum . BuiltinType . Type ) ;
766
+
767
+ Context . Return . StringBuilder . Clear ( ) ;
768
+ Context . Return . Write ( $ "(::{ @enum . QualifiedOriginalName } ){ Context . Parameter . Name } ") ;
769
+
752
770
return true ;
753
771
}
754
772
0 commit comments