From b17f101cfc75565f9991c856ec62f1e17b0ab104 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 06:09:01 +0000 Subject: 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 --- lib/Parser/ParserExpression.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'lib/Parser/ParserExpression.cc') 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 Parser::ParseNumberExpr() { } std::unique_ptr 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 &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 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: { -- cgit v1.3.1-4-g156e