Lines Matching full:expression
1 //===--- ParseExpr.cpp - Expression Parsing -------------------------------===//
11 /// \brief Provides the Expression parsing implementation.
17 /// as the 'cast-expression' production. Everything else is either a binary
37 /// Note: we diverge from the C99 grammar when parsing the assignment-expression
39 /// parsed as a unary-expression, but consistency dictates that it be a
42 /// unary-expression and conditional-expression don't produce. Because we want
43 /// consistency, we parse the LHS as a conditional-expression, then check for
47 /// pm-expression: [C++ 5.5]
48 /// cast-expression
49 /// pm-expression '.*' cast-expression
50 /// pm-expression '->*' cast-expression
52 /// multiplicative-expression: [C99 6.5.5]
53 /// Note: in C++, apply pm-expression instead of cast-expression
54 /// cast-expression
55 /// multiplicative-expression '*' cast-expression
56 /// multiplicative-expression '/' cast-expression
57 /// multiplicative-expression '%' cast-expression
59 /// additive-expression: [C99 6.5.6]
60 /// multiplicative-expression
61 /// additive-expression '+' multiplicative-expression
62 /// additive-expression '-' multiplicative-expression
64 /// shift-expression: [C99 6.5.7]
65 /// additive-expression
66 /// shift-expression '<<' additive-expression
67 /// shift-expression '>>' additive-expression
69 /// relational-expression: [C99 6.5.8]
70 /// shift-expression
71 /// relational-expression '<' shift-expression
72 /// relational-expression '>' shift-expression
73 /// relational-expression '<=' shift-expression
74 /// relational-expression '>=' shift-expression
76 /// equality-expression: [C99 6.5.9]
77 /// relational-expression
78 /// equality-expression '==' relational-expression
79 /// equality-expression '!=' relational-expression
81 /// AND-expression: [C99 6.5.10]
82 /// equality-expression
83 /// AND-expression '&' equality-expression
85 /// exclusive-OR-expression: [C99 6.5.11]
86 /// AND-expression
87 /// exclusive-OR-expression '^' AND-expression
89 /// inclusive-OR-expression: [C99 6.5.12]
90 /// exclusive-OR-expression
91 /// inclusive-OR-expression '|' exclusive-OR-expression
93 /// logical-AND-expression: [C99 6.5.13]
94 /// inclusive-OR-expression
95 /// logical-AND-expression '&&' inclusive-OR-expression
97 /// logical-OR-expression: [C99 6.5.14]
98 /// logical-AND-expression
99 /// logical-OR-expression '||' logical-AND-expression
101 /// conditional-expression: [C99 6.5.15]
102 /// logical-OR-expression
103 /// logical-OR-expression '?' expression ':' conditional-expression
104 /// [GNU] logical-OR-expression '?' ':' conditional-expression
105 /// [C++] the third operand is an assignment-expression
107 /// assignment-expression: [C99 6.5.16]
108 /// conditional-expression
109 /// unary-expression assignment-operator assignment-expression
110 /// [C++] throw-expression [C++ 15]
115 /// expression: [C99 6.5.17]
116 /// assignment-expression ...[opt]
117 /// expression ',' assignment-expression ...[opt]
127 /// for example, \@encode-expression.
137 /// process of disambiguating between an expression and a declaration.
142 // Silence extension warnings in the sub-expression
172 /// \brief Parse an assignment expression where part of an Objective-C message
179 /// Since this handles full assignment-expression's, it handles postfix
196 // An expression is potentially evaluated unless it appears where an
197 // integral constant expression is required (see 5.19) [...].
214 // If this is a decl-specifier, we can't be at the start of an expression.
218 /// \brief Parse a binary expression that starts with \p LHS and has a
239 // possibly be the start of an expression. For instance:
257 // logical-OR-expression '?' expression ':' conditional-expression
258 // In particular, the RHS of the '?' is 'expression', not
259 // 'logical-OR-expression' as we might expect.
267 // logical-OR-expression '?' ':' conditional-expression [GNU]
305 // Code completion for the right-hand side of an assignment expression
315 // as a prefix, at least. However, in C++, an assignment-expression could
316 // be a throw-expression, which is not a valid cast-expression.
319 // an assignment-expression in C++, and in C++11, we can have a
406 /// \brief Parse a cast-expression, or, if \p isUnaryExpression is true,
407 /// parse a unary-expression.
409 /// \p isAddressOfOperand exists because an id-expression that is the
448 /// \brief Parse a cast-expression, or, if \pisUnaryExpression is true, parse
449 /// a unary-expression.
451 /// \p isAddressOfOperand exists because an id-expression that is the operand
453 /// is set to true if the token is not the start of a cast-expression, and no
457 /// cast-expression: [C99 6.5.4]
458 /// unary-expression
459 /// '(' type-name ')' cast-expression
461 /// unary-expression: [C99 6.5.3]
462 /// postfix-expression
463 /// '++' unary-expression
464 /// '--' unary-expression
465 /// unary-operator cast-expression
466 /// 'sizeof' unary-expression
469 /// [GNU] '__alignof' unary-expression
474 /// [C++11] 'noexcept' '(' expression ')' [C++11 5.3.7]
475 /// [C++] new-expression
476 /// [C++] delete-expression
482 /// primary-expression: [C99 6.5.1]
484 /// [C++] id-expression
490 /// '(' expression ')'
496 /// [GNU] '__builtin_va_arg' '(' assignment-expression ',' type-name ')'
507 /// [C++] simple-type-specifier '(' expression-list[opt] ')' [C++ 5.2.3]
509 /// [C++] typename-specifier '(' expression-list[opt] ')' [C++ 5.2.3]
511 /// [C++] 'const_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
512 /// [C++] 'dynamic_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
513 /// [C++] 'reinterpret_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
514 /// [C++] 'static_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1]
515 /// [C++] 'typeid' '(' expression ')' [C++ 5.2p1]
529 /// id-expression: [C++ 5.1]
540 /// new-expression: [C++ 5.3.4]
546 /// delete-expression: [C++ 5.3.5]
547 /// '::'[opt] 'delete' cast-expression
548 /// '::'[opt] 'delete' '[' ']' cast-expression
610 /// [Embarcadero] expression-trait:
623 // This handles all of cast-expression, unary-expression, postfix-expression,
624 // and primary-expression. We handle them together like this for efficiency
625 // and to simplify handling of an expression starting with a '(' token: which
626 // may be one of a parenthesized expression, cast-expression, compound literal
627 // expression, or statement expression.
629 // If the parsed tokens consist of a primary-expression, the cases below
631 // to handle the postfix expression suffixes. Cases that cannot be followed
636 // If this expression is limited to being a unary-expression, the parent can
637 // not start a cast expression.
657 // postfix-expression exist, parse them now.
660 // We have parsed the cast-expression and no postfix-expr pieces are
668 // primary-expression
690 assert(Res.get() == 0 && "Stray primary-expression annotation?");
702 case tok::identifier: { // primary-expression: identifier
870 case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2]
871 case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU]
872 case tok::kw_L__FUNCTION__: // primary-expression: L__FUNCTION__ [MS]
873 case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
877 case tok::string_literal: // primary-expression: string-literal
884 case tok::kw__Generic: // primary-expression: generic-selection [C11 6.5.1]
890 case tok::kw___builtin_astype: // primary-expression: [OCL] as_type()
895 case tok::plusplus: // unary-expression: '++' unary-expression [C99]
896 case tok::minusminus: { // unary-expression: '--' unary-expression [C99]
898 // unary-expression:
899 // ++ cast-expression
900 // -- cast-expression
907 case tok::amp: { // unary-expression: '&' cast-expression
916 case tok::star: // unary-expression: '*' cast-expression
917 case tok::plus: // unary-expression: '+' cast-expression
918 case tok::minus: // unary-expression: '-' cast-expression
919 case tok::tilde: // unary-expression: '~' cast-expression
920 case tok::exclaim: // unary-expression: '!' cast-expression
921 case tok::kw___real: // unary-expression: '__real' cast-expression [GNU]
922 case tok::kw___imag: { // unary-expression: '__imag' cast-expression [GNU]
930 case tok::kw___extension__:{//unary-expression:'__extension__' cast-expr [GNU]
939 case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')'
943 case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')'
944 case tok::kw___alignof: // unary-expression: '__alignof' unary-expression
945 // unary-expression: '__alignof' '(' type-name ')'
946 case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression
947 // unary-expression: 'sizeof' '(' type-name ')'
948 case tok::kw_vec_step: // unary-expression: OpenCL 'vec_step' expression
950 case tok::ampamp: { // unary-expression: '&&' identifier
1041 // postfix-expression: typename-specifier '(' expression-list[opt] ')'
1047 // postfix-expression: simple-type-specifier '(' expression-list[opt] ')'
1064 case tok::annot_cxxscope: { // [C++] id-expression: qualified-id
1079 // cast expression.
1089 // Parse as an id-expression.
1099 // expression.
1105 // Fall through to treat the template-id as an id-expression.
1108 case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id
1120 // ::new -> [C++] new-expression
1121 // ::delete -> [C++] delete-expression
1128 // This is not a type name or scope specifier, it is an invalid expression.
1133 case tok::kw_new: // [C++] new-expression
1136 case tok::kw_delete: // [C++] delete-expression
1139 case tok::kw_noexcept: { // [C++0x] 'noexcept' '(' expression ')'
1245 // we have a valid lambda expression, we have an invalid lambda
1246 // expression, or we have something that doesn't appear to be a lambda.
1270 /// \brief Once the leading part of a postfix-expression is parsed, this
1274 /// postfix-expression: [C99 6.5.2]
1275 /// primary-expression
1276 /// postfix-expression '[' expression ']'
1277 /// postfix-expression '[' braced-init-list ']'
1278 /// postfix-expression '(' argument-expression-list[opt] ')'
1279 /// postfix-expression '.' identifier
1280 /// postfix-expression '->' identifier
1281 /// postfix-expression '++'
1282 /// postfix-expression '--'
1286 /// argument-expression-list: [C99 6.5.2]
1287 /// argument-expression ...[opt]
1288 /// argument-expression-list ',' assignment-expression ...[opt]
1292 // Now that the primary-expression piece of the postfix-expression has been
1293 // parsed, see if there are any postfix-expression pieces here.
1306 // If we see identifier: after an expression, and we're not already in a
1318 default: // Not a postfix-expression suffix.
1320 case tok::l_square: { // postfix-expression: p-e '[' expression ']'
1321 // If we have a array postfix expression that starts on a new line and
1323 // semicolon after the base expression and that the array postfix-expr is
1326 // expression and recover by pretending there is no suffix.
1331 // Reject array indices starting with a lambda-expression. '[[' is
1359 case tok::l_paren: // p-e: p-e '(' argument-expression-list[opt] ')'
1360 case tok::lesslessless: { // p-e: p-e '<<<' argument-expression-list '>>>'
1361 // '(' argument-expression-list[opt] ')'
1451 // postfix-expression: p-e '->' template[opt] id-expression
1452 // postfix-expression: p-e '.' template[opt] id-expression
1486 // Code completion for a member access expression.
1501 // pseudo-destructor expression (based on the type of base
1502 // expression), or we didn't see a '~' in the right place. We
1511 // After a '.' in a member access expression, treat the keyword
1535 case tok::plusplus: // postfix-expression: postfix-expression '++'
1536 case tok::minusminus: // postfix-expression: postfix-expression '--'
1548 /// vec_step and we are at the start of an expression or a parenthesized
1550 /// expression (isCastExpr == false) or the type (isCastExpr == true).
1553 /// unary-expression: [C99 6.5.3]
1554 /// 'sizeof' unary-expression
1556 /// [GNU] '__alignof' unary-expression
1564 /// [GNU/C++] typeof unary-expression
1579 "Not a typeof/sizeof/alignof/vec_step expression!");
1583 // If the operand doesn't start with an '(', it must be an expression.
1594 // type-name, or it is a unary-expression that starts with a compound
1595 // literal, or starts with a primary-expression that is a parenthesized
1596 // expression.
1612 // GNU typeof in C requires the expression to be parenthesized. Not so for
1613 // sizeof/alignof or in C++. Therefore, the parenthesized expression is
1614 // the start of a unary-expression, but doesn't include any postfix
1627 /// \brief Parse a sizeof or alignof expression.
1630 /// unary-expression: [C99 6.5.3]
1631 /// 'sizeof' unary-expression
1634 /// [GNU] '__alignof' unary-expression
1643 "Not a sizeof/alignof/vec_step expression!");
1734 /// primary-expression: [C99 6.5.1]
1735 /// [GNU] '__builtin_va_arg' '(' assignment-expression ',' type-name ')'
1740 /// [OCL] '__builtin_astype' '(' assignment-expression ',' type-name ')'
1745 /// [GNU] offsetof-member-designator '[' expression ']'
1765 default: llvm_unreachable("Not a builtin primary expression!");
1831 // offsetof-member-designator: offsetof-member-design '[' expression ']'
1894 // The first argument is an expression to be converted, followed by a comma.
1934 /// not the parsed cast-expression.
1937 /// primary-expression: [C99 6.5.1]
1938 /// '(' expression ')'
1940 /// postfix-expression: [C99 6.5.2]
1943 /// cast-expression: [C99 6.5.4]
1944 /// '(' type-name ')' cast-expression
1945 /// [ARC] bridged-cast-expression
1947 /// [ARC] bridged-cast-expression:
1948 /// (__bridge type-name) cast-expression
1949 /// (__bridge_transfer type-name) cast-expression
1950 /// (__bridge_retained type-name) cast-expression
2013 // Parse an Objective-C ARC ownership cast expression.
2046 // Otherwise, this is a compound literal expression or cast expression.
2099 // Note that this doesn't parse the subsequent cast-expression, it just
2121 // Parse the cast-expression that follows it next.
2122 // TODO: For cast expression with CastTy.
2138 // Parse the expression-list.
2155 // Don't build a paren expression unless we actually match a ')'.
2175 /// postfix-expression: [C99 6.5.2]
2197 /// primary-expression: [C99 6.5.1]
2222 /// _Generic ( assignment-expression , generic-assoc-list )
2227 /// type-name : assignment-expression
2228 /// default : assignment-expression
2243 // C11 6.5.1.1p3 "The controlling expression of a generic selection is
2314 /// ParseExpressionList - Used for C/C++ (argument-)expression-list.
2317 /// argument-expression-list:
2318 /// assignment-expression
2319 /// argument-expression-list , assignment-expression
2321 /// [C++] expression-list:
2322 /// [C++] assignment-expression
2323 /// [C++] expression-list , assignment-expression
2325 /// [C++0x] expression-list:
2333 /// [C++0x] assignment-expression
2420 // argument decls, decls within the compound expression, etc. This also
2437 // the expression case, because the expression case requires a parameter list.