|
15 | 15 | //
|
16 | 16 | //===----------------------------------------------------------------------===//
|
17 | 17 |
|
| 18 | +#include "swift/APIDigester/ModuleDiagsConsumer.h" |
18 | 19 | #include "swift/AST/DiagnosticEngine.h"
|
19 | 20 | #include "swift/AST/DiagnosticsModuleDiffer.h"
|
20 |
| -#include "swift/APIDigester/ModuleDiagsConsumer.h" |
| 21 | +#include "swift/Basic/SourceManager.h" |
21 | 22 |
|
22 | 23 | using namespace swift;
|
23 | 24 |
|
@@ -81,6 +82,81 @@ static StringRef getCategoryName(uint32_t ID) {
|
81 | 82 | return "/* Others */";
|
82 | 83 | }
|
83 | 84 | }
|
| 85 | + |
| 86 | +static StringRef getSerializedIdentifier(uint32_t ID) { |
| 87 | + switch (ID) { |
| 88 | + case LocalDiagID::removed_decl: |
| 89 | + return "removedDecl"; |
| 90 | + case LocalDiagID::moved_decl: |
| 91 | + return "movedDecl"; |
| 92 | + case LocalDiagID::decl_kind_changed: |
| 93 | + return "declKindChanged"; |
| 94 | + case LocalDiagID::renamed_decl: |
| 95 | + return "renamedDecl"; |
| 96 | + case LocalDiagID::objc_name_change: |
| 97 | + return "objcNameChange"; |
| 98 | + case LocalDiagID::decl_attr_change: |
| 99 | + return "declAttrChange"; |
| 100 | + case LocalDiagID::decl_new_attr: |
| 101 | + return "declNewAttr"; |
| 102 | + case LocalDiagID::func_self_access_change: |
| 103 | + return "funcSelfAccessChange"; |
| 104 | + case LocalDiagID::new_decl_without_intro: |
| 105 | + return "newDeclWithoutIntro"; |
| 106 | + case LocalDiagID::default_arg_removed: |
| 107 | + return "defaultArgRemoved"; |
| 108 | + case LocalDiagID::decl_type_change: |
| 109 | + return "declTypeChange"; |
| 110 | + case LocalDiagID::func_type_escaping_changed: |
| 111 | + return "funcTypeEscapingChanged"; |
| 112 | + case LocalDiagID::param_ownership_change: |
| 113 | + return "paramOwnershipChange"; |
| 114 | + case LocalDiagID::type_witness_change: |
| 115 | + return "typeWitnessChange"; |
| 116 | + case LocalDiagID::raw_type_change: |
| 117 | + return "rawTypeChange"; |
| 118 | + case LocalDiagID::generic_sig_change: |
| 119 | + return "genericSigChange"; |
| 120 | + case LocalDiagID::enum_case_added: |
| 121 | + return "enumCaseAdded"; |
| 122 | + case LocalDiagID::decl_added: |
| 123 | + return "declAdded"; |
| 124 | + case LocalDiagID::decl_reorder: |
| 125 | + return "declReorder"; |
| 126 | + case LocalDiagID::var_has_fixed_order_change: |
| 127 | + return "varHasFixedOrderChange"; |
| 128 | + case LocalDiagID::func_has_fixed_order_change: |
| 129 | + return "funcHasFixedOrderChange"; |
| 130 | + case LocalDiagID::conformance_added: |
| 131 | + return "conformanceAdded"; |
| 132 | + case LocalDiagID::conformance_removed: |
| 133 | + return "conformanceRemoved"; |
| 134 | + case LocalDiagID::optional_req_changed: |
| 135 | + return "optionalReqChanged"; |
| 136 | + case LocalDiagID::existing_conformance_added: |
| 137 | + return "existingConformanceAdded"; |
| 138 | + case LocalDiagID::default_associated_type_removed: |
| 139 | + return "defaultAssociatedTypeRemoved"; |
| 140 | + case LocalDiagID::protocol_req_added: |
| 141 | + return "protocolReqAdded"; |
| 142 | + case LocalDiagID::decl_new_witness_table_entry: |
| 143 | + return "declNewWitnessTableEntry"; |
| 144 | + case LocalDiagID::super_class_removed: |
| 145 | + return "superClassRemoved"; |
| 146 | + case LocalDiagID::super_class_changed: |
| 147 | + return "superClassChanged"; |
| 148 | + case LocalDiagID::no_longer_open: |
| 149 | + return "noLongerOpen"; |
| 150 | + case LocalDiagID::desig_init_added: |
| 151 | + return "desigInitAdded"; |
| 152 | + case LocalDiagID::added_invisible_designated_init: |
| 153 | + return "addedInvisibleDesignatedInit"; |
| 154 | + case LocalDiagID::not_inheriting_convenience_inits: |
| 155 | + return "notInheritingConvenienceInits"; |
| 156 | + default: |
| 157 | + return "other"; |
| 158 | + } |
| 159 | +} |
84 | 160 | }
|
85 | 161 |
|
86 | 162 | swift::ide::api::
|
@@ -123,6 +199,49 @@ swift::ide::api::ModuleDifferDiagsConsumer::~ModuleDifferDiagsConsumer() {
|
123 | 199 | }
|
124 | 200 | }
|
125 | 201 |
|
| 202 | +void swift::ide::api::ModuleDifferDiagnosticInfo::serialize( |
| 203 | + llvm::json::OStream &JSON) { |
| 204 | + JSON.object([&]() { |
| 205 | + JSON.attribute("identifier", getSerializedIdentifier((uint32_t)ID)); |
| 206 | + JSON.attribute("text", Text); |
| 207 | + JSON.attribute("location", Loc); |
| 208 | + }); |
| 209 | +} |
| 210 | + |
| 211 | +void swift::ide::api::ModuleDifferDiagsJSONConsumer::handleDiagnostic( |
| 212 | + SourceManager &SM, const DiagnosticInfo &Info) { |
| 213 | + llvm::SmallString<256> Text; |
| 214 | + { |
| 215 | + llvm::raw_svector_ostream Out(Text); |
| 216 | + DiagnosticEngine::formatDiagnosticText(Out, Info.FormatString, |
| 217 | + Info.FormatArgs); |
| 218 | + } |
| 219 | + llvm::SmallString<32> Loc; |
| 220 | + if (Info.Loc.isValid()) { |
| 221 | + Loc = SM.getDisplayNameForLoc(Info.Loc); |
| 222 | + } |
| 223 | + AllDiags.push_back(ModuleDifferDiagnosticInfo(Info.ID, Text, Loc)); |
| 224 | +} |
| 225 | + |
| 226 | +swift::ide::api::ModuleDifferDiagsJSONConsumer:: |
| 227 | + ~ModuleDifferDiagsJSONConsumer() { |
| 228 | + llvm::json::OStream JSON(OS, 2); |
| 229 | + |
| 230 | + JSON.object([&]() { |
| 231 | + JSON.attributeObject("version", [&]() { |
| 232 | + JSON.attribute("major", 0); |
| 233 | + JSON.attribute("minor", 1); |
| 234 | + }); |
| 235 | + JSON.attributeArray("diagnostics", [&]() { |
| 236 | + for (auto &Info : AllDiags) { |
| 237 | + Info.serialize(JSON); |
| 238 | + } |
| 239 | + }); |
| 240 | + }); |
| 241 | + |
| 242 | + JSON.flush(); |
| 243 | +} |
| 244 | + |
126 | 245 | bool swift::ide::api::
|
127 | 246 | FilteringDiagnosticConsumer::shouldProceed(const DiagnosticInfo &Info) {
|
128 | 247 | if (allowedBreakages->empty()) {
|
|
0 commit comments