DelayedDiagnostic.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //===--- DelayedDiagnostic.cpp - Delayed declarator diagnostics -*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the DelayedDiagnostic class implementation, which
  11. // is used to record diagnostics that are being conditionally produced
  12. // during declarator parsing.
  13. //
  14. // This file also defines AccessedEntity.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #include "clang/Sema/DelayedDiagnostic.h"
  18. #include <string.h>
  19. using namespace clang;
  20. using namespace sema;
  21. // //
  22. ///////////////////////////////////////////////////////////////////////////////
  23. DelayedDiagnostic
  24. DelayedDiagnostic::makeAvailability(Sema::AvailabilityDiagnostic AD,
  25. SourceLocation Loc,
  26. const NamedDecl *D,
  27. const ObjCInterfaceDecl *UnknownObjCClass,
  28. const ObjCPropertyDecl *ObjCProperty,
  29. StringRef Msg,
  30. bool ObjCPropertyAccess) {
  31. DelayedDiagnostic DD;
  32. switch (AD) {
  33. case Sema::AD_Deprecation:
  34. DD.Kind = Deprecation;
  35. break;
  36. case Sema::AD_Unavailable:
  37. DD.Kind = Unavailable;
  38. break;
  39. case Sema::AD_Partial:
  40. llvm_unreachable("AD_Partial diags should not be delayed");
  41. }
  42. DD.Triggered = false;
  43. DD.Loc = Loc;
  44. DD.DeprecationData.Decl = D;
  45. DD.DeprecationData.UnknownObjCClass = UnknownObjCClass;
  46. DD.DeprecationData.ObjCProperty = ObjCProperty;
  47. char *MessageData = nullptr;
  48. if (Msg.size()) {
  49. MessageData = new char [Msg.size()];
  50. memcpy(MessageData, Msg.data(), Msg.size());
  51. }
  52. DD.DeprecationData.Message = MessageData;
  53. DD.DeprecationData.MessageLen = Msg.size();
  54. DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess;
  55. return DD;
  56. }
  57. void DelayedDiagnostic::Destroy() {
  58. switch (static_cast<DDKind>(Kind)) {
  59. case Access:
  60. getAccessData().~AccessedEntity();
  61. break;
  62. case Deprecation:
  63. case Unavailable:
  64. delete [] DeprecationData.Message;
  65. break;
  66. case ForbiddenType:
  67. break;
  68. }
  69. }