brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · cb2721b Raw
74 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file defines the DelayedDiagnostic class implementation, which10// is used to record diagnostics that are being conditionally produced11// during declarator parsing.12//13// This file also defines AccessedEntity.14//15//===----------------------------------------------------------------------===//16 17#include "clang/Sema/DelayedDiagnostic.h"18#include <cstring>19 20using namespace clang;21using namespace sema;22 23DelayedDiagnostic24DelayedDiagnostic::makeAvailability(AvailabilityResult AR,25                                    ArrayRef<SourceLocation> Locs,26                                    const NamedDecl *ReferringDecl,27                                    const NamedDecl *OffendingDecl,28                                    const ObjCInterfaceDecl *UnknownObjCClass,29                                    const ObjCPropertyDecl  *ObjCProperty,30                                    StringRef Msg,31                                    bool ObjCPropertyAccess) {32  assert(!Locs.empty());33  DelayedDiagnostic DD;34  DD.Kind = Availability;35  DD.Triggered = false;36  DD.Loc = Locs.front();37  DD.AvailabilityData.ReferringDecl = ReferringDecl;38  DD.AvailabilityData.OffendingDecl = OffendingDecl;39  DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass;40  DD.AvailabilityData.ObjCProperty = ObjCProperty;41  char *MessageData = nullptr;42  if (!Msg.empty()) {43    MessageData = new char [Msg.size()];44    memcpy(MessageData, Msg.data(), Msg.size());45  }46  DD.AvailabilityData.Message = MessageData;47  DD.AvailabilityData.MessageLen = Msg.size();48 49  DD.AvailabilityData.SelectorLocs = new SourceLocation[Locs.size()];50  memcpy(DD.AvailabilityData.SelectorLocs, Locs.data(),51         sizeof(SourceLocation) * Locs.size());52  DD.AvailabilityData.NumSelectorLocs = Locs.size();53 54  DD.AvailabilityData.AR = AR;55  DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess;56  return DD;57}58 59void DelayedDiagnostic::Destroy() {60  switch (Kind) {61  case Access:62    getAccessData().~AccessedEntity();63    break;64 65  case Availability:66    delete[] AvailabilityData.Message;67    delete[] AvailabilityData.SelectorLocs;68    break;69 70  case ForbiddenType:71    break;72  }73}74