clang 20.0.0git
PlistSupport.h
Go to the documentation of this file.
1//===- PlistSupport.h - Plist Output Utilities ------------------*- C++ -*-===//
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#ifndef LLVM_CLANG_BASIC_PLISTSUPPORT_H
10#define LLVM_CLANG_BASIC_PLISTSUPPORT_H
11
12#include "clang/Basic/LLVM.h"
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/SmallVector.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/Support/raw_ostream.h"
19#include <cassert>
20#include <cstdint>
21
22namespace clang {
23namespace markup {
24
25using FIDMap = llvm::DenseMap<FileID, unsigned>;
26
27inline unsigned AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
28 FileID FID) {
29 auto [I, Inserted] = FIDs.try_emplace(FID, V.size());
30 if (Inserted)
31 V.push_back(FID);
32 return I->second;
33}
34
35inline unsigned AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
37 FileID FID = SM.getFileID(SM.getExpansionLoc(L));
38 return AddFID(FIDs, V, FID);
39}
40
41inline unsigned GetFID(const FIDMap &FIDs, FileID FID) {
42 FIDMap::const_iterator I = FIDs.find(FID);
43 assert(I != FIDs.end());
44 return I->second;
45}
46
47inline unsigned GetFID(const FIDMap &FIDs, const SourceManager &SM,
49 FileID FID = SM.getFileID(SM.getExpansionLoc(L));
50 return GetFID(FIDs, FID);
51}
52
53inline raw_ostream &Indent(raw_ostream &o, const unsigned indent) {
54 for (unsigned i = 0; i < indent; ++i)
55 o << ' ';
56 return o;
57}
58