ParseResult parseModule();
private:
+ /// Parse an attribute alias declaration.
ParseResult parseAttributeAliasDef();
+ /// Parse an attribute alias declaration.
ParseResult parseTypeAliasDef();
// Functions.
///
ParseResult ModuleParser::parseAttributeAliasDef() {
assert(getToken().is(Token::hash_identifier));
-
- StringRef attrId = getTokenSpelling().drop_front();
+ StringRef aliasName = getTokenSpelling().drop_front();
// Check for redefinitions.
- if (getState().attributeAliasDefinitions.count(attrId) > 0)
- return emitError("redefinition of attribute alias id '" + attrId + "'");
+ if (getState().attributeAliasDefinitions.count(aliasName) > 0)
+ return emitError("redefinition of attribute alias id '" + aliasName + "'");
+
+ // Make sure this isn't invading the dialect attribute namespace.
+ if (aliasName.contains('.'))
+ return emitError("attribute names with a '.' are reserved for "
+ "dialect-defined names");
consumeToken(Token::hash_identifier);
- // Parse the '='
+ // Parse the '='.
if (parseToken(Token::equal, "expected '=' in attribute alias definition"))
return failure();
if (!attr)
return failure();
- getState().attributeAliasDefinitions[attrId] = attr;
+ getState().attributeAliasDefinitions[aliasName] = attr;
return success();
}
///
ParseResult ModuleParser::parseTypeAliasDef() {
assert(getToken().is(Token::exclamation_identifier));
-
StringRef aliasName = getTokenSpelling().drop_front();
// Check for redefinitions.
// Register this alias with the parser state.
getState().typeAliasDefinitions.try_emplace(aliasName, aliasedType);
-
return success();
}
// Parse the attribute dict.
SmallVector<NamedAttribute, 2> attrs;
- if (getToken().is(Token::l_brace)) {
+ if (getToken().is(Token::l_brace))
if (parseAttributeDict(attrs))
return failure();
- }
+
argAttrs.push_back(attrs);
return success();
};
emitError("expected a top level entity");
return failure();
- // If we got to the end of the file, then we're done.
+ // If we got to the end of the file, then we're done.
case Token::eof:
return success();
case Token::error:
return failure();
+ // Parse an attribute alias.
case Token::hash_identifier:
if (parseAttributeAliasDef())
return failure();
break;
+ // Parse a type alias.
case Token::exclamation_identifier:
if (parseTypeAliasDef())
return failure();