aboutsummaryrefslogtreecommitdiff
path: root/lib/Parser/ParserExpression.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 06:09:01 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 06:09:01 +0000
commitb17f101cfc75565f9991c856ec62f1e17b0ab104 (patch)
tree6c925f06c45dbaa557a0451cfca33f17be71ec67 /lib/Parser/ParserExpression.cc
parent16231050058131860f710073c17d3bca7c6637eb (diff)
feat(operators): add member and unary overloads with explicit calls
Select member and global candidates together, enforce private access, and reuse argument marshalling. Materialize temporary receivers for chaining and register them for the existing object cleanup mechanism. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/Parser/ParserExpression.cc')
-rw-r--r--lib/Parser/ParserExpression.cc25
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/Parser/ParserExpression.cc b/lib/Parser/ParserExpression.cc
index a4f4fcc..6cde5bf 100644
--- a/lib/Parser/ParserExpression.cc
+++ b/lib/Parser/ParserExpression.cc
@@ -41,9 +41,16 @@ std::unique_ptr<ExprAST> Parser::ParseNumberExpr() {
}
std::unique_ptr<ExprAST> Parser::ParseIdentifierExpr() {
- std::string IdName = Lex.IdentifierStr;
int Line = Lex.getLine();
- getNextToken();
+ std::string IdName;
+ if (CurTok == tok_operator) {
+ int Op;
+ IdName = ParseOperatorName(Op);
+ if (IdName.empty()) return nullptr;
+ } else {
+ IdName = Lex.IdentifierStr;
+ getNextToken();
+ }
if (CurTok == '(' && !atCaseBoundary()) {
getNextToken();
@@ -110,15 +117,21 @@ bool Parser::ParseDesignatorSuffix(std::vector<DesignatorAccess> &Out) {
Out.push_back(std::move(A));
} else if (CurTok == '.') {
getNextToken();
- if (CurTok != tok_identifier && CurTok != tok_new && CurTok != tok_delete) {
+ if (CurTok != tok_identifier && CurTok != tok_new && CurTok != tok_delete && CurTok != tok_operator) {
cps::sourceDiagnostic(Lex.getLine(), "error: Expected field name after '.' at line %d\n", Lex.getLine());
return false;
}
DesignatorAccess A;
A.Kind = AccessKind::Field;
- A.FieldName = CurTok == tok_new ? "NEW" : CurTok == tok_delete ? "DELETE" : Lex.IdentifierStr;
+ if (CurTok == tok_operator) {
+ int Op;
+ A.FieldName = ParseOperatorName(Op);
+ if (A.FieldName.empty()) return false;
+ } else {
+ A.FieldName = CurTok == tok_new ? "NEW" : CurTok == tok_delete ? "DELETE" : Lex.IdentifierStr;
+ getNextToken();
+ }
Out.push_back(std::move(A));
- getNextToken();
} else if (CurTok == '^') {
getNextToken();
DesignatorAccess A;
@@ -172,7 +185,7 @@ std::unique_ptr<ExprAST> Parser::ParsePrimaryImpl() {
case tok_new:
cps::sourceDiagnostic(Lex.getLine(), "error: NEW is only allowed on the right of an assignment at line %d\n", Lex.getLine());
return nullptr;
- case tok_identifier: return ParseIdentifierExpr();
+ case tok_identifier: case tok_operator: return ParseIdentifierExpr();
case tok_number_int: return ParseNumberExpr();
case tok_number_real: return ParseNumberExpr();
case tok_string_literal: {