Skip to content

Commit

Permalink
Add . and -> operator overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsheep committed Aug 3, 2020
1 parent 71c3b0a commit f230e6b
Show file tree
Hide file tree
Showing 6 changed files with 994 additions and 948 deletions.
6 changes: 3 additions & 3 deletions src/grammar/SandLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ fragment CharChar: ~ ['\r\n] | Escape;
DecimalLiteral: NONZERODIGIT (DIGITSEPARATOR? DIGIT)*;
FloatingLiteral:
(DecimalLiteral | ZeroLiteral)? '.' (
DIGIT (DIGITSEPARATOR? DIGIT)*
)?;
(DecimalLiteral | ZeroLiteral)? '.' DIGIT (
DIGITSEPARATOR? DIGIT
)*;
ZeroLiteral: '0';
Expand Down
2 changes: 2 additions & 0 deletions src/grammar/SandParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ overloadableOperator:
| '>'
| greaterThanOrEqualToOperator
| '[' ']'
| '->'
| '.'
| shiftOperator
| shiftEqualOperator;

Expand Down
17 changes: 17 additions & 0 deletions src/grammar/Visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,23 @@ class Visitor
auto scope = this->scopes.top();
auto expr = this->valueFromExpression(context->expression());

if (context->Arrow())
{
std::vector<Value *> args = {expr};
if (auto overload = this->getOperatorOverload("->", args))
{
expr = overload->call(scope->builder(), scope->module(), args);
}
}
else
{
std::vector<Value *> args = {expr};
if (auto overload = this->getOperatorOverload(".", args))
{
expr = overload->call(scope->builder(), scope->module(), args);
}
}

if (context->Arrow())
{
if (!Type::behind_reference(expr->type)->is_pointer())
Expand Down
Loading

0 comments on commit f230e6b

Please sign in to comment.