Skip to content

Commit f9019bc

Browse files
committed
remove optional parse option
1 parent 431bf8a commit f9019bc

File tree

2 files changed

+21
-50
lines changed

2 files changed

+21
-50
lines changed

mlir/include/mlir/Dialect/Polynomial/IR/PolynomialAttributes.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ def Polynomial_IntPolynomialAttr : Polynomial_Attr<"IntPolynomial", "int_polynom
3838
}];
3939
let parameters = (ins "::mlir::polynomial::IntPolynomial":$polynomial);
4040
let hasCustomAssemblyFormat = 1;
41-
let extraClassDeclaration = [{
42-
/// A parser which, upon failure to parse, does not emit errors and just returns
43-
/// a null attribute.
44-
static Attribute parse(AsmParser &parser, Type type, bool optional);
45-
}];
4641
}
4742

4843
def Polynomial_FloatPolynomialAttr : Polynomial_Attr<"FloatPolynomial", "float_polynomial"> {
@@ -65,11 +60,6 @@ def Polynomial_FloatPolynomialAttr : Polynomial_Attr<"FloatPolynomial", "float_p
6560
}];
6661
let parameters = (ins "FloatPolynomial":$polynomial);
6762
let hasCustomAssemblyFormat = 1;
68-
let extraClassDeclaration = [{
69-
/// A parser which, upon failure to parse, does not emit errors and just returns
70-
/// a null attribute.
71-
static Attribute parse(AsmParser &parser, Type type, bool optional);
72-
}];
7363
}
7464

7565
def Polynomial_TypedIntPolynomialAttr : Polynomial_Attr<

mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ using ParseCoefficientFn = std::function<OptionalParseResult(MonomialType &)>;
3838
/// a '+'.
3939
///
4040
template <typename Monomial>
41-
ParseResult parseMonomial(AsmParser &parser, Monomial &monomial,
42-
llvm::StringRef &variable, bool &isConstantTerm,
43-
bool &shouldParseMore,
44-
ParseCoefficientFn<Monomial> parseAndStoreCoefficient,
45-
bool optional) {
41+
ParseResult
42+
parseMonomial(AsmParser &parser, Monomial &monomial, llvm::StringRef &variable,
43+
bool &isConstantTerm, bool &shouldParseMore,
44+
ParseCoefficientFn<Monomial> parseAndStoreCoefficient) {
4645
OptionalParseResult parsedCoeffResult = parseAndStoreCoefficient(monomial);
4746

4847
isConstantTerm = false;
@@ -86,9 +85,8 @@ ParseResult parseMonomial(AsmParser &parser, Monomial &monomial,
8685
// If there's a **, then the integer exponent is required.
8786
APInt parsedExponent(apintBitWidth, 0);
8887
if (failed(parser.parseInteger(parsedExponent))) {
89-
if (!optional)
90-
parser.emitError(parser.getCurrentLocation(),
91-
"found invalid integer exponent");
88+
parser.emitError(parser.getCurrentLocation(),
89+
"found invalid integer exponent");
9290
return failure();
9391
}
9492

@@ -107,18 +105,16 @@ template <typename Monomial>
107105
LogicalResult
108106
parsePolynomialAttr(AsmParser &parser, llvm::SmallVector<Monomial> &monomials,
109107
llvm::StringSet<> &variables,
110-
ParseCoefficientFn<Monomial> parseAndStoreCoefficient,
111-
bool optional) {
108+
ParseCoefficientFn<Monomial> parseAndStoreCoefficient) {
112109
while (true) {
113110
Monomial parsedMonomial;
114111
llvm::StringRef parsedVariableRef;
115112
bool isConstantTerm;
116113
bool shouldParseMore;
117114
if (failed(parseMonomial<Monomial>(
118115
parser, parsedMonomial, parsedVariableRef, isConstantTerm,
119-
shouldParseMore, parseAndStoreCoefficient, optional))) {
120-
if (!optional)
121-
parser.emitError(parser.getCurrentLocation(), "expected a monomial");
116+
shouldParseMore, parseAndStoreCoefficient))) {
117+
parser.emitError(parser.getCurrentLocation(), "expected a monomial");
122118
return failure();
123119
}
124120

@@ -134,32 +130,25 @@ parsePolynomialAttr(AsmParser &parser, llvm::SmallVector<Monomial> &monomials,
134130
if (succeeded(parser.parseOptionalGreater())) {
135131
break;
136132
}
137-
if (!optional)
138-
parser.emitError(
139-
parser.getCurrentLocation(),
140-
"expected + and more monomials, or > to end polynomial attribute");
133+
parser.emitError(
134+
parser.getCurrentLocation(),
135+
"expected + and more monomials, or > to end polynomial attribute");
141136
return failure();
142137
}
143138

144139
if (variables.size() > 1) {
145140
std::string vars = llvm::join(variables.keys(), ", ");
146-
if (!optional)
147-
parser.emitError(
148-
parser.getCurrentLocation(),
149-
"polynomials must have one indeterminate, but there were multiple: " +
150-
vars);
141+
parser.emitError(
142+
parser.getCurrentLocation(),
143+
"polynomials must have one indeterminate, but there were multiple: " +
144+
vars);
151145
return failure();
152146
}
153147

154148
return success();
155149
}
156150

157151
Attribute IntPolynomialAttr::parse(AsmParser &parser, Type type) {
158-
return IntPolynomialAttr::parse(parser, type, /*optional=*/false);
159-
}
160-
161-
Attribute IntPolynomialAttr::parse(AsmParser &parser, Type type,
162-
bool optional) {
163152
if (failed(parser.parseLess()))
164153
return {};
165154

@@ -174,27 +163,19 @@ Attribute IntPolynomialAttr::parse(AsmParser &parser, Type type,
174163
parser.parseOptionalInteger(parsedCoeff);
175164
monomial.setCoefficient(parsedCoeff);
176165
return result;
177-
},
178-
optional))) {
166+
}))) {
179167
return {};
180168
}
181169

182170
auto result = IntPolynomial::fromMonomials(monomials);
183171
if (failed(result)) {
184-
if (!optional)
185-
parser.emitError(parser.getCurrentLocation())
186-
<< "parsed polynomial must have unique exponents among monomials";
172+
parser.emitError(parser.getCurrentLocation())
173+
<< "parsed polynomial must have unique exponents among monomials";
187174
return {};
188175
}
189176
return IntPolynomialAttr::get(parser.getContext(), result.value());
190177
}
191-
192178
Attribute FloatPolynomialAttr::parse(AsmParser &parser, Type type) {
193-
return FloatPolynomialAttr::parse(parser, type, /*optional=*/false);
194-
}
195-
196-
Attribute FloatPolynomialAttr::parse(AsmParser &parser, Type type,
197-
bool optional) {
198179
if (failed(parser.parseLess()))
199180
return {};
200181

@@ -209,8 +190,8 @@ Attribute FloatPolynomialAttr::parse(AsmParser &parser, Type type,
209190
return OptionalParseResult(result);
210191
};
211192

212-
if (failed(parsePolynomialAttr<FloatMonomial>(
213-
parser, monomials, variables, parseAndStoreCoefficient, optional))) {
193+
if (failed(parsePolynomialAttr<FloatMonomial>(parser, monomials, variables,
194+
parseAndStoreCoefficient))) {
214195
return {};
215196
}
216197

0 commit comments

Comments
 (0)