-
Notifications
You must be signed in to change notification settings - Fork 46
[JExtract] Import Foundation.Data
if used
#301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a53dbd4
to
9f2c63e
Compare
Foundation.Data
if usedFoundation.Data
if used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool, lgtm -- some minor things inline
// FIXME: Make this conditional. | ||
outputSwiftFiles += [ | ||
outputSwiftDirectory.appending(path: "Data+SwiftJava.swift") | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That FIXME will be hard to resolve... we'd have to grep files manually for any foundation imports etc I guess before we run any of the commands :(
But yeah, good to keep that fixme
var str = retBytes.getString(0); | ||
SwiftRuntime.trace("retStr=" + str); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
btw I'm thinking we should start trying to move all these examples into tests, so we'll get a better report "what failed" when CI fails.
But this we can do later separately
@@ -65,6 +63,9 @@ package class FFMSwift2JavaGenerator: Swift2JavaGenerator { | |||
return String(filePathPart.replacing(".swift", with: "+SwiftJava.swift")) | |||
}) | |||
self.expectedOutputSwiftFiles.insert("\(translator.swiftModuleName)Module+SwiftJava.swift") | |||
|
|||
// FIXME: Can we avoid this? | |||
self.expectedOutputSwiftFiles.insert("Data+SwiftJava.swift") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is unavoidable in today's SwiftPM.
Can we call the file Foundation_Data+SwiftJava.swift
maybe? just to lessen the chance of clashing with some user defined Data type?
FYI ongoing sadness with build plugins @bnbarham heh
if let dataDecl = self.symbolTable[.data] { | ||
if self.isUsing(dataDecl) { | ||
visitor.visit(nominalDecl: dataDecl.syntax!.asNominal!, in: nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Good enough for our current needs.
public init(cString: UnsafePointer<Int8>) | ||
public func withCString(_ body: (UnsafePointer<Int8>) -> Void) | ||
} | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense but I'm a bit worried about those "inline" pseudo-interface files... While we can't use the real files... maybe we could make this info at least real files and not just strings hardcoded like this, put them in SwiftTypes/KnownModules/Foundation.swiftinterface
and then use them using the Bundle
APIs? Seems that could work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try making them resources in followups
// If we have already recorded a nominal type with the name in this module, | ||
// it's an invalid redeclaration. | ||
if let _ = symbolTable.lookupType(node.name.text, parent: parent) { | ||
// TODO: Diagnose? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be good to at least log on debug here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I forgot to hook up the Logger
passed in to SwiftSymbolTable.setup()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s be nice to do probably, thank you
if importedType.methods.contains(where: check) { | ||
return true | ||
} | ||
if importedGlobalVariables.contains(where: check) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if importedGlobalVariables.contains(where: check) { | |
if importedType.variables.contains(where: check) { |
Instead of the pointer to the value witness table. Witnesses expect type metadata.
* Introduce `KnownSwiftModules` to represent `Swift` and `Foundation` modules. * `SwiftSymbolTable.setup()` is now a factory method to create `SwiftSymbolTable`. It scans the source file for module dependency. If `import Foundation` is found, add `Foundation` from the `KnownSwiftModules` (Just `Data` for now) * In `Swift2JavaTranslator` import `Data` APIs if any of the imported APIs use `Data` * `Data` has limited hardcoded APIs `init(bytes:count:)`, `getter:count`, and `withUnsafeBytes(_:)`. * Add `import Foundation` in Swift thunk if any of the the original source files import it
9d37c22
to
c2f683e
Compare
KnownSwiftModules
to representSwift
andFoundation
modules.SwiftSymbolTable.setup()
is now a factory method to createSwiftSymbolTable
. It scans the source file for module dependency. Ifimport Foundation
is found, addFoundation
from theKnownSwiftModules
(JustData
for now)Swift2JavaTranslator
importData
APIs if any of the imported APIs useData
Data
has limited hardcoded APIsinit(bytes:count:)
,getter:count
, andwithUnsafeBytes(_:)
.import Foundation
in Swift thunk if any of the the original source files import it