mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -61,31 +61,31 @@ class Value {
|
||||
Value(const Value&) = delete;
|
||||
Value& operator=(const Value&) = delete;
|
||||
|
||||
// Returns the enumerator corresponding to the most-derived type of this
|
||||
// object.
|
||||
auto Tag() const -> Kind { return kind; }
|
||||
|
||||
void Print(llvm::raw_ostream& out) const;
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
|
||||
// Returns the sub-Value specified by `path`, which must be a valid field
|
||||
// path for *this.
|
||||
auto GetField(Nonnull<Arena*> arena, const FieldPath& path,
|
||||
SourceLocation loc) const -> Nonnull<const Value*>;
|
||||
SourceLocation source_loc) const -> Nonnull<const Value*>;
|
||||
|
||||
// Returns a copy of *this, but with the sub-Value specified by `path`
|
||||
// set to `field_value`. `path` must be a valid field path for *this.
|
||||
auto SetField(Nonnull<Arena*> arena, const FieldPath& path,
|
||||
Nonnull<const Value*> field_value, SourceLocation loc) const
|
||||
-> Nonnull<const Value*>;
|
||||
Nonnull<const Value*> field_value,
|
||||
SourceLocation source_loc) const -> Nonnull<const Value*>;
|
||||
|
||||
// Returns the enumerator corresponding to the most-derived type of this
|
||||
// object.
|
||||
auto kind() const -> Kind { return kind_; }
|
||||
|
||||
protected:
|
||||
// Constructs a Value. `tag` must be the enumerator corresponding to the
|
||||
// Constructs a Value. `kind` must be the enumerator corresponding to the
|
||||
// most-derived type being constructed.
|
||||
explicit Value(Kind kind) : kind(kind) {}
|
||||
explicit Value(Kind kind) : kind_(kind) {}
|
||||
|
||||
private:
|
||||
const Kind kind;
|
||||
const Kind kind_;
|
||||
};
|
||||
|
||||
using VarValues = std::vector<std::pair<std::string, Nonnull<const Value*>>>;
|
||||
@@ -115,7 +115,7 @@ class IntValue : public Value {
|
||||
explicit IntValue(int val) : Value(Kind::IntValue), val(val) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::IntValue;
|
||||
return value->kind() == Kind::IntValue;
|
||||
}
|
||||
|
||||
auto Val() const -> int { return val; }
|
||||
@@ -135,7 +135,7 @@ class FunctionValue : public Value {
|
||||
body(body) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::FunctionValue;
|
||||
return value->kind() == Kind::FunctionValue;
|
||||
}
|
||||
|
||||
auto Name() const -> const std::string& { return name; }
|
||||
@@ -155,7 +155,7 @@ class PointerValue : public Value {
|
||||
: Value(Kind::PointerValue), val(std::move(val)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::PointerValue;
|
||||
return value->kind() == Kind::PointerValue;
|
||||
}
|
||||
|
||||
auto Val() const -> const Address& { return val; }
|
||||
@@ -170,7 +170,7 @@ class BoolValue : public Value {
|
||||
explicit BoolValue(bool val) : Value(Kind::BoolValue), val(val) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::BoolValue;
|
||||
return value->kind() == Kind::BoolValue;
|
||||
}
|
||||
|
||||
auto Val() const -> bool { return val; }
|
||||
@@ -195,7 +195,7 @@ class StructValue : public Value {
|
||||
}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::StructValue;
|
||||
return value->kind() == Kind::StructValue;
|
||||
}
|
||||
|
||||
auto elements() const -> const std::vector<TupleElement>& {
|
||||
@@ -218,7 +218,7 @@ class NominalClassValue : public Value {
|
||||
: Value(Kind::NominalClassValue), type(type), inits(inits) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::NominalClassValue;
|
||||
return value->kind() == Kind::NominalClassValue;
|
||||
}
|
||||
|
||||
auto Type() const -> Nonnull<const Value*> { return type; }
|
||||
@@ -238,7 +238,7 @@ class AlternativeConstructorValue : public Value {
|
||||
choice_name(std::move(choice_name)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::AlternativeConstructorValue;
|
||||
return value->kind() == Kind::AlternativeConstructorValue;
|
||||
}
|
||||
|
||||
auto AltName() const -> const std::string& { return alt_name; }
|
||||
@@ -260,7 +260,7 @@ class AlternativeValue : public Value {
|
||||
argument(argument) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::AlternativeValue;
|
||||
return value->kind() == Kind::AlternativeValue;
|
||||
}
|
||||
|
||||
auto AltName() const -> const std::string& { return alt_name; }
|
||||
@@ -286,7 +286,7 @@ class TupleValue : public Value {
|
||||
: Value(Kind::TupleValue), elements(std::move(elements)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::TupleValue;
|
||||
return value->kind() == Kind::TupleValue;
|
||||
}
|
||||
|
||||
auto Elements() const -> const std::vector<TupleElement>& { return elements; }
|
||||
@@ -311,7 +311,7 @@ class BindingPlaceholderValue : public Value {
|
||||
type(type) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::BindingPlaceholderValue;
|
||||
return value->kind() == Kind::BindingPlaceholderValue;
|
||||
}
|
||||
|
||||
auto Name() const -> const std::optional<std::string>& { return name; }
|
||||
@@ -328,7 +328,7 @@ class IntType : public Value {
|
||||
IntType() : Value(Kind::IntType) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::IntType;
|
||||
return value->kind() == Kind::IntType;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -338,7 +338,7 @@ class BoolType : public Value {
|
||||
BoolType() : Value(Kind::BoolType) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::BoolType;
|
||||
return value->kind() == Kind::BoolType;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -348,7 +348,7 @@ class TypeType : public Value {
|
||||
TypeType() : Value(Kind::TypeType) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::TypeType;
|
||||
return value->kind() == Kind::TypeType;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -363,7 +363,7 @@ class FunctionType : public Value {
|
||||
ret(ret) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::FunctionType;
|
||||
return value->kind() == Kind::FunctionType;
|
||||
}
|
||||
|
||||
auto Deduced() const -> const std::vector<GenericBinding>& { return deduced; }
|
||||
@@ -383,7 +383,7 @@ class PointerType : public Value {
|
||||
: Value(Kind::PointerType), type(type) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::PointerType;
|
||||
return value->kind() == Kind::PointerType;
|
||||
}
|
||||
|
||||
auto Type() const -> Nonnull<const Value*> { return type; }
|
||||
@@ -398,7 +398,7 @@ class AutoType : public Value {
|
||||
AutoType() : Value(Kind::AutoType) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::AutoType;
|
||||
return value->kind() == Kind::AutoType;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -414,7 +414,7 @@ class StructType : public Value {
|
||||
: Value(Kind::StructType), fields_(std::move(fields)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::StructType;
|
||||
return value->kind() == Kind::StructType;
|
||||
}
|
||||
|
||||
auto fields() const -> const VarValues& { return fields_; }
|
||||
@@ -433,7 +433,7 @@ class NominalClassType : public Value {
|
||||
methods(std::move(methods)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::NominalClassType;
|
||||
return value->kind() == Kind::NominalClassType;
|
||||
}
|
||||
|
||||
auto Name() const -> const std::string& { return name; }
|
||||
@@ -455,7 +455,7 @@ class ChoiceType : public Value {
|
||||
alternatives(std::move(alternatives)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::ChoiceType;
|
||||
return value->kind() == Kind::ChoiceType;
|
||||
}
|
||||
|
||||
auto Name() const -> const std::string& { return name; }
|
||||
@@ -472,7 +472,7 @@ class ContinuationType : public Value {
|
||||
ContinuationType() : Value(Kind::ContinuationType) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::ContinuationType;
|
||||
return value->kind() == Kind::ContinuationType;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -483,7 +483,7 @@ class VariableType : public Value {
|
||||
: Value(Kind::VariableType), name(std::move(name)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::VariableType;
|
||||
return value->kind() == Kind::VariableType;
|
||||
}
|
||||
|
||||
auto Name() const -> const std::string& { return name; }
|
||||
@@ -499,7 +499,7 @@ class ContinuationValue : public Value {
|
||||
: Value(Kind::ContinuationValue), stack(std::move(stack)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::ContinuationValue;
|
||||
return value->kind() == Kind::ContinuationValue;
|
||||
}
|
||||
|
||||
auto Stack() const -> const std::vector<Nonnull<Frame*>>& { return stack; }
|
||||
@@ -514,7 +514,7 @@ class StringType : public Value {
|
||||
StringType() : Value(Kind::StringType) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::StringType;
|
||||
return value->kind() == Kind::StringType;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -525,7 +525,7 @@ class StringValue : public Value {
|
||||
: Value(Kind::StringValue), val(std::move(val)) {}
|
||||
|
||||
static auto classof(const Value* value) -> bool {
|
||||
return value->Tag() == Kind::StringValue;
|
||||
return value->kind() == Kind::StringValue;
|
||||
}
|
||||
|
||||
auto Val() const -> const std::string& { return val; }
|
||||
@@ -535,11 +535,11 @@ class StringValue : public Value {
|
||||
};
|
||||
|
||||
auto CopyVal(Nonnull<Arena*> arena, Nonnull<const Value*> val,
|
||||
SourceLocation loc) -> Nonnull<const Value*>;
|
||||
SourceLocation source_loc) -> Nonnull<const Value*>;
|
||||
|
||||
auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2) -> bool;
|
||||
auto ValueEqual(Nonnull<const Value*> v1, Nonnull<const Value*> v2,
|
||||
SourceLocation loc) -> bool;
|
||||
SourceLocation source_loc) -> bool;
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
|
||||
Reference in New Issue
Block a user