File tree Expand file tree Collapse file tree 7 files changed +45
-5
lines changed Expand file tree Collapse file tree 7 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 99 ` Declarations.includeMemberSet ` , ` Declarations.useOriginalName ` ,
1010 ` Declarations.renameWithMap ` , ` Declarations.useMemberOriginalName ` , and
1111 ` Declarations.renameMemberWithMap ` .
12+ - Fix [ a bug] ( https://github.com/dart-lang/native/issues/2782 ) where unnamed
13+ enum constants were being multiply defined.
1214- Fix [ a bug] ( https://github.com/dart-lang/native/issues/2761 ) in imported
1315 NS_OPTIONS enums.
1416- Fix [ a bug] ( https://github.com/dart-lang/native/issues/2760 ) in the internal
Original file line number Diff line number Diff line change @@ -19,7 +19,11 @@ import '../utils.dart';
1919
2020/// Adds a macro definition to be parsed later.
2121void saveMacroDefinition (Context context, clang_types.CXCursor cursor) {
22+ final bindingsIndex = context.bindingsIndex;
2223 final macroUsr = cursor.usr ();
24+ if (bindingsIndex.isSeenMacro (macroUsr)) {
25+ return ;
26+ }
2327 final originalMacroName = cursor.spelling ();
2428 final decl = Declaration (usr: macroUsr, originalName: originalMacroName);
2529 if (clang.clang_Cursor_isMacroBuiltin (cursor) == 0 &&
@@ -30,7 +34,7 @@ void saveMacroDefinition(Context context, clang_types.CXCursor cursor) {
3034 '${cursor .completeStringRepr ()}' ,
3135 );
3236 final prefixedName = context.config.macros.rename (decl);
33- context. bindingsIndex.addMacroToSeen (macroUsr, prefixedName);
37+ bindingsIndex.addMacroToSeen (macroUsr, prefixedName);
3438 _saveMacro (prefixedName, macroUsr, originalMacroName, context);
3539 }
3640}
Original file line number Diff line number Diff line change @@ -48,6 +48,13 @@ Constant? _addUnNamedEnumConstant(
4848 final logger = context.logger;
4949 final config = context.config;
5050 final bindingsIndex = context.bindingsIndex;
51+
52+ final usr = cursor.usr ();
53+ final oldConstant = bindingsIndex.getSeenUnnamedEnumConstant (usr);
54+ if (oldConstant != null ) {
55+ return oldConstant;
56+ }
57+
5158 final unnamedEnumConstants = context.unnamedEnumConstants;
5259 final apiAvailability = ApiAvailability .fromCursor (cursor, context);
5360 if (apiAvailability.availability == Availability .none) {
@@ -59,7 +66,7 @@ Constant? _addUnNamedEnumConstant(
5966 '++++ Adding Constant from unnamed enum: ${cursor .completeStringRepr ()}' ,
6067 );
6168 final constant = UnnamedEnumConstant (
62- usr: cursor. usr () ,
69+ usr: usr,
6370 originalName: cursor.spelling (),
6471 name: config.unnamedEnums.rename (
6572 Declaration (usr: cursor.usr (), originalName: cursor.spelling ()),
Original file line number Diff line number Diff line change @@ -510,8 +510,6 @@ class BindingsIndex {
510510 bool isSeenFunc (String usr) => _functions.containsKey (usr);
511511 void addFuncToSeen (String usr, Func func) => _functions[usr] = func;
512512 Func ? getSeenFunc (String usr) => _functions[usr];
513- bool isSeenUnnamedEnumConstant (String usr) =>
514- _unnamedEnumConstants.containsKey (usr);
515513 void addUnnamedEnumConstantToSeen (String usr, Constant enumConstant) =>
516514 _unnamedEnumConstants[usr] = enumConstant;
517515 Constant ? getSeenUnnamedEnumConstant (String usr) =>
@@ -521,7 +519,6 @@ class BindingsIndex {
521519 Global ? getSeenGlobalVar (String usr) => _globals[usr];
522520 bool isSeenMacro (String usr) => _macros.containsKey (usr);
523521 void addMacroToSeen (String usr, String macro ) => _macros[usr] = macro ;
524- String ? getSeenMacro (String usr) => _macros[usr];
525522 bool isSeenUnsupportedTypealias (String usr) =>
526523 _unsupportedTypealiases.contains (usr);
527524 void addUnsupportedTypealiasToSeen (String usr) =>
Original file line number Diff line number Diff line change 77 include :
88 - Fruit
99 - CoffeeOptions
10+ unnamed-enums :
11+ include :
12+ - UnnamedEnumValue
13+ macros :
14+ include :
15+ - SOME_MACRO
1016objc-interfaces :
1117 include :
1218 - EnumTestInterface
1319headers :
1420 entry-points :
21+ # Multiple includes to repro https://github.com/dart-lang/native/issues/2782
22+ - ' enum_test.m'
23+ - ' enum_test.m'
1524 - ' enum_test.m'
Original file line number Diff line number Diff line change @@ -54,6 +54,21 @@ void main() {
5454 );
5555 });
5656
57+ test ('Multi def regression test' , () {
58+ // Regression test for https://github.com/dart-lang/native/issues/2782
59+ final bindings = File (
60+ path.join (
61+ packagePathForTests,
62+ 'test' ,
63+ 'native_objc_test' ,
64+ 'enum_bindings.dart' ,
65+ ),
66+ ).readAsStringSync ();
67+
68+ expect (bindings, isNot (contains ('UnnamedEnumValue\$ 1' )));
69+ expect (bindings, isNot (contains ('SOME_MACRO\$ 1' )));
70+ });
71+
5772 test ('Imported enum' , () {
5873 // Regression test for https://github.com/dart-lang/native/issues/2761
5974 expect (
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ typedef NS_OPTIONS(NSUInteger, CoffeeOptions) {
1919 CoffeeOptionsIced = 1 << 2 ,
2020};
2121
22+ enum {
23+ UnnamedEnumValue,
24+ };
25+
26+ #define SOME_MACRO 123
27+
2228@interface EnumTestInterface : NSObject {}
2329
2430+(int32_t )useImportedNSEnum : (NSQualityOfService )x ;
You can’t perform that action at this time.
0 commit comments