using llvm::SMLoc;
using llvm::SourceMgr;
-/// Simple enum to make code read better in cases that would otherwise return a
-/// bool value. Failure is "true" in a boolean context.
-enum ParseResult { ParseSuccess, ParseFailure };
+/// Simple wrapper class around LogicalResult that allows for explicit
+/// conversion to bool. This allows for the parser to chain together parse rules
+/// without the clutter of "failed/succeeded".
+class ParseResult : public LogicalResult {
+public:
+ ParseResult(LogicalResult result = success()) : LogicalResult(result) {}
+
+ /// Failure is true in a boolean context.
+ explicit operator bool() const { return failed(*this); }
+};
namespace {
class Parser;
ParseResult parseOptionalTrailingLocation(Owner *owner) {
// If there is a 'loc' we parse a trailing location.
if (!getToken().is(Token::kw_loc))
- return ParseSuccess;
+ return success();
// Parse the location.
llvm::Optional<Location> directLoc;
if (parseLocation(&directLoc))
- return ParseFailure;
+ return failure();
owner->setLoc(*directLoc);
- return ParseSuccess;
+ return success();
}
/// Parse an inline location.
// If we hit a parse error in response to a lexer error, then the lexer
// already reported the error.
if (getToken().is(Token::error))
- return ParseFailure;
+ return failure();
getContext()->emitError(getEncodedSourceLocation(loc), message);
- return ParseFailure;
+ return failure();
}
/// Consume the specified token if present and return success. On failure,
ParseResult Parser::parseToken(Token::Kind expectedToken,
const Twine &message) {
if (consumeIf(expectedToken))
- return ParseSuccess;
+ return success();
return emitError(message);
}
const std::function<ParseResult()> &parseElement) {
// Non-empty case starts with an element.
if (parseElement())
- return ParseFailure;
+ return failure();
// Otherwise we have a list of comma separated elements.
while (consumeIf(Token::comma)) {
if (parseElement())
- return ParseFailure;
+ return failure();
}
- return ParseSuccess;
+ return success();
}
/// Parse a comma-separated list of elements, terminated with an arbitrary
if (!allowEmptyList)
return emitError("expected list element");
consumeToken(rightToken);
- return ParseSuccess;
+ return success();
}
if (parseCommaSeparatedList(parseElement) ||
parseToken(rightToken, "expected ',' or '" +
Token::getTokenSpelling(rightToken) + "'"))
- return ParseFailure;
+ return failure();
- return ParseSuccess;
+ return success();
}
//===----------------------------------------------------------------------===//
// Consume the 'x'.
consumeToken(Token::bare_identifier);
- return ParseSuccess;
+ return success();
}
/// Parse a dimension list of a tensor or memref type. This populates the
// Make sure we have an 'x' or something like 'xbf32'.
if (parseXInDimensionList())
- return ParseFailure;
+ return failure();
}
- return ParseSuccess;
+ return success();
}
/// Parse the body of a pretty dialect type, which starts and ends with <>'s,
unsigned length = curPtr - prettyName.begin();
prettyName = StringRef(prettyName.begin(), length);
consumeToken();
- return ParseSuccess;
+ return success();
}
/// Parse an extended type.
return emitError("affine map after memory space in memref type");
auto affineMap = parseAttribute();
if (!affineMap)
- return ParseFailure;
+ return failure();
// Verify that the parsed attribute is an affine map.
if (auto affineMapAttr = affineMap.dyn_cast<AffineMapAttr>())
else
return emitError("expected affine map in memref type");
}
- return ParseSuccess;
+ return success();
};
// Parse a list of mappings and address space if present.
auto parseElt = [&]() -> ParseResult {
auto elt = parseType();
elements.push_back(elt);
- return elt ? ParseSuccess : ParseFailure;
+ return elt ? success() : failure();
};
return parseCommaSeparatedList(parseElt);
///
ParseResult Parser::parseTypeListParens(SmallVectorImpl<Type> &elements) {
if (parseToken(Token::l_paren, "expected '('"))
- return ParseFailure;
+ return failure();
// Handle empty lists.
if (getToken().is(Token::r_paren))
- return consumeToken(), ParseSuccess;
+ return consumeToken(), success();
if (parseTypeListNoParens(elements) ||
parseToken(Token::r_paren, "expected ')'"))
- return ParseFailure;
- return ParseSuccess;
+ return failure();
+ return success();
}
/// Parse a function result type.
Type t = parseNonFunctionType();
if (!t)
- return ParseFailure;
+ return failure();
elements.push_back(t);
- return ParseSuccess;
+ return success();
}
//===----------------------------------------------------------------------===//
case Token::minus: {
auto result = p.parseAttribute(eltTy);
if (!result)
- return ParseResult::ParseFailure;
+ return failure();
// check result matches the element type.
switch (eltTy.getKind()) {
case StandardTypes::BF16:
default:
return p.emitError("expected element literal of primitive type");
}
- return ParseSuccess;
+ return success();
}
/// Parse a list of either lists or elements, returning the dimensions of the
TensorLiteralParser::parseList(llvm::SmallVectorImpl<int64_t> &dims) {
p.consumeToken(Token::l_square);
- auto checkDims = [&](const llvm::SmallVectorImpl<int64_t> &prevDims,
- const llvm::SmallVectorImpl<int64_t> &newDims) {
+ auto checkDims =
+ [&](const llvm::SmallVectorImpl<int64_t> &prevDims,
+ const llvm::SmallVectorImpl<int64_t> &newDims) -> ParseResult {
if (prevDims == newDims)
- return ParseSuccess;
+ return success();
return p.emitError("tensor literal is invalid; ranks are not consistent "
"between elements");
};
bool first = true;
llvm::SmallVector<int64_t, 4> newDims;
unsigned size = 0;
- auto parseCommaSeparatedList = [&]() {
+ auto parseCommaSeparatedList = [&]() -> ParseResult {
llvm::SmallVector<int64_t, 4> thisDims;
if (p.getToken().getKind() == Token::l_square) {
if (parseList(thisDims))
- return ParseFailure;
+ return failure();
} else if (parseElement()) {
- return ParseFailure;
+ return failure();
}
++size;
if (!first)
return checkDims(newDims, thisDims);
newDims = thisDims;
first = false;
- return ParseSuccess;
+ return success();
};
if (p.parseCommaSeparatedListUntil(Token::r_square, parseCommaSeparatedList))
- return ParseFailure;
+ return failure();
// Return the sublists' dimensions with 'size' prepended.
dims.clear();
dims.push_back(size);
dims.append(newDims.begin(), newDims.end());
- return ParseSuccess;
+ return success();
}
/// Given a parsed reference to a function name like @foo and a type that it
auto parseElt = [&]() -> ParseResult {
elements.push_back(parseAttribute());
- return elements.back() ? ParseSuccess : ParseFailure;
+ return elements.back() ? success() : failure();
};
if (parseCommaSeparatedListUntil(Token::r_square, parseElt))
if (parseToken(Token::l_paren, "expected '(' in inline location") ||
parseLocationInstance(loc) ||
parseToken(Token::r_paren, "expected ')' in inline location"))
- return ParseFailure;
- return ParseSuccess;
+ return failure();
+ return success();
}
/// Specific location instances.
// Parse the ':'.
if (parseToken(Token::colon, "expected ':' in FileLineColLoc"))
- return ParseFailure;
+ return failure();
// Parse the column number.
if (getToken().isNot(Token::integer))
auto file = UniquedFilename::get(str, ctx);
*loc = FileLineColLoc::get(file, line.getValue(), column.getValue(), ctx);
- return ParseSuccess;
+ return success();
}
// Otherwise, this is a NameLoc.
*loc = NameLoc::get(Identifier::get(str, ctx), ctx);
- return ParseSuccess;
+ return success();
}
// Check for a 'unknown' for an unknown location.
getToken().getSpelling() == "unknown") {
consumeToken(Token::bare_identifier);
*loc = UnknownLoc::get(ctx);
- return ParseSuccess;
+ return success();
}
// If the token is 'fused', then this is a fused location.
// Parse the '>' token.
if (parseToken(Token::greater,
"expected '>' after fused location metadata"))
- return ParseFailure;
+ return failure();
}
// Parse the '['.
if (parseToken(Token::l_square, "expected '[' in fused location"))
- return ParseFailure;
+ return failure();
// Parse the internal locations.
llvm::SmallVector<Location, 4> locations;
do {
llvm::Optional<Location> newLoc;
if (parseLocationInstance(&newLoc))
- return ParseFailure;
+ return failure();
locations.push_back(*newLoc);
// Parse the ','.
// Parse the ']'.
if (parseToken(Token::r_square, "expected ']' in fused location"))
- return ParseFailure;
+ return failure();
// Return the fused location.
if (metadata)
*loc = FusedLoc::get(locations, metadata, getContext());
else
*loc = FusedLoc::get(locations, ctx);
- return ParseSuccess;
+ return success();
}
// Check for the 'callsite' signifying a callsite location.
// Parse the '('.
if (parseToken(Token::l_paren, "expected '(' in callsite location"))
- return ParseFailure;
+ return failure();
// Parse the callee location.
llvm::Optional<Location> calleeLoc;
if (parseLocationInstance(&calleeLoc))
- return ParseFailure;
+ return failure();
// Parse the 'at'.
if (getToken().isNot(Token::bare_identifier) ||
// Parse the caller location.
llvm::Optional<Location> callerLoc;
if (parseLocationInstance(&callerLoc))
- return ParseFailure;
+ return failure();
// Parse the ')'.
if (parseToken(Token::r_paren, "expected ')' in callsite location"))
- return ParseFailure;
+ return failure();
// Return the callsite location.
*loc = CallSiteLoc::get(*calleeLoc, *callerLoc, ctx);
- return ParseSuccess;
+ return success();
}
return emitError("expected location instance");
ParseResult
Parser::parseAttributeDict(SmallVectorImpl<NamedAttribute> &attributes) {
if (!consumeIf(Token::l_brace))
- return ParseFailure;
+ return failure();
auto parseElt = [&]() -> ParseResult {
// We allow keywords as attribute names.
if (!consumeIf(Token::colon)) {
// If there is no ':', we treat this as a unit attribute.
attributes.push_back({nameId, builder.getUnitAttr()});
- return ParseSuccess;
+ return success();
}
auto attr = parseAttribute();
if (!attr)
- return ParseFailure;
+ return failure();
attributes.push_back({nameId, attr});
- return ParseSuccess;
+ return success();
};
if (parseCommaSeparatedListUntil(Token::r_brace, parseElt))
- return ParseFailure;
+ return failure();
- return ParseSuccess;
+ return success();
}
//===----------------------------------------------------------------------===//
consumeToken(Token::bare_identifier);
dimsAndSymbols.push_back({name, idExpr});
- return ParseSuccess;
+ return success();
}
/// Parse the list of dimensional identifiers to an affine map.
ParseResult AffineParser::parseDimIdList(unsigned &numDims) {
if (parseToken(Token::l_paren,
"expected '(' at start of dimensional identifiers list")) {
- return ParseFailure;
+ return failure();
}
auto parseElt = [&]() -> ParseResult {
AffineParser::parseDimAndOptionalSymbolIdList(unsigned &numDims,
unsigned &numSymbols) {
if (parseDimIdList(numDims)) {
- return ParseResult::ParseFailure;
+ return failure();
}
if (!getToken().is(Token::l_square)) {
numSymbols = 0;
- return ParseResult::ParseSuccess;
+ return success();
}
return parseSymbolIdList(numSymbols);
}
// List of dimensional and optional symbol identifiers.
if (parseDimAndOptionalSymbolIdList(numDims, numSymbols)) {
- return ParseResult::ParseFailure;
+ return failure();
}
// This is needed for parsing attributes as we wouldn't know whether we would
} else if (isArrow) {
parseToken(Token::arrow, "expected '->' or '['");
map = parseAffineMapRange(numDims, numSymbols);
- return map ? ParseSuccess : ParseFailure;
+ return map ? success() : failure();
} else if (parseToken(Token::colon, "expected ':' or '['")) {
- return ParseFailure;
+ return failure();
}
if ((set = parseIntegerSetConstraints(numDims, numSymbols)))
- return ParseSuccess;
+ return success();
- return ParseFailure;
+ return failure();
}
/// Parse the range and sizes affine map definition inline.
SmallVector<AffineExpr, 4> exprs;
auto parseElt = [&]() -> ParseResult {
auto elt = parseAffineExpr();
- ParseResult res = elt ? ParseSuccess : ParseFailure;
+ ParseResult res = elt ? success() : failure();
exprs.push_back(elt);
return res;
};
auto loc = getToken().getLoc();
auto elt = parseAffineExpr();
if (!elt)
- return ParseFailure;
+ return failure();
if (!elt.isSymbolicOrConstant())
return emitError(loc,
"size expressions cannot refer to dimension values");
rangeSizes.push_back(elt);
- return ParseSuccess;
+ return success();
};
if (parseCommaSeparatedListUntil(Token::r_paren, parseRangeSize, false))
ParseResult FunctionParser::parseFunctionBody(bool hadNamedArguments) {
auto braceLoc = getToken().getLoc();
if (parseToken(Token::l_brace, "expected '{' in function"))
- return ParseFailure;
+ return failure();
// Make sure we have at least one block.
if (getToken().is(Token::r_brace))
// Parse the first block.
if (parseBlock(firstBlock))
- return ParseFailure;
+ return failure();
// Parse the remaining list of blocks.
if (parseRegionBody(function->getBody()))
- return ParseFailure;
+ return failure();
// Verify that all referenced blocks were defined.
if (!forwardRef.empty()) {
auto loc = SMLoc::getFromPointer(entry.first);
emitError(loc, "reference to an undefined block");
}
- return ParseFailure;
+ return failure();
}
return finalizeFunction(braceLoc);
ArrayRef<std::pair<FunctionParser::SSAUseInfo, Type>> entryArguments) {
// Parse the '{'.
if (parseToken(Token::l_brace, "expected '{' to begin a region"))
- return ParseFailure;
+ return failure();
// Check for an empty region.
if (entryArguments.empty() && consumeIf(Token::r_brace))
- return ParseSuccess;
+ return success();
Block *currentBlock = builder.getInsertionBlock();
// Parse the first block directly to allow for it to be unnamed.
if (addDefinition(placeholderArgPair.first,
block->addArgument(placeholderArgPair.second))) {
delete block;
- return ParseFailure;
+ return failure();
}
if (parseBlock(block)) {
delete block;
- return ParseFailure;
+ return failure();
}
// Verify that no other arguments were parsed.
// Parse the rest of the region.
region.push_back(block);
if (parseRegionBody(region))
- return ParseFailure;
+ return failure();
// Reset insertion point to the current block.
builder.setInsertionPointToEnd(currentBlock);
- return ParseSuccess;
+ return success();
}
/// Region.
while (!consumeIf(Token::r_brace)) {
Block *newBlock = nullptr;
if (parseBlock(newBlock))
- return ParseFailure;
+ return failure();
region.push_back(newBlock);
}
- return ParseSuccess;
+ return success();
}
/// Block declaration.
SMLoc nameLoc = getToken().getLoc();
auto name = getTokenSpelling();
if (parseToken(Token::caret_identifier, "expected block name"))
- return ParseFailure;
+ return failure();
block = defineBlockNamed(name, nameLoc, block);
SmallVector<BlockArgument *, 8> bbArgs;
if (parseOptionalBlockArgList(bbArgs, block) ||
parseToken(Token::r_paren, "expected ')' to end argument list"))
- return ParseFailure;
+ return failure();
}
if (parseToken(Token::colon, "expected ':' after block name"))
- return ParseFailure;
+ return failure();
return parseBlockBody(block);
}
switch (getToken().getKind()) {
default:
if (parseOperation())
- return ParseFailure;
+ return failure();
break;
}
}
- return ParseSuccess;
+ return success();
}
/// Create and remember a new placeholder for a forward reference.
auto loc = SMLoc::getFromPointer(entry.first);
emitError(loc, "use of undeclared SSA value name");
}
- return ParseFailure;
+ return failure();
}
- return ParseSuccess;
+ return success();
}
FunctionParser::~FunctionParser() {
entries[useInfo.number].first = value;
entries[useInfo.number].second = useInfo.loc;
- return ParseSuccess;
+ return success();
}
/// Parse a SSA operand for an operation.
result.number = 0;
result.loc = getToken().getLoc();
if (parseToken(Token::percent_identifier, "expected SSA operand"))
- return ParseFailure;
+ return failure();
// If we have an affine map ID, it is a result number.
if (getToken().is(Token::hash_identifier)) {
consumeToken(Token::hash_identifier);
}
- return ParseSuccess;
+ return success();
}
/// Parse a (possibly empty) list of SSA operands.
ParseResult
FunctionParser::parseOptionalSSAUseList(SmallVectorImpl<SSAUseInfo> &results) {
if (getToken().isNot(Token::percent_identifier))
- return ParseSuccess;
+ return success();
return parseCommaSeparatedList([&]() -> ParseResult {
SSAUseInfo result;
if (parseSSAUse(result))
- return ParseFailure;
+ return failure();
results.push_back(result);
- return ParseSuccess;
+ return success();
});
}
SmallVectorImpl<ValueTy *> &results) {
SmallVector<SSAUseInfo, 4> valueIDs;
if (parseOptionalSSAUseList(valueIDs))
- return ParseFailure;
+ return failure();
// If there were no operands, then there is no colon or type lists.
if (valueIDs.empty())
- return ParseSuccess;
+ return success();
SmallVector<Type, 4> types;
if (parseToken(Token::colon, "expected ':' in operand list") ||
parseTypeListNoParens(types))
- return ParseFailure;
+ return failure();
if (valueIDs.size() != types.size())
return emitError("expected " + Twine(valueIDs.size()) +
if (auto *value = resolveSSAUse(valueIDs[i], types[i]))
results.push_back(cast<ValueTy>(value));
else
- return ParseFailure;
+ return failure();
}
- return ParseSuccess;
+ return success();
}
/// Get the block with the specified name, creating it if it doesn't already
Block *&dest, SmallVectorImpl<Value *> &operands) {
// Verify branch is identifier and get the matching block.
if (!getToken().is(Token::caret_identifier))
- return emitError("expected block name");
+ return emitError("expected block name"), true;
dest = getBlockNamed(getTokenSpelling(), getToken().getLoc());
consumeToken();
SmallVectorImpl<Block *> &destinations,
SmallVectorImpl<SmallVector<Value *, 4>> &operands) {
if (parseToken(Token::l_square, "expected '['"))
- return ParseFailure;
+ return failure();
auto parseElt = [this, &destinations, &operands]() {
Block *dest;
bool r = parseSuccessorAndUseList(dest, destOperands);
destinations.push_back(dest);
operands.push_back(destOperands);
- return r ? ParseFailure : ParseSuccess;
+ return r ? failure() : success();
};
return parseCommaSeparatedListUntil(Token::r_square, parseElt,
/*allowEmptyList=*/false);
ParseResult FunctionParser::parseOptionalBlockArgList(
SmallVectorImpl<BlockArgument *> &results, Block *owner) {
if (getToken().is(Token::r_brace))
- return ParseSuccess;
+ return success();
// If the block already has arguments, then we're handling the entry block.
// Parse and register the names for the arguments, but do not add them.
return {};
return type;
});
- return type ? ParseSuccess : ParseFailure;
+ return type ? success() : failure();
});
}
} else {
// Otherwise, this is a comma separated list of result ids.
if (consumeIf(Token::comma)) {
- auto parseNextResult = [&] {
+ auto parseNextResult = [&]() -> ParseResult {
// Parse the next result id.
if (!getToken().is(Token::percent_identifier))
return emitError("expected valid ssa identifier");
resultIDs.emplace_back(getTokenSpelling(), getToken().getLoc());
consumeToken(Token::percent_identifier);
- return ParseSuccess;
+ return success();
};
if (parseCommaSeparatedList(parseNextResult))
- return ParseFailure;
+ return failure();
}
numExpectedResults = resultIDs.size();
}
if (parseToken(Token::equal, "expected '=' after SSA name"))
- return ParseFailure;
+ return failure();
}
Operation *op;
// If parsing of the basic operation failed, then this whole thing fails.
if (!op)
- return ParseFailure;
+ return failure();
// If the operation had a name, register it.
if (!resultIDs.empty()) {
for (unsigned i = 0, e = op->getNumResults(); i != e; ++i)
if (addDefinition({resultIDs[i].first, 0, resultIDs[i].second},
op->getResult(i)))
- return ParseFailure;
+ return failure();
} else {
// Otherwise, we use the same name for all results.
StringRef name = resultIDs.front().first;
for (unsigned i = 0, e = op->getNumResults(); i != e; ++i)
if (addDefinition({name, i, loc}, op->getResult(i)))
- return ParseFailure;
+ return failure();
}
}
// Try to parse the optional trailing location.
if (parseOptionalTrailingLocation(op))
- return ParseFailure;
+ return failure();
- return ParseSuccess;
+ return success();
}
namespace {
return false;
}
bool parseComma() override {
- return parser.parseToken(Token::comma, "expected ','");
+ return failed(parser.parseToken(Token::comma, "expected ','"));
}
bool parseColon() override {
- return parser.parseToken(Token::colon, "expected ':'");
+ return failed(parser.parseToken(Token::colon, "expected ':'"));
}
bool parseEqual() override {
- return parser.parseToken(Token::equal, "expected '='");
+ return failed(parser.parseToken(Token::equal, "expected '='"));
}
bool parseType(Type &result) override {
parseOptionalAttributeDict(SmallVectorImpl<NamedAttribute> &result) override {
if (parser.getToken().isNot(Token::l_brace))
return false;
- return parser.parseAttributeDict(result) == ParseFailure;
+ return failed(parser.parseAttributeDict(result));
}
/// Parse a function name like '@foo' and return the name in a form that can
}
bool parseLParen() override {
- return parser.parseToken(Token::l_paren, "expected '('");
+ return failed(parser.parseToken(Token::l_paren, "expected '('"));
}
bool parseRParen() override {
- return parser.parseToken(Token::r_paren, "expected ')'");
+ return failed(parser.parseToken(Token::r_paren, "expected ')'"));
}
bool parseOperandList(SmallVectorImpl<OperandType> &result,
parsedRegionEntryArgumentPlaceholders.emplace_back(value);
}
- return parser.parseOperationRegion(region, regionArguments);
+ return failed(parser.parseOperationRegion(region, regionArguments));
}
/// Parse a region argument. Region arguments define new values, so this also
if (auto defLoc = parser.getDefinitionLoc(argument.name, argument.number)) {
parser.emitError(argument.location,
"redefinition of SSA value '" + argument.name + "'");
- return parser.emitError(*defLoc, "previously defined here");
+ return parser.emitError(*defLoc, "previously defined here"), true;
}
return false;
}
auto parseElt = [&]() -> ParseResult {
bool isEq;
auto elt = parseAffineConstraint(&isEq);
- ParseResult res = elt ? ParseSuccess : ParseFailure;
+ ParseResult res = elt ? success() : failure();
if (elt) {
constraints.push_back(elt);
isEqs.push_back(isEq);
// Parse the '='
if (parseToken(Token::equal, "expected '=' in attribute alias definition"))
- return ParseFailure;
+ return failure();
// Parse the attribute value.
Attribute attr = parseAttribute();
if (!attr)
- return ParseFailure;
+ return failure();
getState().attributeAliasDefinitions[attrId] = attr;
- return ParseSuccess;
+ return success();
}
/// Parse a type alias declaration.
// Parse the '=' and 'type'.
if (parseToken(Token::equal, "expected '=' in type alias definition") ||
parseToken(Token::kw_type, "expected 'type' in type alias definition"))
- return ParseFailure;
+ return failure();
// Parse the type.
Type aliasedType = parseType();
if (!aliasedType)
- return ParseFailure;
+ return failure();
// Register this alias with the parser state.
getState().typeAliasDefinitions.try_emplace(aliasName, aliasedType);
- return ParseSuccess;
+ return success();
}
/// Parse a (possibly empty) list of Function arguments with types.
argNames.push_back(name);
if (parseToken(Token::colon, "expected ':'"))
- return ParseFailure;
+ return failure();
} else {
// Reject this if the preceding argument had a name.
if (!argNames.empty())
// Parse argument type
auto elt = parseType();
if (!elt)
- return ParseFailure;
+ return failure();
argTypes.push_back(elt);
// Parse the attribute dict.
SmallVector<NamedAttribute, 2> attrs;
if (getToken().is(Token::l_brace)) {
if (parseAttributeDict(attrs))
- return ParseFailure;
+ return failure();
}
argAttrs.push_back(attrs);
- return ParseSuccess;
+ return success();
};
return parseCommaSeparatedListUntil(Token::r_paren, parseElt);
SmallVector<Type, 4> argTypes;
if (parseArgumentList(argTypes, argNames, argAttrs))
- return ParseFailure;
+ return failure();
// Parse the return type if present.
SmallVector<Type, 4> results;
if (consumeIf(Token::arrow)) {
if (parseFunctionResultTypes(results))
- return ParseFailure;
+ return failure();
}
type = builder.getFunctionType(argTypes, results);
- return ParseSuccess;
+ return success();
}
/// Function declarations.
auto loc = getToken().getLoc();
if (parseFunctionSignature(name, type, argNames, argAttrs))
- return ParseFailure;
+ return failure();
// If function attributes are present, parse them.
SmallVector<NamedAttribute, 8> attrs;
if (consumeIf(Token::kw_attributes)) {
if (parseAttributeDict(attrs))
- return ParseFailure;
+ return failure();
}
// Okay, the function signature was parsed correctly, create the function now.
// Parse an optional trailing location.
if (parseOptionalTrailingLocation(function))
- return ParseFailure;
+ return failure();
// Add the attributes to the function arguments.
for (unsigned i = 0, e = function->getNumArguments(); i != e; ++i)
// External functions have no body.
if (getToken().isNot(Token::l_brace))
- return ParseSuccess;
+ return success();
// Create the parser.
auto parser = FunctionParser(getState(), function);
if (hadNamedArguments) {
for (unsigned i = 0, e = function->getNumArguments(); i != e; ++i) {
if (parser.addDefinition({argNames[i], 0, loc}, function->getArgument(i)))
- return ParseFailure;
+ return failure();
}
}
if (!resolvedFunction) {
forwardRef.second->emitError("reference to undefined function '" +
name.str() + "'");
- return ParseFailure;
+ return failure();
}
remappingTable[builder.getFunctionAttr(forwardRef.second)] =
// If there was nothing to remap, then we're done.
if (remappingTable.empty())
- return ParseSuccess;
+ return success();
// Otherwise, walk the entire module replacing uses of one attribute set
// with the correct ones.
for (auto forwardRef : getState().functionForwardRefs)
delete forwardRef.second;
getState().functionForwardRefs.clear();
- return ParseSuccess;
+ return success();
}
/// This is the top-level module parser.
switch (getToken().getKind()) {
default:
emitError("expected a top level entity");
- return ParseFailure;
+ return failure();
// If we got to the end of the file, then we're done.
case Token::eof:
// stop. Someday we could introduce error recovery if there was demand
// for it.
case Token::error:
- return ParseFailure;
+ return failure();
case Token::hash_identifier:
if (parseAttributeAliasDef())
- return ParseFailure;
+ return failure();
break;
case Token::exclamation_identifier:
if (parseTypeAliasDef())
- return ParseFailure;
+ return failure();
break;
case Token::kw_func:
if (parseFunc())
- return ParseFailure;
+ return failure();
break;
}
}