Skip to content

Commit f230e6b

Browse files
committed
Add . and -> operator overloads
1 parent 71c3b0a commit f230e6b

File tree

6 files changed

+994
-948
lines changed

6 files changed

+994
-948
lines changed

src/grammar/SandLexer.g4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ fragment CharChar: ~ ['\r\n] | Escape;
129129
DecimalLiteral: NONZERODIGIT (DIGITSEPARATOR? DIGIT)*;
130130
131131
FloatingLiteral:
132-
(DecimalLiteral | ZeroLiteral)? '.' (
133-
DIGIT (DIGITSEPARATOR? DIGIT)*
134-
)?;
132+
(DecimalLiteral | ZeroLiteral)? '.' DIGIT (
133+
DIGITSEPARATOR? DIGIT
134+
)*;
135135
136136
ZeroLiteral: '0';
137137

src/grammar/SandParser.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ overloadableOperator:
172172
| '>'
173173
| greaterThanOrEqualToOperator
174174
| '[' ']'
175+
| '->'
176+
| '.'
175177
| shiftOperator
176178
| shiftEqualOperator;
177179

src/grammar/Visitor.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,23 @@ class Visitor
28842884
auto scope = this->scopes.top();
28852885
auto expr = this->valueFromExpression(context->expression());
28862886

2887+
if (context->Arrow())
2888+
{
2889+
std::vector<Value *> args = {expr};
2890+
if (auto overload = this->getOperatorOverload("->", args))
2891+
{
2892+
expr = overload->call(scope->builder(), scope->module(), args);
2893+
}
2894+
}
2895+
else
2896+
{
2897+
std::vector<Value *> args = {expr};
2898+
if (auto overload = this->getOperatorOverload(".", args))
2899+
{
2900+
expr = overload->call(scope->builder(), scope->module(), args);
2901+
}
2902+
}
2903+
28872904
if (context->Arrow())
28882905
{
28892906
if (!Type::behind_reference(expr->type)->is_pointer())

0 commit comments

Comments
 (0)