Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/AbstractBasicWriter.h
Line
Count
Source (jump to first uncovered line)
1
//==--- AbstractBasicWriter.h - Abstract basic value serialization --------===//
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_AST_ABSTRACTBASICWRITER_H
10
#define LLVM_CLANG_AST_ABSTRACTBASICWRITER_H
11
12
#include "clang/AST/ASTContext.h"
13
#include "clang/AST/DeclTemplate.h"
14
15
namespace clang {
16
namespace serialization {
17
18
template <class T>
19
145k
inline llvm::Optional<T> makeOptionalFromNullable(const T &value) {
20
145k
  return (value.isNull()
21
145k
            ? 
llvm::Optional<T>()102
22
145k
            : 
llvm::Optional<T>(value)145k
);
23
145k
}
llvm::Optional<clang::QualType> clang::serialization::makeOptionalFromNullable<clang::QualType>(clang::QualType const&)
Line
Count
Source
19
145k
inline llvm::Optional<T> makeOptionalFromNullable(const T &value) {
20
145k
  return (value.isNull()
21
145k
            ? 
llvm::Optional<T>()102
22
145k
            : 
llvm::Optional<T>(value)145k
);
23
145k
}
llvm::Optional<clang::TemplateName> clang::serialization::makeOptionalFromNullable<clang::TemplateName>(clang::TemplateName const&)
Line
Count
Source
19
74
inline llvm::Optional<T> makeOptionalFromNullable(const T &value) {
20
74
  return (value.isNull()
21
74
            ? 
llvm::Optional<T>()0
22
74
            : llvm::Optional<T>(value));
23
74
}
24
25
template <class T>
26
239k
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
27
239k
  return (value ? 
llvm::Optional<T*>(value)188k
:
llvm::Optional<T*>()50.9k
);
28
239k
}
llvm::Optional<clang::ConceptDecl const*> clang::serialization::makeOptionalFromPointer<clang::ConceptDecl const>(clang::ConceptDecl const*)
Line
Count
Source
26
847
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
27
847
  return (value ? 
llvm::Optional<T*>(value)6
:
llvm::Optional<T*>()841
);
28
847
}
llvm::Optional<clang::IdentifierInfo const*> clang::serialization::makeOptionalFromPointer<clang::IdentifierInfo const>(clang::IdentifierInfo const*)
Line
Count
Source
26
38
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
27
38
  return (value ? llvm::Optional<T*>(value) : 
llvm::Optional<T*>()0
);
28
38
}
llvm::Optional<clang::TagDecl const*> clang::serialization::makeOptionalFromPointer<clang::TagDecl const>(clang::TagDecl const*)
Line
Count
Source
26
81.4k
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
27
81.4k
  return (value ? 
llvm::Optional<T*>(value)33.3k
:
llvm::Optional<T*>()48.1k
);
28
81.4k
}
llvm::Optional<clang::TemplateTypeParmDecl const*> clang::serialization::makeOptionalFromPointer<clang::TemplateTypeParmDecl const>(clang::TemplateTypeParmDecl const*)
Line
Count
Source
26
156k
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
27
156k
  return (value ? 
llvm::Optional<T*>(value)154k
:
llvm::Optional<T*>()2.00k
);
28
156k
}
29
30
// PropertyWriter is a class concept that requires the following method:
31
//   BasicWriter find(llvm::StringRef propertyName);
32
// where BasicWriter is some class conforming to the BasicWriter concept.
33
// An abstract AST-node writer is created with a PropertyWriter and
34
// performs a sequence of calls like so:
35
//   propertyWriter.find(propertyName).write##TypeName(value)
36
// to write the properties of the node it is serializing.
37
38
// BasicWriter is a class concept that requires methods like:
39
//   void write##TypeName(ValueType value);
40
// where TypeName is the name of a PropertyType node from PropertiesBase.td
41
// and ValueType is the corresponding C++ type name.
42
//
43
// In addition to the concrete property types, BasicWriter is expected
44
// to implement these methods:
45
//
46
//   template <class EnumType>
47
//   void writeEnum(T value);
48
//
49
//     Writes an enum value as the current property.  EnumType will always
50
//     be an enum type.  Only necessary if the BasicWriter doesn't provide
51
//     type-specific writers for all the enum types.
52
//
53
//   template <class ValueType>
54
//   void writeOptional(Optional<ValueType> value);
55
//
56
//     Writes an optional value as the current property.
57
//
58
//   template <class ValueType>
59
//   void writeArray(ArrayRef<ValueType> value);
60
//
61
//     Writes an array of values as the current property.
62
//
63
//   PropertyWriter writeObject();
64
//
65
//     Writes an object as the current property; the returned property
66
//     writer will be subjected to a sequence of property writes and then
67
//     discarded before any other properties are written to the "outer"
68
//     property writer (which need not be the same type).  The sub-writer
69
//     will be used as if with the following code:
70
//
71
//       {
72
//         auto &&widget = W.find("widget").writeObject();
73
//         widget.find("kind").writeWidgetKind(...);
74
//         widget.find("declaration").writeDeclRef(...);
75
//       }
76
77
// WriteDispatcher is a template which does type-based forwarding to one
78
// of the write methods of the BasicWriter passed in:
79
//
80
// template <class ValueType>
81
// struct WriteDispatcher {
82
//   template <class BasicWriter>
83
//   static void write(BasicWriter &W, ValueType value);
84
// };
85
86
// BasicWriterBase provides convenience implementations of the write
87
// methods for EnumPropertyType and SubclassPropertyType types that just
88
// defer to the "underlying" implementations (for UInt32 and the base class,
89
// respectively).
90
//
91
// template <class Impl>
92
// class BasicWriterBase {
93
// protected:
94
//   Impl &asImpl();
95
// public:
96
//   ...
97
// };
98
99
// The actual classes are auto-generated; see ClangASTPropertiesEmitter.cpp.
100
#include "clang/AST/AbstractBasicWriter.inc"
101
102
/// DataStreamBasicWriter provides convenience implementations for many
103
/// BasicWriter methods based on the assumption that the
104
/// ultimate writer implementation is based on a variable-length stream
105
/// of unstructured data (like Clang's module files).  It is designed
106
/// to pair with DataStreamBasicReader.
107
///
108
/// This class can also act as a PropertyWriter, implementing find("...")
109
/// by simply forwarding to itself.
110
///
111
/// Unimplemented methods:
112
///   writeBool
113
///   writeUInt32
114
///   writeUInt64
115
///   writeIdentifier
116
///   writeSelector
117
///   writeSourceLocation
118
///   writeQualType
119
///   writeStmtRef
120
///   writeDeclRef
121
template <class Impl>
122
class DataStreamBasicWriter : public BasicWriterBase<Impl> {
123
protected:
124
  using BasicWriterBase<Impl>::asImpl;
125
11.1M
  DataStreamBasicWriter(ASTContext &ctx) : BasicWriterBase<Impl>(ctx) {}
126
127
public:
128
  /// Implement property-find by ignoring it.  We rely on properties being
129
  /// serialized and deserialized in a reliable order instead.
130
18.2M
  Impl &find(const char *propertyName) {
131
18.2M
    return asImpl();
132
18.2M
  }
133
134
  // Implement object writing by forwarding to this, collapsing the
135
  // structure into a single data stream.
136
4.72M
  Impl &writeObject() { return asImpl(); }
137
138
  template <class T>
139
5.73M
  void writeEnum(T value) {
140
5.73M
    asImpl().writeUInt32(uint32_t(value));
141
5.73M
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::ArrayType::ArraySizeModifier>(clang::ArrayType::ArraySizeModifier)
Line
Count
Source
139
17.3k
  void writeEnum(T value) {
140
17.3k
    asImpl().writeUInt32(uint32_t(value));
141
17.3k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::attr::Kind>(clang::attr::Kind)
Line
Count
Source
139
16.7k
  void writeEnum(T value) {
140
16.7k
    asImpl().writeUInt32(uint32_t(value));
141
16.7k
  }
Unexecuted instantiation: void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::BuiltinType::Kind>(clang::BuiltinType::Kind)
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::AutoTypeKeyword>(clang::AutoTypeKeyword)
Line
Count
Source
139
847
  void writeEnum(T value) {
140
847
    asImpl().writeUInt32(uint32_t(value));
141
847
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::TemplateArgument::ArgKind>(clang::TemplateArgument::ArgKind)
Line
Count
Source
139
838k
  void writeEnum(T value) {
140
838k
    asImpl().writeUInt32(uint32_t(value));
141
838k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::TemplateName::NameKind>(clang::TemplateName::NameKind)
Line
Count
Source
139
387k
  void writeEnum(T value) {
140
387k
    asImpl().writeUInt32(uint32_t(value));
141
387k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::DeclarationName::NameKind>(clang::DeclarationName::NameKind)
Line
Count
Source
139
3.49M
  void writeEnum(T value) {
140
3.49M
    asImpl().writeUInt32(uint32_t(value));
141
3.49M
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::NestedNameSpecifier::SpecifierKind>(clang::NestedNameSpecifier::SpecifierKind)
Line
Count
Source
139
108k
  void writeEnum(T value) {
140
108k
    asImpl().writeUInt32(uint32_t(value));
141
108k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OverloadedOperatorKind>(clang::OverloadedOperatorKind)
Line
Count
Source
139
123k
  void writeEnum(T value) {
140
123k
    asImpl().writeUInt32(uint32_t(value));
141
123k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::ElaboratedTypeKeyword>(clang::ElaboratedTypeKeyword)
Line
Count
Source
139
153k
  void writeEnum(T value) {
140
153k
    asImpl().writeUInt32(uint32_t(value));
141
153k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::VectorType::VectorKind>(clang::VectorType::VectorKind)
Line
Count
Source
139
3.01k
  void writeEnum(T value) {
140
3.01k
    asImpl().writeUInt32(uint32_t(value));
141
3.01k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::CallingConv>(clang::CallingConv)
Line
Count
Source
139
290k
  void writeEnum(T value) {
140
290k
    asImpl().writeUInt32(uint32_t(value));
141
290k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::RefQualifierKind>(clang::RefQualifierKind)
Line
Count
Source
139
289k
  void writeEnum(T value) {
140
289k
    asImpl().writeUInt32(uint32_t(value));
141
289k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::UnaryTransformType::UTTKind>(clang::UnaryTransformType::UTTKind)
Line
Count
Source
139
78
  void writeEnum(T value) {
140
78
    asImpl().writeUInt32(uint32_t(value));
141
78
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OpenMPBindClauseKind>(clang::OpenMPBindClauseKind)
Line
Count
Source
139
20
  void writeEnum(T value) {
140
20
    asImpl().writeUInt32(uint32_t(value));
141
20
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OpenMPDeviceClauseModifier>(clang::OpenMPDeviceClauseModifier)
Line
Count
Source
139
353
  void writeEnum(T value) {
140
353
    asImpl().writeUInt32(uint32_t(value));
141
353
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OpenMPLastprivateModifier>(clang::OpenMPLastprivateModifier)
Line
Count
Source
139
476
  void writeEnum(T value) {
140
476
    asImpl().writeUInt32(uint32_t(value));
141
476
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OpenMPOrderClauseKind>(clang::OpenMPOrderClauseKind)
Line
Count
Source
139
60
  void writeEnum(T value) {
140
60
    asImpl().writeUInt32(uint32_t(value));
141
60
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OpenMPReductionClauseModifier>(clang::OpenMPReductionClauseModifier)
Line
Count
Source
139
1.01k
  void writeEnum(T value) {
140
1.01k
    asImpl().writeUInt32(uint32_t(value));
141
1.01k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OpenMPDependClauseKind>(clang::OpenMPDependClauseKind)
Line
Count
Source
139
8
  void writeEnum(T value) {
140
8
    asImpl().writeUInt32(uint32_t(value));
141
8
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<llvm::omp::TraitSet>(llvm::omp::TraitSet)
Line
Count
Source
139
705
  void writeEnum(T value) {
140
705
    asImpl().writeUInt32(uint32_t(value));
141
705
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<llvm::omp::TraitSelector>(llvm::omp::TraitSelector)
Line
Count
Source
139
737
  void writeEnum(T value) {
140
737
    asImpl().writeUInt32(uint32_t(value));
141
737
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<llvm::omp::TraitProperty>(llvm::omp::TraitProperty)
Line
Count
Source
139
1.13k
  void writeEnum(T value) {
140
1.13k
    asImpl().writeUInt32(uint32_t(value));
141
1.13k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::APValue::ValueKind>(clang::APValue::ValueKind)
Line
Count
Source
139
196
  void writeEnum(T value) {
140
196
    asImpl().writeUInt32(uint32_t(value));
141
196
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<llvm::omp::Directive>(llvm::omp::Directive)
Line
Count
Source
139
248
  void writeEnum(T value) {
140
248
    asImpl().writeUInt32(uint32_t(value));
141
248
  }
142
143
  template <class T>
144
980k
  void writeArray(llvm::ArrayRef<T> array) {
145
980k
    asImpl().writeUInt32(array.size());
146
1.23M
    for (const T &elt : array) {
147
1.23M
      WriteDispatcher<T>::write(asImpl(), elt);
148
1.23M
    }
149
980k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::TemplateArgument>(llvm::ArrayRef<clang::TemplateArgument>)
Line
Count
Source
144
394k
  void writeArray(llvm::ArrayRef<T> array) {
145
394k
    asImpl().writeUInt32(array.size());
146
658k
    for (const T &elt : array) {
147
658k
      WriteDispatcher<T>::write(asImpl(), elt);
148
658k
    }
149
394k
  }
Unexecuted instantiation: void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::NamedDecl const*>(llvm::ArrayRef<clang::NamedDecl const*>)
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::QualType>(llvm::ArrayRef<clang::QualType>)
Line
Count
Source
144
292k
  void writeArray(llvm::ArrayRef<T> array) {
145
292k
    asImpl().writeUInt32(array.size());
146
572k
    for (const T &elt : array) {
147
572k
      WriteDispatcher<T>::write(asImpl(), elt);
148
572k
    }
149
292k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::FunctionType::ExtParameterInfo>(llvm::ArrayRef<clang::FunctionType::ExtParameterInfo>)
Line
Count
Source
144
289k
  void writeArray(llvm::ArrayRef<T> array) {
145
289k
    asImpl().writeUInt32(array.size());
146
289k
    for (const T &elt : array) {
147
859
      WriteDispatcher<T>::write(asImpl(), elt);
148
859
    }
149
289k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::ObjCProtocolDecl const*>(llvm::ArrayRef<clang::ObjCProtocolDecl const*>)
Line
Count
Source
144
3.69k
  void writeArray(llvm::ArrayRef<T> array) {
145
3.69k
    asImpl().writeUInt32(array.size());
146
3.69k
    for (const T &elt : array) {
147
966
      WriteDispatcher<T>::write(asImpl(), elt);
148
966
    }
149
3.69k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::APValue>(llvm::ArrayRef<clang::APValue>)
Line
Count
Source
144
69
  void writeArray(llvm::ArrayRef<T> array) {
145
69
    asImpl().writeUInt32(array.size());
146
142
    for (const T &elt : array) {
147
142
      WriteDispatcher<T>::write(asImpl(), elt);
148
142
    }
149
69
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::CXXRecordDecl const*>(llvm::ArrayRef<clang::CXXRecordDecl const*>)
Line
Count
Source
144
6
  void writeArray(llvm::ArrayRef<T> array) {
145
6
    asImpl().writeUInt32(array.size());
146
6
    for (const T &elt : array) {
147
0
      WriteDispatcher<T>::write(asImpl(), elt);
148
0
    }
149
6
  }
150
151
  template <class T>
152
850k
  void writeOptional(llvm::Optional<T> value) {
153
850k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
154
850k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::QualType>(llvm::Optional<clang::QualType>)
Line
Count
Source
152
600k
  void writeOptional(llvm::Optional<T> value) {
153
600k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
154
600k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::ConceptDecl const*>(llvm::Optional<clang::ConceptDecl const*>)
Line
Count
Source
152
847
  void writeOptional(llvm::Optional<T> value) {
153
847
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
154
847
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::IdentifierInfo const*>(llvm::Optional<clang::IdentifierInfo const*>)
Line
Count
Source
152
38
  void writeOptional(llvm::Optional<T> value) {
153
38
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
154
38
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<unsigned int>(llvm::Optional<unsigned int>)
Line
Count
Source
152
10.2k
  void writeOptional(llvm::Optional<T> value) {
153
10.2k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
154
10.2k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::TemplateName>(llvm::Optional<clang::TemplateName>)
Line
Count
Source
152
74
  void writeOptional(llvm::Optional<T> value) {
153
74
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
154
74
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::TagDecl const*>(llvm::Optional<clang::TagDecl const*>)
Line
Count
Source
152
81.4k
  void writeOptional(llvm::Optional<T> value) {
153
81.4k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
154
81.4k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::TemplateTypeParmDecl const*>(llvm::Optional<clang::TemplateTypeParmDecl const*>)
Line
Count
Source
152
156k
  void writeOptional(llvm::Optional<T> value) {
153
156k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
154
156k
  }
155
156
185k
  void writeAPSInt(const llvm::APSInt &value) {
157
185k
    asImpl().writeBool(value.isUnsigned());
158
185k
    asImpl().writeAPInt(value);
159
185k
  }
160
161
608k
  void writeAPInt(const llvm::APInt &value) {
162
608k
    asImpl().writeUInt32(value.getBitWidth());
163
608k
    const uint64_t *words = value.getRawData();
164
1.21M
    for (size_t i = 0, e = value.getNumWords(); i != e; 
++i608k
)
165
608k
      asImpl().writeUInt64(words[i]);
166
608k
  }
167
168
0
  void writeFixedPointSemantics(const llvm::FixedPointSemantics &sema) {
169
0
    asImpl().writeUInt32(sema.getWidth());
170
0
    asImpl().writeUInt32(sema.getScale());
171
0
    asImpl().writeUInt32(sema.isSigned() | sema.isSaturated() << 1 |
172
0
                         sema.hasUnsignedPadding() << 2);
173
0
  }
174
175
  void writeLValuePathSerializationHelper(
176
25
      APValue::LValuePathSerializationHelper lvaluePath) {
177
25
    ArrayRef<APValue::LValuePathEntry> path = lvaluePath.Path;
178
25
    QualType elemTy = lvaluePath.getType();
179
25
    asImpl().writeQualType(elemTy);
180
25
    asImpl().writeUInt32(path.size());
181
25
    auto &ctx = ((BasicWriterBase<Impl> *)this)->getASTContext();
182
25
    for (auto elem : path) {
183
15
      if (elemTy->getAs<RecordType>()) {
184
9
        asImpl().writeUInt32(elem.getAsBaseOrMember().getInt());
185
9
        const Decl *baseOrMember = elem.getAsBaseOrMember().getPointer();
186
9
        if (const auto *recordDecl = dyn_cast<CXXRecordDecl>(baseOrMember)) {
187
1
          asImpl().writeDeclRef(recordDecl);
188
1
          elemTy = ctx.getRecordType(recordDecl);
189
8
        } else {
190
8
          const auto *valueDecl = cast<ValueDecl>(baseOrMember);
191
8
          asImpl().writeDeclRef(valueDecl);
192
8
          elemTy = valueDecl->getType();
193
8
        }
194
9
      } else {
195
6
        asImpl().writeUInt32(elem.getAsArrayIndex());
196
6
        elemTy = ctx.getAsArrayType(elemTy)->getElementType();
197
6
      }
198
15
    }
199
25
  }
200
201
313k
  void writeQualifiers(Qualifiers value) {
202
313k
    static_assert(sizeof(value.getAsOpaqueValue()) <= sizeof(uint32_t),
203
313k
                  "update this if the value size changes");
204
313k
    asImpl().writeUInt32(value.getAsOpaqueValue());
205
313k
  }
206
207
  void writeExceptionSpecInfo(
208
289k
                        const FunctionProtoType::ExceptionSpecInfo &esi) {
209
289k
    asImpl().writeUInt32(uint32_t(esi.Type));
210
289k
    if (esi.Type == EST_Dynamic) {
211
3
      asImpl().writeArray(esi.Exceptions);
212
289k
    } else if (isComputedNoexcept(esi.Type)) {
213
8.26k
      asImpl().writeExprRef(esi.NoexceptExpr);
214
281k
    } else if (esi.Type == EST_Uninstantiated) {
215
1.95k
      asImpl().writeDeclRef(esi.SourceDecl);
216
1.95k
      asImpl().writeDeclRef(esi.SourceTemplate);
217
279k
    } else if (esi.Type == EST_Unevaluated) {
218
15.9k
      asImpl().writeDeclRef(esi.SourceDecl);
219
15.9k
    }
220
289k
  }
221
222
859
  void writeExtParameterInfo(FunctionProtoType::ExtParameterInfo epi) {
223
859
    static_assert(sizeof(epi.getOpaqueValue()) <= sizeof(uint32_t),
224
859
                  "opaque value doesn't fit into uint32_t");
225
859
    asImpl().writeUInt32(epi.getOpaqueValue());
226
859
  }
227
228
153k
  void writeNestedNameSpecifier(NestedNameSpecifier *NNS) {
229
    // Nested name specifiers usually aren't too long. I think that 8 would
230
    // typically accommodate the vast majority.
231
153k
    SmallVector<NestedNameSpecifier *, 8> nestedNames;
232
233
    // Push each of the NNS's onto a stack for serialization in reverse order.
234
262k
    while (NNS) {
235
108k
      nestedNames.push_back(NNS);
236
108k
      NNS = NNS->getPrefix();
237
108k
    }
238
239
153k
    asImpl().writeUInt32(nestedNames.size());
240
262k
    while (!nestedNames.empty()) {
241
108k
      NNS = nestedNames.pop_back_val();
242
108k
      NestedNameSpecifier::SpecifierKind kind = NNS->getKind();
243
108k
      asImpl().writeNestedNameSpecifierKind(kind);
244
108k
      switch (kind) {
245
818
      case NestedNameSpecifier::Identifier:
246
818
        asImpl().writeIdentifier(NNS->getAsIdentifier());
247
818
        continue;
248
249
5.42k
      case NestedNameSpecifier::Namespace:
250
5.42k
        asImpl().writeNamespaceDeclRef(NNS->getAsNamespace());
251
5.42k
        continue;
252
253
4
      case NestedNameSpecifier::NamespaceAlias:
254
4
        asImpl().writeNamespaceAliasDeclRef(NNS->getAsNamespaceAlias());
255
4
        continue;
256
257
102k
      case NestedNameSpecifier::TypeSpec:
258
102k
      case NestedNameSpecifier::TypeSpecWithTemplate:
259
102k
        asImpl().writeQualType(QualType(NNS->getAsType(), 0));
260
102k
        continue;
261
262
17
      case NestedNameSpecifier::Global:
263
        // Don't need to write an associated value.
264
17
        continue;
265
266
0
      case NestedNameSpecifier::Super:
267
0
        asImpl().writeDeclRef(NNS->getAsRecordDecl());
268
0
        continue;
269
108k
      }
270
0
      llvm_unreachable("bad nested name specifier kind");
271
0
    }
272
153k
  }
273
};
274
275
} // end namespace serialization
276
} // end namespace clang
277
278
#endif