mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3627 from ethereum/additional-keywords
[BREAKING] Add new reserved keywords.
This commit is contained in:
commit
d1e7e9ef5e
@ -7,6 +7,9 @@ Breaking Changes:
|
|||||||
* Disallow conversions between bytesX and uintY of different size.
|
* Disallow conversions between bytesX and uintY of different size.
|
||||||
* Commandline interface: Require ``-`` if standard input is used as source.
|
* Commandline interface: Require ``-`` if standard input is used as source.
|
||||||
* General: New keywords: ``calldata``
|
* General: New keywords: ``calldata``
|
||||||
|
* General: Add new reserved keywords: ``alias``, ``apply``, ``auto``, ``copyof``, ``define``, ``immutable``,
|
||||||
|
``implements``, ``macro``, ``mutable``, ``override``, ``partial``, ``promise``, ``reference``, ``sealed``,
|
||||||
|
``sizeof``, ``supports``, ``typedef`` and ``unchecked``.
|
||||||
* General: ``continue`` in a ``do...while`` loop jumps to the condition (it used to jump to the loop body). Warning: this may silently change the semantics of existing code.
|
* General: ``continue`` in a ``do...while`` loop jumps to the condition (it used to jump to the loop body). Warning: this may silently change the semantics of existing code.
|
||||||
* General: Signed right shift uses proper arithmetic shift, i.e. rounding towards negative infinity. Warning: this may silently change the semantics of existing code!
|
* General: Signed right shift uses proper arithmetic shift, i.e. rounding towards negative infinity. Warning: this may silently change the semantics of existing code!
|
||||||
* Introduce ``emit`` as a keyword instead of parsing it as identifier.
|
* Introduce ``emit`` as a keyword instead of parsing it as identifier.
|
||||||
|
@ -409,8 +409,11 @@ Reserved Keywords
|
|||||||
|
|
||||||
These keywords are reserved in Solidity. They might become part of the syntax in the future:
|
These keywords are reserved in Solidity. They might become part of the syntax in the future:
|
||||||
|
|
||||||
``abstract``, ``after``, ``case``, ``catch``, ``default``, ``final``, ``in``, ``inline``, ``let``, ``match``, ``null``,
|
``abstract``, ``after``, ``alias``, ``apply``, ``auto``, ``case``, ``catch``, ``copyof``, ``default``,
|
||||||
``of``, ``relocatable``, ``static``, ``switch``, ``try``, ``type``, ``typeof``.
|
``define``, ``final``, ``immutable``, ``implements``, ``in``, ``inline``, ``let``, ``macro``, ``match``,
|
||||||
|
``mutable``, ``null``, ``of``, ``override``, ``partial``, ``promise``, ``reference``, ``relocatable``,
|
||||||
|
``sealed``, ``sizeof``, ``static``, ``supports``, ``switch``, ``try``, ``type``, ``typedef``, ``typeof``,
|
||||||
|
``unchecked``.
|
||||||
|
|
||||||
Language Grammar
|
Language Grammar
|
||||||
================
|
================
|
||||||
|
@ -223,22 +223,41 @@ namespace solidity
|
|||||||
/* Keywords reserved for future use. */ \
|
/* Keywords reserved for future use. */ \
|
||||||
K(Abstract, "abstract", 0) \
|
K(Abstract, "abstract", 0) \
|
||||||
K(After, "after", 0) \
|
K(After, "after", 0) \
|
||||||
|
K(Alias, "alias", 0) \
|
||||||
|
K(Apply, "apply", 0) \
|
||||||
|
K(Auto, "auto", 0) \
|
||||||
K(Case, "case", 0) \
|
K(Case, "case", 0) \
|
||||||
K(Catch, "catch", 0) \
|
K(Catch, "catch", 0) \
|
||||||
|
K(CopyOf, "copyof", 0) \
|
||||||
K(Default, "default", 0) \
|
K(Default, "default", 0) \
|
||||||
|
K(Define, "define", 0) \
|
||||||
K(Final, "final", 0) \
|
K(Final, "final", 0) \
|
||||||
|
K(Immutable, "immutable", 0) \
|
||||||
|
K(Implements, "implements", 0) \
|
||||||
K(In, "in", 0) \
|
K(In, "in", 0) \
|
||||||
K(Inline, "inline", 0) \
|
K(Inline, "inline", 0) \
|
||||||
K(Let, "let", 0) \
|
K(Let, "let", 0) \
|
||||||
|
K(Macro, "macro", 0) \
|
||||||
K(Match, "match", 0) \
|
K(Match, "match", 0) \
|
||||||
|
K(Mutable, "mutable", 0) \
|
||||||
K(NullLiteral, "null", 0) \
|
K(NullLiteral, "null", 0) \
|
||||||
K(Of, "of", 0) \
|
K(Of, "of", 0) \
|
||||||
|
K(Override, "override", 0) \
|
||||||
|
K(Partial, "partial", 0) \
|
||||||
|
K(Promise, "promise", 0) \
|
||||||
|
K(Reference, "reference", 0) \
|
||||||
K(Relocatable, "relocatable", 0) \
|
K(Relocatable, "relocatable", 0) \
|
||||||
|
K(Sealed, "sealed", 0) \
|
||||||
|
K(Sizeof, "sizeof", 0) \
|
||||||
K(Static, "static", 0) \
|
K(Static, "static", 0) \
|
||||||
|
K(Supports, "supports", 0) \
|
||||||
K(Switch, "switch", 0) \
|
K(Switch, "switch", 0) \
|
||||||
K(Try, "try", 0) \
|
K(Try, "try", 0) \
|
||||||
K(Type, "type", 0) \
|
K(Type, "type", 0) \
|
||||||
|
K(Typedef, "typedef", 0) \
|
||||||
K(TypeOf, "typeof", 0) \
|
K(TypeOf, "typeof", 0) \
|
||||||
|
K(Unchecked, "unchecked", 0) \
|
||||||
|
\
|
||||||
/* Illegal token - not able to scan. */ \
|
/* Illegal token - not able to scan. */ \
|
||||||
T(Illegal, "ILLEGAL", 0) \
|
T(Illegal, "ILLEGAL", 0) \
|
||||||
\
|
\
|
||||||
@ -295,7 +314,7 @@ public:
|
|||||||
static bool isStateMutabilitySpecifier(Value op) { return op == Pure || op == Constant || op == View || op == Payable; }
|
static bool isStateMutabilitySpecifier(Value op) { return op == Pure || op == Constant || op == View || op == Payable; }
|
||||||
static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == SubEther; }
|
static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == SubEther; }
|
||||||
static bool isTimeSubdenomination(Value op) { return op == SubSecond || op == SubMinute || op == SubHour || op == SubDay || op == SubWeek || op == SubYear; }
|
static bool isTimeSubdenomination(Value op) { return op == SubSecond || op == SubMinute || op == SubHour || op == SubDay || op == SubWeek || op == SubYear; }
|
||||||
static bool isReservedKeyword(Value op) { return (Abstract <= op && op <= TypeOf); }
|
static bool isReservedKeyword(Value op) { return (Abstract <= op && op <= Unchecked); }
|
||||||
|
|
||||||
// @returns a string corresponding to the JS token string
|
// @returns a string corresponding to the JS token string
|
||||||
// (.e., "<" for the token LT) or NULL if the token doesn't
|
// (.e., "<" for the token LT) or NULL if the token doesn't
|
||||||
|
@ -491,28 +491,46 @@ BOOST_AUTO_TEST_CASE(keyword_is_reserved)
|
|||||||
auto keywords = {
|
auto keywords = {
|
||||||
"abstract",
|
"abstract",
|
||||||
"after",
|
"after",
|
||||||
|
"alias",
|
||||||
|
"apply",
|
||||||
|
"auto",
|
||||||
"case",
|
"case",
|
||||||
"catch",
|
"catch",
|
||||||
|
"copyof",
|
||||||
"default",
|
"default",
|
||||||
|
"define",
|
||||||
"final",
|
"final",
|
||||||
|
"immutable",
|
||||||
|
"implements",
|
||||||
"in",
|
"in",
|
||||||
"inline",
|
"inline",
|
||||||
"let",
|
"let",
|
||||||
|
"macro",
|
||||||
"match",
|
"match",
|
||||||
|
"mutable",
|
||||||
"null",
|
"null",
|
||||||
"of",
|
"of",
|
||||||
|
"override",
|
||||||
|
"partial",
|
||||||
|
"promise",
|
||||||
|
"reference",
|
||||||
"relocatable",
|
"relocatable",
|
||||||
|
"sealed",
|
||||||
|
"sizeof",
|
||||||
"static",
|
"static",
|
||||||
|
"supports",
|
||||||
"switch",
|
"switch",
|
||||||
"try",
|
"try",
|
||||||
"type",
|
"type",
|
||||||
"typeof"
|
"typedef",
|
||||||
|
"typeof",
|
||||||
|
"unchecked"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const auto& keyword: keywords)
|
for (const auto& keyword: keywords)
|
||||||
{
|
{
|
||||||
auto text = std::string("contract ") + keyword + " {}";
|
auto text = std::string("contract ") + keyword + " {}";
|
||||||
CHECK_PARSE_ERROR(text.c_str(), "Expected identifier but got reserved keyword");
|
CHECK_PARSE_ERROR(text.c_str(), string("Expected identifier but got reserved keyword '") + keyword + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user