mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implemented parsing for UserDefinedValueType
Also added parsing tests.
This commit is contained in:
parent
d3ae9cf71b
commit
9f7426b4a9
@ -113,6 +113,9 @@ ASTPointer<SourceUnit> Parser::parse(CharStream& _charStream)
|
||||
case Token::Enum:
|
||||
nodes.push_back(parseEnumDefinition());
|
||||
break;
|
||||
case Token::Type:
|
||||
nodes.push_back(parseUserDefinedValueTypeDefinition());
|
||||
break;
|
||||
case Token::Function:
|
||||
nodes.push_back(parseFunctionDefinition(true));
|
||||
break;
|
||||
@ -364,6 +367,8 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition()
|
||||
subNodes.push_back(parseStructDefinition());
|
||||
else if (currentTokenValue == Token::Enum)
|
||||
subNodes.push_back(parseEnumDefinition());
|
||||
else if (currentTokenValue == Token::Type)
|
||||
subNodes.push_back(parseUserDefinedValueTypeDefinition());
|
||||
else if (
|
||||
// Workaround because `error` is not a keyword.
|
||||
currentTokenValue == Token::Identifier &&
|
||||
@ -1010,6 +1015,22 @@ ASTPointer<UserDefinedTypeName> Parser::parseUserDefinedTypeName()
|
||||
return nodeFactory.createNode<UserDefinedTypeName>(identifierPath);
|
||||
}
|
||||
|
||||
ASTPointer<UserDefinedValueTypeDefinition> Parser::parseUserDefinedValueTypeDefinition()
|
||||
{
|
||||
ASTNodeFactory nodeFactory(*this);
|
||||
expectToken(Token::Type);
|
||||
auto&& [name, nameLocation] = expectIdentifierWithLocation();
|
||||
expectToken(Token::Is);
|
||||
ASTPointer<TypeName> typeName = parseTypeName();
|
||||
nodeFactory.markEndPosition();
|
||||
expectToken(Token::Semicolon);
|
||||
return nodeFactory.createNode<UserDefinedValueTypeDefinition>(
|
||||
name,
|
||||
move(nameLocation),
|
||||
typeName
|
||||
);
|
||||
}
|
||||
|
||||
ASTPointer<IdentifierPath> Parser::parseIdentifierPath()
|
||||
{
|
||||
RecursionGuard recursionGuard(*this);
|
||||
|
@ -95,6 +95,7 @@ private:
|
||||
ASTPointer<ASTNode> parseFunctionDefinition(bool _freeFunction = false);
|
||||
ASTPointer<StructDefinition> parseStructDefinition();
|
||||
ASTPointer<EnumDefinition> parseEnumDefinition();
|
||||
ASTPointer<UserDefinedValueTypeDefinition> parseUserDefinedValueTypeDefinition();
|
||||
ASTPointer<EnumValue> parseEnumValue();
|
||||
ASTPointer<VariableDeclaration> parseVariableDeclaration(
|
||||
VarDeclParserOptions const& _options = {},
|
||||
|
@ -0,0 +1,5 @@
|
||||
type MyInt is uint;
|
||||
|
||||
contract C {
|
||||
type MyAddress is address;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
type(MyInt) is uint256;
|
||||
// ----
|
||||
// ParserError 2314: (4-5): Expected identifier but got '('
|
@ -0,0 +1,6 @@
|
||||
function f() {
|
||||
type(uint).max;
|
||||
type MyInt is int;
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (44-49): Expected ';' but got identifier
|
Loading…
Reference in New Issue
Block a user