From 74d7d49bcfe64ddd35064f963d9698faeadf49ff Mon Sep 17 00:00:00 2001 From: josh11b <15258583+josh11b@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:19:02 -0700 Subject: [PATCH] Include function call and subscripting/indexing in the operator list and precedence chart (#4052) Co-authored-by: Josh L Co-authored-by: Richard Smith --- docs/design/expressions/README.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/design/expressions/README.md b/docs/design/expressions/README.md index e3ea89ba4439..39ba34f37418 100644 --- a/docs/design/expressions/README.md +++ b/docs/design/expressions/README.md @@ -63,12 +63,20 @@ graph BT top((" ")) - memberAccess>"x.y
+subgraph memberCallIndex[" "] + direction LR + memberAccess{"x.y
x.(...)
x->y
- x->(...)"] + x->(...)"} click memberAccess "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/member_access.md" + callAndIndexing{"x(...)
+ x[y]"} + click callAndIndexing "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/indexing.md" +end +style memberCallIndex fill:none + constType["const T"] click pointer-type "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/type_operators.md" @@ -148,16 +156,20 @@ graph BT top --> parens & braces & unqualifiedName - constType --> top + memberCallIndex --> top + + callAndIndexing --> memberAccess + memberAccess --> callAndIndexing + + constType --> memberCallIndex pointerType --> constType as --> pointerType - memberAccess --> top - pointer --> memberAccess + pointer --> memberCallIndex negation & complement & incDec --> pointer unary --> negation & complement %% Use a longer arrow here to put `not` next to `and` and `or`. - not -------> memberAccess + not -------> memberCallIndex as & multiplication & modulo & bitwise_and & bitwise_or & bitwise_xor & shift --> unary addition --> multiplication comparison --> as & addition & modulo & bitwise_and & bitwise_or & bitwise_xor & shift @@ -302,6 +314,8 @@ Most expressions are modeled as operators: | Category | Operator | Syntax | Function | | ---------- | ----------------------------------- | --------- | --------------------------------------------------------------------- | +| Call | `()` (unary) | `x(...)` | Function call: the value returned by calling the function `x`. | +| Call | [`[]`](indexing.md) (unary) | `x[y]` | Subscripting or indexing: returns the element `y` of `x`. | | Pointer | [`*`](pointer_operators.md) (unary) | `*x` | Pointer dereference: the object pointed to by `x`. | | Pointer | [`&`](pointer_operators.md) (unary) | `&x` | Address-of: a pointer to the object `x`. | | Arithmetic | [`-`](arithmetic.md) (unary) | `-x` | The negation of `x`. |