Rename Ptr<T> to Nonnull<T*> (#832)

Note that ptr.h also includes an enable_if change, to help avoid https://bugs.llvm.org/show_bug.cgi?id=51881
This commit is contained in:
Jon Meow
2021-09-16 19:22:57 -07:00
committed by GitHub
parent 5e66248db0
commit 56dc4ae375
35 changed files with 584 additions and 535 deletions
+22 -22
View File
@@ -71,7 +71,7 @@ class AutoPattern : public Pattern {
class BindingPattern : public Pattern {
public:
BindingPattern(SourceLocation loc, std::optional<std::string> name,
Ptr<const Pattern> type)
Nonnull<const Pattern*> type)
: Pattern(Kind::BindingPattern, loc), name(std::move(name)), type(type) {}
static auto classof(const Pattern* pattern) -> bool {
@@ -82,11 +82,11 @@ class BindingPattern : public Pattern {
auto Name() const -> const std::optional<std::string>& { return name; }
// The pattern specifying the type of values that this pattern matches.
auto Type() const -> Ptr<const Pattern> { return type; }
auto Type() const -> Nonnull<const Pattern*> { return type; }
private:
std::optional<std::string> name;
Ptr<const Pattern> type;
Nonnull<const Pattern*> type;
};
// A pattern that matches a tuple value field-wise.
@@ -94,14 +94,14 @@ class TuplePattern : public Pattern {
public:
// Represents a portion of a tuple pattern corresponding to a single field.
struct Field {
Field(std::string name, Ptr<const Pattern> pattern)
Field(std::string name, Nonnull<const Pattern*> pattern)
: name(std::move(name)), pattern(pattern) {}
// The field name. Cannot be empty
std::string name;
// The pattern the field must match.
Ptr<const Pattern> pattern;
Nonnull<const Pattern*> pattern;
};
TuplePattern(SourceLocation loc, std::vector<Field> fields)
@@ -111,7 +111,7 @@ class TuplePattern : public Pattern {
// ExpressionPattern.
//
// REQUIRES: tuple_literal->Tag() == Expression::Kind::TupleLiteral
TuplePattern(Ptr<Arena> arena, Ptr<const Expression> tuple_literal);
TuplePattern(Nonnull<Arena*> arena, Nonnull<const Expression*> tuple_literal);
static auto classof(const Pattern* pattern) -> bool {
return pattern->Tag() == Kind::TuplePattern;
@@ -126,19 +126,19 @@ class TuplePattern : public Pattern {
// Converts paren_contents to a Pattern, interpreting the parentheses as
// grouping if their contents permit that interpretation, or as forming a
// tuple otherwise.
auto PatternFromParenContents(Ptr<Arena> arena, SourceLocation loc,
auto PatternFromParenContents(Nonnull<Arena*> arena, SourceLocation loc,
const ParenContents<Pattern>& paren_contents)
-> Ptr<const Pattern>;
-> Nonnull<const Pattern*>;
// Converts paren_contents to a TuplePattern, interpreting the parentheses as
// forming a tuple.
auto TuplePatternFromParenContents(Ptr<Arena> arena, SourceLocation loc,
auto TuplePatternFromParenContents(Nonnull<Arena*> arena, SourceLocation loc,
const ParenContents<Pattern>& paren_contents)
-> Ptr<const TuplePattern>;
-> Nonnull<const TuplePattern*>;
// Converts `contents` to ParenContents<Pattern> by replacing each Expression
// with an ExpressionPattern.
auto ParenExpressionToParenPattern(Ptr<Arena> arena,
auto ParenExpressionToParenPattern(Nonnull<Arena*> arena,
const ParenContents<Expression>& contents)
-> ParenContents<Pattern>;
@@ -148,9 +148,9 @@ class AlternativePattern : public Pattern {
// Constructs an AlternativePattern that matches a value of the type
// specified by choice_type if it represents an alternative named
// alternative_name, and its arguments match `arguments`.
AlternativePattern(SourceLocation loc, Ptr<const Expression> choice_type,
AlternativePattern(SourceLocation loc, Nonnull<const Expression*> choice_type,
std::string alternative_name,
Ptr<const TuplePattern> arguments)
Nonnull<const TuplePattern*> arguments)
: Pattern(Kind::AlternativePattern, loc),
choice_type(choice_type),
alternative_name(std::move(alternative_name)),
@@ -158,30 +158,30 @@ class AlternativePattern : public Pattern {
// Constructs an AlternativePattern that matches the alternative specified
// by `alternative`, if its arguments match `arguments`.
AlternativePattern(SourceLocation loc, Ptr<const Expression> alternative,
Ptr<const TuplePattern> arguments);
AlternativePattern(SourceLocation loc, Nonnull<const Expression*> alternative,
Nonnull<const TuplePattern*> arguments);
static auto classof(const Pattern* pattern) -> bool {
return pattern->Tag() == Kind::AlternativePattern;
}
auto ChoiceType() const -> Ptr<const Expression> { return choice_type; }
auto ChoiceType() const -> Nonnull<const Expression*> { return choice_type; }
auto AlternativeName() const -> const std::string& {
return alternative_name;
}
auto Arguments() const -> Ptr<const TuplePattern> { return arguments; }
auto Arguments() const -> Nonnull<const TuplePattern*> { return arguments; }
private:
Ptr<const Expression> choice_type;
Nonnull<const Expression*> choice_type;
std::string alternative_name;
Ptr<const TuplePattern> arguments;
Nonnull<const TuplePattern*> arguments;
};
// A pattern that matches a value if it is equal to the value of a given
// expression.
class ExpressionPattern : public Pattern {
public:
ExpressionPattern(Ptr<const Expression> expression)
ExpressionPattern(Nonnull<const Expression*> expression)
: Pattern(Kind::ExpressionPattern, expression->SourceLoc()),
expression(expression) {}
@@ -189,10 +189,10 @@ class ExpressionPattern : public Pattern {
return pattern->Tag() == Kind::ExpressionPattern;
}
auto Expression() const -> Ptr<const Expression> { return expression; }
auto Expression() const -> Nonnull<const Expression*> { return expression; }
private:
Ptr<const Carbon::Expression> expression;
Nonnull<const Carbon::Expression*> expression;
};
} // namespace Carbon