Skip to content
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

Objective C Union support #706

Merged
merged 4 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

##### Enhancements

* None.
* Objective C Union support.
[Brian Osborn](https://github.com/bosborn)
[#705](https://github.com/jpsim/SourceKitten/issues/705)

##### Bug Fixes

Expand Down Expand Up @@ -85,7 +87,7 @@

* Fix crashes when parsing .m files.
[Joe Laws](https://github.com/jlaws)

* Stop the program immediately if the `xcodebuild` command fails.
[John Fairhurst](https://github.com/johnfairh)
[#643](https://github.com/jpsim/SourceKitten/issues/643)
Expand Down
3 changes: 3 additions & 0 deletions Source/SourceKittenFramework/ObjCDeclarationKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public enum ObjCDeclarationKind: String {
case mark = "sourcekitten.source.lang.objc.mark"
/// `struct`
case `struct` = "sourcekitten.source.lang.objc.decl.struct"
/// `union`
case `union` = "sourcekitten.source.lang.objc.decl.union"
/// `field`
case field = "sourcekitten.source.lang.objc.decl.field"
/// `ivar`
Expand All @@ -62,6 +64,7 @@ public enum ObjCDeclarationKind: String {
case CXCursor_VarDecl: self = .constant
case CXCursor_FunctionDecl: self = .function
case CXCursor_StructDecl: self = .struct
case CXCursor_UnionDecl: self = .union
case CXCursor_FieldDecl: self = .field
case CXCursor_ObjCIvarDecl: self = .ivar
case CXCursor_ModuleImportDecl: self = .moduleImport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ClangTranslationUnitTests: XCTestCase {
func testCodeFormattingObjectiveCDocs() {
compare(clangFixture: "CodeFormatting")
}

func testUnionObjectiveCDocs() {
compare(clangFixture: "Union")
}
}

#endif
1 change: 1 addition & 0 deletions Tests/SourceKittenFrameworkTests/Fixtures/Union.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typedef union { double a; int b; } VALUE;
139 changes: 139 additions & 0 deletions Tests/SourceKittenFrameworkTests/Fixtures/Union.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[
{
"Union.h" : {
"key.diagnostic_stage" : "",
"key.substructure" : [
{
"key.always_deprecated" : false,
"key.always_unavailable" : false,
"key.deprecation_message" : "",
"key.doc.column" : 9,
"key.doc.file" : "Union.h",
"key.doc.line" : 1,
"key.filepath" : "Union.h",
"key.kind" : "sourcekitten.source.lang.objc.decl.union",
"key.name" : "",
"key.parsed_declaration" : "union { double a; int b; }",
"key.parsed_scope.end" : 1,
"key.parsed_scope.start" : 1,
"key.substructure" : [
{
"key.always_deprecated" : false,
"key.always_unavailable" : false,
"key.deprecation_message" : "",
"key.doc.column" : 25,
"key.doc.file" : "Union.h",
"key.doc.line" : 1,
"key.filepath" : "Union.h",
"key.kind" : "sourcekitten.source.lang.objc.decl.field",
"key.name" : "a",
"key.parsed_declaration" : "double a",
"key.parsed_scope.end" : 1,
"key.parsed_scope.start" : 1,
"key.swift_declaration" : "var a: Double { get set }",
"key.swift_name" : "a",
"key.unavailable_message" : "",
"key.usr" : "c:@UA@VALUE@FI@a"
},
{
"key.always_deprecated" : false,
"key.always_unavailable" : false,
"key.deprecation_message" : "",
"key.doc.column" : 33,
"key.doc.file" : "Union.h",
"key.doc.line" : 1,
"key.filepath" : "Union.h",
"key.kind" : "sourcekitten.source.lang.objc.decl.field",
"key.name" : "b",
"key.parsed_declaration" : "int b",
"key.parsed_scope.end" : 1,
"key.parsed_scope.start" : 1,
"key.swift_declaration" : "var b: Int32 { get set }",
"key.swift_name" : "b",
"key.unavailable_message" : "",
"key.usr" : "c:@UA@VALUE@FI@b"
}
],
"key.swift_declaration" : "struct VALUE",
"key.swift_name" : "VALUE",
"key.unavailable_message" : "",
"key.usr" : "c:@UA@VALUE"
},
{
"key.always_deprecated" : false,
"key.always_unavailable" : false,
"key.deprecation_message" : "",
"key.doc.column" : 38,
"key.doc.file" : "Union.h",
"key.doc.line" : 1,
"key.filepath" : "Union.h",
"key.kind" : "sourcekitten.source.lang.objc.decl.typedef",
"key.name" : "VALUE",
"key.parsed_declaration" : "typedef union { double a; int b; } VALUE",
"key.parsed_scope.end" : 1,
"key.parsed_scope.start" : 1,
"key.substructure" : [
{
"key.always_deprecated" : false,
"key.always_unavailable" : false,
"key.deprecation_message" : "",
"key.doc.column" : 9,
"key.doc.file" : "Union.h",
"key.doc.line" : 1,
"key.filepath" : "Union.h",
"key.kind" : "sourcekitten.source.lang.objc.decl.union",
"key.name" : "",
"key.parsed_declaration" : "union { double a; int b; }",
"key.parsed_scope.end" : 1,
"key.parsed_scope.start" : 1,
"key.substructure" : [
{
"key.always_deprecated" : false,
"key.always_unavailable" : false,
"key.deprecation_message" : "",
"key.doc.column" : 25,
"key.doc.file" : "Union.h",
"key.doc.line" : 1,
"key.filepath" : "Union.h",
"key.kind" : "sourcekitten.source.lang.objc.decl.field",
"key.name" : "a",
"key.parsed_declaration" : "double a",
"key.parsed_scope.end" : 1,
"key.parsed_scope.start" : 1,
"key.swift_declaration" : "var a: Double { get set }",
"key.swift_name" : "a",
"key.unavailable_message" : "",
"key.usr" : "c:@UA@VALUE@FI@a"
},
{
"key.always_deprecated" : false,
"key.always_unavailable" : false,
"key.deprecation_message" : "",
"key.doc.column" : 33,
"key.doc.file" : "Union.h",
"key.doc.line" : 1,
"key.filepath" : "Union.h",
"key.kind" : "sourcekitten.source.lang.objc.decl.field",
"key.name" : "b",
"key.parsed_declaration" : "int b",
"key.parsed_scope.end" : 1,
"key.parsed_scope.start" : 1,
"key.swift_declaration" : "var b: Int32 { get set }",
"key.swift_name" : "b",
"key.unavailable_message" : "",
"key.usr" : "c:@UA@VALUE@FI@b"
}
],
"key.swift_declaration" : "struct VALUE",
"key.swift_name" : "VALUE",
"key.unavailable_message" : "",
"key.usr" : "c:@UA@VALUE"
}
],
"key.unavailable_message" : "",
"key.usr" : "c:@T@VALUE"
}
]
}
}
]