DelayedDiagnostic.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //===- DelayedDiagnostic.cpp - Delayed declarator diagnostics -------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the DelayedDiagnostic class implementation, which
  10. // is used to record diagnostics that are being conditionally produced
  11. // during declarator parsing.
  12. //
  13. // This file also defines AccessedEntity.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #include "clang/Sema/DelayedDiagnostic.h"
  17. #include <cstring>
  18. using namespace clang;
  19. using namespace sema;
  20. DelayedDiagnostic
  21. DelayedDiagnostic::makeAvailability(AvailabilityResult AR,
  22. ArrayRef<SourceLocation> Locs,
  23. const NamedDecl *ReferringDecl,
  24. const NamedDecl *OffendingDecl,
  25. const ObjCInterfaceDecl *UnknownObjCClass,
  26. const ObjCPropertyDecl *ObjCProperty,
  27. StringRef Msg,
  28. bool ObjCPropertyAccess) {
  29. assert(!Locs.empty());
  30. DelayedDiagnostic DD;
  31. DD.Kind = Availability;
  32. DD.Triggered = false;
  33. DD.Loc = Locs.front();
  34. DD.AvailabilityData.ReferringDecl = ReferringDecl;
  35. DD.AvailabilityData.OffendingDecl = OffendingDecl;
  36. DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;
  37. DD.AvailabilityData.ObjCProperty = ObjCProperty;
  38. char *MessageData = nullptr;
  39. if (!Msg.empty()) {
  40. MessageData = new char [Msg.size()];
  41. memcpy(MessageData, Msg.data(), Msg.size());
  42. }
  43. DD.AvailabilityData.Message = MessageData;
  44. DD.AvailabilityData.MessageLen = Msg.size();
  45. DD.AvailabilityData.SelectorLocs = new SourceLocation[Locs.size()];
  46. memcpy(DD.AvailabilityData.SelectorLocs, Locs.data(),
  47. sizeof(SourceLocation) * Locs.size());
  48. DD.AvailabilityData.NumSelectorLocs = Locs.size();
  49. DD.AvailabilityData.AR = AR;
  50. DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;
  51. return DD;
  52. }
  53. void DelayedDiagnostic::Destroy() {
  54. switch (Kind) {
  55. case Access:
  56. getAccessData().~AccessedEntity();
  57. break;
  58. case Availability:
  59. delete[] AvailabilityData.Message;
  60. delete[] AvailabilityData.SelectorLocs;
  61. break;
  62. case ForbiddenType:
  63. break;
  64. }
  65. }