* 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:
Darshal Shetty
2022-02-05 10:27:54 -05:00
committed by GitHub
parent f6cbd2231e
commit 4479c55305
11 changed files with 131 additions and 5 deletions
+2
View File
@@ -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); }
+8 -1
View File
@@ -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