Coverage Report

Created: 2020-02-25 14:32

/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 CLANG_AST_ABSTRACTBASICWRITER_H
10
#define CLANG_AST_ABSTRACTBASICWRITER_H
11
12
#include "clang/AST/DeclTemplate.h"
13
14
namespace clang {
15
namespace serialization {
16
17
template <class T>
18
188k
inline llvm::Optional<T> makeOptionalFromNullable(const T &value) {
19
188k
  return (value.isNull()
20
188k
            ? 
llvm::Optional<T>()73
21
188k
            : 
llvm::Optional<T>(value)188k
);
22
188k
}
llvm::Optional<clang::QualType> clang::serialization::makeOptionalFromNullable<clang::QualType>(clang::QualType const&)
Line
Count
Source
18
188k
inline llvm::Optional<T> makeOptionalFromNullable(const T &value) {
19
188k
  return (value.isNull()
20
188k
            ? 
llvm::Optional<T>()73
21
188k
            : 
llvm::Optional<T>(value)188k
);
22
188k
}
llvm::Optional<clang::TemplateName> clang::serialization::makeOptionalFromNullable<clang::TemplateName>(clang::TemplateName const&)
Line
Count
Source
18
10
inline llvm::Optional<T> makeOptionalFromNullable(const T &value) {
19
10
  return (value.isNull()
20
10
            ? 
llvm::Optional<T>()0
21
10
            : llvm::Optional<T>(value));
22
10
}
23
24
template <class T>
25
348k
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
26
348k
  return (value ? 
llvm::Optional<T*>(value)269k
:
llvm::Optional<T*>()79.6k
);
27
348k
}
llvm::Optional<clang::ConceptDecl const*> clang::serialization::makeOptionalFromPointer<clang::ConceptDecl const>(clang::ConceptDecl const*)
Line
Count
Source
25
401
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
26
401
  return (value ? 
llvm::Optional<T*>(value)0
: llvm::Optional<T*>());
27
401
}
llvm::Optional<clang::IdentifierInfo const*> clang::serialization::makeOptionalFromPointer<clang::IdentifierInfo const>(clang::IdentifierInfo const*)
Line
Count
Source
25
78
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
26
78
  return (value ? llvm::Optional<T*>(value) : 
llvm::Optional<T*>()0
);
27
78
}
llvm::Optional<clang::TagDecl const*> clang::serialization::makeOptionalFromPointer<clang::TagDecl const>(clang::TagDecl const*)
Line
Count
Source
25
115k
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
26
115k
  return (value ? 
llvm::Optional<T*>(value)38.0k
:
llvm::Optional<T*>()77.2k
);
27
115k
}
llvm::Optional<clang::TemplateTypeParmDecl const*> clang::serialization::makeOptionalFromPointer<clang::TemplateTypeParmDecl const>(clang::TemplateTypeParmDecl const*)
Line
Count
Source
25
232k
inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
26
232k
  return (value ? 
llvm::Optional<T*>(value)230k
:
llvm::Optional<T*>()1.99k
);
27
232k
}
28
29
// PropertyWriter is a class concept that requires the following method:
30
//   BasicWriter find(llvm::StringRef propertyName);
31
// where BasicWriter is some class conforming to the BasicWriter concept.
32
// An abstract AST-node writer is created with a PropertyWriter and
33
// performs a sequence of calls like so:
34
//   propertyWriter.find(propertyName).write##TypeName(value)
35
// to write the properties of the node it is serializing.
36
37
// BasicWriter is a class concept that requires methods like:
38
//   void write##TypeName(ValueType value);
39
// where TypeName is the name of a PropertyType node from PropertiesBase.td
40
// and ValueType is the corresponding C++ type name.
41
//
42
// In addition to the concrete property types, BasicWriter is expected
43
// to implement these methods:
44
//
45
//   template <class EnumType>
46
//   void writeEnum(T value);
47
//
48
//     Writes an enum value as the current property.  EnumType will always
49
//     be an enum type.  Only necessary if the BasicWriter doesn't provide
50
//     type-specific writers for all the enum types.
51
//
52
//   template <class ValueType>
53
//   void writeOptional(Optional<ValueType> value);
54
//
55
//     Writes an optional value as the current property.
56
//
57
//   template <class ValueType>
58
//   void writeArray(ArrayRef<ValueType> value);
59
//
60
//     Writes an array of values as the current property.
61
//
62
//   PropertyWriter writeObject();
63
//
64
//     Writes an object as the current property; the returned property
65
//     writer will be subjected to a sequence of property writes and then
66
//     discarded before any other properties are written to the "outer"
67
//     property writer (which need not be the same type).  The sub-writer
68
//     will be used as if with the following code:
69
//
70
//       {
71
//         auto &&widget = W.find("widget").writeObject();
72
//         widget.find("kind").writeWidgetKind(...);
73
//         widget.find("declaration").writeDeclRef(...);
74
//       }
75
76
// WriteDispatcher is a template which does type-based forwarding to one
77
// of the write methods of the BasicWriter passed in:
78
//
79
// template <class ValueType>
80
// struct WriteDispatcher {
81
//   template <class BasicWriter>
82
//   static void write(BasicWriter &W, ValueType value);
83
// };
84
85
// BasicWriterBase provides convenience implementations of the write
86
// methods for EnumPropertyType and SubclassPropertyType types that just
87
// defer to the "underlying" implementations (for UInt32 and the base class,
88
// respectively).
89
//
90
// template <class Impl>
91
// class BasicWriterBase {
92
// protected:
93
//   Impl &asImpl();
94
// public:
95
//   ...
96
// };
97
98
// The actual classes are auto-generated; see ClangASTPropertiesEmitter.cpp.
99
#include "clang/AST/AbstractBasicWriter.inc"
100
101
/// DataStreamBasicWriter provides convenience implementations for many
102
/// BasicWriter methods based on the assumption that the
103
/// ultimate writer implementation is based on a variable-length stream
104
/// of unstructured data (like Clang's module files).  It is designed
105
/// to pair with DataStreamBasicReader.
106
///
107
/// This class can also act as a PropertyWriter, implementing find("...")
108
/// by simply forwarding to itself.
109
///
110
/// Unimplemented methods:
111
///   writeBool
112
///   writeUInt32
113
///   writeUInt64
114
///   writeIdentifier
115
///   writeSelector
116
///   writeSourceLocation
117
///   writeQualType
118
///   writeStmtRef
119
///   writeDeclRef
120
template <class Impl>
121
class DataStreamBasicWriter : public BasicWriterBase<Impl> {
122
protected:
123
  using BasicWriterBase<Impl>::asImpl;
124
125
public:
126
  /// Implement property-find by ignoring it.  We rely on properties being
127
  /// serialized and deserialized in a reliable order instead.
128
23.7M
  Impl &find(const char *propertyName) {
129
23.7M
    return asImpl();
130
23.7M
  }
131
132
  // Implement object writing by forwarding to this, collapsing the
133
  // structure into a single data stream.
134
6.10M
  Impl &writeObject() { return asImpl(); }
135
136
  template <class T>
137
7.50M
  void writeEnum(T value) {
138
7.50M
    asImpl().writeUInt32(uint32_t(value));
139
7.50M
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::ArrayType::ArraySizeModifier>(clang::ArrayType::ArraySizeModifier)
Line
Count
Source
137
18.1k
  void writeEnum(T value) {
138
18.1k
    asImpl().writeUInt32(uint32_t(value));
139
18.1k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::attr::Kind>(clang::attr::Kind)
Line
Count
Source
137
18.2k
  void writeEnum(T value) {
138
18.2k
    asImpl().writeUInt32(uint32_t(value));
139
18.2k
  }
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
137
401
  void writeEnum(T value) {
138
401
    asImpl().writeUInt32(uint32_t(value));
139
401
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::TemplateArgument::ArgKind>(clang::TemplateArgument::ArgKind)
Line
Count
Source
137
1.22M
  void writeEnum(T value) {
138
1.22M
    asImpl().writeUInt32(uint32_t(value));
139
1.22M
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::TemplateName::NameKind>(clang::TemplateName::NameKind)
Line
Count
Source
137
569k
  void writeEnum(T value) {
138
569k
    asImpl().writeUInt32(uint32_t(value));
139
569k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::DeclarationName::NameKind>(clang::DeclarationName::NameKind)
Line
Count
Source
137
4.30M
  void writeEnum(T value) {
138
4.30M
    asImpl().writeUInt32(uint32_t(value));
139
4.30M
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::NestedNameSpecifier::SpecifierKind>(clang::NestedNameSpecifier::SpecifierKind)
Line
Count
Source
137
168k
  void writeEnum(T value) {
138
168k
    asImpl().writeUInt32(uint32_t(value));
139
168k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OverloadedOperatorKind>(clang::OverloadedOperatorKind)
Line
Count
Source
137
223k
  void writeEnum(T value) {
138
223k
    asImpl().writeUInt32(uint32_t(value));
139
223k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::ElaboratedTypeKeyword>(clang::ElaboratedTypeKeyword)
Line
Count
Source
137
215k
  void writeEnum(T value) {
138
215k
    asImpl().writeUInt32(uint32_t(value));
139
215k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::VectorType::VectorKind>(clang::VectorType::VectorKind)
Line
Count
Source
137
1.94k
  void writeEnum(T value) {
138
1.94k
    asImpl().writeUInt32(uint32_t(value));
139
1.94k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::CallingConv>(clang::CallingConv)
Line
Count
Source
137
379k
  void writeEnum(T value) {
138
379k
    asImpl().writeUInt32(uint32_t(value));
139
379k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::RefQualifierKind>(clang::RefQualifierKind)
Line
Count
Source
137
379k
  void writeEnum(T value) {
138
379k
    asImpl().writeUInt32(uint32_t(value));
139
379k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::UnaryTransformType::UTTKind>(clang::UnaryTransformType::UTTKind)
Line
Count
Source
137
102
  void writeEnum(T value) {
138
102
    asImpl().writeUInt32(uint32_t(value));
139
102
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OpenMPLastprivateModifier>(clang::OpenMPLastprivateModifier)
Line
Count
Source
137
442
  void writeEnum(T value) {
138
442
    asImpl().writeUInt32(uint32_t(value));
139
442
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<clang::OpenMPOrderClauseKind>(clang::OpenMPOrderClauseKind)
Line
Count
Source
137
43
  void writeEnum(T value) {
138
43
    asImpl().writeUInt32(uint32_t(value));
139
43
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<llvm::omp::TraitSet>(llvm::omp::TraitSet)
Line
Count
Source
137
323
  void writeEnum(T value) {
138
323
    asImpl().writeUInt32(uint32_t(value));
139
323
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<llvm::omp::TraitSelector>(llvm::omp::TraitSelector)
Line
Count
Source
137
323
  void writeEnum(T value) {
138
323
    asImpl().writeUInt32(uint32_t(value));
139
323
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeEnum<llvm::omp::TraitProperty>(llvm::omp::TraitProperty)
Line
Count
Source
137
522
  void writeEnum(T value) {
138
522
    asImpl().writeUInt32(uint32_t(value));
139
522
  }
140
141
  template <class T>
142
1.35M
  void writeArray(llvm::ArrayRef<T> array) {
143
1.35M
    asImpl().writeUInt32(array.size());
144
1.71M
    for (const T &elt : array) {
145
1.71M
      WriteDispatcher<T>::write(asImpl(), elt);
146
1.71M
    }
147
1.35M
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::TemplateArgument>(llvm::ArrayRef<clang::TemplateArgument>)
Line
Count
Source
142
591k
  void writeArray(llvm::ArrayRef<T> array) {
143
591k
    asImpl().writeUInt32(array.size());
144
977k
    for (const T &elt : array) {
145
977k
      WriteDispatcher<T>::write(asImpl(), elt);
146
977k
    }
147
591k
  }
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
142
381k
  void writeArray(llvm::ArrayRef<T> array) {
143
381k
    asImpl().writeUInt32(array.size());
144
734k
    for (const T &elt : array) {
145
734k
      WriteDispatcher<T>::write(asImpl(), elt);
146
734k
    }
147
381k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::FunctionType::ExtParameterInfo>(llvm::ArrayRef<clang::FunctionType::ExtParameterInfo>)
Line
Count
Source
142
379k
  void writeArray(llvm::ArrayRef<T> array) {
143
379k
    asImpl().writeUInt32(array.size());
144
379k
    for (const T &elt : array) {
145
277
      WriteDispatcher<T>::write(asImpl(), elt);
146
277
    }
147
379k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::ObjCProtocolDecl const*>(llvm::ArrayRef<clang::ObjCProtocolDecl const*>)
Line
Count
Source
142
3.63k
  void writeArray(llvm::ArrayRef<T> array) {
143
3.63k
    asImpl().writeUInt32(array.size());
144
3.63k
    for (const T &elt : array) {
145
699
      WriteDispatcher<T>::write(asImpl(), elt);
146
699
    }
147
3.63k
  }
148
149
  template <class T>
150
1.20M
  void writeOptional(llvm::Optional<T> value) {
151
1.20M
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
152
1.20M
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::QualType>(llvm::Optional<clang::QualType>)
Line
Count
Source
150
847k
  void writeOptional(llvm::Optional<T> value) {
151
847k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
152
847k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::ConceptDecl const*>(llvm::Optional<clang::ConceptDecl const*>)
Line
Count
Source
150
401
  void writeOptional(llvm::Optional<T> value) {
151
401
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
152
401
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::IdentifierInfo const*>(llvm::Optional<clang::IdentifierInfo const*>)
Line
Count
Source
150
78
  void writeOptional(llvm::Optional<T> value) {
151
78
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
152
78
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<unsigned int>(llvm::Optional<unsigned int>)
Line
Count
Source
150
13.4k
  void writeOptional(llvm::Optional<T> value) {
151
13.4k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
152
13.4k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::TemplateName>(llvm::Optional<clang::TemplateName>)
Line
Count
Source
150
10
  void writeOptional(llvm::Optional<T> value) {
151
10
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
152
10
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::TagDecl const*>(llvm::Optional<clang::TagDecl const*>)
Line
Count
Source
150
115k
  void writeOptional(llvm::Optional<T> value) {
151
115k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
152
115k
  }
void clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeOptional<clang::TemplateTypeParmDecl const*>(llvm::Optional<clang::TemplateTypeParmDecl const*>)
Line
Count
Source
150
232k
  void writeOptional(llvm::Optional<T> value) {
151
232k
    WriteDispatcher<T>::write(asImpl(), PackOptionalValue<T>::pack(value));
152
232k
  }
153
154
224k
  void writeAPSInt(const llvm::APSInt &value) {
155
224k
    asImpl().writeBool(value.isUnsigned());
156
224k
    asImpl().writeAPInt(value);
157
224k
  }
158
159
704k
  void writeAPInt(const llvm::APInt &value) {
160
704k
    asImpl().writeUInt32(value.getBitWidth());
161
704k
    const uint64_t *words = value.getRawData();
162
1.40M
    for (size_t i = 0, e = value.getNumWords(); i != e; 
++i704k
)
163
704k
      asImpl().writeUInt64(words[i]);
164
704k
  }
165
166
403k
  void writeQualifiers(Qualifiers value) {
167
403k
    static_assert(sizeof(value.getAsOpaqueValue()) <= sizeof(uint32_t),
168
403k
                  "update this if the value size changes");
169
403k
    asImpl().writeUInt32(value.getAsOpaqueValue());
170
403k
  }
171
172
  void writeExceptionSpecInfo(
173
379k
                        const FunctionProtoType::ExceptionSpecInfo &esi) {
174
379k
    asImpl().writeUInt32(uint32_t(esi.Type));
175
379k
    if (esi.Type == EST_Dynamic) {
176
3
      asImpl().writeArray(esi.Exceptions);
177
379k
    } else if (isComputedNoexcept(esi.Type)) {
178
13.6k
      asImpl().writeExprRef(esi.NoexceptExpr);
179
365k
    } else if (esi.Type == EST_Uninstantiated) {
180
3.82k
      asImpl().writeDeclRef(esi.SourceDecl);
181
3.82k
      asImpl().writeDeclRef(esi.SourceTemplate);
182
361k
    } else if (esi.Type == EST_Unevaluated) {
183
18.5k
      asImpl().writeDeclRef(esi.SourceDecl);
184
18.5k
    }
185
379k
  }
186
187
277
  void writeExtParameterInfo(FunctionProtoType::ExtParameterInfo epi) {
188
277
    static_assert(sizeof(epi.getOpaqueValue()) <= sizeof(uint32_t),
189
277
                  "opaque value doesn't fit into uint32_t");
190
277
    asImpl().writeUInt32(epi.getOpaqueValue());
191
277
  }
192
193
215k
  void writeNestedNameSpecifier(NestedNameSpecifier *NNS) {
194
215k
    // Nested name specifiers usually aren't too long. I think that 8 would
195
215k
    // typically accommodate the vast majority.
196
215k
    SmallVector<NestedNameSpecifier *, 8> nestedNames;
197
215k
198
215k
    // Push each of the NNS's onto a stack for serialization in reverse order.
199
384k
    while (NNS) {
200
168k
      nestedNames.push_back(NNS);
201
168k
      NNS = NNS->getPrefix();
202
168k
    }
203
215k
204
215k
    asImpl().writeUInt32(nestedNames.size());
205
384k
    while (!nestedNames.empty()) {
206
168k
      NNS = nestedNames.pop_back_val();
207
168k
      NestedNameSpecifier::SpecifierKind kind = NNS->getKind();
208
168k
      asImpl().writeNestedNameSpecifierKind(kind);
209
168k
      switch (kind) {
210
885
      case NestedNameSpecifier::Identifier:
211
885
        asImpl().writeIdentifier(NNS->getAsIdentifier());
212
885
        continue;
213
0
214
11.2k
      case NestedNameSpecifier::Namespace:
215
11.2k
        asImpl().writeNamespaceDeclRef(NNS->getAsNamespace());
216
11.2k
        continue;
217
0
218
4
      case NestedNameSpecifier::NamespaceAlias:
219
4
        asImpl().writeNamespaceAliasDeclRef(NNS->getAsNamespaceAlias());
220
4
        continue;
221
0
222
156k
      case NestedNameSpecifier::TypeSpec:
223
156k
      case NestedNameSpecifier::TypeSpecWithTemplate:
224
156k
        asImpl().writeQualType(QualType(NNS->getAsType(), 0));
225
156k
        continue;
226
156k
227
156k
      case NestedNameSpecifier::Global:
228
24
        // Don't need to write an associated value.
229
24
        continue;
230
156k
231
156k
      case NestedNameSpecifier::Super:
232
0
        asImpl().writeDeclRef(NNS->getAsRecordDecl());
233
0
        continue;
234
0
      }
235
0
      llvm_unreachable("bad nested name specifier kind");
236
0
    }
237
215k
  }
238
};
239
240
} // end namespace serialization
241
} // end namespace clang
242
243
#endif