Mass rename SourceLoc and Tag (#860)

This does a mass rename of:

-   `SourceLoc()` -> `source_loc()` for property naming
    - `loc` -> `source_loc_` for underscore+consistency
    - Generally changing function args to `source_loc` for consistency
-   `Tag()` -> `kind()` for property naming and `Kind` parity
    - `tag` -> `kind_` for underscore

Also renames `Pos` and `Results` on `Action`. These are a bit of an exception in that most base classes only have `Tag` and maybe `SourceLoc`, whereas `Action` has a little more. I felt okay having `source_loc()` and `kind()` on the base class where children do `Exp()` and the like, but it felt weird to me to mix it on the same class.

The reason for doing this cross-class in one PR is so that I can do it efficiently with a global replace in the codebase, rather than e.g. changing `Expression` but having to read through compiler errors to determine where it's calling `Expression`'s `Tag` versus a different `Tag`. The end result should be equivalent.
This commit is contained in:
Jon Meow
2021-09-29 16:52:12 -07:00
committed by GitHub
parent c4e40aaa86
commit 70797e8bf8
27 changed files with 779 additions and 734 deletions
+31 -31
View File
@@ -29,48 +29,48 @@ class Action {
Action(const Value&) = delete;
Action& operator=(const Value&) = delete;
// The position or state of the action. Starts at 0 and goes up to the number
// of subexpressions.
//
// pos indicates how many of the entries in the following `results` vector
// will be filled in the next time this action is active.
// For each i < pos, results[i] contains a pointer to a Value.
auto Pos() const -> int { return pos; }
// Results from a subexpression.
auto Results() const -> const std::vector<Nonnull<const Value*>>& {
return results;
}
void SetPos(int pos) { this->pos = pos; }
void AddResult(Nonnull<const Value*> result) { results.push_back(result); }
void AddResult(Nonnull<const Value*> result) { results_.push_back(result); }
void Clear() {
pos = 0;
results.clear();
pos_ = 0;
results_.clear();
}
// Returns the enumerator corresponding to the most-derived type of this
// object.
auto Tag() const -> Kind { return kind; }
static void PrintList(const Stack<Nonnull<Action*>>& ls,
llvm::raw_ostream& out);
void Print(llvm::raw_ostream& out) const;
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
// Returns the enumerator corresponding to the most-derived type of this
// object.
auto kind() const -> Kind { return kind_; }
// The position or state of the action. Starts at 0 and goes up to the number
// of subexpressions.
//
// pos indicates how many of the entries in the following `results` vector
// will be filled in the next time this action is active.
// For each i < pos, results[i] contains a pointer to a Value.
auto pos() const -> int { return pos_; }
void set_pos(int pos) { this->pos_ = pos; }
// Results from a subexpression.
auto results() const -> const std::vector<Nonnull<const Value*>>& {
return results_;
}
protected:
// Constructs an Action. `tag` must be the enumerator corresponding to the
// Constructs an Action. `kind` must be the enumerator corresponding to the
// most-derived type being constructed.
explicit Action(Kind kind) : kind(kind) {}
explicit Action(Kind kind) : kind_(kind) {}
private:
int pos = 0;
std::vector<Nonnull<const Value*>> results;
int pos_ = 0;
std::vector<Nonnull<const Value*>> results_;
const Kind kind;
const Kind kind_;
};
class LValAction : public Action {
@@ -79,7 +79,7 @@ class LValAction : public Action {
: Action(Kind::LValAction), exp(exp) {}
static auto classof(const Action* action) -> bool {
return action->Tag() == Kind::LValAction;
return action->kind() == Kind::LValAction;
}
auto Exp() const -> Nonnull<const Expression*> { return exp; }
@@ -94,7 +94,7 @@ class ExpressionAction : public Action {
: Action(Kind::ExpressionAction), exp(exp) {}
static auto classof(const Action* action) -> bool {
return action->Tag() == Kind::ExpressionAction;
return action->kind() == Kind::ExpressionAction;
}
auto Exp() const -> Nonnull<const Expression*> { return exp; }
@@ -109,7 +109,7 @@ class PatternAction : public Action {
: Action(Kind::PatternAction), pat(pat) {}
static auto classof(const Action* action) -> bool {
return action->Tag() == Kind::PatternAction;
return action->kind() == Kind::PatternAction;
}
auto Pat() const -> Nonnull<const Pattern*> { return pat; }
@@ -124,7 +124,7 @@ class StatementAction : public Action {
: Action(Kind::StatementAction), stmt(stmt) {}
static auto classof(const Action* action) -> bool {
return action->Tag() == Kind::StatementAction;
return action->kind() == Kind::StatementAction;
}
auto Stmt() const -> Nonnull<const Statement*> { return stmt; }