diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-17 06:50:29 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-17 06:50:29 +0000 |
| commit | c89477d615fb0ce4d89786ef848ffe6aca1da088 (patch) | |
| tree | b2c5692cfa4946fcd1df034630fc1a678d922b9c /lib/Parser/ParserFunction.cc | |
| parent | 43451328a5ae74ffa34356259ee02e3786f070c3 (diff) | |
feat(classes): support explicit NEW constructor method calls
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/Parser/ParserFunction.cc')
| -rw-r--r-- | lib/Parser/ParserFunction.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Parser/ParserFunction.cc b/lib/Parser/ParserFunction.cc index ad187c8..1b8b470 100644 --- a/lib/Parser/ParserFunction.cc +++ b/lib/Parser/ParserFunction.cc @@ -132,6 +132,10 @@ std::optional<std::vector<ParamDecl>> Parser::ParsePrototypeArgs(bool AllowByRef std::unique_ptr<FunctionDefAST> Parser::ParseFunction(const std::string &OwnerClass, bool IsPublic) { int Line = Lex.getLine(); getNextToken(); + if (CurTok == tok_new || (CurTok == tok_identifier && sameIdentifier(Lex.IdentifierStr, "NEW"))) { + fprintf(stderr, "error: constructor NEW must be a PROCEDURE at line %d\n", Line); + return nullptr; + } if (CurTok != tok_identifier) { fprintf(stderr, "error: Expected function name\n"); return nullptr; @@ -176,12 +180,16 @@ std::unique_ptr<FunctionDefAST> Parser::ParseFunction(const std::string &OwnerCl std::unique_ptr<FunctionDefAST> Parser::ParseProcedure(const std::string &OwnerClass, bool IsPublic) { int Line = Lex.getLine(); getNextToken(); - if (CurTok != tok_identifier) { + if (CurTok != tok_identifier && CurTok != tok_new) { fprintf(stderr, "error: Expected procedure name\n"); return nullptr; } - std::string Name = Lex.IdentifierStr; + std::string Name = CurTok == tok_new ? "NEW" : Lex.IdentifierStr; + if (OwnerClass.empty() && sameIdentifier(Name, "NEW")) { + fprintf(stderr, "error: constructor NEW is only allowed in a CLASS at line %d\n", Line); + return nullptr; + } getNextToken(); auto Args = ParsePrototypeArgs(/*AllowByRef=*/true); |
