mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 07:21:04 +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:
@@ -42,37 +42,38 @@ class Expression {
|
||||
IntrinsicExpression,
|
||||
};
|
||||
|
||||
// Returns the enumerator corresponding to the most-derived type of this
|
||||
// object.
|
||||
auto Tag() const -> Kind { return kind; }
|
||||
|
||||
auto SourceLoc() const -> SourceLocation { return loc; }
|
||||
|
||||
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_; }
|
||||
|
||||
auto source_loc() const -> SourceLocation { return source_loc_; }
|
||||
|
||||
protected:
|
||||
// Constructs an Expression representing syntax at the given line number.
|
||||
// `tag` must be the enumerator corresponding to the most-derived type being
|
||||
// `kind` must be the enumerator corresponding to the most-derived type being
|
||||
// constructed.
|
||||
Expression(Kind kind, SourceLocation loc) : kind(kind), loc(loc) {}
|
||||
Expression(Kind kind, SourceLocation source_loc)
|
||||
: kind_(kind), source_loc_(source_loc) {}
|
||||
|
||||
private:
|
||||
const Kind kind;
|
||||
SourceLocation loc;
|
||||
const Kind kind_;
|
||||
SourceLocation source_loc_;
|
||||
};
|
||||
|
||||
// Converts paren_contents to an Expression, interpreting the parentheses as
|
||||
// grouping if their contents permit that interpretation, or as forming a
|
||||
// tuple otherwise.
|
||||
auto ExpressionFromParenContents(
|
||||
Nonnull<Arena*> arena, SourceLocation loc,
|
||||
Nonnull<Arena*> arena, SourceLocation source_loc,
|
||||
const ParenContents<Expression>& paren_contents) -> Nonnull<Expression*>;
|
||||
|
||||
// Converts paren_contents to an Expression, interpreting the parentheses as
|
||||
// forming a tuple.
|
||||
auto TupleExpressionFromParenContents(
|
||||
Nonnull<Arena*> arena, SourceLocation loc,
|
||||
Nonnull<Arena*> arena, SourceLocation source_loc,
|
||||
const ParenContents<Expression>& paren_contents) -> Nonnull<Expression*>;
|
||||
|
||||
// A FieldInitializer represents the initialization of a single tuple field.
|
||||
@@ -102,11 +103,12 @@ enum class Operator {
|
||||
|
||||
class IdentifierExpression : public Expression {
|
||||
public:
|
||||
explicit IdentifierExpression(SourceLocation loc, std::string name)
|
||||
: Expression(Kind::IdentifierExpression, loc), name(std::move(name)) {}
|
||||
explicit IdentifierExpression(SourceLocation source_loc, std::string name)
|
||||
: Expression(Kind::IdentifierExpression, source_loc),
|
||||
name(std::move(name)) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::IdentifierExpression;
|
||||
return exp->kind() == Kind::IdentifierExpression;
|
||||
}
|
||||
|
||||
auto Name() const -> const std::string& { return name; }
|
||||
@@ -117,15 +119,15 @@ class IdentifierExpression : public Expression {
|
||||
|
||||
class FieldAccessExpression : public Expression {
|
||||
public:
|
||||
explicit FieldAccessExpression(SourceLocation loc,
|
||||
explicit FieldAccessExpression(SourceLocation source_loc,
|
||||
Nonnull<Expression*> aggregate,
|
||||
std::string field)
|
||||
: Expression(Kind::FieldAccessExpression, loc),
|
||||
: Expression(Kind::FieldAccessExpression, source_loc),
|
||||
aggregate(aggregate),
|
||||
field(std::move(field)) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::FieldAccessExpression;
|
||||
return exp->kind() == Kind::FieldAccessExpression;
|
||||
}
|
||||
|
||||
auto Aggregate() const -> Nonnull<const Expression*> { return aggregate; }
|
||||
@@ -139,14 +141,15 @@ class FieldAccessExpression : public Expression {
|
||||
|
||||
class IndexExpression : public Expression {
|
||||
public:
|
||||
explicit IndexExpression(SourceLocation loc, Nonnull<Expression*> aggregate,
|
||||
explicit IndexExpression(SourceLocation source_loc,
|
||||
Nonnull<Expression*> aggregate,
|
||||
Nonnull<Expression*> offset)
|
||||
: Expression(Kind::IndexExpression, loc),
|
||||
: Expression(Kind::IndexExpression, source_loc),
|
||||
aggregate(aggregate),
|
||||
offset(offset) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::IndexExpression;
|
||||
return exp->kind() == Kind::IndexExpression;
|
||||
}
|
||||
|
||||
auto Aggregate() const -> Nonnull<const Expression*> { return aggregate; }
|
||||
@@ -161,11 +164,11 @@ class IndexExpression : public Expression {
|
||||
|
||||
class IntLiteral : public Expression {
|
||||
public:
|
||||
explicit IntLiteral(SourceLocation loc, int val)
|
||||
: Expression(Kind::IntLiteral, loc), val(val) {}
|
||||
explicit IntLiteral(SourceLocation source_loc, int val)
|
||||
: Expression(Kind::IntLiteral, source_loc), val(val) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::IntLiteral;
|
||||
return exp->kind() == Kind::IntLiteral;
|
||||
}
|
||||
|
||||
auto Val() const -> int { return val; }
|
||||
@@ -176,11 +179,11 @@ class IntLiteral : public Expression {
|
||||
|
||||
class BoolLiteral : public Expression {
|
||||
public:
|
||||
explicit BoolLiteral(SourceLocation loc, bool val)
|
||||
: Expression(Kind::BoolLiteral, loc), val(val) {}
|
||||
explicit BoolLiteral(SourceLocation source_loc, bool val)
|
||||
: Expression(Kind::BoolLiteral, source_loc), val(val) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::BoolLiteral;
|
||||
return exp->kind() == Kind::BoolLiteral;
|
||||
}
|
||||
|
||||
auto Val() const -> bool { return val; }
|
||||
@@ -191,11 +194,11 @@ class BoolLiteral : public Expression {
|
||||
|
||||
class StringLiteral : public Expression {
|
||||
public:
|
||||
explicit StringLiteral(SourceLocation loc, std::string val)
|
||||
: Expression(Kind::StringLiteral, loc), val(std::move(val)) {}
|
||||
explicit StringLiteral(SourceLocation source_loc, std::string val)
|
||||
: Expression(Kind::StringLiteral, source_loc), val(std::move(val)) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::StringLiteral;
|
||||
return exp->kind() == Kind::StringLiteral;
|
||||
}
|
||||
|
||||
auto Val() const -> const std::string& { return val; }
|
||||
@@ -206,24 +209,25 @@ class StringLiteral : public Expression {
|
||||
|
||||
class StringTypeLiteral : public Expression {
|
||||
public:
|
||||
explicit StringTypeLiteral(SourceLocation loc)
|
||||
: Expression(Kind::StringTypeLiteral, loc) {}
|
||||
explicit StringTypeLiteral(SourceLocation source_loc)
|
||||
: Expression(Kind::StringTypeLiteral, source_loc) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::StringTypeLiteral;
|
||||
return exp->kind() == Kind::StringTypeLiteral;
|
||||
}
|
||||
};
|
||||
|
||||
class TupleLiteral : public Expression {
|
||||
public:
|
||||
explicit TupleLiteral(SourceLocation loc) : TupleLiteral(loc, {}) {}
|
||||
explicit TupleLiteral(SourceLocation source_loc)
|
||||
: TupleLiteral(source_loc, {}) {}
|
||||
|
||||
explicit TupleLiteral(SourceLocation loc,
|
||||
explicit TupleLiteral(SourceLocation source_loc,
|
||||
std::vector<FieldInitializer> fields)
|
||||
: Expression(Kind::TupleLiteral, loc), fields(std::move(fields)) {}
|
||||
: Expression(Kind::TupleLiteral, source_loc), fields(std::move(fields)) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::TupleLiteral;
|
||||
return exp->kind() == Kind::TupleLiteral;
|
||||
}
|
||||
|
||||
auto Fields() const -> const std::vector<FieldInitializer>& { return fields; }
|
||||
@@ -248,7 +252,7 @@ class StructLiteral : public Expression {
|
||||
}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::StructLiteral;
|
||||
return exp->kind() == Kind::StructLiteral;
|
||||
}
|
||||
|
||||
auto fields() const -> const std::vector<FieldInitializer>& {
|
||||
@@ -272,7 +276,7 @@ class StructTypeLiteral : public Expression {
|
||||
: Expression(Kind::StructTypeLiteral, loc), fields_(std::move(fields)) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::StructTypeLiteral;
|
||||
return exp->kind() == Kind::StructTypeLiteral;
|
||||
}
|
||||
|
||||
auto fields() const -> const std::vector<FieldInitializer>& {
|
||||
@@ -286,14 +290,14 @@ class StructTypeLiteral : public Expression {
|
||||
class PrimitiveOperatorExpression : public Expression {
|
||||
public:
|
||||
explicit PrimitiveOperatorExpression(
|
||||
SourceLocation loc, Operator op,
|
||||
SourceLocation source_loc, Operator op,
|
||||
std::vector<Nonnull<Expression*>> arguments)
|
||||
: Expression(Kind::PrimitiveOperatorExpression, loc),
|
||||
: Expression(Kind::PrimitiveOperatorExpression, source_loc),
|
||||
op(op),
|
||||
arguments(std::move(arguments)) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::PrimitiveOperatorExpression;
|
||||
return exp->kind() == Kind::PrimitiveOperatorExpression;
|
||||
}
|
||||
|
||||
auto Op() const -> Operator { return op; }
|
||||
@@ -311,14 +315,15 @@ class PrimitiveOperatorExpression : public Expression {
|
||||
|
||||
class CallExpression : public Expression {
|
||||
public:
|
||||
explicit CallExpression(SourceLocation loc, Nonnull<Expression*> function,
|
||||
explicit CallExpression(SourceLocation source_loc,
|
||||
Nonnull<Expression*> function,
|
||||
Nonnull<Expression*> argument)
|
||||
: Expression(Kind::CallExpression, loc),
|
||||
: Expression(Kind::CallExpression, source_loc),
|
||||
function(function),
|
||||
argument(argument) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::CallExpression;
|
||||
return exp->kind() == Kind::CallExpression;
|
||||
}
|
||||
|
||||
auto Function() const -> Nonnull<const Expression*> { return function; }
|
||||
@@ -333,17 +338,17 @@ class CallExpression : public Expression {
|
||||
|
||||
class FunctionTypeLiteral : public Expression {
|
||||
public:
|
||||
explicit FunctionTypeLiteral(SourceLocation loc,
|
||||
explicit FunctionTypeLiteral(SourceLocation source_loc,
|
||||
Nonnull<Expression*> parameter,
|
||||
Nonnull<Expression*> return_type,
|
||||
bool is_omitted_return_type)
|
||||
: Expression(Kind::FunctionTypeLiteral, loc),
|
||||
: Expression(Kind::FunctionTypeLiteral, source_loc),
|
||||
parameter(parameter),
|
||||
return_type(return_type),
|
||||
is_omitted_return_type(is_omitted_return_type) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::FunctionTypeLiteral;
|
||||
return exp->kind() == Kind::FunctionTypeLiteral;
|
||||
}
|
||||
|
||||
auto Parameter() const -> Nonnull<const Expression*> { return parameter; }
|
||||
@@ -360,41 +365,41 @@ class FunctionTypeLiteral : public Expression {
|
||||
|
||||
class BoolTypeLiteral : public Expression {
|
||||
public:
|
||||
explicit BoolTypeLiteral(SourceLocation loc)
|
||||
: Expression(Kind::BoolTypeLiteral, loc) {}
|
||||
explicit BoolTypeLiteral(SourceLocation source_loc)
|
||||
: Expression(Kind::BoolTypeLiteral, source_loc) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::BoolTypeLiteral;
|
||||
return exp->kind() == Kind::BoolTypeLiteral;
|
||||
}
|
||||
};
|
||||
|
||||
class IntTypeLiteral : public Expression {
|
||||
public:
|
||||
explicit IntTypeLiteral(SourceLocation loc)
|
||||
: Expression(Kind::IntTypeLiteral, loc) {}
|
||||
explicit IntTypeLiteral(SourceLocation source_loc)
|
||||
: Expression(Kind::IntTypeLiteral, source_loc) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::IntTypeLiteral;
|
||||
return exp->kind() == Kind::IntTypeLiteral;
|
||||
}
|
||||
};
|
||||
|
||||
class ContinuationTypeLiteral : public Expression {
|
||||
public:
|
||||
explicit ContinuationTypeLiteral(SourceLocation loc)
|
||||
: Expression(Kind::ContinuationTypeLiteral, loc) {}
|
||||
explicit ContinuationTypeLiteral(SourceLocation source_loc)
|
||||
: Expression(Kind::ContinuationTypeLiteral, source_loc) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::ContinuationTypeLiteral;
|
||||
return exp->kind() == Kind::ContinuationTypeLiteral;
|
||||
}
|
||||
};
|
||||
|
||||
class TypeTypeLiteral : public Expression {
|
||||
public:
|
||||
explicit TypeTypeLiteral(SourceLocation loc)
|
||||
: Expression(Kind::TypeTypeLiteral, loc) {}
|
||||
explicit TypeTypeLiteral(SourceLocation source_loc)
|
||||
: Expression(Kind::TypeTypeLiteral, source_loc) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::TypeTypeLiteral;
|
||||
return exp->kind() == Kind::TypeTypeLiteral;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -409,7 +414,7 @@ class IntrinsicExpression : public Expression {
|
||||
intrinsic(intrinsic) {}
|
||||
|
||||
static auto classof(const Expression* exp) -> bool {
|
||||
return exp->Tag() == Kind::IntrinsicExpression;
|
||||
return exp->kind() == Kind::IntrinsicExpression;
|
||||
}
|
||||
|
||||
auto Intrinsic() const -> IntrinsicKind { return intrinsic; }
|
||||
|
||||
Reference in New Issue
Block a user