Attribute,
Double,
Integer,
- Operation,
String,
Type,
Unsigned,
return static_cast<int64_t>(opaqueVal);
}
- /// Returns this argument as an operation.
- Operation &getAsOperation() const {
- assert(getKind() == DiagnosticArgumentKind::Operation);
- return *reinterpret_cast<Operation *>(opaqueVal);
- }
-
/// Returns this argument as a string.
StringRef getAsString() const {
assert(getKind() == DiagnosticArgumentKind::String);
sizeof(T) <= sizeof(uint64_t)>::type * = 0)
: kind(DiagnosticArgumentKind::Unsigned), opaqueVal(uint64_t(val)) {}
- // Construct from an operation reference.
- explicit DiagnosticArgument(Operation &val) : DiagnosticArgument(&val) {}
- explicit DiagnosticArgument(Operation *val)
- : kind(DiagnosticArgumentKind::Operation),
- opaqueVal(reinterpret_cast<intptr_t>(val)) {
- assert(val && "expected valid operation");
- }
-
// Construct from a string reference.
explicit DiagnosticArgument(StringRef val)
: kind(DiagnosticArgumentKind::String), stringVal(val) {}
/// Stream in an OperationName.
Diagnostic &operator<<(OperationName val);
+ /// Stream in an Operation.
+ Diagnostic &operator<<(Operation &val);
+ Diagnostic &operator<<(Operation *val) {
+ return *this << *val;
+ }
+
/// Stream in a range.
template <typename T> Diagnostic &operator<<(iterator_range<T> range) {
return appendRange(range);
// DiagnosticArgument
//===----------------------------------------------------------------------===//
-// Construct from an Attribute.
+/// Construct from an Attribute.
DiagnosticArgument::DiagnosticArgument(Attribute attr)
: kind(DiagnosticArgumentKind::Attribute),
opaqueVal(reinterpret_cast<intptr_t>(attr.getAsOpaquePointer())) {}
-// Construct from a Type.
+/// Construct from a Type.
DiagnosticArgument::DiagnosticArgument(Type val)
: kind(DiagnosticArgumentKind::Type),
opaqueVal(reinterpret_cast<intptr_t>(val.getAsOpaquePointer())) {}
case DiagnosticArgumentKind::Integer:
os << getAsInteger();
break;
- case DiagnosticArgumentKind::Operation:
- getAsOperation().print(os, OpPrintingFlags().useLocalScope());
- break;
case DiagnosticArgumentKind::String:
os << getAsString();
break;
return *this;
}
+/// Stream in an Operation.
+Diagnostic &Diagnostic::operator<<(Operation &val) {
+ std::string str;
+ llvm::raw_string_ostream os(str);
+ os << val;
+ return *this << os.str();
+}
+
/// Outputs this diagnostic to a stream.
void Diagnostic::print(raw_ostream &os) const {
for (auto &arg : getArguments())