Commit Graph

5 Commits

Author SHA1 Message Date
Jordan Rose
86203cad7e [ClangImporter] Import enum case aliases using static let properties.
I don't want to call this complete until
a) we handle using alias names in switch statements (right now they're
   straight-up rejected, not just non-complete), and
b) we prefer non-deprecated names over deprecated ones to be the "real"
   enum cases.
but this is a good start, and fixes them showing up poorly in the SDK
analyzer.

rdar://problem/18662118

Swift SVN r27130
2015-04-08 19:23:38 +00:00
Jordan Rose
7a6d8ea940 Revert "[ClangImporter] Add convert-inits for enums defined in terms of other enums."
This reverts r25401. After reviewing the issues this was intended to solve,
and then talking to Dave, I've decided that this doesn't actually solve
enough of the problems we wanted it to, and it creates added complexity,
so I'm taking it back out.

Originally rdar://problem/19667625.

Swift SVN r25489
2015-02-23 22:52:41 +00:00
Jordan Rose
eb1c542900 [test] Remove hardcoded LLVM register name in test/ClangModules/enum.swift.
Swift SVN r25402
2015-02-19 21:52:49 +00:00
Jordan Rose
83639ca702 [ClangImporter] Add convert-inits for enums defined in terms of other enums.
This pattern isn't too uncommon:

typedef CF_ENUM(CFIndex, CFFoo) {
  CFFooBar
};
typedef NS_ENUM(NSInteger, NSFoo) {
  NSFooBar = CFFooBar
};

NSFoo and CFFoo are distinct types, but sometimes you need to convert from
one to the other. Today the only way to do to that is via rawValue, which
is especially unpleasant if the raw types don't match.

This commit introduces a new converting initializer for NSFoo:

  init!(_ value: CFFoo) {
    self.init(rawValue: RawType(value.rawValue))
  }

It's failable by necessity because init(rawValue:) is failable for proper
enums. In practice an audit of our public headers found zero cases where
there are "more" cases in CFFoo than in NSFoo, i.e. cases where the
conversion would fail.

This also applies to option sets and opaque enums, but those use a
non-failable initializer because there's no way to check validity.

rdar://problem/19667625

Swift SVN r25401
2015-02-19 21:11:43 +00:00
Jordan Rose
229ddc0fe1 [test] Collapse three enum tests into one.
The next commit will add tests that mix different kinds of enums and the
division doesn't make too much sense at that point.

No functionality change.

Swift SVN r25400
2015-02-19 21:11:42 +00:00