@@ -103,6 +103,16 @@ LogicalResult mlir::substrait::IntervalDaySecondAttr::verify(
103103 return success ();
104104}
105105
106+ LogicalResult mlir::substrait::VarCharAttr::verify (
107+ llvm::function_ref<mlir::InFlightDiagnostic()> emitError, StringAttr value,
108+ VarCharType type) {
109+ int32_t value_length = value.size ();
110+ if (value_length > type.getLength ())
111+ return emitError () << " value length must be at most " << type.getLength ()
112+ << " characters." ;
113+ return success ();
114+ }
115+
106116// ===----------------------------------------------------------------------===//
107117// Substrait types
108118// ===----------------------------------------------------------------------===//
@@ -288,6 +298,26 @@ void printCountAsAll(OpAsmPrinter &printer, Operation *op, IntegerAttr count) {
288298 printer << count.getValue ();
289299}
290300
301+ // Parses a VarCharType by extracting the length from the given parser. Assumes
302+ // the length is surrounded by `<` and `>` symbols, which are removed. On
303+ // success, assigns the parsed type to `type` and returns success.
304+ ParseResult parseVarCharTypeByLength (AsmParser &parser, VarCharType &type) {
305+ // remove `<` and `>` symbols
306+ int64_t result;
307+ if (parser.parseInteger (result))
308+ return failure ();
309+
310+ type = VarCharType::get (parser.getContext (), result);
311+
312+ return success ();
313+ }
314+
315+ // Prints the VarCharType by outputting its length to the given printer.
316+ void printVarCharTypeByLength (AsmPrinter &printer, VarCharType type) {
317+ // Normal integer.
318+ printer << type.getLength ();
319+ }
320+
291321ParseResult parseDecimalNumber (AsmParser &parser, DecimalType &type,
292322 IntegerAttr &value) {
293323 llvm::SMLoc loc = parser.getCurrentLocation ();
0 commit comments