@@ -38,11 +38,10 @@ using ParseCoefficientFn = std::function<OptionalParseResult(MonomialType &)>;
38
38
// / a '+'.
39
39
// /
40
40
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) {
46
45
OptionalParseResult parsedCoeffResult = parseAndStoreCoefficient (monomial);
47
46
48
47
isConstantTerm = false ;
@@ -86,9 +85,8 @@ ParseResult parseMonomial(AsmParser &parser, Monomial &monomial,
86
85
// If there's a **, then the integer exponent is required.
87
86
APInt parsedExponent (apintBitWidth, 0 );
88
87
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" );
92
90
return failure ();
93
91
}
94
92
@@ -107,18 +105,16 @@ template <typename Monomial>
107
105
LogicalResult
108
106
parsePolynomialAttr (AsmParser &parser, llvm::SmallVector<Monomial> &monomials,
109
107
llvm::StringSet<> &variables,
110
- ParseCoefficientFn<Monomial> parseAndStoreCoefficient,
111
- bool optional) {
108
+ ParseCoefficientFn<Monomial> parseAndStoreCoefficient) {
112
109
while (true ) {
113
110
Monomial parsedMonomial;
114
111
llvm::StringRef parsedVariableRef;
115
112
bool isConstantTerm;
116
113
bool shouldParseMore;
117
114
if (failed (parseMonomial<Monomial>(
118
115
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" );
122
118
return failure ();
123
119
}
124
120
@@ -134,32 +130,25 @@ parsePolynomialAttr(AsmParser &parser, llvm::SmallVector<Monomial> &monomials,
134
130
if (succeeded (parser.parseOptionalGreater ())) {
135
131
break ;
136
132
}
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" );
141
136
return failure ();
142
137
}
143
138
144
139
if (variables.size () > 1 ) {
145
140
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);
151
145
return failure ();
152
146
}
153
147
154
148
return success ();
155
149
}
156
150
157
151
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) {
163
152
if (failed (parser.parseLess ()))
164
153
return {};
165
154
@@ -174,27 +163,19 @@ Attribute IntPolynomialAttr::parse(AsmParser &parser, Type type,
174
163
parser.parseOptionalInteger (parsedCoeff);
175
164
monomial.setCoefficient (parsedCoeff);
176
165
return result;
177
- },
178
- optional))) {
166
+ }))) {
179
167
return {};
180
168
}
181
169
182
170
auto result = IntPolynomial::fromMonomials (monomials);
183
171
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" ;
187
174
return {};
188
175
}
189
176
return IntPolynomialAttr::get (parser.getContext (), result.value ());
190
177
}
191
-
192
178
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) {
198
179
if (failed (parser.parseLess ()))
199
180
return {};
200
181
@@ -209,8 +190,8 @@ Attribute FloatPolynomialAttr::parse(AsmParser &parser, Type type,
209
190
return OptionalParseResult (result);
210
191
};
211
192
212
- if (failed (parsePolynomialAttr<FloatMonomial>(
213
- parser, monomials, variables, parseAndStoreCoefficient, optional ))) {
193
+ if (failed (parsePolynomialAttr<FloatMonomial>(parser, monomials, variables,
194
+ parseAndStoreCoefficient ))) {
214
195
return {};
215
196
}
216
197
0 commit comments