Add constexpr if statements

Co-Authored-By: Thomas Johansen <thomasjo@gmail.com>
edge_only_predecessors
Max Brunsfeld 2018-05-14 13:43:15 +07:00
parent 743d6de28d
commit 3a76511be9
4 changed files with 71148 additions and 68057 deletions

@ -46,3 +46,28 @@ T main() {
(identifier)
(compound_statement
(expression_statement (shift_expression (identifier) (identifier))))))))
===========================================
Constexpr if statements
===========================================
T f() {
if constexpr (std::is_pointer_v<T>)
return *t;
else
return t;
}
---
(translation_unit
(function_definition
(type_identifier)
(function_declarator (identifier) (parameter_list))
(compound_statement
(if_statement
(template_function
(scoped_identifier (namespace_identifier) (identifier))
(template_argument_list (type_descriptor (type_identifier))))
(return_statement (pointer_expression (identifier)))
(return_statement (identifier))))))

@ -388,6 +388,17 @@ module.exports = grammar(C, {
$.for_range_loop
),
if_statement: $ => prec.right(seq(
'if',
optional('constexpr'),
'(', $._expression, ')',
$._statement,
optional(seq(
'else',
$._statement
))
)),
for_range_loop: $ => seq(
'for',
'(',

12
src/grammar.json vendored

@ -2880,6 +2880,18 @@
"type": "STRING",
"value": "if"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "constexpr"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "("

139157
src/parser.c vendored

File diff suppressed because it is too large Load Diff