From 56e97d0ddd3fff2bee160bae04e8f659671f398d Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 03:55:22 +0000 Subject: refactor(parser): share the designator degrade rule for INPUT and expressions INPUT targets and identifier expressions now build their legacy VariableExprAST/ArrayAccessExprAST/DesignatorExprAST node through makeDesignator(). INPUT still sets the target line explicitly. Co-Authored-By: Claude Opus 5.5 --- lib/Parser/Parser.cc | 8 +------- lib/Parser/ParserExpression.cc | 14 ++++++++++---- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/Parser/Parser.cc b/lib/Parser/Parser.cc index 37fe8ec..d17856b 100644 --- a/lib/Parser/Parser.cc +++ b/lib/Parser/Parser.cc @@ -271,13 +271,7 @@ std::unique_ptr Parser::ParseInputStmt() { getNextToken(); std::vector Accesses; if (!ParseDesignatorSuffix(Accesses)) return nullptr; - std::unique_ptr Target; - if (Accesses.empty()) - Target = std::make_unique(Name); - else if (Accesses.size() == 1 && Accesses[0].Kind == AccessKind::Index) - Target = std::make_unique(Name, std::move(Accesses[0].Indices), Line); - else - Target = std::make_unique(Name, std::move(Accesses), Line); + auto Target = makeDesignator(Name, std::move(Accesses), Line); Target->setLine(Line); return std::make_unique(std::move(Target)); } diff --git a/lib/Parser/ParserExpression.cc b/lib/Parser/ParserExpression.cc index 6ed3f1c..398ba84 100644 --- a/lib/Parser/ParserExpression.cc +++ b/lib/Parser/ParserExpression.cc @@ -112,12 +112,18 @@ std::unique_ptr Parser::ParseIdentifierExpr() { if (CurTok == '(' && !atCaseBoundary()) return ParseMemberCall(IdName, std::move(Accesses), Line); - // Degrade rule: shapes that existed before designators keep their nodes. + return makeDesignator(IdName, std::move(Accesses), Line); +} + +// Degrade rule: shapes that existed before designators keep their nodes. +// A bare VariableExprAST carries no line; callers set it when they need one. +std::unique_ptr Parser::makeDesignator( + const std::string &Name, std::vector Accesses, int Line) { if (Accesses.empty()) - return std::make_unique(IdName); + return std::make_unique(Name); if (Accesses.size() == 1 && Accesses[0].Kind == AccessKind::Index) - return std::make_unique(IdName, std::move(Accesses[0].Indices), Line); - return std::make_unique(IdName, std::move(Accesses), Line); + return std::make_unique(Name, std::move(Accesses[0].Indices), Line); + return std::make_unique(Name, std::move(Accesses), Line); } // The final field suffix names the method; preceding suffixes form its receiver. -- cgit v1.3.1-4-g156e