Author: Haojian Wu Date: 2022-03-17T09:47:24+01:00 New Revision: 5a624956ced826745447dd95381624fb4bb10a7f
URL: https://github.com/llvm/llvm-project/commit/5a624956ced826745447dd95381624fb4bb10a7f DIFF: https://github.com/llvm/llvm-project/commit/5a624956ced826745447dd95381624fb4bb10a7f.diff LOG: [pseudo] Fix some naming-style violations. Added: Modified: clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h clang-tools-extra/pseudo/lib/Grammar.cpp clang-tools-extra/pseudo/lib/GrammarBNF.cpp clang-tools-extra/pseudo/lib/LRGraph.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h b/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h index ab71b6a56af1e..7e94c4b89d854 100644 --- a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h +++ b/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h @@ -157,11 +157,11 @@ struct GrammarTable { struct Nonterminal { std::string Name; - // Corresponding rules that construct the non-terminal, it is a [start, end) + // Corresponding rules that construct the non-terminal, it is a [Start, End) // index range of the Rules table. struct { - RuleID start; - RuleID end; + RuleID Start; + RuleID End; } RuleRange; }; diff --git a/clang-tools-extra/pseudo/lib/Grammar.cpp b/clang-tools-extra/pseudo/lib/Grammar.cpp index 542d30c7c5051..c362a14a51e13 100644 --- a/clang-tools-extra/pseudo/lib/Grammar.cpp +++ b/clang-tools-extra/pseudo/lib/Grammar.cpp @@ -36,8 +36,8 @@ Grammar::Grammar(std::unique_ptr<GrammarTable> Table) : T(std::move(Table)) { llvm::ArrayRef<Rule> Grammar::rulesFor(SymbolID SID) const { assert(isNonterminal(SID)); const auto &R = T->Nonterminals[SID].RuleRange; - assert(R.end <= T->Rules.size()); - return llvm::makeArrayRef(&T->Rules[R.start], R.end - R.start); + assert(R.End <= T->Rules.size()); + return llvm::makeArrayRef(&T->Rules[R.Start], R.End - R.Start); } const Rule &Grammar::lookupRule(RuleID RID) const { @@ -65,7 +65,7 @@ std::string Grammar::dumpRules(SymbolID SID) const { assert(isNonterminal(SID)); std::string Result; const auto &Range = T->Nonterminals[SID].RuleRange; - for (RuleID RID = Range.start; RID < Range.end; ++RID) + for (RuleID RID = Range.Start; RID < Range.End; ++RID) Result.append(dumpRule(RID)).push_back('\n'); return Result; } @@ -140,17 +140,17 @@ std::vector<llvm::DenseSet<SymbolID>> followSets(const Grammar &G) { for (const auto &R : G.table().Rules) { // Rule 2: for a rule X := ... Y Z, we add all symbols from FIRST(Z) to // FOLLOW(Y). - for (size_t i = 0; i + 1 < R.seq().size(); ++i) { - if (isToken(R.seq()[i])) + for (size_t I = 0; I + 1 < R.seq().size(); ++I) { + if (isToken(R.seq()[I])) continue; // We only need to consider the next symbol because symbols are // non-nullable. - SymbolID Next = R.seq()[i + 1]; + SymbolID Next = R.seq()[I + 1]; if (isToken(Next)) // First set for a terminal is itself. - Changed |= ExpandFollowSet(R.seq()[i], {Next}); + Changed |= ExpandFollowSet(R.seq()[I], {Next}); else - Changed |= ExpandFollowSet(R.seq()[i], FirstSets[Next]); + Changed |= ExpandFollowSet(R.seq()[I], FirstSets[Next]); } // Rule 3: for a rule X := ... Z, we add all symbols from FOLLOW(X) to // FOLLOW(Z). diff --git a/clang-tools-extra/pseudo/lib/GrammarBNF.cpp b/clang-tools-extra/pseudo/lib/GrammarBNF.cpp index 5e4739719eacd..57ed2ca7c8f0b 100644 --- a/clang-tools-extra/pseudo/lib/GrammarBNF.cpp +++ b/clang-tools-extra/pseudo/lib/GrammarBNF.cpp @@ -203,7 +203,7 @@ class GrammarBuilder { const auto &T = G.table(); for (SymbolID SID = 0; SID < T.Nonterminals.size(); ++SID) { auto Range = T.Nonterminals[SID].RuleRange; - if (Range.start == Range.end) + if (Range.Start == Range.End) Diagnostics.push_back( llvm::formatv("No rules for nonterminal: {0}", G.symbolName(SID))); llvm::StringRef NameRef = T.Nonterminals[SID].Name; @@ -216,7 +216,7 @@ class GrammarBuilder { if (T.Rules[RID] == T.Rules[RID + 1]) Diagnostics.push_back( llvm::formatv("Duplicate rule: `{0}`", G.dumpRule(RID))); - // Warning for nullable non-terminals + // Warning for nullable nonterminals if (T.Rules[RID].Size == 0) Diagnostics.push_back( llvm::formatv("Rule `{0}` has a nullable RHS", G.dumpRule(RID))); diff --git a/clang-tools-extra/pseudo/lib/LRGraph.cpp b/clang-tools-extra/pseudo/lib/LRGraph.cpp index edb544fef4940..9dc0cdbbdab81 100644 --- a/clang-tools-extra/pseudo/lib/LRGraph.cpp +++ b/clang-tools-extra/pseudo/lib/LRGraph.cpp @@ -75,7 +75,7 @@ State closure(ItemSet Queue, const Grammar &G) { if (pseudo::isToken(NextSym)) continue; auto RRange = G.table().Nonterminals[NextSym].RuleRange; - for (RuleID RID = RRange.start; RID < RRange.end; ++RID) { + for (RuleID RID = RRange.Start; RID < RRange.End; ++RID) { Item NewItem = Item::start(RID, G); if (InQueue.insert(NewItem).second) // new Queue.push_back(std::move(NewItem)); @@ -204,7 +204,7 @@ LRGraph LRGraph::buildLR0(const Grammar &G) { std::vector<StateID> PendingStates; // Initialize states with the start symbol. auto RRange = G.table().Nonterminals[G.startSymbol()].RuleRange; - for (RuleID RID = RRange.start; RID < RRange.end; ++RID) { + for (RuleID RID = RRange.Start; RID < RRange.End; ++RID) { auto StartState = std::vector<Item>{Item::start(RID, G)}; auto Result = Builder.insert(std::move(StartState)); assert(Result.second && "State must be new"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits