Skip to content

Commit

Permalink
[pseudo] Fix some naming-style violations.
Browse files Browse the repository at this point in the history
  • Loading branch information
hokein committed Mar 17, 2022
1 parent 45cb2df commit 5a62495
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
Expand Up @@ -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;
};

Expand Down
16 changes: 8 additions & 8 deletions clang-tools-extra/pseudo/lib/Grammar.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/pseudo/lib/GrammarBNF.cpp
Expand Up @@ -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;
Expand All @@ -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)));
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/pseudo/lib/LRGraph.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 5a62495

Please sign in to comment.