Skip to content

Commit

Permalink
[clang][ExtractAPI] Allow serialization for ObjC++ headers (#74733)
Browse files Browse the repository at this point in the history
rdar://79874441
  • Loading branch information
daniel-grumberg committed Dec 7, 2023
1 parent db3bc49 commit 789a5bb
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 3 deletions.
3 changes: 2 additions & 1 deletion clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ StringRef getLanguageName(Language Lang) {
return "objective-c";
case Language::CXX:
return "c++";
case Language::ObjCXX:
return "objective-c++";

// Unsupported language currently
case Language::ObjCXX:
case Language::OpenCL:
case Language::OpenCLCXX:
case Language::CUDA:
Expand Down
101 changes: 99 additions & 2 deletions clang/test/ExtractAPI/language.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,42 @@
// RUN: %t/c.reference.output.json.in >> %t/c.reference.output.json
// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
// RUN: %t/objc.reference.output.json.in >> %t/objc.reference.output.json
// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
// RUN: %t/objcpp.reference.output.json.in >> %t/objcpp.reference.output.json

// RUN: %clang -extract-api -x c-header -target arm64-apple-macosx \
// RUN: %clang_cc1 -extract-api -x c-header -triple arm64-apple-macosx \
// RUN: %t/c.h -o %t/c.output.json | FileCheck -allow-empty %s
// RUN: %clang -extract-api -x objective-c-header -target arm64-apple-macosx \
// RUN: %clang_cc1 -extract-api -x objective-c-header -triple arm64-apple-macosx \
// RUN: %t/objc.h -o %t/objc.output.json | FileCheck -allow-empty %s
// RUN: %clang_cc1 -extract-api -x objective-c++-header -triple arm64-apple-macosx \
// RUN: %t/objcpp.h -o %t/objcpp.output.json | FileCheck -allow-empty %s

// Generator version is not consistent across test runs, normalize it.
// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
// RUN: %t/c.output.json >> %t/c.output-normalized.json
// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
// RUN: %t/objc.output.json >> %t/objc.output-normalized.json
// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
// RUN: %t/objcpp.output.json >> %t/objcpp.output-normalized.json

// RUN: diff %t/c.reference.output.json %t/c.output-normalized.json
// RUN: diff %t/objc.reference.output.json %t/objc.output-normalized.json
// RUN: diff %t/objcpp.reference.output.json %t/objcpp.output-normalized.json

// CHECK-NOT: error:
// CHECK-NOT: warning:

//--- c.h
char c;
///expected-no-diagnostics

//--- objc.h
char objc;
///expected-no-diagnostics

//--- objcpp.h
char objcpp;
///expected-no-diagnostics

//--- c.reference.output.json.in
{
Expand Down Expand Up @@ -196,3 +209,87 @@ char objc;
}
]
}
//--- objcpp.reference.output.json.in
{
"metadata": {
"formatVersion": {
"major": 0,
"minor": 5,
"patch": 3
},
"generator": "?"
},
"module": {
"name": "",
"platform": {
"architecture": "arm64",
"operatingSystem": {
"minimumVersion": {
"major": 11,
"minor": 0,
"patch": 0
},
"name": "macosx"
},
"vendor": "apple"
}
},
"relationships": [],
"symbols": [
{
"accessLevel": "public",
"declarationFragments": [
{
"kind": "typeIdentifier",
"preciseIdentifier": "c:C",
"spelling": "char"
},
{
"kind": "text",
"spelling": " "
},
{
"kind": "identifier",
"spelling": "objcpp"
},
{
"kind": "text",
"spelling": ";"
}
],
"identifier": {
"interfaceLanguage": "objective-c++",
"precise": "c:@objcpp"
},
"kind": {
"displayName": "Global Variable",
"identifier": "objective-c++.var"
},
"location": {
"position": {
"character": 5,
"line": 0
},
"uri": "file://INPUT_DIR/objcpp.h"
},
"names": {
"navigator": [
{
"kind": "identifier",
"spelling": "objcpp"
}
],
"subHeading": [
{
"kind": "identifier",
"spelling": "objcpp"
}
],
"title": "objcpp"
},
"pathComponents": [
"objcpp"
]
}
]
}

0 comments on commit 789a5bb

Please sign in to comment.