mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:31:06 +01:00
Pointers (#1060)
* Naive pointer implementation * Bug fixes and better pointer tests * Remove debug print statement * Implement changes suggested by @geoffromer Also add a failing test case that tests applying the address-of operator to an rvalue.
This commit is contained in:
@@ -38,6 +38,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
%s AFTER_OPERAND
|
||||
|
||||
/* table-begin */
|
||||
AMPERSAND "&"
|
||||
AND "and"
|
||||
API "api"
|
||||
ARROW "->"
|
||||
@@ -134,6 +135,7 @@ string_literal \"([^\\\"\n\v\f\r]|\\.)*\"
|
||||
%}
|
||||
|
||||
/* table-begin */
|
||||
{AMPERSAND} { return SIMPLE_TOKEN(AMPERSAND); }
|
||||
{AND} { return SIMPLE_TOKEN(AND); }
|
||||
{API} { return SIMPLE_TOKEN(API); }
|
||||
{ARROW} { return SIMPLE_TOKEN(ARROW); }
|
||||
|
||||
@@ -141,6 +141,7 @@
|
||||
%token
|
||||
// Most tokens have their spelling defined in lexer.lpp.
|
||||
// table-begin
|
||||
AMPERSAND
|
||||
AND
|
||||
API
|
||||
ARROW
|
||||
@@ -214,7 +215,7 @@
|
||||
%nonassoc EQUAL_EQUAL
|
||||
%left PLUS MINUS
|
||||
%left BINARY_STAR
|
||||
%precedence NOT UNARY_MINUS PREFIX_STAR
|
||||
%precedence NOT UNARY_MINUS PREFIX_STAR AMPERSAND
|
||||
// We need to give the `UNARY_STAR` token a precedence, rather than overriding
|
||||
// the precedence of the `expression UNARY_STAR` rule below, because bison
|
||||
// compares the precedence of the final token (for a shift) to the precedence
|
||||
@@ -367,6 +368,12 @@ expression:
|
||||
context.source_loc(), Operator::Deref,
|
||||
std::vector<Nonnull<Expression*>>({$2}));
|
||||
}
|
||||
| AMPERSAND expression
|
||||
{
|
||||
$$ = arena->New<PrimitiveOperatorExpression>(
|
||||
context.source_loc(), Operator::AddressOf,
|
||||
std::vector<Nonnull<Expression*>>({$2}));
|
||||
}
|
||||
| expression tuple
|
||||
{ $$ = arena->New<CallExpression>(context.source_loc(), $1, $2); }
|
||||
| expression POSTFIX_STAR
|
||||
|
||||
Reference in New Issue
Block a user