0.7.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
USRGeneration.h
Go to the documentation of this file.
1//===- USRGeneration.h - Routines for USR generation ------------*- 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#include <clang/Basic/LLVM.h>
10#include <llvm/ADT/StringRef.h>
11namespace clang {
12class ASTContext;
13class Decl;
14class LangOptions;
15class MacroDefinitionRecord;
16class Module;
17class SourceLocation;
18class SourceManager;
19class QualType;
20}
21
22namespace clanguml {
23// clang-format off
24
25namespace common {
26namespace index {
27using namespace clang;
28
29static inline StringRef getUSRSpacePrefix() {
30 return "c:";
31}
32
33/// Generate a USR for a Decl, including the USR prefix.
34/// \returns true if the results should be ignored, false otherwise.
35bool generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf);
36bool generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf,
37 const LangOptions &LangOpts);
38
39/// Generate a USR fragment for an Objective-C class.
40void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS,
41 StringRef ExtSymbolDefinedIn = "",
42 StringRef CategoryContextExtSymbolDefinedIn = "");
43
44/// Generate a USR fragment for an Objective-C class category.
45void generateUSRForObjCCategory(StringRef Cls, StringRef Cat, raw_ostream &OS,
46 StringRef ClsExtSymbolDefinedIn = "",
47 StringRef CatExtSymbolDefinedIn = "");
48
49/// Generate a USR fragment for an Objective-C instance variable. The
50/// complete USR can be created by concatenating the USR for the
51/// encompassing class with this USR fragment.
52void generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS);
53
54/// Generate a USR fragment for an Objective-C method.
55void generateUSRForObjCMethod(StringRef Sel, bool IsInstanceMethod,
56 raw_ostream &OS);
57
58/// Generate a USR fragment for an Objective-C property.
59void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS);
60
61/// Generate a USR fragment for an Objective-C protocol.
62void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS,
63 StringRef ExtSymbolDefinedIn = "");
64
65/// Generate USR fragment for a global (non-nested) enum.
66void generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS,
67 StringRef ExtSymbolDefinedIn = "");
68
69/// Generate a USR fragment for an enum constant.
70void generateUSRForEnumConstant(StringRef EnumConstantName, raw_ostream &OS);
71
72/// Generate a USR for a macro, including the USR prefix.
73///
74/// \returns true on error, false on success.
75bool generateUSRForMacro(const MacroDefinitionRecord *MD,
76 const SourceManager &SM, SmallVectorImpl<char> &Buf);
77bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
78 const SourceManager &SM, SmallVectorImpl<char> &Buf);
79
80/// Generates a USR for a type.
81///
82/// \return true on error, false on success.
83bool generateUSRForType(QualType T, ASTContext &Ctx,
84 SmallVectorImpl<char> &Buf);
85bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl<char> &Buf,
86 const LangOptions &LangOpts);
87
88/// Generate a USR for a module, including the USR prefix.
89/// \returns true on error, false on success.
90bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS);
91
92/// Generate a USR for a top-level module name, including the USR prefix.
93/// \returns true on error, false on success.
94bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS);
95
96/// Generate a USR fragment for a module.
97/// \returns true on error, false on success.
98bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS);
99
100/// Generate a USR fragment for a module name.
101/// \returns true on error, false on success.
102bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS);
103
104
105} // namespace index
106} // namespace common
107
108} // namespace clanguml